Example #1
0
MStatus polyModifierCmd::cacheMeshData()
{
	MStatus status = MS::kSuccess;

	MFnDependencyNode depNodeFn;
	MFnDagNode dagNodeFn;

	MObject meshNode = fDagPath.node();
	MObject dupMeshNode;
	MPlug dupMeshNodeOutMeshPlug;

	// Duplicate the mesh
	//
	dagNodeFn.setObject( meshNode );
	dupMeshNode = dagNodeFn.duplicate();

	MDagPath dupMeshDagPath;
	MDagPath::getAPathTo( dupMeshNode, dupMeshDagPath );
	dupMeshDagPath.extendToShape();

	depNodeFn.setObject( dupMeshDagPath.node() );
	dupMeshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status );
	MCheckStatus( status, "Could not retrieve outMesh" );

	// Retrieve the meshData
	//
	status = dupMeshNodeOutMeshPlug.getValue( fMeshData );
	MCheckStatus( status, "Could not retrieve meshData" );

	// Delete the duplicated node
	//
	MGlobal::deleteNode( dupMeshNode );

	return status;
}
Example #2
0
//############################################### tima:
bool polyModifierCmd::setZeroTweaks()
{
	MFnNumericData numDataFn;
	MObject nullVector;
	MFnDependencyNode depNodeFn;

	numDataFn.create( MFnNumericData::k3Float );
	numDataFn.setData( 0, 0, 0 );
	nullVector = numDataFn.object();

	MObject object = fDagPath.node();
	depNodeFn.setObject( object);
	MPlug meshTweakPlug = depNodeFn.findPlug( "pnts" );
	MPlug tweak;

	unsigned numTweaks = fTweakIndexArray.length();

	if( !meshTweakPlug.isNull() )
	{
		for( unsigned i = 0; i < numTweaks; i++ )
		{
			tweak = meshTweakPlug.elementByLogicalIndex( fTweakIndexArray[i] );
			tweak.setValue( nullVector );
		}
	}
	
	return true;
}
Example #3
0
bool
PxrUsdMayaWriteUtil::ReadMayaAttribute(
        const MFnDependencyNode& depNode,
        const MString& name,
        VtVec3fArray* val)
{
    MStatus status;
    depNode.attribute(name, &status);

    if (status == MS::kSuccess) {
        MPlug plug = depNode.findPlug(name);
        MObject dataObj;

        if ( (plug.getValue(dataObj) == MS::kSuccess) &&
             (dataObj.hasFn(MFn::kVectorArrayData)) ) {

            MFnVectorArrayData dData(dataObj, &status);
            if (status == MS::kSuccess) {
                MVectorArray arrayValues = dData.array();
                size_t numValues = arrayValues.length();
                val->resize(numValues);
                for (size_t i = 0; i < numValues; ++i) {
                    (*val)[i].Set(
                            arrayValues[i][0],
                            arrayValues[i][1],
                            arrayValues[i][2]);
                }
                return true;
            }
        }
    }

    return false;
}
Example #4
0
void EntityNode::UnloadArt()
{
    MStatus stat;

    // remove anything currently imported/referenced
    MFnDagNode dagFn( thisMObject() );
    while( dagFn.childCount() )
    {
        stat = MGlobal::deleteNode( dagFn.child( 0 ) );
        MContinueErr( stat, ("Unable to delete" + dagFn.fullPathName() ).asChar() );
    }

    ClearInstances();

    MObjectArray forDelete;
    GetImportNodes( forDelete );
    MFnDependencyNode depFn;

    u32 num = forDelete.length();
    for( u32 i = 0; i < num; ++i )
    {
        MObject& node = forDelete[i];

        MObjectHandle handle( node );
        if( !handle.isValid() )
            continue;

        depFn.setObject( node );

        stat = MGlobal::deleteNode( node );
        MContinueErr( stat, ("Unable to delete" + depFn.name() ).asChar() );
    }

    forDelete.clear();
}
Example #5
0
void ExtractAttribute(MFnDependencyNode& fn, std::string name, SMatAttrib& attrib)
{
	MPlug p;

	// extract attribute color
	std::string r = name + "R";
	std::string g = name + "G";
	std::string b = name + "B";

	p = fn.findPlug(r.c_str());	p.getValue(attrib.color[0]);
	p = fn.findPlug(g.c_str());	p.getValue(attrib.color[1]);
	p = fn.findPlug(b.c_str());	p.getValue(attrib.color[2]);

	// extract attribute texture
	MString texname;

	p = fn.findPlug(name.c_str());
	
	MPlugArray plugs;
	p.connectedTo(plugs,true,true);

	for(int i = 0; i != plugs.length(); ++i)
	{
		if (plugs[i].node().apiType() == MFn::kFileTexture) 
		{
			MFnDependencyNode fnDep(plugs[i].node());
			texname = fnDep.name();
			break;
		}
	}

	attrib.textureID = GetTextureID( texname );
}
    //---------------------------------------------------
    bool DagHelper::connectToList ( const MPlug& source, const MObject& destination, const MString& destinationAttribute, int* _index )
    {
        MStatus status;
        MFnDependencyNode destFn ( destination );
        MPlug dest = destFn.findPlug ( destinationAttribute, &status );

        if ( status != MStatus::kSuccess ) return false;

        if ( !dest.isArray() ) return false;

        int index = ( _index != NULL ) ? *_index : -1;

        if ( index < 0 )
        {
            index = getNextAvailableIndex ( dest, ( int ) dest.evaluateNumElements() );

            if ( _index != NULL ) *_index = index;
        }

        MPlug d = dest.elementByLogicalIndex ( index );

        MDGModifier modifier;
        modifier.connect ( source, d );
        status = modifier.doIt();
        return status == MStatus::kSuccess;
    }
	void AttributeParser::parseAttributes(MFnDependencyNode & fnNode, AttributeParser & parser)
	{
		MStatus status;
		unsigned int attrCount = fnNode.attributeCount(&status);
        if (!status) return;
        std::set<String> parsedAttributes;
		for (unsigned int attrIndex = 0; attrIndex < attrCount; ++attrIndex)
		{
			MObject attrObject = fnNode.attribute(attrIndex, &status);
            if (!status) continue;

			MFnAttribute fnAttr(attrObject, &status);
			if (!status) continue;

			MString attrName = fnAttr.name(&status);
            if (!status) continue;

            // Don't parse the same attribute twice.
            // This can happen with compound attributes.
            String attrNameStr = attrName.asChar();
            if (parsedAttributes.find(attrNameStr) != parsedAttributes.end()) {
                continue;
            }
            parsedAttributes.insert(attrNameStr);

			parser.parseAttribute(fnNode, attrObject, parsedAttributes);
		}
	}
