DylanD Posted June 22, 2018 Share Posted June 22, 2018 Hey again everyone, I have a problem, I import a mesh and when I try to rotate one of the child pieces the piece rotates around the centre of the parent mesh/import instead of its own axis' which is what I meant for it to do. Any idea whats wrong? and or how to fix it? I think it could possible have to do with how I made the object in blender, but I'm not very good with blender, the object is only 4 object in one really, imagine it was a piece of wood with 4 wheels and I want to rotate the wheels around their y axis when instead it rotates around the centres axis. heres the line I use to import the meshes and rotate(the mesh is made of 4 pieces and I just want to rotate the first piece around its own z axis): BABYLON.SceneLoader.ImportMesh("","./models/","myMesh.babylon",this.scene,(meshes)=>{ importFunc(meshes); meshes[0].rotation.z += Math.PI/4; } Here is a playground to illustrate what I want to happen and whats actually happening. The green cube is doing what I want rotating about its own axis', the red cube it what actually happens. Pretend as though both of those cubes are from the same imported mesh. Eg meshes[0], and that the sphere is the centre of the meshes. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 25, 2018 Share Posted June 25, 2018 Hello there is no playground in your post By the way your code is good. The mesh will rotate locally around its center if everything is set up correctly in Blender. Here is a simple example:https://www.babylonjs-playground.com/#MGY5FK DylanD 1 Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 25, 2018 Author Share Posted June 25, 2018 1 hour ago, Deltakosh said: Hello there is no playground in your post By the way your code is good. The mesh will rotate locally around its center if everything is set up correctly in Blender. Here is a simple example:https://www.babylonjs-playground.com/#MGY5FK Hey DeltaKosh, strange I noticed when I first posted it, the post didn't have a playground even though I added it so I added it again, here Is the playground I wanted to show: https://www.babylonjs-playground.com/#LJPRIN#2 It must be something wrong in blender... any good tutorials that you could suggest? Thanks Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 26, 2018 Share Posted June 26, 2018 @DylanD Change the child world space to local space: https://doc.babylonjs.com/features/position,_rotation,_scaling DB DylanD 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 26, 2018 Share Posted June 26, 2018 Pinging @V!nc3r who can probably help with Blender DylanD 1 Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted June 26, 2018 Share Posted June 26, 2018 Do you have a little blend scene to share? Origin position can be modified here: Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 26, 2018 Author Share Posted June 26, 2018 31 minutes ago, dbawel said: @DylanD Chance the child world space to local space: https://doc.babylonjs.com/features/position,_rotation,_scaling DB Hi dbawel, is this what you meant? meshes[0].rotate(BABYLON.Axis.Z, Math.PI / 150, BABYLON.Space.LOCAL); Because it did not work and that what I think I was supposed to do, not entirely sure I. I went through the doc but theres a lot there... Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 26, 2018 Share Posted June 26, 2018 @DylanD I love the devs on this forum (especially @Deltakosh as he truly cares and owns his code), so the us no way to contradict them. However, as an old school dev, I prefer to handle simple tasks such as this in code. For me, I'd export the meshes, parent them in the code, and change their world space. Done... in just a few minutes, and expands your knowledge of handling world space vs. local space as well as hierarchies... which will benefit you greatly. I hope DK or @V!nc3r isn't offended in any way by this, this is not my intent. I love these guys! We all have our opinions, and are always here to help when we can. DB V!nc3r 1 Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 26, 2018 Author Share Posted June 26, 2018 23 minutes ago, V!nc3r said: Do you have a little blend scene to share? Origin position can be modified here: Hello, V!nc3r! hmmmm I can't share the exact one, but I guess I could make an example... except I know nothing doubt blender... well I will try to get a example up.. not sure when it will happen... I will try this Geometry to origin(???/Transform/GeometrytoOrigin) Thanks. Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 26, 2018 Share Posted June 26, 2018 @DylanD I would pay more attention to Pivot for simple animations: mesh.setPivotPoint(Vector3); However, my favorite approach is to set a 'null' object as a child of the parent, then set your visible child you want to animate as a child to the null, and this provide an invisible pivot point which is not fixed... if you wish to animate this as well. But agan, this is old school, but still necessary in many situations. However, it works in all situations for the most part. Don't be afraid to layer your hierarchies, as this provide endless animation possibilities. Just remember this is all accomplished in the BJS code. DB DylanD 1 Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 26, 2018 Author Share Posted June 26, 2018 2 hours ago, dbawel said: @DylanD I would pay more attention to Pivot for simple animations: mesh.setPivotPoint(Vector3); However, my favorite approach is to set a 'null' object as a child of the parent, then set your visible child you want to animate as a child to the null, and this provide an invisible pivot point which is not fixed... if you wish to animate this as well. But agan, this is old school, but still necessary in many situations. However, it works in all situations for the most part. Don't be afraid to layer your hierarchies, as this provide endless animation possibilities. Just remember this is all accomplished in the BJS code. DB Hey so I tried changing the pivot to something local, by that I mean I made a cube and positioned it where I wanted my other mesh to rotate around, then I set the meshes pivot point to the cubes position. So I set the meshes position to the cubes position, so that it would simulate its own axis', however it started to rotate about the box but about a unit away, which leads me to believe it is a larger mesh than I though. Im trying to figure out exactly whats happening but everything keeps confusing me each step. So more information (as you can probably tell I write a post double check "my numbers" then hit post, but then I get new information sometimes... ) when I set the new pivot point it changes the position of the mesh.... This is really confusing, il try to keep updating on Important imformation. So much to look into so little time. Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 26, 2018 Author Share Posted June 26, 2018 could Quaternions help? I know they do stuff with rotation, but in a different way than, mesh.rotation does. I don't really understand them though. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 26, 2018 Share Posted June 26, 2018 perhaps you could share your blend file so @V!nc3r could have a look? Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 12 hours ago, Deltakosh said: perhaps you could share your blend file so @V!nc3r could have a look? unfortunately I don't think I can as I do not own the blender file, I am sorry. ? Although on this blender file It has Three pieces, a body mesh a back mesh and a front mesh (I think they're meshes at least). Each piece has a black dotted line to an orange point under the body, which seems to be their new origin or axis' , since when I try to rotate the back or front mesh they rotate about that point. I tried using the Geometry to origin and it didn't seem to work or do anything at all for that matter, probably I used it wrong... Sorry I know this isn't a lot to go off of, but if you guys have any ideas I would greatly appreciate it! Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted June 27, 2018 Share Posted June 27, 2018 3 hours ago, DylanD said: black dotted line to an orange point under the body The orange point is the origin of an object, the dotted line is here to tell you there is a parent-child relation Here suzanne is child of the cube. If I rotate the cube, suzanne turn around too. If i rotate suzanne, the cube doesn't care. Hope that's help. DylanD 1 Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 3 minutes ago, V!nc3r said: The orange point is the origin of an object, the dotted line is here to tell you there is a parent-child relation Here suzanne is child of the cube. If I rotate the cube, suzanne turn around too. If i rotate suzanne, the cube doesn't care. Hope that's help. Hey again! Hahahahaha I just checked this because I just figured out that one of my meshes is actually made up of 2 more meshes, and that I might be able to rotate the other two meshes instead of the parent mesh if I can just find a way to move the child mesh! But I haven't figured that out yet. Thanks! Any ideas how to access the child meshes from an imported mesh, I tried meshes[0].getchildren[0] but that didn't seem to work so I'm not really sure how to do that. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 meshes[0].getChildren()[0] should work Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 When I do a for(let piece of meshes){console.log("Another mesh");} it only logs 4 meshes when I think I should have 6, since one of those 4 object should be a parent with 2 Childs. but I guess that is not the case... Any ideas? Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 you can call scene.debugLayer.show() to get an UI to help you DylanD 1 Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 53 minutes ago, Deltakosh said: meshes[0].getChildren()[0] should work this makes an error(error in onSuccess call back), maybe I cannot just access those child meshes because of how they are set up in blender? Il look into that unless you guys have any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 maybe they're not actually child objects? They're in the hierarchy like so: mainMesh{ backMesh{ backMesh1 backMesh2 } } does that not mean they have a parent child relationship? if not how could I access those is the lower of the hierarchy? Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 yea so console.log(meshes[0].getChildren().length); comes up 0 for every import mesh from that .babylon file so maybe they're not parent/child relationship so I'm back to being unsure of what to do any ideas? Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 also I have another question, any idea why sometimes when I load my scene my imported mesh is not always at the same spot? I set the imported mesh' parent to one of my in scene object and it varies where It is sometime not being ontop the object at all. Oh and I also set their poisition to be equal to each other... but one problem at a time I guess. Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 possible I understood wrong, I think each thing is an object and then it is the higher in the hierarchy to the child like meshes. so there are actually 4 meshes but more objects? yes I think so. Quote Link to comment Share on other sites More sharing options...
DylanD Posted June 27, 2018 Author Share Posted June 27, 2018 2 hours ago, DylanD said: also I have another question, any idea why sometimes when I load my scene my imported mesh is not always at the same spot? I set the imported mesh' parent to one of my in scene object and it varies where It is sometime not being ontop the object at all. Oh and I also set their poisition to be equal to each other... but one problem at a time I guess. I fixed this by: scene object is just a box mesh... setting the position of the scene object to 0,0,0 in the import function function. That way if theres a loading time problem it will still be in the correct position! (On scene load my scene object start moving, so it was always a little off, but too much for me). Still not sure about the rotation stuff though from up there ^ I like this Babylon stuff 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.