瀏覽代碼

allow more than 256 materials per model

Nicolas Cannasse 3 年之前
父節點
當前提交
29b687692c
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 6 2
      hxd/fmt/hmd/Reader.hx
  2. 10 2
      hxd/fmt/hmd/Writer.hx

+ 6 - 2
hxd/fmt/hmd/Reader.hx

@@ -149,7 +149,9 @@ class Reader {
 			g.vertexStride = i.readByte();
 			g.vertexFormat = [for( k in 0...i.readByte() ) new GeometryFormat(readCachedName(), GeometryDataFormat.fromInt(i.readByte()))];
 			g.vertexPosition = i.readInt32();
-			g.indexCounts = [for( k in 0...i.readByte() ) i.readInt32()];
+			var subCount = i.readByte();
+			if( subCount == 0xFF ) subCount = i.readInt32();
+			g.indexCounts = [for( k in 0...subCount ) i.readInt32()];
 			g.indexPosition = i.readInt32();
 			g.bounds = readBounds();
 			d.geometries.push(g);
@@ -183,7 +185,9 @@ class Reader {
 			d.models.push(m);
 			if( m.geometry < 0 ) continue;
 			m.materials = [];
-			for( k in 0...i.readByte() )
+			var matCount = i.readByte();
+			if( matCount == 0xFF ) matCount = i.readInt32();
+			for( k in 0...matCount )
 				m.materials.push(i.readInt32());
 			m.skin = readSkin();
 		}

+ 10 - 2
hxd/fmt/hmd/Writer.hx

@@ -121,7 +121,11 @@ class Writer {
 				out.writeByte(f.format.toInt());
 			}
 			out.writeInt32(g.vertexPosition);
-			out.writeByte(g.indexCounts.length);
+			if( g.indexCounts.length >= 0xFF ) {
+				out.writeByte(0xFF);
+				out.writeInt32(g.indexCounts.length);
+			} else
+				out.writeByte(g.indexCounts.length);
 			for( i in g.indexCounts )
 				out.writeInt32(i);
 			out.writeInt32(g.indexPosition);
@@ -151,7 +155,11 @@ class Writer {
 			writePosition(m.position);
 			out.writeInt32(m.geometry + 1);
 			if( m.geometry < 0 ) continue;
-			out.writeByte(m.materials.length);
+			if( m.materials.length >= 0xFF ) {
+				out.writeByte(0xFF);
+				out.writeInt32(m.materials.length);
+			} else
+				out.writeByte(m.materials.length);
 			for( m in m.materials )
 				out.writeInt32(m);
 			if( m.skin == null )