From cc658abf743c9b7ac46b5fe48dc6fd1a24fbc973 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sat, 10 May 2014 16:10:39 +0200 Subject: [PATCH] Figued out a way to retain object properties nonwritable avoiding breakage and notifying the user. See 35e18100c42c2ffc911cd9ff2c8140cf4fb5025a. --- src/core/Object3D.js | 53 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 46af194ac7..dd11c496f2 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -17,26 +17,61 @@ THREE.Object3D = function () { this.up = THREE.Object3D.DefaultUp.clone(); - this.position = new THREE.Vector3(); - var scope = this; + + var position = new THREE.Vector3(); + var rotation = new THREE.Euler(); + var quaternion = new THREE.Quaternion(); + var scale = new THREE.Vector3( 1, 1, 1 ); + + rotation.onChange( function () { + quaternion.setFromEuler( rotation, false ); + } ); + + quaternion.onChange( function () { + rotation.setFromQuaternion( quaternion, undefined, false ); + } ); Object.defineProperties( this, { + position: { + enumerable: true, + get: function () { + return position; + }, + set: function ( value ) { + console.warn( 'THREE: .position = new THREE.Vector3() pattern no longer works. Use .position.set() instead.' ); + position.copy( value ); + } + }, rotation: { enumerable: true, - value: new THREE.Euler().onChange( function () { - scope.quaternion.setFromEuler( scope.rotation, false ); - } ) + get: function () { + return rotation; + }, + set: function ( value ) { + console.warn( 'THREE: .rotation = new THREE.Euler() pattern no longer works. Use .rotation.set() instead.' ); + rotation.copy( value ); + } }, quaternion: { enumerable: true, - value: new THREE.Quaternion().onChange( function () { - scope.rotation.setFromQuaternion( scope.quaternion, undefined, false ); - } ) + get: function () { + return quaternion; + }, + set: function ( value ) { + console.warn( 'THREE: .quaternion = new THREE.Quaternion() pattern no longer works. Use .quaternion.set() instead.' ); + quaternion.copy( value ); + } }, scale: { enumerable: true, - value: new THREE.Vector3( 1, 1, 1 ) + get: function () { + return scale; + }, + set: function ( value ) { + console.warn( 'THREE: .scale = new THREE.Vector3() pattern no longer works. Use .scale.set() instead.' ); + scale.copy( value ); + } } } ); -- GitLab