MStatus TestDeformer::deform(MDataBlock& data, MItGeometry& iter, const MMatrix& localToWorldMatrix, unsigned int mIndex) { MStatus status; // get the current node state short initialized_mapping = data.inputValue( initialized_data, &status).asShort(); CHECK_MSTATUS(status); __debug("%s(), initialized_mapping=%d, mIndex=%d", __FUNCTION__, initialized_mapping, mIndex); if( initialized_mapping == 1 ) { initVertMapping(data, iter, localToWorldMatrix, mIndex); // set initialized_data to 2 automatically. User don't have to set it manully. MObject tObj = thisMObject(); MPlug setInitMode = MPlug( tObj, initialized_data ); setInitMode.setShort( 2 ); // and sync initialized_mapping from initialized_data // so, the code section: // if (initialized_mapping == 2) // { // ... // } // will be executed when this deform() function is called next time. initialized_mapping = data.inputValue( initialized_data, &status ).asShort(); CHECK_MSTATUS(status); } if( initialized_mapping == 2 ) { envelope = MPxDeformerNode::envelope; MDataHandle envelopeHandle = data.inputValue( envelope, &status ); CHECK_MSTATUS( status ); MArrayDataHandle vertMapArrayData = data.inputArrayValue( vert_map, &status ); CHECK_MSTATUS( status ); MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status ); CHECK_MSTATUS( status ); /// 1. init tempOutputPts to zero points MPointArray tempOutputPts; iter.reset(); while( !iter.isDone(&status) ) { CHECK_MSTATUS(tempOutputPts.append(MPoint(0, 0, 0))); CHECK_MSTATUS(iter.next()); } assert(tempOutputPts.length() == iter.count()); /// 2. set tempOutputPts to deform values which comes from each driver mesh iter.reset(); int numMeshes = meshAttrHandle.elementCount(); __debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes); CHECK_MSTATUS(meshAttrHandle.jumpToElement(0)); // for each driver mesh for( int count=0; count < numMeshes; ++count ) { __debug("%s(), count=%d", __FUNCTION__, count); // for one driver mesh: currentMesh MDataHandle currentMesh = meshAttrHandle.inputValue(&status); CHECK_MSTATUS( status ); MObject meshMobj = currentMesh.asMesh(); __debugMeshInfo(__FUNCTION__, meshMobj); // accumulate deform values of currentMesh to tempOutputPts _deform_on_one_mesh(data, iter, localToWorldMatrix, mIndex, meshMobj, envelopeHandle, vertMapArrayData, tempOutputPts ); if( !meshAttrHandle.next() ) { break; } }// for each driver mesh /// 3. add deform value to this geometry(driven mesh) int i = 0; iter.reset(); while( !iter.isDone(&status) ) { MPoint p = iter.position(MSpace::kObject, &status); CHECK_MSTATUS(status); // add the deform value to this vertex CHECK_MSTATUS(iter.setPosition( p + tempOutputPts[i]/numMeshes )); CHECK_MSTATUS(iter.next()); ++i; } assert(tempOutputPts.length() == iter.count()); }// if return( MS::kSuccess ); }
// The initialize routine is called after the node has been created. // It sets up the input and output attributes and adds them to the // node. Finally the dependencies are arranged so that when the // inputs change Maya knowns to call compute to recalculate the output // value. // MStatus stringFormat::initialize() { MFnNumericAttribute numAttr; MFnTypedAttribute typedAttr; MFnStringData stringData; MStatus stat; MStatus stat2; // Setup the input attributes // attrFormat = typedAttr.create("format", "f", MFnData::kString, stringData.create(&stat2), &stat); CHECK_MSTATUS( stat2 ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( typedAttr.setStorable( true ) ); CHECK_MSTATUS( typedAttr.setKeyable( true ) ); attrValues = numAttr.create("values", "v", MFnNumericData::kDouble, 0, &stat); CHECK_MSTATUS( stat ); CHECK_MSTATUS( numAttr.setArray( true ) ); CHECK_MSTATUS( numAttr.setReadable( false ) ); CHECK_MSTATUS( numAttr.setIndexMatters( true ) ); CHECK_MSTATUS( numAttr.setStorable( true ) ); CHECK_MSTATUS( numAttr.setKeyable( true ) ); attrOutput = typedAttr.create( "output", "o", MFnData::kString, stringData.create(&stat2), &stat); CHECK_MSTATUS( stat2 ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( typedAttr.setWritable( false ) ); CHECK_MSTATUS( typedAttr.setStorable( false ) ); // Add the attributes to the node // CHECK_MSTATUS( addAttribute( attrFormat ) ); CHECK_MSTATUS( addAttribute( attrValues ) ); CHECK_MSTATUS( addAttribute( attrOutput ) ); // Set the attribute dependencies // CHECK_MSTATUS( attributeAffects( attrFormat, attrOutput ) ); CHECK_MSTATUS( attributeAffects( attrValues, attrOutput ) ); return MS::kSuccess; }
void LuxRenderer::defineTriangleMesh(mtlu_MayaObject *obj, bool noObjectDef = false) { MObject meshObject = obj->mobject; MStatus stat = MStatus::kSuccess; MFnMesh meshFn(meshObject, &stat); CHECK_MSTATUS(stat); MItMeshPolygon faceIt(meshObject, &stat); CHECK_MSTATUS(stat); MPointArray points; meshFn.getPoints(points); MFloatVectorArray normals; meshFn.getNormals( normals, MSpace::kWorld ); MFloatArray uArray, vArray; meshFn.getUVs(uArray, vArray); logger.debug(MString("Translating mesh object ") + meshFn.name().asChar()); MString meshFullName = obj->fullNiceName; MIntArray trianglesPerFace, triVertices; meshFn.getTriangles(trianglesPerFace, triVertices); int numTriangles = 0; for( size_t i = 0; i < trianglesPerFace.length(); i++) numTriangles += trianglesPerFace[i]; // lux render does not have a per vertex per face normal definition, here we can use one normal and uv per vertex only // So I create the triangles with unique vertices, normals and uvs. Of course this way vertices etc. cannot be shared. int numPTFloats = numTriangles * 3 * 3; logger.debug(MString("Num Triangles: ") + numTriangles + " num tri floats " + numPTFloats); float *floatPointArray = new float[numPTFloats]; float *floatNormalArray = new float[numPTFloats]; float *floatUvArray = new float[numTriangles * 3 * 2]; logger.debug(MString("Allocated ") + numPTFloats + " floats for point and normals"); MIntArray triangelVtxIdListA; MFloatArray floatPointArrayA; MPointArray triPoints; MIntArray triVtxIds; MIntArray faceVtxIds; MIntArray faceNormalIds; int *triangelVtxIdList = new int[numTriangles * 3]; for( uint sgId = 0; sgId < obj->shadingGroups.length(); sgId++) { MString slotName = MString("slot_") + sgId; } int triCount = 0; int vtxCount = 0; for(faceIt.reset(); !faceIt.isDone(); faceIt.next()) { int faceId = faceIt.index(); int numTris; faceIt.numTriangles(numTris); faceIt.getVertices(faceVtxIds); MIntArray faceUVIndices; faceNormalIds.clear(); for( uint vtxId = 0; vtxId < faceVtxIds.length(); vtxId++) { faceNormalIds.append(faceIt.normalIndex(vtxId)); int uvIndex; faceIt.getUVIndex(vtxId, uvIndex); faceUVIndices.append(uvIndex); } int perFaceShadingGroup = 0; if( obj->perFaceAssignments.length() > 0) perFaceShadingGroup = obj->perFaceAssignments[faceId]; //logger.info(MString("Face ") + faceId + " will receive SG " + perFaceShadingGroup); for( int triId = 0; triId < numTris; triId++) { int faceRelIds[3]; faceIt.getTriangle(triId, triPoints, triVtxIds); for( uint triVtxId = 0; triVtxId < 3; triVtxId++) { for(uint faceVtxId = 0; faceVtxId < faceVtxIds.length(); faceVtxId++) { if( faceVtxIds[faceVtxId] == triVtxIds[triVtxId]) { faceRelIds[triVtxId] = faceVtxId; } } } uint vtxId0 = faceVtxIds[faceRelIds[0]]; uint vtxId1 = faceVtxIds[faceRelIds[1]]; uint vtxId2 = faceVtxIds[faceRelIds[2]]; uint normalId0 = faceNormalIds[faceRelIds[0]]; uint normalId1 = faceNormalIds[faceRelIds[1]]; uint normalId2 = faceNormalIds[faceRelIds[2]]; uint uvId0 = faceUVIndices[faceRelIds[0]]; uint uvId1 = faceUVIndices[faceRelIds[1]]; uint uvId2 = faceUVIndices[faceRelIds[2]]; floatPointArray[vtxCount * 3] = points[vtxId0].x; floatPointArray[vtxCount * 3 + 1] = points[vtxId0].y; floatPointArray[vtxCount * 3 + 2] = points[vtxId0].z; floatNormalArray[vtxCount * 3] = normals[normalId0].x; floatNormalArray[vtxCount * 3 + 1] = normals[normalId0].y; floatNormalArray[vtxCount * 3 + 2] = normals[normalId0].z; floatUvArray[vtxCount * 2] = uArray[uvId0]; floatUvArray[vtxCount * 2 + 1] = vArray[uvId0]; vtxCount++; floatPointArray[vtxCount * 3] = points[vtxId1].x; floatPointArray[vtxCount * 3 + 1] = points[vtxId1].y; floatPointArray[vtxCount * 3 + 2] = points[vtxId1].z; floatNormalArray[vtxCount * 3] = normals[normalId1].x; floatNormalArray[vtxCount * 3 + 1] = normals[normalId1].y; floatNormalArray[vtxCount * 3 + 2] = normals[normalId1].z; floatUvArray[vtxCount * 2] = uArray[uvId1]; floatUvArray[vtxCount * 2 + 1] = vArray[uvId1]; vtxCount++; floatPointArray[vtxCount * 3] = points[vtxId2].x; floatPointArray[vtxCount * 3 + 1] = points[vtxId2].y; floatPointArray[vtxCount * 3 + 2] = points[vtxId2].z; floatNormalArray[vtxCount * 3] = normals[normalId2].x; floatNormalArray[vtxCount * 3 + 1] = normals[normalId2].y; floatNormalArray[vtxCount * 3 + 2] = normals[normalId2].z; floatUvArray[vtxCount * 2] = uArray[uvId2]; floatUvArray[vtxCount * 2 + 1] = vArray[uvId2]; vtxCount++; //logger.debug(MString("Vertex count: ") + vtxCount + " maxId " + ((vtxCount - 1) * 3 + 2) + " ptArrayLen " + (numTriangles * 3 * 3)); triangelVtxIdList[triCount * 3] = triCount * 3; triangelVtxIdList[triCount * 3 + 1] = triCount * 3 + 1; triangelVtxIdList[triCount * 3 + 2] = triCount * 3 + 2; triCount++; } } //generatetangents bool Generate tangent space using miktspace, useful if mesh has a normal map that was also baked using miktspace (such as blender or xnormal) false //subdivscheme string Subdivision algorithm, options are "loop" and "microdisplacement" "loop" //displacementmap string Name of the texture used for the displacement. Subdivscheme parameter must always be provided, as load-time displacement is handled by the loop-subdivision code. none - optional. (loop subdiv can be used without displacement, microdisplacement will not affect the mesh without a displacement map specified) //dmscale float Scale of the displacement (for an LDR map, this is the maximum height of the displacement in meter) 0.1 //dmoffset float Offset of the displacement. 0 //dmnormalsmooth bool Smoothing of the normals of the subdivided faces. Only valid for loop subdivision. true //dmnormalsplit bool Force the mesh to split along breaks in the normal. If a mesh has no normals (flat-shaded) it will rip open on all edges. Only valid for loop subdivision. false //dmsharpboundary bool Try to preserve mesh boundaries during subdivision. Only valid for loop subdivision. false //nsubdivlevels integer Number of subdivision levels. This is only recursive for loop subdivision, microdisplacement will need much larger values (such as 50). 0 bool generatetangents = false; getBool(MString("mtlu_mesh_generatetangents"), meshFn, generatetangents); int subdivscheme = 0; const char *subdAlgos[] = {"loop", "microdisplacement"}; getInt(MString("mtlu_mesh_subAlgo"), meshFn, subdivscheme); const char *subdalgo = subdAlgos[subdivscheme]; float dmscale; getFloat(MString("mtlu_mesh_dmscale"), meshFn, dmscale); float dmoffset; getFloat(MString("mtlu_mesh_dmoffset"), meshFn, dmoffset); MString displacementmap; getString(MString("mtlu_mesh_displacementMap"), meshFn, displacementmap); const char *displacemap = displacementmap.asChar(); bool dmnormalsmooth = true; getBool(MString("mtlu_mesh_dmnormalsmooth"), meshFn, dmnormalsmooth); bool dmnormalsplit = false; getBool(MString("mtlu_mesh_dmnormalsplit"), meshFn, dmnormalsplit); bool dmsharpboundary = false; getBool(MString("mtlu_mesh_dmsharpboundary"), meshFn, dmsharpboundary); int nsubdivlevels = 0; getInt(MString("mtlu_mesh_subdivlevel"), meshFn, nsubdivlevels); // a displacment map needs its own texture defintion MString displacementTextureName = ""; if(displacementmap.length() > 0) { ParamSet dmParams = CreateParamSet(); dmParams->AddString("filename", &displacemap); displacementTextureName = meshFn.name() + "_displacementMap"; this->lux->texture(displacementTextureName.asChar(), "float", "imagemap", boost::get_pointer(dmParams)); } ParamSet triParams = CreateParamSet(); int numPointValues = numTriangles * 3; int numUvValues = numTriangles * 3 * 2; clock_t startTime = clock(); logger.info(MString("Adding mesh values to params.")); triParams->AddInt("indices", triangelVtxIdList, numTriangles * 3); triParams->AddPoint("P", floatPointArray, numPointValues); triParams->AddNormal("N", floatNormalArray, numPointValues); triParams->AddFloat("uv", floatUvArray, numUvValues); if( nsubdivlevels > 0) triParams->AddInt("nsubdivlevels", &nsubdivlevels, 1); triParams->AddBool("generatetangents", &generatetangents, 1); triParams->AddString("subdivscheme", &subdalgo , 1); if(displacementmap.length() > 0) { triParams->AddFloat("dmoffset", &dmoffset, 1); triParams->AddFloat("dmscale", &dmscale, 1); const char *dmft = displacementTextureName.asChar(); triParams->AddString("displacementmap", &dmft); } triParams->AddBool("dmnormalsmooth", &dmnormalsmooth, 1); triParams->AddBool("dmnormalsplit", &dmnormalsplit, 1); triParams->AddBool("dmsharpboundary", &dmsharpboundary, 1); clock_t pTime = clock(); if(!noObjectDef) this->lux->objectBegin(meshFullName.asChar()); this->lux->shape("trianglemesh", boost::get_pointer(triParams)); if(!noObjectDef) this->lux->objectEnd(); clock_t eTime = clock(); logger.info(MString("Timing: Parameters: ") + ((pTime - startTime)/CLOCKS_PER_SEC) + " objTime " + ((eTime - pTime)/CLOCKS_PER_SEC) + " all " + ((eTime - startTime)/CLOCKS_PER_SEC)); return; }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus Cell3D::initialize() { MFnMatrixAttribute mAttr; MFnNumericAttribute nAttr; // Input attributes aColorGain = nAttr.createColor("colorGain", "cg"); MAKE_INPUT(nAttr); CHECK_MSTATUS( nAttr.setDefault(1.0f,1.0f,1.0f) ); aColorOffset = nAttr.createColor("colorOffset", "co"); MAKE_INPUT(nAttr); aPlaceMat = mAttr.create("placementMatrix", "pm", MFnMatrixAttribute::kFloat); MAKE_INPUT(mAttr); // Implicit shading network attributes aPointWorld = nAttr.createPoint("pointWorld", "pw"); MAKE_INPUT(nAttr); CHECK_MSTATUS( nAttr.setHidden(true) ); // Create output attributes aOutF0 = nAttr.create( "F0", "f0", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); aOutF1 = nAttr.create( "F1", "f1", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); aOutN0 = nAttr.create( "N0", "n0", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); aOutBorderDist = nAttr.create("borderDistance", "bd", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); aOutColor = nAttr.createColor("outColor", "oc"); MAKE_OUTPUT(nAttr); aOutAlpha = nAttr.create( "outAlpha", "oa", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); // Add attributes to the node database. CHECK_MSTATUS( addAttribute(aColorGain) ); CHECK_MSTATUS( addAttribute(aColorOffset) ); CHECK_MSTATUS( addAttribute(aPointWorld) ); CHECK_MSTATUS( addAttribute(aPlaceMat) ); CHECK_MSTATUS( addAttribute(aOutAlpha) ); CHECK_MSTATUS( addAttribute(aOutColor) ); CHECK_MSTATUS( addAttribute(aOutF0) ); CHECK_MSTATUS( addAttribute(aOutF1) ); CHECK_MSTATUS( addAttribute(aOutN0) ); CHECK_MSTATUS( addAttribute(aOutBorderDist) ); // All input affect the output color and alpha CHECK_MSTATUS( attributeAffects (aColorGain, aOutColor) ); CHECK_MSTATUS( attributeAffects (aColorOffset, aOutColor) ); CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutColor) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutColor) ); CHECK_MSTATUS( attributeAffects (aColorGain, aOutAlpha) ); CHECK_MSTATUS( attributeAffects (aColorOffset, aOutAlpha) ); CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutAlpha) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutAlpha) ); // Geometry attribute affect all other outputs. CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutF0) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutF0) ); CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutF1) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutF1) ); CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutN0) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutN0) ); CHECK_MSTATUS( attributeAffects (aPlaceMat, aOutBorderDist) ); CHECK_MSTATUS( attributeAffects (aPointWorld, aOutBorderDist) ); return MS::kSuccess; }
// // Deform computation // MStatus jhMeshBlur::deform( MDataBlock& block,MItGeometry& iter,const MMatrix& m,unsigned int multiIndex) { MStatus returnStatus; // Envelope float envData = block.inputValue(envelope, &returnStatus).asFloat(); CHECK_MSTATUS(returnStatus); if(envData == 0) return MS::kFailure; /* VARIABLES */ //float factor = block.inputValue(aShapeFactor, &returnStatus).asFloat(); float fStrength = block.inputValue(aStrength, &returnStatus).asFloat(); CHECK_MSTATUS(returnStatus); if (fStrength == 0) return MS::kFailure; float fThreshold = block.inputValue(aTreshhold, &returnStatus).asFloat(); CHECK_MSTATUS(returnStatus); float fW = 0.0f; // weight float fDistance; fStrength *= envData; double dKracht = block.inputValue(aInterpPower, &returnStatus).asDouble(); CHECK_MSTATUS(returnStatus); double dDotProduct; // Dotproduct of the point bool bTweakblur = block.inputValue(aTweakBlur, &returnStatus).asBool(); CHECK_MSTATUS(returnStatus); bool bQuad = block.inputValue(aQuadInterp, &returnStatus).asBool(); CHECK_MSTATUS(returnStatus); MTime inTime = block.inputValue(aTime).asTime(); int nTijd = (int)inTime.as(MTime::kFilm); MFloatVectorArray currentNormals; // normals of mesh MFnPointArrayData fnPoints; // help converting to MPointArrays MFloatVector dirVector; // direction vector of the point MFloatVector normal; // normal of the point MPointArray savedPoints; // save all point before edited MMatrix matInv = m.inverse(); // inversed matrix MPoint ptA; // current point (iter mesh) MPoint ptB; // previous point (iter mesh) MPoint ptC; // mesh before previous point (iter mesh) // get node, use node to get inputGeom, use inputGeom to get mesh data, use mesh data to get normal data MFnDependencyNode nodeFn(this->thisMObject()); MPlug inGeomPlug(nodeFn.findPlug(this->inputGeom,true)); MObject inputObject(inGeomPlug.asMObject()); MFnMesh inMesh(inputObject); inMesh.getVertexNormals(true, currentNormals); // get the previous mesh data MPlug oldMeshPlug = nodeFn.findPlug(MString("oldMesh")); MPlug oldMeshPositionsAPlug = oldMeshPlug.elementByLogicalIndex((multiIndex*4) + 0); MPlug oldMeshPositionsBPlug = oldMeshPlug.elementByLogicalIndex((multiIndex*4) + 1); MPlug oldMeshPositionsCPlug = oldMeshPlug.elementByLogicalIndex((multiIndex*4) + 2); // cache for tweak mode MPlug oldMeshPositionsDPlug = oldMeshPlug.elementByLogicalIndex((multiIndex*4) + 3); // cache for tweak mode // convert to MPointArrays MObject objOldMeshA; MObject objOldMeshB; MObject objOldMeshC; // cache MObject objOldMeshD; // cache oldMeshPositionsAPlug.getValue(objOldMeshA); oldMeshPositionsBPlug.getValue(objOldMeshB); oldMeshPositionsCPlug.getValue(objOldMeshC); // cache oldMeshPositionsDPlug.getValue(objOldMeshD); // cache fnPoints.setObject(objOldMeshA); MPointArray oldMeshPositionsA = fnPoints.array(); fnPoints.setObject(objOldMeshB); MPointArray oldMeshPositionsB = fnPoints.array(); fnPoints.setObject(objOldMeshC); MPointArray oldMeshPositionsC = fnPoints.array(); // cache fnPoints.setObject(objOldMeshD); MPointArray oldMeshPositionsD = fnPoints.array(); // cache // If mesh position variables are empty,fill them with default values if(oldMeshPositionsA.length() == 0 || nTijd <= 1){ iter.allPositions(oldMeshPositionsA); for(int i=0; i < oldMeshPositionsA.length(); i++) { // convert to world oldMeshPositionsA[i] = oldMeshPositionsA[i] * m; } oldMeshPositionsB.copy(oldMeshPositionsA); oldMeshPositionsC.copy(oldMeshPositionsA); // cache oldMeshPositionsD.copy(oldMeshPositionsA); // cache } // get back old date again if (bTweakblur == true) { // restore cache oldMeshPositionsA.copy(oldMeshPositionsC); oldMeshPositionsB.copy(oldMeshPositionsD); } iter.allPositions(savedPoints); for(int i=0; i < savedPoints.length(); i++) { // convert points to world points savedPoints[i] = savedPoints[i] * m; } // Actual Iteration through points for (; !iter.isDone(); iter.next()){ // get current position ptA = iter.position(); // get old positions ptB = oldMeshPositionsA[iter.index()] * matInv; ptC = oldMeshPositionsB[iter.index()] * matInv; fDistance = ptA.distanceTo(ptB); fW = weightValue(block,multiIndex,iter.index()); if (fDistance * (fStrength*fW) < fThreshold && fThreshold > 0){ iter.setPosition(ptA); } else { // aim/direction vector to calculate strength dirVector = (ptA - ptB); // (per punt) dirVector.normalize(); normal = currentNormals[iter.index()]; dDotProduct = normal.x * dirVector.x + normal.y * dirVector.y + normal.z * dirVector.z; if(bQuad == true){ MVector vecA(((ptB - ptC) + (ptA - ptB)) / 2); vecA.normalize(); MPoint hiddenPt(ptB + (vecA * fDistance) * dKracht); ptA = quadInterpBetween(ptB, hiddenPt, ptA, (1 - fStrength * fW) + (linearInterp(dDotProduct, -1, 1) * (fStrength * fW) ) ); } else { MPoint halfway = (ptA - ptB) * 0.5; MPoint offset = halfway * dDotProduct * (fStrength*fW); ptA = ptA - ((halfway * (fStrength*fW)) - offset); // + (offset * strength); } // set new value iter.setPosition(ptA); } } if(bTweakblur == false){ oldMeshPositionsD.copy(oldMeshPositionsB); oldMeshPositionsC.copy(oldMeshPositionsA); oldMeshPositionsB.copy(oldMeshPositionsA); oldMeshPositionsA.copy(savedPoints); // Save back to plugs objOldMeshA = fnPoints.create(oldMeshPositionsA); objOldMeshB = fnPoints.create(oldMeshPositionsB); objOldMeshC = fnPoints.create(oldMeshPositionsC); objOldMeshD = fnPoints.create(oldMeshPositionsD); oldMeshPositionsAPlug.setValue(objOldMeshA); oldMeshPositionsBPlug.setValue(objOldMeshB); oldMeshPositionsCPlug.setValue(objOldMeshC); oldMeshPositionsDPlug.setValue(objOldMeshD); } return returnStatus; }
// The initialize routine is called after the node has been created. // It sets up the input and output attributes and adds them to the node. // Finally the dependencies are arranged so that when the inputs // change Maya knowns to call compute to recalculate the output values. // MStatus hwColorPerVertexShader::initialize() { MFnNumericAttribute nAttr; MFnTypedAttribute tAttr; MStatus status; // Create input attributes. // All attributes are cached internal // aColorGain = nAttr.createColor( "colorGain", "cg", &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(1.f, 1.f, 1.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aTranspGain = nAttr.create("transparencyGain", "tg", MFnNumericData::kFloat, 1.f, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(1.f)); CHECK_MSTATUS( nAttr.setSoftMin(0.f)); CHECK_MSTATUS( nAttr.setSoftMax(2.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aColorBias = nAttr.createColor( "colorBias", "cb", &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(0.f, 0.f, 0.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aTranspBias = nAttr.create( "transparencyBias", "tb", MFnNumericData::kFloat, 0.f, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(0.f)); CHECK_MSTATUS( nAttr.setSoftMin(-1.f)); CHECK_MSTATUS( nAttr.setSoftMax(1.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aNormalsPerVertex = nAttr.create("normalsPerVertex", "nv", MFnNumericData::kInt, 0, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(false)); CHECK_MSTATUS( nAttr.setDefault(0)); CHECK_MSTATUS( nAttr.setSoftMin(0)); CHECK_MSTATUS( nAttr.setSoftMax(3)); nAttr.setCached( true ); nAttr.setInternal( true ); aColorsPerVertex = nAttr.create("colorsPerVertex", "cv", MFnNumericData::kInt, 0, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(false)); CHECK_MSTATUS( nAttr.setDefault(0)); CHECK_MSTATUS( nAttr.setSoftMin(0)); CHECK_MSTATUS( nAttr.setSoftMax(5)); nAttr.setCached( true ); nAttr.setInternal( true ); aColorSetName = tAttr.create("colorSetName", "cs", MFnData::kString, MObject::kNullObj, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( tAttr.setStorable(true)); CHECK_MSTATUS( tAttr.setKeyable(false)); tAttr.setCached( true ); tAttr.setInternal( true ); aTexRotateX = nAttr.create( "texRotateX", "tx", MFnNumericData::kFloat, 0.f, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(0.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aTexRotateY = nAttr.create( "texRotateY", "ty", MFnNumericData::kFloat, 0.f, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(0.f)); nAttr.setCached( true ); nAttr.setInternal( true ); aTexRotateZ = nAttr.create( "texRotateZ", "tz", MFnNumericData::kFloat, 0.f, &status); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable(true)); CHECK_MSTATUS( nAttr.setKeyable(true)); CHECK_MSTATUS( nAttr.setDefault(0.f)); nAttr.setCached( true ); nAttr.setInternal( true ); // create output attributes here // outColor is the only output attribute and it is inherited // so we do not need to create or add it. // // Add the attributes here CHECK_MSTATUS( addAttribute(aColorGain)); CHECK_MSTATUS( addAttribute(aTranspGain)); CHECK_MSTATUS( addAttribute(aColorBias)); CHECK_MSTATUS( addAttribute(aTranspBias)); CHECK_MSTATUS( addAttribute(aNormalsPerVertex)); CHECK_MSTATUS( addAttribute(aColorsPerVertex)); CHECK_MSTATUS( addAttribute(aColorSetName)); CHECK_MSTATUS( addAttribute(aTexRotateX)); CHECK_MSTATUS( addAttribute(aTexRotateY)); CHECK_MSTATUS( addAttribute(aTexRotateZ)); CHECK_MSTATUS( attributeAffects (aColorGain, outColor)); CHECK_MSTATUS( attributeAffects (aTranspGain, outColor)); CHECK_MSTATUS( attributeAffects (aColorBias, outColor)); CHECK_MSTATUS( attributeAffects (aTranspBias, outColor)); CHECK_MSTATUS( attributeAffects (aNormalsPerVertex, outColor)); CHECK_MSTATUS( attributeAffects (aColorsPerVertex, outColor)); CHECK_MSTATUS( attributeAffects (aColorSetName, outColor)); CHECK_MSTATUS( attributeAffects (aTexRotateX, outColor)); CHECK_MSTATUS( attributeAffects (aTexRotateY, outColor)); CHECK_MSTATUS( attributeAffects (aTexRotateZ, outColor)); return MS::kSuccess; }
MStatus retargetLocator::initialize() { MFnNumericAttribute nAttr; MFnMatrixAttribute mAttr; MFnEnumAttribute eAttr; MFnUnitAttribute uAttr; MFnCompoundAttribute cAttr; MFnTypedAttribute tAttr; aOutput = nAttr.create( "output", "output", MFnNumericData::kDouble ); nAttr.setStorable( false ); CHECK_MSTATUS( addAttribute( aOutput ) ); aDiscMatrix = mAttr.create( "discMatrix", "discMatrix" ); mAttr.setStorable( true ); CHECK_MSTATUS( addAttribute( aDiscMatrix ) ); CHECK_MSTATUS( attributeAffects( aDiscMatrix, aOutput ) ); aDiscAxis = eAttr.create( "discAxis", "discAxis", 0 ); eAttr.addField( "X", 0 ); eAttr.addField( "Y", 1 ); eAttr.addField( "Z", 2 ); eAttr.setStorable( true ); eAttr.setChannelBox( true ); eAttr.setReadable( true ); CHECK_MSTATUS( addAttribute( aDiscAxis ) ); CHECK_MSTATUS( attributeAffects( aDiscAxis, aOutput ) ); aDiscDivision = nAttr.create( "discDivision", "discDivision", MFnNumericData::kInt, 32 ); nAttr.setMin( 1 ); nAttr.setMax( 32 ); nAttr.setStorable( true ); nAttr.setChannelBox( true ); CHECK_MSTATUS( addAttribute( aDiscDivision ) ); CHECK_MSTATUS( attributeAffects( aDiscDivision, aOutput ) ); aDiscAngle = uAttr.create( "discAngle", "discAngle", MFnUnitAttribute::kAngle, 0.0 ); uAttr.setStorable( true ); uAttr.setChannelBox( true ); CHECK_MSTATUS( addAttribute( aDiscAngle ) ); CHECK_MSTATUS( attributeAffects( aDiscAngle, aOutput ) ); aDiscOffsetX = nAttr.create( "discOffsetX", "discOffsetX", MFnNumericData::kDouble, 0.0 ); aDiscOffsetY = nAttr.create( "discOffsetY", "discOffsetY", MFnNumericData::kDouble, 0.0 ); aDiscOffsetZ = nAttr.create( "discOffsetZ", "discOffsetZ", MFnNumericData::kDouble, 0.0 ); aDiscOffset = nAttr.create( "discOffset", "discOffset", aDiscOffsetX, aDiscOffsetY, aDiscOffsetZ ); uAttr.setStorable( true ); uAttr.setChannelBox( true ); CHECK_MSTATUS( addAttribute( aDiscOffset ) ); CHECK_MSTATUS( attributeAffects( aDiscOffset, aOutput ) ); aDiscSizeX = nAttr.create( "discSizeX", "discSizeX", MFnNumericData::kDouble, 1.0 ); aDiscSizeY = nAttr.create( "discSizeY", "discSizeY", MFnNumericData::kDouble, 1.0 ); aDiscSizeZ = nAttr.create( "discSizeZ", "discSizeZ", MFnNumericData::kDouble, 1.0 ); aDiscSize = nAttr.create( "discSize", "discSize", aDiscSizeX, aDiscSizeY, aDiscSizeZ ); uAttr.setStorable( true ); uAttr.setChannelBox( true ); CHECK_MSTATUS( addAttribute( aDiscSize ) ); CHECK_MSTATUS( attributeAffects( aDiscSize, aOutput ) ); aDiscActiveColor = nAttr.createColor( "discActiveColor", "discActiveColor" ); nAttr.setStorable( true ); nAttr.setUsedAsColor(true); nAttr.setDefault(1.0f, 1.0f, 1.0f); CHECK_MSTATUS( addAttribute( aDiscActiveColor ) ); CHECK_MSTATUS( attributeAffects( aDiscActiveColor, aOutput ) ); aDiscLeadColor = nAttr.createColor( "discLeadColor", "discLeadColor" ); nAttr.setStorable( true ); nAttr.setUsedAsColor(true); nAttr.setDefault(.263f, 1.0f, .639f); CHECK_MSTATUS( addAttribute( aDiscLeadColor ) ); CHECK_MSTATUS( attributeAffects( aDiscLeadColor, aOutput ) ); aDiscDefaultColor = nAttr.createColor( "discDefaultColor", "discDefaultColor" ); nAttr.setStorable( true ); nAttr.setUsedAsColor(true); nAttr.setDefault(.0f, .016f, .376f); CHECK_MSTATUS( addAttribute( aDiscDefaultColor ) ); CHECK_MSTATUS( attributeAffects( aDiscDefaultColor, aOutput ) ); aDiscFillAlpha = nAttr.create( "discFillAlpha", "discFillAlpha", MFnNumericData::kFloat, 0.1f ); nAttr.setStorable( true ); nAttr.setMin( 0.0f ); nAttr.setMax( 1.0f ); CHECK_MSTATUS( addAttribute( aDiscFillAlpha ) ); CHECK_MSTATUS( attributeAffects( aDiscFillAlpha, aOutput ) ); aDiscLineAlpha = nAttr.create( "discLineAlpha", "discLineAlpha", MFnNumericData::kFloat, 1.0f ); nAttr.setStorable( true ); nAttr.setMin( 0.0f ); nAttr.setMax( 1.0f ); CHECK_MSTATUS( addAttribute( aDiscLineAlpha ) ); CHECK_MSTATUS( attributeAffects( aDiscLineAlpha, aOutput ) ); aArrow = cAttr.create( "arrow", "arrow" ); aInheritMatrix = nAttr.create( "inheritMatrix", "inheritMatrix", MFnNumericData::kBoolean, false ); aInputMesh = tAttr.create( "inputMesh", "inputMesh", MFnData::kMesh ); aAimMatrix = mAttr.create( "aimMatrix", "aimMatrix" ); aStartSize = nAttr.create( "startSize", "startSize", MFnNumericData::kFloat, 0.5f ); aSize = nAttr.create( "size", "size", MFnNumericData::kFloat, 1.0f ); aActiveColor = nAttr.createColor( "activeColor", "activeColor" ); nAttr.setUsedAsColor(true); nAttr.setDefault(1.0f, 1.0f, 1.0f); aLeadColor = nAttr.createColor( "leadColor", "leadColor" ); nAttr.setUsedAsColor(true); nAttr.setDefault(.263f, 1.0f, .639f); aDefaultColor = nAttr.createColor( "defaultColor", "defaultColor" ); nAttr.setUsedAsColor(true); nAttr.setDefault(.0f, .016f, .376f); aFillAlpha = nAttr.create( "fillAlpha", "fillAlpha", MFnNumericData::kFloat, 0.1f ); aLineAlpha = nAttr.create( "lineAlpha", "lineAlpha", MFnNumericData::kFloat, 1.0f ); aOffsetX = nAttr.create( "offsetX", "offsetX", MFnNumericData::kDouble, 0.0 ); aOffsetY = nAttr.create( "offsetY", "offsetY", MFnNumericData::kDouble, 0.0 ); aOffsetZ = nAttr.create( "offsetZ", "offsetZ", MFnNumericData::kDouble, 0.0 ); aOffset = nAttr.create( "offset", "offset", aOffsetX, aOffsetY, aOffsetZ ); cAttr.addChild( aInheritMatrix ); cAttr.addChild( aAimMatrix ); cAttr.addChild( aInputMesh ); cAttr.addChild( aStartSize ); cAttr.addChild( aSize ); cAttr.addChild( aActiveColor ); cAttr.addChild( aLeadColor ); cAttr.addChild( aDefaultColor ); cAttr.addChild( aFillAlpha ); cAttr.addChild( aLineAlpha ); cAttr.addChild( aOffset ); cAttr.setArray( true ); cAttr.setStorable( true ); CHECK_MSTATUS( addAttribute( aArrow ) ); CHECK_MSTATUS( attributeAffects( aArrow, aOutput ) ); return MS::kSuccess; }
void MayaObject::getMeshData(MPointArray& points, MFloatVectorArray& normals, MFloatArray& uArray, MFloatArray& vArray, MIntArray& triPointIndices, MIntArray& triNormalIndices, MIntArray& triUvIndices, MIntArray& triMatIndices) { MStatus stat; MObject meshObject = this->mobject; MMeshSmoothOptions options; MFnMesh tmpMesh(this->mobject, &stat); MFnMeshData meshData; MObject dataObject; MObject smoothedObj; // create smooth mesh if needed if (tmpMesh.findPlug("displaySmoothMesh").asBool()) { stat = tmpMesh.getSmoothMeshDisplayOptions(options); if (stat) { if (!tmpMesh.findPlug("useSmoothPreviewForRender", false, &stat).asBool()) { //Logging::debug(MString("useSmoothPreviewForRender turned off")); int smoothLevel = tmpMesh.findPlug("renderSmoothLevel", false, &stat).asInt(); options.setDivisions(smoothLevel); } if (options.divisions() > 0) { dataObject = meshData.create(); smoothedObj = tmpMesh.generateSmoothMesh(dataObject, &options, &stat); if (stat) { meshObject = smoothedObj; } } } } MFnMesh meshFn(meshObject, &stat); CHECK_MSTATUS(stat); MItMeshPolygon faceIt(meshObject, &stat); CHECK_MSTATUS(stat); meshFn.getPoints(points); meshFn.getNormals(normals, MSpace::kObject); meshFn.getUVs(uArray, vArray); uint numVertices = points.length(); uint numNormals = normals.length(); uint numUvs = uArray.length(); //Logging::debug(MString("numVertices ") + numVertices); //Logging::debug(MString("numNormals ") + numNormals); //Logging::debug(MString("numUvs ") + numUvs); // some meshes may have no uv's // to avoid problems I add a default uv coordinate if (numUvs == 0) { Logging::warning(MString("Object has no uv's: ") + this->shortName); uArray.append(0.0); vArray.append(0.0); } for (uint nid = 0; nid < numNormals; nid++) { if (normals[nid].length() < 0.1f) Logging::warning(MString("Malformed normal in ") + this->shortName); } MPointArray triPoints; MIntArray triVtxIds; MIntArray faceVtxIds; MIntArray faceNormalIds; for (faceIt.reset(); !faceIt.isDone(); faceIt.next()) { int faceId = faceIt.index(); int numTris; faceIt.numTriangles(numTris); faceIt.getVertices(faceVtxIds); int perFaceShadingGroup = 0; if (this->perFaceAssignments.length() > 0) perFaceShadingGroup = this->perFaceAssignments[faceId]; MIntArray faceUVIndices; faceNormalIds.clear(); for (uint vtxId = 0; vtxId < faceVtxIds.length(); vtxId++) { faceNormalIds.append(faceIt.normalIndex(vtxId)); int uvIndex; if (numUvs == 0) { faceUVIndices.append(0); } else{ faceIt.getUVIndex(vtxId, uvIndex); //if (uvIndex > uArray.length()) // Logging::info(MString("-----------------> UV Problem!!! uvIndex ") + uvIndex + " > uvArray in object " + this->shortName); faceUVIndices.append(uvIndex); } } for (int triId = 0; triId < numTris; triId++) { int faceRelIds[3]; faceIt.getTriangle(triId, triPoints, triVtxIds); for (uint triVtxId = 0; triVtxId < 3; triVtxId++) { for (uint faceVtxId = 0; faceVtxId < faceVtxIds.length(); faceVtxId++) { if (faceVtxIds[faceVtxId] == triVtxIds[triVtxId]) { faceRelIds[triVtxId] = faceVtxId; } } } uint vtxId0 = faceVtxIds[faceRelIds[0]]; uint vtxId1 = faceVtxIds[faceRelIds[1]]; uint vtxId2 = faceVtxIds[faceRelIds[2]]; uint normalId0 = faceNormalIds[faceRelIds[0]]; uint normalId1 = faceNormalIds[faceRelIds[1]]; uint normalId2 = faceNormalIds[faceRelIds[2]]; uint uvId0 = faceUVIndices[faceRelIds[0]]; uint uvId1 = faceUVIndices[faceRelIds[1]]; uint uvId2 = faceUVIndices[faceRelIds[2]]; triPointIndices.append(vtxId0); triPointIndices.append(vtxId1); triPointIndices.append(vtxId2); triNormalIndices.append(normalId0); triNormalIndices.append(normalId1); triNormalIndices.append(normalId2); triUvIndices.append(uvId0); triUvIndices.append(uvId1); triUvIndices.append(uvId2); triMatIndices.append(perFaceShadingGroup); //Logging::debug(MString("vtxIds ") + vtxId0 + " " + vtxId1 + " " + vtxId2); //Logging::debug(MString("nIds ") + normalId0 + " " + normalId1 + " " + normalId2); //Logging::debug(MString("uvIds ") + uvId0 + " " + uvId1 + " " + uvId2); } } }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus PhongNode::initialize() { MFnNumericAttribute nAttr; MFnLightDataAttribute lAttr; aTranslucenceCoeff = nAttr.create("translucenceCoeff", "tc", MFnNumericData::kFloat); MAKE_INPUT(nAttr); aDiffuseReflectivity = nAttr.create("diffuseReflectivity", "drfl", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(0.8f) ); aColor = nAttr.createColor( "color", "c" ); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(0.0f, 0.58824f, 0.644f) ); aIncandescence = nAttr.createColor( "incandescence", "ic" ); MAKE_INPUT(nAttr); aOutColor = nAttr.createColor( "outColor", "oc" ); MAKE_OUTPUT(nAttr); aPointCamera = nAttr.createPoint( "pointCamera", "pc" ); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); aPower = nAttr.create( "power", "pow", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setMin(0.0f) ); CHECK_MSTATUS ( nAttr.setMax(200.0f) ); CHECK_MSTATUS ( nAttr.setDefault(10.0f) ); aSpecularity = nAttr.create( "specularity", "spc", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setMin(0.0f) ); CHECK_MSTATUS ( nAttr.setMax(1.0f) ) ; CHECK_MSTATUS ( nAttr.setDefault(0.5f) ); aReflectGain = nAttr.create( "reflectionGain", "rg", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setMin(0.0f) ); CHECK_MSTATUS ( nAttr.setMax(1.0f) ); CHECK_MSTATUS ( nAttr.setDefault(0.5f) ); aNormalCamera = nAttr.createPoint( "normalCamera", "n" ); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); aTriangleNormalCamera = nAttr.createPoint( "triangleNormalCamera", "tn" ); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f)); CHECK_MSTATUS ( nAttr.setHidden(true)); aLightDirection = nAttr.createPoint( "lightDirection", "ld" ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); aLightIntensity = nAttr.createColor( "lightIntensity", "li" ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); aLightAmbient = nAttr.create( "lightAmbient", "la", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightSpecular = nAttr.create( "lightSpecular", "ls", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightShadowFraction = nAttr.create("lightShadowFraction", "lsf", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aPreShadowIntensity = nAttr.create("preShadowIntensity", "psi", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightBlindData = nAttr.createAddr("lightBlindData", "lbld"); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightData = lAttr.create( "lightDataArray", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData); CHECK_MSTATUS ( lAttr.setArray(true) ); CHECK_MSTATUS ( lAttr.setStorable(false) ); CHECK_MSTATUS ( lAttr.setHidden(true) ); CHECK_MSTATUS ( lAttr.setDefault(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, false, 0.0f, 1.0f, NULL) ); // rayOrigin MObject RayX = nAttr.create( "rayOx", "rxo", MFnNumericData::kFloat, 0.0 ); MObject RayY = nAttr.create( "rayOy", "ryo", MFnNumericData::kFloat, 0.0 ); MObject RayZ = nAttr.create( "rayOz", "rzo", MFnNumericData::kFloat, 0.0 ); aRayOrigin = nAttr.create( "rayOrigin", "rog", RayX, RayY, RayZ ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(false) ); // rayDirection RayX = nAttr.create( "rayDirectionX", "rdx", MFnNumericData::kFloat, 1.0 ); RayY = nAttr.create( "rayDirectionY", "rdy", MFnNumericData::kFloat, 0.0 ); RayZ = nAttr.create( "rayDirectionZ", "rdz", MFnNumericData::kFloat, 0.0 ); aRayDirection = nAttr.create( "rayDirection", "rad", RayX, RayY, RayZ ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(false) ); // objectId aObjectId = nAttr.createAddr( "objectId", "oi" ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(false) ); // raySampler aRaySampler = nAttr.createAddr("raySampler", "rtr"); CHECK_MSTATUS ( nAttr.setStorable(false)); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(false) ); // rayDepth aRayDepth = nAttr.create( "rayDepth", "rd", MFnNumericData::kShort, 0.0 ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS (nAttr.setHidden(true) ) ; CHECK_MSTATUS ( nAttr.setReadable(false) ); CHECK_MSTATUS ( addAttribute(aTranslucenceCoeff) ); CHECK_MSTATUS ( addAttribute(aDiffuseReflectivity) ); CHECK_MSTATUS ( addAttribute(aColor) ); CHECK_MSTATUS ( addAttribute(aIncandescence) ); CHECK_MSTATUS ( addAttribute(aPointCamera) ); CHECK_MSTATUS ( addAttribute(aNormalCamera) ); CHECK_MSTATUS ( addAttribute(aTriangleNormalCamera) ); CHECK_MSTATUS ( addAttribute(aLightData) ); CHECK_MSTATUS ( addAttribute(aPower) ); CHECK_MSTATUS ( addAttribute(aSpecularity) ); CHECK_MSTATUS ( addAttribute(aOutColor) ); CHECK_MSTATUS ( addAttribute(aRayOrigin) ); CHECK_MSTATUS ( addAttribute(aRayDirection) ); CHECK_MSTATUS ( addAttribute(aObjectId) ); CHECK_MSTATUS ( addAttribute(aRaySampler) ); CHECK_MSTATUS ( addAttribute(aRayDepth) ); CHECK_MSTATUS ( addAttribute(aReflectGain) ); CHECK_MSTATUS ( attributeAffects (aTranslucenceCoeff, aOutColor)); CHECK_MSTATUS ( attributeAffects (aDiffuseReflectivity, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightIntensity, aOutColor)); CHECK_MSTATUS ( attributeAffects (aIncandescence, aOutColor)); CHECK_MSTATUS ( attributeAffects (aPointCamera, aOutColor)); CHECK_MSTATUS ( attributeAffects (aNormalCamera, aOutColor)); CHECK_MSTATUS ( attributeAffects (aTriangleNormalCamera, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightData, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightAmbient, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightSpecular, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightDiffuse, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightDirection, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightShadowFraction, aOutColor)); CHECK_MSTATUS ( attributeAffects (aPreShadowIntensity, aOutColor)); CHECK_MSTATUS ( attributeAffects (aLightBlindData, aOutColor)); CHECK_MSTATUS ( attributeAffects (aPower, aOutColor)); CHECK_MSTATUS ( attributeAffects (aSpecularity, aOutColor)); CHECK_MSTATUS ( attributeAffects (aColor, aOutColor)); CHECK_MSTATUS ( attributeAffects (aRayOrigin,aOutColor)); CHECK_MSTATUS ( attributeAffects (aRayDirection,aOutColor)); CHECK_MSTATUS ( attributeAffects (aObjectId,aOutColor)); CHECK_MSTATUS ( attributeAffects (aRaySampler,aOutColor)); CHECK_MSTATUS ( attributeAffects (aRayDepth,aOutColor)); CHECK_MSTATUS ( attributeAffects (aReflectGain,aOutColor) ); return MS::kSuccess; }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus CheckerNode::initialize() { MFnNumericAttribute nAttr; // Input attributes aColor1 = nAttr.createColor("color1", "c1"); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setDefault(0., .58824, .644) ); // Light blue aColor2 = nAttr.createColor("color2", "c2"); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setDefault(1., 1., 1.) ); // White aBias = nAttr.create( "bias", "b", MFnNumericData::k2Float); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setMin(0.0f, 0.0f) ); CHECK_MSTATUS(nAttr.setMax(1.0f, 1.0f) ); CHECK_MSTATUS(nAttr.setDefault(0.5f, 0.5f) ); // Implicit shading network attributes MObject child1 = nAttr.create( "uCoord", "u", MFnNumericData::kFloat); MObject child2 = nAttr.create( "vCoord", "v", MFnNumericData::kFloat); aUVCoord = nAttr.create( "uvCoord","uv", child1, child2); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setHidden(true) ); // Output attributes aOutColor = nAttr.createColor("outColor", "oc"); MAKE_OUTPUT(nAttr); aOutAlpha = nAttr.create( "outAlpha", "oa", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); // Add attributes to the node database. CHECK_MSTATUS(addAttribute(aColor1)); CHECK_MSTATUS(addAttribute(aColor2)); CHECK_MSTATUS(addAttribute(aBias)); CHECK_MSTATUS(addAttribute(aUVCoord)); CHECK_MSTATUS(addAttribute(aOutColor)); CHECK_MSTATUS(addAttribute(aOutAlpha)); // All input affect the output color and alpha CHECK_MSTATUS(attributeAffects (aColor1, aOutColor)); CHECK_MSTATUS(attributeAffects(aColor1, aOutAlpha)); CHECK_MSTATUS(attributeAffects (aColor2, aOutColor)); CHECK_MSTATUS(attributeAffects(aColor2, aOutAlpha)); CHECK_MSTATUS(attributeAffects(aBias, aOutColor)); CHECK_MSTATUS(attributeAffects(aBias, aOutAlpha)); CHECK_MSTATUS(attributeAffects (aUVCoord, aOutColor)); CHECK_MSTATUS(attributeAffects(aUVCoord, aOutAlpha)); return MS::kSuccess; }
MStatus initializePlugin( MObject obj) { MStatus status; MFnPlugin plugin(obj, "Pixar", "1.0", "Any"); // we use lambdas to pass in MCreatorFunctions into the various Maya registration // functions so that we can specify the static data that the registered // shape/data/node should be using. status = plugin.registerData( _data.stageData.typeName, _data.stageData.typeId, []() { return UsdMayaStageData::creator(_data.stageData); }); CHECK_MSTATUS(status); status = plugin.registerShape( _data.proxyShape.typeName, _data.proxyShape.typeId, []() { return UsdMayaProxyShape::creator(_data.proxyShape); }, []() { return UsdMayaProxyShape::initialize( &(_data.proxyShape)); }, UsdMayaProxyShapeUI::creator, &UsdMayaProxyDrawOverride::sm_drawDbClassification); CHECK_MSTATUS(status); status = plugin.registerNode( _data.referenceAssembly.typeName, _data.referenceAssembly.typeId, []() { return UsdMayaReferenceAssembly::creator( _data.referenceAssembly); }, []() { return UsdMayaReferenceAssembly::initialize( &(_data.referenceAssembly)); }, MPxNode::kAssembly, &UsdMayaReferenceAssembly::_classification); CHECK_MSTATUS(status); status = MHWRender::MDrawRegistry::registerDrawOverrideCreator( UsdMayaProxyDrawOverride::sm_drawDbClassification, UsdMayaProxyDrawOverride::sm_drawRegistrantId, UsdMayaProxyDrawOverride::Creator); CHECK_MSTATUS(status); status = MGlobal::sourceFile("usdMaya.mel"); CHECK_MSTATUS(status); // Set the label for the assembly node type so that it appears correctly // in the 'Create -> Scene Assembly' menu. const MString assemblyTypeLabel("UsdReferenceAssembly"); MString setLabelCmd; status = setLabelCmd.format("assembly -e -type ^1s -label ^2s", _data.referenceAssembly.typeName, assemblyTypeLabel); CHECK_MSTATUS(status); status = MGlobal::executeCommand(setLabelCmd); CHECK_MSTATUS(status); // Procs stored in usdMaya.mel // Add assembly callbacks for accessing data without creating an MPxAssembly instance status = MGlobal::executeCommand("assembly -e -repTypeLabelProc usdMaya_UsdMayaReferenceAssembly_repTypeLabel -type " + _data.referenceAssembly.typeName); CHECK_MSTATUS(status); status = MGlobal::executeCommand("assembly -e -listRepTypesProc usdMaya_UsdMayaReferenceAssembly_listRepTypes -type " + _data.referenceAssembly.typeName); CHECK_MSTATUS(status); // Attribute Editor Templates // XXX: The try/except here is temporary until we change the Pixar-internal // package name to match the external package name. MString attribEditorCmd( "try:\n" " from pxr.UsdMaya import AEpxrUsdReferenceAssemblyTemplate\n" "except ImportError:\n" " from pixar.UsdMaya import AEpxrUsdReferenceAssemblyTemplate\n" "AEpxrUsdReferenceAssemblyTemplate.addMelFunctionStubs()"); status = MGlobal::executePythonCommand(attribEditorCmd); CHECK_MSTATUS(status); status = plugin.registerCommand("usdExport", usdExport::creator, usdExport::createSyntax ); if (!status) { status.perror("registerCommand usdExport"); } status = plugin.registerCommand("usdImport", []() { return usdImport::creator(_data.referenceAssembly.typeName.asChar(), _data.proxyShape.typeName.asChar()); }, usdImport::createSyntax ); if (!status) { status.perror("registerCommand usdImport"); } status = plugin.registerCommand("usdListShadingModes", usdListShadingModes::creator, usdListShadingModes::createSyntax); if (!status) { status.perror("registerCommand usdListShadingModes"); } status = plugin.registerFileTranslator("pxrUsdImport", "", []() { return usdTranslatorImport::creator( _data.referenceAssembly.typeName.asChar(), _data.proxyShape.typeName.asChar()); }, "usdTranslatorImport", // options script name const_cast<char*>(usdTranslatorImportDefaults), false); if (!status) { status.perror("pxrUsd: unable to register USD Import translator."); } status = plugin.registerFileTranslator("pxrUsdExport", "", usdTranslatorExport::creator, "usdTranslatorExport", // options script name const_cast<char*>(usdTranslatorExportDefaults), true); if (!status) { status.perror("pxrUsd: unable to register USD Export translator."); } return status; }
MStatus TestDeformer::initialize() { MFnNumericAttribute numericAttr; MFnTypedAttribute polyMeshAttr; MFnEnumAttribute enumAttr; MStatus status; // Status will be used to hold the MStatus value // vertSnapInput driver_mesh = polyMeshAttr.create( "vertSnapInput", "vsnpin", MFnData::kMesh, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( polyMeshAttr.setStorable( false ) ); CHECK_MSTATUS( polyMeshAttr.setArray(true) ); CHECK_MSTATUS( polyMeshAttr.setConnectable( true ) ); CHECK_MSTATUS( addAttribute(driver_mesh) ); CHECK_MSTATUS( attributeAffects(driver_mesh, outputGeom) ); // initialize is used to mark this node's state initialized_data = enumAttr.create( "initialize", "inl", 0/*default*/, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( enumAttr.addField( "Off", 0) ); CHECK_MSTATUS( enumAttr.addField( "Re-Set Bind", 1) ); CHECK_MSTATUS( enumAttr.addField( "Bound", 2) ); CHECK_MSTATUS( enumAttr.setKeyable(true) ); CHECK_MSTATUS( enumAttr.setStorable(true) ); CHECK_MSTATUS( enumAttr.setReadable(true) ); CHECK_MSTATUS( enumAttr.setWritable(true) ); CHECK_MSTATUS( enumAttr.setDefault(0) ); CHECK_MSTATUS( addAttribute( initialized_data ) ); CHECK_MSTATUS( attributeAffects( initialized_data, outputGeom ) ); // hold the vertex index mapping vert_map = numericAttr.create( "vtxIndexMap", "vtximp", MFnNumericData::kLong, 0/*default*/, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( numericAttr.setKeyable(false) ); CHECK_MSTATUS( numericAttr.setArray(true) ); CHECK_MSTATUS( numericAttr.setStorable(true) ); CHECK_MSTATUS( numericAttr.setReadable(true) ); CHECK_MSTATUS( numericAttr.setWritable(true) ); CHECK_MSTATUS( addAttribute( vert_map ) ); CHECK_MSTATUS( attributeAffects( vert_map, outputGeom ) ); CHECK_MSTATUS( MGlobal::executePythonCommand("import maya.cmds; maya.cmds.makePaintable('"+TestDeformer::cTypeName()+"', 'weights', attrType='multiFloat')") ); return( MS::kSuccess ); }
void TestDeformer::_deform_on_one_mesh(MDataBlock& data, MItGeometry& iter, const MMatrix& localToWorldMatrix, unsigned int mIndex, MObject &driver_mesh, const MDataHandle &envelopeHandle, MArrayDataHandle &vertMapArrayData, MPointArray &tempOutputPts) { MStatus status; float env = envelopeHandle.asFloat(); // use driver_meshVertIter to walk through the vertex of the current driver mesh MItMeshVertex driver_meshVertIter( driver_mesh, &status ); CHECK_MSTATUS( status ); int i = 0; iter.reset(); while( !iter.isDone(&status) ) { CHECK_MSTATUS( status ); // get the weight float weight = weightValue( data, mIndex, iter.index() ); //painted weight float ww = weight * env; if ( fabs(ww) > FLT_EPSILON )//if ( ww != 0 ) { __debug("%s(), vertMapArrayData.elementCount()=%d, iter.index()=%d", __FUNCTION__, vertMapArrayData.elementCount(), iter.index()); // get index_mapped to which the currrent vertex vI is mapped CHECK_MSTATUS(vertMapArrayData.jumpToElement(iter.index())); int index_mapped = vertMapArrayData.inputValue(&status).asInt(); CHECK_MSTATUS( status ); if( index_mapped >= 0 ) { __debug("index_mapped=%d", index_mapped); int prevInt; CHECK_MSTATUS( driver_meshVertIter.setIndex(index_mapped, prevInt) ); // vertex wrold position on driver mesh MPoint mappedPt = driver_meshVertIter.position( MSpace::kWorld, &status ); CHECK_MSTATUS( status ); // vertex wrold position on driven mesh MPoint iterPt = iter.position(MSpace::kObject, &status) * localToWorldMatrix; CHECK_MSTATUS( status ); // use ww to interpolate between mappedPt and iterPt MPoint pt = iterPt + ((mappedPt - iterPt) * ww ); pt = pt * localToWorldMatrix.inverse(); /// put the deform points to tempOutputPts tempOutputPts[i] += pt; } }//if CHECK_MSTATUS(iter.next()); ++i; }//while }
void TestDeformer::initVertMapping(MDataBlock& data, MItGeometry& iter, const MMatrix& localToWorldMatrix, unsigned int mIndex) { MStatus status; MArrayDataHandle vertMapOutArrayData = data.outputArrayValue( vert_map, &status ); CHECK_MSTATUS( status ); // use vertMapOutArrayBuilder to modify vertMapOutArrayData iter.reset(); int count = iter.count(); MArrayDataBuilder vertMapOutArrayBuilder( vert_map, count, &status ); CHECK_MSTATUS( status ); MPointArray allPts;// world vertex position of the driven mesh allPts.clear(); // walk through the driven mesh /// copy MItGeometry's vertex to vertMapOutArrayData int i = 0; while( !iter.isDone(&status) ) { CHECK_MSTATUS( status ); MDataHandle initIndexDataHnd = vertMapOutArrayBuilder.addElement( i, &status ); CHECK_MSTATUS( status ); int negIndex = -1; initIndexDataHnd.setInt( negIndex ); initIndexDataHnd.setClean(); // append a vertex position(world coordination) to allPts CHECK_MSTATUS(allPts.append( iter.position() * localToWorldMatrix )); i = i+1; iter.next(); } CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder )); /// Append more vertex from each driver mesh to vertMapOutArrayData MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status ); CHECK_MSTATUS( status ); int numMeshes = meshAttrHandle.elementCount(); __debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes); CHECK_MSTATUS(meshAttrHandle.jumpToElement(0)); for( int meshIndex=0; meshIndex < numMeshes; ++meshIndex ) { __debug("%s(), meshIndex=%d", __FUNCTION__, meshIndex); MDataHandle currentMesh = meshAttrHandle.inputValue(&status); CHECK_MSTATUS(status); MObject meshMobj = currentMesh.asMesh(); __debug("%s(), meshMobj.apiTypeStr()=%s", __FUNCTION__, meshMobj.apiTypeStr()); __debugMeshInfo(__FUNCTION__, meshMobj); { _initVertMapping_on_one_mesh(meshMobj, vertMapOutArrayBuilder, allPts);// Note: vertMapOutArrayBuilder is updated in this function! //CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder )); } if( !meshAttrHandle.next() ) { break; } }// for (mesh CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder )); }
MStatus MayaToIndigoGlobals::initialize() { MayaRenderGlobalsNode::initialize(); MFnNumericAttribute nAttr; MFnTypedAttribute tAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus stat = MStatus::kSuccess; // ------------- automatically created attributes start ----------- // white_point = eAttr.create("white_point", "white_point", 4, &stat); stat = eAttr.addField( "User", 0 ); stat = eAttr.addField( "A", 1 ); stat = eAttr.addField( "B", 2 ); stat = eAttr.addField( "C", 3 ); stat = eAttr.addField( "D50", 4 ); stat = eAttr.addField( "D55", 5 ); stat = eAttr.addField( "D65", 6 ); stat = eAttr.addField( "D75", 7 ); stat = eAttr.addField( "E", 8 ); stat = eAttr.addField( "F1", 9 ); stat = eAttr.addField( "F2", 10 ); stat = eAttr.addField( "F3", 11 ); stat = eAttr.addField( "F4", 12 ); stat = eAttr.addField( "F5", 13 ); stat = eAttr.addField( "F6", 14 ); stat = eAttr.addField( "F7", 15 ); stat = eAttr.addField( "F8", 16 ); stat = eAttr.addField( "F9", 17 ); stat = eAttr.addField( "F10", 18 ); stat = eAttr.addField( "F11", 19 ); stat = eAttr.addField( "F12", 20 ); CHECK_MSTATUS(addAttribute( white_point )); white_pointX = nAttr.create("white_pointX", "white_pointX", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( white_pointX )); white_pointY = nAttr.create("white_pointY", "white_pointY", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( white_pointY )); bih_tri_threshold = nAttr.create("bih_tri_threshold", "bih_tri_threshold", MFnNumericData::kInt, 1100000); CHECK_MSTATUS(addAttribute( bih_tri_threshold )); metropolis = nAttr.create("metropolis", "metropolis", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( metropolis )); large_mutation_prob = nAttr.create("large_mutation_prob", "large_mutation_prob", MFnNumericData::kFloat, 0.1); CHECK_MSTATUS(addAttribute( large_mutation_prob )); max_change = nAttr.create("max_change", "max_change", MFnNumericData::kFloat, .01); CHECK_MSTATUS(addAttribute( max_change )); max_num_consec_rejections = nAttr.create("max_num_consec_rejections", "max_num_consec_rejections", MFnNumericData::kInt, 1000); CHECK_MSTATUS(addAttribute( max_num_consec_rejections )); logging = nAttr.create("logging", "logging", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( logging )); path_tracing = eAttr.create("path_tracing", "path_tracing", 0, &stat); stat = eAttr.addField( "bidirectional", 0 ); stat = eAttr.addField( "backwards", 1 ); CHECK_MSTATUS(addAttribute( path_tracing )); tone_mapper = eAttr.create("tone_mapper", "tone_mapper", 1, &stat); stat = eAttr.addField( "linear", 0 ); stat = eAttr.addField( "reinhard", 1 ); stat = eAttr.addField( "camera", 2 ); CHECK_MSTATUS(addAttribute( tone_mapper )); tone_linearScale = nAttr.create("tone_linearScale", "tone_linearScale", MFnNumericData::kFloat, 1.0); nAttr.setMin(0.0001); nAttr.setMax(100); CHECK_MSTATUS(addAttribute( tone_linearScale )); tone_reinhardPreScale = nAttr.create("tone_reinhardPreScale", "tone_reinhardPreScale", MFnNumericData::kFloat, 1.0); CHECK_MSTATUS(addAttribute( tone_reinhardPreScale )); tone_reinhardPostScale = nAttr.create("tone_reinhardPostScale", "tone_reinhardPostScale", MFnNumericData::kFloat, 1.0); CHECK_MSTATUS(addAttribute( tone_reinhardPostScale )); tone_reinhardBurn = nAttr.create("tone_reinhardBurn", "tone_reinhardBurn", MFnNumericData::kFloat, 10.0); CHECK_MSTATUS(addAttribute( tone_reinhardBurn )); tone_cameraResponse_function_path = tAttr.create("tone_cameraResponse_function_path", "tone_cameraResponse_function_path", MFnNumericData::kString); CHECK_MSTATUS(addAttribute( tone_cameraResponse_function_path )); tone_cameraEv_adjust = nAttr.create("tone_cameraEv_adjust", "tone_cameraEv_adjust", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( tone_cameraEv_adjust )); tone_cameraFilm_iso = nAttr.create("tone_cameraFilm_iso", "tone_cameraFilm_iso", MFnNumericData::kFloat, 200.0); CHECK_MSTATUS(addAttribute( tone_cameraFilm_iso )); save_untonemapped_exr = nAttr.create("save_untonemapped_exr", "save_untonemapped_exr", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( save_untonemapped_exr )); save_tonemapped_exr = nAttr.create("save_tonemapped_exr", "save_tonemapped_exr", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( save_tonemapped_exr )); save_igi = nAttr.create("save_igi", "save_igi", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( save_igi )); image_save_period = nAttr.create("image_save_period", "image_save_period", MFnNumericData::kFloat, 60); CHECK_MSTATUS(addAttribute( image_save_period )); halt_time = nAttr.create("halt_time", "halt_time", MFnNumericData::kFloat, -1); CHECK_MSTATUS(addAttribute( halt_time )); halt_samples_per_pixel = nAttr.create("halt_samples_per_pixel", "halt_samples_per_pixel", MFnNumericData::kInt, -1); CHECK_MSTATUS(addAttribute( halt_samples_per_pixel )); hybrid = nAttr.create("hybrid", "hybrid", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( hybrid )); auto_choose_num_threads = nAttr.create("auto_choose_num_threads", "auto_choose_num_threads", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( auto_choose_num_threads )); num_threads = nAttr.create("num_threads", "num_threads", MFnNumericData::kBoolean, 1); CHECK_MSTATUS(addAttribute( num_threads )); super_sample_factor = nAttr.create("super_sample_factor", "super_sample_factor", MFnNumericData::kInt, 2); CHECK_MSTATUS(addAttribute( super_sample_factor )); watermark = nAttr.create("watermark", "watermark", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( watermark )); info_overlay = nAttr.create("info_overlay", "info_overlay", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( info_overlay )); cache_trees = nAttr.create("cache_trees", "cache_trees", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( cache_trees )); aperture_diffraction = nAttr.create("aperture_diffraction", "aperture_diffraction", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( aperture_diffraction )); post_process_diffraction = nAttr.create("post_process_diffraction", "post_process_diffraction", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( post_process_diffraction )); render_foreground_alpha = nAttr.create("render_foreground_alpha", "render_foreground_alpha", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( render_foreground_alpha )); splat_filter = eAttr.create("splat_filter", "splat_filter", 0, &stat); stat = eAttr.addField( "fastbox", 0 ); stat = eAttr.addField( "radial", 1 ); stat = eAttr.addField( "mn_cubic", 2 ); CHECK_MSTATUS(addAttribute( splat_filter )); splat_filter_cubic_b = nAttr.create("splat_filter_cubic_b", "splat_filter_cubic_b", MFnNumericData::kFloat, 0.6); CHECK_MSTATUS(addAttribute( splat_filter_cubic_b )); splat_filter_cubic_ring = nAttr.create("splat_filter_cubic_ring", "splat_filter_cubic_ring", MFnNumericData::kFloat, 0.2); CHECK_MSTATUS(addAttribute( splat_filter_cubic_ring )); downsize_filter = eAttr.create("downsize_filter", "downsize_filter", 0, &stat); stat = eAttr.addField( "mn_cubic", 0 ); stat = eAttr.addField( "gauss", 1 ); stat = eAttr.addField( "sharp", 2 ); CHECK_MSTATUS(addAttribute( downsize_filter )); downsize_filter_cubic_radius = nAttr.create("downsize_filter_cubic_radius", "downsize_filter_cubic_radius", MFnNumericData::kFloat, 2); CHECK_MSTATUS(addAttribute( downsize_filter_cubic_radius )); vignetting = nAttr.create("vignetting", "vignetting", MFnNumericData::kBoolean, true); CHECK_MSTATUS(addAttribute( vignetting )); gpu = nAttr.create("gpu", "gpu", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( gpu )); selected_gpu_device = eAttr.create("selected_gpu_device", "selected_gpu_device", 0, &stat); stat = eAttr.addField( "CUDA", 0 ); stat = eAttr.addField( "OPEN_CL", 1 ); CHECK_MSTATUS(addAttribute( selected_gpu_device )); glass_acceleration = nAttr.create("glass_acceleration", "glass_acceleration", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( glass_acceleration )); environmentType = eAttr.create("environmentType", "environmentType", 1, &stat); stat = eAttr.addField( "Off", 0 ); stat = eAttr.addField( "Color/Map", 1 ); stat = eAttr.addField( "Sun", 2 ); CHECK_MSTATUS(addAttribute( environmentType )); environmentColor = nAttr.createColor("environmentColor", "environmentColor"); nAttr.setDefault(0.4,0.4,1.0); CHECK_MSTATUS(addAttribute( environmentColor )); environmentSun = mAttr.create("environmentSun", "environmentSun"); CHECK_MSTATUS(addAttribute( environmentSun )); turbidity = nAttr.create("turbidity", "turbidity", MFnNumericData::kFloat, 2.0); CHECK_MSTATUS(addAttribute( turbidity )); extra_atmospheric = nAttr.create("extra_atmospheric", "extra_atmospheric", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( extra_atmospheric )); sun_layer = nAttr.create("sun_layer", "sun_layer", MFnNumericData::kInt, 0); CHECK_MSTATUS(addAttribute( sun_layer )); sky_layer = nAttr.create("sky_layer", "sky_layer", MFnNumericData::kInt, 0); CHECK_MSTATUS(addAttribute( sky_layer )); sky_model = eAttr.create("sky_model", "sky_model", 0, &stat); stat = eAttr.addField( "original", 0 ); stat = eAttr.addField( "captured-simulation", 1 ); CHECK_MSTATUS(addAttribute( sky_model )); environmentMapType = eAttr.create("environmentMapType", "environmentMapType", 0, &stat); stat = eAttr.addField( "Spherical", 0 ); stat = eAttr.addField( "Lat-Long", 1 ); CHECK_MSTATUS(addAttribute( environmentMapType )); environmentMapMultiplier = nAttr.create("environmentMapMultiplier", "environmentMapMultiplier", MFnNumericData::kFloat, 1.0); CHECK_MSTATUS(addAttribute( environmentMapMultiplier )); MFnStringData fnStringData; MObject defaultString; defaultString = fnStringData.create( "notepad.exe" ); preferredTextEditor = tAttr.create("preferredTextEditor", "preferredTextEditor", MFnNumericData::kString, defaultString); CHECK_MSTATUS(addAttribute( preferredTextEditor )); // ------------- automatically created attributes end ----------- // return stat; }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus PhongNode::compute( const MPlug& plug, MDataBlock& block ) { if ((plug != aOutColor) && (plug.parent() != aOutColor)) return MS::kUnknownParameter; MFloatVector resultColor(0.0,0.0,0.0); // get sample surface shading parameters MFloatVector& surfaceNormal = block.inputValue( aNormalCamera ).asFloatVector(); MFloatVector& cameraPosition = block.inputValue( aPointCamera ).asFloatVector(); // use for raytracing api enhancement below MFloatVector point = cameraPosition; MFloatVector normal = surfaceNormal; MFloatVector& surfaceColor = block.inputValue( aColor ).asFloatVector(); MFloatVector& incandescence = block.inputValue( aIncandescence ).asFloatVector(); float diffuseReflectivity = block.inputValue( aDiffuseReflectivity ).asFloat(); // float translucenceCoeff = block.inputValue( aTranslucenceCoeff ).asFloat(); // User-defined Reflection Color Gain float reflectGain = block.inputValue( aReflectGain ).asFloat(); // Phong shading attributes float power = block.inputValue( aPower ).asFloat(); float spec = block.inputValue( aSpecularity ).asFloat(); float specularR, specularG, specularB; float diffuseR, diffuseG, diffuseB; diffuseR = diffuseG = diffuseB = specularR = specularG = specularB = 0.0; // get light list MArrayDataHandle lightData = block.inputArrayValue( aLightData ); int numLights = lightData.elementCount(); // iterate through light list and get ambient/diffuse values for( int count=1; count <= numLights; count++ ) { MDataHandle currentLight = lightData.inputValue(); MFloatVector& lightIntensity = currentLight.child(aLightIntensity).asFloatVector(); // Find the blind data void*& blindData = currentLight.child( aLightBlindData ).asAddr(); // find ambient component if( currentLight.child(aLightAmbient).asBool() ) { diffuseR += lightIntensity[0]; diffuseG += lightIntensity[1]; diffuseB += lightIntensity[2]; } MFloatVector& lightDirection = currentLight.child(aLightDirection).asFloatVector(); if ( blindData == NULL ) { // find diffuse and specular component if( currentLight.child(aLightDiffuse).asBool() ) { float cosln = lightDirection * surfaceNormal;; if( cosln > 0.0f ) // calculate only if facing light { diffuseR += lightIntensity[0] * ( cosln * diffuseReflectivity ); diffuseG += lightIntensity[1] * ( cosln * diffuseReflectivity ); diffuseB += lightIntensity[2] * ( cosln * diffuseReflectivity ); } CHECK_MSTATUS( cameraPosition.normalize() ); if( cosln > 0.0f ) // calculate only if facing light { float RV = ( ( (2*surfaceNormal) * cosln ) - lightDirection ) * cameraPosition; if( RV > 0.0 ) RV = 0.0; if( RV < 0.0 ) RV = -RV; if ( power < 0 ) power = -power; float s = spec * powf( RV, power ); specularR += lightIntensity[0] * s; specularG += lightIntensity[1] * s; specularB += lightIntensity[2] * s; } } } else { float cosln = MRenderUtil::diffuseReflectance( blindData, lightDirection, point, surfaceNormal, true ); if( cosln > 0.0f ) // calculate only if facing light { diffuseR += lightIntensity[0] * ( cosln * diffuseReflectivity ); diffuseG += lightIntensity[1] * ( cosln * diffuseReflectivity ); diffuseB += lightIntensity[2] * ( cosln * diffuseReflectivity ); } CHECK_MSTATUS ( cameraPosition.normalize() ); if ( currentLight.child(aLightSpecular).asBool() ) { MFloatVector specLightDirection = lightDirection; MDataHandle directionH = block.inputValue( aRayDirection ); MFloatVector direction = directionH.asFloatVector(); float lightAttenuation = 1.0; specLightDirection = MRenderUtil::maximumSpecularReflection( blindData, lightDirection, point, surfaceNormal, direction ); lightAttenuation = MRenderUtil::lightAttenuation( blindData, point, surfaceNormal, false ); // Are we facing the light if ( specLightDirection * surfaceNormal > 0.0f ) { float power2 = block.inputValue( aPower ).asFloat(); MFloatVector rv = 2 * surfaceNormal * ( surfaceNormal * direction ) - direction; float s = spec * powf( rv * specLightDirection, power2 ); specularR += lightIntensity[0] * s * lightAttenuation; specularG += lightIntensity[1] * s * lightAttenuation; specularB += lightIntensity[2] * s * lightAttenuation; } } } if( !lightData.next() ) break; } // factor incident light with surface color and add incandescence resultColor[0] = ( diffuseR * surfaceColor[0] ) + specularR + incandescence[0]; resultColor[1] = ( diffuseG * surfaceColor[1] ) + specularG + incandescence[1]; resultColor[2] = ( diffuseB * surfaceColor[2] ) + specularB + incandescence[2]; // add the reflection color if (reflectGain > 0.0) { MStatus status; // required attributes for using raytracer // origin, direction, sampler, depth, and object id. // MDataHandle originH = block.inputValue( aRayOrigin, &status); MFloatVector origin = originH.asFloatVector(); MDataHandle directionH = block.inputValue( aRayDirection, &status); MFloatVector direction = directionH.asFloatVector(); MDataHandle samplerH = block.inputValue( aRaySampler, &status); void*& samplerPtr = samplerH.asAddr(); MDataHandle depthH = block.inputValue( aRayDepth, &status); short depth = depthH.asShort(); MDataHandle objH = block.inputValue( aObjectId, &status); void*& objId = objH.asAddr(); MFloatVector reflectColor; MFloatVector reflectTransparency; MFloatVector& triangleNormal = block.inputValue( aTriangleNormalCamera ).asFloatVector(); // compute reflected ray MFloatVector l = -direction; float dot = l * normal; if( dot < 0.0 ) dot = -dot; MFloatVector refVector = 2 * normal * dot - l; // reflection ray float dotRef = refVector * triangleNormal; if( dotRef < 0.0 ) { const float s = 0.01f; MFloatVector mVec = refVector - dotRef * triangleNormal; mVec.normalize(); refVector = mVec + s * triangleNormal; } CHECK_MSTATUS ( refVector.normalize() ); status = MRenderUtil::raytrace( point, // origin refVector, // direction objId, // object id samplerPtr, // sampler info depth, // ray depth reflectColor, // output color and transp reflectTransparency); // add in the reflection color resultColor[0] += reflectGain * (reflectColor[0]); resultColor[1] += reflectGain * (reflectColor[1]); resultColor[2] += reflectGain * (reflectColor[2]); } // set ouput color attribute MDataHandle outColorHandle = block.outputValue( aOutColor ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); return MS::kSuccess; }
MStatus progressWindowPlugin::doIt(const MArgList &args) { MStatus stat = MS::kSuccess; MString title = "Doing Nothing"; MString sleeping = "Sleeping: "; int amount = 0; int maxProgress = 10; // First reserve the progress window. If a progress window is already // active (eg. through the mel "progressWindow" command), this command // fails. // if (!MProgressWindow::reserve()) { MGlobal::displayError("Progress window already in use."); stat = MS::kFailure; return stat; } // // Set up and print progress window state // CHECK_MSTATUS(MProgressWindow::setProgressRange(amount, maxProgress)); CHECK_MSTATUS(MProgressWindow::setTitle(title)); CHECK_MSTATUS(MProgressWindow::setInterruptable(true)); CHECK_MSTATUS(MProgressWindow::setProgress(amount)); MString progressWindowState = MString("Progress Window Info:") + MString("\nMin: ") + MProgressWindow::progressMin() + MString("\nMax: ") + MProgressWindow::progressMax() + MString("\nTitle: ") + MProgressWindow::title() + MString("\nInterruptible: ") + MProgressWindow::isInterruptable(); MGlobal::displayInfo(progressWindowState); CHECK_MSTATUS(MProgressWindow::startProgress()); // Count 10 seconds // for (int i = amount; i < maxProgress; i++) { if (i != 0 && MProgressWindow::isCancelled()) { MGlobal::displayInfo("Progress interrupted!"); break; } MString statusStr = sleeping; statusStr += i; CHECK_MSTATUS(MProgressWindow::setProgressStatus(statusStr)); CHECK_MSTATUS(MProgressWindow::advanceProgress(1)); MGlobal::displayInfo(MString("Current progress: ") + MProgressWindow::progress()); MGlobal::executeCommand("pause -sec 1", false, false); } // End the progress, unreserving the progress window so it can be used // elsewhere. // CHECK_MSTATUS(MProgressWindow::endProgress()); return stat; }
// The initialize routine is called after the node has been created. // It sets up the input and output attributes and adds them to the node. // Finally the dependencies are arranged so that when the inputs // change Maya knowns to call compute to recalculate the output values. // The inputs are: input, scale, frames // The outputs are: sineOutput, cosineOutput // MStatus circle::initialize() { MFnNumericAttribute nAttr; MStatus stat; // Setup the input attributes // input = nAttr.create( "input", "in", MFnNumericData::kFloat, 0.0, &stat ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( nAttr.setStorable( true ) ); scale = nAttr.create( "scale", "sc", MFnNumericData::kFloat, 10.0, &stat ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( nAttr.setStorable( true ) ); frames = nAttr.create( "frames", "fr", MFnNumericData::kFloat, 48.0, &stat ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( nAttr.setStorable( true ) ); // Setup the output attributes // sOutput = nAttr.create( "sineOutput", "so", MFnNumericData::kFloat, 0.0, &stat ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( nAttr.setWritable( false ) ); CHECK_MSTATUS( nAttr.setStorable( false ) ); cOutput = nAttr.create( "cosineOutput", "co", MFnNumericData::kFloat, 0.0, &stat ); CHECK_MSTATUS( stat ); CHECK_MSTATUS( nAttr.setWritable( false ) ); CHECK_MSTATUS( nAttr.setStorable( false ) ); // Add the attributes to the node // CHECK_MSTATUS( addAttribute( input ) ); CHECK_MSTATUS( addAttribute( scale ) ); CHECK_MSTATUS( addAttribute( frames ) ); CHECK_MSTATUS( addAttribute( sOutput ) ); CHECK_MSTATUS( addAttribute( cOutput ) ); // Set the attribute dependencies // CHECK_MSTATUS( attributeAffects( input, sOutput ) ); CHECK_MSTATUS( attributeAffects( input, cOutput ) ); CHECK_MSTATUS( attributeAffects( scale, sOutput ) ); CHECK_MSTATUS( attributeAffects( scale, cOutput ) ); CHECK_MSTATUS( attributeAffects( frames, sOutput ) ); CHECK_MSTATUS( attributeAffects( frames, cOutput ) ); return MS::kSuccess; }
// // DESCRIPTION: MStatus brick::initialize() { MFnNumericAttribute nAttr; MFnTypedAttribute tAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus status; outColor = nAttr.createColor("outColor", "outColor"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( outColor )); //---------------------------- automatically created attributes start ------------------------------------ MObject scaleX = nAttr.create("scaleX", "scalex", MFnNumericData::kDouble, 0.0); MObject scaleY = nAttr.create("scaleY", "scaley", MFnNumericData::kDouble, 0.0); MObject scaleZ = nAttr.create("scaleZ", "scalez", MFnNumericData::kDouble, 0.0); scale = nAttr.create("scale", "scale", scaleX, scaleY, scaleZ); MAKE_INPUT(nAttr); nAttr.setDefault(1,1,1); CHECK_MSTATUS(addAttribute( scale )); brickbevel = nAttr.create("brickbevel", "brickbevel", MFnNumericData::kFloat, 0.0); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickbevel )); brickbond = eAttr.create("brickbond", "brickbond", 0, &status); status = eAttr.addField( "stacked", 0 ); status = eAttr.addField( "flemish", 1 ); status = eAttr.addField( "english", 2 ); status = eAttr.addField( "herringbone", 3 ); status = eAttr.addField( "basket", 4 ); status = eAttr.addField( "chain link", 5 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( brickbond )); mortarsize = nAttr.create("mortarsize", "mortarsize", MFnNumericData::kFloat, 0.01); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( mortarsize )); brickwidth = nAttr.create("brickwidth", "brickwidth", MFnNumericData::kFloat, 0.3); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickwidth )); bricktex = nAttr.createColor("bricktex", "bricktex"); MAKE_INPUT(nAttr); nAttr.setDefault(1.0,1.0,1.0); CHECK_MSTATUS(addAttribute( bricktex )); brickdepth = nAttr.create("brickdepth", "brickdepth", MFnNumericData::kFloat, 0.15); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickdepth )); coordinates = eAttr.create("coordinates", "coordinates", 0, &status); status = eAttr.addField( "global", 0 ); status = eAttr.addField( "local", 1 ); status = eAttr.addField( "global normal", 2 ); status = eAttr.addField( "localnormal", 3 ); status = eAttr.addField( "uv", 4 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( coordinates )); brickmodtex = nAttr.create("brickmodtex", "brickmodtex", MFnNumericData::kFloat, 1.0); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickmodtex )); MObject rotateX = nAttr.create("rotateX", "rotatex", MFnNumericData::kDouble, 0.0); MObject rotateY = nAttr.create("rotateY", "rotatey", MFnNumericData::kDouble, 0.0); MObject rotateZ = nAttr.create("rotateZ", "rotatez", MFnNumericData::kDouble, 0.0); rotate = nAttr.create("rotate", "rotate", rotateX, rotateY, rotateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( rotate )); motartex = nAttr.createColor("motartex", "motartex"); MAKE_INPUT(nAttr); nAttr.setDefault(0.2,0.2,0.2); CHECK_MSTATUS(addAttribute( motartex )); brickrun = nAttr.create("brickrun", "brickrun", MFnNumericData::kFloat, 0.75); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickrun )); MObject translateX = nAttr.create("translateX", "translatex", MFnNumericData::kDouble, 0.0); MObject translateY = nAttr.create("translateY", "translatey", MFnNumericData::kDouble, 0.0); MObject translateZ = nAttr.create("translateZ", "translatez", MFnNumericData::kDouble, 0.0); translate = nAttr.create("translate", "translate", translateX, translateY, translateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( translate )); brickheight = nAttr.create("brickheight", "brickheight", MFnNumericData::kFloat, 0.1); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( brickheight )); luxOutFloat = nAttr.create("luxOutFloat", "luxOutFloat", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( luxOutFloat )); luxOutColor = nAttr.createColor("luxOutColor", "luxOutColor"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( luxOutColor )); CHECK_MSTATUS ( attributeAffects( scale, luxOutFloat)); CHECK_MSTATUS ( attributeAffects( scale, luxOutColor)); CHECK_MSTATUS ( attributeAffects( scale, outColor)); //---------------------------- automatically created attributes end ------------------------------------ return MS::kSuccess; }
MStatus CoatingBSDF::initialize() { MFnNumericAttribute nAttr; MFnLightDataAttribute lAttr; MFnTypedAttribute tAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus status; // Status will be used to hold the MStatus value // returned by each api function call. It is important // to check the status returned by a call to aid in // debugging. Failed API calls can result in subtle // errors that can be difficult to track down, you may // wish to use the CHECK_MSTATUS macro for any API // call where you do not need to provide your own // error handling. // //---------------------------- automatically created attributes start ------------------------------------ normalMapping = nAttr.create("normalMapping", "normalMapping", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( normalMapping )); kappa = nAttr.create("kappa", "kappa", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( kappa )); bump = nAttr.create("bump", "bump", MFnNumericData::kFloat, 1.0); CHECK_MSTATUS(addAttribute( bump )); anisotropy = nAttr.create("anisotropy", "anisotropy", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( anisotropy )); reflectanceColor = nAttr.createColor("reflectanceColor", "reflectanceColor"); nAttr.setDefault(0.0,0.0,0.0); CHECK_MSTATUS(addAttribute( reflectanceColor )); ior = nAttr.create("ior", "ior", MFnNumericData::kFloat, 1.5); CHECK_MSTATUS(addAttribute( ior )); roughness = nAttr.create("roughness", "roughness", MFnNumericData::kFloat, 0.1); CHECK_MSTATUS(addAttribute( roughness )); microRoughnessHeight = nAttr.create("microRoughnessHeight", "microRoughnessHeight", MFnNumericData::kFloat, 0.25); CHECK_MSTATUS(addAttribute( microRoughnessHeight )); coatingAbsorption = nAttr.create("coatingAbsorption", "coatingAbsorption", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( coatingAbsorption )); microRoughness = nAttr.create("microRoughness", "microRoughness", MFnNumericData::kBoolean, false); CHECK_MSTATUS(addAttribute( microRoughness )); rotation = nAttr.create("rotation", "rotation", MFnNumericData::kFloat, 0.0); CHECK_MSTATUS(addAttribute( rotation )); thickness = nAttr.create("thickness", "thickness", MFnNumericData::kFloat, 100.0); CHECK_MSTATUS(addAttribute( thickness )); microRoughnessWidth = nAttr.create("microRoughnessWidth", "microRoughnessWidth", MFnNumericData::kFloat, 10.0); CHECK_MSTATUS(addAttribute( microRoughnessWidth )); //---------------------------- automatically created attributes end ------------------------------------ // Input Attributes // aTranslucenceCoeff = nAttr.create( "translucenceCoeff", "tc", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aDiffuseReflectivity = nAttr.create( "diffuseReflectivity", "drfl", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.8f ) ); aColor = nAttr.createColor( "color", "c", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.58824f, 0.644f ) ); aIncandescence = nAttr.createColor( "incandescence", "ic", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); aInTransparency = nAttr.createColor( "transparency", "it", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); // Color Output // aOutColor = nAttr.createColor( "outColor", "oc", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setHidden( false ) ); CHECK_MSTATUS( nAttr.setReadable( true ) ); CHECK_MSTATUS( nAttr.setWritable( false ) ); aOutTransparency = nAttr.createColor( "outTransparency", "ot", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setHidden( false ) ); CHECK_MSTATUS( nAttr.setReadable( true ) ); CHECK_MSTATUS( nAttr.setWritable( false ) ); // Camera Normals // aNormalCameraX = nAttr.create( "normalCameraX", "nx", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCameraY = nAttr.create( "normalCameraY", "ny", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCameraZ = nAttr.create( "normalCameraZ", "nz", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCamera = nAttr.create( "normalCamera","n", aNormalCameraX, aNormalCameraY, aNormalCameraZ, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); CHECK_MSTATUS( nAttr.setHidden( true ) ); // Light Direction // aLightDirectionX = nAttr.create( "lightDirectionX", "ldx", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirectionY = nAttr.create( "lightDirectionY", "ldy", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirectionZ = nAttr.create( "lightDirectionZ", "ldz", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirection = nAttr.create( "lightDirection", "ld", aLightDirectionX, aLightDirectionY, aLightDirectionZ, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); // Light Intensity // aLightIntensityR = nAttr.create( "lightIntensityR", "lir", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensityG = nAttr.create( "lightIntensityG", "lig", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensityB = nAttr.create( "lightIntensityB", "lib", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensity = nAttr.create( "lightIntensity", "li", aLightIntensityR, aLightIntensityG, aLightIntensityB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); // Light // aLightAmbient = nAttr.create( "lightAmbient", "la", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( true ) ); aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( true ) ); aLightSpecular = nAttr.create( "lightSpecular", "ls", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( false ) ); aLightShadowFraction = nAttr.create( "lightShadowFraction", "lsf", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aPreShadowIntensity = nAttr.create( "preShadowIntensity", "psi", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightBlindData = nAttr.createAddr( "lightBlindData", "lbld", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightData = lAttr.create( "lightDataArray", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( lAttr.setArray( true ) ); CHECK_MSTATUS( lAttr.setStorable( false ) ); CHECK_MSTATUS( lAttr.setHidden( true ) ); CHECK_MSTATUS( lAttr.setDefault( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, false, 1.0f, 1.0f, NULL ) ); // Next we will add the attributes we have defined to the node // CHECK_MSTATUS( addAttribute( aTranslucenceCoeff ) ); CHECK_MSTATUS( addAttribute( aDiffuseReflectivity ) ); CHECK_MSTATUS( addAttribute( aColor ) ); CHECK_MSTATUS( addAttribute( aIncandescence ) ); CHECK_MSTATUS( addAttribute( aInTransparency ) ); CHECK_MSTATUS( addAttribute( aOutColor ) ); CHECK_MSTATUS( addAttribute( aOutTransparency ) ); CHECK_MSTATUS( addAttribute( aNormalCamera ) ); // Only add the parent of the compound CHECK_MSTATUS( addAttribute( aLightData ) ); // The attributeAffects() method is used to indicate when the input // attribute affects the output attribute. This knowledge allows Maya // to optimize dependencies in the graph in more complex nodes where // there may be several inputs and outputs, but not all the inputs // affect all the outputs. // CHECK_MSTATUS( attributeAffects( aTranslucenceCoeff, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aDiffuseReflectivity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aColor, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aInTransparency, aOutTransparency ) ); CHECK_MSTATUS( attributeAffects( aInTransparency, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aIncandescence, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityR, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityB, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityG, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraX, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraY, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraZ, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCamera, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionX, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionY, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionZ, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirection, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightAmbient, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightSpecular, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDiffuse, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightShadowFraction, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aPreShadowIntensity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightBlindData, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightData, aOutColor ) ); return( MS::kSuccess ); }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus clearcoat::initialize() { MFnNumericAttribute nAttr; MFnCompoundAttribute cAttr; aIndex = nAttr.create( "index", "ix", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setDefault(1.8f) ); CHECK_MSTATUS ( nAttr.setSoftMin(1.0f) ); CHECK_MSTATUS ( nAttr.setSoftMax(5.0f) ); aScale = nAttr.create( "scale", "s", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setDefault(1.55f) ); CHECK_MSTATUS ( nAttr.setSoftMin(0.0f) ); CHECK_MSTATUS ( nAttr.setSoftMax(5.0f) ); aBias = nAttr.create( "bias", "b", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setDefault(-0.1f) ); CHECK_MSTATUS ( nAttr.setSoftMin(-1.0f) ); CHECK_MSTATUS ( nAttr.setSoftMax( 1.0f) ); aNormalCameraX = nAttr.create( "normalCameraX", "nx", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); aNormalCameraY = nAttr.create( "normalCameraY", "ny", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false)); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); aNormalCameraZ = nAttr.create( "normalCameraZ", "nz", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); aNormalCamera = nAttr.create( "normalCamera","n", aNormalCameraX, aNormalCameraY, aNormalCameraZ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f)); CHECK_MSTATUS ( nAttr.setHidden(true) ); aRayDirectionX = nAttr.create( "rayDirectionX", "rx", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); aRayDirectionY = nAttr.create( "rayDirectionY", "ry", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false)); CHECK_MSTATUS ( nAttr.setDefault(1.0f)); aRayDirectionZ = nAttr.create( "rayDirectionZ", "rz", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); aRayDirection = nAttr.create( "rayDirection","r", aRayDirectionX, aRayDirectionY, aRayDirectionZ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); // Outputs aOutValue = nAttr.create( "outValue", "ov", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setHidden(false) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( addAttribute(aIndex)); CHECK_MSTATUS ( addAttribute(aScale) ); CHECK_MSTATUS ( addAttribute(aBias) ); // compound attribute - only need to add parent CHECK_MSTATUS ( addAttribute(aNormalCamera) ); // compound attribute - only need to add parent CHECK_MSTATUS ( addAttribute(aRayDirection) ); CHECK_MSTATUS ( addAttribute(aOutValue) ); CHECK_MSTATUS ( attributeAffects (aIndex, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aScale, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aBias, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aNormalCameraX, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aNormalCameraY, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aNormalCameraZ, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aNormalCamera, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aRayDirectionX, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aRayDirectionY, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aRayDirectionZ, aOutValue) ); CHECK_MSTATUS ( attributeAffects (aRayDirection, aOutValue) ); return MS::kSuccess; }
// Compute takes two parameters: plug and data. // - Plug is the the data value that needs to be recomputed // - Data provides handles to all of the nodes attributes, only these // handles should be used when performing computations. // MStatus CoatingBSDF::compute( const MPlug& plug, MDataBlock& block ) { // The plug parameter will allow us to determine which output attribute // needs to be calculated. // if( plug == aOutColor || plug == aOutTransparency || plug.parent() == aOutColor || plug.parent() == aOutTransparency ) { MStatus status; MFloatVector resultColor( 0.0, 0.0, 0.0 ); // Get surface shading parameters from input block // MFloatVector& surfaceNormal = block.inputValue( aNormalCamera, &status ).asFloatVector(); CHECK_MSTATUS( status ); MFloatVector& surfaceColor = block.inputValue( aColor, &status ).asFloatVector(); CHECK_MSTATUS( status ); MFloatVector& incandescence = block.inputValue( aIncandescence, &status ).asFloatVector(); CHECK_MSTATUS( status ); float diffuseReflectivity = block.inputValue( aDiffuseReflectivity, &status ).asFloat(); CHECK_MSTATUS( status ); // float translucenceCoeff = block.inputValue( aTranslucenceCoeff, // &status ).asFloat(); // CHECK_MSTATUS( status ); // Get light list // MArrayDataHandle lightData = block.inputArrayValue( aLightData, &status ); CHECK_MSTATUS( status ); int numLights = lightData.elementCount( &status ); CHECK_MSTATUS( status ); // Calculate the effect of the lights in the scene on the color // // Iterate through light list and get ambient/diffuse values // for( int count=1; count <= numLights; count++ ) { // Get the current light out of the array // MDataHandle currentLight = lightData.inputValue( &status ); CHECK_MSTATUS( status ); // Get the intensity of that light // MFloatVector& lightIntensity = currentLight.child( aLightIntensity ).asFloatVector(); // Find ambient component // if ( currentLight.child( aLightAmbient ).asBool() ) { resultColor += lightIntensity; } // Find diffuse component // if ( currentLight.child( aLightDiffuse ).asBool() ) { MFloatVector& lightDirection = currentLight.child( aLightDirection ).asFloatVector(); float cosln = lightDirection * surfaceNormal; if ( cosln > 0.0f ) { resultColor += lightIntensity * ( cosln * diffuseReflectivity ); } } // Advance to the next light. // if ( count < numLights ) { status = lightData.next(); CHECK_MSTATUS( status ); } } // Factor incident light with surface color and add incandescence // resultColor[0] = resultColor[0] * surfaceColor[0] + incandescence[0]; resultColor[1] = resultColor[1] * surfaceColor[1] + incandescence[1]; resultColor[2] = resultColor[2] * surfaceColor[2] + incandescence[2]; // Set ouput color attribute // if ( plug == aOutColor || plug.parent() == aOutColor ) { // Get the handle to the attribute // MDataHandle outColorHandle = block.outputValue( aOutColor, &status ); CHECK_MSTATUS( status ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; // Set the output value outColorHandle.setClean(); // Mark the output value as clean } // Set ouput transparency // if ( plug == aOutTransparency || plug.parent() == aOutTransparency ) { MFloatVector& transparency = block.inputValue( aInTransparency, &status ).asFloatVector(); CHECK_MSTATUS( status ); // Get the handle to the attribute // MDataHandle outTransHandle = block.outputValue( aOutTransparency, &status ); CHECK_MSTATUS( status ); MFloatVector& outTrans = outTransHandle.asFloatVector(); outTrans = transparency; // Set the output value outTransHandle.setClean(); // Mark the output value as clean } } else { return( MS::kUnknownParameter ); // We got an unexpected plug } return( MS::kSuccess ); }
// // DESCRIPTION: /////////////////////////////////////////////////////// MStatus depthShader::initialize() { MFnNumericAttribute nAttr; // Create input attributes aColorNear = nAttr.createColor("color", "c"); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setDefault(0., 1., 0.)); // Green aColorFar = nAttr.createColor("colorFar", "cf"); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setDefault(0., 0., 1.)); // Blue aNear = nAttr.create("near", "n", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setMin(0.0f)); CHECK_MSTATUS(nAttr.setSoftMax(1000.0f)); aFar = nAttr.create("far", "f", MFnNumericData::kFloat); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setMin(0.0f)); CHECK_MSTATUS(nAttr.setSoftMax(1000.0f)); CHECK_MSTATUS(nAttr.setDefault(2.0f)); aPointCamera = nAttr.createPoint("pointCamera", "p"); MAKE_INPUT(nAttr); CHECK_MSTATUS(nAttr.setHidden(true)); // Create output attributes aOutColor = nAttr.createColor("outColor", "oc"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute(aColorNear)); CHECK_MSTATUS(addAttribute(aColorFar)); CHECK_MSTATUS(addAttribute(aNear) ); CHECK_MSTATUS(addAttribute(aFar)); CHECK_MSTATUS(addAttribute(aPointCamera)); CHECK_MSTATUS(addAttribute(aOutColor)); CHECK_MSTATUS(attributeAffects(aColorNear, aOutColor)); CHECK_MSTATUS(attributeAffects(aColorFar, aOutColor)); CHECK_MSTATUS(attributeAffects(aNear, aOutColor)); CHECK_MSTATUS(attributeAffects(aFar, aOutColor)); CHECK_MSTATUS(attributeAffects(aPointCamera, aOutColor)); return MS::kSuccess; }
// // DESCRIPTION: MStatus marble::initialize() { MFnNumericAttribute nAttr; MFnTypedAttribute tAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus status; outColor = nAttr.createColor("outColor", "outColor"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( outColor )); //---------------------------- automatically created attributes start ------------------------------------ scale = nAttr.create("scale", "scale", MFnNumericData::kFloat, 1); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( scale )); octaves = nAttr.create("octaves", "octaves", MFnNumericData::kInt, 8); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( octaves )); coordinates = eAttr.create("coordinates", "coordinates", 0, &status); status = eAttr.addField( "global", 0 ); status = eAttr.addField( "local", 1 ); status = eAttr.addField( "global normal", 2 ); status = eAttr.addField( "localnormal", 3 ); status = eAttr.addField( "uv", 4 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( coordinates )); roughness = nAttr.create("roughness", "roughness", MFnNumericData::kFloat, 0.5); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( roughness )); MObject rotateX = nAttr.create("rotateX", "rotatex", MFnNumericData::kDouble, 0.0); MObject rotateY = nAttr.create("rotateY", "rotatey", MFnNumericData::kDouble, 0.0); MObject rotateZ = nAttr.create("rotateZ", "rotatez", MFnNumericData::kDouble, 0.0); rotate = nAttr.create("rotate", "rotate", rotateX, rotateY, rotateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( rotate )); variation = nAttr.create("variation", "variation", MFnNumericData::kFloat, 0.2); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( variation )); MObject translateX = nAttr.create("translateX", "translatex", MFnNumericData::kDouble, 0.0); MObject translateY = nAttr.create("translateY", "translatey", MFnNumericData::kDouble, 0.0); MObject translateZ = nAttr.create("translateZ", "translatez", MFnNumericData::kDouble, 0.0); translate = nAttr.create("translate", "translate", translateX, translateY, translateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( translate )); luxOutColor = nAttr.createColor("luxOutColor", "luxOutColor"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( luxOutColor )); CHECK_MSTATUS ( attributeAffects( scale, luxOutColor)); CHECK_MSTATUS ( attributeAffects( scale, outColor)); //---------------------------- automatically created attributes end ------------------------------------ return MS::kSuccess; }
btCompoundShape* convex_decomposition_hacd::ConvexDecomp(int numVertices, float* vertices, int numIndices,const unsigned int* indices) { //----------------------------------------------- // HACD //----------------------------------------------- std::vector< HACD::Vec3<HACD::Real> > points; std::vector< HACD::Vec3<long> > triangles; for(int i=0; i<numVertices; i++ ) { int index = i*3; HACD::Vec3<HACD::Real> vertex(vertices[index], vertices[index+1],vertices[index+2]); points.push_back(vertex); } for(int i=0;i<numIndices/3;i++) { int index = i*3; HACD::Vec3<long> triangle(indices[index], indices[index+1], indices[index+2]); triangles.push_back(triangle); } HACD::HACD myHACD; myHACD.SetPoints(&points[0]); myHACD.SetNPoints(points.size()); myHACD.SetTriangles(&triangles[0]); myHACD.SetNTriangles(triangles.size()); myHACD.SetCompacityWeight(0.1); myHACD.SetVolumeWeight(0.0); // HACD parameters // Recommended parameters: 2 100 0 0 0 0 size_t nClusters = 2; double concavity = 10; bool invert = false; bool addExtraDistPoints = true;//false; bool addNeighboursDistPoints = true;//false; bool addFacesPoints = false; myHACD.SetNClusters(nClusters); // minimum number of clusters myHACD.SetNVerticesPerCH(256); // max of 100 vertices per convex-hull myHACD.SetConcavity(concavity); // maximum concavity myHACD.SetAddExtraDistPoints(addExtraDistPoints); myHACD.SetAddNeighboursDistPoints(addNeighboursDistPoints); myHACD.SetAddFacesPoints(addFacesPoints); myHACD.SetAddExtraDistPoints(true); myHACD.SetAddFacesPoints(true); MStatus stat = MS::kSuccess; MString title = "Esc to stop"; MString sleeping = "Esc to stop"; int amount = 0; int maxProgress = 1000; // First reserve the progress window. If a progress window is already // active (eg. through the mel "progressWindow" command), this command // fails. // if (!MProgressWindow::reserve()) { MGlobal::displayError("Progress window already in use."); stat = MS::kFailure; } // // Set up and print progress window state // CHECK_MSTATUS(MProgressWindow::setProgressRange(amount, maxProgress)); CHECK_MSTATUS(MProgressWindow::setTitle(title)); CHECK_MSTATUS(MProgressWindow::setInterruptable(true)); CHECK_MSTATUS(MProgressWindow::setProgress(amount)); MString progressWindowState = MString("Progress Window Info:") + MString("\nMin: ") + MProgressWindow::progressMin() + MString("\nMax: ") + MProgressWindow::progressMax() + MString("\nTitle: ") + MProgressWindow::title() + MString("\nInterruptible: ") + MProgressWindow::isInterruptable(); MGlobal::displayInfo(progressWindowState); CHECK_MSTATUS(MProgressWindow::startProgress()); int i=1; MString statusStr = sleeping; statusStr += i; CHECK_MSTATUS(MProgressWindow::setProgressStatus(statusStr)); CHECK_MSTATUS(MProgressWindow::advanceProgress(1)); MGlobal::displayInfo(MString("Current progress: ") + MProgressWindow::progress()); MGlobal::executeCommand("pause -sec 1", false,false); // Count 10 seconds // /* for (int i = amount; i < maxProgress; i++) { if (i != 0 && MProgressWindow::isCancelled()) { MGlobal::displayInfo("Progress interrupted!"); break; } MString statusStr = sleeping; statusStr += i; CHECK_MSTATUS(MProgressWindow::setProgressStatus(statusStr)); CHECK_MSTATUS(MProgressWindow::advanceProgress(1)); MGlobal::displayInfo(MString("Current progress: ") + MProgressWindow::progress()); MGlobal::executeCommand("pause -sec 1", false, false); } */ // End the progress, unreserving the progress window so it can be used // elsewhere. // myHACD.SetCallBack(mayaCallback); bool result = myHACD.Compute(); if (!result) { nClusters = 0; } else { nClusters = myHACD.GetNClusters(); } CHECK_MSTATUS(MProgressWindow::endProgress()); // myHACD.Save("output.wrl", false); btCompoundShape* compound = new btCompoundShape(); // mMergedTriangleMesh = new btTriangleMesh(); //now create some bodies if (1) { btTransform trans; trans.setIdentity(); for (int c=0;c<nClusters;c++) { //generate convex result size_t nPoints = myHACD.GetNPointsCH(c); size_t nTriangles = myHACD.GetNTrianglesCH(c); float* vertices = new float[nPoints*3]; unsigned int* triangles = new unsigned int[nTriangles*3]; HACD::Vec3<HACD::Real> * pointsCH = new HACD::Vec3<HACD::Real>[nPoints]; HACD::Vec3<long> * trianglesCH = new HACD::Vec3<long>[nTriangles]; myHACD.GetCH(c, pointsCH, trianglesCH); // points for(size_t v = 0; v < nPoints; v++) { vertices[3*v] = pointsCH[v].X(); vertices[3*v+1] = pointsCH[v].Y(); vertices[3*v+2] = pointsCH[v].Z(); } // triangles for(size_t f = 0; f < nTriangles; f++) { triangles[3*f] = trianglesCH[f].X(); triangles[3*f+1] = trianglesCH[f].Y(); triangles[3*f+2] = trianglesCH[f].Z(); } delete [] pointsCH; delete [] trianglesCH; ConvexDecompResult(nPoints, vertices, nTriangles, triangles); } for (int i=0;i<m_convexShapes.size();i++) { btVector3 centroid = m_convexCentroids[i]; trans.setOrigin(centroid); btConvexHullShape* convexShape = m_convexShapes[i]; compound->addChildShape(trans,convexShape); } } /* mMergedTriangleVertices = new float[mNumMergedTriangleVertices*3]; mMergedTriangleIndices = new int[mNumMergedTriangleIndices]; for(int i=0; i<m_trimeshes.size(); i++) { mMergedTriangleVertices[i] = }*/ return compound; }
// // DESCRIPTION: MStatus blender_marble::initialize() { MFnNumericAttribute nAttr; MFnTypedAttribute tAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus status; outColor = nAttr.createColor("outColor", "outColor"); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( outColor )); //---------------------------- automatically created attributes start ------------------------------------ noisesize = nAttr.create("noisesize", "noisesize", MFnNumericData::kFloat, 0.25); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( noisesize )); noisebasis2 = eAttr.create("noisebasis2", "noisebasis2", 0, &status); status = eAttr.addField( "blender_original", 0 ); status = eAttr.addField( "original_perlin", 1 ); status = eAttr.addField( "improved_perlin", 2 ); status = eAttr.addField( "voronoi_f1", 3 ); status = eAttr.addField( "voronoi_f2", 4 ); status = eAttr.addField( "voronoi_f3", 5 ); status = eAttr.addField( "voronoi_f4", 6 ); status = eAttr.addField( "voronoi_f2f1", 7 ); status = eAttr.addField( "voronoi_crackle", 8 ); status = eAttr.addField( "cell_noise", 9 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( noisebasis2 )); noisebasis = eAttr.create("noisebasis", "noisebasis", 0, &status); status = eAttr.addField( "sin", 0 ); status = eAttr.addField( "saw", 1 ); status = eAttr.addField( "tri", 2 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( noisebasis )); MObject scaleX = nAttr.create("scaleX", "scalex", MFnNumericData::kDouble, 0.0); MObject scaleY = nAttr.create("scaleY", "scaley", MFnNumericData::kDouble, 0.0); MObject scaleZ = nAttr.create("scaleZ", "scalez", MFnNumericData::kDouble, 0.0); scale = nAttr.create("scale", "scale", scaleX, scaleY, scaleZ); MAKE_INPUT(nAttr); nAttr.setDefault(1,1,1); CHECK_MSTATUS(addAttribute( scale )); noisedepth = nAttr.create("noisedepth", "noisedepth", MFnNumericData::kInt, 2); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( noisedepth )); turbulance = nAttr.create("turbulance", "turbulance", MFnNumericData::kFloat, 5.0); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( turbulance )); coordinates = eAttr.create("coordinates", "coordinates", 0, &status); status = eAttr.addField( "global", 0 ); status = eAttr.addField( "local", 1 ); status = eAttr.addField( "global normal", 2 ); status = eAttr.addField( "localnormal", 3 ); status = eAttr.addField( "uv", 4 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( coordinates )); bright = nAttr.create("bright", "bright", MFnNumericData::kFloat, 1.0); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( bright )); MObject rotateX = nAttr.create("rotateX", "rotatex", MFnNumericData::kDouble, 0.0); MObject rotateY = nAttr.create("rotateY", "rotatey", MFnNumericData::kDouble, 0.0); MObject rotateZ = nAttr.create("rotateZ", "rotatez", MFnNumericData::kDouble, 0.0); rotate = nAttr.create("rotate", "rotate", rotateX, rotateY, rotateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( rotate )); noisetype = eAttr.create("noisetype", "noisetype", 1, &status); status = eAttr.addField( "soft_noise", 0 ); status = eAttr.addField( "hard_noise", 1 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( noisetype )); MObject translateX = nAttr.create("translateX", "translatex", MFnNumericData::kDouble, 0.0); MObject translateY = nAttr.create("translateY", "translatey", MFnNumericData::kDouble, 0.0); MObject translateZ = nAttr.create("translateZ", "translatez", MFnNumericData::kDouble, 0.0); translate = nAttr.create("translate", "translate", translateX, translateY, translateZ); MAKE_INPUT(nAttr); nAttr.setDefault(0,0,0); CHECK_MSTATUS(addAttribute( translate )); type = eAttr.create("type", "type", 0, &status); status = eAttr.addField( "soft", 0 ); status = eAttr.addField( "sharp", 1 ); status = eAttr.addField( "sharper", 2 ); MAKE_INPUT(eAttr); CHECK_MSTATUS(addAttribute( type )); contrast = nAttr.create("contrast", "contrast", MFnNumericData::kFloat, 1.0); MAKE_INPUT(nAttr); CHECK_MSTATUS(addAttribute( contrast )); luxOutFloat = nAttr.create("luxOutFloat", "luxOutFloat", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); CHECK_MSTATUS(addAttribute( luxOutFloat )); CHECK_MSTATUS ( attributeAffects( noisesize, luxOutFloat)); CHECK_MSTATUS ( attributeAffects( noisesize, outColor)); //---------------------------- automatically created attributes end ------------------------------------ return MS::kSuccess; }
MStatus stringFormat::compute (const MPlug& plug, MDataBlock& data) { MStatus status; // Check that the requested recompute is one of the output values // if (plug == attrOutput) { // Read the input values // MDataHandle inputData = data.inputValue (attrFormat, &status); CHECK_MSTATUS( status ); MString format = inputData.asString(); // Get input data handle, use outputArrayValue since we do not // want to evaluate all inputs, only the ones related to the // requested multiIndex. This is for efficiency reasons. // MArrayDataHandle vals = data.outputArrayValue(attrValues, &status); CHECK_MSTATUS( status ); int indx = 0; int param; char letter; while ((indx = findNextMatch(format, indx, param, letter)) > 0) { double val = 0.; status = vals.jumpToElement(param); if (status == MStatus::kSuccess) { MDataHandle thisVal = vals.inputValue( &status ); if (status == MStatus::kSuccess) { val = thisVal.asDouble(); } } MString replace; bool valid = false; switch (letter) { case 'd': // Integer val = floor(val+.5); // No break here case 'f': // Float replace.set(val); valid = true; break; case 't': // Timecode { const char * sign = ""; if (val<0) { sign = "-"; val = -val; } int valInt = (int)(val+.5); int sec = valInt / 24; int frame = valInt - sec * 24; int min = sec / 60; sec -= min * 60; int hour = min / 60; min -= hour * 60; char buffer[90]; if (hour>0) sprintf(buffer, "%s%d:%02d:%02d.%02d", sign, hour, min, sec, frame); else sprintf(buffer, "%s%02d:%02d.%02d", sign, min, sec, frame); replace = buffer; } valid = true; break; } if (valid) { format = format.substring(0, indx-2) + replace + format.substring(indx+2, format.length()-1); indx += replace.length() - 3; } } // Store the result // MDataHandle output = data.outputValue(attrOutput, &status ); CHECK_MSTATUS( status ); output.set( format ); } else { return MS::kUnknownParameter; } return MS::kSuccess; }
MStatus mtmEnvLight::initialize() { MFnTypedAttribute tAttr; MFnNumericAttribute nAttr; MFnLightDataAttribute lAttr; MFnEnumAttribute eAttr; MFnMessageAttribute mAttr; MStatus stat; //aColor = nAttr.createColor( "color", "c" ); //CHECK_MSTATUS ( nAttr.setKeyable(true) ); //CHECK_MSTATUS ( nAttr.setStorable(true) ); //CHECK_MSTATUS ( nAttr.setDefault(0.0f, 0.58824f, 0.644f) ); aLightColor = nAttr.createColor( "lightColor", "lightColor" ); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); nAttr.setDefault(0.7f, 0.58824f, 0.344f); aShadowColor = nAttr.createColor( "shadowColor", "sc" ); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setDefault(0.0f, 0.0f, 0.0f) ); aPosition = nAttr.createPoint( "position", "pos" ); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); aInputDirection = nAttr.createPoint( "inputDirection", "id" ); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setDefault(-1.0f, 0.0f, 0.0f) ); aInputAmbient = nAttr.create( "ambientOn", "an", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setHidden(false) ); CHECK_MSTATUS ( nAttr.setDefault(true) ); aInputDiffuse = nAttr.create( "emitDiffuse", "dn", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setHidden(false) ); CHECK_MSTATUS ( nAttr.setDefault(true) ); aInputSpecular = nAttr.create( "emitSpecular", "sn", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setHidden(false) ); CHECK_MSTATUS ( nAttr.setDefault(true) ); aIntensity = nAttr.create( "intensity", "i", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setKeyable(true) ); CHECK_MSTATUS ( nAttr.setStorable(true) ); CHECK_MSTATUS ( nAttr.setHidden(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f) ); samplingquality = nAttr.create( "samplingquality", "samplingquality", MFnNumericData::kFloat, 1.0); envmap = tAttr.create( "envmap", "envmap", MFnNumericData::kString); tAttr.setUsedAsFilename(true); areamap = tAttr.create( "areamap", "areamap", MFnNumericData::kString); tAttr.setUsedAsFilename(true); areafullsphere = nAttr.create( "areafullsphere", "areafullsphere", MFnNumericData::kBoolean, true); envintensity = nAttr.createColor( "envintensity", "envintensity" ); nAttr.setDefault(1.0f, 1.0f, 1.0f); raybackground = nAttr.create( "raybackground", "raybackground", MFnNumericData::kBoolean, false); castshadow = nAttr.create( "castshadow", "castshadow", MFnNumericData::kBoolean, true); envtype = eAttr.create( "envtype", "envtype", 0, &stat); stat = eAttr.addField( "Direct Lighting", 0 ); stat = eAttr.addField( "Ambient Occlusion", 1 ); stat = eAttr.addField( "Full Irradiance", 2 ); stat = eAttr.addField( "Raytrace Background", 3 ); eAttr.setDefault(0); doraysamples = nAttr.create( "doraysamples", "doraysamples", MFnNumericData::kBoolean, false); doadaptive = nAttr.create( "doadaptive", "doadaptive", MFnNumericData::kBoolean, false); domaxdist = nAttr.create( "domaxdist", "domaxdist", MFnNumericData::kBoolean, false); maxdist = nAttr.create( "maxdist", "maxdist", MFnNumericData::kFloat, 10.0); coneangle = nAttr.create( "coneangle", "coneangle", MFnNumericData::kFloat, 45.0); envtint = nAttr.createColor( "envtint", "envtint" ); nAttr.setDefault(1.0f, 1.0f, 1.0f); shadowI = nAttr.create( "shadowI", "shadowI", MFnNumericData::kFloat, 1.0); samples = nAttr.create( "samples", "samples", MFnNumericData::kInt, 32); MFnStringData fnStringData; MObject defaultObjectMask; defaultObjectMask = fnStringData.create( "*" ); objectmask = tAttr.create( "objectmask", "objectmask", MFnNumericData::kString, defaultObjectMask); usePortalGeometry = nAttr.create( "usePortalGeometry", "usePortalGeometry", MFnNumericData::kBoolean, false); portalGeometry = mAttr.create( "portalGeometry", "portalGeometry"); mAttr.setConnectable(true); mAttr.accepts(MFnData::kAny); // Outputs aLightDirection = nAttr.createPoint( "lightDirection", "ld" ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(-1.0f, 0.0f, 0.0f) ); aLightIntensity = nAttr.createColor( "lightIntensity", "li" ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(1.0f, 0.5f, 0.2f) ); aLightAmbient = nAttr.create( "lightAmbient", "la", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); nAttr.setDefault(true); aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(true) ); aLightSpecular = nAttr.create( "lightSpecular", "ls", MFnNumericData::kBoolean); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(true) ); aLightShadowFraction = nAttr.create("lightShadowFraction","lsf", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(0.0f) ); aPreShadowIntensity = nAttr.create("preShadowIntensity","psi", MFnNumericData::kFloat); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( nAttr.setDefault(0.0f) ); aLightBlindData = nAttr.createAddr("lightBlindData","lbld"); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightData = lAttr.create( "lightData", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS ( lAttr.setStorable(false) ); CHECK_MSTATUS ( lAttr.setHidden(true) ); lAttr.setDefault(-1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.2f, true, true, true, 0.0f, 1.0f, NULL); CHECK_MSTATUS ( addAttribute(coneangle) ); CHECK_MSTATUS ( addAttribute(samples) ); CHECK_MSTATUS ( addAttribute(objectmask) ); CHECK_MSTATUS ( addAttribute(shadowI) ); CHECK_MSTATUS ( addAttribute(envtint) ); CHECK_MSTATUS ( addAttribute(maxdist) ); CHECK_MSTATUS ( addAttribute(domaxdist) ); CHECK_MSTATUS ( addAttribute(doadaptive) ); CHECK_MSTATUS ( addAttribute(doraysamples) ); CHECK_MSTATUS ( addAttribute(envtype) ); CHECK_MSTATUS ( addAttribute(castshadow) ); CHECK_MSTATUS ( addAttribute(raybackground) ); CHECK_MSTATUS ( addAttribute(envintensity) ); CHECK_MSTATUS ( addAttribute(areafullsphere) ); CHECK_MSTATUS ( addAttribute(areamap) ); CHECK_MSTATUS ( addAttribute(envmap) ); CHECK_MSTATUS ( addAttribute(samplingquality) ); CHECK_MSTATUS ( addAttribute(usePortalGeometry) ); CHECK_MSTATUS ( addAttribute(portalGeometry) ); //CHECK_MSTATUS ( addAttribute(aColor) ); CHECK_MSTATUS ( addAttribute(aLightColor) ); CHECK_MSTATUS ( addAttribute(aShadowColor) ); CHECK_MSTATUS ( addAttribute(aPosition) ); CHECK_MSTATUS ( addAttribute(aInputDirection) ); CHECK_MSTATUS ( addAttribute(aInputAmbient) ); CHECK_MSTATUS ( addAttribute(aInputDiffuse) ); CHECK_MSTATUS ( addAttribute(aInputSpecular) ); CHECK_MSTATUS ( addAttribute(aIntensity) ); CHECK_MSTATUS ( addAttribute(aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightIntensity, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightDirection, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightAmbient, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightDiffuse, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightSpecular, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightShadowFraction, aLightData) ); CHECK_MSTATUS ( attributeAffects (aPreShadowIntensity, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightBlindData, aLightData) ); CHECK_MSTATUS ( attributeAffects (aLightData, aLightData) ); //CHECK_MSTATUS ( attributeAffects (aColor, aLightData) ); CHECK_MSTATUS ( attributeAffects (aPosition, aLightData) ); CHECK_MSTATUS ( attributeAffects (aInputDirection, aLightData) ); CHECK_MSTATUS ( attributeAffects (aInputAmbient, aLightData) ); CHECK_MSTATUS ( attributeAffects (aInputDiffuse, aLightData) ); CHECK_MSTATUS ( attributeAffects (aInputSpecular, aLightData) ); CHECK_MSTATUS ( attributeAffects (aIntensity, aLightData) ); return MS::kSuccess; }
MStatus lambert::initialize() { MFnNumericAttribute nAttr; MFnLightDataAttribute lAttr; MStatus status; // Status will be used to hold the MStatus value // returned by each api function call. It is important // to check the status returned by a call to aid in // debugging. Failed API calls can result in subtle // errors that can be difficult to track down, you may // wish to use the CHECK_MSTATUS macro for any API // call where you do not need to provide your own // error handling. // // Attribute Initialization: // // create - The create function creates a new attribute for the // node, it takes a long name for the attribute, a short // name for the attribute, the type of the attribute, // and a status object to determine if the api call was // successful. // // setKeyable - Sets whether this attribute should accept keyframe // data, Attributes are not keyable by default. // // setStorable - Sets whether this attribute should be storable. If an // attribute is storable, then it will be writen out // when the node is stored to a file. Attributes are // storable by default. // // setDefault - Sets the default value for this attribute. // // setUsedAsColor - Sets whether this attribute should be presented as // a color in the UI. // // setHidden - Sets whether this attribute should be hidden from the // UI. This is useful if the attribute is being used for // blind data, or if it is being used as scratch space // for a geometry calculation (should also be marked // non-connectable in that case). Attributes are not // hidden by default. // // setReadable - Sets whether this attribute should be readable. If an // attribute is readable, then it can be used as the // source in a dependency graph connection. Attributes // are readable by default. // // setWritable - Sets whether this attribute should be readable. If an // attribute is writable, then it can be used as the // destination in a dependency graph connection. If an // attribute is not writable then setAttr commands will // fail to change the attribute. If both keyable and // writable for an attribute are set to true it will be // displayed in the channel box when the node is // selected. Attributes are writable by default. // // setArray - Sets whether this attribute should have an array of // data. This should be set to true if the attribute // needs to accept multiple incoming connections. // Attributes are single elements by default. // // Input Attributes // aTranslucenceCoeff = nAttr.create( "translucenceCoeff", "tc", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aDiffuseReflectivity = nAttr.create( "diffuseReflectivity", "drfl", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.8f ) ); aColorR = nAttr.create( "colorR", "cr",MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aColorG = nAttr.create( "colorG", "cg", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.58824f ) ); aColorB = nAttr.create( "colorB", "cb",MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.644f ) ); aColor = nAttr.create( "color", "c", aColorR, aColorG, aColorB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.58824f, 0.644f ) ); CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); aIncandescenceR = nAttr.create( "incandescenceR", "ir", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aIncandescenceG = nAttr.create( "incandescenceG", "ig", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aIncandescenceB = nAttr.create( "incandescenceB", "ib", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); aIncandescence = nAttr.create( "incandescence", "ic", aIncandescenceR, aIncandescenceG, aIncandescenceB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); aInTransR = nAttr.create( "transparencyR", "itr", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); aInTransG = nAttr.create( "transparencyG", "itg", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); aInTransB = nAttr.create( "transparencyB", "itb", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); aInTransparency = nAttr.create( "transparency", "it", aInTransR, aInTransG, aInTransB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setKeyable( true ) ); CHECK_MSTATUS( nAttr.setStorable( true ) ); CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); // Output Attributes // // Color Output // aOutColorR = nAttr.create( "outColorR", "ocr", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutColorG = nAttr.create( "outColorG", "ocg", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutColorB = nAttr.create( "outColorB", "ocb", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutColor = nAttr.create( "outColor", "oc", aOutColorR, aOutColorG, aOutColorB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setHidden( false ) ); CHECK_MSTATUS( nAttr.setReadable( true ) ); CHECK_MSTATUS( nAttr.setWritable( false ) ); // Transparency Output // aOutTransR = nAttr.create( "outTransparencyR", "otr", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutTransG = nAttr.create( "outTransparencyG", "otg", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutTransB = nAttr.create( "outTransparencyB", "otb", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); aOutTransparency = nAttr.create( "outTransparency", "ot", aOutTransR,aOutTransG,aOutTransB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setHidden( false ) ); CHECK_MSTATUS( nAttr.setReadable( true ) ); CHECK_MSTATUS( nAttr.setWritable( false ) ); // Camera Normals // aNormalCameraX = nAttr.create( "normalCameraX", "nx", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCameraY = nAttr.create( "normalCameraY", "ny", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCameraZ = nAttr.create( "normalCameraZ", "nz", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aNormalCamera = nAttr.create( "normalCamera","n", aNormalCameraX, aNormalCameraY, aNormalCameraZ, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( nAttr.setStorable( false ) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); CHECK_MSTATUS( nAttr.setHidden( true ) ); // Light Direction // aLightDirectionX = nAttr.create( "lightDirectionX", "ldx", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirectionY = nAttr.create( "lightDirectionY", "ldy", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirectionZ = nAttr.create( "lightDirectionZ", "ldz", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightDirection = nAttr.create( "lightDirection", "ld", aLightDirectionX, aLightDirectionY, aLightDirectionZ, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); // Light Intensity // aLightIntensityR = nAttr.create( "lightIntensityR", "lir", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensityG = nAttr.create( "lightIntensityG", "lig", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensityB = nAttr.create( "lightIntensityB", "lib", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightIntensity = nAttr.create( "lightIntensity", "li", aLightIntensityR, aLightIntensityG, aLightIntensityB, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); // Light // aLightAmbient = nAttr.create( "lightAmbient", "la", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( true ) ); aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( true ) ); aLightSpecular = nAttr.create( "lightSpecular", "ls", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( false ) ); aLightShadowFraction = nAttr.create( "lightShadowFraction", "lsf", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aPreShadowIntensity = nAttr.create( "preShadowIntensity", "psi", MFnNumericData::kFloat, 0, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); aLightBlindData = nAttr.createAddr( "lightBlindData", "lbld", &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS ( nAttr.setStorable(false) ); CHECK_MSTATUS ( nAttr.setHidden(true) ); CHECK_MSTATUS ( nAttr.setReadable(true) ); CHECK_MSTATUS ( nAttr.setWritable(false) ); aLightData = lAttr.create( "lightDataArray", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData, &status ); CHECK_MSTATUS( status ); CHECK_MSTATUS( lAttr.setArray( true ) ); CHECK_MSTATUS( lAttr.setStorable( false ) ); CHECK_MSTATUS( lAttr.setHidden( true ) ); CHECK_MSTATUS( lAttr.setDefault( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, false, 1.0f, 1.0f, NULL ) ); // Next we will add the attributes we have defined to the node // CHECK_MSTATUS( addAttribute( aTranslucenceCoeff ) ); CHECK_MSTATUS( addAttribute( aDiffuseReflectivity ) ); CHECK_MSTATUS( addAttribute( aColor ) ); CHECK_MSTATUS( addAttribute( aIncandescence ) ); CHECK_MSTATUS( addAttribute( aInTransparency ) ); CHECK_MSTATUS( addAttribute( aOutColor ) ); CHECK_MSTATUS( addAttribute( aOutTransparency ) ); CHECK_MSTATUS( addAttribute( aNormalCamera ) ); // Only add the parent of the compound CHECK_MSTATUS( addAttribute( aLightData ) ); // The attributeAffects() method is used to indicate when the input // attribute affects the output attribute. This knowledge allows Maya // to optimize dependencies in the graph in more complex nodes where // there may be several inputs and outputs, but not all the inputs // affect all the outputs. // CHECK_MSTATUS( attributeAffects( aTranslucenceCoeff, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aDiffuseReflectivity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aColorR, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aColorG, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aColorB, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aColor, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aInTransR, aOutTransparency ) ); CHECK_MSTATUS( attributeAffects( aInTransG, aOutTransparency ) ); CHECK_MSTATUS( attributeAffects( aInTransB, aOutTransparency ) ); CHECK_MSTATUS( attributeAffects( aInTransparency, aOutTransparency ) ); CHECK_MSTATUS( attributeAffects( aInTransparency, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aIncandescenceR, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aIncandescenceG, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aIncandescenceB, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aIncandescence, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityR, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityB, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensityG, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightIntensity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraX, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraY, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCameraZ, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aNormalCamera, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionX, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionY, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirectionZ, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDirection, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightAmbient, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightSpecular, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightDiffuse, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightShadowFraction, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aPreShadowIntensity, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightBlindData, aOutColor ) ); CHECK_MSTATUS( attributeAffects( aLightData, aOutColor ) ); return( MS::kSuccess ); }
// Attributes initialisation MStatus DA_GridGenerator::initialize() { MStatus stat; MFnCompoundAttribute cAttr; MFnNumericAttribute nAttr; MFnEnumAttribute eAttr; MFnTypedAttribute tAttr; // // Controls // aWidth = nAttr.create("width", "w", MFnNumericData::kDouble, 1.0); nAttr.setMin(0.001); nAttr.setChannelBox(true); nAttr.setKeyable(true); stat = addAttribute(aWidth); CHECK_MSTATUS(stat); aHeight = nAttr.create("height", "h", MFnNumericData::kDouble, 1.0); nAttr.setMin(0.001); nAttr.setChannelBox(true); nAttr.setKeyable(true); stat = addAttribute(aHeight); CHECK_MSTATUS(stat); aResolutionX = nAttr.create("resolutionX", "resx", MFnNumericData::kInt, 10); nAttr.setMin(2); nAttr.setChannelBox(true); nAttr.setKeyable(true); aResolutionY = nAttr.create("resolutionY", "resy", MFnNumericData::kInt, 10); nAttr.setMin(2); nAttr.setChannelBox(true); nAttr.setKeyable(true); aResolution = cAttr.create("resolution", "res"); stat = cAttr.addChild(aResolutionX); CHECK_MSTATUS(stat); stat = cAttr.addChild(aResolutionY); CHECK_MSTATUS(stat); stat = addAttribute(aResolution); CHECK_MSTATUS(stat); aPattern = eAttr.create("pattern","pat",0); eAttr.addField(DA_GridGeneratorPatterns::NONE, 0); eAttr.addField(DA_GridGeneratorPatterns::BRICK_U, 1); eAttr.addField(DA_GridGeneratorPatterns::BRICK_V, 2); eAttr.setChannelBox(true); eAttr.setKeyable(true); stat = addAttribute(aPattern); CHECK_MSTATUS(stat); // // Outputs // aOutDynamicArray = tAttr.create("outDynamicArray", "oda", MFnData::kDynArrayAttrs); tAttr.setWritable(false); // Just output stat = addAttribute(aOutDynamicArray); CHECK_MSTATUS(stat); // // Attributes affects // attributeAffects(aWidth, aOutDynamicArray); attributeAffects(aHeight, aOutDynamicArray); attributeAffects(aResolutionX, aOutDynamicArray); attributeAffects(aResolutionY, aOutDynamicArray); attributeAffects(aPattern, aOutDynamicArray); // Done return stat; }