Browse Source

Bugfix terrain ( null map )

ShiroSmith 6 years ago
parent
commit
b27f08cdd5
2 changed files with 9 additions and 3 deletions
  1. 8 1
      hide/prefab/terrain/Terrain.hx
  2. 1 2
      hide/prefab/terrain/TerrainEditor.hx

+ 8 - 1
hide/prefab/terrain/Terrain.hx

@@ -106,6 +106,7 @@ class Terrain extends Object3D {
 
 
 	public function saveHeightTextures( ctx : Context ) {
 	public function saveHeightTextures( ctx : Context ) {
 		for( tile in terrain.tiles ) {
 		for( tile in terrain.tiles ) {
+			if( tile.tileX == null || tile.tileY == null ) continue;
 			var pixels = tile.heightMap.capturePixels();
 			var pixels = tile.heightMap.capturePixels();
 			var fileName = tile.tileX + "_" + tile.tileY + "_" + "h";
 			var fileName = tile.tileX + "_" + tile.tileY + "_" + "h";
 			ctx.shared.savePrefabDat(fileName, "heightMap", name, pixels.bytes);
 			ctx.shared.savePrefabDat(fileName, "heightMap", name, pixels.bytes);
@@ -115,6 +116,7 @@ class Terrain extends Object3D {
 	public function saveWeightTextures( ctx : Context ) {
 	public function saveWeightTextures( ctx : Context ) {
 		var packedWeightsTex = new h3d.mat.Texture(terrain.weightMapResolution, terrain.weightMapResolution, [Target], RGBA);
 		var packedWeightsTex = new h3d.mat.Texture(terrain.weightMapResolution, terrain.weightMapResolution, [Target], RGBA);
 		for( tile in terrain.tiles ) {
 		for( tile in terrain.tiles ) {
+			if( tile.tileX == null || tile.tileY == null ) continue;
 			h3d.Engine.getCurrent().pushTarget(packedWeightsTex);
 			h3d.Engine.getCurrent().pushTarget(packedWeightsTex);
 			packWeight.shader.indexMap = tile.surfaceIndexMap;
 			packWeight.shader.indexMap = tile.surfaceIndexMap;
 			packWeight.shader.weightTextures = tile.surfaceWeightArray;
 			packWeight.shader.weightTextures = tile.surfaceWeightArray;
@@ -137,12 +139,17 @@ class Terrain extends Object3D {
 		var resDir = ctx.shared.loadDir(name);
 		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 fileInfos = res.name.split(".");
+			var ext = fileInfos[1];
+			var file = fileInfos[0];
+			if( ext == "bin" ) return;
 			var coords = file.split("_");
 			var coords = file.split("_");
 			var x = Std.parseInt(coords[0]);
 			var x = Std.parseInt(coords[0]);
 			var y = Std.parseInt(coords[1]);
 			var y = Std.parseInt(coords[1]);
+			if( x == null || y == null ) continue;
 			var type = coords[2];
 			var type = coords[2];
 			var tile = terrain.createTile(x, y);
 			var tile = terrain.createTile(x, y);
+
 			switch( type ) {
 			switch( type ) {
 				case "h":
 				case "h":
 				if( height ) {
 				if( height ) {

+ 1 - 2
hide/prefab/terrain/TerrainEditor.hx

@@ -95,8 +95,7 @@ class TerrainEditor {
 
 
 	public function save() {
 	public function save() {
 		if( editContext == null ) return;
 		if( editContext == null ) return;
-		editContext.scene.setCurrent();
-		var ctx = editContext;
+		editContext.scene.setCurrent();		if( terrainPrefab == null ) return;		var ctx = editContext;
 		var datPath = new haxe.io.Path(ctx.rootContext.shared.currentPath);
 		var datPath = new haxe.io.Path(ctx.rootContext.shared.currentPath);
 		datPath.ext = "dat";
 		datPath.ext = "dat";
 		var fullPath = ctx.ide.getPath(datPath.toString() + "/" + terrainPrefab.name);
 		var fullPath = ctx.ide.getPath(datPath.toString() + "/" + terrainPrefab.name);