geometryOverrideHighPerformance/geometryOverrideHighPerformance.h

geometryOverrideHighPerformance/geometryOverrideHighPerformance.h
//-
// ==========================================================================
// Copyright 2018 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk
// license agreement provided at the time of installation or download,
// or which otherwise accompanies this software in either electronic
// or hard copy form.
// ==========================================================================
//+
#ifndef GeometryOverrideHighPerformance_h
#define GeometryOverrideHighPerformance_h
#include "geometryOverrideHighPerformanceHelper.h"
#include <maya/MPxGeometryOverride.h>
#include <maya/MPxSurfaceShape.h>
#include <maya/MFloatVector.h>
#include <maya/MHWGeometry.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MDagMessage.h>
#include <vector>
class GeometryOverrideHighPerformance_shape : public MPxSurfaceShape
{
public:
static void * creator()
{
return new GeometryOverrideHighPerformance_shape();
}
static MStatus initialize();
~GeometryOverrideHighPerformance_shape() override;
//
// Overrides from MPxNode
//
MStatus connectionMade(const MPlug& plug, const MPlug& otherPlug, bool asSrc) override;
MStatus connectionBroken(const MPlug& plug, const MPlug& otherPlug, bool asSrc) override;
void postConstructor() override;
MStatus setDependentsDirty(const MPlug& plug, MPlugArray& plugArray) override;
MStatus postEvaluation(const MDGContext& context, const MEvaluationNode& evaluationNode, PostEvaluationType evalType) override;
//
// Overrides from MPxSurfaceShape
//
bool isBounded() const override { return true; }
MBoundingBox boundingBox() const override;
void setSizeChangedSinceVP2Update(bool value);
bool evalSizeChangedSinceVP2Update();
bool evalInputMeshChangedSinceVP2Update();
void setInputMeshChangedSinceVP2Update(bool value);
bool evalInputMeshGeoChangedSinceVP2Update();
void setInputMeshGeoChangedSinceVP2Update(bool value);
bool evalMaterialChangedSinceVP2Update();
void setMaterialChangedSinceVP2Update(bool value);
const Float3Array& getPositions() const { return fPositions; }
const Float3Array& getNormals() const { return fNormals; }
const Float3Array& getTangents() const { return fTangents; }
const Float3Array& getBiTangents() const { return fBiTangents; }
const Float2Array & getTexCoords() const { return fTextureCoords; }
const IndexList& getIndices() const { return fIndices; }
public:
static MTypeId fsId; // plugin node id
static MObject fsInputMesh; // The input mesh to use (Node attribute)
static MObject fsSize; // The size of the mesh (Node attribute)
static MObject fsInputMeshBoundingBoxMin;
static MObject fsInputMeshBoundingBoxMax;
// Use an internal attribute to store if any attribute which affects
// the geometry created by the node has changed since the last time
// the GeometryOverride was executed.
//
// attributes are stored in the MDataBlock and the MDataBlock is context
// aware storage, so internal attributes are a good way to communicate between the
// MPxNode and the MPxGeometryOverride which is safe to use with VP2 Custom Caching.
static MObject fsSizeChangedSinceVP2Update;
static MObject fsInputMeshChanged;
static MObject fsInputMeshGeoChanged;
static MObject fsMaterialChanged;
private:
GeometryOverrideHighPerformance_shape();
static Float3Array fPositions; // vertex positions
static Float3Array fNormals; // vertex normals
static Float3Array fTangents; // vertex tangents
static Float3Array fBiTangents; // vertex bitangents
static Float2Array fTextureCoords; // vertex texture UV
static IndexList fIndices; // vertex indices used to draw the cube in filled mode
static MBoundingBox fBoundingBox;
MBoundingBox fInputMeshBoundingBox;
bool fUseInputMesh = false;
MCallbackId mInstanceAddedCallbackId = 0;
};
class GeometryOverrideHighPerformance : public MHWRender::MPxGeometryOverride
{
public:
static MHWRender::MPxGeometryOverride* Creator(const MObject& obj)
{
return new GeometryOverrideHighPerformance(obj);
}
~GeometryOverrideHighPerformance() override;
void updateDG() override;
void updateRenderItems(const MDagPath& path, MHWRender::MRenderItemList& list) override;
const MHWRender::MRenderItemList& renderItems,
MHWRender::MGeometry& data) override;
void cleanUp() override;
bool isIndexingDirty(const MRenderItem& item) override;
bool requiresGeometryUpdate() const override;
bool requiresUpdateRenderItems(const MDagPath& path) const override;
bool supportsVP2CustomCaching() const override;
private:
GeometryOverrideHighPerformance(const MObject& obj);
void updateWireframeItems(const char* renderItemName, MGeometry::DrawMode mode, unsigned int depthPriority,
MColor color, bool isEnabled, MHWRender::MRenderItemList& renderItemList,
const MHWRender::MShaderManager& shaderManager);
void populateInputMeshGeometry(const MHWRender::MGeometryRequirements& requirements, const MHWRender::MRenderItemList& renderItems, MHWRender::MGeometry& data);
void populateDefaultMeshGeometry(const MHWRender::MGeometryRequirements& requirements, const MHWRender::MRenderItemList& renderItems, MHWRender::MGeometry& data);
private:
static const char* sActiveWireframeRenderItemName;
static const char* sDormantWireframeRenderItemName;
static const char* sCustomShadedItemName;
GeometryOverrideHighPerformance_shape* fMesh = nullptr;
MObject fSurfaceNode;
MDagPath fInputMeshPath;
MHWRender::DisplayStatus fDisplayStatus = MHWRender::DisplayStatus::kNoStatus;
MColor fWireframeDisplayColor;
float fSizeMultiplier = 1.0f;
};
#endif // GeometryOverrideHighPerformance_h