Ver Fonte

Exporter: move code from hide to fbx writter

lviguier há 1 ano atrás
pai
commit
afa68db7bf
2 ficheiros alterados com 73 adições e 1 exclusões
  1. 5 1
      h3d/scene/Object.hx
  2. 68 0
      hxd/fmt/fbx/Writer.hx

+ 5 - 1
h3d/scene/Object.hx

@@ -230,7 +230,11 @@ class Object {
 	inline function get_drawn() return flags.has(FDrawn);
 	inline function set_posChanged(b) return flags.set(FPosChanged, b || follow != null);
 	inline function set_culled(b) return flags.set(FCulled, b);
-	inline function set_visible(b) return flags.set(FVisible,b);
+	function set_visible(b) {
+		if (this.name == "light")
+			trace(b);
+		return flags.set(FVisible,b);
+	};
 	inline function set_allocated(b) return flags.set(FAllocated, b);
 	inline function set_followPositionOnly(b) return flags.set(FFollowPositionOnly, b);
 	inline function set_lightCameraCenter(b) return flags.set(FLightCameraCenter, b);

+ 68 - 0
hxd/fmt/fbx/Writer.hx

@@ -3,6 +3,14 @@ package hxd.fmt.fbx;
 import hxd.fmt.fbx.Data;
 import hxd.fmt.hmd.Data;
 
+typedef ExportParams = {
+	forward: Int,
+	forwardSign: Int,
+	up: Int,
+	upSign: Int,
+}
+
+
 class Writer {
 	var out: haxe.io.Output;
 
@@ -785,4 +793,64 @@ class Writer {
 
 		out.write(bytes);
 	}
+
+	public function export(toExport: Array<h3d.scene.Object>, destinationPath: String, callb : Void -> Void, ?params : ExportParams) {
+		if (this.out == null)
+			this.out = new haxe.io.BytesOutput();
+
+		function clean( obj : h3d.scene.Object ) : h3d.scene.Object {
+			if (Std.downcast(obj, h3d.scene.Interactive) != null)
+				return null;
+
+			var o = new h3d.scene.Object();
+			var multiMat = Std.downcast(obj, h3d.scene.MultiMaterial);
+			if (multiMat != null)
+				o = new h3d.scene.MultiMaterial(multiMat.primitive, multiMat.materials);
+			else {
+				var m = Std.downcast(obj, h3d.scene.Mesh);
+				if (m != null)
+					o = new h3d.scene.Mesh(m.primitive, m.material);
+			}
+
+			o.x = obj.x;
+			o.y = obj.y;
+			o.z = obj.z;
+			o.scaleX = obj.scaleX;
+			o.scaleY = obj.scaleY;
+			o.scaleZ = obj.scaleZ;
+			@:privateAccess o.qRot.load(@:privateAccess obj.qRot);
+			o.name = obj.name;
+			o.follow = obj.follow;
+			o.followPositionOnly = obj.followPositionOnly;
+			o.visible = obj.visible;
+			if( obj.defaultTransform != null )
+				o.defaultTransform = obj.defaultTransform.clone();
+			for( c in @:privateAccess obj.children ) {
+				var c2 = clean(c);
+				if (c2 == null)
+					continue;
+				@:privateAccess c2.parent = o;
+				@:privateAccess o.children.push(c2);
+			}
+
+			return o;
+		}
+
+		// Clean a bit the object hierarchy to remove non-needed objects
+		// (Interactibles for example)
+		var roots = new Array<h3d.scene.Object>();
+		for (o in toExport) {
+			var t = clean(o);
+			if (t != null)
+				roots.push(t);
+		}
+
+		// Handle the export of selection into a fbx file
+		if (destinationPath != null) {
+			var out = new haxe.io.BytesOutput();
+			new hxd.fmt.fbx.Writer(out).write(roots, params);
+			sys.io.File.saveBytes(destinationPath, out.getBytes());
+			callb();
+		}
+	}
 }