Example #8
0
// --------------------------------------------------------------------------------------------
void polyModifierCmd::collectNodeState()
// --------------------------------------------------------------------------------------------
{
	MStatus status;

	// Collect node state information on the given polyMeshShape
	//
	// - HasHistory (Construction History exists)
	// - HasTweaks
	// - HasRecordHistory (Construction History is turned on)
	//
	fDagPath.extendToShape();
	MObject meshNodeShape = fDagPath.node();

	MFnDependencyNode depNodeFn;
	depNodeFn.setObject( meshNodeShape );

	MPlug inMeshPlug = depNodeFn.findPlug( "inMesh" );
	fHasHistory = inMeshPlug.isConnected();

	// Tweaks exist only if the multi "pnts" attribute contains plugs
	// which contain non-zero tweak values. Use false, until proven true
	// search algorithm.
	//
	fHasTweaks = false;
	MPlug tweakPlug = depNodeFn.findPlug( "pnts" );
	if( !tweakPlug.isNull() )
	{
		// ASSERT: tweakPlug should be an array plug!
		//
		MAssert( (tweakPlug.isArray()),
				 "tweakPlug.isArray() -- tweakPlug is not an array plug" );

		MPlug tweak;
		MFloatVector tweakData;
		int i;
		int numElements = tweakPlug.numElements();

		for( i = 0; i < numElements; i++ )
		{
			tweak = tweakPlug.elementByPhysicalIndex( i, &status );
			if( status == MS::kSuccess && !tweak.isNull() )
			{
				getFloat3PlugValue( tweak, tweakData );
				if( 0 != tweakData.x ||
					0 != tweakData.y ||
					0 != tweakData.z )
				{
					fHasTweaks = true;
					break;
				}
			}
		}
	}

	int result;
	MGlobal::executeCommand( "constructionHistory -q -tgl", result );
	fHasRecordHistory = (0 != result);
}
Example #9
0
MStatus PRTAttrs::addParameter(MFnDependencyNode & node, MObject & attr, MFnAttribute& tAttr) {
	if(!(node.hasAttribute(tAttr.shortName()))) {
		MCHECK(tAttr.setKeyable (true));
		MCHECK(tAttr.setHidden(false));
		MCHECK(tAttr.setStorable(true));
		MCHECK(node.addAttribute(attr));
	}
	return MS::kSuccess;
}
 //---------------------------
 String DocumentExporter::dagPathToColladaName ( const MDagPath& dagPath )
 {
     // Get a COLLADA suitable node name from a DAG path
     // For import/export symmetry, this should be exactly the
     // Maya node name. If we include any more of the path, we'll
     // get viral node names after repeated import/export.
     MFnDependencyNode node ( dagPath.node() );
     return mayaNameToColladaName ( node.name(), true );
 }
