Esempio n. 1
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 );
}
Esempio n. 2
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);
}
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;
		}

	}

}
    //---------------------------------------------------------------
    String EffectTextureExporter::exportImage ( const MObject &texture )
    {
        // Retrieve the texture filename
        MFnDependencyNode textureNode ( texture );
        MString mayaName = textureNode.name();
        MPlug filenamePlug = textureNode.findPlug ( ATTR_FILE_TEXTURE_NAME );

        // Get the maya image id.
        String mayaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() );

        // Generate a COLLADA id for the new light object
        String colladaImageId;

        // Check if there is an extra attribute "colladaId" and use this as export id.
        MString attributeValue;
        DagHelper::getPlugValue ( texture, COLLADA_ID_ATTRIBUTE_NAME, attributeValue );
        if ( attributeValue != EMPTY_CSTRING )
        {
            // Generate a valid collada name, if necessary.
            colladaImageId = mDocumentExporter->mayaNameToColladaName ( attributeValue, false );
        }
        else
        {
            // Generate a COLLADA id for the new light object
            colladaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() );
        }
        // Make the id unique and store it in a map for refernences.
        colladaImageId = mImageIdList.addId ( colladaImageId );
        mMayaIdColladaImageId [mayaImageId] = colladaImageId;

        // Get the maya filename with the path to the file.
        MString mayaFileName;
        filenamePlug.getValue ( mayaFileName );
        if ( mayaFileName.length () == 0 ) return NULL;
        String sourceFile = mayaFileName.asChar ();
        COLLADASW::URI sourceFileUri ( COLLADASW::URI::nativePathToUri ( sourceFile ) );
        if ( sourceFileUri.getScheme ().empty () )
            sourceFileUri.setScheme ( COLLADASW::URI::SCHEME_FILE );

        COLLADASW::Image* colladaImage = exportImage ( mayaImageId, colladaImageId, sourceFileUri );
        if ( colladaImage == NULL ) return NULL;

        // Export the node type, because PSD textures don't behave the same as File textures.
        String nodeType = texture.hasFn ( MFn::kPsdFileTexture ) ? MAYA_TEXTURE_PSDTEXTURE : MAYA_TEXTURE_FILETEXTURE;
        colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_NODETYPE, nodeType );

        // Export whether this image is in fact an image sequence
        MPlug imgSeqPlug = textureNode.findPlug ( ATTR_IMAGE_SEQUENCE );
        bool isImgSeq = false;
        imgSeqPlug.getValue ( isImgSeq );
        colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_IMAGE_SEQUENCE, isImgSeq );

        return colladaImage->getImageId();
    }
    //---------------------------------------------------
    // 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;
    }
