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

Update volumetric lightmap save method

ShiroSmith 7 жил өмнө
parent
commit
66c105da96

+ 2 - 2
hide/prefab/ContextShared.hx

@@ -66,11 +66,11 @@ class ContextShared extends hxd.prefab.ContextShared {
 		sys.io.File.saveBytes(file, bytes);
 		sys.io.File.saveBytes(file, bytes);
 	}
 	}
 
 
-	override function savePrefabDat(file : String, ext:String, p : hide.prefab.Prefab, bytes : haxe.io.Bytes ){
+	override function savePrefabDat(file : String, ext:String, p : String, bytes : haxe.io.Bytes ){
 		var path = new haxe.io.Path(currentPath);
 		var path = new haxe.io.Path(currentPath);
 		path.ext = "dat";
 		path.ext = "dat";
 		var datDir = path.toString();
 		var datDir = path.toString();
-		var instanceDir = datDir + "/" + p.name;
+		var instanceDir = datDir + "/" + p;
 		if(!sys.FileSystem.isDirectory( hide.Ide.inst.getPath(datDir)))
 		if(!sys.FileSystem.isDirectory( hide.Ide.inst.getPath(datDir)))
 			sys.FileSystem.createDirectory( hide.Ide.inst.getPath(datDir));
 			sys.FileSystem.createDirectory( hide.Ide.inst.getPath(datDir));
 		if(!sys.FileSystem.isDirectory( hide.Ide.inst.getPath(instanceDir)))
 		if(!sys.FileSystem.isDirectory( hide.Ide.inst.getPath(instanceDir)))

+ 16 - 4
hide/prefab/l3d/VolumetricLightmap.hx

@@ -131,6 +131,7 @@ class VolumetricLightmap extends Object3D {
 			previewSphere.setPosition(probePos.x, probePos.y, probePos.z);
 			previewSphere.setPosition(probePos.x, probePos.y, probePos.z);
 			var shader = new h3d.shader.pbr.SHDisplay();
 			var shader = new h3d.shader.pbr.SHDisplay();
 			shader.order = volumetricLightmap.shOrder;
 			shader.order = volumetricLightmap.shOrder;
+			shader.strength = volumetricLightmap.strength;
 			var coefCount = volumetricLightmap.getCoefCount();
 			var coefCount = volumetricLightmap.getCoefCount();
 			shader.SIZE = coefCount;
 			shader.SIZE = coefCount;
 
 
@@ -147,7 +148,17 @@ class VolumetricLightmap extends Object3D {
 
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		super.updateInstance(ctx, propName);
 		super.updateInstance(ctx, propName);
-		if( propName != "visible" && propName != "strength" && propName != "order" && propName != "displaySH_field") resetLightmap();
+
+		if(propName ==  "strength" && displaySH){
+			var previewSpheres = volumetricLightmap.findAll(c -> if(c.name == "_previewSphere") c else null);
+			for(ps in previewSpheres){
+				var mesh = Std.instance(ps, h3d.scene.Mesh);
+				var shader = mesh.material.mainPass.getShader(h3d.shader.pbr.SHDisplay);
+				if(shader != null) shader.strength = volumetricLightmap.strength;
+			}
+		}
+		if( propName != "visible" && propName != "strength" && propName != "order" && propName != "displaySH_field")
+			resetLightmap();
 	}
 	}
 
 
 	override function makeInstance(ctx:Context):Context {
 	override function makeInstance(ctx:Context):Context {
@@ -165,8 +176,9 @@ class VolumetricLightmap extends Object3D {
 		volumetricLightmap.shOrder = order;
 		volumetricLightmap.shOrder = order;
 		volumetricLightmap.useAlignedProb = false;
 		volumetricLightmap.useAlignedProb = false;
 		volumetricLightmap.strength = strength;
 		volumetricLightmap.strength = strength;
-		var bytes = ctx.shared.loadBakedBytes(name+".vlm");
-		if( bytes != null ) volumetricLightmap.load(bytes);
+
+		var res = ctx.shared.loadPrefabDat("sh", "bake", name);
+		if(res != null) volumetricLightmap.load(res.entry.getBytes());
 
 
 		#if editor
 		#if editor
 		initProbes();
 		initProbes();
@@ -274,7 +286,7 @@ class VolumetricLightmap extends Object3D {
 		baker.onEnd = function() {
 		baker.onEnd = function() {
 			if( onEnd != null ) onEnd();
 			if( onEnd != null ) onEnd();
 			var bytes = volumetricLightmap.save();
 			var bytes = volumetricLightmap.save();
-			ctx.rootContext.shared.saveBakedBytes(name+".vlm", bytes);
+			ctx.rootContext.shared.savePrefabDat("sh", "bake", name, bytes);
 		}
 		}
 	}
 	}
 
 

+ 9 - 4
hide/prefab/terrain/Terrain.hx

@@ -32,6 +32,11 @@ class Terrain extends Object3D {
 	var editor : hide.prefab.terrain.TerrainEditor;
 	var editor : hide.prefab.terrain.TerrainEditor;
 	#end
 	#end
 
 
+	public function new(?parent) {
+		super(parent);
+		type = "terrain";
+	}
+
 	override function load( obj : Dynamic ) {
 	override function load( obj : Dynamic ) {
 		super.load(obj);
 		super.load(obj);
 		tileSize = obj.tileSize == null ? 1 : obj.tileSize;
 		tileSize = obj.tileSize == null ? 1 : obj.tileSize;
@@ -81,7 +86,7 @@ class Terrain extends Object3D {
 		for(tile in terrain.tiles){
 		for(tile in terrain.tiles){
 			var pixels = tile.heightMap.capturePixels();
 			var pixels = tile.heightMap.capturePixels();
 			var name = tile.tileX + "_" + tile.tileY + "_" + "h";
 			var name = tile.tileX + "_" + tile.tileY + "_" + "h";
-			ctx.shared.savePrefabDat(name, "heightMap", this, pixels.bytes);
+			ctx.shared.savePrefabDat(name, "heightMap", name, pixels.bytes);
 		}
 		}
 	}
 	}
 
 
@@ -97,17 +102,17 @@ class Terrain extends Object3D {
 			var pixels = packedWeightsTex.capturePixels();
 			var pixels = packedWeightsTex.capturePixels();
 			var bytes = pixels.toPNG();
 			var bytes = pixels.toPNG();
 			var name = tile.tileX + "_" + tile.tileY + "_" + "w";
 			var name = tile.tileX + "_" + tile.tileY + "_" + "w";
-			ctx.shared.savePrefabDat(name, "png", this, bytes);
+			ctx.shared.savePrefabDat(name, "png", name, bytes);
 
 
 			var pixels = tile.surfaceIndexMap.capturePixels();
 			var pixels = tile.surfaceIndexMap.capturePixels();
 			var bytes = pixels.toPNG();
 			var bytes = pixels.toPNG();
 			var name = tile.tileX + "_" + tile.tileY + "_" + "i";
 			var name = tile.tileX + "_" + tile.tileY + "_" + "i";
-			ctx.shared.savePrefabDat(name, "png", this, bytes);
+			ctx.shared.savePrefabDat(name, "png", name, bytes);
 		}
 		}
 	}
 	}
 
 
 	function loadTerrain(ctx : Context){
 	function loadTerrain(ctx : Context){
-		var resDir = ctx.shared.loadDir(this);
+		var resDir = ctx.shared.loadDir(name);
 		if(resDir == null) return;
 		if(resDir == null) return;
 		for(res in resDir){
 		for(res in resDir){
 			var file = res.name.split(".")[0];
 			var file = res.name.split(".")[0];