Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math: Added Vector3.setFromEuler(); removed Euler.toVector3() #23494

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions docs/api/en/math/Euler.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ <h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
Returns an array of the form [[page:.x x], [page:.y y], [page:.z z], [page:.order order ]].
</p>

<h3>[method:Vector3 toVector3]( [param:Vector3 optionalResult] )</h3>
<p>
[page:Vector3 optionalResult] — (optional) If specified, the result will be copied into this Vector,
otherwise a new one will be created. <br /><br />

Returns the Euler's [page:.x x], [page:.y y] and [page:.z z] properties as a [page:Vector3].
</p>


<h2>Source</h2>

<p>
Expand Down
5 changes: 5 additions & 0 deletions docs/api/en/math/Vector3.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ <h3>[method:this setFromCylindrical]( [param:Cylindrical c] )</h3>
<h3>[method:this setFromCylindricalCoords]( [param:Float radius], [param:Float theta], [param:Float y] )</h3>
<p>Sets this vector from the cylindrical coordinates [page:Cylindrical radius], [page:Cylindrical theta] and [page:Cylindrical y].</p>

<h3>[method:this setFromEuler]( [param:Euler euler] )</h3>
<p>
Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from the x, y, and z components of the specified [page:Euler Euler Angle].
</p>

<h3>[method:this setFromMatrixColumn]( [param:Matrix4 matrix], [param:Integer index] )</h3>
<p>
Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from [page:Integer index] column of [page:Matrix4 matrix].
Expand Down
2 changes: 1 addition & 1 deletion editor/js/Sidebar.Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function SidebarObject( editor ) {
}

const newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.MathUtils.DEG2RAD, objectRotationY.getValue() * THREE.MathUtils.DEG2RAD, objectRotationZ.getValue() * THREE.MathUtils.DEG2RAD );
if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
if ( new THREE.Vector3().setFromEuler( object.rotation ).distanceTo( new THREE.Vector3().setFromEuler( newRotation ) ) >= 0.01 ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, this code block instantiates new object frequently. At least it is now more honest about it, and is no worse than before.


editor.execute( new SetRotationCommand( editor, object, newRotation ) );

Expand Down
10 changes: 2 additions & 8 deletions examples/jsm/animation/CCDIKSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,13 @@ class CCDIKSolver {

if ( rotationMin !== undefined ) {

link.rotation.setFromVector3(
link.rotation
.toVector3( _vector )
.max( rotationMin ) );
link.rotation.setFromVector3( _vector.setFromEuler( link.rotation ).max( rotationMin ) );
Copy link
Collaborator Author

@WestLangley WestLangley Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ping @takahirox

  1. There does not appear to be a test case for use of rotationMin/Max. Personally, I do not think it makes sense to clamp Euler angles anyway -- except in very special cases.

  2. Also unrelated to this PR, I am not sure you want to call updateMatrixWorld() a few lines later. Maybe use updateWorldMatrix(), where you can control recursion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out. Let me take a look closer later...


}

if ( rotationMax !== undefined ) {

link.rotation.setFromVector3(
link.rotation
.toVector3( _vector )
.min( rotationMax ) );
link.rotation.setFromVector3( _vector.setFromEuler( link.rotation ).min( rotationMax ) );

}

Expand Down
10 changes: 10 additions & 0 deletions src/Three.Legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { PointsMaterial } from './materials/PointsMaterial.js';
import { ShaderMaterial } from './materials/ShaderMaterial.js';
import { Box2 } from './math/Box2.js';
import { Box3 } from './math/Box3.js';
import { Euler } from './math/Euler.js';
import { Sphere } from './math/Sphere.js';
import { Color } from './math/Color.js';
import { Frustum } from './math/Frustum.js';
Expand Down Expand Up @@ -399,6 +400,15 @@ Box3.prototype.size = function ( optionalTarget ) {

};

//

Euler.prototype.toVector3 = function () {

console.error( 'THREE.Euler: .toVector3() has been removed. Use Vector3.setFromEuler() instead' );

};


//

Sphere.prototype.empty = function () {
Expand Down
15 changes: 0 additions & 15 deletions src/math/Euler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Quaternion } from './Quaternion.js';
import { Vector3 } from './Vector3.js';
import { Matrix4 } from './Matrix4.js';
import { clamp } from './MathUtils.js';

Expand Down Expand Up @@ -288,20 +287,6 @@ class Euler {

}

toVector3( optionalResult ) {

if ( optionalResult ) {

return optionalResult.set( this._x, this._y, this._z );

} else {

return new Vector3( this._x, this._y, this._z );

}

}

_onChange( callback ) {

this._onChangeCallback = callback;
Expand Down
10 changes: 10 additions & 0 deletions src/math/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ class Vector3 {

}

setFromEuler( e ) {

this.x = e._x;
this.y = e._y;
this.z = e._z;

return this;

}

equals( v ) {

return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
Expand Down
19 changes: 0 additions & 19 deletions test/unit/src/math/Euler.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,6 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.test( 'set/setFromVector3/toVector3', ( assert ) => {

var a = new Euler();

a.set( 0, 1, 0, 'ZYX' );
assert.ok( a.equals( eulerAzyx ), 'Passed!' );
assert.ok( ! a.equals( eulerAxyz ), 'Passed!' );
assert.ok( ! a.equals( eulerZero ), 'Passed!' );

var vec = new Vector3( 0, 1, 0 );

var b = new Euler().setFromVector3( vec, 'ZYX' );
assert.ok( a.equals( b ), 'Passed!' );

var c = b.toVector3();
assert.ok( c.equals( vec ), 'Passed!' );

} );

QUnit.test( 'clone/copy/equals', ( assert ) => {

var a = eulerAxyz.clone();
Expand Down