Esempio n. 6
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;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
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 );
}
Esempio n. 10
0
MString getConnectedFileTexturePath(const MString& plugName, MFnDependencyNode& depFn)
{
    MStatus stat;
    MString path = "";
    MPlug plug = depFn.findPlug(plugName, &stat);
    if (!stat)
        return path;
    if (plug.isConnected())
    {
        MPlugArray parray;
        plug.connectedTo(parray, true, false, &stat);
        if (!stat)
            return path;

        if (parray.length() == 0)
            return path;

        MPlug destPlug = parray[0];
        MObject fileNode = destPlug.node();
        if (!fileNode.hasFn(MFn::kFileTexture))
        {
            return path;
        }

        MFnDependencyNode fileDepFn(fileNode);
        MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat);

        if (!stat)
        {
            return path;
        }
        path = ftn.asString();
    }
    return path;
}
Esempio n. 11
0
void getConnectedChildPlugs(const char *attrName, MFnDependencyNode& depFn, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs)
{
    MPlug p = depFn.findPlug(attrName);
    if (p.isCompound() && !p.isArray())
    {
        getConnectedChildPlugs(p, dest, thisNodePlugs, otherSidePlugs);
        return;
    }
    if (p.isArray())
    {
        for (uint i = 0; i < p.numElements(); i++)
        {
            if (p[i].numConnectedChildren() == 0)
                continue;
            if (!p[i].isCompound())
                getConnectedChildPlugs(p[i], dest, thisNodePlugs, otherSidePlugs);
            else
            {
                if (getAttributeNameFromPlug(p) == MString("colorEntryList"))
                {
                    getConnectedChildPlugs(p[i].child(1), dest, thisNodePlugs, otherSidePlugs);
                }
            }
        }
    }
}
Esempio n. 12
0
static bool
_GetMetadataUnchecked(
    const MFnDependencyNode& node,
    const TfToken& key,
    VtValue* value)
{
    VtValue fallback = SdfSchema::GetInstance().GetFallback(key);
    if (fallback.IsEmpty()) {
        return false;
    }

    std::string mayaAttrName = _GetMayaAttrNameForMetadataKey(key);
    MPlug plug = node.findPlug(mayaAttrName.c_str());
    if (plug.isNull()) {
        return false;
    }

    TfType ty = fallback.GetType();
    VtValue result = UsdMayaWriteUtil::GetVtValue(plug, ty, TfToken());
    if (result.IsEmpty()) {
        TF_RUNTIME_ERROR(
                "Cannot convert plug '%s' into metadata '%s' (%s)",
                plug.name().asChar(),
                key.GetText(),
                ty.GetTypeName().c_str());
        return false;
    }

    *value = result;
    return true;
}
Esempio n. 13
0
MObject getConnectedFileTextureObject(MString& plugName, MFnDependencyNode& depFn)
{
	MStatus stat;
	MString path = "";
	MPlug plug = depFn.findPlug(plugName, &stat);
	if( !stat )
		return MObject::kNullObj;
	if( plug.isConnected())
	{
		MPlugArray parray;
		plug.connectedTo(parray, true, false, &stat);
		if( !stat )
			return MObject::kNullObj;

		if( parray.length() == 0 )
			return MObject::kNullObj;

		MPlug destPlug = parray[0];
		MObject fileNode = destPlug.node();	
		if( !fileNode.hasFn(MFn::kFileTexture) )
		{
			return MObject::kNullObj;
		}else{
			return fileNode;
		}

	}
	return MObject::kNullObj;
}
    // ------------------------------------------------------------
    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 );
        }
    }
    void AttributeParser::parseMatrixAttribute(MFnDependencyNode & node, MObject & attribute)
    {
        MStatus status;

        MFnMatrixAttribute fnMatrixAttribute(attribute, &status);
        if (!status) return;

        MPlug plug = node.findPlug(attribute, &status);
        if (!status) return;

        MPlugArray plugArray;
        bool hasConnection = plug.connectedTo(plugArray, true, false, &status);
        if (!status) return;
        if (hasConnection)
        {
            MPlug externalPlug = plugArray[0];
            bool externalPlugNull = externalPlug.isNull(&status);
            if (!status) return;
            if (!externalPlugNull)
            {
                MFnAttribute fnAttribute(attribute, &status);
                if (!status) return;

                MString name = fnAttribute.name(&status);
                if (!status) return;

                //MObject pluggedObject = externalPlug.node(&status);
                //if (!status) return;

                // TODO pass matrix to callback? onMatrix(...) instead of onConnection(...)?
                onConnection(plug, name, externalPlug);
            }
        }
    }
Esempio n. 16
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;
}
    //---------------------------------------------------
    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 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);
	}
Esempio n. 19
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;
}
    void AttributeParser::parseCompoundAttribute(MFnDependencyNode & node, MObject & attr, std::set<String>& parsedAttributes)
    {
        MStatus status;

        MFnCompoundAttribute fnCompoundAttribute(attr, &status);
        if (!status) return;

        unsigned int numChildren = fnCompoundAttribute.numChildren(&status);
        if (!status) return;

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

        MFnAttribute fnAttr(attr, &status);
        if (!status) return;

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

        onCompoundAttribute(plug, name);

        // Recurse children
        for (unsigned int i = 0; i < fnCompoundAttribute.numChildren(); ++i)
        {
            MObject child = fnCompoundAttribute.child(i, &status);
            if (!status) return;

            MFnAttribute childFnAttr(child);
            parsedAttributes.insert(childFnAttr.name().asChar());

            parseAttribute(node, child, parsedAttributes);
        }
    }
