Q3D Tips&Tricks

» Mon May 18, 2015 6:52 pm

@rekjl thanks im happy that this topic has a meaning for other users!

As we all know the documentation for Q3D plugin is worked on by the plugins developers i opened the topic, cause at the time i bought it there was very little documentation, and the examples will not help a lot the newbys as i was before and im still am , at this moment with Q3d but i said what i learn to share, so here is my next shared knowledge, even though is simple and already given by the Q3D examples some users wont actually understand it for what it is, so il brake it in the simplest way so everyone can understand,
i seen lately on the Q3d page that some people are trying to figure it out the angle in 3d , or apply force at surtain angle, il tell you just this, there is no need for angle calculation once you have the mouse position in XYZ is basically the same thing , so for you to apply a 3d physics force into the 3d plane, you just need to look at the Raycaster example,

what raycaster does is casting a line projection or whatever you want to call it, towards the mouse position x,y and calculates the Z axes based on the viewport position, and the object inside your world, now you can do this for all kind of objects, but essentially for it to work, properly and easy way, is not to cast on an moving object, but on a static object, as is a platform, that signifies the ground from your world, i did a pool example for you guys to see how this works, so basically the raycaster example you can clone it into your game and replace surtain parts, as the maximum distance from where to cast, and take position and so on, since c2 now offers 100,000px width /height surface, even though it doesn't really matter cause in Q3d everything is at a difference space time and magnitude.

so the simple fact? raycaster example is the method to solve the Mouse X Y Z, is already given to you,
now to apply a force or an impulse once you have the raycast casting the line towards the desired plane, or object , instead of breaking your heads figuring out what is the mouse.z use this variable instead

(lets say you keep the raycaster as the default name)

Q3dOymoPhysics.ApplyForceAtPosition Raycaster.x Raycaster.y Raycaster.z that wold be your mouse position in the 3d world

and the result it wold be something like in this Link deprecated il reupload soon.

And forgot to mention, when you use raycast example, you need 1 thing to work, your q3dobject has to use a 3d model, can be a cube shape what ever, atleast on my side until i dident set an model to use, dident worked.
Last edited by gamecorpstudio on Thu May 28, 2015 10:57 pm, edited 1 time in total.
B
54
S
14
G
64
Posts: 1,252
Reputation: 39,500

» Thu May 28, 2015 5:24 am

Hello, all!

Some people complained that morph animations were very hard to do, so I thought I'd share a way to create morph animations from rigged ones that I sort of stumbled upon during my searches through forums and tutorials. I didn't actually find tutorials on how to do this whole process--just bits and pieces of information that I pasted together and experimented with. So this is my own way of doing it, and it's somewhat rough. Anyone who knows how to do it better, please correct me if you want! If this is already common knowledge, then this might come in handy for people new to Blender.

I tried to do a walk cycle without using a rig--just manipulating the vertices--and I realized that it would take one hundred years for me to do it. Then I had the thought that maybe I could somehow capture rigged poses with Blender's shape keys and paste them into an animation timeline. Sure enough, it's possible, but there are a few tricks to doing it fairly fast and well. And there's also the question of how to do multiple morph animations in a single .json file, add more animations to the same file as you need them, and rename them as separate animations so that they can be called and tweened in Q3D. I might talk about how to do that in another post, because I'm still trying to figure out how to simplify that process. I've been able to do it so far, mostly by copying and pasting animations from one .json file into another, but it's a tedious and sometimes confusing process. For now I'll just concentrate on a single morph animation, with a suggestion for how to do multiple ones in a single file later in this post.

It turns out that the morph animations run pretty smoothly and well in Q3D and, as @QuaziGNRLNose has said, they are less costly for the hard drive to handle. So far it's working so well that I've decided to make my scenes as boneless as possible.

Here's how to do it:

1. First create your model, rig and skeletal animation as you normally would.

