Bläddra i källkod

NodeEditor: cleanup (#23332)

* add AngleEditor

* cleanup
sunag 3 år sedan
förälder
incheckning
1a1d338e14

+ 14 - 2
examples/jsm/node-editor/NodeEditor.js

@@ -6,6 +6,7 @@ import { InvertEditor } from './math/InvertEditor.js';
 import { LimiterEditor } from './math/LimiterEditor.js';
 import { DotEditor } from './math/DotEditor.js';
 import { PowerEditor } from './math/PowerEditor.js';
+import { AngleEditor } from './math/AngleEditor.js';
 import { TrigonometryEditor } from './math/TrigonometryEditor.js';
 import { FloatEditor } from './inputs/FloatEditor.js';
 import { Vector2Editor } from './inputs/Vector2Editor.js';
@@ -130,9 +131,15 @@ export const NodeList = [
 			{
 				name: 'Trigonometry',
 				icon: 'wave-sine',
-				tip: 'Sin / Cos / Tan',
+				tip: 'Sin / Cos / Tan / ...',
 				nodeClass: TrigonometryEditor
 			},
+			{
+				name: 'Angle',
+				icon: 'angle',
+				tip: 'Degress / Radians',
+				nodeClass: AngleEditor
+			},
 			{
 				name: 'Normalize',
 				icon: 'fold',
@@ -210,6 +217,7 @@ export const ClassLib = {
 	LimiterEditor,
 	DotEditor,
 	PowerEditor,
+	AngleEditor,
 	TrigonometryEditor,
 	FloatEditor,
 	Vector2Editor,
@@ -346,7 +354,11 @@ export class NodeEditor extends EventDispatcher {
 
 		newButton.onClick( () => {
 
-			if ( confirm( 'are you sure' ) ) this.newProject();
+			if ( confirm( 'Are you sure?' ) === true ) {
+
+				this.newProject();
+
+			}
 
 		} );
 

+ 1 - 1
examples/jsm/node-editor/accessors/NormalEditor.js

@@ -14,7 +14,7 @@ export class NormalEditor extends BaseNode {
 			{ name: 'Local', value: NormalNode.LOCAL },
 			{ name: 'World', value: NormalNode.WORLD },
 			{ name: 'View', value: NormalNode.VIEW },
-			{ name: 'Geometry', value: NormalNode.GEOMETRY },
+			{ name: 'Geometry', value: NormalNode.GEOMETRY }
 		], NormalNode.LOCAL ).onChange( () => {
 
 			node.scope = optionsField.getValue();

+ 1 - 1
examples/jsm/node-editor/accessors/PositionEditor.js

@@ -14,7 +14,7 @@ export class PositionEditor extends BaseNode {
 			{ name: 'Local', value: PositionNode.LOCAL },
 			{ name: 'World', value: PositionNode.WORLD },
 			{ name: 'View', value: PositionNode.VIEW },
-			{ name: 'ViewDirection', value: PositionNode.VIEW_DIRECTION },
+			{ name: 'View Direction', value: PositionNode.VIEW_DIRECTION }
 		], PositionNode.LOCAL ).onChange( () => {
 
 			node.scope = optionsField.getValue();

+ 39 - 0
examples/jsm/node-editor/math/AngleEditor.js

@@ -0,0 +1,39 @@
+import { SelectInput, Element, LabelElement } from '../../libs/flow.module.js';
+import { BaseNode } from '../core/BaseNode.js';
+import { MathNode, Vector3Node } from '../../renderers/nodes/Nodes.js';
+
+const DEFAULT_VALUE = new Vector3Node();
+
+export class AngleEditor extends BaseNode {
+
+	constructor() {
+
+		const node = new MathNode( MathNode.SIN, DEFAULT_VALUE );
+
+		super( 'Angle', 1, node, 175 );
+
+		const optionsField = new SelectInput( [
+			{ name: 'Degrees to Radians', value: MathNode.RAD },
+			{ name: 'Radians to Degrees', value: MathNode.DEG }
+		], MathNode.RAD ).onChange( () => {
+
+			node.method = optionsField.getValue();
+
+			this.invalidate();
+
+		} );
+
+		const input = new LabelElement( 'A' ).setInput( 1 );
+
+		input.onConnect( () => {
+
+			node.aNode = input.getLinkedObject() || DEFAULT_VALUE;
+
+		} );
+
+		this.add( new Element().add( optionsField ) )
+			.add( input );
+
+	}
+
+}

+ 2 - 5
examples/jsm/node-editor/math/TrigonometryEditor.js

@@ -10,19 +10,16 @@ export class TrigonometryEditor extends BaseNode {
 
 		const node = new MathNode( MathNode.SIN, DEFAULT_VALUE );
 
-		super( 'Angle / Trigonometry', 1, node, 220 );
+		super( 'Trigonometry', 1, node, 175 );
 
 		const optionsField = new SelectInput( [
-			{ name: 'Radian', value: MathNode.RAD },
-			{ name: 'Degree', value: MathNode.DEG },
-
 			{ name: 'Sin', value: MathNode.SIN },
 			{ name: 'Cos', value: MathNode.COS },
 			{ name: 'Tan', value: MathNode.TAN },
 
 			{ name: 'asin', value: MathNode.ASIN },
 			{ name: 'acos', value: MathNode.ACOS },
-			{ name: 'atan', value: MathNode.ATAN },
+			{ name: 'atan', value: MathNode.ATAN }
 		], MathNode.SIN ).onChange( () => {
 
 			node.method = optionsField.getValue();

+ 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: