// To add: Tangent, Binormal (sizes/etc??) // BlendIndices/BlendWeights: Type = Color ... stored as ARGB I think but presumably swizzled as RGBA internal Vertex(BinaryReader br, Mesh mesh) : this() { TextureCoordinates = new Vector2[MaxTextureCoordinates]; VertexElement[] elements = mesh.VertexDeclaration.Elements; foreach (var element in elements) { if (element.Stream == -1) { break; } switch(element.Usage) { case VertexElementUsage.Position: Position = new Vector3(br); break; case VertexElementUsage.Normal: Normal = new Vector3(br); break; case VertexElementUsage.TextureCoordinate: TextureCoordinates[element.UsageIndex] = new Vector2(br); break; case VertexElementUsage.Color: if (element.UsageIndex == 0) // As per DirectX docs { DiffuseColor = br.ReadUInt32(); } else if (element.UsageIndex == 1) // As per DirectX docs { SpecularColor = br.ReadUInt32(); } else { br.ReadUInt32(); } break; case VertexElementUsage.BlendWeight: BlendWeights = new float[4]; uint tmpWeight = br.ReadUInt32(); BlendWeights[0] = ((tmpWeight >> 16) & 0xFF)/255.0f; BlendWeights[1] = ((tmpWeight >> 8) & 0xFF)/255.0f; BlendWeights[2] = ((tmpWeight) & 0xFF)/255.0f; BlendWeights[3] = ((tmpWeight >> 24) & 0xFF)/255.0f; break; case VertexElementUsage.BlendIndices: BlendIndices = new uint[4]; uint tmpIndices = br.ReadUInt32(); BlendIndices[0] = (tmpIndices >> 16) & 0xFF; BlendIndices[1] = (tmpIndices >> 8) & 0xFF; BlendIndices[2] = (tmpIndices) & 0xFF; BlendIndices[3] = (tmpIndices >> 24) & 0xFF; break; default: br.BaseStream.Seek(element.Size, SeekOrigin.Current); break; } } }
internal Geometry(Resource.Models.Model info) { int index = 0; Meshes = new List<Mesh>(info.Geometries.Count); foreach (var dataInfo in info.Geometries) { var mesh = new Mesh(dataInfo); mesh.MaterialIndex = info.ShaderMappings[index++]; Meshes.Add(mesh); } }
private static void ExportVertex(TextWriter sw, Mesh m, Vertex v) { var boneIndex = m.VertexHasBlendInfo ? v.BlendIndices[0] : 0; var normal = m.VertexHasNormal ? v.Normal : new Vector3(); var uv = m.VertexHasTexture ? v.TextureCoordinates[0] : new Vector2(); var position = v.Position; sw.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} 1 0 1.000000", boneIndex, F(position.X), F(position.Y), F(position.Z), F(normal.X), F(normal.Y), F(normal.Z), F(uv.X), F(uv.Y)); }