2. Save your original skeletal anim file (you wouldn't want to lose it) and do a "save as" to create a separate morph animation file using the same model.

3. While you're in Object Mode, count the number of poses in your animation cycle (not including the first pose), select both the model and its skeleton, and use shift + D to duplicate the model that many times. If your last pose is the same as the first--as in a walk cycle--don't count the last one either. For instance, if you have nine poses in your walk cycle, create 7 clones of the model. In the case of the walk cycle I just mentioned, you should now have 8 identical models. Place them in a row, next to each other, from left to right. You're going to be using the first model (the one you cloned from) as the final, boneless, morph animation model, while you're going to use the other models for capturing each pose and transferring the pose to the first model. It's important that you keep that model in its original centered spot. I made the mistake of using one of the cloned models as the final one (not centered in the Blender 3D view), and the exported version was off-center in Q3D.

4. Start with your first (original) model. We'll call this model 1. Select model 1 (not its skeleton) in Object Mode and set the timeline to the first frame, the first pose. This pose will be the Shape Key "basis" for all of the shape keys that you will create. Once the model is in this pose, open the Modifier window (click the wrench icon in the Properties window), and the first thing you will see is the Armature Modifier. Click Apply to capture the first pose, and the Armature Modifier disappears.

5. While still in Object Mode, select model 1's skeleton (only) and then switch to Edit Mode. Press X to delete the bones.

6. Now we're going to create model 1's first Shape Key: Switch back to Object Mode and select model 1. Open the Data window by clicking the vertex triangle icon (next to the wrench). Scroll down to the Shape Key section and click the plus sign (the add button) to create the first Shape Key, which is named "Basis" by default.

7. Now proceed to the second model in line. This model will represent and capture the second pose in the timeline, and will be used to transfer that pose--as a Shape Key--to model 1. Select model 2 (not its skeleton) in Object Mode and set the timeline to the second pose. As you did in #4 above, open the Modifier window and apply the the Armature Modifier.

8. Repeat what you did in #5 to delete the bones of model 2.

9. Repeat what you did in #6 to create model 2's first Shape Key, which will also be named "Basis." You don't have to change the name of this key.

10. Keeping model 2 selected in Object Mode, select model 1. In model 1's Shape Key window, click the dark triangle button underneath the add and subtract buttons. (I think you can also press W) to bring up the Specials list. Select "Join as Shapes." This will automatically transfer model 2's Shape Key to model 1. You don't have to rename this key either.

You can test whether or not the transfer worked by selecting only model 1 and switching to Edit Mode. Click on the Basis key and the new key, and you should see the model switch from pose to pose. You can also switch to Object Mode and use the "value" slider underneath the Shape Keys to shift from 0 to 1, to see model 1 morph from the basis pose to the second pose. 0 always references the basis pose, while 1 references the target pose for that particular Shape Key.

11. Repeat #'s 7 through 10 for each of the models, capturing each pose as they're arranged on the timeline and transferring each, as Shape Keys, to model 1. Test each Shape Key, just in case.

12. Once you're finished with all the models, delete all of them except for model 1.

13, Switch from Action Editor to Shape Key Editor. Create and name a new animation by clicking the add button in the field next to "summary." You will see that the timeline is divided into one channel per pose, not including the first pose (or the last pose, if it's the same as the first). Why the first (or last) pose wasn't included confused me at first, but the reason became clear after I stumbled through the recording process--as you will also see in the next step:

14. To record the first pose, the Basis, set the timeline at frame 1, set all of the channels at 0, click Key, select Insert Keyframes, and select All Channels. Setting 0 in all channels is exactly the same as setting and recording the first pose--which is why a first pose channel is unnecessary. If the last pose is the same as the first, repeat this process for the last frame of your animation.

15. For the second pose, set the timeline at whatever the next frame is going to be, set channel 1 at 1, and set all of the other channels at 0. Record the keyframes for all channels as you did in #14. For the third pose, move the timeline to the next frame, set only channel 2 at 1 and all the others at 0. Record. For the fourth pose, move the timeline to the next frame, set only channel 3 at 1 and all the others at 0. Do this for all of the poses (except, of course, for the last pose if it's the same as the first).

16. Make sure that you save often as you go through this process, and save the model when its animation is finished. Now you can export the model, choosing the three.js exporter (File>Export>Three.js). Here's how I set up the export page. I don't exactly know if this part is correct, but it works in Q3D:

I checked Vertices, Faces, Normals, UVs (but not bones or skinning)
I checked FaceMaterials and Vertex Colors.
I checked Morph Animation and kept Skeletal Animations off
I'm not sure if it's necessary, but I checked Frame Index As Time and Embed Animation
I didn't check any of the Scene boxes.
For Settings, I checked Textures and Copy Textures, and I kept Enable Precision checked.

Within your Construct 2 project, import the .json file into your Files file in the Projects window. Double-click the newly imported .json to open it in Notepad or Wordpad (or whatever program it opens into) and change the name of your animation to what you want by doing the following. I use Notepad, so I'm not sure how this is done in Wordpad:

1. Click Edit>Replace. In the Find What field, enter "animation_". In the Replace With field, enter "walk" or whatever name you choose. Then click "Replace All."
4. Save the file.

That's it! The animation is renamed.

For multiple animations in a single file, so far I have created separate .json files of the same model with single animations in each of them. I just renamed and copied the animation part of each file and pasted it into the original model/morph animation file within Construct 2. That sounds straightforward enough, but it's somewhat tedious, because the files are so large. It's a little tricky selecting such a large portion of the script, because you have to know where the animation portion begins and ends. I marked the beginning and end of that section by creating a large gap between it and the rest of the script.

What I haven't tried yet is to place all of the morph animations on a single timeline. That would work, I think, but you'd have to know where each animation begins and ends, and go through a more complex renaming process. Also, I'm not sure if each separate animation has to begin with the 000000 frame or not???

Then there's something I just started exploring (but haven't figured out yet), and that's how to parent objects to this boneless mesh so that you can have your character carry things, wear helmets, etc. I know that in Blender you can attach a single bone to a single vertex while still preserving the morph animation--and I was able to do that--but I don't know if it's possible to parent an object to that bone. Is that hierarchy preserved in the .json file? I remember @QuaziGNRLNose mentioning something about that somewhere--I think....

Another thing I wondered about is the huge .json file size. Does that hurt the game's performance? Is skeletal animation the better choice? I know that @QuaziGNRLNose said that skeletal animation is more costly to performance, but is that still true in version 2.4?

B
11
S
2
Posts: 19
Reputation: 676

» Thu May 28, 2015 10:53 am

Thank you
B
213
S
29
G
14
Posts: 1,868
Reputation: 36,972

» Thu May 28, 2015 10:59 pm

awesome, tips man, thanks a lot, really covered a large problem for most of us your awesome @terransage

don't worrie no computer will explode on my shift haha ...
Last edited by gamecorpstudio on Fri May 29, 2015 2:47 pm, edited 1 time in total.
B
54
S
14
G
64
Posts: 1,252
Reputation: 39,500

» Fri May 29, 2015 3:36 am

You're welcome, @Lordshiva1948 and @gamecorpstudio! I just hope my tips don't cause your computers to explode.....
B
11
S
2
Posts: 19
Reputation: 676

» Fri May 29, 2015 8:50 pm

@terransage

To reduce the json file size, you can remove the whitespace. this can considerably shrink the filesize.

Morph Animations use a lot of memory but their performance is better since the GPU animates them very efficiently through shaders. Because they use a lot of memory however they tend to work better for models with fewer vertices. There is no simple way to make something like a carried weapon through hierarchies using morph targets because they don't have any bones (and this is in fact why they are faster, if they had bones they'd be much slower) Some old games that use morph targets work around this by saving extra information about the position/orientation of a hand for every frame of every animaton, and then placing the object there. This is basically something like image points in C2. You could attempt something like this but it would have to be coded in events in C2 as a custom solution.

