Parcourir la source

shadows baking ok

ncannasse il y a 7 ans
Parent
commit
af5dd469dd
4 fichiers modifiés avec 29 ajouts et 3 suppressions
  1. 1 1
      hide/comp/SceneEditor.hx
  2. 5 1
      hide/prefab/ContextShared.hx
  3. 17 1
      hide/prefab/Light.hx
  4. 6 0
      hide/view/l3d/Level3D.hx

+ 1 - 1
hide/comp/SceneEditor.hx

@@ -1134,7 +1134,7 @@ class SceneEditor {
 		if(layer != null) {
 			uniqueName = layer.uniqueNames;
 		}
-		if( p.type == "volumetricLightmap" )
+		if( p.type == "volumetricLightmap" || p.type == "light" )
 			uniqueName = true;
 
 		var prefix = null;

+ 5 - 1
hide/prefab/ContextShared.hx

@@ -38,7 +38,11 @@ class ContextShared extends hxd.prefab.ContextShared {
 	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);
+		var file = hide.Ide.inst.getPath(path.toString());
+		if( bytes == null )
+			try sys.FileSystem.deleteFile(file) catch( e : Dynamic ) {};
+		else
+			sys.io.File.saveBytes(file, bytes);
 	}
 	#end
 }

+ 17 - 1
hide/prefab/Light.hx

@@ -78,7 +78,6 @@ class Light extends Object3D {
 			shadows = getShadowsDefault();
 	}
 
-
 	override function applyPos( o : h3d.scene.Object ) {
 		super.applyPos(o);
 		o.setScale(1.0);
@@ -99,9 +98,19 @@ class Light extends Object3D {
 		}
 		ctx.local3d.name = name;
 		updateInstance(ctx);
+		loadBaked(ctx);
 		return ctx;
 	}
 
+	function loadBaked( ctx : Context ) {
+		var name = name+".li";
+		var bytes = ctx.shared.loadBakedBytes(name);
+		if( bytes == null ) return;
+		var light = cast(ctx.local3d,h3d.scene.pbr.Light);
+		if( !light.shadows.loadStaticData(bytes) )
+			ctx.shared.saveBakedBytes(name,null);
+	}
+
 	override function updateInstance( ctx : Context, ?propName : String ) {
 		applyPos(ctx.local3d);
 
@@ -214,6 +223,13 @@ class Light extends Object3D {
 
 	#if editor
 
+	public function saveBaked( ctx : Context ) {
+		var name = name+".li";
+		var light = cast(ctx.shared.contexts.get(this).local3d,h3d.scene.pbr.Light);
+		var data = light.shadows.saveStaticData();
+		ctx.shared.saveBakedBytes(name, data);
+	}
+
 	override function setSelected( ctx : Context, b : Bool ) {
 		var sel = ctx.local3d.getObjectByName("__selection");
 		if( sel != null ) sel.visible = b;

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

@@ -322,6 +322,8 @@ class Level3D extends FileView {
 	}
 
 	function bakeLights() {
+		var curSel = sceneEditor.curEdit.elements;
+		sceneEditor.selectObjects([]);
 		var passes = [];
 		for( m in scene.s3d.getMaterials() ) {
 			var s = m.getPass("shadow");
@@ -332,6 +334,10 @@ class Level3D extends FileView {
 		scene.s3d.computeStatic();
 		for( p in passes )
 			p.isStatic = false;
+		var lights = data.getAll(hide.prefab.Light);
+		for( l in lights )
+			l.saveBaked(sceneEditor.context);
+		sceneEditor.selectObjects(curSel);
 	}
 
 	function bakeVolumetricLightmaps(){