Jump to content

imported blender .babylon mesh/scene axis' off


DylanD
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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

 

Link to comment
Share on other sites

23 minutes ago, V!nc3r said:

Do you have a little blend scene to share?

Origin position can be modified here:

quUOGSw.png

 

 

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.

 

Link to comment
Share on other sites

@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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!:D

Link to comment
Share on other sites

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

O3kV41p.png

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.

Link to comment
Share on other sites

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

O3kV41p.png

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :D 

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