Esempio n. 21
0
bool getFloat2(MString& plugName, MFnDependencyNode& dn, MVector& value)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	bool result = false;
	MPlug plug = dn.findPlug(plugName + "0", &stat);
	if( !stat )
		return false;
	value.x = plug.asFloat(ctx, &stat);
	plug = dn.findPlug(plugName + "1", &stat);
	if( !stat )
		return false;
	value.y = plug.asFloat(ctx, &stat);
	if(stat)
		return true;
	return result;
}
Esempio n. 22
0
int getIntAttr(const char *plugName, MFnDependencyNode& dn, int defaultValue)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return defaultValue;
	return plug.asInt(ctx, &stat);
}
Esempio n. 23
0
MString getString(const char *plugName, MFnDependencyNode& dn)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return "";
	return plug.asString(ctx, &stat);
}
void NifTextureConnector::ConnectTexture( MDagPath mesh_path ) {
	MDGModifier dgModifier;
	MFnDependencyNode chooserFn;
	chooserFn.create( "uvChooser", "uvChooser" );

	//Connection between the mesh and the uvChooser
	MFnMesh meshFn;
	meshFn.setObject(mesh_path);
	dgModifier.connect( meshFn.findPlug("uvSet")[uvSet].child(0), chooserFn.findPlug("uvSets").elementByLogicalIndex(0) );

	//Connections between the uvChooser and the place2dTexture
	dgModifier.connect( chooserFn.findPlug("outUv"), texturePlacement.findPlug("uvCoord") );
	dgModifier.connect( chooserFn.findPlug("outVertexCameraOne"), texturePlacement.findPlug("vertexCameraOne") );
	dgModifier.connect( chooserFn.findPlug("outVertexUvOne"), texturePlacement.findPlug("vertexUvOne") );
	dgModifier.connect( chooserFn.findPlug("outVertexUvTwo"), texturePlacement.findPlug("vertexUvTwo") );
	dgModifier.connect( chooserFn.findPlug("outVertexUvThree"), texturePlacement.findPlug("vertexUvThree") );
	dgModifier.doIt();
}
Esempio n. 25
0
bool getColor(MString& plugName, MFnDependencyNode& dn, MString& value)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	bool result = false;
	float r, g, b;
	MPlug plug = dn.findPlug(plugName + "R", &stat);
	if( !stat ) return false;
	r = plug.asFloat(ctx, &stat);
	plug = dn.findPlug(plugName + "G", &stat);
	if( !stat ) return false;
	g = plug.asFloat(ctx, &stat);
	plug = dn.findPlug(plugName + "B", &stat);
	if( !stat ) return false;
	b = plug.asFloat(ctx, &stat);
	value = MString("") + r + " " + g + " " + b;
	result = true;
	return result;
}
Esempio n. 26
0
bool getBoolAttr(const char *plugName, MFnDependencyNode& dn, bool defaultValue)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	bool result = false;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return false;
	return plug.asBool(ctx, &stat);
}
    //---------------------------------------------------
    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 );
    }
    //---------------------------------------------------
    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;
    }
Esempio n. 29
0
bool getPoint(MString& plugName, MFnDependencyNode& dn, MVector& value)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	bool result = false;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return false;
	MPlug Xplug = dn.findPlug(plugName + "X", &stat);
	MPlug Yplug = dn.findPlug(plugName + "Y", &stat);
	MPlug Zplug = dn.findPlug(plugName + "Z", &stat);
	if( !stat )
		return false;
	value.x = Xplug.asDouble(ctx, &stat);
	value.y = Yplug.asDouble(ctx, &stat);
	value.z = Zplug.asDouble(ctx, &stat);
	if( !stat )
		return false;
	return true;
}
Esempio n. 30
0
void liqRibData::parseVectorAttributes( MFnDependencyNode & nodeFn, MStringArray & strArray, ParameterType pType )
{
  int i;
  MStatus status;
  if ( strArray.length() > 0 ) {
    for ( i = 0; i < strArray.length(); i++ ) {
      liqTokenPointer tokenPointerPair;
      MString cutString = strArray[i].substring(5, strArray[i].length());
      MPlug vPlug = nodeFn.findPlug( strArray[i] );
      MObject plugObj;
      status = vPlug.getValue( plugObj );
      if ( plugObj.apiType() == MFn::kVectorArrayData ) {
        MFnVectorArrayData  fnVectorArrayData( plugObj );
        MVectorArray vectorArrayData = fnVectorArrayData.array( &status );
        tokenPointerPair.set(   cutString.asChar(),
                                pType,
                                ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false,
                                true,
                                false,
                                vectorArrayData.length() );
        for ( int kk = 0; kk < vectorArrayData.length(); kk++ ) {
          tokenPointerPair.setTokenFloat( kk, vectorArrayData[kk].x, vectorArrayData[kk].y, vectorArrayData[kk].z );
        }

        // should it be per vertex or face-varying
        if ( ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) && ( vectorArrayData.length() == faceVaryingCount ) ) {
          tokenPointerPair.setDetailType( rFaceVarying);
        } else {
          tokenPointerPair.setDetailType( rVertex );
        }

        // store it all
        tokenPointerArray.push_back( tokenPointerPair );

      } else {
        // Hmmmm float ? double ?
        float x, y, z;
          tokenPointerPair.set( cutString.asChar(),
                                pType,
                                ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false,
                                false,
                                false,
                                0 );
        vPlug.child(0).getValue( x );
        vPlug.child(1).getValue( y );
        vPlug.child(2).getValue( z );
        tokenPointerPair.setTokenFloat( 0, x, y, z );
        tokenPointerPair.setDetailType( rConstant );
        tokenPointerArray.push_back( tokenPointerPair );
      }
    }
  }
}