#include <maya/MIOStream.h>
#include <stdio.h>
#include <stdlib.h>
#include <maya/MFn.h>
#include <maya/MPxNode.h>
#include <maya/MPxManipContainer.h>
#include <maya/MPxSelectionContext.h>
#include <maya/MPxContextCommand.h>
#include <maya/MModelMessage.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MPoint.h>
#include <maya/MVector.h>
#include <maya/MDagPath.h>
#include <maya/MManipData.h>
#include <maya/MSelectionList.h>
#include <maya/MItSurfaceCV.h>
#include <maya/MFnComponent.h>
#include <maya/MFnScaleManip.h>
{
double x,y,z;
return result;
}
else {
return result;
}
}
{
public:
componentScaleManip();
~componentScaleManip() override;
static void * creator();
void setSurfaceDagPath(
const MDagPath& dagPath) {
surfaceDagPath = dagPath;
}
void setComponentObject(
const MObject& obj) {
component = obj;
}
public:
private:
int numComponents;
unsigned dummyPlugIndex;
};
MTypeId componentScaleManip::id( 0x80021 );
componentScaleManip::componentScaleManip() : numComponents(0)
, initialPositions(NULL)
, initialControlPoint(NULL)
{
}
componentScaleManip::~componentScaleManip()
{
delete [] initialPositions;
delete [] initialControlPoint;
}
void *componentScaleManip::creator()
{
return new componentScaleManip();
}
MStatus componentScaleManip::initialize()
{
return stat;
}
MStatus componentScaleManip::createChildren()
{
fScaleManip = addScaleManip("scaleManip", "scale");
return stat;
}
{
if (componentFn.elementCount() > numComponents)
{
delete [] initialPositions;
delete [] initialControlPoint;
numComponents = componentFn.elementCount();
initialPositions =
new MPoint[numComponents];
initialControlPoint =
new MPoint[numComponents];
}
int i = 0;
{
if (i >= numComponents)
{
break;
}
centroid += initialPositions[i];
MPlug controlPointArrayPlug = nodeFn.findPlug(
"controlPoints",
true, &stat);
if (controlPointArrayPlug.
isNull())
{
return MS::kFailure;
}
if (controlPointPlug.
isNull())
{
return MS::kFailure;
}
initialControlPoint[i] = vectorPlugValue(controlPointPlug);
unsigned plugIndex = addManipToPlugConversion(controlPointPlug);
if (plugIndex != (unsigned)i)
{
return MS::kFailure;
}
}
centroid = centroid / numComponents;
addPlugToManipConversion(scaleManip.scaleCenterIndex());
finishAddingManips();
return stat;
}
void componentScaleManip::draw(
M3dView & view,
{
}
MManipData componentScaleManip::plugToManipConversion(
unsigned index) {
if (index == scaleManip.scaleCenterIndex())
{
numericData.
setData(centroid.x,centroid.y,centroid.z);
}
return obj;
}
MManipData componentScaleManip::manipToPlugConversion(
unsigned index) {
if (index < (unsigned)numComponents)
{
getConverterManipValue(scaleManip.scaleIndex(), scaleVal);
MVector positionVec = initialPositions[index] - centroid;
MVector newPosition(positionVec.x*scaleVal.
x,
positionVec.y*scaleVal.
y, positionVec.z*scaleVal.
z);
newPosition = newPosition - positionVec;
newPosition += initialControlPoint[index];
numericData.
setData(newPosition.x,newPosition.y,newPosition.z);
}
return obj;
}
{
public:
ComponentScaleContext();
static void updateManipulators(void * data);
private:
MCallbackId id1;
};
ComponentScaleContext::ComponentScaleContext()
{
MString str(
"Plugin component scaling manipulator");
setTitleString(str);
}
void ComponentScaleContext::toolOnSetup(
MEvent &)
{
MString str(
"Scale the selected components");
setHelpString(str);
updateManipulators(this);
updateManipulators,
this, &status);
if (!status) {
}
}
void ComponentScaleContext::toolOffCleanup()
{
if (!status) {
}
}
void ComponentScaleContext::updateManipulators(void * data)
{
ComponentScaleContext * ctxPtr = (ComponentScaleContext *) data;
ctxPtr->deleteManipulators();
if (MS::kSuccess == stat) {
for (; !iter.isDone(); iter.next()) {
iter.getDagPath(dagPath, components);
{
"a component.");
continue;
}
MString manipName (
"componentScaleManip");
componentScaleManip* manipulator =
(componentScaleManip *) componentScaleManip::newManipulator(manipName, manipObject);
if (NULL != manipulator) {
ctxPtr->addManipulator(manipObject);
manipulator->setSurfaceDagPath(dagPath);
manipulator->setComponentObject(components);
if (!manipulator->connectToDependNode(dagPath.
node()))
{
" object");
}
}
}
}
}
{
public:
componentScaleContext() {};
public:
static void* creator();
};
{
return new ComponentScaleContext();
}
void *componentScaleContext::creator()
{
return new componentScaleContext;
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"6.0",
"Any");
status = plugin.registerContextCommand("componentScaleContext",
&componentScaleContext::creator);
if (!status) {
return status;
}
status = plugin.registerNode("componentScaleManip", componentScaleManip::id,
&componentScaleManip::creator, &componentScaleManip::initialize,
if (!status) {
return status;
}
return status;
}
{
status = plugin.deregisterContextCommand("componentScaleContext");
if (!status) {
return status;
}
status = plugin.deregisterNode(componentScaleManip::id);
if (!status) {
return status;
}
return status;
}