#include <maya/MFnPlugin.h>
#include <maya/MDrawRegistry.h>
#include "geometryOverrideExample1.h"
#include <maya/MShaderManager.h>
#include <maya/MSelectionMask.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MGlobal.h>
#include <iostream>
static void instancingChangedCallback(
MDagPath& child,
MDagPath& parent,
void* clientData)
{
}
GeometryOverrideExample1_shape::GeometryOverrideExample1_shape()
{
const float normal_value = 0.5775f;
fNormals.push_back(
MFloatVector(-normal_value, -normal_value, -normal_value));
fNormals.push_back(
MFloatVector( normal_value, -normal_value, -normal_value));
fNormals.push_back(
MFloatVector( normal_value, -normal_value, normal_value));
fNormals.push_back(
MFloatVector(-normal_value, -normal_value, normal_value));
fNormals.push_back(
MFloatVector(-normal_value, normal_value, -normal_value));
fNormals.push_back(
MFloatVector(-normal_value, normal_value, normal_value));
fNormals.push_back(
MFloatVector( normal_value, normal_value, normal_value));
fNormals.push_back(
MFloatVector( normal_value, normal_value, -normal_value));
fShadedIndices =
{
0, 1, 2, 2, 3, 0,
4, 5, 6, 6, 7, 4,
0, 3, 5, 5, 4, 0,
1, 7, 6, 6, 2, 1,
4, 1, 0, 4, 7, 1,
5, 3, 2, 2, 6, 5,
};
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,
};
}
GeometryOverrideExample1_shape::~GeometryOverrideExample1_shape()
{
}
void GeometryOverrideExample1_shape::postConstructor()
{
setRenderable(true);
}
MSelectionMask GeometryOverrideExample1_shape::getShapeSelectionMask()
const
{
}
MBoundingBox GeometryOverrideExample1_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* GeometryOverrideExample1::sActiveWireframeRenderItemName = "GeometryOverrideExample1_ActiveWireframe";
const char* GeometryOverrideExample1::sDormantWireframeRenderItemName = "GeometryOverrideExample1_DormantWireframe";
const char* GeometryOverrideExample1::sShadedRenderItemName = "GeometryOverrideExample1_shaded";
GeometryOverrideExample1::GeometryOverrideExample1(
const MObject& obj)
{
if (status)
{
fMesh = dynamic_cast<GeometryOverrideExample1_shape*>(node.userNode());
}
}
GeometryOverrideExample1::~GeometryOverrideExample1()
{
}
MHWRender::DrawAPI GeometryOverrideExample1::supportedDrawAPIs() const
{
return (MHWRender::kOpenGL | MHWRender::kDirectX11 | MHWRender::kOpenGLCoreProfile);
}
void GeometryOverrideExample1::updateDG()
{
}
bool GeometryOverrideExample1::requiresGeometryUpdate() const
{
return false;
}
bool GeometryOverrideExample1::supportsEvaluationManagerParallelUpdate() const
{
return true;
}
{
return;
MRenderer* renderer = MRenderer::theRenderer();
if (!renderer)
return;
const MShaderManager* shaderManager = renderer->getShaderManager();
if (!shaderManager)
return;
auto renderItemIndex = renderItems.
indexOf(sShadedRenderItemName);
if (renderItemIndex < 0)
{
shadedRenderItem->
enable(
true);
MShaderInstance* shader = shaderManager->getStockShader(MShaderManager::k3dSolidShader);
if (shader)
{
const float blueColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
shader->setParameter("solidColor", blueColor);
shaderManager->releaseShader(shader);
}
renderItems.
append(shadedRenderItem);
}
bool isWireFrameRenderItemEnabled = displayStatus == MHWRender::kLead || displayStatus == MHWRender::kActive;
updateWireframeItems(sActiveWireframeRenderItemName,
wireframeColor,
isWireFrameRenderItemEnabled,
renderItems,
*shaderManager);
isWireFrameRenderItemEnabled = displayStatus == MHWRender::kDormant;
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;
switch (desc.semantic())
{
case MGeometry::kPosition:
{
if (positionBuffer)
{
GeometryOverrideExample1_shape::PositionList positions = fMesh->getPositions();
void* buffer = positionBuffer->
acquire(positions.size(),
true );
if(buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample1_shape::PositionList::value_type) * positions.size();
memcpy(buffer, positions.data(), bufferSizeInByte);
positionBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kNormal:
{
if (normalsBuffer)
{
GeometryOverrideExample1_shape::NormalList normals = fMesh->getNormals();
void* buffer = normalsBuffer->
acquire(normals.size(),
true );
if(buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample1_shape::NormalList::value_type) * normals.size();
memcpy(buffer, normals.data(), bufferSizeInByte);
normalsBuffer->
commit(buffer);
}
}
}
break;
case MGeometry::kTexture:
case MGeometry::kColor:
case MGeometry::kTangent:
case MGeometry::kBitangent:
case MGeometry::kTangentWithSign:
case MGeometry::kInvalidSemantic:
break;
}
}
const int numItems = renderItems.
length();
for (int i = 0; i < numItems; i++)
{
if (!item)
continue;
{
if (indexBuffer)
{
GeometryOverrideExample1_shape::IndexList indices = fMesh->getShadedIndices();
void* buffer = indexBuffer->
acquire(indices.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample1_shape::IndexList::value_type) * indices.size();
memcpy(buffer, indices.data(), bufferSizeInByte);
}
}
}
{
if (indexBuffer)
{
GeometryOverrideExample1_shape::IndexList indices = fMesh->getWireFrameIndices();
void* buffer = indexBuffer->
acquire(indices.size(),
true );
if (buffer)
{
const std::size_t bufferSizeInByte =
sizeof(GeometryOverrideExample1_shape::IndexList::value_type) * indices.size();
memcpy(buffer, indices.data(), bufferSizeInByte);
}
}
}
}
}
void GeometryOverrideExample1::cleanUp()
{
}
void GeometryOverrideExample1::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/geometryOverrideExample1");
MString sDrawRegistrantId(
"geometryOverrideExample1Plugin");
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerShape("geometryOverrideExample1_shape",
GeometryOverrideExample1_shape::id,
&GeometryOverrideExample1_shape::creator,
&GeometryOverrideExample1_shape::initialize,
nullptr,
&sDrawDbClassification);
if (!status)
{
std::cerr << "Failed to register geometryOverrideExample1_shape." << std::endl;
return status;
}
sDrawRegistrantId,
GeometryOverrideExample1::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(GeometryOverrideExample1_shape::id);
if (!status)
{
std::cerr << "Failed to deregister GeometryOverrideExample1_shape." << std::endl;
}
return status;
}