소스 검색

rename H3D format to HMD

Nicolas Cannasse 11 년 전
부모
커밋
df14983796
11개의 변경된 파일45개의 추가작업 그리고 31개의 파일을 삭제
  1. 5 3
      h3d/anim/Animation.hx
  2. 2 2
      h3d/prim/HMDModel.hx
  3. 7 3
      hxd/fmt/fbx/HMDOut.hx
  4. 1 1
      hxd/fmt/hmd/Data.hx
  5. 11 3
      hxd/fmt/hmd/Library.hx
  6. 5 5
      hxd/fmt/hmd/Reader.hx
  7. 3 3
      hxd/fmt/hmd/Writer.hx
  8. 1 1
      hxd/res/EmbedOptions.hx
  9. 4 4
      hxd/res/FbxModel.hx
  10. 4 4
      hxd/res/FileTree.hx
  11. 2 2
      samples/skin/Main.hx

+ 5 - 3
h3d/anim/Animation.hx

@@ -129,7 +129,7 @@ class Animation {
 	@:access(h3d.scene.Skin.skinData)
 	public function bind( base : h3d.scene.Object ) {
 		var currentSkin : h3d.scene.Skin = null;
-		for( a in objects ) {
+		for( a in objects.copy() ) {
 			if( currentSkin != null ) {
 				// quick lookup for joints (prevent creating a temp object)
 				var j = currentSkin.skinData.namedJoints.get(a.objectName);
@@ -139,8 +139,10 @@ class Animation {
 				}
 			}
 			var obj = base.getObjectByName(a.objectName);
-			if( obj == null )
-				throw a.objectName + " was not found";
+			if( obj == null ) {
+				objects.remove(a);
+				continue;
+			}
 			var joint = Std.instance(obj, h3d.scene.Skin.Joint);
 			if( joint != null ) {
 				currentSkin = cast joint.parent;

+ 2 - 2
h3d/prim/H3DModel.hx → h3d/prim/HMDModel.hx

@@ -1,8 +1,8 @@
 package h3d.prim;
 
-class H3DModel extends MeshPrimitive {
+class HMDModel extends MeshPrimitive {
 
-	var data : hxd.fmt.h3d.Data.Geometry;
+	var data : hxd.fmt.hmd.Data.Geometry;
 	var dataPosition : Int;
 	var entry : hxd.res.FileEntry;
 

+ 7 - 3
hxd/fmt/fbx/H3DOut.hx → hxd/fmt/fbx/HMDOut.hx

@@ -1,9 +1,9 @@
 package hxd.fmt.fbx;
 using hxd.fmt.fbx.Data;
 import hxd.fmt.fbx.BaseLibrary;
-import hxd.fmt.h3d.Data;
+import hxd.fmt.hmd.Data;
 
-class H3DOut extends BaseLibrary {
+class HMDOut extends BaseLibrary {
 
 	var d : Data;
 	var dataOut : haxe.io.BytesOutput;
@@ -18,6 +18,10 @@ class H3DOut extends BaseLibrary {
 		return tmp.getFloat(0);
 	}
 
+	override function keepJoint(_) : Null<Bool> {
+		return true;
+	}
+
 	function buildGeom( geom : hxd.fmt.fbx.Geometry, skin : h3d.anim.Skin, dataOut : haxe.io.BytesOutput ) {
 		var g = new Geometry();
 
@@ -454,7 +458,7 @@ class H3DOut extends BaseLibrary {
 		return a;
 	}
 
-	public function toH3D( filePath : String, includeGeometry : Bool ) : Data {
+	public function toHMD( filePath : String, includeGeometry : Bool ) : Data {
 
 		leftHandConvert();
 		autoMerge();

+ 1 - 1
hxd/fmt/h3d/Data.hx → hxd/fmt/hmd/Data.hx

@@ -1,4 +1,4 @@
-package hxd.fmt.h3d;
+package hxd.fmt.hmd;
 
 enum GeometryDataFormat {
 	DFloat;

+ 11 - 3
hxd/fmt/h3d/Library.hx → hxd/fmt/hmd/Library.hx

@@ -1,4 +1,5 @@
-package hxd.fmt.h3d;
+package hxd.fmt.hmd;
+import hxd.fmt.hmd.Data;
 
 class Library {
 
@@ -17,7 +18,7 @@ class Library {
 	function makePrimitive( id : Int ) {
 		var p = cachedPrimitives[id];
 		if( p != null ) return p;
-		p = new h3d.prim.H3DModel(header.geometries[id], header.dataPosition, entry);
+		p = new h3d.prim.HMDModel(header.geometries[id], header.dataPosition, entry);
 		cachedPrimitives[id] = p;
 		return p;
 	}
@@ -40,6 +41,11 @@ class Library {
 		return mat;
 	}
 
+	function makeSkin( skin : Skin ) {
+		var s = new h3d.anim.Skin(skin.name, 0, 3);
+		return s;
+	}
+
 	public function makeObject( ?loadTexture : String -> h3d.mat.Texture ) : h3d.scene.Object {
 		if( loadTexture == null )
 			loadTexture = function(_) return h3d.mat.Texture.fromColor(0xFF00FF);
@@ -52,7 +58,9 @@ class Library {
 				obj = new h3d.scene.Object();
 			} else {
 				var prim = m.geometries.length == 1 ? makePrimitive(m.geometries[0]) : new h3d.prim.MultiPrimitive([for( g in m.geometries ) makePrimitive(g)]);
-				if( m.materials.length == 1 )
+				if( m.skin != null )
+					obj = new h3d.scene.Skin(makeSkin(m.skin), [for( m in m.materials ) makeMaterial(m, loadTexture)]);
+				else if( m.materials.length == 1 )
 					obj = new h3d.scene.Mesh(prim, makeMaterial(m.materials[0],loadTexture));
 				else
 					obj = new h3d.scene.MultiMaterial(prim, [for( m in m.materials ) makeMaterial(m,loadTexture)]);

+ 5 - 5
hxd/fmt/h3d/Reader.hx → hxd/fmt/hmd/Reader.hx

@@ -1,5 +1,5 @@
-package hxd.fmt.h3d;
-import hxd.fmt.h3d.Data;
+package hxd.fmt.hmd;
+import hxd.fmt.hmd.Data;
 
 class Reader {
 
@@ -42,11 +42,11 @@ class Reader {
 	public function readHeader() : Data {
 		var d = new Data();
 		var h = i.readString(3);
-		if( h != "H3D" ) {
+		if( h != "HMD" ) {
 			if( h.charCodeAt(0) == ";".code )
-				throw "FBX was not converted to H3D";
+				throw "FBX was not converted to HMD";
 			if( h.charCodeAt(0) == 'X'.code )
-				throw "XBX was not converted to H3D";
+				throw "XBX was not converted to HMD";
 			throw "Invalid XBX header " + StringTools.urlEncode(h);
 		}
 		d.version = i.readByte();

+ 3 - 3
hxd/fmt/h3d/Writer.hx → hxd/fmt/hmd/Writer.hx

@@ -1,5 +1,5 @@
-package hxd.fmt.h3d;
-import hxd.fmt.h3d.Data;
+package hxd.fmt.hmd;
+import hxd.fmt.hmd.Data;
 
 class Writer {
 
@@ -111,7 +111,7 @@ class Writer {
 		var bytes = header.getBytes();
 		out = old;
 
-		out.writeString("H3D");
+		out.writeString("HMD");
 		out.writeByte(d.version);
 		out.writeInt32(bytes.length + 12);
 		out.write(bytes);

+ 1 - 1
hxd/res/EmbedOptions.hx

@@ -4,7 +4,7 @@ typedef EmbedOptions = {
 	?compressSounds : Bool,
 	?createXBX : Bool,
 	?xbxFilter : String -> hxd.fmt.fbx.Data.FbxNode -> hxd.fmt.fbx.Data.FbxNode,
-	?createH3D : Bool,
+	?createHMD : Bool,
 	?tmpDir : String,
 	?fontsChars : String,
 }

+ 4 - 4
hxd/res/FbxModel.hx

@@ -19,7 +19,7 @@ class FbxModel extends Resource {
 			lib = loader.load(entry.path.substr(0, -4) + "FBX").toFbx();
 			lib.loadXtra(entry.getBytes().toString());
 		case 'H'.code:
-			throw "FBX model was converted to H3D : use res.toH3d()";
+			throw "FBX model was converted to HMD : use res.toHmd()";
 		default:
 			throw "Unsupported model format " + entry.path;
 		}
@@ -27,9 +27,9 @@ class FbxModel extends Resource {
 		return lib;
 	}
 
-	public function toH3d() : hxd.fmt.h3d.Library {
-		var h3d = new hxd.fmt.h3d.Reader(new FileInput(entry)).readHeader();
-		return new hxd.fmt.h3d.Library(entry, h3d);
+	public function toHmd() : hxd.fmt.hmd.Library {
+		var hmd = new hxd.fmt.hmd.Reader(new FileInput(entry)).readHeader();
+		return new hxd.fmt.hmd.Library(entry, hmd);
 	}
 
 }

+ 4 - 4
hxd/res/FileTree.hx

@@ -118,15 +118,15 @@ class FileTree {
 				fullPath = tmp;
 			}
 			Context.registerModuleDependency(currentModule, fullPath);
-		case "fbx" if( options.createH3D ):
+		case "fbx" if( options.createHMD ):
 			var tmp = options.tmpDir + name + ".h3d";
 			if( getTime(tmp) < getTime(fullPath) || true ) {
 				Sys.println("Converting " + relPath);
-				var fbx = new hxd.fmt.fbx.H3DOut();
+				var fbx = new hxd.fmt.fbx.HMDOut();
 				fbx.loadTextFile(sys.io.File.getContent(fullPath));
-				var h3d = fbx.toH3D(fullPath.substr(0,fullPath.length-file.length), !StringTools.startsWith(file,"Anim_") );
+				var h3d = fbx.toHMD(fullPath.substr(0,fullPath.length-file.length), !StringTools.startsWith(file,"Anim_") );
 				var out = sys.io.File.write(tmp);
-				new hxd.fmt.h3d.Writer(out).write(h3d);
+				new hxd.fmt.hmd.Writer(out).write(h3d);
 				out.close();
 			}
 			Context.registerModuleDependency(currentModule, fullPath);

+ 2 - 2
samples/skin/Main.hx

@@ -3,7 +3,7 @@ import h3d.scene.*;
 class Main extends hxd.App {
 
 	override function init() {
-		var prim = hxd.Res.Model.toH3d();
+		var prim = hxd.Res.Model.toHmd();
 		var obj = prim.makeObject(loadTexture);
 		obj.scale(0.1);
 		s3d.addChild(obj);
@@ -33,7 +33,7 @@ class Main extends hxd.App {
 	}
 
 	static function main() {
-		hxd.Res.initEmbed({ createH3D : true });
+		hxd.Res.initEmbed({ createHMD : true });
 		new Main();
 	}