2
0
Эх сурвалжийг харах

[editor] Exposed Edtor3DIcon to non editor builds

Clément Espeute 2 сар өмнө
parent
commit
ea88a775dc

+ 26 - 25
hrt/impl/EditorTools.hx

@@ -1,24 +1,24 @@
 package hrt.impl;
 
-#if editor
-
 class EditorIcon extends hrt.prefab.l3d.Billboard.BillboardObj {
-    public var scaleWithParent = false;
-	public var category : IconCategory;
+	public var scaleWithParent = false;
+	public var category:IconCategory;
 
-	public function new(?tile : h3d.mat.Texture,  ?parent : h3d.scene.Object, category: IconCategory) {
+	public function new(?tile:h3d.mat.Texture, ?parent:h3d.scene.Object, category:IconCategory) {
 		super(tile, parent);
 		ignoreCollide = false;
 		this.category = category;
 	}
 
 	override function sync(ctx) {
-        visible =  EditorTools.isVisible(category);
-        super.sync(ctx);
-    }
+		#if editor
+		visible = EditorTools.isVisible(category);
+		#end
+		super.sync(ctx);
+	}
 
 	override function getLocalCollider():h3d.col.Collider {
-		return new h3d.col.Sphere(0,0,0,billboardScale/2.0);
+		return new h3d.col.Sphere(0, 0, 0, billboardScale / 2.0);
 	}
 
 	// Ingonre scale and rotation
@@ -34,26 +34,26 @@ class EditorIcon extends hrt.prefab.l3d.Billboard.BillboardObj {
 			absPos.tz += parent.absPos.tz;
 		}
 
-		if( invPos != null )
+		if (invPos != null)
 			invPos._44 = 0; // mark as invalid
 	}
 }
 
 class Editor2DIcon extends h2d.ObjectFollower {
-	public var category : IconCategory;
+	public var category:IconCategory;
 
-
-	public function new( obj, ?parent, texture, category: IconCategory)  {
+	public function new(obj, ?parent, texture, category:IconCategory) {
 		super(obj, parent);
 		horizontalAlign = Middle;
 		followVisibility = true;
 		var ico = new h2d.Bitmap(h2d.Tile.fromTexture(texture), this);
 		this.category = category;
-
 	}
 
 	override function sync(ctx) {
+		#if editor
 		visible = EditorTools.isVisible(category);
+		#end
 		super.sync(ctx);
 	}
 }
@@ -66,22 +66,23 @@ enum IconCategory {
 	Misc;
 }
 
+#if editor
 class EditorTools {
 	// Create a 3d Icon that will be displayed inside the scene as a 3d object, meaning that it can be
 	// obscured by the other objects
-    public static function create3DIcon(object:h3d.scene.Object, iconPath:String, scale:Float = 1.0, category: IconCategory) : EditorIcon {
+	public static function create3DIcon(object:h3d.scene.Object, iconPath:String, scale:Float = 1.0, category:IconCategory):EditorIcon {
 		var ide = hide.Ide.inst;
-        var tex = ide.getTexture(iconPath);
-        var icon = new EditorIcon(tex, object, category);
+		var tex = ide.getTexture(iconPath);
+		var icon = new EditorIcon(tex, object, category);
 
-        icon.texture = tex;
+		icon.texture = tex;
 		icon.billboardScale = scale;
 
-        return icon;
-    }
+		return icon;
+	}
 
 	// Creates a 2d Icon that will be displayed in front of all the other icons
-	public static function create2DIcon(object: h3d.scene.Object, s2d: h2d.Object, iconPath: String, category: IconCategory) : Editor2DIcon {
+	public static function create2DIcon(object:h3d.scene.Object, s2d:h2d.Object, iconPath:String, category:IconCategory):Editor2DIcon {
 		var ide = hide.Ide.inst;
 		return new Editor2DIcon(object, s2d, ide.getTexture(iconPath), category);
 	}
@@ -90,7 +91,7 @@ class EditorTools {
 		for (categoryName in haxe.EnumTools.getConstructors(IconCategory)) {
 			var category = haxe.EnumTools.createByName(IconCategory, categoryName, []);
 			var ide = hide.Ide.inst;
-			if(!ide.show3DIconsCategory.exists(category)) {
+			if (!ide.show3DIconsCategory.exists(category)) {
 				var value = js.Browser.window.localStorage.getItem(iconVisibilityKey(category));
 				var shouldBeDisplayed = false;
 				if (value == null || value == "true") {
@@ -101,12 +102,12 @@ class EditorTools {
 		}
 	}
 
-	public static function iconVisibilityKey(category: IconCategory) {
+	public static function iconVisibilityKey(category:IconCategory) {
 		return "3dIconVisibility/" + haxe.EnumTools.EnumValueTools.getName(category);
 	}
 
-	public static function isVisible(category: IconCategory) : Bool {
+	public static function isVisible(category:IconCategory):Bool {
 		return hide.Ide.inst.show3DIcons && hide.Ide.inst.show3DIconsCategory.get(category);
 	}
 }
-#end
+#end

+ 58 - 76
hrt/prefab/l3d/Billboard.hx

@@ -1,98 +1,80 @@
 package hrt.prefab.l3d;
 
 class BillboardShader extends hxsl.Shader {
-
 	static var SRC = {
-
-		@param var scale : Float;
-
+		@param var scale:Float;
 		@:import h3d.shader.BaseMesh;
-
-        function vertex() {
-            var newModelView = mat4(
-                vec4(camera.view[0].x, camera.view[1].x, camera.view[2].x, global.modelView[0].w),
-                vec4(camera.view[0].y, camera.view[1].y, camera.view[2].y, global.modelView[1].w),
-                vec4(camera.view[0].z, camera.view[1].z, camera.view[2].z, global.modelView[2].w),
-                vec4(0, 0, 0, 1)
-            );
-
-            // scale
-            newModelView = mat4(
-                vec4(scale /*length(global.modelView[0].xyz)*/, 0.0, 0.0, 0.0),
-                vec4(0.0, scale /*length(global.modelView[1].xyz)*/, 0.0, 0.0),
-                vec4(0.0, 0.0, scale /*length(global.modelView[2].xyz)*/, 0.0),
-                vec4(0.0, 0.0, 0.0, 1.0)
-            ) * newModelView;
-
-            // Fix rotation
-            newModelView = mat4(
-                vec4(1,0,0,0),
-                vec4(0,-1,0,0),
-                vec4(0,0,-1,0),
-                vec4(0,0,0,1)) * newModelView;
-
-            transformedPosition = relativePosition * newModelView.mat3x4();
-            transformedNormal = (input.normal * newModelView.mat3()).normalize();
-        }
+		function vertex() {
+			var newModelView = mat4(
+				vec4(camera.view[0].x, camera.view[1].x, camera.view[2].x, global.modelView[0].w),
+				vec4(camera.view[0].y, camera.view[1].y, camera.view[2].y, global.modelView[1].w),
+				vec4(camera.view[0].z, camera.view[1].z, camera.view[2].z, global.modelView[2].w),
+				vec4(0, 0, 0, 1));
+
+			// scale
+			newModelView = mat4(
+				vec4(scale /*length(global.modelView[0].xyz)*/, 0.0, 0.0, 0.0),
+				vec4(0.0, scale /*length(global.modelView[1].xyz)*/, 0.0, 0.0),
+				vec4(0.0, 0.0, scale /*length(global.modelView[2].xyz)*/, 0.0),
+				vec4(0.0, 0.0, 0.0, 1.0)) * newModelView;
+
+			// Fix rotation
+			newModelView = mat4(vec4(1, 0, 0, 0), vec4(0, -1, 0, 0), vec4(0, 0, -1, 0), vec4(0, 0, 0, 1)) * newModelView;
+
+			transformedPosition = relativePosition * newModelView.mat3x4();
+			transformedNormal = (input.normal * newModelView.mat3()).normalize();
+		}
 	};
-
 }
 
-
 class BillboardObj extends h3d.scene.Mesh {
+	var prim:h3d.prim.Polygon;
+	var shader:BillboardShader;
 
-    var prim : h3d.prim.Polygon;
-    var shader : BillboardShader;
-	public var billboardScale : Float = 1.0;
+	public var billboardScale:Float = 1.0;
 
-    public var texture(get, set) : h3d.mat.Texture;
+	public var texture(get, set):h3d.mat.Texture;
 
-    function set_texture(tex : h3d.mat.Texture) : h3d.mat.Texture {
-        return material.texture = tex;
-    }
+	function set_texture(tex:h3d.mat.Texture):h3d.mat.Texture {
+		return material.texture = tex;
+	}
 
-    function get_texture() : h3d.mat.Texture {
-        return material.texture;
-    }
+	function get_texture():h3d.mat.Texture {
+		return material.texture;
+	}
 
-    public var color(get, set) : h3d.Vector4;
+	public var color(get, set):h3d.Vector4;
 
-    function set_color(col : h3d.Vector4) : h3d.Vector4 {
-        return material.color = col;
-    }
+	function set_color(col:h3d.Vector4):h3d.Vector4 {
+		return material.color = col;
+	}
 
-    function get_color() : h3d.Vector4 {
-        return material.color;
-    }
+	function get_color():h3d.Vector4 {
+		return material.color;
+	}
 
 	override function sync(ctx:h3d.scene.RenderContext) {
 		shader.scale = billboardScale;
 		super.sync(ctx);
 	}
 
-    public function new(?tile : h3d.mat.Texture,  ?parent : h3d.scene.Object) {
-        var shape : hrt.prefab.l3d.Polygon.Shape = Quad(0);
-        var cache = hrt.prefab.l3d.Polygon.getPrimCache();
-        prim = cache.get(shape);
-        if(prim == null)
-            prim = Polygon.createPrimitive(shape);
-        super(prim, null, parent);
-
-        shader = new BillboardShader();
-        material.mainPass.addShader(shader);
-        material.mainPass.setBlendMode(Alpha);
-        material.props = {
-                mode: "Overlay",
-                blend: "Alpha",
-                shadows: false,
-                culling: "Back",
-                colorMask: 0xff,
-            };
-        material.refreshProps();
-    }
-
-    /* ignore parent shaders hack*/
-	override public function getMaterials( ?a : Array<h3d.mat.Material>, recursive = true ) {
-        return [];
-    }
-}
+	public function new(?tile:h3d.mat.Texture, ?parent:h3d.scene.Object) {
+		var shape:hrt.prefab.l3d.Polygon.Shape = Quad(0);
+		var cache = hrt.prefab.l3d.Polygon.getPrimCache();
+		prim = cache.get(shape);
+		if (prim == null)
+			prim = Polygon.createPrimitive(shape);
+		super(prim, null, parent);
+
+		shader = new BillboardShader();
+		material.mainPass.addShader(shader);
+		material.mainPass.setBlendMode(Alpha);
+		material.mainPass.setPassName("afterTonemapping");
+		texture = tile;
+	}
+
+	/* ignore parent shaders hack*/
+	override public function getMaterials(?a:Array<h3d.mat.Material>, recursive = true) {
+		return [];
+	}
+}