Problem to import from Blender with GLB format (MergeMeshes)

Hi,

I created a model on Blender (2.79b) with a short animation to test.
My model is scaled at 1.00 and all bones at the first frame were reseted (ALT G/S/R).
This model is for a game, so, i need to clone mesh/materials and animation for each player.

Blender 2.79b file

I use BabylonJS v4.1.0

First, i exported my model with the “Babylon 5.6.4” plugin. The animation is not correct.

Then, i exported in GLB format (v2). The animation is fine but instead of having 1 mesh, there are a lot of meshes ( root and 10 primitives).
I don’t really see the advantage of having a mesh per material and especially that the .babylon export creates a single mesh.:thinking:

I need to work with only 1 mesh so i try to merge them into 1 mesh but it gives an error:

BABYLON.SceneLoader.ImportMesh("", path, "ChickenV2.glb", scene, function (newMeshes, particleSystems, newSkeletons) {
  var skeleton=newSkeletons[0];
  var newMesh=BABYLON.Mesh.MergeMeshes(newMeshes);
  newMesh.skeleton=skeleton;
  var idleAnim = scene.beginAnimation(skeleton, 0, 50,  true);
});
Error: Positions are required
    at e._validate (babylon.js:16)
    at e.merge (babylon.js:16)
    at Function.t.MergeMeshes (babylon.js:16)
    at charactere2:252
    at p (babylon.js:16)
    at babylon.js:16

If i set “multiMultiMaterials” option, i get an other type of error.
var newMesh=BABYLON.Mesh.MergeMeshes(newMeshes, undefined, undefined, undefined, undefined, true);

TypeError: Cannot read property 'length' of undefined
    at Function.t.MergeMeshes (babylon.js:16)
    at charactere2:254
    at p (babylon.js:16)
    at babylon.js:16

How to solve my problem? :slightly_smiling_face:

If the meshes are splitted at different levels in the tree with different animations or materials there might just not be mergeable.

Now about why it is splitted, lets summon @JCPalmer our blender master :slight_smile:

Also from what I remember I think you should be using 2.8 of blender with the latest exporter version ?

I really don’t like the new version of Blender but i tested with Blender 2.82a and i have the same problem.

I edited my first message for adding the blender file and a screenshot.

1 Like

I am not a good contact for GLB, even on Blender. I was aware that it did not manifest single meshes with multi-materials, but did not even know there was a tree.

There is only one mesh according to the picture, but I did bring it up in 2.83 & see 10 materials for the mesh, so must be being broken down by that.

Exported from Blender 2.83.0 using exporter 6.4.1 (Blender 2.79 & anything older than exporter 6.0 will not be looked at by me). The log file for the export is:

Exporter version: 6.4.1, Blender version: 2.83.0
========= Conversion from Blender to Babylon.js =========
	Scene settings used :
		Inline textures     :  false
		Material Type       :  PBR
		Positions Precision :  4
		Normals Precision   :  3
		UVs Precision       :  3
		Vert Color Precision:  3
		Mat Weight Precision:  2
		Keep Z-up r-handed  :  no
		Texture directory   :  #######################
	Python World class constructor completed
	processing begun of skeleton:  Armature, id:  0
		processing begun of bone:  body, index:  0
		processing begun of bone:  head, index:  1
		processing begun of bone:  wing.L, index:  2
		processing begun of bone:  wing.R, index:  3
		processing begun of bone:  foot.L, index:  4
		processing begun of bone:  foot.R, index:  5
		processing begun of bone:  tail, index:  6
		processing action ArmatureAction:  in[0 - 50], out[0 - 50]
	processing begun of mesh:  Chicken
		processing begun of material:  head
		processing begun of material:  tail
		processing begun of material:  beak
		processing begun of material:  eye
		processing begun of material:  pupil
		processing begun of material:  body
		processing begun of material:  wing
		processing begun of material:  leg
		processing begun of material:  crest
		processing begun of material:  chest
		processing begun of multimaterial:  ChickenV2.Multimaterial#0
		num positions      :  746
		num normals        :  746
		num tangents       :  0
		num uvs            :  0
		num uvs2           :  0
		num colors         :  0
		num triangles      :  1348
		Skeleton stats:  
			Total Influencers:  746
			Avg # of influencers per vertex:  1
			Highest # of influencers observed:  1, num vertices with this:  746
			exported as 1 influencers
			num skeletonWeights and skeletonIndices:  2984
	processing begun of camera (UniversalCamera):  Camera
	processing begun of light (POINT):  Lamp
========= Writing of JSON file started =========
	writing mesh:  Chicken
========= Writing of JSON file completed =========
========= end of processing =========
elapsed time:  0 min, 0.2201 secs

It looked ok from the sandbox, though you can not run skeletal animations from sandbox. I am not writing the code to do it from html.

Did notice that although the skeleton did not have any transforms, the mesh did show a location other than 0,0,0. You might try applying that transform as well.

1 Like

@JCPalmer: Thanks for answer. But i didn’t apply any transforms on the mesh.

I would rather use the .babylon format than .glb too. But for the moment, neither of the two formats gives me satisfaction.

What I did is quite simple and i don’t understand why i have problems. :disappointed_relieved:

The skeleton is parented with ‘Empty groups’ to my group of vertex.

I took care to have a scale=1 and to reset all the bones (G/R/S) at the first frame.


Are there other checks / manipulations to perform before exporting? :face_with_monocle:

Could the problem be due to the fact that i’m using not “Connected” bones?

Playground: Babylon.js Playground

Blender animation:
ChickenV2
Playground animation:
ChickenV2-sandbox


Ops, i deleted by mistake the blender file and i can’t edit my first message. I put it again here:
Blender file (2.79)

Well, on Blender, if i apply a reset (ALT G/S/G) on the mesh at the first frame, the animation is fine with Babylon. By cons, on Blender, just after the export, the mesh is automatically moved in other spot. Weird.