Example #11
0
std::string CMayaNode::GetName()
{
    MStatus status;
    MFnDependencyNode	depNode (m_dagPath.node(), &status);
    if (status != MS::kSuccess)
        return "";

    return depNode.name ().asChar();
}
void Exporter::extractColor(Color& tempcolor, MFnDependencyNode& fn, MString name)
{
	MPlug p;

	MString r = name;
	r += "R";
	MString g = name;
	g += "G";
	MString b = name;
	b += "B";
	MString a = name;
	a += "A";

	p = fn.findPlug(r.asChar());
	p.getValue(tempcolor.r);
	p = fn.findPlug(g.asChar());
	p.getValue(tempcolor.g);
	p = fn.findPlug(b.asChar());
	p.getValue(tempcolor.b);
	p = fn.findPlug(a.asChar());
	p.getValue(tempcolor.a);
	p = fn.findPlug(name.asChar());

	MPlugArray connections;
	p.connectedTo(connections, true, false);

	int debug = connections.length();

	for (int i = 0; i != connections.length(); ++i)
	{
		// if file texture found
		if (connections[i].node().apiType() == MFn::kFileTexture)
		{
			// bind a function set to it ....
			MFnDependencyNode fnDep(connections[i].node());

			// to get the node name
			tempcolor.texfileInternal = fnDep.name().asChar();
			MPlug filename = fnDep.findPlug("ftn");

			//sparar hela s�kv�gen till texturen
			tempcolor.texfileExternal = filename.asString().asChar();

			//kopierar texturfiler
			std::string base_filename = tempcolor.texfileExternal.substr(tempcolor.texfileExternal.find_last_of("/\\") + 1);

			CopyFile(tempcolor.texfileExternal.c_str(), base_filename.c_str(), false);

			// stop looping
			break;
		}

	}

}
Example #13
0
MStatus polyModifierCmd::processModifierNode( MObject modifierNode,
											  modifyPolyData& data )
{
	MStatus status = MS::kSuccess;

	MFnDependencyNode depNodeFn ( modifierNode );
	data.modifierNodeSrcAttr = depNodeFn.attribute( "outMesh" );
	data.modifierNodeDestAttr = depNodeFn.attribute( "inMesh" );

	return status;
}
    //---------------------------------------------------
    MObject DagHelper::createExpression ( const MPlug& plug, const MString& expression )
    {
        MFnDependencyNode expressionFn;
        MObject expressionObj = expressionFn.create ( "expression" );
        DagHelper::setPlugValue ( expressionObj, "expression", expression );

        MPlug output = expressionFn.findPlug ( "output" );
        MPlug firstOutput = output.elementByLogicalIndex ( 0 );
        DagHelper::connect ( firstOutput, plug );
        return expressionObj;
    }
    //---------------------------------------------------
    bool DagHelper::connectToList ( const MObject& source, const MString& sourceAttribute, const MObject& destination, const MString& destinationAttribute, int* index )
    {
        MStatus status;
        MFnDependencyNode srcFn ( source );

        MPlug src = srcFn.findPlug ( sourceAttribute, &status );

        if ( status != MStatus::kSuccess ) return false;

        return connectToList ( src, destination, destinationAttribute, index );
    }
    //---------------------------------------
    void MaterialExporter::exportCustomHwShaderNode( 
        COLLADASW::InstanceEffect &effectInstance, 
        MObject shader )
    {
        MFnDependencyNode fnNode ( shader );
        if ( fnNode.typeId() == cgfxShaderNode::sId ) 
        {
            // Add the technique hint and the effect attributes to the collada document.
            exportCgfxShaderNode ( effectInstance, (cgfxShaderNode*) fnNode.userNode () );
        }

    }
