Пример #1
0
        int AddObj(IObj obj)
        {
            var indexes = new List <int>();

            foreach (var face in obj.Faces)
            {
                indexes.AddRange(face.VertexIndexes);
            }

            var geomId = RTC.NewTriangleMesh(scenePtr, MeshFlags.Static, obj.Faces.Count, obj.Vertices.Count, 1);

            RTC.CheckLastError();

            var indexBuffer = RTC.MapBuffer(scenePtr, geomId, RTC.BufferType.IndexBuffer);

            RTC.CheckLastError();
            Marshal.Copy(indexes.ToArray(), 0, indexBuffer, indexes.Count);
            RTC.UnmapBuffer(scenePtr, geomId, RTC.BufferType.IndexBuffer);

            var vertexBuffer = RTC.MapBuffer(scenePtr, geomId, RTC.BufferType.VertexBuffer);

            RTC.CheckLastError();

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

            RTC.UnmapBuffer(scenePtr, geomId, RTC.BufferType.VertexBuffer);

            //RTC.Commit( scenePtr );
            //RTC.EnableGeometry( scenePtr, geomId );
            RTC.CheckLastError();

            return((int)geomId);
        }