Giter Site home page Giter Site logo

Comments (17)

deltakosh avatar deltakosh commented on May 22, 2024

The transform parameter is a BABYLON.Matrix

from babylon.js.

cyle avatar cyle commented on May 22, 2024

Okay -- so how would I use a Matrix to apply a transform? For instance, say I want to rotate a Mesh along the z axis by Math.PI/2. How would I bake that in? Is there a way to capture the Mesh's current matrix after rotating it, and feeding that to applyTransform() ? Or instead would I somehow pass a Matrix of the rotation? Does any of that make sense?

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

In this case just use this code:

var transform = BABYLON.Matrix.RotationZ(Math.PI / 2);
mesh.applyTransform(transform);

from babylon.js.

cyle avatar cyle commented on May 22, 2024

Now I've run into a new problem -- when I apply that transform, it applies on top of the existing rotation. Which means if, in Blender, I make a model that's rotated, the additional rotation here rotates it further. Is there a way to import a model from blender and apply its current rotations, scalings, etc? Is there a way to simply get its current matrix and apply that? I appreciate any help.

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

The object's rotation is baked into the vertices when exported from blender. So for now there is no way of applying your transform before the rotation from blender:(

from babylon.js.

cyle avatar cyle commented on May 22, 2024

Okay, cool. I probably need to use a pivot point then. My issue right now is importing a model from Blender that has several meshes and trying to rotate them all along the same axis -- I probably just need to give them all the same pivot point so they rotate properly.

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

sounds good:)

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

In the next version, I've renamed applyTransform to bakeTransformIntoVertices

from babylon.js.

cyle avatar cyle commented on May 22, 2024

I'm having a problem figuring out how to properly set pivot points now, haha.

My problem is this: I'm importing a model from Blender that has multiple meshes; my thought is to run through all of them, give them a common pivot point, and rotate them together. However, I just can't seem to figure out how to do this. Can you provide any help?

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

You can use mesh.setPivotMatrix()

from babylon.js.

cyle avatar cyle commented on May 22, 2024

Yes, but I mean how do I use that, too? I can't seem to feed it a set of coordinates to use as the pivot point. I'll try uploading a demo of what I'm trying to do, maybe you can take a look and let me know what I'm doing wrong.

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

It awaits a matrix. For instance:
mesh.setPivotMatrix(BABYLON.Matrix.Translation(1,0,2));

from babylon.js.

cyle avatar cyle commented on May 22, 2024

And are those relative or absolute coordinates? So if a mesh is at 5, 5, 10, and i want it to pivot around the global origin 0, 0, 0, would the matrix put into setPivotMatrix be 0, 0, 0, or -5, -5, -10? does that make sense? thanks for your continued help on this, by the way. using this engine is my first real dive into programming vector math using matrices and whatnot. most of it has come very easily, but stuff like this is a little harder for me.

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

The pivot matrix is an absolute transform. But by default, the pivot should not be required.
If the mesh is defined like this:
mesh.position = new BABYLON.Vector4(5, 5, 10)
You don't have to define the pivot UNLESS the mesh's geometry is not well centered.

For instance, if you mesh's geometry is composed of 3 vertices ((5, 5, 5), (6, 6, 5 and (7,5,5)). The inner pivot position is (6, 5.5, 5) and if you want to rotate this mesh around 0 you have to set the pivot matrix to BABYLON.Matrix.Translation(-6, -5.5, -5).

But if your geometry is ((-0.5,-0.5, 0), (0, 0.5, 0), (0.5,0,0)) you do not have to set the pivot because it is already centered to (0,0,0)

Am I clear?

from babylon.js.

cyle avatar cyle commented on May 22, 2024

Okay, here is the project: https://github.com/cyle/babylonjs-model-test2

So right now when you load that scene (index.html) it's loading the model (which is exported from blender, has multiple meshes) with the front of the space ship pointing at the camera along the Z axis (Z axis is represented as the blue cube). I'd like it to be pointed upwards along the Y axis (Y axis is represented as the green cube) instead. Doing so means rotating all of the imported meshes, though every time I try it rotates them locally along each meshes' center point. So if you just run through all of them and do a .rotation.x = Math.PI/2, it rotates each mesh instead of the whole ship.

I successfully got them all to rotate by making the center-most mesh the "parent" of the other meshes, but then I don't know how to "bake" the new positions into all of the meshes and de-"parent" the central mesh. It'd be much better to import the model, rotate all of the meshes along a central pivot point, and then "bake" their new positions into each mesh.

Does that make sense? Any suggestions?

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

Suggestion: You could bake mesh.getWolrdMatrix() and then remove parent info.

from babylon.js.

deltakosh avatar deltakosh commented on May 22, 2024

But you can also use mesh.setPivotMatrix on all meshes and use a BABYLON.Matrix.Translation. The translation value should be equal to centership.position - currentship.position

from babylon.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.