Browse Source

UpdateInstancify almost everywhere

trethaller 7 years ago
parent
commit
8614c923cb

+ 6 - 6
hide/comp/SceneEditor.hx

@@ -922,9 +922,9 @@ class SceneEditor {
 		function apply(b) {
 			for(c in obj3ds) {
 				c.o.visible = b ? visible : c.vis;
-				var obj = getContext(c.o).local3d;
-				if(obj != null) {
-					c.o.applyPos(obj);
+				var ctx = getContext(c.o);
+				if(ctx != null) {
+					c.o.updateInstance(ctx, "visible");
 				}
 				onPrefabChange(c.o);
 			}
@@ -1034,9 +1034,9 @@ class SceneEditor {
 			obj3d.y = position.y;
 			obj3d.z = position.z;
 		}
-		var o = getContext(obj3d).local3d;
-		if(o != null)
-			obj3d.applyPos(o);
+		var ctx = getContext(obj3d);
+		if(ctx != null)
+			obj3d.updateInstance(ctx);
 	}
 
 	function deleteElements(elts : Array<PrefabElement>) {

+ 1 - 1
hide/prefab/Box.hx

@@ -30,7 +30,7 @@ class Box extends Object3D {
 
 		ctx.local3d = mesh;
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
+		updateInstance(ctx);
 		return ctx;
 	}
 

+ 3 - 1
hide/prefab/Light.hx

@@ -112,7 +112,7 @@ class Light extends Object3D {
 	}
 
 	override function updateInstance( ctx : Context, ?propName : String ) {
-		applyPos(ctx.local3d);
+		super.updateInstance(ctx, propName);
 
 		var isPbr = Std.is(h3d.mat.MaterialSetup.current, h3d.mat.PbrMaterialSetup);
 		if( !isPbr )
@@ -120,6 +120,8 @@ class Light extends Object3D {
 
 		var color = color | 0xff000000;
 		var light = cast(ctx.local3d,h3d.scene.pbr.Light);
+		light.setScale(1.0);		
+
 		switch( kind ) {
 		case Point:
 			var pl = Std.instance(light, h3d.scene.pbr.PointLight);

+ 2 - 2
hide/prefab/Model.hx

@@ -36,9 +36,9 @@ class Model extends Object3D {
 				obj = root;
 			}
 			obj.name = name;
-			applyPos(obj);
 			ctx.local3d.addChild(obj);
 			ctx.local3d = obj;
+			updateInstance(ctx);
 
 			if( animation != null )
 				obj.playAnimation(ctx.loadAnimation(animation));
@@ -49,7 +49,7 @@ class Model extends Object3D {
 		}
 		ctx.local3d = new h3d.scene.Object(ctx.local3d);
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
+		updateInstance(ctx);
 		return ctx;
 	}
 

+ 17 - 7
hide/prefab/Object3D.hx

@@ -35,7 +35,7 @@ class Object3D extends Prefab {
 		ctx = ctx.clone(this);
 		ctx.local3d = new h3d.scene.Object(ctx.local3d);
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
+		updateInstance(ctx);
 		return ctx;
 	}
 
@@ -84,7 +84,22 @@ class Object3D extends Prefab {
 		o.scaleY = scaleY;
 		o.scaleZ = scaleZ;
 		o.setRotation(Math.degToRad(rotationX), Math.degToRad(rotationY), Math.degToRad(rotationZ));
-		o.visible = visible;
+	}
+
+	override function updateInstance( ctx: Context, ?propName : String ) {
+		var o = ctx.local3d;
+		o.x = x;
+		o.y = y;
+		o.z = z;
+		if(propName == null || propName.indexOf("scale") == 0) {
+			o.scaleX = scaleX;
+			o.scaleY = scaleY;
+			o.scaleZ = scaleZ;
+		}
+		if(propName == null || propName.indexOf("rotation") == 0)
+			o.setRotation(Math.degToRad(rotationX), Math.degToRad(rotationY), Math.degToRad(rotationZ));
+		if(propName == null || propName == "visible")
+			o.visible = visible;
 	}
 
 	#if editor
@@ -106,11 +121,6 @@ class Object3D extends Prefab {
 			</div>
 		');
 		ctx.properties.add(props, this, function(pname) {
-			var obj = ctx.getContext(this).local3d;
-			if( pname == "visible" )
-				obj.visible = visible;
-			else
-				applyPos(obj);
 			ctx.onChange(this, pname);
 		});
 	}

+ 9 - 7
hide/prefab/fx/Emitter.hx

@@ -344,13 +344,17 @@ class Emitter extends Object3D {
 	public function new(?parent) {
 		super(parent);
 		props = { };
+		for(param in emitterParams) {
+			if(param.def != null)
+				resetParam(param);
+		}
 	}
 
 	public static var emitterParams : Array<ParamDef> = [
 		{ name: "emitRate", t: PInt(0, 100), def: 5, disp: "Rate", animate: true },
 		{ name: "lifeTime", t: PFloat(0, 10), def: 1.0 },
 		{ name: "maxCount", t: PInt(0, 100), def: 20, },
-		{ name: "emitShape", t: PChoice(["Cone", "Disc", "Sphere", "Box"]), disp: "Shape", },
+		{ name: "emitShape", t: PChoice(["Cone", "Disc", "Sphere", "Box"]), disp: "Emit Shape", },
 		{ name: "emitAngle", t: PFloat(0, 360.0), disp: "Angle", },
 		{ name: "camAlign", t: PVec(3, -1.0, 1.0), def: [0.,0.,0.] },
 		{ name: "alignDirection", t: PBool, def: false, disp: "Align Direction" },
@@ -439,7 +443,9 @@ class Emitter extends Object3D {
 			Reflect.setField(props, param.name, param.def);
 	}
 
-	public function applyParams(emitterObj: EmitterObject) {
+	override function updateInstance( ctx: Context, ?propName : String ) {
+		super.updateInstance(ctx, propName);
+		var emitterObj = Std.instance(ctx.local3d, EmitterObject);
 		var randIdx = 0;
 		var template = children[0];
 		if(template == null)
@@ -594,10 +600,9 @@ class Emitter extends Object3D {
 		ctx = ctx.clone(this);
 		var emitterObj = new EmitterObject(ctx.local3d);
 		emitterObj.context = ctx;
-		applyParams(emitterObj);
 		ctx.local3d = emitterObj;
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
+		updateInstance(ctx);
 		return ctx;
 	}
 
@@ -614,9 +619,6 @@ class Emitter extends Object3D {
 
 		function onChange(?pname: String) {
 			ctx.onChange(this, pname);
-			var emitter = Std.instance(ctx.getContext(this).local3d, EmitterObject);
-			if(emitter != null)
-				applyParams(emitter);
 
 			if(pname == "emitShape") {
 				refresh();

+ 0 - 2
hide/prefab/l3d/Decal.hx

@@ -53,9 +53,7 @@ class Decal extends Object3D {
 
 		ctx.local3d = mesh;
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
 		updateInstance(ctx);
-
 		return ctx;
 	}
 

+ 0 - 1
hide/prefab/l3d/Polygon.hx

@@ -138,7 +138,6 @@ class Polygon extends Object3D {
 		mesh.material.mainPass.culling = None;
 		ctx.local3d = mesh;
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
 		updateInstance(ctx);
 		return ctx;
 	}

+ 3 - 3
hide/prefab/l3d/VolumetricLightmap.hx

@@ -145,8 +145,8 @@ class VolumetricLightmap extends Object3D {
 		}
 	}
 
-	override function applyPos( o : h3d.scene.Object ) {
-		super.applyPos(o);
+	override function updateInstance( ctx: Context, ?propName : String ) {
+		super.updateInstance(ctx, propName);
 		resetLightmap();
 	}
 
@@ -159,7 +159,7 @@ class VolumetricLightmap extends Object3D {
 		volumetricLightmap.setPosition(-0.5, -0.5, 0);
 		ctx.local3d = obj;
 		ctx.local3d.name = name;
-		applyPos(ctx.local3d);
+		updateInstance(ctx);
 
 		volumetricLightmap.voxelSize = new h3d.Vector(voxelsize_x,voxelsize_y,voxelsize_z);
 		volumetricLightmap.shOrder = order;