Explorar o código

L3D: Better support for referenced prefabs, including sub-l3ds

trethaller %!s(int64=7) %!d(string=hai) anos
pai
achega
20cad4bfa7
Modificáronse 4 ficheiros con 48 adicións e 40 borrados
  1. 1 1
      hide/comp/SceneEditor.hx
  2. 20 10
      hide/prefab/Reference.hx
  3. 26 28
      hide/prefab/l3d/Instance.hx
  4. 1 1
      hide/view/l3d/Level3D.hx

+ 1 - 1
hide/comp/SceneEditor.hx

@@ -826,7 +826,7 @@ class SceneEditor {
 			var obj3d : Object3D;
 			var obj3d : Object3D;
 			var relative = ide.makeRelative(path);
 			var relative = ide.makeRelative(path);
 
 
-			if(StringTools.endsWith(path, ".fx")) {
+			if(hxd.prefab.Library.getPrefabType(path) != null) {
 				var ref = new hide.prefab.Reference(parent);
 				var ref = new hide.prefab.Reference(parent);
 				ref.refpath = "/" + relative;
 				ref.refpath = "/" + relative;
 				obj3d = ref;
 				obj3d = ref;

+ 20 - 10
hide/prefab/Reference.hx

@@ -33,13 +33,15 @@ class Reference extends Object3D {
 		if(refpath == null)
 		if(refpath == null)
 			return null;
 			return null;
 		if(isFile()) {
 		if(isFile()) {
-			#if editor
-			if(shared == null) // Allow resolving ref in Hide prefore makeInstance 
+			if(shared == null) { // Allow resolving ref in Hide prefore makeInstance 
+				#if editor
 				ref = hide.Ide.inst.loadPrefab(refpath.substr(1));
 				ref = hide.Ide.inst.loadPrefab(refpath.substr(1));
+				#else
+				return null;
+				#end
+			}
 			else
 			else
-			#else
-			ref = shared.loadPrefab(refpath.substr(1));
-			#end
+				ref = shared.loadPrefab(refpath.substr(1));
 			return ref;
 			return ref;
 		}
 		}
 		else {
 		else {
@@ -72,11 +74,18 @@ class Reference extends Object3D {
 		if(p == null)
 		if(p == null)
 			return ctx;
 			return ctx;
 
 
-		ctx = ctx.clone(this);
-		ctx.isRef = true;
-		var refCtx = p.makeInstance(ctx);
-		ctx.local3d = refCtx.local3d;
-		updateInstance(ctx);
+		if(isFile()) {
+			ctx = super.makeInstance(ctx);
+			p.makeInstance(ctx);
+		}
+		else {
+			ctx = ctx.clone(this);
+			ctx.isRef = true;
+			var refCtx = p.makeInstanceRec(ctx);
+			ctx.local3d = refCtx.local3d;
+			updateInstance(ctx);
+		}
+		
 		return ctx;
 		return ctx;
 	}
 	}
 
 
@@ -89,6 +98,7 @@ class Reference extends Object3D {
 		return Std.instance(p, c);
 		return Std.instance(p, c);
 	}
 	}
 
 
+
 	#if editor
 	#if editor
 
 
 
 

+ 26 - 28
hide/prefab/l3d/Instance.hx

@@ -19,7 +19,7 @@ class Instance extends Object3D {
 		var modelPath = findModelPath(kind.sheet, kind.idx.obj);
 		var modelPath = findModelPath(kind.sheet, kind.idx.obj);
 		if(modelPath != null) {
 		if(modelPath != null) {
 			try {
 			try {
-				if(modelPath.indexOf(".prefab") > 0) {
+				if(hxd.prefab.Library.getPrefabType(modelPath) != null) {
 					var ref = ctx.shared.loadPrefab(modelPath);
 					var ref = ctx.shared.loadPrefab(modelPath);
 					var ctx = ctx.clone(this);
 					var ctx = ctx.clone(this);
 					ctx.isRef = true;
 					ctx.isRef = true;
@@ -50,20 +50,6 @@ class Instance extends Object3D {
 		return ctx;
 		return ctx;
 	}
 	}
 
 
-	#if editor
-
-	override function edit( ctx : EditContext ) {
-		super.edit(ctx);
-		var sheet = getCdbModel();
-		if( sheet == null ) return;
-		//ctx.properties.addProps([for(c in sheet.columns) {t: getPropType(c), name: c.name}], this.props);
-	}
-
-	override function getHideProps() : HideProps {
-		return { icon : "circle", name : "Instance" };
-	}
-
-	// Move to Prefab?
 	public static function getCdbKind(p: Prefab) {
 	public static function getCdbKind(p: Prefab) {
 		if(p.props == null)
 		if(p.props == null)
 			return null;
 			return null;
@@ -97,22 +83,11 @@ class Instance extends Object3D {
 		return refSheet.columns.find(c -> c.type == cdb.Data.ColumnType.TId);
 		return refSheet.columns.find(c -> c.type == cdb.Data.ColumnType.TId);
 	}
 	}
 
 
-	static function getModel(refSheet : cdb.Sheet, obj : Dynamic) {
-		var path = findModelPath(refSheet, obj);
-		if(path == null)
-			return null;
-		try {
-			var model = hxd.res.Loader.currentInstance.load(path).toModel();
-			return model;
-		} catch( e : hxd.res.NotFound ) {}
-		return null;
-	}
-
-	static function findModelPath(refSheet : cdb.Sheet, obj : Dynamic) {
+	public static function findModelPath(refSheet : cdb.Sheet, obj : Dynamic) {
 		function filter(f: String) {
 		function filter(f: String) {
 			if(f != null) {
 			if(f != null) {
 				var lower = f.toLowerCase();
 				var lower = f.toLowerCase();
-				if(StringTools.endsWith(lower, ".fbx") || StringTools.endsWith(lower, ".prefab"))
+				if(StringTools.endsWith(lower, ".fbx") || hxd.prefab.Library.getPrefabType(lower) != null)
 					return f;
 					return f;
 			}
 			}
 			return null;
 			return null;
@@ -141,6 +116,29 @@ class Instance extends Object3D {
 		return path;
 		return path;
 	}
 	}
 
 
+	#if editor
+
+	override function edit( ctx : EditContext ) {
+		super.edit(ctx);
+		var sheet = getCdbModel();
+		if( sheet == null ) return;
+	}
+
+	override function getHideProps() : HideProps {
+		return { icon : "circle", name : "Instance" };
+	}
+
+	static function getModel(refSheet : cdb.Sheet, obj : Dynamic) {
+		var path = findModelPath(refSheet, obj);
+		if(path == null)
+			return null;
+		try {
+			var model = hxd.res.Loader.currentInstance.load(path).toModel();
+			return model;
+		} catch( e : hxd.res.NotFound ) {}
+		return null;
+	}
+
 	static function findTile(refSheet : cdb.Sheet, obj : Dynamic) {
 	static function findTile(refSheet : cdb.Sheet, obj : Dynamic) {
 		var tileCol = refSheet.columns.find(c -> c.type == cdb.Data.ColumnType.TTilePos);
 		var tileCol = refSheet.columns.find(c -> c.type == cdb.Data.ColumnType.TTilePos);
 		if(tileCol != null) {
 		if(tileCol != null) {

+ 1 - 1
hide/view/l3d/Level3D.hx

@@ -513,7 +513,7 @@ class Level3D extends FileView {
 	}
 	}
 
 
 	override function onDragDrop(items : Array<String>, isDrop : Bool) {
 	override function onDragDrop(items : Array<String>, isDrop : Bool) {
-		var supported = ["fbx", "fx"];
+		var supported = ["fbx", "fx", "l3d", "prefab"];
 		var paths = [];
 		var paths = [];
 		for(path in items) {
 		for(path in items) {
 			var ext = haxe.io.Path.extension(path).toLowerCase();
 			var ext = haxe.io.Path.extension(path).toLowerCase();