The frame naming doesn't matter if it starts at 0000 or not, Q3D just reads the frames in the order they're placed in the file, sequentially, and trims any numeric characters off to find the "animation name". I tried my best to make it simple but the current exporters for three.js are still in development.
B
55
S
7
G
6
Posts: 1,949
Reputation: 7,693

» Sat May 30, 2015 7:40 am

Thanks, @QuaziGNRLnose. I'm glad to hear that the animation frames don't have to be re-numbered. My copy-and-paste way of adding new animations to a .json file works, but it takes a lot of patience. I guess putting all of the animations in a single timeline is the way to go,

As for the characters carrying things, I considered the idea of animating an object to follow the character's hand, but I wasn't sure how to pull that off, especially with the 2D editor.

I also thought about creating cloned versions of the same character with objects "modeled" into their hands, and somehow switch the characters at the moment the original character reaches for and touches something. The pose, position and angle that the original character is in at the end of the reaching animation would have to exactly match the starting pose, position and angle of the "spawned," object-carrying character. Or that character could already be there, but invisible. I've done something like that in Unity, instantiating model clones and destroying or hiding the original. Of course, the object-carrying model would have to be re-rigged and re-morphed, with the model and the object it's carrying joined as one. (Sorry, I'm kind of thinking out loud....)

Edit: I think I've got the "character-carrying-things" that I mentioned in the last paragraph figured out. I discovered that it's easy to "model" an object into an already morph-animated model, export and import that model into Q3D without having to redo the animations, and then use the Construct 2 Event Sheets to seamlessly replace the original model reaching for an object. Once I've got it worked out 100%, I'll add it to the tutorial above.
B
11
S
2
Posts: 19
Reputation: 676

» Mon Jun 01, 2015 8:48 pm

terransage wrote:Edit: I think I've got the "character-carrying-things" that I mentioned in the last paragraph figured out. I discovered that it's easy to "model" an object into an already morph-animated model, export and import that model into Q3D without having to redo the animations, and then use the Construct 2 Event Sheets to seamlessly replace the original model reaching for an object. Once I've got it worked out 100%, I'll add it to the tutorial above.

wait so we can use the monster morph animation tutorial, characters that is already from q3d, just swap the model ? and keep the same animation of movement!? i mean bones or what contains?! just change the shape of model basically?! that will be so awesome, cause it solves most of problems, just wold need to have a same size character, and then bam new characters every time!
B
54
S
14
G
64
Posts: 1,252
Reputation: 39,500

» Tue Jun 02, 2015 1:58 am

@gamecorpstudio wrote:
wait so we can use the monster morph animation tutorial, characters that is already from q3d, just swap the model ? and keep the same animation of movement!? i mean bones or what contains?! just change the shape of model basically?! that will be so awesome, cause it solves most of problems, just wold need to have a same size character, and then bam new characters every time!

Well, sort of. I think you could do what you're thinking, as long as you use the same rigged model as the base for all of the morph-animated characters. But you would have to use the same number of vertices--just shift them around while still having them attached to the same bones containing the same rigged animations that you would share between different versions of that model. I've never altered a model after rigging it, so I'm not even sure how that would be done (although I have added objects to the model after it has been morph-animated; and that's information that I'm going to put in the tutorial above). For re-shaping a rigged character, I think you would either have to use Shape Keys to shift the vertices around, or you could detach the bones from the vertices, shift the vertices around to create the new character, add a new material/texture, then re-parent the model to the bones, creating vertex groups, etc. That way the character would look different, but it would be animated the same.

The process I was talking about in my "edit" above is a way to resolve the problem of the morph-animated character carrying things in his hands, since an object can't be parented to a hand bone (because there aren't any bones). To test whether or not that could be done, I went back to my morph-animated character in Blender, added a cylinder to the scene, re-sized, rotated and positioned it in the character's hand, selected first the object and then the character, shifted to Edit Mode, selected three adjacent vertices in the character's hand--close to the cylinder--and pressed Control+P to parent the object to the vertices. Then I played the walk cycle and, sure enough, the cylinder moved (and rotated correctly) with the hand, as if he was really carrying it. At first I made the mistake of parenting the cylinder to a single vertex. It followed the hand when the character walked, but it refused to rotate. Parenting to three vertices "locks" the object into place, correcting the rotation problem.

