Przeglądaj źródła

added hmd bounds

Nicolas Cannasse 11 lat temu
rodzic
commit
c40b5c8f09

+ 1 - 1
h3d/prim/HMDModel.hx

@@ -13,7 +13,7 @@ class HMDModel extends MeshPrimitive {
 	}
 
 	override function getBounds() {
-		return new h3d.col.Bounds();
+		return data.bounds;
 	}
 
 	override function alloc(engine:h3d.Engine) {

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

@@ -59,6 +59,7 @@ class HMDOut extends BaseLibrary {
 		var vbuf = new hxd.FloatBuffer();
 		var ibuf = new hxd.IndexBuffer();
 
+		g.bounds = new h3d.col.Bounds();
 		var tmpBuf = new haxe.ds.Vector(stride);
 		var vertexRemap = [];
 		var index = geom.getPolygons();
@@ -81,6 +82,7 @@ class HMDOut extends BaseLibrary {
 				tmpBuf[p++] = x;
 				tmpBuf[p++] = y;
 				tmpBuf[p++] = z;
+				g.bounds.addPos(x, y, z);
 
 				if( normals != null ) {
 					var nx = normals[k * 3];
@@ -163,11 +165,6 @@ class HMDOut extends BaseLibrary {
 	function addGeometry() {
 
 		var root = buildHierarchy().root;
-		if( root.childs.length == 1 && !root.isMesh ) {
-			root = root.childs[0];
-			root.parent = null;
-		}
-
 		var objects = [], joints = [], skins = [];
 		var uid = 0;
 		function indexRec( t : TmpObject ) {
@@ -253,6 +250,10 @@ class HMDOut extends BaseLibrary {
 		}
 
 		objects = [];
+		if( root.childs.length == 1 && root.model == null ) {
+			root = root.childs[0];
+			root.parent = null;
+		}
 		indexRec(root); // reorder after we have changed hierarchy
 
 		var hskins = new Map(), tmpGeom = new Map();

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

@@ -63,6 +63,7 @@ class Geometry {
 	public var vertexPosition : DataPosition;
 	public var indexCount : Int;
 	public var indexPosition : DataPosition;
+	public var bounds : h3d.col.Bounds;
 	public function new() {
 	}
 }

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

@@ -39,6 +39,17 @@ class Reader {
 		return p;
 	}
 
+	function readBounds() {
+		var b = new h3d.col.Bounds();
+		b.xMin = i.readFloat();
+		b.yMin = i.readFloat();
+		b.zMin = i.readFloat();
+		b.xMax = i.readFloat();
+		b.yMax = i.readFloat();
+		b.zMax = i.readFloat();
+		return b;
+	}
+
 	public function readHeader() : Data {
 		var d = new Data();
 		var h = i.readString(3);
@@ -61,6 +72,7 @@ class Reader {
 			g.vertexPosition = i.readInt32();
 			g.indexCount = i.readInt32();
 			g.indexPosition = i.readInt32();
+			g.bounds = readBounds();
 			d.geometries.push(g);
 		}
 

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

@@ -36,6 +36,15 @@ class Writer {
 		}
 	}
 
+	function writeBounds( b : h3d.col.Bounds ) {
+		out.writeFloat(b.xMin);
+		out.writeFloat(b.yMin);
+		out.writeFloat(b.zMin);
+		out.writeFloat(b.xMax);
+		out.writeFloat(b.yMax);
+		out.writeFloat(b.zMax);
+	}
+
 	public function write( d : Data ) {
 		var old = out;
 		var header = new haxe.io.BytesOutput();
@@ -53,6 +62,7 @@ class Writer {
 			out.writeInt32(g.vertexPosition);
 			out.writeInt32(g.indexCount);
 			out.writeInt32(g.indexPosition);
+			writeBounds(g.bounds);
 		}
 
 		out.writeInt32(d.materials.length);