From e962fd89af865d6e01522e9752f5fbd855ce128a Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 5 Mar 2011 05:25:14 +0100 Subject: partially working obj importer. still untested in-game --- NW4RTools/Models/Material.cs | 13 ++++++++++ NW4RTools/Models/OpenGL/GLModel.cs | 2 +- NW4RTools/Models/VertexData.cs | 52 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) (limited to 'NW4RTools/Models') diff --git a/NW4RTools/Models/Material.cs b/NW4RTools/Models/Material.cs index 0bf0acc..519790c 100644 --- a/NW4RTools/Models/Material.cs +++ b/NW4RTools/Models/Material.cs @@ -18,6 +18,17 @@ namespace NW4RTools.Models { public byte MapType; public byte Flags; public Matrix TexMatrix; + + public SRTSettingInfo() { + ScaleX = 1.0f; + ScaleY = 1.0f; + + CameraID = 0xFF; + LightID = 0xFf; + Flags = 1; + + TexMatrix.Identity(); + } } @@ -62,6 +73,8 @@ namespace NW4RTools.Models { IndirectTexMtxCalcMethod2 = new byte[4]; TexObj = new byte[8][]; // todo + SRTSettings = new SRTSettingInfo[8]; + ChanCtrls = new ChanCtrl[2]; TextureInfos = new List(); } } diff --git a/NW4RTools/Models/OpenGL/GLModel.cs b/NW4RTools/Models/OpenGL/GLModel.cs index 8ca3f31..072ea00 100644 --- a/NW4RTools/Models/OpenGL/GLModel.cs +++ b/NW4RTools/Models/OpenGL/GLModel.cs @@ -257,7 +257,7 @@ namespace NW4RTools.Models.OpenGL { break; if ((cmd & (int)GXCommand.DrawPrimitiveMask) != 0) { - PrimitiveType prim = (PrimitiveType)((cmd >> 3) & 7); + PrimitiveType prim = (PrimitiveType)((cmd >> (byte)GXCommand.PrimitiveShiftAmount) & 7); int vtxCount = dl.ReadUInt16(); if ((cmd & 7) != 0) diff --git a/NW4RTools/Models/VertexData.cs b/NW4RTools/Models/VertexData.cs index 187b9aa..feb8eb6 100644 --- a/NW4RTools/Models/VertexData.cs +++ b/NW4RTools/Models/VertexData.cs @@ -60,6 +60,54 @@ namespace NW4RTools.Models { } } + public virtual void Save() { + int elementCount = Data[0].Length; + float scale = 1.0f / (1 << Fraction); + var output = new OutputStream(); + + switch (ComponentType) { + case VertexSettings.CompType.UInt8: + foreach (var array in Data) { + for (int i = 0; i < elementCount; i++) { + output.WriteByte((byte)(array[i] / scale)); + } + } + break; + case VertexSettings.CompType.Int8: + foreach (var array in Data) { + for (int i = 0; i < elementCount; i++) { + output.WriteSByte((sbyte)(array[i] / scale)); + } + } + break; + case VertexSettings.CompType.UInt16: + foreach (var array in Data) { + for (int i = 0; i < elementCount; i++) { + output.WriteUInt16((ushort)(array[i] / scale)); + } + } + break; + case VertexSettings.CompType.Int16: + foreach (var array in Data) { + for (int i = 0; i < elementCount; i++) { + output.WriteInt16((short)(array[i] / scale)); + } + } + break; + case VertexSettings.CompType.Float32: + foreach (var array in Data) { + for (int i = 0; i < elementCount; i++) { + output.WriteFloat(array[i]); + } + } + break; + default: + throw new NotImplementedException(String.Format("unimplemented type {0}", (int)ComponentType)); + } + + RawData = output.GetBuffer(); + } + public abstract int GetRealCount(); } @@ -186,6 +234,10 @@ namespace NW4RTools.Models { return ret; } + + public override void Save() { + throw new NotImplementedException(); + } } -- cgit v1.2.3