Browse Source

xtra : export selection, fix UV flip, urlEncode names

ncannasse 10 năm trước cách đây
mục cha
commit
a59bd3250d
2 tập tin đã thay đổi với 27 bổ sung7 xóa
  1. 1 1
      hxd/fmt/fbx/BaseLibrary.hx
  2. 26 6
      tools/xtra/xtraExporter.ms

+ 1 - 1
hxd/fmt/fbx/BaseLibrary.hx

@@ -148,7 +148,7 @@ class BaseLibrary {
 		var xml = Xml.parse(data).firstElement();
 		if( uvAnims == null ) uvAnims = new Map();
 		for( e in new haxe.xml.Fast(xml).elements ) {
-			var obj = e.att.name;
+			var obj = StringTools.urlDecode(e.att.name);
 			var frames = [for( f in e.elements ) { var f = f.innerData.split(" ");  { t : Std.parseFloat(f[0]) * 9622116.25, u : Std.parseFloat(f[1]), v : Std.parseFloat(f[2]) }} ];
 			uvAnims.set(obj, frames);
 		}

+ 26 - 6
tools/xtra/xtraExporter.ms

@@ -1,19 +1,38 @@
 macroScript XtraExport Category:"Shiro" tooltip:"Xtra Export" buttontext:"XTRA"
 (
+
+fn f_URLEncode _STR =
+(
+dotnet.loadassembly "System.Web"
+dotnet.loadassembly "System.Text"
+local httpUtility = dotnetClass "System.Web.HttpUtility"
+local enc = dotnetClass "System.Text.Encoding"
+local urlEncodedString = httpUtility.UrlEncode _STR enc.UTF8
+return urlEncodedString
+)
+
 	function export file = (
-		format "Exporting %" file
+		format "Exporting %\n" file
 		deleteFile file
 		local f = createFile file
 		local somethingDone = false
 		format "<xtra>\n" to:f
-		for m in Geometry do (
+		local sel = getCurrentSelection()
+		if sel.count == 0 then sel = Geometry
+		for m in sel do (
 			if m.material == undefined then continue
 			local diffuse = m.material.diffuseMap
 			if diffuse == undefined then continue
 			local coords = diffuse.coords
 			local hasUVAnim = false
 			local curU = 0.
-			local curV = 0.	
+			local curV = 0.
+			local flip = 1
+			/*
+				when inverting faces, we have no way to tell that culling was flip and UV anim will go another way.
+				Let's mark such objects with backfaceCull
+			*/
+			if m.backfaceCull then flip = -1
 			local timeVal = animationRange.start.ticks
 			for frame = animationRange.start to animationRange.end do (
 				at time frame (			
@@ -21,12 +40,13 @@ macroScript XtraExport Category:"Shiro" tooltip:"Xtra Export" buttontext:"XTRA"
 						if not hasUVAnim then (
 							somethingDone = true
 							hasUVAnim = true
-							format "<uv name='%'>\n" m.name to:f
+							local name = f_URLEncode(m.name)
+							format "<uv name='%'>\n" name to:f
 							if timeVal != frame.ticks then format "<f>% % %</f>\n" timeVal curU curV to:f
 						)
 						timeVal = frame.ticks
-						curU = coords.U_offset
-						curV = coords.V_offset				
+						curU = coords.U_offset * flip
+						curV = coords.V_offset	* flip
 						format "<f>% % %</f>\n" timeVal curU curV to:f
 					)
 				)