Browse Source

added sceneeditor.huds to display cdb icons on top of 3D objects + follow paths for ranges

Nicolas Cannasse 4 years ago
parent
commit
c76cdf02fa
3 changed files with 55 additions and 3 deletions
  1. 1 0
      bin/defaultProps.json
  2. 35 0
      hide/Ide.hx
  3. 19 3
      hrt/prefab/Object3D.hx

+ 1 - 0
bin/defaultProps.json

@@ -117,6 +117,7 @@
 
 	"sceneeditor.icons" : {},
 	"sceneeditor.ranges" : {},
+	"sceneeditor.huds" : {},
 
 	// l3d config
 	"l3d.groundLayer": "ground",

+ 35 - 0
hide/Ide.hx

@@ -494,6 +494,41 @@ class Ide {
 		return resourceDir+"/"+relPath;
 	}
 
+	public function resolveCDBValue( path : String, obj : Dynamic ) : Dynamic {
+		var path = path.split(".");
+		var sheet = database.getSheet(path.shift());
+		if( sheet == null )
+			return null;
+		while( path.length > 0 && sheet != null ) {
+			var f = path.shift();
+			var value = Reflect.field(obj, f);
+			if( value == null )
+				return null;
+			var current = sheet;
+			sheet = null;
+			for( c in current.columns ) {
+				if( c.name == f ) {
+					switch( c.type ) {
+					case TRef(name):
+						sheet = database.getSheet(name);
+						var ref = sheet.index.get(value);
+						if( ref == null )
+							return null;
+						value = ref.obj;
+					case TProperties:
+						sheet = current.getSub(c);
+					default:
+					}
+					break;
+				}
+			}
+			obj = value;
+		}
+		for( f in path )
+			obj = Reflect.field(obj, f);
+		return obj;
+	}
+
 	var showErrors = true;
 	public function error( e : Dynamic ) {
 		if( showErrors && !js.Browser.window.confirm(e) )

+ 19 - 3
hrt/prefab/Object3D.hx

@@ -178,13 +178,12 @@ class Object3D extends Prefab {
 		if( shared != null && shared.editorDisplay ) {
 			var sheet = getCdbType();
 			if( sheet != null ) {
+				var ide = hide.Ide.inst;
 				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);
+						var value : Dynamic = ide.resolveCDBValue(sheet+"."+key, props);
 						if( value != null ) {
 							var mesh = new h3d.scene.Mesh(h3d.prim.Cylinder.defaultUnitCylinder(128), ctx.local3d);
 							mesh.name = "$UI.RANGE";
@@ -201,6 +200,23 @@ class Object3D extends Prefab {
 						}
 					}
 				}
+				var icon : String = Reflect.field(shared.scene.config.get("sceneeditor.huds"), sheet);
+				if( icon != null ) {
+					var t : cdb.Types.TilePos = ide.resolveCDBValue(sheet+"."+icon, props);
+					if( t != null && t.file != null ) {
+						var obj = Std.downcast(ctx.local2d, h2d.ObjectFollower);
+						if( obj == null || obj.follow != ctx.local3d )
+							ctx.local2d = obj = new h2d.ObjectFollower(ctx.local3d, ctx.local2d);
+						var bmp = cast(obj.getChildAt(0), h2d.Bitmap);
+						if( bmp == null ) bmp = new h2d.Bitmap(null, obj);
+						bmp.tile = h2d.Tile.fromTexture(ctx.loadTexture(t.file)).sub(
+							t.x * t.size,
+							t.y * t.size,
+							(t.width == null ? 1 : t.width) * t.size,
+							(t.height == null ? 1 : t.height) * t.size
+						).center();
+					}
+				}
 			}
 		}
 	}