MarianG Posted February 11, 2015 Share Posted February 11, 2015 Hi, I'm new to babylonjs js. I worked in ThreeJS before, but babylonjs looks nice. And now a have a litle problem.I have a human character, and a object. My character move to the object and have to take the object in the right hand. He go to the object, the object is aplied to the character skeleton, and he move like skeleton, but in front of character not in his hand. I don't know how to set object position in character hand. If i set object.parent = character, the object disappear. Thanks for help, and sorry my english. Screen: http://prntscr.com/63rz4u Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 11, 2015 Share Posted February 11, 2015 Hello and welcome:) I think that setting object.parent = character but with object.position = BABYLON.Vector3.Zero() Quote Link to comment Share on other sites More sharing options...
gryff Posted February 11, 2015 Share Posted February 11, 2015 He go to the object, the object is aplied to the character skeleton, and he move like skeleton, but in front of character not in his hand. Hi bulisor - welcome to BJS forum. An interesting question. And I don't know that I have an answer - rather just a thought. Can the character have an invisible object - say a simple cube - in his/her right hand, and you make the object to be picked up a child of that invisible object in the right hand? cheers, gryff Quote Link to comment Share on other sites More sharing options...
gryff Posted February 12, 2015 Share Posted February 12, 2015 Bulisor, thinking about the issue some more, the suggestion I made above I do not think will work as the armature is moving the vertices of meshes not the objects origins. It is a very interesting question - one that is important for gaming - changing weapons for example. I wonder if there is a more complex coding answer. cheers, gryff Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 12, 2015 Author Share Posted February 12, 2015 Thanks guys. An interesting question. And I don't know that I have an answer - rather just a thought. Can the character have an invisible object - say a simple cube - in his/her right hand, and you make the object to be picked up a child of that invisible object in the right hand? This is an interesting trick. I will try it, and i will inform you about the rezults. But I think the problem is somewhere here: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._geometry._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(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights, false); obj.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, floatIndices, false);//maybe here must set one more kind of vertices, like positions or, I don;t know}update: Doesn't work with invisible object. I read in diferrent topic that bones need updateMatrix. And I try: object.parent =character; object.position =new BABYLON.Vector3(0,0,0); attache(object,character.skeleton,"joint3"); var matrix = character.getWorldMatrix().clone(); //console.log(matrix); object.skeleton.bones['number_of_affected_bone'].updateMatrix(matrix);Insteed of character, I used a rectangle what is animed, it bending. Screen : http://prntscr.com/644bgx. After I run code above, I obtain: http://prntscr.com/644dhd. Almost done Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 12, 2015 Share Posted February 12, 2015 this error:for (var ii = 0; ii < obj._geometry._totalVertices; ii++) {Fix:for (var i = 0; i < obj.getTotaleVertices(); i++) Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 12, 2015 Author Share Posted February 12, 2015 this error:for (var ii = 0; ii < obj._geometry._totalVertices; ii++) {Fix:for (var i = 0; i < obj.getTotaleVertices(); i++) obj._geometry._totalVertices; and obj.getTotaleVertices(); are the same 3204. That's not a problem Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 12, 2015 Share Posted February 12, 2015 Not only is not the same one no longer exists. I have had this error and this places it work again with this correction. I also use this function and it works. Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 12, 2015 Author Share Posted February 12, 2015 Ok. I fix it. Thanks. But still the same result. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 12, 2015 Share Posted February 12, 2015 I do not think it's because of the function. This function works for me. Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 16, 2015 Author Share Posted February 16, 2015 I think problems are meshes I used:here are objecthttps://www.dropbox.com/s/r4rr4n2he32k911/topor_bone.fbx?dl=0 - .fbxhttps://www.dropbox.com/s/vo1k2rhouldwl2q/toporu.babylon?dl=0 - .babylonand character is Dude, from your example.Thank again. And sorry for insistence. Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 16, 2015 Share Posted February 16, 2015 The Dude object is not centered. the parent object is at 0,0,0 but all child meshes' vertices are not. Their position is, however, 0,0,0 (which can be rather confusing :-) ). The VertexData is simply not centered. Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 18, 2015 Author Share Posted February 18, 2015 The Dude object is not centered. the parent object is at 0,0,0 but all child meshes' vertices are not. Their position is, however, 0,0,0 (which can be rather confusing :-) ). The VertexData is simply not centered. Thanks, that, was the problem. I fix it. Thanks again. Quote Link to comment Share on other sites More sharing options...
MarianG Posted February 18, 2015 Author Share Posted February 18, 2015 One more question. When I select my character, i put a torus under it, and set torus position, character position. It;s ok. But my character is walking on heightmap, and it climb and down.var ray = new BABYLON.Ray(new BABYLON.Vector3(obj.position.x, ground.getBoundingInfo().maximum.y + 1, obj.position.z),new BABYLON.Vector3(0, -1, 0)); var worldInverse = new BABYLON.Matrix(); ground.getWorldMatrix().invertToRef(worldInverse); ray = BABYLON.Ray.Transform(ray, worldInverse); var pickInfo = ground.intersects(ray); obj.lookAt(new BABYLON.Vector3(x1,pickInfo.pickedPoint.y,y1)); if (pickInfo.hit) { obj.position.y = pickInfo.pickedPoint.y; }It works fine, torus follow character, but i want that torus rotate automaticaly according to the ground shape, to be visible totally, not like this http://prntscr.com/66losr. Or it's not ok a torus for this, I may use other method? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.