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);
            }
        }
Ejemplo n.º 2
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);
            }
        }