Bladeren bron

World: fix material on missing textures

trethaller 7 jaren geleden
bovenliggende
commit
99266d958b
2 gewijzigde bestanden met toevoegingen van 13 en 6 verwijderingen
  1. 9 1
      h3d/mat/BigTexture.hx
  2. 4 5
      h3d/scene/World.hx

+ 9 - 1
h3d/mat/BigTexture.hx

@@ -142,7 +142,7 @@ class BigTexture {
 		return split(q.tl, sw, sh, rw, rh);
 	}
 
-	public function allocPos( w : Int, h : Int ) {
+	function allocPos( w : Int, h : Int ) {
 		var q = findBest(space, w, h);
 		if( q == null )
 			return null;
@@ -172,6 +172,14 @@ class BigTexture {
 		return e;
 	}
 
+	public function addEmpty( width : Int, height : Int ) {
+		var q = allocPos(width, height);
+		if( q == null )
+			return null;
+		var e = new BigTextureElement(this, q, q.x / size, q.y / size, width / size, height / size);
+		return e;
+	}
+
 	function uploadPixels( pixels : hxd.Pixels, x : Int, y : Int, alphaChannel ) {
 		var bpp = hxd.Pixels.bytesPerPixel(allPixels.format);
 		if( alphaChannel ) {

+ 4 - 5
h3d/scene/World.hx

@@ -251,7 +251,7 @@ class World extends Object {
 				if( res != null )
 					specTex = btex.spec.add(res);
 				else
-					btex.spec.allocPos(t.width, t.height); // keep UV in-sync
+					specTex = btex.spec.addEmpty(t.width, t.height); // keep UV in-sync
 			}
 		}
 
@@ -264,7 +264,7 @@ class World extends Object {
 			if( res != null )
 				normalMap = btex.normal.add(res);
 			else
-				btex.normal.allocPos(t.width, t.height); // keep UV in-sync
+				normalMap = btex.normal.addEmpty(t.width, t.height); // keep UV in-sync
 		}
 
 		var m = new WorldMaterial();
@@ -339,7 +339,7 @@ class World extends Object {
 					var nx = vl[p++];
 					var ny = vl[p++];
 					var nz = vl[p++];
-					var tx = 0., ty = 0., tz = 0.;
+					var tx = 1., ty = 0., tz = 0.;
 					if(enableNormalMaps) {
 						tx = vl[p++];
 						ty = vl[p++];
@@ -498,9 +498,8 @@ class World extends Object {
 		} else
 			mesh.material.specularAmount = 0;
 
-		if(mat.normal != null) {
+		if(enableNormalMaps)
 			mesh.material.normalMap = mat.normal.t.tex;
-		}
 	}
 
 	override function dispose() {