2
0
ncannasse 12 жил өмнө
parent
commit
5470d37abc

+ 8 - 0
hxd/res/Any.hx

@@ -10,6 +10,10 @@ class Any extends Resource {
 		this.loader = loader;
 	}
 	
+	public function toModel() {
+		return loader.loadModel(entry.path);
+	}
+	
 	public function toFbx() {
 		return loader.loadModel(entry.path).toFbx();
 	}
@@ -22,6 +26,10 @@ class Any extends Resource {
 		return loader.loadTexture(entry.path).toTile();
 	}
 
+	public function getTexture() {
+		return loader.loadTexture(entry.path);
+	}
+	
 	public function toSound() {
 		return loader.loadSound(entry.path);
 	}

+ 2 - 1
hxd/res/LocalFileSystem.hx

@@ -26,7 +26,8 @@ private class LocalEntry extends FileEntry {
 	
 	function convertToXBX() {
 		function getXBX() {
-			var fbx = h3d.fbx.Parser.parse(getBytes().toString());
+			var fbx = null;
+			try fbx = h3d.fbx.Parser.parse(getBytes().toString()) catch( e : Dynamic ) throw Std.string(e) + " in " + relPath;
 			fbx = fs.xbxFilter(this, fbx);
 			var out = new haxe.io.BytesOutput();
 			new h3d.fbx.XBXWriter(out).write(fbx);

+ 1 - 1
hxd/res/Resource.hx

@@ -3,7 +3,7 @@ package hxd.res;
 class Resource {
 	
 	public var name(get, never) : String;
-	var entry : FileEntry;
+	public var entry(default,null) : FileEntry;
 	
 	public function new(entry) {
 		this.entry = entry;

+ 41 - 21
hxd/res/Texture.hx

@@ -15,6 +15,11 @@ class Texture extends Resource {
 	var tex : h3d.mat.Texture;
 	var inf : { width : Int, height : Int, isPNG : Bool };
 	
+	public function isPNG() {
+		getSize();
+		return inf.isPNG;
+	}
+	
 	public function getSize() : { width : Int, height : Int } {
 		if( inf != null )
 			return inf;
@@ -64,6 +69,37 @@ class Texture extends Resource {
 		return inf;
 	}
 	
+	public function getPixels() {
+		getSize();
+		if( inf.isPNG ) {
+			var png = new format.png.Reader(new haxe.io.BytesInput(entry.getBytes()));
+			png.checkCRC = false;
+			var bytes = hxd.impl.Tmp.getBytes(inf.width * inf.height * 4);
+			format.png.Tools.extract32(png.read(), bytes);
+			return bytes;
+		} else {
+			throw "getPixels not supported for " + name;
+			return null;
+		}
+	}
+	
+	function makeSquare( bmp : haxe.io.Bytes ) {
+		var tw = tex.width, th = tex.height, w = inf.width, h = inf.height;
+		var out = hxd.impl.Tmp.getBytes(tw * th * 4);
+		var p = 0, b = 0;
+		for( y in 0...h ) {
+			out.blit(p, bmp, b, w * 4);
+			p += w * 4;
+			b += w * 4;
+			for( i in 0...(tw - w) * 4 )
+				out.set(p++, 0);
+		}
+		for( i in 0...(th - h) * tw )
+			out.set(p++, 0);
+		hxd.impl.Tmp.saveBytes(bmp);
+		return out;
+	}
+	
 	function loadTexture() {
 		var tw = tex.width, th = tex.height;
 		var w =	inf.width, h = inf.height;
@@ -75,13 +111,8 @@ class Texture extends Resource {
 					needResize = false;
 				}
 				// immediately loading the PNG is faster than going through loadBitmap
-				var png = new format.png.Reader(new haxe.io.BytesInput(entry.getBytes()));
-				png.checkCRC = false;
-				var bytes = hxd.impl.Tmp.getBytes(tw * th * 4);
-				format.png.Tools.extract32(png.read(), bytes);
-				if( !isSquare ) {
-					throw "TODO";
-				}
+				var bytes = getPixels();
+				if( !isSquare ) bytes = makeSquare(bytes);
 				tex.uploadBytes(bytes);
 				hxd.impl.Tmp.saveBytes(bytes);
 			}
@@ -99,20 +130,9 @@ class Texture extends Resource {
 				if( isSquare )
 					tex.uploadBitmap(bmp);
 				else {
-					var out = hxd.impl.Tmp.getBytes(tw * th * 4);
-					var bmp = bmp.getBytes();
-					var p = 0, b = 0;
-					for( y in 0...h ) {
-						for( x in 0...w * 4 )
-							out.set(p++, bmp.get(b++));
-						for( i in 0...(tw - w) * 4 )
-							out.set(p++, 0);
-					}
-					for( i in 0...(th - h) * tw )
-						out.set(p++, 0);
-					hxd.impl.Tmp.saveBytes(bmp);
-					tex.uploadBytes(out);
-					hxd.impl.Tmp.saveBytes(out);
+					var bytes = makeSquare(bmp.getBytes());
+					tex.uploadBytes(bytes);
+					hxd.impl.Tmp.saveBytes(bytes);
 				}
 				bmp.dispose();
 			});