The only thing I haven't tested, yet, is whether or not I can now join the object to the model, to make them one model--and still have the morph animation work the same way for the whole model. I just realized that (*gulp*). It seems that hierarchies that aren't armatures can't be exported in .json files. I forgot about that.
After I'm done writing this, I'll have to experiment with that. And I might have to put the tutorial on hold....

As for "swapping" out the two versions of the character model, I haven't yet tested it with the model carrying the cylinder. But I did swap between the original model and a duplicate, triggering it with a key press. I was pretty surprised by how seamless it was! I had to use a few conditions/actions in the Event Sheet, juggle a few Euler angles to get the new model to face in exactly the same direction as the first. All of that, I'll mention in my edit to the tutorial--exactly what actions I used.

You mentioned a character that is already in Q3D. Are you talking about the monsters created by @QuaziGNRLnose? If you wanted to swap bodies with one of those creatures, you'd have to match one of their start or end poses as closely as possible, have one character end its animation cycle in a pose that begins the animation cycle of the second character, in order to make it look as natural as possible. In Unity, when a character dies, you can swap it out for a "ragdoll" version of the same character, matching each of its bones--position and rotation--with the bones of the destroyed character. Are you thinking of taking one of those Q3D monsters into Blender and altering its shape/texture? Because they're morph-animated (I think), you would have to capture their alterations with Shape Keys in every pose of the animation. Or maybe I'm not understanding your question?

