Exemple #1
0
        public void Generate()
        {
            initialized = false;

            Oni.UnpinMemory(facesHandle);
            Oni.UnpinMemory(verticesHandle);
            Oni.UnpinMemory(halfEdgesHandle);
            Oni.UnpinMemory(orientationsHandle);
            Oni.UnpinMemory(visualMapHandle);

            // Calculate amount of memory that we need to allocate upfront:
            Oni.CalculatePrimitiveCounts(halfEdgeMesh, input.vertices,
                                         input.triangles,
                                         input.vertices.Length,
                                         input.triangles.Length);

            vertexCount = Oni.GetVertexCount(halfEdgeMesh);

            // Allocate memory for half edge data:
            Array.Resize(ref heVertices, vertexCount);
            Array.Resize(ref heFaces, Oni.GetFaceCount(halfEdgeMesh));
            Array.Resize(ref heHalfEdges, Oni.GetHalfEdgeCount(halfEdgeMesh));
            Array.Resize(ref heOrientations, vertexCount);
            Array.Resize(ref visualMap, input.vertexCount);

            // Pin memory and hand it to Oni:
            facesHandle        = Oni.PinMemory(heFaces);
            verticesHandle     = Oni.PinMemory(heVertices);
            halfEdgesHandle    = Oni.PinMemory(heHalfEdges);
            orientationsHandle = Oni.PinMemory(heOrientations);
            visualMapHandle    = Oni.PinMemory(visualMap);

            Oni.SetFaces(halfEdgeMesh, facesHandle.AddrOfPinnedObject(), heFaces.Length);
            Oni.SetVertices(halfEdgeMesh, verticesHandle.AddrOfPinnedObject(), heVertices.Length);
            Oni.SetHalfEdges(halfEdgeMesh, halfEdgesHandle.AddrOfPinnedObject(), heHalfEdges.Length);
            Oni.SetInverseOrientations(halfEdgeMesh, orientationsHandle.AddrOfPinnedObject());
            Oni.SetVisualMap(halfEdgeMesh, visualMapHandle.AddrOfPinnedObject());

            // Generate half edge structure:
            Oni.Generate(halfEdgeMesh, input.vertices,
                         input.triangles,
                         input.vertices.Length,
                         input.triangles.Length,
                         ref scale);

            Oni.GetHalfEdgeMeshInfo(halfEdgeMesh, ref meshInfo);

            initialized = true;
        }