コード例 #1
0
    public static Mesh PlanktonToUnity(this PlanktonMesh plankton)
    {
        int vCount   = plankton.Vertices.Count;
        var vertices = new Vector3[vCount];

        for (int i = 0; i < vCount; i++)
        {
            PlanktonVertex v = plankton.Vertices[i];
            vertices[i] = new Vector3(v.X, v.Y, v.Z);
        }

        int fCount    = plankton.Faces.Count;
        var triangles = new int[fCount * 3];

        int[] faceVertices = new int[3];
        for (int i = 0; i < fCount; i++)
        {
            if (!plankton.Faces[i].IsUnused)
            {
                plankton.Faces.GetFaceVerticesNonAlloc(i, faceVertices);
                triangles[i * 3]     = faceVertices[0];
                triangles[i * 3 + 1] = faceVertices[1];
                triangles[i * 3 + 2] = faceVertices[2];
            }
        }

        var mesh = new Mesh();

        mesh.vertices  = vertices;
        mesh.uv        = plankton.Vertices.Select(v => v.data.UV).ToArray();
        mesh.normals   = plankton.Vertices.Select(v => v.data.Normal).ToArray();
        mesh.triangles = triangles;
        mesh.RecalculateTangents();
        return(mesh);
    }
コード例 #2
0
 private void UpdateVertexPositionsAndVelicities()
 {
     for (int i = 0; i < ptMesh.Vertices.Count; i++)
     {
         if (totalWeights[i] == 0)
         {
             continue;
         }
         PlanktonVertex vertex = ptMesh.Vertices[i];
         Vector3d       move   = totalWeightedMoves[i] / totalWeights[i];
         ptMesh.Vertices.SetVertex(i, vertex.X + move.X, vertex.Y + move.Y, vertex.Z + move.Z);
     }
 }
コード例 #3
0
        //EDGE VECTOR
        /* return the edge vector from a halfedge index pointing from halfedge start towards halfedge end */
        public Vector3d edgeVector(PlanktonMesh pMesh, int halfedgeIndex)
        {
            PlanktonHalfedge pHalfedge = pMesh.Halfedges[halfedgeIndex];

            //start vertex
            PlanktonVertex pVStart = pMesh.Vertices[pHalfedge.StartVertex];
            Point3d startVertex = new Point3d(pVStart.X, pVStart.Y, pVStart.Z);

            //end vertex
            PlanktonVertex pVEnd = pMesh.Vertices[pMesh.Halfedges[pHalfedge.NextHalfedge].StartVertex];
            Point3d endVertex = new Point3d(pVEnd.X, pVEnd.Y, pVEnd.Z);

            //edge vector
            Vector3d vecEdge = new Vector3d(endVertex - startVertex);

            return vecEdge;
        }
コード例 #4
0
        public List <Point3d> facesPosTag(PlanktonMesh pMesh)
        {
            List <Point3d> facesPos = new List <Point3d>();

            //PlanktonFace pF in pMesh.Faces
            for (int i = 0; i < pMesh.Faces.Count; i++)
            {
                Vector3d vecFaceCenter = new Vector3d(0, 0, 0);
                int[]    faceVertices  = pMesh.Faces.GetFaceVertices(i);
                foreach (int fVertex in faceVertices)
                {
                    PlanktonVertex pV        = pMesh.Vertices[fVertex];
                    Vector3d       vecVertex = new Vector3d(pV.X, pV.Y, pV.Z);
                    vecFaceCenter = Vector3d.Add(vecFaceCenter, vecVertex);
                }
                Vector3d vecPos = Vector3d.Divide(vecFaceCenter, faceVertices.Length);
                facesPos.Add(new Point3d(vecPos.X, vecPos.Y, vecPos.Z));
            }
            return(facesPos);
        }
コード例 #5
0
 /// <summary>
 /// Creates a Rhino Point3f from a Plankton vertex.
 /// </summary>
 /// <param name="vertex">A Plankton vertex</param>
 /// <returns>A Point3f with the same coordinates as the vertex.</returns>
 public static Point3f ToPoint3f(this PlanktonVertex vertex)
 {
     return(new Point3f(vertex.X, vertex.Y, vertex.Z));
 }
コード例 #6
0
 public static Vector3 ToUnity(this PlanktonVertex v)
 {
     return(new Vector3(v.X, v.Y, v.Z));
 }
コード例 #7
0
 public static Point3d ToPoint3d(this PlanktonVertex pV)
 {
     return(new Point3d(pV.ToPoint3f()));
 }