Anyway, I realized I have a lot more experimenting to do before I can add to the tutorial....
B
11
S
2
Posts: 19
Reputation: 676

» Tue Jun 02, 2015 4:13 am

terransage wrote:You mentioned a character that is already in Q3D. Are you talking about the monsters created by @QuaziGNRLnose? If you wanted to swap bodies with one of those creatures, you'd have to match one of their start or end poses as closely as possible, have one character end its animation cycle in a pose that begins the animation cycle of the second character, in order to make it look as natural as possible. In Unity, when a character dies, you can swap it out for a "ragdoll" version of the same character, matching each of its bones--position and rotation--with the bones of the destroyed character. Are you thinking of taking one of those Q3D monsters into Blender and altering its shape/texture? Because they're morph-animated (I think), you would have to capture their alterations with Shape Keys in every pose of the animation. Or maybe I'm not understanding your question?

Anyway, I realized I have a lot more experimenting to do before I can add to the tutorial....

yes i was thinking of the monsters from the animation morphing tutorial example, they have already the animation morphing and all the bones working, they kinda move slow but that's not the problem, the thing is i want to change the model itself to make it look like a human/or something else but keep the bones, and animation! i think its possible and easy to be done il try with blender tonight, after i manage to load the json in blender
the other solution i was thinking to export an character and load the animation from the monster json to the new obj ! not sure how that will work ! but il give it a shot and see what happens!

i tried placing one time a new obj into the same q3dmodel but then, the new obj dident had the animation on it, so i want to keep old model, add new model and on start of layout just load animation and bones from existing model i guess if there is an option to it! this way i wont sit there for hours picking bones and vertices xaxa but im not sure if is possible! il test it and post here!
B
54
S
14
G
64
Posts: 1,252
Reputation: 39,500

PreviousNext