Jump to content

Modify a part of a mesh linked to a skeleton with an another mesh in Babylon.js ?


Zino54220
 Share

Recommended Posts

Hi guys !

 

On the advice of Gwenael, I write this topic for my question...

 

As the title say it, how can I modify a part or many parts of a mesh imported in Babylon.js linked to a skeleton with an another mesh without bone?

 

An example ? Ok ... :)

 

I have this mesh in Blender v2.67 :

 

post-6162-0-79527600-1389984250.gif

 

 

You can see the mesh linked to a skeleton composed of 3 bones... As you see it, the mesh moves with the skeleton... until this, all is ok ^^ !

 

Now an another mesh like this for example :

 

post-6162-0-50477100-1389984250.gif

 

 

A basic mesh without animation, nothing to say...

 

So in my Babylon scene, I have this... (after import of my 2 files.babylon of course)

 

post-6162-0-26697900-1389984250.gif

 

 

And the result that I would like will be anything like this :

 

post-6162-0-37779700-1389984249.gif

 

 

I saw in tutorial that a skeleton have a bone array and a bone can "access" to his mesh linked...Gwenael talks me about "submeshes" too... but a example made by a competent person like ProfessorF, Gwenael or DeltaKosh will be more evident to understand I think : )

 

 

Thanks you for your help.

 

 

P.S :

 

If anyone want my Blender or Babylon files to go quickly in this research, I will send them.

 

 

Link to comment
Share on other sites

This should be possible.

Each cube has an identifier. The one to replaced shalt be rendered invisible with setEnabled() for example. Then either you attached your sphere to the os (more lasts to retrieve)
either you attached your sphere to your cube rendered invisible, which should be easier: sphere.parent = cube.

Your cube is already attached to the os, by attaching the sphere to cube invisible the sphere will follow movements of the os.

If you want to after detach the sphere, replace the cube in visible and make a dispose() on the sphere.

Good luck

Link to comment
Share on other sites

Yes that's right... In fact, I would like a way to identify the different parts of a mesh linked with a skeleton, made with Blender and imported in Babylon.js....

 

Do the vertex group make this ? If it's right, how can I use them in Babylon.js ?

 

The vertex group and submeshes are the same things ?

 

I see the "algorithm" of Dad72, but in Blender, I only have one name of mesh because the 3 cube are joined with CTRL + J and i dont know how get the ID of the mesh's parts... (It's not the name of mesh right...?)

 

In Babylon.js, after imported, I have my : var objWithSkel.

 

Can I access to my part of mesh with : objWithSkel.Mesh(name, scene); ? (or "name" will be the name of my vertex group that I want modify...)

 

Can I modify the mesh simply with :  objWithSkel.Mesh(name, scene) = objWithoutSkel; ?

 

Or I should pass by :  objWithSkel.Skeleton(name, id, scene).Bone(name, skeleton, parentBone, matrix).Mesh(name, scene) = objWithoutSkel; ?

 

For the second way, is compulsory to precise all the parameters ?

 

 

 

I will try all of this things this week and I will inform you...

 

 

 

Thanks you for your attention :)

 

P.S :

 

Special thanks to ProfessorF ^^ for his personal commitment

Link to comment
Share on other sites

So, a little point...

 

I have tried these codes's lines :

 

("Bone.001" is the bone linked to the mesh that I want modify with "Sphere"."Bone" is the name of the Bone parent of "Bone.001".

These name are the name made in Blender.)

 

//testCube.Bone("Bone.001", skeletons[0], "Bone", testCube.Matrix()).Mesh = testSphere.Mesh("Sphere", scene);
   

2°    
//testCube.Skeleton.Mesh("Bone.001", scene) = testSphere.Mesh("Sphere", scene);

 

3°       
//var objAChanger = scene.getMeshByName("Bone.001");

//objAChanger = testSphere.getMesh();

 

4°       
//testCube.Skeleton[0].Mesh("Bone.001", scene) = testSphere.getMesh();
 

//testCube.Skeleton.Mesh("Bone.001", scene) = testSphere.getMesh();

 

 

The lines 2°, 4° and 5° give me a white screen. The others give no changes.

 

Unfortunately, there is not a method like :

 

...Bone.("Bone.001").setMesh(testSphere.getMesh());   :wacko:

 

I will continu my research.

Link to comment
Share on other sites

Why not search for the name of the box to replace. Then make the box invisible and attach (.parent) the sphere to this cube. What should be simpler and more direct and resoudras your problem. your sphere attached to the cube which is invisible will take into account the movement of os.

 