Example #17
0
MString AppleseedRenderer::defineColor(MFnDependencyNode& shader, MString& attributeName, MString colorSpace = "srgb", float intensity = 1.0f)
{
	MColor col(0,0,0);
	if(!getColor(attributeName, shader, col))
	{
		logger.error(MString("Unable to get color values from node: ") + shader.name());
		return "";
	}
	MString colorName = shader.name() + "_" + attributeName;
	defineColor(colorName, col, intensity, colorSpace);
	return colorName;
}
    //---------------------------------------------------
    // set the bind pose for a transform
    //
    MStatus DagHelper::setBindPoseInverse ( const MObject& node, const MMatrix& bindPoseInverse )
    {
        MStatus status;
        MFnDependencyNode dgFn ( node );
        MPlug bindPosePlug = dgFn.findPlug ( "bindPose", &status );
        if ( status != MS::kSuccess )
        {
            MGlobal::displayWarning ( MString ( "No bindPose found on node " ) + dgFn.name() );
            return status;
        }

        MFnMatrixData matrixFn;
        MObject val = matrixFn.create ( bindPoseInverse.inverse(), &status );
        MObject invval = matrixFn.create ( bindPoseInverse, &status );
        if ( status != MS::kSuccess )
        {
            MGlobal::displayWarning ( MString ( "Error setting bindPose on node " ) + dgFn.name() );
            return status;
        }

        // set the bind pose on the joint itself
        bindPosePlug.setValue ( val );

        // Now, perhaps more significantly, see if there's a
        // skinCluster using this bone and update its bind
        // pose (as the joint bind pose is not connected to
        // the skin - it's set at bind time from the joint's
        // current position, and our importer may not want to
        // disturb the current scene state just to put bones
        // in a bind position before creating skin clusters)
        MObject _node ( node );
        MItDependencyGraph it ( _node, MFn::kSkinClusterFilter );
        while ( !it.isDone() )
        {
            MPlug plug = it.thisPlug();
            unsigned int idx = plug.logicalIndex();
            MFnDependencyNode skinFn ( plug.node() );
            MPlug skinBindPosePlug = skinFn.findPlug ( "bindPreMatrix", &status );

            if ( status == MS::kSuccess )
            {
                // The skinCluster stores inverse inclusive matrix
                // so notice we use invval (the MObject created off
                // the inverse matrix here)
                skinBindPosePlug = skinBindPosePlug.elementByLogicalIndex ( idx );
                skinBindPosePlug.setValue ( invval );
            }

            it.next();
        }

        return status;
    }
    //---------------------------------------------------
    MObject DagHelper::createAnimationCurve ( const MPlug& plug, const char* curveType )
    {
        MStatus rc;
        MFnDependencyNode curveFn;
        curveFn.create ( curveType, &rc );

        if ( rc == MStatus::kSuccess )
        {
            DagHelper::connect ( curveFn.object(), "output", plug );
        }

        return curveFn.object();
    }
    // -------------------------------------------
    const String& SceneElement::getNodeName() const
    {
        if ( mNodeName.empty() )
        {
            const MObject & _node = getNode();

            // Attach a function set
            MFnDependencyNode fn ( _node );
            mNodeName = DocumentExporter::mayaNameToColladaName ( fn.name() );
        }

        return mNodeName;
    }
    //---------------------------------------------------
    MPlug DagHelper::addAttribute ( const MObject& node, const MObject& attribute )
    {
        MPlug plug;
        MFnAttribute attributeFn ( attribute );
        MFnDependencyNode depFn ( node );
        MStatus status = depFn.addAttribute ( attribute, MFnDependencyNode::kLocalDynamicAttr );
        if ( status == MStatus::kSuccess )
        {
            plug = depFn.findPlug ( attribute );
        }

        return plug;
    }
