Jump to content

How to know on which mesh one skeleton is linked?


snot224
 Share

Recommended Posts

Hi all,

i'm back from a long time, and I update from v2.3 to v2.4 and my code don't work anymore ...
I just want to know here how to identify and be sure to link correct skeleton with the correct mesh ?


Here the example to explain my problem :

In 3DSMax, I create an house with 6 objects, on this house I put bones (55 bones) and somes animations (After export it represent 6 skeletons).

Now, I would like to import them in Babylon, BUT when I tryed to start animation, black screen appear, and this console log :
TypeError: Argument 3 is not valid for any of the 3-argument overloads of WebGLRenderingContext.uniformMatrix4fv.[En savoir plus]


Here my code, that worked fine in v2.3 but don't work anymore in v2.4, and same kind of code work fine with less complexe modele (1 meshe for 1 skeleton)

// code d'importation et de sauvegarde
BABYLON.SceneLoader.ImportMesh("",dossier,fichier,scene,function(mesh, particleSystems, skeletons)
{
        controleurObjet.tabModele[name].mesh                = [];
        controleurObjet.tabModele[name].bone                = [];
        var i;
      
        // On rajoute uniquement les éléments visible (pas les structures)          
        for (i=0;i<mesh.length;i++)
        {
             if(mesh[i].isVisible)
             {
                 controleurObjet.tabModele[name].mesh.push(mesh[i]);
                 // On marque le modèle de départ
                 mesh[i].isVisible                  = false;
             }
         }
              
         for (i=0; i<skeletons.length;i++)
         {
             controleurObjet.tabModele[name].bone.push(skeletons[i]);
         }
}


// clonage
for (i=0 ; i<controleurObjet.tabModele[this.type].mesh.length ; i++)
{
    this.mesh[i] = controleurObjet.tabModele[this.type].mesh[i].clone(this.name+'_'+i);
    this.parametrage(i);
}
	
for (i=0 ; i<controleurObjet.tabModele[this.type].bone.length ; i++)
{
    this.mesh[i].skeleton = controleurObjet.tabModele[this.type].bone[i].clone(this.name+'_'+i);
}


// Start animation de construction
for (var i=0;i<this.mesh.length;i++)
{
	if (this.mesh[i].skeleton)
	{
		scene.beginAnimation(this.mesh[i].skeleton,0,10, false, 1);
	}
}


I know that the problem comes because I only keep visible meshes, but If I delete the line "if(mesh.isVisible)", no animation working, and If I keep this line, error above apear ..

Someone could explain to me how to know on which mesh I could link correct skeleton ?

 

Link to comment
Share on other sites

Not sure if 3ds exporter works like blender one, but I found out that when I import meshes with an armature ( from a blender exported babylon file ) , the skeleton is automaticaly applied to the mesh that are set to use the armature defined in my blender scene.

You should check if it's the same by doing

console.log(mesh[i].skeleton)

in your very first for...loop , if it's the case then you can do all the cloning without keeping skeletons in a separate array.

Link to comment
Share on other sites

I found the error, but it look like very strange ...

in the function "parametrage" that I call in the first part (here the code)

Batiment.prototype.parametrage = function(id)
{		
	this.mesh[id].scaling 		= new BABYLON.Vector3(0.07,0.07,0.07);
	
	// Paramètre
	this.mesh[id].checkCollisions	= true;
	this.mesh[id].receiveShadows	= true;
	this.mesh[id].visibility	= 1;
	
	this.mesh[id].isVisible		= true;
	
		
	shadowGenerator.getShadowMap().renderList.push(this.mesh[id]);
};

when I comment the line of the shadowGenerator, no more error, animations works. but, no more shadow for the meshs...

I just update to v2.5 and same things.

Here the error log :
TypeError: Argument 3 is not valid for any of the 3-argument overloads of WebGLRenderingContext.uniformMatrix4fv.[En savoir plus]  babylon-2.5.js:5:4857
    s.prototype.setMatrices babylon-2.5.js:5:4857
    t.prototype.setMatrices babylon-2.5.js:15:26904
    t/a babylon-2.5.js:7:29664
    t/this._shadowMap.customRenderFunction babylon-2.5.js:7:30065
    t.prototype.render babylon-2.5.js:10:29895
    t.prototype.render babylon-2.5.js:10:27206
    i.prototype.renderToTarget babylon-2.5.js:15:3280
    i.prototype.render babylon-2.5.js:15:2586
    i.prototype._renderForCamera babylon-2.5.js:12:3526
    i.prototype._processSubCameras babylon-2.5.js:12:5901
    i.prototype.render babylon-2.5.js:12:10034
    creerJeu/</<  nko.js:265:5
    s.prototype._renderLoop babylon-2.5.js:4:23094
    bound  self-hosted

The strangest thing is that for all over objects (using exactly the same shadowGenerator), shadow works fine.

Link to comment
Share on other sites

Here how I declare the ShadowGenerator

// ********************************************************
// Shadow
// ********************************************************
shadowGenerator 				= new BABYLON.ShadowGenerator(4096,shadowLight);
shadowGenerator.useVarianceShadowMap 	        = true;
shadowGenerator.usePoissonSampling 		= true;
shadowGenerator._darkness		        = -0.8;
shadowGenerator.bias 				= 0.0001;
shadowGenerator.getShadowMap().anisotropicFilteringLevel = __CONST_ANISOTROPIC__;

 

Link to comment
Share on other sites

Try that : Make sure that your scene object is accessible anywhere in your code, then in your function

Batiment.prototype.parametrage

Replace :

shadowGenerator.getShadowMap().renderList.push(this.mesh[id]);

By :

yourSceneObject.executeWhenReady(function() { shadowGenerator.getShadowMap().renderList.push(this.mesh[id]); });

You should do this for anything that requires the mesh to be already in the render loop ( particles emitter , octree etc.. ) , I had the issue once and it's very hard to reproduce because it depends of how fast your browser performs.

Link to comment
Share on other sites

2 hours ago, xaero59 said:

Try that : Make sure that your scene object is accessible anywhere in your code, then in your function


Batiment.prototype.parametrage

Replace :


shadowGenerator.getShadowMap().renderList.push(this.mesh[id]);

By :

yourSceneObject.executeWhenReady(function() { shadowGenerator.getShadowMap().renderList.push(this.mesh[id]); });

You should do this for anything that requires the mesh to be already in the render loop ( particles emitter , octree etc.. ) , I had the issue once and it's very hard to reproduce because it depends of how fast your browser performs.

YES, thanks so mush ! It is the good solution !

Thanks man :)

I understand now why sometime it worked and sometime no, and why when I delete some object it works (because it take less time to be ready !

Thanks again, I could take the next step ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...