in Frensh:

Pourquoi ne pas rechercher le nom du cube à remplacer. puis le rendre invisible et attacher la sphère à ce cube. Ce qui devrais être plus simple et plus direct et résoudras votre probleme. votre sphère attaché au cube qui est invisible prendra en compte les mouvement des os.

Link to comment
Share on other sites

This algo is good for me but i don't know how do this...

 

Do I must use the obj "scene" or the obj "testCube"  to get the obj cube to change ?

 

I see an algo like thise :

 

1° Get the obj cube to change thanks to the name's bones (or name's group vertex) linked

2° Set the property visible at false to the object cube

3° Link the sphere to the object cube

 

 

But when I want to do this (like in my examples...) I don't arrive to make the first step...

 

I'll try tonight this code to make the step 1° :

 

var cubeToChange = testCube.Bone("Bone.001", skeletons[0], "Bone", testCube.Matrix()).Mesh.GetMesh();

 

After this step, it will be easier to make the step 2° and for the step 3°, I don't know...

 

 

I'll inform you in every case...

 

 

Thanks you very much Dad72 for your reply!  :) 

Link to comment
Share on other sites

I tried your code's lines and unfortunately, nothing happen...

 

In my opinion, it is because the mesh made in blender is composed by many mesh at the begining but join in one mesh which call "Cube.001" in my case.

 

So I no longer have access to the different meshes of the beginning.

 

I only know the name of my vertex groups made automaticaly by Blender with the option "With Automatic Wheight" (their name is the same that the name of their bone linked...)

 

Here, an example of my code with the Dad72's lines...

//Test d'un import d'un objet.babylon de blenderBABYLON.SceneLoader.ImportMesh("Cube.001", "Mesh/", "cube.babylon", scene,function (newMeshes,particleSystems, skeletons){        setupCube(testCube,newMeshes,skeletons);                        scene.beginAnimation(skeletons[0], 0, 51, true, 1.0);            //Test d'un 2éme import d'un objet.babylon de blender        BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene,        function (newMeshes2)        {            setupPosition(testSphere,newMeshes2,5,2,10);                    //Here the Dad72 code's lines...            var objectFind = scene.getMeshByName("Bone.004") ;  // Find the cube by name, here it's the name of the group vertex...            testSphere.parent = objectFind.getMesh();           // Attach sphere in cube            objectFind.isVisible = false;                       //Cube not visible                });       });

Here the result in a .gif...

 

post-6162-0-47187900-1390601971.gif

 

So how can I get the name of my interested mesh if the name of the vertex group is not correct ?

 

Do you have an idea gentlemen ? :)

Link to comment
Share on other sites

You can probably achieve a objects that composed your models.

 

newMeshes[0] = empty

newMeshes[1]

newMeshes[2]

...

        BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene, function (newMeshes)        {            setupPosition(testSphere, newMeshes, 5, 2, 10);                      var objectFind = newMeshes[2] ;             testSphere.parent = objectFind;             objectFind.isVisible = false;                });

It would be nice if you could put your code between code tag, please. The code is more enjoyable to read

Link to comment
Share on other sites

I try your solution but no more effects...

 

