//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ // DISCLAIMER: THIS PLUGIN IS PROVIDED AS IS. IT IS NOT SUPPORTED BY // ALIAS, SO PLEASE USE AND MODIFY AT YOUR OWN RISK. // // PLUGIN NAME: closestPointOnMesh v1.0 // FILE: closestPointOnMeshNode.cpp // DESCRIPTION: -Defines "closestPointOnMesh" node. // -Please see readme.txt for full details. // AUTHOR: QT // REFERENCES: -This plugin's concept is based off of the "closestPointOnSurface" node. // -The MEL script AEclosestPointOnSurfaceTemplate.mel was referred to for // the AE template MEL script that accompanies the closestPointOnMesh node. // LAST UPDATED: Oct. 13th, 2001. // COMPILED AND TESTED ON: Maya 4.0 on Windows // HEADER FILES: #include "closestPointOnMeshNode.h" #include "closestNormalUVAndFace.h" // DEFINE CLASS'S STATIC DATA MEMBERS: MTypeId closestPointOnMeshNode::id(0x00105481); MObject closestPointOnMeshNode::aInMesh; MObject closestPointOnMeshNode::aInPosition; MObject closestPointOnMeshNode::aInPositionX; MObject closestPointOnMeshNode::aInPositionY; MObject closestPointOnMeshNode::aInPositionZ; MObject closestPointOnMeshNode::aPosition; MObject closestPointOnMeshNode::aPositionX; MObject closestPointOnMeshNode::aPositionY; MObject closestPointOnMeshNode::aPositionZ; MObject closestPointOnMeshNode::aNormal; MObject closestPointOnMeshNode::aNormalX; MObject closestPointOnMeshNode::aNormalY; MObject closestPointOnMeshNode::aNormalZ; MObject closestPointOnMeshNode::aParameterU; MObject closestPointOnMeshNode::aParameterV; MObject closestPointOnMeshNode::aClosestFaceIndex; // CONSTRUCTOR DEFINITION: closestPointOnMeshNode::closestPointOnMeshNode() { } // DESTRUCTOR DEFINITION: closestPointOnMeshNode::~closestPointOnMeshNode() { } // FOR CREATING AN INSTANCE OF THIS NODE: void *closestPointOnMeshNode::creator() { return new closestPointOnMeshNode(); } // INITIALIZES THE NODE BY CREATING ITS ATTRIBUTES: MStatus closestPointOnMeshNode::initialize() { // CREATE AND ADD ".inMesh" ATTRIBUTE: MFnTypedAttribute inMeshAttrFn; aInMesh = inMeshAttrFn.create("inMesh", "im", MFnData::kMesh); inMeshAttrFn.setStorable(true); inMeshAttrFn.setKeyable(false); inMeshAttrFn.setReadable(true); inMeshAttrFn.setWritable(true); inMeshAttrFn.setCached(false); addAttribute(aInMesh); // CREATE AND ADD ".inPositionX" ATTRIBUTE: MFnNumericAttribute inPositionXAttrFn; aInPositionX = inPositionXAttrFn.create("inPositionX", "ipx", MFnNumericData::kDouble, 0.0); inPositionXAttrFn.setStorable(true); inPositionXAttrFn.setKeyable(true); inPositionXAttrFn.setReadable(true); inPositionXAttrFn.setWritable(true); addAttribute(aInPositionX); // CREATE AND ADD ".inPositionY" ATTRIBUTE: MFnNumericAttribute inPositionYAttrFn; aInPositionY = inPositionYAttrFn.create("inPositionY", "ipy", MFnNumericData::kDouble, 0.0); inPositionYAttrFn.setStorable(true); inPositionYAttrFn.setKeyable(true); inPositionYAttrFn.setReadable(true); inPositionYAttrFn.setWritable(true); addAttribute(aInPositionY); // CREATE AND ADD ".inPositionZ" ATTRIBUTE: MFnNumericAttribute inPositionZAttrFn; aInPositionZ = inPositionZAttrFn.create("inPositionZ", "ipz", MFnNumericData::kDouble, 0.0); inPositionZAttrFn.setStorable(true); inPositionZAttrFn.setKeyable(true); inPositionZAttrFn.setReadable(true); inPositionZAttrFn.setWritable(true); addAttribute(aInPositionZ); // CREATE AND ADD ".inPosition" ATTRIBUTE: MFnNumericAttribute inPositionAttrFn; aInPosition = inPositionAttrFn.create("inPosition", "ip", aInPositionX, aInPositionY, aInPositionZ); inPositionAttrFn.setStorable(true); inPositionAttrFn.setKeyable(true); inPositionAttrFn.setReadable(true); inPositionAttrFn.setWritable(true); addAttribute(aInPosition); // CREATE AND ADD ".positionX" ATTRIBUTE: MFnNumericAttribute pointXAttrFn; aPositionX = pointXAttrFn.create("positionX", "px", MFnNumericData::kDouble, 0.0); pointXAttrFn.setStorable(false); pointXAttrFn.setKeyable(false); pointXAttrFn.setReadable(true); pointXAttrFn.setWritable(false); addAttribute(aPositionX); // CREATE AND ADD ".positionY" ATTRIBUTE: MFnNumericAttribute pointYAttrFn; aPositionY = pointYAttrFn.create("positionY", "py", MFnNumericData::kDouble, 0.0); pointYAttrFn.setStorable(false); pointYAttrFn.setKeyable(false); pointYAttrFn.setReadable(true); pointYAttrFn.setWritable(false); addAttribute(aPositionY); // CREATE AND ADD ".positionZ" ATTRIBUTE: MFnNumericAttribute pointZAttrFn; aPositionZ = pointZAttrFn.create("positionZ", "pz", MFnNumericData::kDouble, 0.0); pointZAttrFn.setStorable(false); pointZAttrFn.setKeyable(false); pointZAttrFn.setReadable(true); pointZAttrFn.setWritable(false); addAttribute(aPositionZ); // CREATE AND ADD ".position" ATTRIBUTE: MFnNumericAttribute pointAttrFn; aPosition = pointAttrFn.create("position", "p", aPositionX, aPositionY, aPositionZ); pointAttrFn.setStorable(false); pointAttrFn.setKeyable(false); pointAttrFn.setReadable(true); pointAttrFn.setWritable(false); addAttribute(aPosition); // CREATE AND ADD ".normalX" ATTRIBUTE: MFnNumericAttribute normalXAttrFn; aNormalX = normalXAttrFn.create("normalX", "nx", MFnNumericData::kDouble, 0.0); normalXAttrFn.setStorable(false); normalXAttrFn.setKeyable(false); normalXAttrFn.setReadable(true); normalXAttrFn.setWritable(false); addAttribute(aNormalX); // CREATE AND ADD ".normalY" ATTRIBUTE: MFnNumericAttribute normalYAttrFn; aNormalY = normalYAttrFn.create("normalY", "ny", MFnNumericData::kDouble, 0.0); normalYAttrFn.setStorable(false); normalYAttrFn.setKeyable(false); normalYAttrFn.setReadable(true); normalYAttrFn.setWritable(false); addAttribute(aNormalY); // CREATE AND ADD ".normalZ" ATTRIBUTE: MFnNumericAttribute normalZAttrFn; aNormalZ = normalZAttrFn.create("normalZ", "nz", MFnNumericData::kDouble, 0.0); normalZAttrFn.setStorable(false); normalZAttrFn.setKeyable(false); normalZAttrFn.setReadable(true); normalZAttrFn.setWritable(false); addAttribute(aNormalZ); // CREATE AND ADD ".normal" ATTRIBUTE: MFnNumericAttribute normalAttrFn; aNormal = normalAttrFn.create("normal", "n", aNormalX, aNormalY, aNormalZ); normalAttrFn.setStorable(false); normalAttrFn.setKeyable(false); normalAttrFn.setReadable(true); normalAttrFn.setWritable(false); addAttribute(aNormal); // CREATE AND ADD ".parameterU" ATTRIBUTE: MFnNumericAttribute parameterUAttrFn; aParameterU = parameterUAttrFn.create("parameterU", "u", MFnNumericData::kDouble, 0.0); parameterUAttrFn.setStorable(false); parameterUAttrFn.setKeyable(false); parameterUAttrFn.setReadable(true); parameterUAttrFn.setWritable(false); addAttribute(aParameterU); // CREATE AND ADD ".parameterV" ATTRIBUTE: MFnNumericAttribute parameterVAttrFn; aParameterV = parameterVAttrFn.create("parameterV", "v", MFnNumericData::kDouble, 0.0); parameterVAttrFn.setStorable(false); parameterVAttrFn.setKeyable(false); parameterVAttrFn.setReadable(true); parameterVAttrFn.setWritable(false); addAttribute(aParameterV); // CREATE AND ADD ".closestFaceIndex" ATTRIBUTE: MFnNumericAttribute closestFaceIndexAttrFn; aClosestFaceIndex = closestFaceIndexAttrFn.create("closestFaceIndex", "f", MFnNumericData::kInt, -1); closestFaceIndexAttrFn.setStorable(false); closestFaceIndexAttrFn.setKeyable(false); closestFaceIndexAttrFn.setReadable(true); closestFaceIndexAttrFn.setWritable(false); addAttribute(aClosestFaceIndex); // DEPENDENCY RELATIONS FOR ".inMesh": attributeAffects(aInMesh, aPosition); attributeAffects(aInMesh, aPositionX); attributeAffects(aInMesh, aPositionY); attributeAffects(aInMesh, aPositionZ); attributeAffects(aInMesh, aNormal); attributeAffects(aInMesh, aNormalX); attributeAffects(aInMesh, aNormalY); attributeAffects(aInMesh, aNormalZ); attributeAffects(aInMesh, aParameterU); attributeAffects(aInMesh, aParameterV); attributeAffects(aInMesh, aClosestFaceIndex); // DEPENDENCY RELATIONS FOR ".inPosition": attributeAffects(aInPosition, aPosition); attributeAffects(aInPosition, aPositionX); attributeAffects(aInPosition, aPositionY); attributeAffects(aInPosition, aPositionZ); attributeAffects(aInPosition, aNormal); attributeAffects(aInPosition, aNormalX); attributeAffects(aInPosition, aNormalY); attributeAffects(aInPosition, aNormalZ); attributeAffects(aInPosition, aParameterU); attributeAffects(aInPosition, aParameterV); attributeAffects(aInPosition, aClosestFaceIndex); // DEPENDENCY RELATIONS FOR ".inPositionX": attributeAffects(aInPositionX, aPosition); attributeAffects(aInPositionX, aPositionX); attributeAffects(aInPositionX, aPositionY); attributeAffects(aInPositionX, aPositionZ); attributeAffects(aInPositionX, aNormal); attributeAffects(aInPositionX, aNormalX); attributeAffects(aInPositionX, aNormalY); attributeAffects(aInPositionX, aNormalZ); attributeAffects(aInPositionX, aParameterU); attributeAffects(aInPositionX, aParameterV); attributeAffects(aInPositionX, aClosestFaceIndex); // DEPENDENCY RELATIONS FOR ".inPositionY": attributeAffects(aInPositionY, aPosition); attributeAffects(aInPositionY, aPositionX); attributeAffects(aInPositionY, aPositionY); attributeAffects(aInPositionY, aPositionZ); attributeAffects(aInPositionY, aNormal); attributeAffects(aInPositionY, aNormalX); attributeAffects(aInPositionY, aNormalY); attributeAffects(aInPositionY, aNormalZ); attributeAffects(aInPositionY, aParameterU); attributeAffects(aInPositionY, aParameterV); attributeAffects(aInPositionY, aClosestFaceIndex); // DEPENDENCY RELATIONS FOR ".inPositionZ": attributeAffects(aInPositionZ, aPosition); attributeAffects(aInPositionZ, aPositionX); attributeAffects(aInPositionZ, aPositionY); attributeAffects(aInPositionZ, aPositionZ); attributeAffects(aInPositionZ, aNormal); attributeAffects(aInPositionZ, aNormalX); attributeAffects(aInPositionZ, aNormalY); attributeAffects(aInPositionZ, aNormalZ); attributeAffects(aInPositionZ, aParameterU); attributeAffects(aInPositionZ, aParameterV); attributeAffects(aInPositionZ, aClosestFaceIndex); return MS::kSuccess; } // COMPUTE METHOD'S DEFINITION: MStatus closestPointOnMeshNode::compute(const MPlug &plug, MDataBlock &data) { // DO THE COMPUTE ONLY FOR THE *OUTPUT* PLUGS THAT ARE DIRTIED: if ((plug == aPosition) || (plug == aPositionX) || (plug == aPositionY) || (plug == aPositionZ) || (plug == aNormal) || (plug == aNormalX) || (plug == aNormalY) || (plug == aNormalZ) || (plug == aParameterU) || (plug == aParameterV) || (plug == aClosestFaceIndex)) { // READ IN ".inMesh" DATA: MDataHandle inMeshDataHandle = data.inputValue(aInMesh); MObject inMesh = inMeshDataHandle.asMesh(); // READ IN ".inPositionX" DATA: MDataHandle inPositionXDataHandle = data.inputValue(aInPositionX); double inPositionX = inPositionXDataHandle.asDouble(); // READ IN ".inPositionY" DATA: MDataHandle inPositionYDataHandle = data.inputValue(aInPositionY); double inPositionY = inPositionYDataHandle.asDouble(); // READ IN ".inPositionZ" DATA: MDataHandle inPositionZDataHandle = data.inputValue(aInPositionZ); double inPositionZ = inPositionZDataHandle.asDouble(); // GET THE CLOSEST POSITION, NORMAL, UV AND FACE INDEX: MPoint inPosition(inPositionX, inPositionY, inPositionZ); MPoint position; MVector normal; double parameterU, parameterV; int closestFaceIndex; MDagPath dummyDagPath; closestNormalUVAndFace(dummyDagPath, inPosition, position, normal, parameterU, parameterV, closestFaceIndex, inMesh); // WRITE OUT ".position" DATA: MDataHandle positionDataHandle = data.outputValue(aPosition); positionDataHandle.set(position.x, position.y, position.z); data.setClean(plug); // WRITE OUT ".normal" DATA: MDataHandle normalDataHandle = data.outputValue(aNormal); normalDataHandle.set(normal.x, normal.y, normal.z); data.setClean(plug); // WRITE OUT ".parameterU" DATA: MDataHandle parameterUDataHandle = data.outputValue(aParameterU); parameterUDataHandle.set(parameterU); data.setClean(plug); // WRITE OUT ".parameterV" DATA: MDataHandle parameterVDataHandle = data.outputValue(aParameterV); parameterVDataHandle.set(parameterV); data.setClean(plug); // WRITE OUT ".closestFaceIndex" DATA: MDataHandle closestFaceIndexDataHandle = data.outputValue(aClosestFaceIndex); closestFaceIndexDataHandle.set(closestFaceIndex); data.setClean(plug); } else { return MS::kUnknownParameter; } return MS::kSuccess; }