Hi,
I know that there are converters for FBX to GLTF which is the primary file-format that is used by BabylonJS.
But I have two .FBX files one has mesh data and another has the animations. How should I create a GLTF from them and what are the best practices for exporting the model which has multiple animations form tools like 3Ds Max or Maya.
I am enclosing the model in this post. Please suggest
Animation and mesh are on this link - https://drive.google.com/open?id=15YOlG2pWZPri-eB3hd_CX2I0abeayS7F
There’s multiple paths for this workflow:
You can either import the .FBX into Maya or 3dsMax and use our export tools for those programs:
https://doc.babylonjs.com/resources/maya
https://doc.babylonjs.com/resources/3dsmax
You can also import into Blender, and use its glTF exporter as well.
Or you can use the popular FBX2glTF tool, but I can’t vouch for its reliability, I do not use it too often:
1 Like
This is a glTF question more than a Babylon.js question and is probably better asked on the glTF GitHub, as this is an animation retargeting question. @PatrickRyan and I have discussed this at length a few times before. I don’t really have a good answer for you unfortunately. Basically, the source mesh glTF needs unique identifiers for each of the possible animation targets and each animation glTF would need a glTF extension (or perhaps glTF extras) to specific the unique identifiers of the source mesh. Then extend the Babylon’s glTF loader to support this.
This isn’t trivial to implement or standardize. If you want to try to implement it, I can try to help you out. If you want to try to standardize the way, we should continue the discussion on the glTF GitHub.
2 Likes
@nipundavid, I would add to what @bghgary said with the idea that it really depends on what you are doing with the files and that can alter the best practices for it. If you truly need only one glTF file because maybe you are sending the file to someone to open in a viewer, then Gary is right that this is more of a topic for the glTF GitHub. However, if you are here because you are using the files in a Babylon scene, I would suggest you not assemble them into one file load.
If you were to load both the mesh file and any animation files you need into your scene, you can access the animation group on the animation files and clone it to play on your mesh file so long as they share the same bone hierarchy. This method offers several benefits.
-
If you keep your mesh file separate from your animation files, you can have several people working on the individual files at once without stomping any changes to the binaries. This means one person can be animating a walk while another animates a jump. Or it can mean one person animates the rig while another works on the character meshes.
-
Separating your mesh file from your animation files means that if you have several characters that share animations like a walk cycle, you can have one loaded file for the walk animation and clone it to every mesh who needs it. This saves you on load time as you don’t store the keys for the walk cycle in each mesh who needs it, only one master that gets cloned for everyone.
-
Authoring one file per animation makes edits easier. If you need to go in an tweak keys on an animation, you can open and update just the one you need to alter, leaving the rest alone. This can limit bugs in your animations as only one animation was touched and you don’t have to go back and recheck every animation. This also leads to smaller files which tax your DCC tool less.
-
Adding animations becomes much easier. If you don’t store all of your animations in your mesh file, you can add animations as you want and then hook them up in code as needed. There’s no reason to touch any of your legacy animations.
-
Adding characters becomes much easier. Keeping your meshes separate means you can rig a new mesh to your base skeleton any time you want and add it to the scene with access to all of your animations. This is the best way to keep your scene flexible and allow you to make updates quickly.
To sum up, if you have a specific need to retarget your animations into one glTF file, the only way right now would be to manually combine the data in your DCC tool until we come up with a way to retarget across glTFs at load. Otherwise, if you are using Babylon to create your scene, I would definitely leave them as separate files and take the hit on multiple file loads versus one larger file with all mesh and keys contained in it to get the flexibility of being able to expand your scene easily. Let me know if you have more questions about any of the things I mentioned.
3 Likes
Hi @bghgary and @PatrickRyan , so to begin with, I have a unity3D background. And I know that GLTF is different ball game as it is not just model it has a lot more in it. So let me share my use-case with you.
- User can see a load a model - lets say of a human
- User can see the animations that he can apply on this model - jump, walk, idle etc. which are part of this GLTF file
- He can load more animation from the web and apply them on the loaded mesh in step 1 - given that bone hierarchy is mapped
So are you saying this is not possible at all and I have to pack the all animations in the GLTF file and ship it and I have to raise this on Khronos GLTF feature tracker or is there any way around.
I am also enclosing the screenshot - so the male_mesh.fbx is the main mesh and rest are the animations files which I want to send them from my back-end services on request from the client app.
I am able to convert the models into GLTF format and I can even load them, but how to apply each animation is where I am stuck as the animations are not the part of the mesh gltf file they are loaded externally. I hope I am not asking a lame question
regards,
Nipun David
Update -
So I was looking into Khronos github and I found someone tried what I am doing i.e. load GLTF animation into another GLTF file. But someone said that it is not possible and the guy who had asked this question ended by embedding all the animation in one GLTF file.
Link - Import Animation .glb files to existing GLTF model? · Issue #450 · KhronosGroup/UnityGLTF · GitHub
however, I can do this same in the sandbox by Babylon. i.e. I loaded a gltf which had the only gltf, then I loaded the animation which I was able to see. Can you please put some light on how the sandbox is achieving this. I am sharing the screen record for a better perspective.
As you can see in the video, sandbox applied the animation gltf on the pre-loaded gltf
@nipundavid, what you are seeing in the sandbox is not a combination of the two glTF files, but rather adding the animation information to the scene. The loaded glTF sits in a scene created by the Babylon.js engine in the sandbox, much like you would see in Unity. When we create the scene with the dropping of a glTF file, we position the camera so that it is normalized with the bounding box of the model (so that the model is completely within the camera frustum).
The scene has all of the features of any other Babylon.js scene, which includes a full inspector where you can make changes to the scene. This includes importing animation like you did in your video. What happens is that the animation information from your selected file is imported into the scene and can be played on a mesh that has a matching skeletal hierarchy. So there is no assemblage of the original glTF file and the animation key data. They both exist in the same scene and can be played, retargeted, replaced, etc.
It is much the same as this example playground loading spinner where I am loading in a glTF file with some animations and a morph target. In the playground, I access the model to get the animation group from the model and add a second animation created in code to the animation group from the glTF and play both at once. In no way did I combine the new animation with the original glTF file and write it out, but instead both assets are loaded into memory where I have full control to do whatever I want with them. The original glTF stays unmodified.
This is what I was referring to in my previous post. You can create a playground (or a stand alone scene on your own web server) to create a scene and load in your mesh and animations separately and retarget as you need. However, if you need to combine the animation data into the same file as the mesh and send them all as one file to someone to view in a separate viewer then you will need to assemble them manually in your DCC tool of choice and export all of it at once.
Let me know if you have more questions about this. Take care!
1 Like
Hey @PatrickRyan, thanks for the information.
I didn’t want to change the file structure, all I wanted was to apply animation from one GLTF file to another.
One of the examples on the playground helped me doing so - Off-Site Tutorials List - Babylon.js Documentation
Thanks for the support and quick replies.
Regards,
Nipun David
2 Likes