BABYLON.SceneLoader.ImportMesh("Cube.001", "Mesh/", "cube.babylon", scene,    function (newMeshes,particleSystems, skeletons)    {        setupRobot(testRobot,newMeshes,skeletons);                        scene.beginAnimation(skeletons[0], 0, 51, true, 1.0);            //Test d'import d'un objet.babylon de blender        BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene,        function (newMeshes2)        {            setupPosition(testSphere,newMeshes2,5,2,10);                    var objectFind = newMeshes[2] ; // I tried newMeshes[1] and newMeshes[2]                testSphere.parent = objectFind; // Attach sphere in cube                objectFind.isVisible = false; //Cube not visible                });            });
Link to comment
Share on other sites

I tried this code's lines but always without effect...

BABYLON.SceneLoader.ImportMesh("Cube.001", "Mesh/", "cube.babylon", scene,    function (newMeshes,particleSystems, skeletons)    {        setupRobot(testRobot,newMeshes,skeletons);        scene.beginAnimation(skeletons[0], 0, 51, true, 1.0);        //Test d'import d'un objet.babylon de blender        BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene,        function (newMeshes2)        {            //objectFind = new BABYLON.Mesh("NouveauMesh",scene);            setupPosition(testSphere,newMeshes2,5,2,10);            //objectFind = scene.getMeshByName("Group.003");    //Name of a object group that i add in blender            objectFind = scene.getMeshByName("Bone.001");       //Name of the bone of my interested mesh            //objectFind = newMeshes[2].getMesh();              //Try to get the mesh by the mesh array            testSphere.parent = objectFind.getMesh();           // Attach sphere in cube            objectFind.isVisible = false;                       //Cube not visible                });    });

Thanks to the firefox debuger, I saw that my obj "objectFind" is null...

 

post-6162-0-42065900-1390609337.gif

 

 

Of course, the result is the same with getMeshByName("Group.003"), getMeshByName("Bone.001") and newMeshes[2].getMesh();...

 

But I don't know how do this now...

 

I will continu my research... I'm a keen programmer ^_^

Link to comment
Share on other sites

I have a function for you which enables you to attach an object has a os

function attache(obj, ske, boneName)            {                var matricesWeights = new Array();                var floatIndices = new Array();                var boneIndice = -1;                                for (var i = 0; i < ske.bones.length; i++) {                    if (ske.bones[i].name == boneName) {                        boneIndice=i;                        break;                    }                }                if (boneIndice == -1) { return; }                                for (var ii = 0; ii < obj._totalVertices; ii++) {                    matricesWeights[ii*4+0] = 1.0;                    matricesWeights[ii*4+1] = 0.0;                    matricesWeights[ii*4+2] = 0.0;                    matricesWeights[ii*4+3] = 0.0;                    floatIndices[ii*4+0] = boneIndice;                    floatIndices[ii*4+1] = boneIndice;                    floatIndices[ii*4+2] = boneIndice;                    floatIndices[ii*4+3] = boneIndice;                }                                obj.skeleton = ske;                obj.setVerticesData(matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind, false);                obj.setVerticesData(floatIndices, BABYLON.VertexBuffer.MatricesIndicesKind, false);            }

Use:

BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene, function (newMeshes, particleSystems, skeletons){       // newMeshes[0] est votre modèle à attacher       // skeletons[0] est tout le squelette de votre modèle       // Bone.001 doit être le nom de votre os ou attacher votre modèle.            attache(newMeshes[0], skeletons[0], "Bone.001"); });

You still have more to find to hide the box or the sphere is attach. can be in changing of materials, by making it transparent.

newMeshes[2].material = yourMaterial;

Made a loop to browse through the table "newmeshes" for and find your cube. You can view the results in a console.log() to see what was happening.

 

Have all this, you should solve your problem.

Link to comment
Share on other sites

It smells good  dad72 :) ! It's not perfect but it's better...

 

The second mesh is attached to the first mesh. You can see that the animation makes move all of the meshes in the scene.

 

Here a .gif of the result :

 

post-6162-0-27288600-1390661657.gif

 

 

But the animation of the sphere is reversed bizarely and this position is always fix by my "setupPosition" method...

 

If I put off this method, the sphere comes to the originals X, Y and Z position defined in Blender...

 

Here my code if you want verif that I don't made a mistake :

 

BABYLON.SceneLoader.ImportMesh("Cube.001", "Mesh/", "cube.babylon", scene,function (newMeshes,particleSystems, skeletons){     setupRobot(testRobot,newMeshes,skeletons);                     //Test d'import d'un objet.babylon de blender     BABYLON.SceneLoader.ImportMesh("Sphere", "Mesh/", "sphere.babylon", scene,     function (newMeshes2)     {            //newMeshes2[0] est mon modèle à attacher            //skeletons[0] est tout le squelette de mon premier modèle            //"Bone.001" est le nom de mon os ou attacher mon modèle.                            monterObjSurSkel(newMeshes2[0], skeletons[0], "Bone.001");                        setupPosition(testSphere,newMeshes2,5,2,10);                        scene.beginAnimation(skeletons[0], 0, 51, true, 1.0);                        //objectFind = new BABYLON.Mesh("NouveauMesh",scene);                        //objectFind = scene.getMeshByName("Group.003");    //Name of a object group that i add in blender            //objectFind = scene.getMeshByName("Bone.001");       //Name of the bone of my interested mesh            //objectFind = newMeshes[2].getMesh();              //Try to get the mesh by the mesh array                //testSphere.parent = objectFind.getMesh();           // Attach sphere in cube                //objectFind.isVisible = false;                       //Cube not visible              });});

 

I see the algo to modify this coordinates but if I don't arrive to get my mesh that I would change by the complete mesh "Cube.001", it will be hard to get his coordinates...

 

 

 

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...