Browse Source

vlm bake save

ncannasse 7 years ago
parent
commit
793f99fc93

+ 3 - 0
hide/comp/SceneEditor.hx

@@ -127,6 +127,7 @@ class SceneEditor {
 		context = new hide.prefab.Context();
 		context.onError = function(e) ide.error(e);
 		context.shared = new hide.prefab.ContextShared(scene);
+		context.shared.currentPath = view.state.path;
 		context.init();
 
 		view.keys.register("copy", onCopy);
@@ -1120,6 +1121,8 @@ class SceneEditor {
 		if(layer != null) {
 			uniqueName = layer.uniqueNames;
 		}
+		if( p.type == "volumetricLightmap" )
+			uniqueName = true;
 
 		var prefix = null;
 		if(p.name != null && p.name.length > 0) {

+ 12 - 0
hide/prefab/ContextShared.hx

@@ -29,4 +29,16 @@ class ContextShared extends hxd.prefab.ContextShared {
 		return getScene().loadTexture("",path);
 	}
 
+	override function loadBakedFile():Null<haxe.io.Bytes> {
+		var path = new haxe.io.Path(currentPath);
+		path.ext = "bake";
+		return try sys.io.File.getBytes(hide.Ide.inst.getPath(path.toString())) catch( e : Dynamic ) null;
+	}
+
+	override function saveBakedFile( bytes ) {
+		var path = new haxe.io.Path(currentPath);
+		path.ext = "bake";
+		sys.io.File.saveBytes(hide.Ide.inst.getPath(path.toString()), bytes);
+	}
+
 }

+ 14 - 11
hide/prefab/l3d/VolumetricLightmap.hx

@@ -9,8 +9,8 @@ class VolumetricLightmap extends Object3D {
 	var order : Int = 1;
 	var displaySH_field = false;
 
-	var useWorldAlignedProbe = false;
 	public var volumetricLightmap : h3d.scene.pbr.VolumetricLightmap;
+	var useWorldAlignedProbe = false;
 	var displaySH = false;
 
 	var sceneObject : h3d.scene.Object;
@@ -179,6 +179,8 @@ class VolumetricLightmap extends Object3D {
 		volumetricLightmap.shOrder = order;
 		volumetricLightmap.useAlignedProb = false;
 		volumetricLightmap.strength = strength;
+		var bytes = ctx.shared.loadBakedBytes(name+".vlm");
+		if( bytes != null ) volumetricLightmap.load(bytes);
 
 		#if editor
 
@@ -239,6 +241,7 @@ class VolumetricLightmap extends Object3D {
 			}
 			else{
 				baker.update(dt);
+				if( baker == null ) return;
 				var props = ctx.getCurrentProps(this);
 				props.find(".bakeProgress").val(baker.progress);
 			}
@@ -250,26 +253,22 @@ class VolumetricLightmap extends Object3D {
 			ctx.rebuild();
 		}
 
-		function startBake() {
+		function startedBake() {
 			//var props = ctx.getCurrentProps(this);
 			props.find(".progress").show();
 			props.find(".bake").attr("value","Cancel").off("click").click(function(_) cancel());
+			bakeUpdate(0);
 		}
 
 		props.find(".progress").hide();
 		props.find(".bake").click(function(_) {
-			maxOrderBaked = order;
-			volumetricLightmap.lastBakedProbeIndex = 0;
-			var s3d = @:privateAccess ctx.rootContext.local3d.getScene();
-			baker = new hide.view.l3d.ProbeBakerProcess(s3d, this);
-			startBake();
-			bakeUpdate(0);
+			startBake(ctx, cancel);
+			startedBake();
 			ctx.addUpdate(bakeUpdate);
 		});
 
 		if( baker != null ){
-			startBake();
-			bakeUpdate(0);
+			startedBake();
 			ctx.addUpdate(bakeUpdate);
 		}
 
@@ -280,7 +279,11 @@ class VolumetricLightmap extends Object3D {
 		volumetricLightmap.lastBakedProbeIndex = 0;
 		var s3d = @:privateAccess ctx.rootContext.local3d.getScene();
 		baker = new hide.view.l3d.ProbeBakerProcess(s3d, this);
-		baker.onEnd = function() if( onEnd != null ) onEnd();
+		baker.onEnd = function() {
+			if( onEnd != null ) onEnd();
+			var bytes = volumetricLightmap.save();
+			ctx.rootContext.shared.saveBakedBytes(name+".vlm", bytes);
+		}
 	}
 
 	#end

+ 7 - 0
hide/view/l3d/Level3D.hx

@@ -145,6 +145,13 @@ private class Level3DSceneEditor extends hide.comp.SceneEditor {
 
 	public function bakeVolumetricLightmaps(){
 		var volumetricLightmaps = sceneData.getAll(hide.prefab.l3d.VolumetricLightmap);
+		var total = 0;
+		for( v in volumetricLightmaps )
+			total += v.volumetricLightmap.getProbeCount();
+		if( total == 0 )
+			return;
+		if( !ide.confirm("Bake "+total+" probes?") )
+			return;
 		function bakeNext() {
 			var v = volumetricLightmaps.shift();
 			if( v == null ) {