示例#1
0
        public uint Add(IntPtr scenePtr, MeshFlags flags)
        {
            var meshID = RTC.NewTriangleMesh(scenePtr, flags, triangleCount, vertexCount, 1);

            RTC.CheckLastError();
            return(meshID);
        }
示例#2
0
        /// <summary>
        /// Commits all meshes in this geometry.
        /// </summary>
        internal void Commit()
        {
            foreach (var entry in meshes)
            {
                entry.Value.Update(entry.Key, scenePtr);
                RTC.CheckLastError();

                if (sceneFlags.HasFlag(SceneFlags.Dynamic))
                {
                    RTC.UpdateGeometry(scenePtr, entry.Key);
                    RTC.CheckLastError();
                }
            }

            RTC.Commit(scenePtr);
            RTC.CheckLastError();
        }
示例#3
0
        /// <summary>
        /// Creates a new mesh from index and vertex buffers.
        /// </summary>
        public TriangleMesh(IList <Int32> indices, IList <IEmbreePoint> vertices)
        {
            this.indices       = indices;
            this.vertices      = vertices;
            this.vertexCount   = vertices.Count;
            this.triangleCount = indices.Count / 3;
            RTC.CheckLastError();

            if (vertexCount == 0)
            {
                throw new ArgumentOutOfRangeException("No vertices in mesh");
            }

            if (triangleCount == 0)
            {
                throw new ArgumentOutOfRangeException("No triangles in mesh");
            }
        }
示例#4
0
        /// <summary>
        /// Commits all current instances to the scene.
        /// </summary>
        public void Commit()
        {
            foreach (var entry in instances)
            {
                var instance = entry.Value;
                instance.Geometry.Commit();

                var xtf = new float[12] // Column-major order
                {
                    instance.Transform.U.X, instance.Transform.U.Y, instance.Transform.U.Z,
                    instance.Transform.V.X, instance.Transform.V.Y, instance.Transform.V.Z,
                    instance.Transform.W.X, instance.Transform.W.Y, instance.Transform.W.Z,
                    instance.Transform.T.X, instance.Transform.T.Y, instance.Transform.T.Z
                };

                var pinned = GCHandle.Alloc(xtf, GCHandleType.Pinned); // Pin transform matrix to raw float* array
                RTC.SetTransform(scenePtr, entry.Key, RTC.MatrixLayout.ColumnMajor, pinned.AddrOfPinnedObject());
                pinned.Free();                                         // Release before checking for error
                RTC.CheckLastError();

                if (instance.Enabled)
                {
                    RTC.EnableGeometry(scenePtr, entry.Key);
                }
                else
                {
                    RTC.DisableGeometry(scenePtr, entry.Key);
                }

                RTC.CheckLastError();

                if (sceneFlags.HasFlag(SceneFlags.Dynamic))
                {
                    RTC.UpdateGeometry(scenePtr, entry.Key);
                    RTC.CheckLastError(); // static mesh?
                }
            }

            RTC.Commit(scenePtr);
            RTC.CheckLastError();
        }
示例#5
0
        public void Update(uint geomID, IntPtr scenePtr)
        {
            if (indices.Count / 3 == triangleCount)
            {
                var indexBuffer = RTC.MapBuffer(scenePtr, geomID, RTC.BufferType.IndexBuffer);
                RTC.CheckLastError();

                Marshal.Copy(indices.ToArray(), 0, indexBuffer, indices.Count);

                RTC.UnmapBuffer(scenePtr, geomID, RTC.BufferType.IndexBuffer);
            }
            else
            {
                throw new InvalidOperationException("Index buffer length was changed.");
            }

            if (vertices.Count == vertexCount)
            {
                var vertexBuffer = RTC.MapBuffer(scenePtr, geomID, RTC.BufferType.VertexBuffer);
                RTC.CheckLastError();

                unsafe
                {
                    float *ptr = (float *)vertexBuffer;
                    foreach (var vertex in vertices)
                    {
                        *(ptr++) = vertex.X;
                        *(ptr++) = vertex.Y;
                        *(ptr++) = vertex.Z;
                        *(ptr++) = 1.0f;
                    }
                }

                RTC.UnmapBuffer(scenePtr, geomID, RTC.BufferType.VertexBuffer);
            }
            else
            {
                throw new InvalidOperationException("Vertex buffer length was changed.");
            }
        }
示例#6
0
 /// <summary>
 /// Checks the last embree error for this devices and throws exceptions as needed
 /// </summary>
 public void CheckLastError()
 {
     RTC.CheckLastError(this.devicePtr);
 }