// --------------------------------------------------------
COLLADASW::PrimitivesBase* GeometryPolygonExporter::preparePrimitivesBase(
    const MFnMesh &fnMesh,
    const uint numPolygons,
    const uint exportType )
{
    // Just create a polylist, if there are polygons to export
    // If we have holes in the polygon, we have to use <polygons> instead of <polylist>.
    // If we want to export as triangles, we have to use <triangles>.
    COLLADASW::PrimitivesBase* primitivesBasePoly = createPrimitivesBase ( exportType );

    // Begin to write.
    primitivesBasePoly->openPrimitiveElement();

    // Check if the material should be set
    uint realShaderCount = ( uint ) mShaders.length();
    if ( mShaderPosition < realShaderCount )
    {
        // Add shader-specific parameters (TexCoords sets).
        // Add symbolic name for the material used on this polygon set.
        MFnDependencyNode shaderFn ( mShaders[mShaderPosition] );
        String shaderName = shaderFn.name().asChar();
        String materialName = DocumentExporter::mayaNameToColladaName ( shaderFn.name() );
        primitivesBasePoly->appendMaterial ( materialName );
    }

    // Set the number of polygons
    primitivesBasePoly->appendCount ( numPolygons );

    // Get the polygon input list
    COLLADASW::InputList& inputList = primitivesBasePoly->getInputList();
    getPolygonInputAttributes ( inputList );
    primitivesBasePoly->appendInputList();

    // Set the vertex count list, if we have a POLYLIST
    if ( exportType == PolygonSource::POLYLIST )
    {
        // Retrieve the vertex count list for the polylist element.
        primitivesBasePoly->openVertexCountListElement();
        writeVertexCountList ( primitivesBasePoly, fnMesh );
        primitivesBasePoly->closeElement();
    }

    if ( exportType != PolygonSource::POLYGONS )
    {
        // Prepare the list for add the vertex indexes
        primitivesBasePoly->openPolylistElement();
    }

    return primitivesBasePoly;
}
    // ------------------------------------------------------------
    SceneElement* SceneGraph::createSceneElement ( 
        const MDagPath &dagPath,
        SceneElement* parentSceneElement )
    {
        // Create a new scene element
        SceneElement* sceneElement = new SceneElement ( dagPath );

        // Attach a function set
        MFnDependencyNode fn ( dagPath.node() );

        // Check for multiple instances.
        bool isInstanced = dagPath.isInstanced ();
        if ( parentSceneElement == 0 )
        {
//             dagPath.getAllPathsTo ( ) ()
        }

        // Get the node name
        String nodeName = DocumentExporter::mayaNameToColladaName ( fn.name() );
        sceneElement->setNodeName ( nodeName );

        // Check if it's a node to export and
        // tell the scene node to be transformed or not.
        bool isForced = false;
        bool isVisible = false;
        bool isExportNode = getIsExportNode ( dagPath, isForced, isVisible );
        sceneElement->setIsForced ( isForced );
        sceneElement->setIsVisible ( isVisible );

        // Check for a file reference
        MFnDagNode dagFn ( dagPath );
        bool isLocal = !dagFn.isFromReferencedFile();
        if ( ExportOptions::exportXRefs() && ExportOptions::dereferenceXRefs()) isLocal = true;
        if ( !isLocal && !ExportOptions::exportXRefs() ) isExportNode = false;
        sceneElement->setIsExportNode ( isExportNode );
        sceneElement->setIsLocal ( isLocal );

        if ( parentSceneElement != NULL )
        {
            if ( !sceneElement->containsParentElement ( parentSceneElement ) )
                sceneElement->addParentElement ( parentSceneElement );

            if ( !parentSceneElement->containsChildElement ( sceneElement ) )
                parentSceneElement->addChildElement ( sceneElement );
        }

        return sceneElement;
    }
    // ------------------------------------------------------------
    void EffectTextureExporter::addAngleParameter (
        COLLADASW::Texture* colladaTexture,
        const char* plugName,
        MFnDependencyNode &placement2d )
    {
        MStatus status;
        MPlug plug = placement2d.findPlug ( plugName, &status );
        if ( status == MStatus::kSuccess )
        {
            float angleRad;
            plug.getValue ( angleRad );
            float angleDeg = COLLADABU::Math::Utils::radToDegF ( angleRad );

            // The target id for the animation
            String targetSid = mAnimationTargetPath + plugName;

            // Create the animation
            AnimationExporter* animationExporter = mDocumentExporter->getAnimationExporter();
            bool animated = animationExporter->addPlugAnimation ( plug, targetSid, kBoolean );

            // Add the parameter
            String paramSid = EMPTY_STRING; 
            if ( animated ) paramSid = plugName;
            colladaTexture->addExtraTechniqueParameter ( PROFILE_MAYA, plugName, angleDeg, paramSid );
        }
    }
