浏览代码

Merge branch 'lods' of https://github.com/HeapsIO/heaps into lods

TothBenoit 1 年之前
父节点
当前提交
a398877209
共有 4 个文件被更改,包括 84 次插入1 次删除
  1. 34 1
      hxd/fmt/fbx/HMDOut.hx
  2. 9 0
      hxd/fmt/hmd/Data.hx
  3. 21 0
      hxd/fmt/hmd/Reader.hx
  4. 20 0
      hxd/fmt/hmd/Writer.hx

+ 34 - 1
hxd/fmt/fbx/HMDOut.hx

@@ -772,7 +772,39 @@ 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();
+			var modelName = o.model == null ? null : o.model.getName();
+			if (modelName != null) {
+				var lodNameIdx = modelName.indexOf("LOD");
+				if (lodNameIdx >= 0) {
+					if (modelName.indexOf("LOD") + 3 > modelName.length)
+						throw 'Missing LOD index for model ${modelName}';
+
+					var idx = modelName.indexOf("LOD") + 3;
+					while (idx < modelName.length && Std.parseInt(modelName.substr(idx, 1)) != null)
+						idx++;
+
+					var lodIdx = Std.parseInt(modelName.substr(lodNameIdx + 3, idx));
+
+					if (modelName.charAt(lodNameIdx - 1)  == '_')
+						lodNameIdx--;
+					if (modelName.charAt(idx) == '_')
+						idx++;
+
+					modelName = StringTools.replace(modelName, modelName.substr(lodNameIdx, idx), "");
+
+					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);
+
+					if (lodIdx != 0)
+						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);
@@ -1165,6 +1197,7 @@ class HMDOut extends BaseLibrary {
 		d.models = [];
 		d.animations = [];
 		d.shapes = [];
+		d.lods = [];
 
 		dataOut = new haxe.io.BytesOutput();
 

+ 9 - 0
hxd/fmt/hmd/Data.hx

@@ -90,6 +90,14 @@ class BlendShape {
 	}
 }
 
+class Lod {
+	public var name:String;
+	public var idx:Int;
+	public var geom:Geometry;
+
+	public function new() {}
+}
+
 class Material {
 
 	public var name : String;
@@ -204,6 +212,7 @@ class Data {
 	public var models : Array<Model>;
 	public var animations : Array<Animation>;
 	public var shapes : Array<BlendShape>;
+	public var lods : Array<Lod>;
 	public var dataPosition : Int;
 	public var data : haxe.io.Bytes;
 

+ 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;