Procházet zdrojové kódy

NodeEditor: Fixes (#23309)

* FIX NodeEditor
- use the right Editor Class for Normalize entry
- traverser error if no scene set
FIX MeshEditor
- fix import for three

* esLint
Franck před 3 roky
rodič
revize
be80adf563

+ 23 - 19
examples/jsm/node-editor/NodeEditor.js

@@ -136,7 +136,7 @@ export const NodeList = [
 			{
 				name: 'Normalize',
 				icon: 'fold',
-				nodeClass: OperatorEditor
+				nodeClass: NormalizeEditor
 			}
 		]
 	},
@@ -508,41 +508,45 @@ export class NodeEditor extends EventDispatcher {
 
 			const object3d = this.scene;
 
-			object3d.traverse( ( obj3d ) => {
+			if ( object3d !== null ) {
+
+				object3d.traverse( ( obj3d ) => {
+
+					if ( obj3d.isMesh === true ) {
 
-				if ( obj3d.isMesh === true ) {
+						const button = new ButtonInput( `Mesh - ${obj3d.name}` );
+						button.setIcon( 'ti ti-3d-cube-sphere' );
+						button.addEventListener( 'complete', () => {
 
-					const button = new ButtonInput( `Mesh - ${obj3d.name}` );
-					button.setIcon( `ti ti-3d-cube-sphere` );
-					button.addEventListener( 'complete', () => {
+							for ( const node of this.canvas.nodes ) {
 
-						for ( const node of this.canvas.nodes ) {
+								if ( node.value === obj3d ) {
 
-							if ( node.value === obj3d ) {
+									// not duplicated node
 
-								// not duplicated node
+									this.canvas.select( node );
 
-								this.canvas.select( node );
+									return;
 
-								return;
+								}
 
 							}
 
-						}
+							const node = new MeshEditor( obj3d );
 
-						const node = new MeshEditor( obj3d );
+							this.add( node );
 
-						this.add( node );
+							this.centralizeNode( node );
 
-						this.centralizeNode( node );
+						} );
 
-					} );
+						search.add( button );
 
-					search.add( button );
+					}
 
-				}
+				} );
 
-			} );
+			}
 
 		} );
 

+ 11 - 11
examples/jsm/node-editor/scene/MeshEditor.js

@@ -1,6 +1,6 @@
 import { NumberInput, StringInput, LabelElement } from '../../libs/flow.module.js';
 import { BaseNode } from '../core/BaseNode.js';
-import { Mesh, MathUtils, Vector3} from '../../../../build/three.module.js';
+import { Mesh, MathUtils, Vector3 } from 'three';
 
 export class MeshEditor extends BaseNode {
 
@@ -35,9 +35,9 @@ export class MeshEditor extends BaseNode {
 	setEditor( editor ) {
 
 		if ( this.editor ) {
-			
+
 			this._restoreDefault();
-			
+
 		}
 
 		super.setEditor( editor );
@@ -148,7 +148,7 @@ export class MeshEditor extends BaseNode {
 		const mesh = this.mesh;
 
 		if ( mesh ) {
-			
+
 			const { position, rotation, scale } = mesh;
 
 			position.x = this.posX.getValue();
@@ -158,17 +158,17 @@ export class MeshEditor extends BaseNode {
 			rotation.x = MathUtils.degToRad( this.rotX.getValue() );
 			rotation.y = MathUtils.degToRad( this.rotY.getValue() );
 			rotation.z = MathUtils.degToRad( this.rotZ.getValue() );
-			
+
 			scale.x = this.scaleX.getValue() / 100;
 			scale.y = this.scaleY.getValue() / 100;
 			scale.z = this.scaleZ.getValue() / 100;
-			
+
 			mesh.material = this.material || this.defaultMaterial;
 
 		}
 
 	}
-	
+
 	updateDefault() {
 
 		const { material, position, rotation, scale } = this.mesh;
@@ -182,9 +182,9 @@ export class MeshEditor extends BaseNode {
 		this._restoreDefault();
 
 	}
-	
+
 	_restoreDefault() {
-		
+
 		const position = this.defaultPosition;
 		const rotation = this.defaultRotation;
 		const scale = this.defaultScale;
@@ -200,9 +200,9 @@ export class MeshEditor extends BaseNode {
 		this.scaleX.setValue( scale.x );
 		this.scaleY.setValue( scale.y );
 		this.scaleZ.setValue( scale.z );
-		
+
 		this.mesh.material = this.defaultMaterial;
-		
+
 	}
 
 }

+ 3 - 3
examples/jsm/nodes/math/MathNode.js

@@ -24,7 +24,7 @@ class MathNode extends TempNode {
 
 				return this.b ? 2 : 1;
 
-			// 3
+				// 3
 
 			case MathNode.MIX:
 			case MathNode.CLAMP:
@@ -34,7 +34,7 @@ class MathNode extends TempNode {
 
 				return 3;
 
-			// 2
+				// 2
 
 			case MathNode.MIN:
 			case MathNode.MAX:
@@ -48,7 +48,7 @@ class MathNode extends TempNode {
 
 				return 2;
 
-			// 1
+				// 1
 
 			default: