Procházet zdrojové kódy

TransformControls: Better error handling and docs.

Mugen87 před 5 roky
rodič
revize
da53a30015

+ 3 - 1
docs/examples/en/controls/TransformControls.html

@@ -14,7 +14,9 @@
 
 		<p class="desc">
 			This class can be used to transform objects in 3D space by adapting a similar interaction model of DCC tools like Blender.
-			Unlike other controls, it is not intended to transform the scene's camera.
+			Unlike other controls, it is not intended to transform the scene's camera.<br /><br />
+
+			[name] expects that its attached 3D object is part of the scene graph.
 		</p>
 
 		<h2>Example</h2>

+ 3 - 1
docs/examples/zh/controls/TransformControls.html

@@ -14,7 +14,9 @@
 
 		<p class="desc">
 			This class can be used to transform objects in 3D space by adapting a similar interaction model of DCC tools like Blender.
-			Unlike other controls, it is not intended to transform the scene's camera.
+			Unlike other controls, it is not intended to transform the scene's camera.<br /><br />
+
+			[name] expects that its attached 3D object is part of the scene graph.
 		</p>
 
 		<h2>Example</h2>

+ 11 - 1
examples/js/controls/TransformControls.js

@@ -206,7 +206,17 @@ THREE.TransformControls = function ( camera, domElement ) {
 		if ( this.object !== undefined ) {
 
 			this.object.updateMatrixWorld();
-			this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
+
+			if ( this.object.parent === null ) {
+
+				console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
+
+			} else {
+
+				this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
+
+			}
+
 			this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
 
 			parentQuaternionInv.copy( parentQuaternion ).inverse();

+ 11 - 1
examples/jsm/controls/TransformControls.js

@@ -229,7 +229,17 @@ var TransformControls = function ( camera, domElement ) {
 		if ( this.object !== undefined ) {
 
 			this.object.updateMatrixWorld();
-			this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
+
+			if ( this.object.parent === null ) {
+
+				console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
+
+			} else {
+
+				this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
+
+			}
+
 			this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
 
 			parentQuaternionInv.copy( parentQuaternion ).inverse();