浏览代码

New hide prefab system compat for heaps (-D prefab2) (#1151)

Valden 2 年之前
父节点
当前提交
87dd7866d2
共有 2 个文件被更改,包括 30 次插入0 次删除
  1. 26 0
      h3d/prim/ModelCache.hx
  2. 4 0
      hxd/fmt/hmd/Library.hx

+ 26 - 0
h3d/prim/ModelCache.hx

@@ -148,6 +148,31 @@ class ModelCache {
 	#if hide
 
 	public function loadPrefab( res : hxd.res.Prefab, ?p : hrt.prefab.Prefab, ?parent : h3d.scene.Object ) {
+		#if prefab2
+		if( p == null )
+			p = res.load();
+		var prevChild = 0;
+		var local3d = null;
+		if( parent != null ) {
+			prevChild = parent.numChildren;
+			local3d = parent;
+		} else {
+			local3d = new h3d.scene.Object();
+		}
+		var ctx2 = p.make(parent);
+		if( parent != null ) {
+			// only return object if a single child was added
+			// if not - multiple children were added and cannot be returned as a single object
+			return parent.numChildren == prevChild + 1 ? parent.getChildAt(prevChild) : null;
+		}
+		if( local3d.numChildren == 1 ) {
+			// if we have a single root with no scale/rotate/offset we can return it
+			var obj = local3d.getChildAt(0);
+			if( obj.getTransform().isIdentity() )
+				return obj;
+		}
+		return local3d;
+		#else
 		if( p == null )
 			p = res.load();
 		var ctx = new hrt.prefab.Context();
@@ -171,6 +196,7 @@ class ModelCache {
 				return obj;
 		}
 		return ctx.local3d;
+		#end
 	}
 
 	#end

+ 4 - 0
hxd/fmt/hmd/Library.hx

@@ -754,9 +754,13 @@ class Library {
 			var shader = Std.downcast(c, hrt.prefab.Shader);
 			if ( shader == null )
 				continue;
+			#if prefab2
+			var s = shader.make().shader;
+			#else
 			shader.clone();
 			var ctx = new hrt.prefab.Context();
 			var s = shader.makeShader(ctx);
+			#end
 			@:privateAccess shader.applyShader(null, mat, s);
 		}
 		return true;