コード例 #1
0
        public RenderableModel Add(WavefrontModel model)
        {
            List <Vertex> vertices = new List <Vertex>();
            List <uint>   indices  = new List <uint>();

            foreach (var face in model.Faces)
            {
                indices.Add((uint)indices.Count);
                Vector3 color = new Vector3(model.Normals[face.a.n - 1]);
                color.X = Math.Abs(color.X);
                color.Y = Math.Abs(color.Y);
                color.Z = Math.Abs(color.Z);
                vertices.Add(new Vertex(model.Vertices[face.a.v - 1], color, model.Normals[face.a.n - 1]));
            }

            RenderableModel renderableModel = new RenderableModel(vertices.ToArray(), indices.ToArray(), ShaderLayout_Position, ShaderLayout_Color, ShaderLayout_Normal);

            this.Disposables.Add(renderableModel);
            return(renderableModel);
        }
コード例 #2
0
ファイル: WavefrontModelLoader.cs プロジェクト: fdafadf/main
        public WavefrontModel Load(string[] lines)
        {
            WavefrontModel result = new WavefrontModel();

            //List<Vector3> vertices = new List<Vector3>();
            //List<Vector3> normals = new List<Vector3>();

            foreach (string line in lines)
            {
                if (line.StartsWith("v "))
                {
                    result.Vertices.Add(LineToVector(line));
                }
                else if (line.StartsWith("vn "))
                {
                    result.Normals.Add(LineToVector(line));
                }
                else if (line.StartsWith("f "))
                {
                    Match match = FacePattern.Match(line);

                    if (match.Success)
                    {
                        int a1 = int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
                        int a2 = int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture);
                        int a3 = int.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture);
                        int b1 = int.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture);
                        int b2 = int.Parse(match.Groups[5].Value, CultureInfo.InvariantCulture);
                        int b3 = int.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture);
                        int c1 = int.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture);
                        int c2 = int.Parse(match.Groups[8].Value, CultureInfo.InvariantCulture);
                        int c3 = int.Parse(match.Groups[9].Value, CultureInfo.InvariantCulture);

                        var face = new WavefrontModel.Face();
                        face.a.v = a1;
                        face.a.t = a2;
                        face.a.n = a3;
                        result.Faces.Add(face);
                        face     = new WavefrontModel.Face();
                        face.a.v = b1;
                        face.a.t = b2;
                        face.a.n = b3;
                        result.Faces.Add(face);
                        face     = new WavefrontModel.Face();
                        face.a.v = c1;
                        face.a.t = c2;
                        face.a.n = c3;
                        result.Faces.Add(face);
                        //resultIndices.Add((uint)resultVertices.Count);
                        //resultVertices.Add(new Vertex(vertices[a1 - 1], normals[a3 - 1], normals[a3 - 1]));
                        //resultIndices.Add((uint)resultVertices.Count);
                        //resultVertices.Add(new Vertex(vertices[b1 - 1], normals[b3 - 1], normals[b3 - 1]));
                        //resultIndices.Add((uint)resultVertices.Count);
                        //resultVertices.Add(new Vertex(vertices[c1 - 1], normals[c3 - 1], normals[c3 - 1]));
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else if (line.StartsWith("vn "))
                {
                }
            }

            return(result);
        }