#include "TessellatedQuadGeomOverride.h"
#include "CrackFreePrimitiveGenerator.h"
#include <maya/MViewport2Renderer.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MFragmentManager.h>
#include <maya/MShaderManager.h>
#include <maya/MTextureManager.h>
#include <maya/MUintArray.h>
#include <maya/MSelectionMask.h>
#include <maya/MGlobal.h>
#include <string.h>
namespace
{
const MString kWireframeItemName(
"tessellatedQuadWireframe");
const MString kTessellatedItemName(
"tessellatedQuadTessellated");
const MString kTessellatedSelectorItemName(
"tessellatedQuadTessellatedSelector");
const MString kTessellatedWireframeItemName(
"tessellatedQuadTessellatedWireframe");
const MString kTessellatedWireframeSelectorItemName(
"tessellatedQuadTessellatedWireframeSelector");
const unsigned int kNumPoints = 4;
const unsigned int kNumTris = 2;
const float kPlanePnts[kNumPoints][3] = {
{-1.0, 0.0, -1.0},
{1.0, 0.0, -1.0},
{1.0, 0.0, 1.0},
{-1.0, 0.0, 1.0}
};
const unsigned int kPlaneTriVertIndexes[kNumTris][3] = {
{0, 1, 2},
{2, 3, 0}
};
const float kPlaneUVs[kNumPoints][2] = {
{0.0, 1.0},
{1.0, 1.0},
{1.0, 0.0},
{0.0, 0.0}
};
const unsigned int kPlaneWireVertIndexes[kNumPoints][2] = {
{0, 1},
{1, 2},
{2, 3},
{3, 0}
};
}
void TessellatedQuadGeomOverride::updateRenderItems(
{
if (!renderer) return;
if (!shaderMgr || !textureMgr) return;
int idx = list.
indexOf(kWireframeItemName);
if (idx >= 0)
{
wireframeItem = list.
itemAt(idx);
}
else
{
1);
}
if (wireframeItem)
{
MHWRender::MShaderManager::MStockShader::k3dThickLineShader);
if (shader)
{
const float color[4] = { wireColor.
r, wireColor.
g, wireColor.
b, 1.0f };
}
}
const unsigned int triStride = CrackFreePrimitiveGenerator::computeTriangleSize(
true , true , true );
{
devkitLocation =
MString(getenv(
"MAYA_LOCATION")) +
MString(
"/devkit");
}
MString shaderLocation = devkitLocation +
"/plug-ins/tessellatedQuad/TessellationExample.fx" :
"/plug-ins/tessellatedQuad/TessellationExample.ogsfx");
MString textureLocation = devkitLocation +
MString(
"/plug-ins/tessellatedQuad/moonHeightMapSharp.jpg");
if (list.
indexOf(kTessellatedItemName) < 0)
{
triStride);
if (tessellationShader)
{
MTextureAssignment assignment;
assignment.texture = texture;
}
else
{
std::cerr << "Error when loading: " << er << std::endl;
std::cerr << erSrc << std::endl;
}
}
if (list.
indexOf(kTessellatedSelectorItemName) < 0)
{
triStride);
if (selectionShader)
{
MTextureAssignment assignment;
assignment.texture = texture;
}
else
{
std::cerr << "Error when loading: " << er << std::endl;
std::cerr << erSrc << std::endl;
}
}
if (list.
indexOf(kTessellatedWireframeItemName) < 0)
{
kTessellatedWireframeItemName,
triStride);
if (tessellationShader)
{
MTextureAssignment assignment;
assignment.texture = texture;
}
else
{
std::cerr << "Error when loading: " << er << std::endl;
std::cerr << erSrc << std::endl;
}
}
if (list.
indexOf(kTessellatedWireframeSelectorItemName) < 0)
{
triStride);
if (selectionShader)
{
MTextureAssignment assignment;
assignment.texture = texture;
}
else
{
std::cerr << "Error when loading: " << er << std::endl;
std::cerr << erSrc << std::endl;
}
}
}
void TessellatedQuadGeomOverride::populateGeometry(
{
for (
int ri = 0; ri < vbDescriptors.
length(); ++ri )
{
continue;
{
{
if (positionBuffer)
{
float *verts = (
float *) positionBuffer->
acquire(kNumPoints,
false);
memcpy(verts, kPlanePnts, sizeof(float) * kNumPoints * 3);
positionBuffer->
commit(verts);
}
}
break;
{
if (vb)
{
float *normals= (
float *) vb->
acquire(kNumPoints,
true);
for ( unsigned int ni=0; ni<kNumPoints; ++ni )
{
normals[ni*3 + 0] = 0.0f;
normals[ni*3 + 1] = 1.0f;
normals[ni*3 + 2] = 0.0f;
}
}
}
break;
{
if (uvBuffer)
{
float *uvs = (
float *) uvBuffer->
acquire(kNumPoints,
false);
memcpy(uvs, kPlaneUVs, sizeof(float) * kNumPoints * 2);
}
}
break;
default:
std::cerr <<
"Unexpected vb descriptor: " << vbDescriptor.
semanticName() << std::endl;
break;
};
}
const unsigned int triStride = CrackFreePrimitiveGenerator::computeTriangleSize(
true , true , true );
for (
int ri = 0; ri < renderItems.
length(); ++ri )
{
if ( !item )
continue;
if ( itemName == kWireframeItemName )
{
if (ib)
{
unsigned int* indexes = (
unsigned int *) ib->
acquire(kNumPoints * 2);
memcpy(indexes, kPlaneWireVertIndexes, sizeof(unsigned int) * kNumPoints * 2);
}
}
else if (
itemName == kTessellatedItemName ||
itemName == kTessellatedSelectorItemName ||
itemName == kTessellatedWireframeItemName ||
itemName == kTessellatedWireframeSelectorItemName )
{
if (!patchIB)
{
if (patchIB)
{
MUintArray triIndices(kPlaneTriVertIndexes[0], kNumTris * 3);
float * positionBufferFloat = (
float *)positionBuffer->
map();
float * uvBufferFloat = NULL;
if (uvBuffer) uvBufferFloat = (
float *)uvBuffer->
map();
const unsigned int bufferSize = kNumTris * triStride;
unsigned int* indexes = (
unsigned int*)patchIB->
acquire(bufferSize,
true );
CrackFreePrimitiveGenerator::mutateIndexBuffer(triIndices,
positionBufferFloat,
uvBufferFloat,
true ,
true ,
true ,
indexes);
if (positionBuffer) positionBuffer->
unmap();
if (uvBuffer) uvBuffer->
unmap();
}
}
if (patchIB)
{
}
}
}
}