public void SetAttributeIndex(GXVertexAttribute attribute, uint index) { switch (attribute) { case GXVertexAttribute.PositionMatrixIdx: PositionMatrixIDxIndex = index; break; case GXVertexAttribute.Position: PositionIndex = index; break; case GXVertexAttribute.Normal: NormalIndex = index; break; case GXVertexAttribute.Color0: Color0Index = index; break; case GXVertexAttribute.Color1: Color1Index = index; break; case GXVertexAttribute.Tex0: TexCoord0Index = index; break; case GXVertexAttribute.Tex1: TexCoord1Index = index; break; case GXVertexAttribute.Tex2: TexCoord2Index = index; break; case GXVertexAttribute.Tex3: TexCoord3Index = index; break; case GXVertexAttribute.Tex4: TexCoord4Index = index; break; case GXVertexAttribute.Tex5: TexCoord5Index = index; break; case GXVertexAttribute.Tex6: TexCoord6Index = index; break; case GXVertexAttribute.Tex7: TexCoord7Index = index; break; default: throw new ArgumentException("attribute"); } }
private void SetAssimpColorAttribute(int channel, GXVertexAttribute colorAttrib, Assimp.Mesh mesh) { List <Color> tempList = new List <Color>(); Color color; for (int col = 0; col < mesh.VertexColorChannels[channel].Count; col++) { color = mesh.VertexColorChannels[channel][col].ToSuperBMDColorRGBA(); if (!tempList.Contains(color)) { tempList.Add(color); } } if (!Attributes.CheckAttribute(colorAttrib)) { Attributes.SetAttributeData(colorAttrib, tempList); } else { List <Color> attribData = (List <Color>)Attributes.GetAttributeData(colorAttrib); foreach (Color col in tempList) { if (!attribData.Contains(col)) { attribData.Add(col); } } Attributes.SetAttributeData(colorAttrib, attribData); } }
private void SetAssimpTexCoordAttribute(int channel, GXVertexAttribute texCoordAttrib, Assimp.Mesh mesh) { List <Vector2> tempList = new List <Vector2>(); for (int vec = 0; vec < mesh.TextureCoordinateChannels[channel].Count; vec++) { Vector2 tempCoord = mesh.TextureCoordinateChannels[channel][vec].ToOpenTKVector2(); //tempCoord = new Vector2(tempCoord.X, 1.0f - tempCoord.Y); tempCoord.Y = 1.0f - tempCoord.Y; if (!tempList.Contains(tempCoord)) { tempList.Add(tempCoord); } } if (!Attributes.CheckAttribute(texCoordAttrib)) { Attributes.SetAttributeData(texCoordAttrib, tempList); } else { List <Vector2> attribData = (List <Vector2>)Attributes.GetAttributeData(texCoordAttrib); foreach (Vector2 vec in tempList) { if (!attribData.Contains(vec)) { attribData.Add(vec); } } Attributes.SetAttributeData(texCoordAttrib, attribData); } }
public void SetAttribute(GXVertexAttribute attribute, VertexInputType inputType, int vertexIndex) { if (CheckAttribute(attribute)) { throw new Exception($"Attribute \"{ attribute }\" is already in the vertex descriptor!"); } Attributes.Add(attribute, new Tuple <VertexInputType, int>(inputType, vertexIndex)); }
public bool CheckAttribute(GXVertexAttribute attribute) { if (m_Attributes.Contains(attribute)) { return(true); } else { return(false); } }
public VertexInputType GetAttributeType(GXVertexAttribute attribute) { if (CheckAttribute(attribute)) { return(Attributes[attribute].Item1); } else { throw new ArgumentException("attribute"); } }
public int GetAttributeIndex(GXVertexAttribute attribute) { if (CheckAttribute(attribute)) { return(Attributes[attribute].Item2); } else { throw new ArgumentException("attribute"); } }
public object GetAttributeData(GXVertexAttribute attribute) { if (!CheckAttribute(attribute)) { return(null); } switch (attribute) { case GXVertexAttribute.Position: return(Positions); case GXVertexAttribute.Normal: return(Normals); case GXVertexAttribute.Color0: return(Color_0); case GXVertexAttribute.Color1: return(Color_1); case GXVertexAttribute.Tex0: return(TexCoord_0); case GXVertexAttribute.Tex1: return(TexCoord_1); case GXVertexAttribute.Tex2: return(TexCoord_2); case GXVertexAttribute.Tex3: return(TexCoord_3); case GXVertexAttribute.Tex4: return(TexCoord_4); case GXVertexAttribute.Tex5: return(TexCoord_5); case GXVertexAttribute.Tex6: return(TexCoord_6); case GXVertexAttribute.Tex7: return(TexCoord_7); default: throw new ArgumentException("attribute"); } }
public ShapeVertexDescriptor(EndianBinaryReader reader, int offset) { Attributes = new SortedDictionary <GXVertexAttribute, Tuple <VertexInputType, int> >(); reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin); int index = 0; GXVertexAttribute attrib = (GXVertexAttribute)reader.ReadInt32(); while (attrib != GXVertexAttribute.Null) { Attributes.Add(attrib, new Tuple <VertexInputType, int>((VertexInputType)reader.ReadInt32(), index)); index++; attrib = (GXVertexAttribute)reader.ReadInt32(); } }
public uint GetAttributeIndex(GXVertexAttribute attribute) { switch (attribute) { case GXVertexAttribute.PositionMatrixIdx: return(PositionMatrixIDxIndex); case GXVertexAttribute.Position: return(PositionIndex); case GXVertexAttribute.Normal: return(NormalIndex); case GXVertexAttribute.Color0: return(Color0Index); case GXVertexAttribute.Color1: return(Color1Index); case GXVertexAttribute.Tex0: return(TexCoord0Index); case GXVertexAttribute.Tex1: return(TexCoord1Index); case GXVertexAttribute.Tex2: return(TexCoord2Index); case GXVertexAttribute.Tex3: return(TexCoord3Index); case GXVertexAttribute.Tex4: return(TexCoord4Index); case GXVertexAttribute.Tex5: return(TexCoord5Index); case GXVertexAttribute.Tex6: return(TexCoord6Index); case GXVertexAttribute.Tex7: return(TexCoord7Index); default: throw new ArgumentException("attribute"); } }
public VTX1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null) { Attributes = new VertexData(); StorageFormats = new SortedDictionary <GXVertexAttribute, Tuple <GXDataType, byte> >(); reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin); reader.SkipInt32(); int vtx1Size = reader.ReadInt32(); int attributeHeaderOffset = reader.ReadInt32(); if (modelstats != null) { modelstats.VTX1Size = vtx1Size; } int[] attribDataOffsets = new int[13]; for (int i = 0; i < 13; i++) { attribDataOffsets[i] = reader.ReadInt32(); } GXVertexAttribute attrib = (GXVertexAttribute)reader.ReadInt32(); while (attrib != GXVertexAttribute.Null) { GXComponentCount componentCount = (GXComponentCount)reader.ReadInt32(); GXDataType componentType = (GXDataType)reader.ReadInt32(); byte fractionalBitCount = reader.ReadByte(); StorageFormats.Add(attrib, new Tuple <GXDataType, byte>(componentType, fractionalBitCount)); reader.Skip(3); long curPos = reader.BaseStream.Position; int attribDataSize = 0; int attribOffset = GetAttributeDataOffset(attribDataOffsets, vtx1Size, attrib, out attribDataSize); int attribCount = GetAttributeDataCount(attribDataSize, attrib, componentType, componentCount); Attributes.SetAttributeData(attrib, LoadAttributeData(reader, offset + attribOffset, attribCount, fractionalBitCount, attrib, componentType, componentCount)); reader.BaseStream.Seek(curPos, System.IO.SeekOrigin.Begin); attrib = (GXVertexAttribute)reader.ReadInt32(); } reader.BaseStream.Seek(offset + vtx1Size, System.IO.SeekOrigin.Begin); }
public void SetAttributeData(GXVertexAttribute attribute, object data) { if (!CheckAttribute(attribute)) { m_Attributes.Add(attribute); } switch (attribute) { case GXVertexAttribute.Position: if (data.GetType() != typeof(List <Vector3>)) { throw new ArgumentException("position data"); } else { Positions = (List <Vector3>)data; } break; case GXVertexAttribute.Normal: if (data.GetType() != typeof(List <Vector3>)) { throw new ArgumentException("normal data"); } else { Normals = (List <Vector3>)data; } break; case GXVertexAttribute.Color0: if (data.GetType() != typeof(List <Color>)) { throw new ArgumentException("color0 data"); } else { Color_0 = (List <Color>)data; foreach (Color color in Color_0) { if (color.A < 1.0) { Console.WriteLine("BMD has Vertex Alpha on Channel 0"); break; } } } break; case GXVertexAttribute.Color1: if (data.GetType() != typeof(List <Color>)) { throw new ArgumentException("color1 data"); } else { Color_1 = (List <Color>)data; foreach (Color color in Color_1) { if (color.A < 1.0) { Console.WriteLine("BMD has Vertex Alpha on Channel 1"); break; } } } break; case GXVertexAttribute.Tex0: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord0 data"); } else { TexCoord_0 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex1: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord1 data"); } else { TexCoord_1 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex2: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord2 data"); } else { TexCoord_2 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex3: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord3 data"); } else { TexCoord_3 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex4: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord4 data"); } else { TexCoord_4 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex5: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord5 data"); } else { TexCoord_5 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex6: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord6 data"); } else { TexCoord_6 = (List <Vector2>)data; } break; case GXVertexAttribute.Tex7: if (data.GetType() != typeof(List <Vector2>)) { throw new ArgumentException("texcoord7 data"); } else { TexCoord_7 = (List <Vector2>)data; } break; } }
public bool CheckAttribute(GXVertexAttribute attribute) { return(Attributes.ContainsKey(attribute)); }
private int GetAttributeDataOffset(int[] offsets, int vtx1Size, GXVertexAttribute attribute, out int size) { int offset = 0; size = 0; Vtx1OffsetIndex start = Vtx1OffsetIndex.PositionData; switch (attribute) { case GXVertexAttribute.Position: start = Vtx1OffsetIndex.PositionData; offset = offsets[(int)Vtx1OffsetIndex.PositionData]; break; case GXVertexAttribute.Normal: start = Vtx1OffsetIndex.NormalData; offset = offsets[(int)Vtx1OffsetIndex.NormalData]; break; case GXVertexAttribute.Color0: start = Vtx1OffsetIndex.Color0Data; offset = offsets[(int)Vtx1OffsetIndex.Color0Data]; break; case GXVertexAttribute.Color1: start = Vtx1OffsetIndex.Color1Data; offset = offsets[(int)Vtx1OffsetIndex.Color1Data]; break; case GXVertexAttribute.Tex0: start = Vtx1OffsetIndex.TexCoord0Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord0Data]; break; case GXVertexAttribute.Tex1: start = Vtx1OffsetIndex.TexCoord1Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord1Data]; break; case GXVertexAttribute.Tex2: start = Vtx1OffsetIndex.TexCoord2Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord2Data]; break; case GXVertexAttribute.Tex3: start = Vtx1OffsetIndex.TexCoord3Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord3Data]; break; case GXVertexAttribute.Tex4: start = Vtx1OffsetIndex.TexCoord4Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord4Data]; break; case GXVertexAttribute.Tex5: start = Vtx1OffsetIndex.TexCoord5Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord5Data]; break; case GXVertexAttribute.Tex6: start = Vtx1OffsetIndex.TexCoord6Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord6Data]; break; case GXVertexAttribute.Tex7: start = Vtx1OffsetIndex.TexCoord7Data; offset = offsets[(int)Vtx1OffsetIndex.TexCoord7Data]; break; default: throw new ArgumentException("attribute"); } for (int i = (int)start + 1; i < 13; i++) { if (i == 12) { size = vtx1Size - offset; break; } int nextOffset = offsets[i]; if (nextOffset == 0) { continue; } else { size = nextOffset - offset; break; } } return(offset); }
public object LoadAttributeData(EndianBinaryReader reader, int offset, int count, byte frac, GXVertexAttribute attribute, GXDataType dataType, GXComponentCount compCount) { reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin); object final = null; switch (attribute) { case GXVertexAttribute.Position: switch (compCount) { case GXComponentCount.Position_XY: final = LoadVec2Data(reader, frac, count, dataType); break; case GXComponentCount.Position_XYZ: final = LoadVec3Data(reader, frac, count, dataType); break; } break; case GXVertexAttribute.Normal: switch (compCount) { case GXComponentCount.Normal_XYZ: final = LoadVec3Data(reader, frac, count, dataType); break; case GXComponentCount.Normal_NBT: break; case GXComponentCount.Normal_NBT3: break; } break; case GXVertexAttribute.Color0: case GXVertexAttribute.Color1: final = LoadColorData(reader, count, dataType); break; case GXVertexAttribute.Tex0: case GXVertexAttribute.Tex1: case GXVertexAttribute.Tex2: case GXVertexAttribute.Tex3: case GXVertexAttribute.Tex4: case GXVertexAttribute.Tex5: case GXVertexAttribute.Tex6: case GXVertexAttribute.Tex7: switch (compCount) { case GXComponentCount.TexCoord_S: final = LoadSingleFloat(reader, frac, count, dataType); break; case GXComponentCount.TexCoord_ST: final = LoadVec2Data(reader, frac, count, dataType); break; } break; } return(final); }
public VtxAttrFmtParameter(ushort Unknown, GXVertexAttribute vertexAttrib) { ParameterType = ParameterType.VtxAttrFmt; Unknown_1 = Unknown; VertexAttribute = vertexAttrib; }
private int GetAttributeDataCount(int size, GXVertexAttribute attribute, GXDataType dataType, GXComponentCount compCount) { int compCnt = 0; int compStride = 0; if (attribute == GXVertexAttribute.Color0 || attribute == GXVertexAttribute.Color1) { switch (dataType) { case GXDataType.RGB565: case GXDataType.RGBA4: compCnt = 1; compStride = 2; break; case GXDataType.RGB8: case GXDataType.RGBX8: case GXDataType.RGBA6: case GXDataType.RGBA8: compCnt = 4; compStride = 1; break; } } else { switch (dataType) { case GXDataType.Unsigned8: case GXDataType.Signed8: compStride = 1; break; case GXDataType.Unsigned16: case GXDataType.Signed16: compStride = 2; break; case GXDataType.Float32: compStride = 4; break; } switch (attribute) { case GXVertexAttribute.Position: if (compCount == GXComponentCount.Position_XY) { compCnt = 2; } else if (compCount == GXComponentCount.Position_XYZ) { compCnt = 3; } break; case GXVertexAttribute.Normal: if (compCount == GXComponentCount.Normal_XYZ) { compCnt = 3; } break; case GXVertexAttribute.Tex0: case GXVertexAttribute.Tex1: case GXVertexAttribute.Tex2: case GXVertexAttribute.Tex3: case GXVertexAttribute.Tex4: case GXVertexAttribute.Tex5: case GXVertexAttribute.Tex6: case GXVertexAttribute.Tex7: if (compCount == GXComponentCount.TexCoord_S) { compCnt = 1; } else if (compCount == GXComponentCount.TexCoord_ST) { compCnt = 2; } break; } } return(size / (compCnt * compStride)); }