Esempio n. 1
0
        protected MObject createMesh(MTime time, ref MObject outData)
        {
            int              numVertices, frame;
            float            cubeSize;
            MFloatPointArray points = new MFloatPointArray();
            MFnMesh          meshFS = new MFnMesh();

            // Scale the cube on the frame number, wrap every 10 frames.
            frame = (int)time.asUnits(MTime.Unit.kFilm);
            if (frame == 0)
            {
                frame = 1;
            }
            cubeSize = 0.5f * (float)(frame % 10);

            const int numFaces = 6;

            numVertices = 8;

            MFloatPoint vtx_1 = new MFloatPoint(-cubeSize, -cubeSize, -cubeSize);
            MFloatPoint vtx_2 = new MFloatPoint(cubeSize, -cubeSize, -cubeSize);
            MFloatPoint vtx_3 = new MFloatPoint(cubeSize, -cubeSize, cubeSize);
            MFloatPoint vtx_4 = new MFloatPoint(-cubeSize, -cubeSize, cubeSize);
            MFloatPoint vtx_5 = new MFloatPoint(-cubeSize, cubeSize, -cubeSize);
            MFloatPoint vtx_6 = new MFloatPoint(-cubeSize, cubeSize, cubeSize);
            MFloatPoint vtx_7 = new MFloatPoint(cubeSize, cubeSize, cubeSize);
            MFloatPoint vtx_8 = new MFloatPoint(cubeSize, cubeSize, -cubeSize);

            points.append(vtx_1);
            points.append(vtx_2);
            points.append(vtx_3);
            points.append(vtx_4);
            points.append(vtx_5);
            points.append(vtx_6);
            points.append(vtx_7);
            points.append(vtx_8);


            // Set up an array containing the number of vertices
            // for each of the 6 cube faces (4 verticies per face)
            //
            int[]     face_counts = { 4, 4, 4, 4, 4, 4 };
            MIntArray faceCounts  = new MIntArray(face_counts);

            // Set up and array to assign vertices from points to each face
            //
            int[]     face_connects = { 0, 1, 2, 3,
                                        4,     5, 6, 7,
                                        3,     2, 6, 5,
                                        0,     3, 5, 4,
                                        0,     4, 7, 1,
                                        1,     7, 6, 2 };
            MIntArray faceConnects = new MIntArray(face_connects);

            MObject newMesh = meshFS.create(numVertices, numFaces, points, faceCounts, faceConnects, outData);

            return(newMesh);
        }
Esempio n. 2
0
        protected MObject createMesh(MTime time, ref MObject outData)
        {
            int numVertices, frame;
            float cubeSize;
            MFloatPointArray points = new MFloatPointArray();
            MFnMesh meshFS = new MFnMesh();

            // Scale the cube on the frame number, wrap every 10 frames.
            frame = (int)time.asUnits(MTime.Unit.kFilm);
            if (frame == 0)
                frame = 1;
            cubeSize = 0.5f * (float)(frame % 10);

            const int numFaces = 6;
            numVertices = 8;

            MFloatPoint vtx_1 = new MFloatPoint(-cubeSize, -cubeSize, -cubeSize);
            MFloatPoint vtx_2 = new MFloatPoint(cubeSize, -cubeSize, -cubeSize);
            MFloatPoint vtx_3 = new MFloatPoint(cubeSize, -cubeSize, cubeSize);
            MFloatPoint vtx_4 = new MFloatPoint(-cubeSize, -cubeSize, cubeSize);
            MFloatPoint vtx_5 = new MFloatPoint(-cubeSize, cubeSize, -cubeSize);
            MFloatPoint vtx_6 = new MFloatPoint(-cubeSize, cubeSize, cubeSize);
            MFloatPoint vtx_7 = new MFloatPoint(cubeSize, cubeSize, cubeSize);
            MFloatPoint vtx_8 = new MFloatPoint(cubeSize, cubeSize, -cubeSize);
            points.append(vtx_1);
            points.append(vtx_2);
            points.append(vtx_3);
            points.append(vtx_4);
            points.append(vtx_5);
            points.append(vtx_6);
            points.append(vtx_7);
            points.append(vtx_8);


            // Set up an array containing the number of vertices
            // for each of the 6 cube faces (4 verticies per face)
            //
            int[] face_counts = { 4, 4, 4, 4, 4, 4 };
            MIntArray faceCounts = new MIntArray(face_counts);

            // Set up and array to assign vertices from points to each face 
            //
            int[] face_connects = {	0, 1, 2, 3,
									4, 5, 6, 7,
									3, 2, 6, 5,
									0, 3, 5, 4,
									0, 4, 7, 1,
									1, 7, 6, 2	};
            MIntArray faceConnects = new MIntArray(face_connects);

            MObject newMesh = meshFS.create(numVertices, numFaces, points, faceCounts, faceConnects, outData);

            return newMesh;
        }
