private void PrepareBoneInformation(SepdChunk sepd, PrmsChunk prms) { /* TODO!! B/C HURR DURR, DON'T KNOW https://www.the-gcn.com/topic/2859-oot-3d-3ds-model-format-discussion/page-3#entry46121 */ if (prms.SkinningMode == PrmsChunk.SkinningModes.PerVertex) { uint[] lookupInts = new uint[(int)(Root.VatrChunk.BoneIndexLookup.Length - sepd.BoneIndexLookupArrayOffset) / sepd.BoneIndexLookupSize]; for (int i = 0; i < lookupInts.Length; i++) { switch (sepd.BoneIndexLookupArrayDataType) { case Constants.PicaDataType.Byte: case Constants.PicaDataType.UnsignedByte: lookupInts[i] = (uint)Root.VatrChunk.BoneIndexLookup[sepd.BoneIndexLookupArrayOffset + (i * sizeof(byte))]; break; case Constants.PicaDataType.Short: case Constants.PicaDataType.UnsignedShort: lookupInts[i] = (uint)BitConverter.ToUInt16(Root.VatrChunk.BoneIndexLookup, (int)(sepd.BoneIndexLookupArrayOffset + (i * sizeof(ushort)))); break; case Constants.PicaDataType.Int: case Constants.PicaDataType.UnsignedInt: lookupInts[i] = (uint)BitConverter.ToUInt32(Root.VatrChunk.BoneIndexLookup, (int)(sepd.BoneIndexLookupArrayOffset + (i * sizeof(uint)))); break; case Constants.PicaDataType.Float: lookupInts[i] = (uint)BitConverter.ToSingle(Root.VatrChunk.BoneIndexLookup, (int)(sepd.BoneIndexLookupArrayOffset + (i * sizeof(float)))); break; } } GL.ActiveTexture(TextureUnit.Texture0 + vertBoneTexUnit); GL.BindTexture(TextureTarget.TextureBuffer, vertBoneTexId); GL.BindBuffer(BufferTarget.TextureBuffer, vertBoneBufferId); GL.BufferData <uint>(BufferTarget.TextureBuffer, new IntPtr(lookupInts.Length * sizeof(uint)), lookupInts, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.TextureBuffer, 0); } /* Maaaaaaybe? I dunno... not using this yet either */ Vector2[] weights = new Vector2[(int)(Root.VatrChunk.BoneWeights.Length - sepd.BoneWeightArrayOffset) / 2]; for (int i = 0, j = 0; i < weights.Length; i++, j += 2) { weights[i] = new Vector2( Root.VatrChunk.BoneWeights[sepd.BoneWeightArrayOffset + j], Root.VatrChunk.BoneWeights[sepd.BoneWeightArrayOffset + (j + 1)]); } for (int i = 0; i < prms.BoneIndexCount; i++) { Matrix4 matrix = Matrix4.Identity; SklChunk.Bone bone = Root.SklChunk.Bones.FirstOrDefault(x => x.BoneID == prms.BoneIndices[i]); if (bone != null) { matrix = bone.GetMatrix(prms.SkinningMode != PrmsChunk.SkinningModes.PerVertexNoTrans); } GL.UniformMatrix4(GL.GetUniformLocation(program, string.Format("boneMatrix[{0}]", i)), false, ref matrix); } }
private void RenderBuffer(PrmsChunk prms) { GL.BindBuffer(BufferTarget.ElementArrayBuffer, elementBufferObjects[prms]); GL.DrawElements(PrimitiveType.Triangles, prms.PrmChunk.NumberOfIndices, prms.PrmChunk.DrawElementsType, IntPtr.Zero); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); }
public SepdChunk(byte[] data, int offset, BaseCTRChunk parent) : base(data, offset, parent) { PrmsCount = BitConverter.ToUInt16(ChunkData, 0x08); Unknown0A = BitConverter.ToUInt16(ChunkData, 0x0A); UnknownFloat0C = BitConverter.ToSingle(ChunkData, 0x0C); UnknownFloat10 = BitConverter.ToSingle(ChunkData, 0x10); UnknownFloat14 = BitConverter.ToSingle(ChunkData, 0x14); Unknown18 = BitConverter.ToUInt32(ChunkData, 0x18); Unknown1C = BitConverter.ToUInt32(ChunkData, 0x1C); Unknown20 = BitConverter.ToUInt32(ChunkData, 0x20); int arrayCount = (BaseCTRChunk.IsMajora3D ? 9 : 8); ArrayOffsets = new uint[arrayCount]; ArrayScales = new float[arrayCount]; ArrayDataTypes = new Constants.PicaDataType[arrayCount]; ArrayUnknown1 = new ushort[arrayCount]; ArrayUnknown2 = new uint[arrayCount]; ArrayUnknown3 = new uint[arrayCount]; ArrayUnknown4 = new uint[arrayCount]; ArrayUnknown5 = new uint[arrayCount]; for (int i = 0; i < arrayCount; i++) { ArrayOffsets[i] = BitConverter.ToUInt32(ChunkData, 0x24 + (i * 0x1C)); ArrayScales[i] = BitConverter.ToSingle(ChunkData, 0x28 + (i * 0x1C)); ArrayDataTypes[i] = (Constants.PicaDataType)BitConverter.ToUInt16(ChunkData, 0x2C + (i * 0x1C)); ArrayUnknown1[i] = BitConverter.ToUInt16(ChunkData, 0x2E + (i * 0x1C)); ArrayUnknown2[i] = BitConverter.ToUInt32(ChunkData, 0x30 + (i * 0x1C)); ArrayUnknown3[i] = BitConverter.ToUInt32(ChunkData, 0x34 + (i * 0x1C)); ArrayUnknown4[i] = BitConverter.ToUInt32(ChunkData, 0x38 + (i * 0x1C)); ArrayUnknown5[i] = BitConverter.ToUInt32(ChunkData, 0x3C + (i * 0x1C)); } Unknown_104OoT_120MM = BitConverter.ToUInt32(ChunkData, !BaseCTRChunk.IsMajora3D ? 0x104 : 0x120); int prmsDataOffset = (!BaseCTRChunk.IsMajora3D ? 0x108 : 0x124); PrmsChunks = new PrmsChunk[PrmsCount]; for (int i = 0; i < PrmsChunks.Length; i++) { PrmsChunks[i] = new PrmsChunk(ChunkData, (int)BitConverter.ToUInt16(ChunkData, prmsDataOffset + (i * 2)), this); } switch (NormalArrayDataType) { case Constants.PicaDataType.Byte: case Constants.PicaDataType.UnsignedByte: NormalPointerType = NormalPointerType.Byte; NormalSize = (sizeof(byte) * 3); break; case Constants.PicaDataType.Short: case Constants.PicaDataType.UnsignedShort: NormalPointerType = NormalPointerType.Short; NormalSize = (sizeof(ushort) * 3); break; case Constants.PicaDataType.Int: case Constants.PicaDataType.UnsignedInt: NormalPointerType = NormalPointerType.Int; NormalSize = (sizeof(uint) * 3); break; case Constants.PicaDataType.Float: NormalPointerType = NormalPointerType.Float; NormalSize = (sizeof(float) * 3); break; } switch (ColorArrayDataType) { case Constants.PicaDataType.Byte: ColorPointerType = ColorPointerType.Byte; ColorSize = (sizeof(sbyte) * 4); break; case Constants.PicaDataType.UnsignedByte: ColorPointerType = ColorPointerType.UnsignedByte; ColorSize = (sizeof(byte) * 4); break; case Constants.PicaDataType.Short: ColorPointerType = ColorPointerType.Short; ColorSize = (sizeof(short) * 4); break; case Constants.PicaDataType.UnsignedShort: ColorPointerType = ColorPointerType.UnsignedShort; ColorSize = (sizeof(ushort) * 4); break; case Constants.PicaDataType.Int: ColorPointerType = ColorPointerType.Int; ColorSize = (sizeof(int) * 4); break; case Constants.PicaDataType.UnsignedInt: ColorPointerType = ColorPointerType.UnsignedInt; ColorSize = (sizeof(uint) * 4); break; case Constants.PicaDataType.Float: ColorPointerType = ColorPointerType.Float; ColorSize = (sizeof(float) * 4); break; } switch (TextureCoordArrayDataType) { case Constants.PicaDataType.Byte: case Constants.PicaDataType.UnsignedByte: /* Needs conversion to short during rendering! */ TexCoordPointerType = TexCoordPointerType.Short; TexCoordSize = (sizeof(byte) * 2); break; case Constants.PicaDataType.Short: case Constants.PicaDataType.UnsignedShort: TexCoordPointerType = TexCoordPointerType.Short; TexCoordSize = (sizeof(ushort) * 2); break; case Constants.PicaDataType.Int: case Constants.PicaDataType.UnsignedInt: TexCoordPointerType = TexCoordPointerType.Int; TexCoordSize = (sizeof(uint) * 2); break; case Constants.PicaDataType.Float: TexCoordPointerType = TexCoordPointerType.Float; TexCoordSize = (sizeof(float) * 2); break; } switch (VertexArrayDataType) { case Constants.PicaDataType.Byte: case Constants.PicaDataType.UnsignedByte: /* Needs conversion to short during rendering! */ VertexPointerType = VertexPointerType.Short; VertexSize = (sizeof(byte) * 3); break; case Constants.PicaDataType.Short: case Constants.PicaDataType.UnsignedShort: VertexPointerType = VertexPointerType.Short; VertexSize = (sizeof(ushort) * 3); break; case Constants.PicaDataType.Int: case Constants.PicaDataType.UnsignedInt: VertexPointerType = VertexPointerType.Int; VertexSize = (sizeof(uint) * 3); break; case Constants.PicaDataType.Float: VertexPointerType = VertexPointerType.Float; VertexSize = (sizeof(float) * 3); break; } switch (BoneIndexLookupArrayDataType) { case Constants.PicaDataType.Byte: case Constants.PicaDataType.UnsignedByte: BoneIndexLookupSize = sizeof(byte); break; case Constants.PicaDataType.Short: case Constants.PicaDataType.UnsignedShort: BoneIndexLookupSize = sizeof(ushort); break; case Constants.PicaDataType.Int: case Constants.PicaDataType.UnsignedInt: BoneIndexLookupSize = sizeof(uint); break; case Constants.PicaDataType.Float: BoneIndexLookupSize = sizeof(float); break; } /* For information purposes */ TotalPrimitives = 0; foreach (PrmsChunk prms in PrmsChunks) { TotalPrimitives += (prms.PrmChunk.NumberOfIndices / 3); } }