Преглед на файлове

[animgraph] Compile in game

Clément Espeute преди 8 месеца
родител
ревизия
108b2acefc

+ 13 - 14
hide/comp/ScenePreview.hx

@@ -34,16 +34,6 @@ class ScenePreview extends Scene {
 		menu.get(0).onclick = (e: js.html.MouseEvent) -> {
 			var items : Array<hide.comp.ContextMenu.MenuItem> = [];
 
-			var renderProps = listRenderProps();
-			var renderPropsMenu : Array<hide.comp.ContextMenu.MenuItem> = [];
-			for (prop in renderProps) {
-				renderPropsMenu.push({label: prop.name, click: () -> {
-					previewSettings.renderPropsPath = prop.value;
-					loadSavedRenderProps();
-				}, radio: () -> prop.value == previewSettings.renderPropsPath, stayOpen: true});
-			}
-			items.push({label: "Render Props", menu: renderPropsMenu});
-
 			var loadableMeshes = listLoadableMeshes();
 			if (loadableMeshes.length > 0) {
 				var loadableMeshesMenu : Array<hide.comp.ContextMenu.MenuItem> = [];
@@ -58,7 +48,18 @@ class ScenePreview extends Scene {
 					);
 				}
 				items.push({label: "Preview Mesh", menu: loadableMeshesMenu});
+			}
 
+			var renderProps = listRenderProps();
+			if (renderProps.length > 0) {
+				var renderPropsMenu : Array<hide.comp.ContextMenu.MenuItem> = [];
+				for (prop in renderProps) {
+					renderPropsMenu.push({label: prop.name, click: () -> {
+						previewSettings.renderPropsPath = prop.value;
+						loadSavedRenderProps();
+					}, radio: () -> prop.value == previewSettings.renderPropsPath, stayOpen: true});
+				}
+				items.push({label: "Render Props", menu: renderPropsMenu});
 			}
 
 			hide.comp.ContextMenu.createDropdown(menu.get(0), items);
@@ -134,10 +135,8 @@ class ScenePreview extends Scene {
 				rp = prop;
 			}
 		}
-
-		trace("renderprops", rp);
-		setRenderProps(rp.value);
-		previewSettings.renderPropsPath = rp.value;
+		setRenderProps(rp?.value);
+		previewSettings.renderPropsPath = rp?.value;
 		saveSettings();
 	}
 

+ 1 - 3
hrt/animgraph/AnimGraph.hx

@@ -24,9 +24,7 @@ class AnimGraph extends hrt.prefab.Prefab {
 	var nodes: Array<Node> = [];
 	var parameters : Array<Parameter> = [];
 
-	#if editor
 	var nodeIdCount = 0;
-	#end
 
 	override function makeInstance() {
 		throw "don't make this";
@@ -129,7 +127,7 @@ class AnimGraph extends hrt.prefab.Prefab {
 					#if editor
 					hide.Ide.inst.quickError('Missing node type ${nodeData.type} from graph.');
 					#else
-					throw 'Graph ${this.shared.path} contains unknown node ${nodeData.type}';
+					throw 'Graph ${this.shared.prefabSource} contains unknown node ${nodeData.type}';
 					#end
 				}
 			}

+ 2 - 2
hrt/animgraph/Macros.hx

@@ -100,7 +100,6 @@ class Macros {
 			fields.push(a);
 		}
 
-		#if editor
 		var thisClass = Context.getLocalClass().get();
 		var classPath = thisClass.pack.copy();
 		classPath.push(thisClass.name);
@@ -178,6 +177,7 @@ class Macros {
 
 		var displayName = nodeName;
 
+		#if editor
 		if (!isRoot && fields.find(f -> f.name == "getDisplayName") == null) {
 			fields.push({
 				name: "getDisplayName",
@@ -190,6 +190,7 @@ class Macros {
 				pos: Context.currentPos(),
 			});
 		}
+		#end
 
 		if (doRegister) {
 
@@ -200,7 +201,6 @@ class Macros {
 				pos: Context.currentPos(),
 			});
 		}
-		#end
 		return fields;
 	}
 

+ 23 - 27
hrt/animgraph/Node.hx

@@ -2,13 +2,10 @@ package hrt.animgraph;
 
 typedef Edge = {target: Node, outputIndex: Int};
 
-#if editor
-
 enum OutputType {
 	TFloat;
 	TAnimation;
 }
-
 typedef NodeOutputInfo = {
 	name: String,
 	type: OutputType,
@@ -16,7 +13,6 @@ typedef NodeOutputInfo = {
 
 typedef NodeInputInfo = { > NodeOutputInfo, ?def : Dynamic };
 
-#end
 @:build(hrt.animgraph.Macros.build(false))
 @:autoBuild(hrt.animgraph.Macros.build(true))
 @:keep
@@ -32,6 +28,7 @@ implements hide.view.GraphInterface.IGraphNode
 
 	@:s public var x : Float;
 	@:s public var y : Float;
+	public var id : Int;
 	public var inputEdges: Array<Edge> = [];
 	var animGraph : AnimGraph;
 
@@ -95,9 +92,20 @@ implements hide.view.GraphInterface.IGraphNode
 		return inst;
 	}
 
+	// Autogenerated macro interface
+
+	// Do not override
+	public function getInputs() : Array<NodeInputInfo> {
+		return [];
+	}
+
+	// Do not override
+	public function getOutputs() : Array<NodeOutputInfo> {
+		return [];
+	}
+
 	#if editor
 
-	public var id : Int;
 	public static var __nodeUID : Int = 0;
 
 	public var editor : hide.view.GraphEditor;
@@ -115,18 +123,6 @@ implements hide.view.GraphInterface.IGraphNode
 		return SIZE_DEFAULT;
 	}
 
-	// Autogenerated macro interface
-
-	// Do not override
-	public function getInputs() : Array<NodeInputInfo> {
-		return [];
-	}
-
-	// Do not override
-	public function getOutputs() : Array<NodeOutputInfo> {
-		return [];
-	}
-
 	// If not present in the child classes, will default to the class name
 	// Auto overriden by build macro
 	public function getDisplayName() : String {
@@ -181,16 +177,6 @@ implements hide.view.GraphInterface.IGraphNode
 		y = p.y;
 	}
 
-	// Static helpers
-	static public var registeredNodes = new Map<String, Class<Node>>();
-
-	// Used by macros to auto-register nodes
-	@:noCompletion
-	static public function register(name: String, cl: Class<Node>) : Bool {
-		registeredNodes.set(name, cl);
-		return true;
-	}
-
 	static function getTypeColor(type: OutputType) : Int {
 		switch(type) {
 			case TAnimation:
@@ -204,4 +190,14 @@ implements hide.view.GraphInterface.IGraphNode
 		return a == b;
 	}
 	#end
+
+	// Static helpers
+	static public var registeredNodes = new Map<String, Class<Node>>();
+
+	// Used by macros to auto-register nodes
+	@:noCompletion
+	static public function register(name: String, cl: Class<Node>) : Bool {
+		registeredNodes.set(name, cl);
+		return true;
+	}
 }

+ 2 - 0
hrt/animgraph/nodes/Blend.hx

@@ -50,7 +50,9 @@ class Blend extends AnimNode {
 		m1._43 = z;
 	}
 
+	#if editor
 	override function getSize():Int {
 		return Node.SIZE_SMALL;
 	}
+	#end
 }

