Пример #1
0
        private static Embree.TriangleMesh LoadFromFileIntoScene(String path, Embree.Scene scene, out IList <Embree.Vertex> vertexData, out IList <Embree.Triangle> triData)
        {
            vertexData = new List <Embree.Vertex>();
            triData    = new List <Embree.Triangle>();

            // load the geometry from the .obj file (basic OBJ loader)

            foreach (var line in File.ReadLines(path))
            {
                var tokens = line.Split();

                switch (tokens[0])
                {
                case "v":
                    vertexData.Add(new Embree.Vertex {
                        X = float.Parse(tokens[1], CultureInfo.InvariantCulture),
                        Y = float.Parse(tokens[2], CultureInfo.InvariantCulture),
                        Z = float.Parse(tokens[3], CultureInfo.InvariantCulture),
                    });
                    break;

                case "f":
                    triData.Add(new Embree.Triangle {
                        V0 = int.Parse(tokens[1].Split('/')[0]) - 1,
                        V1 = int.Parse(tokens[2].Split('/')[0]) - 1,
                        V2 = int.Parse(tokens[3].Split('/')[0]) - 1,
                    });
                    break;
                }
            }

            var mesh = scene.NewTriangleMesh(new Embree.TriangleMeshDescription()
            {
                NumVertices  = vertexData.Count,
                NumTriangles = triData.Count,
                Flags        = Embree.GeometryFlags.Static,
                LinearMotion = false,
            });

            mesh.SetVertices(vertexData.ToArray());
            mesh.SetTriangles(triData.ToArray());

            return(mesh);
        }
Пример #2
0
        public SimpleMesh(String filePath, Boolean smoothNormals)
        {
            scene = new Embree.Scene(Embree.SceneFlags.Coherent
                                     | Embree.SceneFlags.Incoherent
                                     | Embree.SceneFlags.Robust);

            IList <Embree.Vertex>   vertexData;
            IList <Embree.Triangle> triData;

            LoadFromFileIntoScene(filePath, scene, out vertexData, out triData);
            scene.Commit();

            // convert geometric vertex/triangle data into our own internal triangle format

            this.triangles = new Triangle[triData.Count];

            for (int t = 0; t < triData.Count; ++t)
            {
                triangles[t].V0.VertexID = triData[t].V0;
                triangles[t].V1.VertexID = triData[t].V1;
                triangles[t].V2.VertexID = triData[t].V2;
                triangles[t].FaceNormal  = Vector.Normalize(Vector.Cross(
                                                                (Point)vertexData[triData[t].V1] - (Point)vertexData[triData[t].V0],
                                                                (Point)vertexData[triData[t].V2] - (Point)vertexData[triData[t].V0]
                                                                ));
            }

            // if we want smooth vertex normals, generate them here
            // (note: we could load them from the .obj file if available, but never mind that for now)

            this.smoothNormals = smoothNormals;

            if (smoothNormals)
            {
                GenerateVertexNormals(vertexData);
            }
        }
Пример #3
0
 public Scene()
 {
     scene = new Embree.Scene(Embree.SceneFlags.Coherent
                              | Embree.SceneFlags.Incoherent
                              | Embree.SceneFlags.Robust);
 }