コード例 #1
0
        public override void createVertexStream(MObject objPath,
            MVertexBuffer vertexBuffer,
            MComponentDataIndexing targetIndexing,
            MComponentDataIndexing sharedIndexing,
            MVertexBufferArray sourceStreams)
        {
            // get the descriptor from the vertex buffer.
            // It describes the format and layout of the stream.
            MVertexBufferDescriptor descriptor = vertexBuffer.descriptor;

            // we are expecting a float stream.
            if (descriptor.dataType != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.DataType.kFloat) return;

            // we are expecting a float2
            if (descriptor.dimension != 2) return;

            // we are expecting a texture channel
            if (descriptor.semantic != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.Semantic.kTexture) return;

            // get the mesh from the current path, if it is not a mesh we do nothing.
            MFnMesh mesh = null;
            try {
                mesh = new MFnMesh(objPath);
            } catch(System.Exception) {
                return; // failed
            }

            MUintArray indices = targetIndexing.indicesProperty;
            uint vertexCount = indices.length;
            if (vertexCount <= 0) return;

            unsafe {
                // acquire the buffer to fill with data.
                float * buffer = (float *)vertexBuffer.acquire(vertexCount);

                for (int i = 0; i < vertexCount; i++)
                {
                    // Here we are embedding some custom data into the stream.
                    // The included effects (vertexBufferGeneratorGL.cgfx and
                    // vertexBufferGeneratorDX11.fx) will alternate
                    // red, green, and blue vertex colored triangles based on this input.
                    *(buffer++) = 1.0f;
                    *(buffer++) = (float)indices[i]; // color index
                }

                // commit the buffer to signal completion.
                vertexBuffer.commit( (byte *)buffer);
            }
        }
コード例 #2
0
        public override bool getSourceIndexing(MObject obj, MComponentDataIndexing sourceIndexing)
        {
            // get the mesh from the current path, if it is not a mesh we do nothing.
            MFnMesh mesh = null;

            try {
                mesh = new MFnMesh(obj);
            } catch (System.Exception) {
                return(false);
            }

            // if it is an empty mesh we do nothing.
            int numPolys = mesh.numPolygons;

            if (numPolys <= 0)
            {
                return(false);
            }

            // for each face
            MUintArray vertToFaceVertIDs = sourceIndexing.indicesProperty;
            uint       faceNum           = 0;

            for (int i = 0; i < numPolys; i++)
            {
                // assign a color ID to all vertices in this face.
                uint faceColorID = faceNum % 3;

                int vertexCount = mesh.polygonVertexCount(i);
                for (int j = 0; j < vertexCount; j++)
                {
                    // set each face vertex to the face color
                    vertToFaceVertIDs.append(faceColorID);
                }

                faceNum++;
            }

            // assign the source indexing
            sourceIndexing.setComponentType(MComponentDataIndexing.MComponentType.kFaceVertex);

            return(true);
        }
コード例 #3
0
        public override bool getSourceIndexing(MObject obj, MComponentDataIndexing sourceIndexing)
		{
            // get the mesh from the current path, if it is not a mesh we do nothing.
			MFnMesh mesh = null;
			try {
				mesh = new MFnMesh(obj);
			} catch(System.Exception) {
				return false;
			}

			// if it is an empty mesh we do nothing.
			int numPolys = mesh.numPolygons;
			if (numPolys <= 0) return false;

			// for each face
            MUintArray vertToFaceVertIDs = sourceIndexing.indicesProperty;
			uint faceNum = 0;
			for (int i = 0; i < numPolys; i++)
			{
				// assign a color ID to all vertices in this face.
				uint faceColorID = faceNum % 3;

				int vertexCount = mesh.polygonVertexCount(i);
				for (int j = 0; j < vertexCount; j++)
				{
					// set each face vertex to the face color
					vertToFaceVertIDs.append(faceColorID);
				}

				faceNum++;
			}

			// assign the source indexing
			sourceIndexing.setComponentType(MComponentDataIndexing.MComponentType.kFaceVertex);

			return true;
		}
コード例 #4
0
        public override void createVertexStream(MObject objPath,
                                                MVertexBuffer vertexBuffer,
                                                MComponentDataIndexing targetIndexing,
                                                MComponentDataIndexing sharedIndexing,
                                                MVertexBufferArray sourceStreams)
        {
            // get the descriptor from the vertex buffer.
            // It describes the format and layout of the stream.
            MVertexBufferDescriptor descriptor = vertexBuffer.descriptor;

            // we are expecting a float stream.
            if (descriptor.dataType != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.DataType.kFloat)
            {
                return;
            }

            // we are expecting a float2
            if (descriptor.dimension != 2)
            {
                return;
            }

            // we are expecting a texture channel
            if (descriptor.semantic != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.Semantic.kTexture)
            {
                return;
            }

            // get the mesh from the current path, if it is not a mesh we do nothing.
            MFnMesh mesh = null;

            try {
                mesh = new MFnMesh(objPath);
            } catch (System.Exception) {
                return;                 // failed
            }

            MUintArray indices     = targetIndexing.indicesProperty;
            uint       vertexCount = indices.length;

            if (vertexCount <= 0)
            {
                return;
            }

            unsafe {
                // acquire the buffer to fill with data.
                float *buffer = (float *)vertexBuffer.acquire(vertexCount);

                for (int i = 0; i < vertexCount; i++)
                {
                    // Here we are embedding some custom data into the stream.
                    // The included effects (vertexBufferGeneratorGL.cgfx and
                    // vertexBufferGeneratorDX11.fx) will alternate
                    // red, green, and blue vertex colored triangles based on this input.
                    *(buffer++) = 1.0f;
                    *(buffer++) = (float)indices[i];                 // color index
                }

                // commit the buffer to signal completion.
                vertexBuffer.commit((byte *)buffer);
            }
        }