#include "blindDataMeshVertexBufferGenerator.h"
#include <maya/MFnMesh.h>
#include <maya/MIntArray.h>
#include <maya/MItMeshVertex.h>
bool blindDataMeshVertexBufferGenerator::getSourceIndexing(
const MObject&
object, MComponentDataIndexing& sourceIndexing)
const
{
if (!status)
return false;
unsigned int vertCount = vertexList.
length();
for (unsigned int i = 0; i < vertCount; ++i)
vertices[i] = (unsigned int)vertexList[i];
sourceIndexing.setComponentType(MComponentDataIndexing::kFaceVertex);
return true;
}
bool blindDataMeshVertexBufferGenerator::getSourceStreams(
const MObject&
object,
MStringArray &sourceStreams)
const
{
return false;
}
void blindDataMeshVertexBufferGenerator::createVertexStream(
const MObject&
object, MVertexBuffer& vertexBuffer,
const MComponentDataIndexing& targetIndexing,
const MComponentDataIndexing& sharedIndexing,
const MVertexBufferArray& sourceStreams)
const
{
const MVertexBufferDescriptor& descriptor = vertexBuffer.descriptor();
if ( (descriptor.dataType() != MGeometry::kFloat) ||
(descriptor.dimension() != 4) ||
(descriptor.semantic() != MGeometry::kColor))
return;
if (!status)
return;
const MUintArray& indices = targetIndexing.indices();
const unsigned int vertexCount = indices.
length();
if (vertexCount <= 0)
return;
const unsigned vertexBufferSize = vertexCount * 4 * sizeof(float);
float* customBuffer = (float*)vertexBuffer.acquire(vertexBufferSize, true );
if (customBuffer)
{
const int blindDataID = 60;
for (; !itVertex.isDone(); itVertex.next())
{
double red, green, blue = 0;
int vertexIndex = itVertex.index();
customBuffer[vertexIndex * 4 ] = static_cast<float>(red);
customBuffer[vertexIndex * 4 + 1] = static_cast<float>(green);
customBuffer[vertexIndex * 4 + 2] = static_cast<float>(blue);
customBuffer[vertexIndex * 4 + 3] = 1.0f;
}
vertexBuffer.commit(customBuffer);
}
}