Exemplo n.º 1
0
        public void Commit()
        {
            foreach (var kv in instances)
            {
                var surface  = kv.Key;
                var instance = kv.Value;

                instance.SetTransform(surface.Location.Transform.ToArray(),
                                      Embree.MatrixLayout.ColumnMajor);
                instance.Enabled = surface.Location.Visible;
            }

            scene.Commit();
        }
Exemplo n.º 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);
            }
        }