Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js - Can I 'apply' position, rotation, and scale to the geometry?

Tags:

three.js

I'd like to edit an object's position, rotation, and scale vectors, then 'apply' them to the geometry, which would zero-out those vectors, but retain the transformation.

For example, let's say I import a cube with a side-length of 1. The min and max vertices of the cube are located at (0, 0, 0) and (1, 1, 1). I set the object's scale to (2, 2, 2) and then apply the transformation to the geometry.

After applying, the scale is reset to (1, 1, 1) and the min and max vertices of the cube are (0, 0, 0) and (2, 2, 2), respectively.

Is there some built-in way to do this?

like image 355
Justin Avatar asked Nov 19 '14 16:11

Justin


People also ask

What is matrix in three js?

Three. js uses matrices to encode 3D transformations---translations (position), rotations, and scaling. Every instance of Object3D has a matrix which stores that object's position, rotation, and scale.

What is applyMatrix4?

applyMatrix4 ( matrix : Matrix4 ) : undefined. Applies the matrix transform to the object and updates the object's position, rotation and scale.


1 Answers

You can apply an object's transform to the object's geometry directly, and then reset the position, rotation, and scale like so:

object.updateMatrix();

object.geometry.applyMatrix( object.matrix );

object.position.set( 0, 0, 0 );
object.rotation.set( 0, 0, 0 );
object.scale.set( 1, 1, 1 );
object.updateMatrix();

three.js r.69

like image 142
WestLangley Avatar answered Sep 20 '22 14:09

WestLangley