Forráskód Böngészése

setSelected review + vlm global scale

ncannasse 7 éve
szülő
commit
cd10cfef53

+ 15 - 71
hide/comp/SceneEditor.hx

@@ -356,7 +356,7 @@ class SceneEditor {
 			var o = ctx.local3d;
 			if(o == null)
 				continue;
-			var meshes = getSelfObjects(elt, h3d.scene.Mesh);
+			var meshes = context.shared.getObjects(elt, h3d.scene.Mesh);
 			var invRootMat = o.getAbsPos().clone();
 			invRootMat.invert();
 			var bounds = new h3d.col.Bounds();
@@ -639,23 +639,6 @@ class SceneEditor {
 		return context.shared.root3d;
 	}
 
-	function getSelfObjects<T:h3d.scene.Object>(p : PrefabElement, c: Class<T>) : Array<T> {
-		var childObjs = [for(c in p.children) {var ctx = getContext(c); if(ctx != null) ctx.local3d; }];
-		var ret = [];
-		function rec(o : Object) {
-			var m = Std.instance(o, c);
-			if(m != null) ret.push(m);
-			for(i in 0...o.numChildren) {
-				var child = o.getChildAt(i);
-				if(childObjs.indexOf(child) < 0) {
-					rec(child);
-				}
-			}
-		}
-		rec(getContext(p).local3d);
-		return ret;
-	}
-
 	public function addObject( e : PrefabElement ) {
 		var roots = e.parent.children;
 		undo.change(Custom(function(undo) {
@@ -672,16 +655,6 @@ class SceneEditor {
 			resetCamera();
 	}
 
-	function setHighlighed(elt: PrefabElement, on: Bool) {
-		var ctx = getContext(elt);
-		if(ctx == null)
-			return;
-		var highlights = ctx.local3d.findAll(c -> if(c.name == "_highlight") c else null);
-		for(o in highlights) {
-			o.visible = on;
-		}
-	}
-
 	public function selectObjects( elts : Array<PrefabElement>, ?includeTree=true) {
 		if( curEdit != null )
 			curEdit.cleanup();
@@ -692,17 +665,22 @@ class SceneEditor {
 			tree.setSelection(elts);
 		}
 
-		var rootElts = edit.rootElements;
-		var objects = edit.rootObjects;
-		addOutline(objects);
-		for(elt in rootElts) {
-			setHighlighed(elt, true);
+		var map = new Map<PrefabElement,Bool>();
+		function selectRec(e : PrefabElement, b:Bool) {
+			if( map.exists(e) )
+				return;
+			map.set(e, true);
+			e.setSelected(context, b);
+			for( e in e.children )
+				selectRec(e,b);
 		}
+
+		for( e in elts )
+			selectRec(e, true);
+
 		edit.cleanups.push(function() {
-			cleanOutline(objects);
-			for(elt in rootElts) {
-				setHighlighed(elt, false);
-			}
+			for( e in map.keys() )
+				e.setSelected(context, false);
 		});
 
 		curEdit = edit;
@@ -1285,40 +1263,6 @@ class SceneEditor {
 		return pos;
 	}
 
-	static function addOutline(objects: Array<Object>) {
-		var outlineShader = new h3d.shader.Outline();
-		outlineShader.size = 0.12;
-		outlineShader.distance = 0;
-		outlineShader.color.setColor(0xffffff);
-
-		var s1 = new h3d.mat.Stencil();
-		s1.setFunc(Always, 1);
-		s1.setOp(Keep, Keep, Replace);
-
-		var s2 = new h3d.mat.Stencil();
-		s2.setFunc(Greater, 1, 0xFF, 0);
-		for(obj in objects) {
-			for( m in obj.getMaterials() ) {
-				m.mainPass.stencil = s1;
-
-				var p = m.allocPass("outline");
-				p.culling = None;
-				p.depthWrite = false;
-				p.addShader(outlineShader);
-				p.stencil = s2;
-			}
-		}
-	}
-
-	static function cleanOutline(objects: Array<Object>) {
-		for(obj in objects) {
-			for( m in obj.getMaterials() ) {
-				m.mainPass.stencil = null;
-				m.removePass(m.getPass("outline"));
-			}
-		}
-	}
-
 	public static function hasParent(elt: PrefabElement, list: Array<PrefabElement>) {
 		for(p in list) {
 			if(isParent(elt, p))

+ 5 - 1
hide/prefab/Object3D.hx

@@ -106,7 +106,11 @@ class Object3D extends Prefab {
 			</div>
 		');
 		ctx.properties.add(props, this, function(pname) {
-			applyPos(ctx.getContext(this).local3d);
+			var obj = ctx.getContext(this).local3d;
+			if( pname == "visible" )
+				obj.visible = visible;
+			else
+				applyPos(obj);
 			ctx.onChange(this, pname);
 		});
 	}

+ 17 - 9
hide/prefab/l3d/Decal.hx

@@ -51,15 +51,6 @@ class Decal extends Object3D {
 		var mesh = new h3d.scene.Mesh(h3d.prim.Cube.defaultUnitCube(), ctx.local3d);
 		mesh.material.setDefaultProps("decal");
 
-		#if editor
-		var wire = new h3d.scene.Box(0xFFFFFFFF,mesh);
-		wire.name = "_highlight";
-		wire.material.setDefaultProps("ui");
-		wire.ignoreCollide = true;
-		wire.material.shadows = false;
-		wire.visible = false;
-		#end
-
 		ctx.local3d = mesh;
 		ctx.local3d.name = name;
 		applyPos(ctx.local3d);
@@ -74,6 +65,23 @@ class Decal extends Object3D {
 		return { icon : "paint-brush", name : "Decal" };
 	}
 
+	override function setSelected( ctx : Context, b : Bool ) {
+		if( b ) {
+			var obj = ctx.shared.contexts.get(this).local3d;
+			var wire = new h3d.scene.Box(0xFFFFFFFF,obj);
+			wire.name = "_highlight";
+			wire.material.setDefaultProps("ui");
+			wire.ignoreCollide = true;
+			wire.material.shadows = false;
+		} else {
+			for( o in ctx.shared.getObjects(this,h3d.scene.Box) )
+				if( o.name == "_highlight" ) {
+					o.remove();
+					return;
+				}
+		}
+	}
+
 	override function edit( ctx : EditContext ) {
 		super.edit(ctx);
 		var props = ctx.properties.add(new hide.Element('

+ 26 - 29
hide/prefab/l3d/VolumetricLightmap.hx

@@ -13,8 +13,6 @@ class VolumetricLightmap extends Object3D {
 	var useWorldAlignedProbe = false;
 	var displaySH = false;
 
-	var sceneObject : h3d.scene.Object;
-
 	#if editor
 	var maxOrderBaked = 0;
 	var baker : hide.view.l3d.ProbeBakerProcess;
@@ -126,9 +124,9 @@ class VolumetricLightmap extends Object3D {
 			previewSphere.name = "_previewSphere";
 			previewSphere.material.setDefaultProps("ui");
 			var size = 0.1;
-			previewSphere.scaleX = size/volumetricLightmap.scaleX;
-			previewSphere.scaleY = size/volumetricLightmap.scaleY;
-			previewSphere.scaleZ = size/volumetricLightmap.scaleZ;
+			previewSphere.scaleX = size/volumetricLightmap.parent.scaleX;
+			previewSphere.scaleY = size/volumetricLightmap.parent.scaleY;
+			previewSphere.scaleZ = size/volumetricLightmap.parent.scaleZ;
 			var probePos = volumetricLightmap.getProbePosition(volumetricLightmap.getProbeCoords(i));
 			volumetricLightmap.globalToLocal(probePos);
 			previewSphere.setPosition(probePos.x, probePos.y, probePos.z);
@@ -149,15 +147,7 @@ class VolumetricLightmap extends Object3D {
 	}
 
 	override function applyPos( o : h3d.scene.Object ) {
-
 		super.applyPos(o);
-
-		volumetricLightmap.setTransform(sceneObject.getAbsPos());
-		volumetricLightmap.scaleX = o.scaleX;
-		volumetricLightmap.scaleY = o.scaleY;
-		volumetricLightmap.scaleZ = o.scaleZ;
-		volumetricLightmap.visible = this.visible;
-
 		resetLightmap();
 	}
 
@@ -165,14 +155,16 @@ class VolumetricLightmap extends Object3D {
 
 		ctx = ctx.clone(this);
 		var obj = new h3d.scene.Object(ctx.local3d);
-		sceneObject = new h3d.scene.Object(obj);
-		sceneObject.setPosition(-0.5, -0.5, -0.5);
-
-		volumetricLightmap = new h3d.scene.pbr.VolumetricLightmap(ctx.local3d);
+		volumetricLightmap = new h3d.scene.pbr.VolumetricLightmap(obj);
+		volumetricLightmap.setPosition(-0.5, -0.5, -0.5);
 		ctx.local3d = obj;
 		ctx.local3d.name = name;
 		applyPos(ctx.local3d);
 
+		#if editor
+		initProbes();
+		#end
+
 		volumetricLightmap.voxelSize = new h3d.Vector(voxelsize_x,voxelsize_y,voxelsize_z);
 		volumetricLightmap.shOrder = order;
 		volumetricLightmap.useAlignedProb = false;
@@ -180,19 +172,7 @@ class VolumetricLightmap extends Object3D {
 		var bytes = ctx.shared.loadBakedBytes(name+".vlm");
 		if( bytes != null ) volumetricLightmap.load(bytes);
 
-		#if editor
-
-		var wire = new h3d.scene.Box(0xFFFFFFFF,obj);
-		wire.name = "_highlight";
-		wire.material.setDefaultProps("ui");
-		wire.ignoreCollide = true;
-		wire.material.shadows = false;
-		wire.material.castShadows = false;
-		wire.visible = false;
-
-		initProbes();
 
-		#end
 
 		return ctx;
 	}
@@ -203,6 +183,23 @@ class VolumetricLightmap extends Object3D {
 		return { icon : "map-o", name : "VolumetricLightmap" };
 	}
 
+	override function setSelected( ctx : Context, b : Bool ) {
+		if( b ) {
+			var obj = ctx.shared.contexts.get(this).local3d;
+			var wire = new h3d.scene.Box(volumetricLightmap.lightProbeTexture == null ? 0xFFFF0000 : 0xFFFFFFFF,obj);
+			wire.name = "_highlight";
+			wire.material.setDefaultProps("ui");
+			wire.ignoreCollide = true;
+			wire.material.shadows = false;
+		} else {
+			for( o in ctx.shared.getObjects(this,h3d.scene.Box) )
+				if( o.name == "_highlight" ) {
+					o.remove();
+					return;
+				}
+		}
+	}
+
 	override function edit( ctx : EditContext ) {
 		super.edit(ctx);
 		var props = new hide.Element('