Trevor Baron пре 6 година
родитељ
комит
c4de10a8d5

+ 16 - 0
nodeEditor/src/components/customDiragramNodes/generic/genericNodeFactory.tsx

@@ -3,15 +3,31 @@ import { GenericNodeWidget } from "./genericNodeWidget";
 import { GenericNodeModel } from "./genericNodeModel";
 import * as React from "react";
 
+/**
+ * Node factory which creates editor nodes
+ */
 export class GenericNodeFactory extends SRD.AbstractNodeFactory {
+	/**
+	 * Constructs a GenericNodeFactory
+	 */
 	constructor() {
 		super("generic");
 	}
 
+	/**
+	 * Generates a node widget
+	 * @param diagramEngine diagram engine
+	 * @param node node to generate
+	 * @returns node widget jsx
+	 */
 	generateReactWidget(diagramEngine: SRD.DiagramEngine, node: GenericNodeModel): JSX.Element {
 		return <GenericNodeWidget node={node} />;
 	}
 
+	/**
+	 * Gets a new instance of a node model
+	 * @returns generic node model
+	 */
 	getNewInstance() {
 		return new GenericNodeModel();
 	}

+ 32 - 7
nodeEditor/src/components/customDiragramNodes/generic/genericNodeModel.ts

@@ -4,19 +4,44 @@ import { NodeMaterialBlock } from 'babylonjs/Materials/Node/nodeMaterialBlock';
 import { Texture } from 'babylonjs/Materials/Textures/texture';
 import { Vector2, Vector3, Vector4, Matrix } from 'babylonjs/Maths/math';
 
+/**
+ * Generic node model which stores information about a node editor block
+ */
 export class GenericNodeModel extends NodeModel {
+	/**
+	 * The babylon block this node represents
+	 */
 	public block:Nullable<NodeMaterialBlock> = null;
+	/**
+	 * Labels for the block
+	 */
 	public headerLabels:Array<{text: string}> = []
-	texture: Nullable<Texture> = null;
-	vector2: Nullable<Vector2> = null;
-	vector3: Nullable<Vector3> = null;
-	vector4: Nullable<Vector4> = null;
-	matrix: Nullable<Matrix> = null;
-	//public textureInputs:Array<{text: string, initialValue: string}> = []
+	/**
+	 * Texture for the node if it exists
+	 */
+	public texture: Nullable<Texture> = null;
+	/**
+	 * Vector2 for the node if it exists
+	 */
+	public vector2: Nullable<Vector2> = null;
+	/**
+	 * Vector3 for the node if it exists
+	 */
+	public vector3: Nullable<Vector3> = null;
+	/**
+	 * Vector4 for the node if it exists
+	 */
+	public vector4: Nullable<Vector4> = null;
+	/**
+	 * Matrix for the node if it exists
+	 */
+	public matrix: Nullable<Matrix> = null;
 
+	/**
+	 * Constructs the node model
+	 */
 	constructor() {
 		super("generic");
-		//this.addPort(new GenericPortModel("right"));
 	}
 
 }

+ 21 - 11
nodeEditor/src/components/customDiragramNodes/generic/genericNodeWidget.tsx

@@ -11,38 +11,46 @@ import { Texture } from 'babylonjs/Materials/Textures/texture';
 import { Engine } from 'babylonjs/Engines/engine';
 import { Tools } from 'babylonjs/Misc/tools';
 
+/**
+ * GenericNodeWidgetProps
+ */
 export interface GenericNodeWidgetProps {
 	node: Nullable<GenericNodeModel>;
 }
 
+/**
+ * GenericNodeWidgetState
+ */
 export interface GenericNodeWidgetState {}
 
-
+/**
+ * Used to display a node block for the node editor
+ */
 export class GenericNodeWidget extends React.Component<GenericNodeWidgetProps, GenericNodeWidgetState> {
-
+	/**
+	 * Creates a GenericNodeWidget
+	 * @param props 
+	 */
 	constructor(props: GenericNodeWidgetProps) {
 		super(props);
 		this.state = {}
 	}
 
-	// componentDidUpdate() {
-	// 	this.updateTexture()
-	// }
-
-	// componentDidMount() {
-	// 	this.updateTexture()
-	// }
-
-
+	/**
+	 * Replaces the texture of the node
+	 * @param file the file of the texture to use
+	 */
 	replaceTexture(file: File) {
 		if(!this.props.node){
 			return;
 		}
+
 		let texture = this.props.node.texture as Texture;
 		if(!texture){
 			this.props.node.texture = new Texture(null, Engine.LastCreatedScene)
 			texture = this.props.node.texture;
 		}
+
         Tools.ReadFile(file, (data) => {
             var blob = new Blob([data], { type: "octet/stream" });
             var url = URL.createObjectURL(blob);
@@ -80,6 +88,7 @@ export class GenericNodeWidget extends React.Component<GenericNodeWidgetProps, G
 				if(port.position == "input"){
 					var control = <div></div>
 
+					// Color of the connection
 					var color = "black"
 					if(port.connection){
 						if(port.connection.isAttribute){
@@ -118,6 +127,7 @@ export class GenericNodeWidget extends React.Component<GenericNodeWidgetProps, G
 				
 			}
 
+			// Display the view depending on the value type of the node
 			if(this.props.node.texture){
 				value = (
 					<div>

+ 13 - 31
nodeEditor/src/components/customDiragramNodes/generic/genericPortModel.ts

@@ -3,28 +3,26 @@ import { Nullable } from 'babylonjs/types';
 import { NodeMaterialConnectionPoint } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPoint';
 import { GenericNodeModel } from './genericNodeModel';
 
-
+/**
+ * Port model for the generic node
+ */
 export class GenericPortModel extends PortModel {
-	position: string | "input" | "output";
-	connection: Nullable<NodeMaterialConnectionPoint> = null;
+	/**
+	 * If the port is input or output
+	 */
+	public position: string | "input" | "output";
+	/**
+	 * What the port is connected to
+	 */
+	public connection: Nullable<NodeMaterialConnectionPoint> = null;
+
+	
 	static idCounter = 0;
 
 	constructor(name:string, type: string = "input") {
-		//(""+GenericPortModel.idCounter)
 		super(name, "generic");
 		this.position = type;
 		GenericPortModel.idCounter++;
-		// this.addListener({
-		// 	selectionChanged: ()=>{
-		// 		console.log("change")
-		// 	},
-		// 	lockChanged: ()=>{
-		// 		console.log("lock")
-		// 	},
-		// 	entityRemoved: ()=>{
-		// 		console.log("rem")
-		// 	}
-		// })
 	}
 
 	syncWithNodeMaterialConnectionPoint(connection:NodeMaterialConnectionPoint){
@@ -36,24 +34,8 @@ export class GenericPortModel extends PortModel {
 		return this.parent as GenericNodeModel
 	}
 
-	// serialize() {
-	// 	return _.merge(super.serialize(), {
-	// 		position: this.position
-	// 	});
-	// }
-
-	// deSerialize(data: any, engine: DiagramEngine) {
-	// 	super.deSerialize(data, engine);
-	// 	this.position = data.position;
-	// }
-
 	link(outPort:GenericPortModel){
 		var link = this.createLinkModel()
-		// link.addListener({
-		// 	selectionChanged: ()=>{
-		// 		console.log("hit")
-		// 	}
-		// })
 		link.setSourcePort(this)
 		link.setTargetPort(outPort)
 		return link;

+ 0 - 3
nodeEditor/src/components/customDiragramNodes/texture/textureNodeModel.ts

@@ -5,8 +5,5 @@ export class TextureNodeModel extends NodeModel {
 	constructor() {
 		super("texture");
 		this.addPort(new TexturePortModel("right"));
-		// this.addPort(new DiamondPortModel("left"));
-		// this.addPort(new DiamondPortModel("bottom"));
-		// this.addPort(new DiamondPortModel("right"));
 	}
 }