Browse Source

hsd prefab

ncannasse 7 years ago
parent
commit
8685337592
4 changed files with 50 additions and 1 deletions
  1. 8 0
      hide/prefab/Context.hx
  2. 40 0
      hide/prefab/Scene.hx
  3. 1 0
      hide/ui/Ide.hx
  4. 1 1
      hide/view/Prefab.hx

+ 8 - 0
hide/prefab/Context.hx

@@ -45,11 +45,19 @@ class Context {
 	}
 
 	public function loadModel( path : String ) {
+		#if editor
+		return hide.comp.Scene.getCurrent().loadModel(path);
+		#else
 		return @:privateAccess shared.cache.loadModel(hxd.res.Loader.currentInstance.load(path).toModel());
+		#end
 	}
 
 	public function loadAnimation( path : String ) {
+		#if editor
+		return hide.comp.Scene.getCurrent().loadAnimation(path);
+		#else
 		return @:privateAccess shared.cache.loadAnimation(hxd.res.Loader.currentInstance.load(path).toModel());
+		#end
 	}
 
 	public function locateObject( path : String ) {

+ 40 - 0
hide/prefab/Scene.hx

@@ -0,0 +1,40 @@
+package hide.prefab;
+
+class Scene extends Prefab {
+
+	override function load(obj:Dynamic) {
+	}
+
+	override function save() {
+		return {};
+	}
+
+	override function makeInstance( ctx : Context ) {
+		#if editor
+		var scene = hide.comp.Scene.getCurrent();
+		var obj = scene.loadModel(source, true);
+		var cam = @:privateAccess scene.defaultCamera;
+
+		// allow to add sub elements relative to camera target
+		var root = new h3d.scene.Object(ctx.local3d);
+		root.x = cam.target.x;
+		root.y = cam.target.y;
+		root.z = cam.target.z;
+		obj.x -= root.x;
+		obj.y -= root.y;
+		obj.z -= root.z;
+		root.addChild(obj);
+
+		ctx = ctx.clone(this);
+		ctx.local3d = root;
+		#end
+		return ctx;
+	}
+
+	override function getHideProps() {
+		return { icon : "cube", name : "Scene", fileSource : ["hsd"] };
+	}
+
+	static var _ = Library.register("scene", Scene);
+
+}

+ 1 - 0
hide/ui/Ide.hx

@@ -528,6 +528,7 @@ class Ide {
 	public static var inst : Ide;
 
 	static function main() {
+		h3d.pass.ShaderManager.STRICT = false; // prevent errors with bad renderer
 		hide.tools.Macros.include(["hide.view","h3d.prim","h3d.scene","h3d.pass","hide.prefab"]);
 		new Ide();
 	}

+ 1 - 1
hide/view/Prefab.hx

@@ -264,6 +264,6 @@ class Prefab extends FileView {
 		}
 	}
 
-	static var _ = FileTree.registerExtension(Prefab,["prf"],{ icon : "sitemap", createNew : "Prefab" });
+	static var _ = FileTree.registerExtension(Prefab,["pref"],{ icon : "sitemap", createNew : "Prefab" });
 
 }