+ 2 - 3
hrt/animgraph/nodes/BlendSpace2D.hx

@@ -10,7 +10,7 @@ typedef BlendSpaceInstancePoint = {
 typedef AnimInfo = {
 	anim: h3d.anim.Animation,
 	proxy: hrt.animgraph.nodes.Input.AnimProxy,
-	indexRemap: Array<Int>,
+	indexRemap: Array<Null<Int>>,
 }
 
 @:access(hrt.animgraph.BlendSpace2D)
@@ -77,7 +77,7 @@ class BlendSpace2D extends AnimNode {
 						var proxy = new hrt.animgraph.nodes.Input.AnimProxy(null);
 						var animInstance = animBase.createInstance(proxy);
 
-						var indexRemap = [];
+						var indexRemap : Array<Null<Int>> = [];
 
 						for (boneId => obj in animInstance.getObjects()) {
 							var ourId = boneMap.getOrPut(obj.objectName, curOurBoneId++);
@@ -225,7 +225,6 @@ class BlendSpace2D extends AnimNode {
 
 		Tools.weightedBlend(workQuats, refQuat, weights, workQuat);
 
-
 		outMatrix.tx = blendedPos.x;
 		outMatrix.ty = blendedPos.y;
 		outMatrix.tz = blendedPos.z;

+ 7 - 3
hrt/animgraph/nodes/FloatParameter.hx

@@ -4,15 +4,19 @@ class FloatParameter extends Node {
 	@:output var value: Float;
 	public var parameter: hrt.animgraph.AnimGraph.Parameter;
 
+	#if editor
 	override function canCreateManually() : Bool {
 		return false;
 	}
 
+	override function getOutputNameOverride(name: String) : String {
+		return parameter?.name ?? "undefined";
+	}
+	#end
+
 	override function tick(dt: Float) : Void {
 		value = parameter?.runtimeValue ?? 0;
 	}
 
-	override function getOutputNameOverride(name: String) : String {
-		return parameter?.name ?? "undefined";
-	}
+
 }

+ 4 - 0
hrt/animgraph/nodes/Input.hx

@@ -36,7 +36,11 @@ class Input extends AnimNode {
 	override function getBoneTransform(id: Int, matrix: h3d.Matrix, ctx: AnimNode.GetBoneTransformContext) {
 		// todo : add sync outside the getBoneMatrix to avoid checks
 		@:privateAccess
+
 		if (!anim.isSync) {
+			// anim.getObjects()[id].targetObject.defaultTransform._14 = ctx.getDefPose()._41;
+			// anim.getObjects()[id].targetObject.defaultTransform._24 = ctx.getDefPose()._42;
+			// anim.getObjects()[id].targetObject.defaultTransform._34 = ctx.getDefPose()._43;
 			anim.sync(true);
 			anim.isSync = true;
 		}

+ 7 - 3
hrt/animgraph/nodes/Output.hx

@@ -11,6 +11,7 @@ class Output extends AnimNode {
 		// update out using inputs
 	}
 
+	#if editor
 	override function getInfo():hide.view.GraphInterface.GraphNodeInfo {
 		var info = super.getInfo();
 		info.dontAddRemove = true;
@@ -22,6 +23,11 @@ class Output extends AnimNode {
 		return Node.SIZE_SMALL;
 	}
 
+	override function canCreateManually():Bool {
+		return false;
+	}
+	#end
+
 	override function getBones(ctx:hrt.animgraph.nodes.AnimNode.GetBoneContext):Map<String, Int> {
 		return a.getBones(ctx);
 	}
@@ -30,7 +36,5 @@ class Output extends AnimNode {
 		return a.getBoneTransform(boneId, outMatrix, ctx);
 	}
 
-	override function canCreateManually():Bool {
-		return false;
-	}
+
 }