Kaynağa Gözat

FX2D : Placeholder + grid + some fixes

Tom Spira 6 yıl önce
ebeveyn
işleme
7876fc8300

+ 47 - 23
hide/view/FXEditor.hx

@@ -74,7 +74,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 
 		var menu = [];
 		if (@:privateAccess parent.is2D) {
-			for(name in ["Group 2D", "Bitmap", "Anim2D", "Atlas", "Text", "Shaders", "Shader Graph"]) {
+			for(name in ["Group 2D", "Bitmap", "Anim2D", "Atlas", "Text", "Shaders", "Shader Graph", "Placeholder"]) {
 				var item = allTypes.find(i -> i.label == name);
 				if(item == null) continue;
 				allTypes.remove(item);
@@ -118,12 +118,12 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 				]
 			});
 			menu.sort(function(l1,l2) return Reflect.compare(l1.label,l2.label));
-			menu.push({label: null, isSeparator: true});
-			menu.push({
-				label: "Other",
-				menu: allTypes
-			});
 		}
+		menu.push({label: null, isSeparator: true});
+		menu.push({
+			label: "Other",
+			menu: allTypes
+		});
 		return menu;
 	}
 }
@@ -151,6 +151,7 @@ class FXEditor extends FileView {
 	var lastSyncChange : Float = 0.;
 	var showGrid = true;
 	var grid : h3d.scene.Graphics;
+	var grid2d : h2d.Graphics;
 
 	var timelineLeftMargin = 10;
 	var xScale = 200.;
@@ -395,10 +396,10 @@ class FXEditor extends FileView {
 		axis.lineStyle(1,0x0000FF); axis.moveTo(0,0,0); axis.lineTo(0,0,1);
 		axis.lineStyle();
 		axis.material.mainPass.setPassName("debuggeom");
-		axis.visible = showGrid;
+		axis.visible = (!is2D) ? showGrid : false;
 
 		cullingPreview = new h3d.scene.Sphere(0xffffff, data.cullingRadius, true, scene.s3d);
-		cullingPreview.visible = showGrid;
+		cullingPreview.visible = (!is2D) ? showGrid : false;
 
 		tools.saveDisplayKey = "FXScene/tools";
 		tools.addButton("video-camera", "Perspective camera", () -> sceneEditor.resetCamera());
@@ -430,8 +431,8 @@ class FXEditor extends FileView {
 
 		tools.addToggle("th", "Show grid", function(v) {
 			showGrid = v;
-			axis.visible = v;
-			cullingPreview.visible = v;
+			axis.visible = (is2D) ? false : v;
+			cullingPreview.visible = (is2D) ? false : v;
 			updateGrid();
 		}, showGrid);
 		tools.addColor("Background color", function(v) {
@@ -449,7 +450,7 @@ class FXEditor extends FileView {
 
 		statusText = new h2d.Text(hxd.res.DefaultFont.get(), scene.s2d);
 		statusText.setPosition(5, 5);
-
+		
 		updateGrid();
 	}
 
@@ -1269,6 +1270,36 @@ class FXEditor extends FileView {
 			grid.remove();
 			grid = null;
 		}
+		if(grid2d != null) {
+			grid2d.remove();
+			grid2d = null;
+		}
+		if(!showGrid)
+			return;
+		if (is2D) {
+			grid2d = new h2d.Graphics(scene.s2d);
+			grid2d.x = scene.s2d.width / 2;
+			grid2d.y = scene.s2d.height / 2;
+			grid2d.scale(1);
+
+			grid2d.lineStyle(1.0, 12632256, 1.0);
+			grid2d.moveTo(0, -2000);
+			grid2d.lineTo(0, 2000);
+			grid2d.moveTo(-2000, 0);
+			grid2d.lineTo(2000, 0);
+			grid2d.lineStyle(1.0, 8421504, 1.0);
+			for(ix in -4...4) {
+				if (ix == 0) continue;
+				grid2d.moveTo(ix*200, -2000);
+				grid2d.lineTo(ix*200, 2000);
+				grid2d.moveTo(-2000, ix*200);
+				grid2d.lineTo(2000, ix*200);
+
+			}
+			grid2d.lineStyle(0);
+
+			return;
+		}
 
 		if(!showGrid)
 			return;
@@ -1314,9 +1345,6 @@ class FXEditor extends FileView {
 			if(currentTime >= previewMax) {
 				currentTime = previewMin;
 
-				//if(data.scriptCode != null && data.scriptCode.length > 0)
-					//sceneEditor.refreshScene(); // This allow to reset the scene when values are modified causes edition issues, solves
-
 				anim.setRandSeed(Std.random(0xFFFFFF));
 			}
 		}
@@ -1334,20 +1362,16 @@ class FXEditor extends FileView {
 			statusText.text = lines.join("\n");
 		}
 
-		var cam = scene.s3d.camera;
-		if( light != null ) {
-			var angle = Math.atan2(cam.target.y - cam.pos.y, cam.target.x - cam.pos.x);
-			light.setDirection(new h3d.Vector(
-				Math.cos(angle) * lightDirection.x - Math.sin(angle) * lightDirection.y,
-				Math.sin(angle) * lightDirection.x + Math.cos(angle) * lightDirection.y,
-				lightDirection.z
-			));
-		}
 		if( autoSync && (currentVersion != undo.currentID || lastSyncChange != properties.lastChange) ) {
 			save();
 			lastSyncChange = properties.lastChange;
 			currentVersion = undo.currentID;
 		}
+
+		if (grid2d != null) {
+			grid2d.x = scene.s2d.width / 2;
+			grid2d.y = scene.s2d.height / 2;
+		}
 	}
 
 	function onUpdate3D(dt:Float) {

+ 3 - 2
hrt/prefab/Object2D.hx

@@ -36,7 +36,8 @@ class Object2D extends Prefab {
 
 		visible = obj.visible == null ? true : obj.visible;
 		
-		blendMode = obj.blendMode == null ? None : std.Type.createEnum(h2d.BlendMode, obj.blendMode);
+		if (obj.blendMode != null)
+			blendMode = std.Type.createEnum(h2d.BlendMode, obj.blendMode);
 	}
 
 	override function makeInstance(ctx:Context):Context {
@@ -89,7 +90,7 @@ class Object2D extends Prefab {
 			o.visible = visible;
 
 		if(propName == null || propName == "blendMode")
-			o.blendMode = blendMode;
+			if (blendMode != null) o.blendMode = blendMode;
 	}
 
 	override function removeInstance(ctx: Context):Bool {

+ 1 - 2
hrt/prefab/Shader.hx

@@ -67,8 +67,7 @@ class Shader extends Prefab {
 			var drawable = Std.downcast(ctx.local2d, h2d.Drawable);
 			if (drawable != null)
 				drawable.addShader(shader);
-		}
-		if(ctx.local3d != null) {
+		} else if(ctx.local3d != null) {
 			for(m in ctx.local3d.getMaterials()) { // TODO: Only add to self materials, not all children materials
 				m.mainPass.addShader(shader);
 			}

+ 4 - 1
hrt/prefab/fx/BaseFX.hx

@@ -110,7 +110,10 @@ class BaseFX extends hrt.prefab.Library {
 					var curve = Curve.getCurve(shaderElt, v.name);
 					var val = Value.VConst(base);
 					if(curve != null)
-						val = Value.VCurveScale(curve, base);
+						if (base != 0.0)
+							val = Value.VCurveScale(curve, base);
+						else
+							val = Value.VCurve(curve);
 					ret.push({
 						def: v,
 						value: val

+ 10 - 23
hrt/prefab/fx/FX2D.hx

@@ -8,7 +8,6 @@ class FX2DAnimation extends h2d.Object {
 
 	public var prefab : hrt.prefab.Prefab;
 	public var onEnd : Void -> Void;
-	public var followVisibility : h3d.scene.Object;
 
 	public var playSpeed : Float;
 	public var localTime : Float = 0.0;
@@ -18,7 +17,6 @@ class FX2DAnimation extends h2d.Object {
 	public var loop : Bool;
 	public var objects: Array<ObjectAnimation> = [];
 	public var shaderAnims : Array<ShaderAnimation> = [];
-	public var constraints : Array<hrt.prefab.Constraint> = [];
 
 	var evaluator : Evaluator;
 	var random : hxd.Rand;
@@ -35,22 +33,6 @@ class FX2DAnimation extends h2d.Object {
 		random.init(seed);
 	}
 
-	public dynamic function customVisibility(self: FX2DAnimation) : Bool {
-		return true;
-	}
-
-	override function sync( ctx : h2d.RenderContext ) {
-		var visiblity : Bool = true;
-		if(followVisibility != null)
-			visiblity = visiblity && followVisibility.visible;
-		if(customVisibility != null)
-			visiblity = visiblity && customVisibility(this);
-
-		this.visible = visiblity;
-
-		super.sync(ctx);
-	}
-
 	public function setTime( time : Float ) {
 		
 		this.localTime = time;
@@ -95,10 +77,10 @@ class FX2DAnimation extends h2d.Object {
 				@:privateAccess if (!atlas.loop) {
 					var t = time - atlas.delayStart;
 					if (t < 0) {
-						atlas.h2dAnim.curFrame = 0;
+						(cast anim.obj2d : h2d.Anim).curFrame = 0;
 					} else {
 						var nbFrames = Math.floor(t*atlas.fpsAnimation);
-						atlas.h2dAnim.curFrame = Math.min(nbFrames, atlas.h2dAnim.frames.length-1);
+						(cast anim.obj2d : h2d.Anim).curFrame = Math.min(nbFrames, (cast anim.obj2d : h2d.Anim).frames.length-1);
 					}
 				}
 			}
@@ -146,7 +128,7 @@ class FX2D extends BaseFX {
 		getObjAnimations(ctx, this, fxanim.objects);
 	}
 
-	static function getObjAnimations(ctx:Context, elt: PrefabElement, anims: Array<ObjectAnimation>) {
+	function getObjAnimations(ctx:Context, elt: PrefabElement, anims: Array<ObjectAnimation>) {
 		for(c in elt.children) {
 			getObjAnimations(ctx, c, anims);
 		}
@@ -235,7 +217,6 @@ class FX2D extends BaseFX {
 				var co = Std.downcast(c , Constraint);
 				if(co == null) c.make(ctx);
 			}
-			getConstraints(ctx, root, fxanim.constraints);
 		}
 		else
 			super.make(ctx);
@@ -247,6 +228,10 @@ class FX2D extends BaseFX {
 		return ctx;
 	}
 
+	public function getTargetShader2D( ctx : Context, name : String ) {
+		return ctx.local2d;
+	}
+
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, null);
 		var fxanim = Std.downcast(ctx.local2d, FX2DAnimation);
@@ -255,7 +240,9 @@ class FX2D extends BaseFX {
 	}
 
 	function createInstance(parent: h2d.Object) : FX2DAnimation {
-		return new FX2DAnimation(parent);
+		var inst = new FX2DAnimation(parent);
+		inst.prefab = this;
+		return inst;
 	}
 
 	#if editor

+ 3 - 1
hrt/prefab/fx2d/Anim2D.hx

@@ -43,6 +43,8 @@ class Anim2D extends Object2D {
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, propName);
 		
+		var h2dAnim = (cast ctx.local2d : h2d.Anim);
+		
 		if (propName == null || (propName == "src" || propName == "widthFrame" || propName == "heightFrame" || propName == "nbFrames")) {
 			if (tex != null) {
 				tex = null;
@@ -73,7 +75,7 @@ class Anim2D extends Object2D {
 
 	override function makeInstance(ctx:Context):Context {
 		ctx = ctx.clone(this);
-		h2dAnim = new h2d.Anim([], fpsAnimation, ctx.local2d);
+		var h2dAnim = new h2d.Anim([], fpsAnimation, ctx.local2d);
 		ctx.local2d = h2dAnim;
 		ctx.local2d.name = name;
 		ctx.cleanup = function() { h2dAnim = null; }

+ 4 - 3
hrt/prefab/fx2d/Atlas.hx

@@ -10,7 +10,6 @@ class Atlas extends Object2D {
 	
 	var loop : Bool = false;
 
-	var h2dAnim : h2d.Anim;
 	var atlas : hxd.res.Atlas;
 
 	override public function load(v:Dynamic) {
@@ -32,6 +31,8 @@ class Atlas extends Object2D {
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, propName);
+
+		var h2dAnim = (cast ctx.local2d : h2d.Anim);
 		
 		if (propName == null || propName == "src") {
 			if (src != null) {
@@ -53,11 +54,11 @@ class Atlas extends Object2D {
 
 	override function makeInstance(ctx:Context):Context {
 		ctx = ctx.clone(this);
-		h2dAnim = new h2d.Anim([], fpsAnimation, ctx.local2d);
+		var h2dAnim = new h2d.Anim([], fpsAnimation, ctx.local2d);
 		ctx.local2d = h2dAnim;
 		ctx.local2d.name = name;
 		ctx.cleanup = function() {
-			h2dAnim = null;
+			ctx.local2d = null;
 		}
 		updateInstance(ctx);
 		return ctx;

+ 2 - 2
hrt/prefab/fx2d/Bitmap.hx

@@ -10,7 +10,6 @@ class Bitmap extends Object2D {
 	var dx : Float = 0;
 	var dy : Float = 0;
 
-	var bmp : h2d.Bitmap;
 	var tex : h3d.mat.Texture;
 
 	override public function load(v:Dynamic) {
@@ -32,6 +31,7 @@ class Bitmap extends Object2D {
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, propName);
+		var bmp = (cast ctx.local2d : h2d.Bitmap);
 		bmp.visible = visible;
 		if (propName == null || propName == "src") {
 			if (tex != null) {
@@ -55,7 +55,7 @@ class Bitmap extends Object2D {
 
 	override function makeInstance(ctx:Context):Context {
 		ctx = ctx.clone(this);
-		bmp = new h2d.Bitmap(null, ctx.local2d);
+		var bmp = new h2d.Bitmap(null, ctx.local2d);
 		bmp.smooth = true;
 		ctx.local2d = bmp;
 		ctx.local2d.name = name;

+ 2 - 2
hrt/prefab/fx2d/Text.hx

@@ -4,7 +4,6 @@ class Text extends Object2D {
 
 	// parameters
 
-	var h2dText : h2d.Text;
 	var color : Int = 16777215;
 	var size : Int = 12;
 	var cutoff : Float = 0.5;
@@ -35,6 +34,7 @@ class Text extends Object2D {
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, propName);
+		var h2dText = (cast ctx.local2d : h2d.Text);
 		h2dText.visible = visible;
 		h2dText.color = h3d.Vector.fromColor(color);
 		h2dText.color.w = 1;
@@ -46,7 +46,7 @@ class Text extends Object2D {
 
 	override function makeInstance(ctx:Context):Context {
 		ctx = ctx.clone(this);
-		h2dText = new h2d.Text(hxd.res.DefaultFont.get(), ctx.local2d);
+		var h2dText = new h2d.Text(hxd.res.DefaultFont.get(), ctx.local2d);
 		h2dText.text = "Lorem ipsum dolor";
 		h2dText.smooth = true;
 		ctx.local2d = h2dText;