Example #25
0
void ExtractNormalMap(MFnDependencyNode& fn, unsigned int* tex = NULL)
{
	MString texname;

	MPlug p = fn.findPlug( "normalCamera" );
	MPlugArray plugs;
	p.connectedTo(plugs,true,true);

	for(int i = 0; i != plugs.length(); ++i)
	{
		if (plugs[i].node().apiType() == MFn::kBump) 
		{
			MFnDependencyNode fnDepBump( plugs[i].node() );
			MPlug pp = fnDepBump.findPlug( "bumpValue" );

			MPlugArray pplugs;
			pp.connectedTo(pplugs, true, true);
			
			for(int j = 0; j != pplugs.length(); ++j)
			{
				if (pplugs[j].node().apiType() == MFn::kFileTexture) 
				{
					MFnDependencyNode fnDep(pplugs[j].node());
					texname = fnDep.name();
					break;
				}
			}
		}
	}

	*tex = GetTextureID( texname );
}
Example #26
0
// --------------------------------------------------------------------------------------------
MStatus polyModifierCmd::processModifierNode( MObject modifierNode,
											  modifyPolyData& data )
// --------------------------------------------------------------------------------------------
{
	MStatus status = MS::kSuccess;

	MFnDependencyNode depNodeFn ( modifierNode );
	data.modifierNodeSrcAttr = depNodeFn.attribute( "outMesh" , &status);

	MCheckStatus( status, "Finden des outMesh Attributes" );

	data.modifierNodeDestAttr = depNodeFn.attribute( "inMesh" , &status );


	return status;
}
	void ShaderFXShaderExporter::exportSamplerAndSurface(const MFnDependencyNode & node, const MObject & attr)
	{
		MStatus status;

		if (!attr.hasFn(MFn::kTypedAttribute))
			return;

		MFnTypedAttribute fnTypedAttr(attr, &status);
		if (!status) return;

		MFnData::Type type = fnTypedAttr.attrType(&status);
		if (!status) return;

		if (type != MFnData::kString)
			return;

		MPlug plug = node.findPlug(attr, &status);

		MString value;
		status = plug.getValue(value);
		if (!status) return;

		if (value.length() == 0)
			return;

		bool isUsedAsFilename = MFnAttribute(attr).isUsedAsFilename(&status);
		if (!status) return;

		// Filename are treated as texture filenames.
		if (!isUsedAsFilename)
			return;
		
		exportSamplerAndSurfaceInner(value);
	}
