Browse Source

lods: wip

LeoVgr 1 year ago
parent
commit
df0037b940
4 changed files with 66 additions and 8 deletions
  1. 20 5
      hxd/fmt/fbx/HMDOut.hx
  2. 5 3
      hxd/fmt/hmd/Data.hx
  3. 21 0
      hxd/fmt/hmd/Reader.hx
  4. 20 0
      hxd/fmt/hmd/Writer.hx

+ 20 - 5
hxd/fmt/fbx/HMDOut.hx

@@ -771,12 +771,27 @@ class HMDOut extends BaseLibrary {
 			var model = new Model();
 			var ref = o.skin == null ? o : o.skin;
 
-			model.name = o.model == null ? null : o.model.getName();
-			if (model.name != null) {
-				var lodNameIdx = model.name.indexOf("_LOD");
-				if (lodNameIdx > 0)
-					trace(model.name.substr(0, lodNameIdx));
+			var modelName = o.model == null ? null : o.model.getName();
+			if (modelName != null) {
+				var lodNameIdx = modelName.indexOf("_LOD");
+				if (lodNameIdx > 0) {
+					var lodIdx = Std.parseInt(modelName.substr(lodNameIdx + 4));
+					modelName = modelName.substr(0, lodNameIdx);
+
+					if (lodIdx != 0) {
+						var g = getChild(o.model, "Geometry");
+
+						var lod = new Lod();
+						lod.name = '${modelName}_LOD${lodIdx}';
+						lod.idx = lodIdx;
+						lod.geom = buildGeom(new hxd.fmt.fbx.Geometry(this, g), null, dataOut, false).g;
+						d.lods.push(lod);
+						continue;
+					}
+				}
 			}
+			
+			model.name = modelName;
 			model.parent = o.parent == null || o.parent.isJoint ? -1 : o.parent.index;
 			model.follow = o.parent != null && o.parent.isJoint ? o.parent.model.getName() : null;
 			var m = ref.model == null ? new hxd.fmt.fbx.BaseLibrary.DefaultMatrixes() : getDefaultMatrixes(ref.model);

+ 5 - 3
hxd/fmt/hmd/Data.hx

@@ -91,9 +91,11 @@ class BlendShape {
 }
 
 class Lod {
-	public var name : Int;
-	public var idx : Int;
-	public var geometry : Index<Geometry>;
+	public var name:String;
+	public var idx:Int;
+	public var geom:Geometry;
+
+	public function new() {}
 }
 
 class Material {

+ 21 - 0
hxd/fmt/hmd/Reader.hx

@@ -248,6 +248,27 @@ class Reader {
 				s.remapPosition = i.readInt32();
 				d.shapes.push(s);
 			}
+
+			var lodLength = i.readInt32();
+			d.lods = [];
+			for (k in 0...lodLength) {
+				var lod = new Lod();
+				lod.name = readName();
+				lod.idx = i.readInt32();
+
+				lod.geom = new Geometry();
+				lod.geom.props = readProps();
+				lod.geom.vertexCount = i.readInt32();
+				lod.geom.vertexFormat = makeFormat();
+				lod.geom.vertexPosition = i.readInt32();
+				var subCount = i.readByte();
+				if( subCount == 0xFF ) subCount = i.readInt32();
+				lod.geom.indexCounts = [for( k in 0...subCount ) i.readInt32()];
+				lod.geom.indexPosition = i.readInt32();
+				lod.geom.bounds = readBounds();
+
+				d.lods.push(lod);
+			}
 		}
 
 

+ 20 - 0
hxd/fmt/hmd/Writer.hx

@@ -210,6 +210,26 @@ class Writer {
 			out.writeInt32(s.remapPosition);
 		}
 
+		out.writeInt32(d.lods.length);
+		for (lod in d.lods) {
+			writeName(lod.name);
+			out.writeInt32(lod.idx);
+			
+			writeProps(lod.geom.props);
+			out.writeInt32(lod.geom.vertexCount);
+			writeFormat(lod.geom.vertexFormat);
+			out.writeInt32(lod.geom.vertexPosition);
+			if( lod.geom.indexCounts.length >= 0xFF ) {
+				out.writeByte(0xFF);
+				out.writeInt32(lod.geom.indexCounts.length);
+			} else
+				out.writeByte(lod.geom.indexCounts.length);
+			for( i in lod.geom.indexCounts )
+				out.writeInt32(i);
+			out.writeInt32(lod.geom.indexPosition);
+			writeBounds(lod.geom.bounds);
+		}
+
 		var bytes = header.getBytes();
 		out = old;