From c3fe440719b4e9a3fb3f4debe28c16cd7c60d7de Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 6 Apr 2011 02:31:39 +0200 Subject: exporters now properly handle position data which only contains X/Y --- NW4RTools/ColladaExporter.cs | 12 ++++++------ NW4RTools/ObjExporter.cs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/NW4RTools/ColladaExporter.cs b/NW4RTools/ColladaExporter.cs index cd5aaf1..ccdc6b0 100644 --- a/NW4RTools/ColladaExporter.cs +++ b/NW4RTools/ColladaExporter.cs @@ -478,15 +478,15 @@ namespace NW4RTools { var posArray = new float_array(); posArray.id = name + "-lib-Position-array"; - posArray.count = (ulong)(posData.GetRealCount() * posData.EntryCount); + posArray.count = (ulong)(3 * posData.EntryCount); posArray.Values = new double[posArray.count]; dest = 0; for (int i = 0; i < posData.EntryCount; i++) { float[] data = posData.GetEntry(i); - for (int j = 0; j < data.Length; j++) { - posArray.Values[dest++] = data[j]; - } + posArray.Values[dest++] = data[0]; + posArray.Values[dest++] = data[1]; + posArray.Values[dest++] = (data.Length <= 2) ? 0 : data[2]; } posSource.Item = posArray; @@ -496,9 +496,9 @@ namespace NW4RTools { var posAcc = posSource.technique_common.accessor = new accessor(); posAcc.source = String.Format("#{0}-lib-Position-array", name); posAcc.count = posData.EntryCount; - posAcc.stride = (ulong)posData.GetRealCount(); + posAcc.stride = 3; - posAcc.param = new param[posData.GetRealCount()]; + posAcc.param = new param[3]; string[] posParamNames = new string[] { "X", "Y", "Z" }; for (int i = 0; i < posAcc.param.Length; i++) { diff --git a/NW4RTools/ObjExporter.cs b/NW4RTools/ObjExporter.cs index 2bd791c..214f84a 100644 --- a/NW4RTools/ObjExporter.cs +++ b/NW4RTools/ObjExporter.cs @@ -39,10 +39,14 @@ namespace NW4RTools { foreach (var kv in CurrentModel.VtxPosData) { VtxPosOffsets[kv.Value] = Offset; Output.WriteLine("# Vertex Positions: {0} [offset {1}]", kv.Key, Offset); - + for (int i = 0; i < kv.Value.EntryCount; i++) { float[] v = kv.Value.GetEntry(i); - Output.WriteLine("v {0} {1} {2}", v[0], v[1], v[2]); + if (kv.Value.ComponentCount == VertexSettings.CompCount.Position2) { + Output.WriteLine("v {0} {1} 0.0", v[0], v[1]); + } else { + Output.WriteLine("v {0} {1} {2}", v[0], v[1], v[2]); + } } Offset += kv.Value.EntryCount; @@ -140,12 +144,15 @@ namespace NW4RTools { GXIndexedVertex[] vtxs = new GXIndexedVertex[vtxCount]; string[] pVtxs = new string[vtxCount]; + // this is a little hackish, oh well + string nrmPrefix = (vs.NormalDesc == VertexSettings.DescType.None) ? "" : "/"; + for (int i = 0; i < vtxCount; i++) { vtxs[i].LoadFrom(dl, vs); string tc = (vtxs[i].TexCoords[0] == -1) ? "" : (tcOffset + vtxs[i].TexCoords[0]).ToString(); - string n = (vtxs[i].Normal == -1) ? "" : (nrmOffset + vtxs[i].Normal).ToString(); - pVtxs[i] = String.Format(" {0}/{1}/{2}", posOffset + vtxs[i].Position, tc, n); + string n = (vtxs[i].Normal == -1) ? "" : "/" + (nrmOffset + vtxs[i].Normal).ToString(); + pVtxs[i] = String.Format(" {0}/{1}{2}{3}", posOffset + vtxs[i].Position, tc, nrmPrefix, n); } switch (prim) { -- cgit v1.2.3