ソースを参照

Prevent shaders from being undesirably added on same object multiple times.

clementlandrin 2 年 前
コミット
c30a40501c
1 ファイル変更9 行追加5 行削除
  1. 9 5
      hrt/prefab/Shader.hx

+ 9 - 5
hrt/prefab/Shader.hx

@@ -87,18 +87,22 @@ class Shader extends Prefab {
 				for( m in material.getMaterials(ctx) )
 					callb(null, m);
 		} else {
-			var objs;
+			var objs = [];
+			function pushUnique(obj : h3d.scene.Object ) {
+				for ( o in objs )
+					if ( o == obj )
+						return;
+				objs.push(obj);
+			}
 			if( recursiveApply ) {
-				objs = [];
 				for( c in parent.flatten() )
 					for( o in shared.getObjects(c, h3d.scene.Object) )
-						objs.push(o);
+						pushUnique(o);
 			} else if( parent.type == "object" ) {
 				// apply to all immediate children
-				objs = [];
 				for( c in parent.children )
 					for( o in shared.getObjects(c, h3d.scene.Object) )
-						objs.push(o);
+						pushUnique(o);
 			} else
 				objs = shared.getObjects(parent, h3d.scene.Object);
 			for( obj in objs )