Example #28
0
bool getColor(MString& plugName, MFnDependencyNode& dn, MColor& value)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	bool result = false;
	float r, g, b;
	// I suppose the attribute is a color and has 3 children
	MPlug plug = dn.findPlug(plugName, stat);
	if (!stat)
		return result;
	if (plug.numChildren() < 3)
		return result;
	r = plug.child(0).asFloat(ctx, &stat);
	if (!stat)
		return result;
	g = plug.child(1).asFloat(ctx, &stat);
	if (!stat)
		return result;
	b = plug.child(2).asFloat(ctx, &stat);
	if (!stat)
		return result;
	value.r = r;
	value.g = g;
	value.b = b;
	return true;
}
Example #29
0
MStatus PRTAttrs::addColorParameter(MFnDependencyNode & node, MObject & attr, const MString & name, MString & value ) {
	MStatus             stat;
	MFnNumericAttribute nAttr;

	const wchar_t* s = value.asWChar();

	attr = nAttr.createColor(longName(name), briefName(name), &stat );
	MCHECK(stat);

	double r = 0.0;
	double g = 0.0;
	double b = 0.0;

	if (s[0] == '#' && wcslen(s) >= 7) {
		r = (double)((prtu::fromHex(s[1]) << 4) + prtu::fromHex(s[2])) / 255.0;
		g = (double)((prtu::fromHex(s[3]) << 4) + prtu::fromHex(s[4])) / 255.0;
		b = (double)((prtu::fromHex(s[5]) << 4) + prtu::fromHex(s[6])) / 255.0;

		nAttr.setDefault(r, g, b);
	}

	MCHECK(addParameter(node, attr, nAttr));

	MFnNumericData fnData;
	MObject        rgb = fnData.create(MFnNumericData::k3Double, &stat);
	MCHECK(stat);

	fnData.setData(r, g, b);
	MPlug plug(node.object(), attr);
	MCHECK(plug.setValue(rgb));

	return MS::kSuccess;
}
Example #30
0
ATTR_TYPE getPlugAttrType(const char *plugName, MFnDependencyNode& dn)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return ATTR_TYPE::ATTR_TYPE_NONE;

	MObject attObj = plug.attribute(&stat);
	MFnAttribute att(attObj);
	if( !stat )
		return ATTR_TYPE::ATTR_TYPE_NONE;

	if(att.isUsedAsColor())
		return ATTR_TYPE::ATTR_TYPE_COLOR;
	if( attObj.apiType() == MFn::kNumericAttribute)
	{
		MFnNumericAttribute na(attObj, &stat);
		if( !stat )
			return ATTR_TYPE::ATTR_TYPE_NONE;
		if( na.unitType() == MFnNumericData::Type::kFloat )
			return ATTR_TYPE::ATTR_TYPE_FLOAT;
	}
	return ATTR_TYPE::ATTR_TYPE_NONE;
}