Browse Source

Add support for empty objects

trethaller 7 years ago
parent
commit
9afb722c1d
3 changed files with 32 additions and 14 deletions
  1. 13 13
      hide/prefab/Model.hx
  2. 15 0
      hide/prefab/Object3D.hx
  3. 4 1
      hide/view/Level3D.hx

+ 13 - 13
hide/prefab/Model.hx

@@ -19,22 +19,22 @@ class Model extends Object3D {
 	}
 
 	override function makeInstance(ctx:Context):Context {
+		if( source == null)
+			return super.makeInstance(ctx);
 		ctx = ctx.clone(this);
-		if( source != null ) {
-			try {
-				var obj = ctx.loadModel(source);
-				obj.name = name;
-				applyPos(obj);
-				ctx.local3d.addChild(obj);
-				ctx.local3d = obj;
+		try {
+			var obj = ctx.loadModel(source);
+			obj.name = name;
+			applyPos(obj);
+			ctx.local3d.addChild(obj);
+			ctx.local3d = obj;
 
-				if( animation != null )
-					obj.playAnimation(ctx.loadAnimation(animation));
+			if( animation != null )
+				obj.playAnimation(ctx.loadAnimation(animation));
 
-				return ctx;
-			} catch( e : hxd.res.NotFound ) {
-				ctx.onError(e);
-			}
+			return ctx;
+		} catch( e : hxd.res.NotFound ) {
+			ctx.onError(e);
 		}
 		ctx.local3d = new h3d.scene.Object(ctx.local3d);
 		ctx.local3d.name = name;

+ 15 - 0
hide/prefab/Object3D.hx

@@ -29,6 +29,14 @@ class Object3D extends Prefab {
 		visible = obj.visible == null ? true : obj.visible;
 	}
 
+	override function makeInstance(ctx:Context):Context {
+		ctx = ctx.clone(this);
+		ctx.local3d = new h3d.scene.Object(ctx.local3d);
+		ctx.local3d.name = name;
+		applyPos(ctx.local3d);
+		return ctx;
+	}
+	
 	override function save() {
 		var o : Dynamic = {};
 		if( x != 0 ) o.x = x;
@@ -93,4 +101,11 @@ class Object3D extends Prefab {
 		#end
 	}
 
+
+	override function getHideProps() {
+		return { icon : "genderless", name : "Empty", fileSource : null };
+	}
+
+	static var _ = Library.register("object", Object3D);
+
 }

+ 4 - 1
hide/view/Level3D.hx

@@ -390,6 +390,9 @@ class Level3D extends FileView {
 	function autoName(p : PrefabElement) {
 		var id = 0;
 		var prefix = p.type;
+		if(prefix == "object")
+			prefix = "group";
+			
 		var model = Std.instance(p, hide.prefab.Model);
 		if(model != null && model.source != null) {
 			var path = new haxe.io.Path(model.source);
@@ -635,7 +638,7 @@ class Level3D extends FileView {
 
 			var registered = new Array<hide.comp.ContextMenu.ContextMenuItem>();
 			var allRegs = @:privateAccess hide.prefab.Library.registeredElements;
-			var allowed = ["model"];
+			var allowed = ["model", "object"];
 			for( ptype in allRegs.keys() ) {
 				if( allowed.indexOf(ptype) < 0 ) continue;
 				var pcl = allRegs.get(ptype);