public void OnEnable() { halfEdgeMesh = Oni.CreateHalfEdgeMesh(); if (scale == Vector3.zero) { scale = Vector3.one; } // Check integrity after serialization, (re?) initialize if there's data missing. if (heFaces == null || heVertices == null || heHalfEdges == null) { initialized = false; heFaces = new List <Oni.Face>(); heVertices = new List <Oni.Vertex>(); heHalfEdges = new List <Oni.HalfEdge>(); } else { initialized = true; facesHandle = Oni.PinMemory(heFaces.ToArray()); verticesHandle = Oni.PinMemory(heVertices.ToArray()); halfEdgesHandle = Oni.PinMemory(heHalfEdges.ToArray()); Oni.SetFaces(halfEdgeMesh, facesHandle.AddrOfPinnedObject(), heFaces.Count); Oni.SetVertices(halfEdgeMesh, verticesHandle.AddrOfPinnedObject(), heVertices.Count); Oni.SetHalfEdges(halfEdgeMesh, halfEdgesHandle.AddrOfPinnedObject(), heHalfEdges.Count); Oni.UnpinMemory(facesHandle); Oni.UnpinMemory(halfEdgesHandle); Oni.UnpinMemory(verticesHandle); } GenerateVisualVertexBuffer(); }
public void OnEnable() { //TODO: when instantiating a mesh, do we really need to duplicate it in the solver also? // we could just keep a reference to the same one... checking if it's zero. //if (halfEdgeMesh == IntPtr.Zero) halfEdgeMesh = Oni.CreateHalfEdgeMesh(); if (scale == Vector3.zero) { scale = Vector3.one; } // Set initial normals and tangents array: if (input != null) { normals = input.normals; tangents = input.tangents; } // Check integrity after serialization, (re?) initialize if there's data missing. if (heFaces == null || heVertices == null || heHalfEdges == null || heOrientations == null || visualMap == null) { initialized = false; heFaces = new Oni.Face[0]; heVertices = new Oni.Vertex[0]; heHalfEdges = new Oni.HalfEdge[0]; heOrientations = new Quaternion[0]; visualMap = new int[0]; } else { initialized = true; facesHandle = Oni.PinMemory(heFaces); verticesHandle = Oni.PinMemory(heVertices); halfEdgesHandle = Oni.PinMemory(heHalfEdges); orientationsHandle = Oni.PinMemory(heOrientations); normalsHandle = Oni.PinMemory(normals); tangentsHandle = Oni.PinMemory(tangents); 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()); Oni.SetNormals(halfEdgeMesh, normalsHandle.AddrOfPinnedObject()); Oni.SetTangents(halfEdgeMesh, tangentsHandle.AddrOfPinnedObject()); } }