Browse Source

moved ranges handling from instance to object3D

Nicolas Cannasse 4 years ago
parent
commit
a0167ef2e7
3 changed files with 43 additions and 49 deletions
  1. 2 2
      hide/comp/SceneEditor.hx
  2. 41 0
      hrt/prefab/Object3D.hx
  3. 0 47
      hrt/prefab/l3d/Instance.hx

+ 2 - 2
hide/comp/SceneEditor.hx

@@ -1456,8 +1456,8 @@ class SceneEditor {
 			editor.fileView = view;
 			editor.fileView = view;
 			editor.onChange = function(pname) {
 			editor.onChange = function(pname) {
 				edit.onChange(e, 'props.$pname');
 				edit.onChange(e, 'props.$pname');
-				var e = Std.instance(e, hrt.prefab.l3d.Instance);
-				if( e != null ) e.addRanges(context.shared.contexts.get(e));
+				var e = Std.instance(e, Object3D);
+				if( e != null ) e.addEditorUI(context.shared.contexts.get(e));
 			}
 			}
 		}
 		}
 	}
 	}

+ 41 - 0
hrt/prefab/Object3D.hx

@@ -133,6 +133,9 @@ class Object3D extends Prefab {
 		var o = ctx.local3d;
 		var o = ctx.local3d;
 		applyTransform(o);
 		applyTransform(o);
 		o.visible = visible;
 		o.visible = visible;
+		#if editor
+		addEditorUI(ctx);
+		#end
 	}
 	}
 
 
 	override function removeInstance(ctx: Context):Bool {
 	override function removeInstance(ctx: Context):Bool {
@@ -156,6 +159,8 @@ class Object3D extends Prefab {
 
 
 		var shader = new h3d.shader.FixedColor(0xffffff);
 		var shader = new h3d.shader.FixedColor(0xffffff);
 		for( m in materials ) {
 		for( m in materials ) {
+			if( m.name != null && StringTools.startsWith(m.name,"$UI.") )
+				continue;
 			var p = m.allocPass("highlight");
 			var p = m.allocPass("highlight");
 			p.culling = None;
 			p.culling = None;
 			p.depthWrite = false;
 			p.depthWrite = false;
@@ -164,6 +169,42 @@ class Object3D extends Prefab {
 		return true;
 		return true;
 	}
 	}
 
 
+	public function addEditorUI( ctx : Context ) {
+		for( r in ctx.shared.getObjects(this,h3d.scene.Object) )
+			if( r.name != null && StringTools.startsWith(r.name,"$UI.") )
+				r.remove();
+		// add ranges
+		var shared = Std.downcast(ctx.shared, hide.prefab.ContextShared);
+		if( shared != null && shared.editorDisplay ) {
+			var sheet = getCdbType();
+			if( sheet != null ) {
+				var ranges = Reflect.field(shared.scene.config.get("sceneeditor.ranges"), sheet);
+				if( ranges != null ) {
+					for( key in Reflect.fields(ranges) ) {
+						var color = Std.parseInt(Reflect.field(ranges,key));
+						var value : Dynamic = props;
+						for( p in key.split(".") )
+							value = Reflect.field(value, p);
+						if( value != null ) {
+							var mesh = new h3d.scene.Mesh(h3d.prim.Cylinder.defaultUnitCylinder(128), ctx.local3d);
+							mesh.name = "$UI.RANGE";
+							mesh.ignoreCollide = true;
+							mesh.ignoreBounds = true;
+							mesh.material.mainPass.culling = None;
+							mesh.material.name = "$UI.RANGE";
+							mesh.setScale(value * 2);
+							mesh.scaleZ = 0.1;
+							mesh.material.color.setColor(color|0xFF000000);
+							mesh.material.mainPass.enableLights = false;
+							mesh.material.shadows = false;
+							mesh.material.mainPass.setPassName("overlay");
+						}
+					}
+				}
+			}
+		}
+	}
+
 	override function makeInteractive( ctx : Context ) : hxd.SceneEvents.Interactive {
 	override function makeInteractive( ctx : Context ) : hxd.SceneEvents.Interactive {
 		var local3d = ctx.local3d;
 		var local3d = ctx.local3d;
 		if(local3d == null)
 		if(local3d == null)

+ 0 - 47
hrt/prefab/l3d/Instance.hx

@@ -43,56 +43,9 @@ class Instance extends Object3D {
 			var bmp = new h2d.Bitmap(tile, objFollow);
 			var bmp = new h2d.Bitmap(tile, objFollow);
 			ctx.local2d = objFollow;
 			ctx.local2d = objFollow;
 		}
 		}
-		addRanges(ctx, true);
 		return ctx;
 		return ctx;
 	}
 	}
 
 
-	public function addRanges( ctx : Context, init = false ) {
-		if( !init ) {
-			for( r in ctx.shared.getObjects(this,h3d.scene.Object) )
-				if( r.name == "RANGE")
-					r.remove();
-		}
-		// add ranges
-		var shared = Std.downcast(ctx.shared, hide.prefab.ContextShared);
-		if( shared != null && shared.editorDisplay ) {
-			var sheet = getCdbType();
-			if( sheet != null ) {
-				var ranges = Reflect.field(shared.scene.config.get("sceneeditor.ranges"), sheet);
-				if( ranges != null ) {
-					for( key in Reflect.fields(ranges) ) {
-						var color = Std.parseInt(Reflect.field(ranges,key));
-						var value : Dynamic = props;
-						for( p in key.split(".") )
-							value = Reflect.field(value, p);
-						if( value != null ) {
-							var mesh = new h3d.scene.Mesh(h3d.prim.Cylinder.defaultUnitCylinder(128), ctx.local3d);
-							mesh.name = "RANGE";
-							mesh.ignoreCollide = true;
-							mesh.ignoreBounds = true;
-							mesh.material.mainPass.culling = None;
-							mesh.material.name = "RANGE";
-							mesh.setScale(value * 2);
-							mesh.scaleZ = 0.1;
-							mesh.material.color.setColor(color|0xFF000000);
-							mesh.material.mainPass.enableLights = false;
-							mesh.material.shadows = false;
-							mesh.material.mainPass.setPassName("overlay");
-						}
-					}
-				}
-			}
-		}
-	}
-
-	override function setSelected(ctx:Context, b:Bool):Bool {
-		var b = super.setSelected(ctx, b);
-		for( m in ctx.shared.getMaterials(this) )
-			if( m.name == "RANGE" )
-				m.removePass(m.getPass("highlight"));
-		return b;
-	}
-
 	override function makeInteractive(ctx:Context):hxd.SceneEvents.Interactive {
 	override function makeInteractive(ctx:Context):hxd.SceneEvents.Interactive {
 		var int = super.makeInteractive(ctx);
 		var int = super.makeInteractive(ctx);
 		if( int == null ) {
 		if( int == null ) {