Esempio n. 3
0
        public MObject ConvertMeshMaya(TriMesh triMesh)
        {
            MFnMesh meshMaya = new MFnMesh();

            int verticeNum          = triMesh.Vertices.Count;
            MFloatPointArray points = new MFloatPointArray();

            for (int i = 0; i < verticeNum; i++)
            {
                float x = (float)triMesh.Vertices[i].Traits.Position.x;
                float y = (float)triMesh.Vertices[i].Traits.Position.y;
                float z = (float)triMesh.Vertices[i].Traits.Position.z;

                MFloatPoint vertex = new MFloatPoint(x, y, z);
                points.append(vertex);
            }


            int faceNum = triMesh.Faces.Count;

            int[] face_Counts = new int[faceNum];
            for (int i = 0; i < faceNum; i++)
            {
                face_Counts[i] = 3;
            }
            MIntArray faceCounts = new MIntArray(face_Counts);


            int[] faceTopology = new int[faceNum * 3];

            for (int j = 0; j < faceNum; j++)
            {
                int index = j * 3;
                faceTopology[index] = triMesh.Faces[j].GetVertex(0).Index;

                faceTopology[index + 1] = triMesh.Faces[j].GetVertex(1).Index;

                faceTopology[index + 2] = triMesh.Faces[j].GetVertex(2).Index;
            }

            MIntArray faceConnects = new MIntArray(faceTopology);

            MObject mesh = meshMaya.create(verticeNum, faceNum, points, faceCounts, faceConnects);

            return(mesh);
        }
Esempio n. 4
0
        private void generatePrimitiveData()
        {
            // Decide which type of primitive to create
            //
            iarr.clear();
            faceCounts.clear();
            faceConnects.clear();

            switch (shapeFlag)
            {
            case 1:
            default:
                create_icosa_points();
                num_verts      = 12;
                num_faces      = 20;
                edges_per_face = 3;
                p_gons         = icosa_gons;
                break;

            case 2:
                create_dodecahedron();
                num_verts      = 20;
                num_faces      = 12;
                edges_per_face = 5;
                p_gons         = dodeca_gons;
                break;

            case 3:
                create_tetrahedron();
                num_verts      = 4;
                num_faces      = 4;
                edges_per_face = 3;
                p_gons         = tetra_gons;
                break;

            case 4:
                create_cube();
                num_verts      = 8;
                num_faces      = 6;
                edges_per_face = 4;
                p_gons         = cube_gons;
                break;

            case 5:
                create_octahedron();
                num_verts      = 6;
                num_faces      = 8;
                edges_per_face = 3;
                p_gons         = octa_gons;
                break;

            case 6:
                createPlane();
                p_gons = null;
                break;

            case 7:
                createCylinder();
                p_gons = null;
                break;

            case 8:
                create_truncated_icosahedron();
                p_gons = null;
                break;
            }

            // Construct the point array
            //
            pa.clear();
            int i;

            for (i = 0; i < num_verts; i++)
            {
                pa.append(iarr[i]);
            }

            // If we are using polygon data then set up the face connect array
            // here. Otherwise, the create function will do it.
            //
            if (null != p_gons)
            {
                num_face_connects = num_faces * edges_per_face;
                num_edges         = num_face_connects / 2;

                for (i = 0; i < num_faces; i++)
                {
                    faceCounts.append(edges_per_face);
                }

                for (i = 0; i < (num_faces * edges_per_face); i++)
                {
                    faceConnects.append(p_gons[i] - 1);
                }
            }
        }
Esempio n. 5
0
        private void FILL(double x, double y, double z)
        {
            MFloatPoint pnt = new MFloatPoint((float)x, (float)y, (float)z);

            iarr.append(pnt);
        }
Esempio n. 6
0
       public MObject ConvertMeshMaya(TriMesh triMesh)
       {
          MFnMesh meshMaya = new MFnMesh();

          int verticeNum = triMesh.Vertices.Count;
          MFloatPointArray points = new MFloatPointArray();
         
          for(int i=0;i<verticeNum;i++)
          {
              float x=(float)triMesh.Vertices[i].Traits.Position.x;
              float y=(float)triMesh.Vertices[i].Traits.Position.y;
              float z=(float)triMesh.Vertices[i].Traits.Position.z;

              MFloatPoint vertex = new MFloatPoint(x,y,z);
              points.append(vertex);
          }

           
           int faceNum = triMesh.Faces.Count;

           int[] face_Counts=new int[faceNum];
           for(int i=0;i<faceNum;i++)
           {
              face_Counts[i]=3;
           }
           MIntArray faceCounts = new MIntArray(face_Counts);


           int[] faceTopology=new int[faceNum*3];
            
           for(int j=0;j<faceNum ;j++)
           {
              int index=j*3;
              faceTopology[index]=triMesh.Faces[j].GetVertex(0).Index ;
               
              faceTopology[index+1]=triMesh.Faces[j].GetVertex(1).Index ;
               
              faceTopology[index+2]=triMesh.Faces[j].GetVertex(2).Index ;
               
           }

           MIntArray faceConnects = new MIntArray(faceTopology);

           MObject mesh= meshMaya.create(verticeNum, faceNum, points, faceCounts, faceConnects);

           return mesh;
       }