#include <maya/MPxImagePlane.h>
#include <maya/MFnPlugin.h>
#include <maya/MImage.h>
#include <maya/MString.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnNumericData.h>
#include <maya/MDataHandle.h>
#include <maya/MPlug.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MRenderUtil.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MPxImagePlaneOverride.h>
#include <maya/MDrawRegistry.h>
#include <maya/MTextureManager.h>
#include <maya/MApiNamespace.h>
{
public:
customImagePlane();
static void* creator();
};
{
public:
customImagePlaneOverride(
const MObject& obj);
virtual ~customImagePlaneOverride();
private:
};
customImagePlane::customImagePlane()
{
}
bool
{
}
bool
customImagePlane::setInternalValue(
const MPlug & plug,
const MDataHandle & handle)
{
}
customImagePlane::loadImageMap(
{
unsigned int width, height;
unsigned int i;
MPlug depthMap( thisMObject(), useDepthMap );
bool value;
depthMap.getValue( value );
if ( value ) {
float *buffer = new float[width*height];
unsigned int c, j;
for ( c = i = 0; i < height; i ++ ) {
for ( j = 0; j < width; j ++, c++ ) {
if ( i > height/2 ) {
buffer[c] = -1.0f;
} else {
buffer[c] = 0.0f;
}
}
}
delete [] buffer;
}
}
MTypeId customImagePlane::id( 0x1A19 );
void*
customImagePlane::creator()
{
return new customImagePlane;
}
customImagePlane::initialize()
{
}
{
return new customImagePlaneOverride(obj);
}
customImagePlaneOverride::customImagePlaneOverride(
const MObject& obj)
, Object(obj)
, FileName("")
{
Texture = nullptr;
}
customImagePlaneOverride::~customImagePlaneOverride()
{
if (Texture)
{
if (textureManager)
{
Texture = nullptr;
}
}
}
{
}
void customImagePlaneOverride::updateDG()
{
if (status)
{
bool useFrameExt = false;
node.findPlug("useFrameExtension").getValue(useFrameExt);
FileName = getFileName(useFrameExt);
}
}
void customImagePlaneOverride::updateColorTexture()
{
if (renderer)
{
if (textureManager)
{
if (Texture)
{
Texture->textureDescription(desc);
unsigned int bpp = Texture->bytesPerPixel();
if (bpp == 4 &&
{
int rowPitch = 0;
size_t slicePitch = 0;
bool generateMipMaps = true;
unsigned char* pixelData = (unsigned char *)Texture->rawData(rowPitch, slicePitch);
unsigned char* val = NULL;
if (pixelData && rowPitch > 0 && slicePitch > 0)
{
bool updateEntireImage = false;
if (updateEntireImage)
{
for (
unsigned int i=0; i<desc.
fHeight; i++)
{
val = pixelData + (i*rowPitch);
for (
unsigned int j=0; j<desc.
fWidth*4; j+=4)
{
*val = 255;
val += 4;
}
}
Texture->update(pixelData, generateMipMaps, rowPitch);
} else {
unsigned int minX = desc.
fWidth / 3;
unsigned int maxX = (desc.
fWidth * 2) / 3;
unsigned int newWidth = maxX - minX;
unsigned int minY = desc.
fHeight/ 3;
unsigned int maxY = (desc.
fHeight *2) / 3;
unsigned int newHeight = maxY - minY;
unsigned char* newData = new unsigned char[newWidth * newHeight * 4];
if (newData)
{
unsigned char* newVal = newData;
for (unsigned int i=minY; i<maxY; i++)
{
val = pixelData + (i*rowPitch) + minX*4;
for (unsigned int j=0; j<newWidth*4; j++)
{
*newVal = 124;
val++;
newVal++;
}
}
updateRegion.
fXRangeMin = minX;
updateRegion.
fXRangeMax = maxX;
updateRegion.
fYRangeMin = minY;
updateRegion.
fYRangeMax = maxY;
Texture->update(newData, generateMipMaps, newWidth*4, &updateRegion);
delete [] newData;
}
}
}
delete [] pixelData;
}
}
}
}
}
static const MString sRegistrantId(
"customImagePlaneOverride");
{
const MString UserClassify(
"geometry/imagePlane:drawdb/geometry/imagePlane/customImagePlane" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"7.0",
"Any");
plugin.registerNode( "customImagePlane", customImagePlane::id,
customImagePlane::creator,
customImagePlane::initialize,
&UserClassify));
"drawdb/geometry/imagePlane/customImagePlane",
sRegistrantId,
customImagePlaneOverride::creator));
return MS::kSuccess;
}
{
plugin.deregisterNode( customImagePlane::id ));
"drawdb/geometry/imagePlane/customImagePlane",
sRegistrantId));
return MS::kSuccess;
}