#include <maya/MFnPlugin.h>
#include <maya/MDrawRegistry.h>
#include "geometryOverrideExample2.h"
#include <maya/MShaderManager.h>
#include <maya/MSelectionMask.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFloatVector.h>
#include <maya/MGlobal.h>
static void instancingChangedCallback(
MDagPath& child,
MDagPath& parent,
void* clientData)
{
}
GeometryOverrideExample2_shape::GeometryOverrideExample2_shape()
{
const float cubeWidth = 1.0f;
const float cubeHeight= 1.0f;
const float cubeDepth = 1.0f;
fPositions.emplace_back(-cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back(-cubeWidth, -cubeHeight, cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back(-cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, -cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, -cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back(-cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back(-cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, -cubeDepth);
fPositions.emplace_back( cubeWidth, cubeHeight, cubeDepth);
fPositions.emplace_back( cubeWidth, -cubeHeight, cubeDepth);
fNormals.emplace_back( 0.0f, 0.0f, -1.0f);
fNormals.emplace_back( 0.0f, 0.0f, -1.0f);
fNormals.emplace_back( 0.0f, 0.0f, -1.0f);
fNormals.emplace_back( 0.0f, 0.0f, -1.0f);
fNormals.emplace_back( 0.0f, 0.0f, 1.0f);
fNormals.emplace_back( 0.0f, 0.0f, 1.0f);
fNormals.emplace_back( 0.0f, 0.0f, 1.0f);
fNormals.emplace_back( 0.0f, 0.0f, 1.0f);
fNormals.emplace_back( 0.0f, 1.0f, 0.0f);
fNormals.emplace_back( 0.0f, 1.0f, 0.0f);
fNormals.emplace_back( 0.0f, 1.0f, 0.0f);
fNormals.emplace_back( 0.0f, 1.0f, 0.0f);
fNormals.emplace_back( 0.0f, -1.0f, 0.0f);
fNormals.emplace_back( 0.0f, -1.0f, 0.0f);
fNormals.emplace_back( 0.0f, -1.0f, 0.0f);
fNormals.emplace_back( 0.0f, -1.0f, 0.0f);
fNormals.emplace_back(-1.0f, 0.0f, 0.0f);
fNormals.emplace_back(-1.0f, 0.0f, 0.0f);
fNormals.emplace_back(-1.0f, 0.0f, 0.0f);
fNormals.emplace_back(-1.0f, 0.0f, 0.0f);
fNormals.emplace_back( 1.0f, 0.0f, 0.0f);
fNormals.emplace_back( 1.0f, 0.0f, 0.0f);
fNormals.emplace_back( 1.0f, 0.0f, 0.0f);
fNormals.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back(-1.0f, 0.0f, 0.0f);
fTangents.emplace_back( 0.0f, 0.0f, -1.0f);
fTangents.emplace_back( 0.0f, 0.0f, -1.0f);
fTangents.emplace_back( 0.0f, 0.0f, -1.0f);
fTangents.emplace_back( 0.0f, 0.0f, -1.0f);
fTangents.emplace_back( 0.0f, 0.0f, 1.0f);
fTangents.emplace_back( 0.0f, 0.0f, 1.0f);
fTangents.emplace_back( 0.0f, 0.0f, 1.0f);
fTangents.emplace_back( 0.0f, 0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 1.0f);
fTextureCoords.emplace_back(0.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 0.0f);
fTextureCoords.emplace_back(1.0f, 1.0f);
fBiTangents.resize(24);
for (int i = 0; i < 24; i++)
{
MFloatVector(fTangents[i].x, fTangents[i].y, fTangents[i].z);
fBiTangents[i].x = biTangents.
x;
fBiTangents[i].y = biTangents.
y;
fBiTangents[i].z = biTangents.
z;
}
fShadedIndices =
{
12, 13, 14, 12, 14, 15,
8, 9, 10, 8, 10, 11,
16, 17, 18, 16, 18, 19,
20, 21, 22, 20, 22, 23,
4, 5, 6, 4, 6, 7,
0, 1, 2, 0, 2, 3,
};
fWireFrameIndices =
{
0, 1, 1, 2, 2, 3, 3, 0,
4, 5, 5, 6, 6, 7, 7, 4,
0, 4, 3, 5, 1, 7, 2, 6,
};
}
GeometryOverrideExample2_shape::~GeometryOverrideExample2_shape()
{
}
void GeometryOverrideExample2_shape::postConstructor()
{
setRenderable(true);
}
MSelectionMask GeometryOverrideExample2_shape::getShapeSelectionMask()
const
{
}
MBoundingBox GeometryOverrideExample2_shape::boundingBox()
const
{
MPoint corner1Point(fPositions[0].x, fPositions[0].y, fPositions[0].z);
MPoint corner2Point(fPositions[6].x, fPositions[6].y, fPositions[6].z);
}
const char* GeometryOverrideExample2::sActiveWireframeRenderItemName = "GeometryOverrideExample2_ActiveWireframe";
const char* GeometryOverrideExample2::sDormantWireframeRenderItemName = "GeometryOverrideExample2_DormantWireframe";
const char* GeometryOverrideExample2::sShadedRenderItemName = "GeometryOverrideExample2_shaded";
GeometryOverrideExample2::GeometryOverrideExample2(
const MObject& obj)
{
if (status)
{
fMesh = dynamic_cast<GeometryOverrideExample2_shape*>(node.userNode());
}
}
GeometryOverrideExample2::~GeometryOverrideExample2()
{
}
{
}
void GeometryOverrideExample2::updateDG()
{
}
bool GeometryOverrideExample2::requiresGeometryUpdate() const
{
return false;
}
bool GeometryOverrideExample2::supportsEvaluationManagerParallelUpdate() const
{
return true;
}
{
return;
MRenderer* renderer = MRenderer::theRenderer();
if (!renderer)
return;
const MShaderManager* shaderManager = renderer->getShaderManager();
if (!shaderManager)
return;
updateWireframeItems(sActiveWireframeRenderItemName,
wireframeColor,
isWireFrameRenderItemEnabled,
renderItems,
*shaderManager);
updateWireframeItems(sDormantWireframeRenderItemName,
wireframeColor,
isWireFrameRenderItemEnabled,
renderItems,
*shaderManager);
}
{
if (!fMesh)
return;
const MVertexBufferDescriptorList& vertexBufferDescriptorList = requirements.
vertexRequirements();
for (int i = 0; i < vertexBufferDescriptorList.length(); i++)
{
MVertexBufferDescriptor desc{};
if (!vertexBufferDescriptorList.getDescriptor(i, desc))
continue;
std::cout << desc.semanticName().asChar() << std::endl;
switch (desc.semantic())
{
case MGeometry::kPosition:
{
if (positionBuffer)
{
GeometryOverrideExample2_shape::Float3Array positions = fMesh->getPositions();
void* buffer = positionBuffer->
acquire(positions.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::Float3Array::value_type) * positions.size();
memcpy(buffer, positions.data(), bufferSizeInByte);
positionBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kNormal:
{
if (normalsBuffer)
{
GeometryOverrideExample2_shape::Float3Array normals = fMesh->getNormals();
void* buffer = normalsBuffer->
acquire(normals.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::Float3Array::value_type) * normals.size();
memcpy(buffer, normals.data(), bufferSizeInByte);
normalsBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kTangent:
{
if (tangentBuffer)
{
GeometryOverrideExample2_shape::Float3Array tangents = fMesh->getTangents();
void* buffer = tangentBuffer->
acquire(tangents.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::Float3Array::value_type) * tangents.size();
memcpy(buffer, tangents.data(), bufferSizeInByte);
tangentBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kBitangent:
{
if (tangentBuffer)
{
GeometryOverrideExample2_shape::Float3Array tangents = fMesh->getBiTangents();
void* buffer = tangentBuffer->
acquire(tangents.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::Float3Array::value_type) * tangents.size();
memcpy(buffer, tangents.data(), bufferSizeInByte);
tangentBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kTexture:
{
if (texCoordsBuffer)
{
GeometryOverrideExample2_shape::Float2Array texCoords = fMesh->getTexCoords();
void* buffer = texCoordsBuffer->
acquire(texCoords.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::Float2Array::value_type) * texCoords.size();
memcpy(buffer, texCoords.data(), bufferSizeInByte);
texCoordsBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kColor:
case MGeometry::kTangentWithSign:
case MGeometry::kInvalidSemantic:
break;
}
}
const int numItems = renderItems.
length();
for (int i = 0; i < numItems; i++)
{
if (!item)
continue;
{
if (indexBuffer)
{
GeometryOverrideExample2_shape::IndexList indices = fMesh->getShadedIndices();
void* buffer = indexBuffer->
acquire(indices.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::IndexList::value_type) * indices.size();
memcpy(buffer, indices.data(), bufferSizeInByte);
}
}
}
{
if (indexBuffer)
{
GeometryOverrideExample2_shape::IndexList indices = fMesh->getWireFrameIndices();
void* buffer = indexBuffer->
acquire(indices.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample2_shape::IndexList::value_type) * indices.size();
memcpy(buffer, indices.data(), bufferSizeInByte);
}
}
}
}
}
void GeometryOverrideExample2::cleanUp()
{
}
void GeometryOverrideExample2::updateWireframeItems(const char* renderItemName, MGeometry::DrawMode drawMode,
unsigned int depthPriority,
MColor color,
bool isEnable,
{
auto renderItemIndex = renderItemList.
indexOf(renderItemName);
if (renderItemIndex < 0)
{
MShaderInstance* shader = shaderManager.
getStockShader(MShaderManager::k3dSolidShader);
if (shader)
{
}
renderItemList.
append(renderItem);
}
else
{
renderItem = renderItemList.
itemAt(renderItemIndex);
}
if (renderItem)
{
if (shader)
{
}
}
}
namespace
{
MString sDrawDbClassification(
"drawdb/geometry/geometryOverrideExample2");
MString sDrawRegistrantId(
"geometryOverrideExample2Plugin");
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerShape("geometryOverrideExample2_shape",
GeometryOverrideExample2_shape::id,
&GeometryOverrideExample2_shape::creator,
&GeometryOverrideExample2_shape::initialize,
nullptr,
&sDrawDbClassification);
if (!status)
{
cerr << "Failed to register geometryOverrideExample2_shape." << std::endl;
return status;
}
sDrawRegistrantId,
GeometryOverrideExample2::Creator);
if (!status)
{
std::cerr << "Failed to register Viewport 2.0 geometry override." << std::endl;
return status;
}
return status;
}
{
if (!status)
{
std::cerr << "Failed to deregister geometry override." << std::endl;
}
status = plugin.deregisterNode(GeometryOverrideExample2_shape::id);
if (!status)
{
cerr << "Failed to deregister GeometryOverrideExample2_shape." << std::endl;
}
return status;
}