Comments (17)
The transform parameter is a BABYLON.Matrix
from babylon.js.
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.
In this case just use this code:
var transform = BABYLON.Matrix.RotationZ(Math.PI / 2);
mesh.applyTransform(transform);
from babylon.js.
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.
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.
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.
sounds good:)
from babylon.js.
In the next version, I've renamed applyTransform to bakeTransformIntoVertices
from babylon.js.
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.
You can use mesh.setPivotMatrix()
from babylon.js.
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.
It awaits a matrix. For instance:
mesh.setPivotMatrix(BABYLON.Matrix.Translation(1,0,2));
from babylon.js.
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.
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.
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.
Suggestion: You could bake mesh.getWolrdMatrix() and then remove parent info.
from babylon.js.
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)
- Cannot build. Missing ImageEncodeOptions, VideoFrame, etc. HOT 4
- [Physics] would like to have motorized constraints added. HOT 1
- Internal types exported in definition types. HOT 1
- scene.ambientColor does not work HOT 1
- ParticleSystem of type "CylinderDirectedParticleEmitter" dont convert direction vectors HOT 1
- PhysicsAggregate does not update mesh with setAngularVelocity and setLinearVelocity after 7.2.1 update HOT 5
- [XR] Failproof the snippet reference in NearInteraction
- Yoyo animations trigger onAnimationGroupLoopedObservable multiple times per loop
- Add support for IES Light Profiles HOT 2
- Improve new texture support in Particle System Editor
- NGE nodes and ports exposed on frame don't export
- GLB Import Not Displaying in BabylonJS Sandbox HOT 2
- 7.4.0 and Custom Procedural Textures HOT 1
- [XR] Update depth sensing implementation to support the new specs
- Specular/Glossiness material to Metal/Rough material conversion HOT 1
- GUI JSON parse - provide callback to allow updating link URLs from development to production servers
- Expand memory leak testing to all packages
- Move documentation repo to the monorepo
- Improve GaussianSplatting for VR HOT 1
- BabylonFileLoader
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babylon.js.