//--------------------------------------------------- bool DagHelper::getPlugValue ( const MPlug& plug, MColor& value ) { MStatus status; if ( plug.isCompound() && plug.numChildren() >= 3 ) { status = plug.child ( 0 ).getValue ( value.r ); if ( status != MStatus::kSuccess ) return false; status = plug.child ( 1 ).getValue ( value.g ); if ( status != MStatus::kSuccess ) return false; status = plug.child ( 2 ).getValue ( value.b ); if ( status != MStatus::kSuccess ) return false; if ( plug.numChildren() >= 4 ) { status = plug.child ( 3 ).getValue ( value.a ); if ( status != MStatus::kSuccess ) return false; } else value.a = 1.0f; return true; } else return false; }
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; }
TheaSDK::Normal3D TheaRenderer::getSunDirection() { MFnDependencyNode depFn(getRenderGlobalsNode()); std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; std::shared_ptr<TheaRenderer> renderer = std::static_pointer_cast<TheaRenderer>(MayaTo::getWorldPtr()->worldRendererPtr); TheaSDK::Normal3D sunDir; MObjectArray nodeList; getConnectedInNodes(MString("sunLightConnection"), getRenderGlobalsNode(), nodeList); if( nodeList.length() > 0) { MVector lightDir(0,0,1); MFnDagNode sunDagNode(nodeList[0]); //lightDir *= this->mtth_renderGlobals->globalConversionMatrix.inverse(); lightDir *= sunDagNode.transformationMatrix(); lightDir *= renderGlobals->globalConversionMatrix; lightDir.normalize(); return TheaSDK::Normal3D(lightDir.x,lightDir.y,lightDir.z); } float sunDirX = 0.0f, sunDirY = 0.0f, sunDirZ = 1.0f; MPlug sunDirPlug = depFn.findPlug("sunDirection"); if (!sunDirPlug.isNull()) { sunDirX = sunDirPlug.child(0).asFloat(); sunDirY = sunDirPlug.child(1).asFloat(); sunDirZ = sunDirPlug.child(2).asFloat(); } return TheaSDK::Normal3D(sunDirX, sunDirY, sunDirZ); }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void ConnectIntWeld( vm::CUndo &undo, const MObject &weldNodeObj, const MDagPath &toWeldPath, int nType, int nIntValue, const MMatrix &offsetMatrix ) { MFnDependencyNode weldFn( weldNodeObj ); MFnDagNode toWeldFn( toWeldPath ); MPlug wiAP = weldFn.findPlug( CVstWeldNode::m_iaWeldInput ); const uint nWeldIndex = vm::NextAvailable( wiAP ); MPlug wiP = wiAP.elementByLogicalIndex( nWeldIndex ); undo.SetAttr( wiP.child( CVstWeldNode::m_iaType ), nType ); undo.SetAttr( wiP.child( CVstWeldNode::m_iaInt ), nIntValue ); MFnMatrixData dFn; MObject mdObj = dFn.create( offsetMatrix ); undo.SetAttr( wiP.child( CVstWeldNode::m_iaOffsetMatrix ), mdObj ); undo.Connect( toWeldFn.findPlug( "parentInverseMatrix" ).elementByLogicalIndex( toWeldPath.instanceNumber() ), wiP.child( CVstWeldNode::m_iaInverseParentSpace ), true ); undo.Connect( toWeldFn.findPlug( "rotateOrder" ), wiP.child( CVstWeldNode::m_iaRotateOrder ), true ); MPlug woAP = weldFn.findPlug( CVstWeldNode::m_oaWeldOutput ); MPlug woP = woAP.elementByLogicalIndex( nWeldIndex ); MPlug tP = woP.child( CVstWeldNode::m_oaTranslate ); undo.Connect( tP.child( CVstWeldNode::m_oaTranslateX ), toWeldFn.findPlug( "translateX" ) ); undo.Connect( tP.child( CVstWeldNode::m_oaTranslateY ), toWeldFn.findPlug( "translateY" ) ); undo.Connect( tP.child( CVstWeldNode::m_oaTranslateZ ), toWeldFn.findPlug( "translateZ" ) ); MPlug rP = woP.child( CVstWeldNode::m_oaRotate ); undo.Connect( rP.child( CVstWeldNode::m_oaRotateX ), toWeldFn.findPlug( "rotateX" ) ); undo.Connect( rP.child( CVstWeldNode::m_oaRotateY ), toWeldFn.findPlug( "rotateY" ) ); undo.Connect( rP.child( CVstWeldNode::m_oaRotateZ ), toWeldFn.findPlug( "rotateZ" ) ); }
//--------------------------------------------------- bool DagHelper::setPlugValue ( MPlug& plug, const MColor& value ) { MStatus status; if ( plug.isCompound() && plug.numChildren() >= 3 ) { MPlug rPlug = plug.child ( 0, &status ); if ( status != MStatus::kSuccess ) return false; status = rPlug.setValue ( value.r ); if ( status != MStatus::kSuccess ) return false; MPlug gPlug = plug.child ( 1, &status ); if ( status != MStatus::kSuccess ) return false; status = gPlug.setValue ( value.g ); if ( status != MStatus::kSuccess ) return false; MPlug bPlug = plug.child ( 2, &status ); if ( status != MStatus::kSuccess ) return false; status = bPlug.setValue ( value.b ); if ( status != MStatus::kSuccess ) return false; if ( plug.numChildren() >= 4 ) { MPlug aPlug = plug.child ( 3, &status ); if ( status != MStatus::kSuccess ) return false; status = aPlug.setValue ( value.a ); if ( status != MStatus::kSuccess ) return false; } } return true; }
MStatus ClassParameterHandler::storeClass( IECore::ConstParameterPtr parameter, MPlug &plug ) { IECorePython::ScopedGILLock gilLock; try { boost::python::object pythonParameter( IECore::constPointerCast<IECore::Parameter>( parameter ) ); boost::python::object classInfo = pythonParameter.attr( "getClass" )( true ); std::string className = boost::python::extract<std::string>( classInfo[1] ); int classVersion = boost::python::extract<int>( classInfo[2] ); std::string searchPathEnvVar = boost::python::extract<std::string>( classInfo[3] ); MString storedClassName; int storedClassVersion; MString storedSearchPathEnvVar; currentClass( plug, storedClassName, storedClassVersion, storedSearchPathEnvVar ); // only set the plug values if the new value is genuinely different, as otherwise // we end up generating unwanted reference edits. if ( storedClassName != className.c_str() || storedClassVersion != classVersion || storedSearchPathEnvVar != searchPathEnvVar.c_str() ) { MStringArray updatedClassInfo; updatedClassInfo.append( className.c_str() ); MString classVersionStr; classVersionStr.set( classVersion, 0 ); updatedClassInfo.append( classVersionStr ); updatedClassInfo.append( searchPathEnvVar.c_str() ); MObject attribute = plug.attribute(); MFnTypedAttribute fnTAttr( attribute ); if ( fnTAttr.attrType() == MFnData::kStringArray ) { MObject data = MFnStringArrayData().create( updatedClassInfo ); plug.setValue( data ); } else { // compatibility for the deprecated compound plug behaviour. keeping this code // so we can still read old scenes. creation of these plugs has been removed. /// \todo: find all such notes and remove the unnecessary code for Cortex 9. plug.child( 0 ).setString( className.c_str() ); plug.child( 1 ).setInt( classVersion ); plug.child( 2 ).setString( searchPathEnvVar.c_str() ); } } } catch( boost::python::error_already_set ) { PyErr_Print(); return MS::kFailure; } catch( const std::exception &e ) { MGlobal::displayError( MString( "ClassParameterHandler::setClass : " ) + e.what() ); return MS::kFailure; } return MS::kSuccess; }
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 ); } } } }
//--------------------------------------------------- MPlug DagHelper::getChildPlug ( const MPlug& parent, const MString& name, MStatus* rc ) { MStatus st; uint childCount = parent.numChildren ( &st ); if ( st != MStatus::kSuccess ) { if ( rc != NULL ) *rc = st; return parent; } // Check shortNames first for ( uint i = 0; i < childCount; ++i ) { MPlug child = parent.child ( i, &st ); if ( st != MStatus::kSuccess ) { if ( rc != NULL ) *rc = st; return parent; } MFnAttribute attributeFn ( child.attribute() ); MString n = attributeFn.shortName(); if ( n == name ) { if ( rc != NULL ) *rc = MStatus::kSuccess; return child; } } // Check longNames second, use shortNames! for ( uint i = 0; i < childCount; ++i ) { MPlug child = parent.child ( i, &st ); if ( st != MStatus::kSuccess ) { if ( rc != NULL ) *rc = st; return parent; } MFnAttribute attributeFn ( child.attribute() ); MString n = attributeFn.name(); if ( n == name ) { if ( rc != NULL ) *rc = MStatus::kSuccess; return child; } } if ( rc != NULL ) *rc = MStatus::kNotFound; return parent; }
void getConnectedChildPlugs(const MPlug& plug, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs) { if (plug.numConnectedChildren() == 0) return; for (uint chId = 0; chId < plug.numChildren(); chId++) if (plug.child(chId).isConnected()) { if ((plug.child(chId).isDestination() && dest) || (plug.child(chId).isSource() && !dest)) { thisNodePlugs.append(plug.child(chId)); otherSidePlugs.append(getDirectConnectedPlug(plug, dest)); } } }
bool isChildOf(MPlug& parent, MPlug& child) { for (uint i = 0; i < parent.numChildren(); i++) if (parent.child(i) == child) return true; return false; }
void getDirectConnectedPlugs(const char *attrName, MFnDependencyNode& depFn, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs) { MPlug thisPlug = depFn.findPlug(attrName); if (!thisPlug.isArray()) { if (thisPlug.isConnected()) { thisNodePlugs.append(thisPlug); otherSidePlugs.append(getDirectConnectedPlug(thisPlug, dest)); } return; } for (uint i = 0; i < thisPlug.numElements(); i++) { if (thisPlug.isCompound()) { // we only support simple compounds like colorListEntry if (MString(attrName) == MString("colorEntryList")) { MPlug element = thisPlug[i]; if (element.child(0).isConnected()) { MPlug connectedPlug = element.child(0); thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } if (element.child(1).isConnected()) { MPlug connectedPlug = element.child(1); thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } } } else{ if (!thisPlug[i].isConnected()) { continue; } MPlug connectedPlug = thisPlug[i]; thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } } }
//--------------------------------------------------- int DagHelper::getChildPlugIndex ( const MPlug& parent, const MString& name, MStatus* rc ) { MStatus st; uint childCount = parent.numChildren ( &st ); CHECK_STATUS_AND_RETURN ( st, -1 ); // Check shortNames first for ( uint i = 0; i < childCount; ++i ) { MPlug child = parent.child ( i, &st ); CHECK_STATUS_AND_RETURN ( st, -1 ); MFnAttribute attributeFn ( child.attribute() ); MString n = attributeFn.shortName(); if ( n == name ) { if ( rc != NULL ) *rc = MStatus::kSuccess; return i; } } // Check longNames second, use shortNames! for ( uint i = 0; i < childCount; ++i ) { MPlug child = parent.child ( i, &st ); CHECK_STATUS_AND_RETURN ( st, -1 ); MFnAttribute attributeFn ( child.attribute() ); MString n = attributeFn.name(); if ( n == name ) { if ( rc != NULL ) *rc = MStatus::kSuccess; return i; } } if ( rc != NULL ) *rc = MStatus::kNotFound; return -1; }
// This function is a utility that can be used to extract vector values from // plugs. // MVector vectorPlugValue(const MPlug& plug) { if (plug.numChildren() == 3) { double x,y,z; MPlug rx = plug.child(0); MPlug ry = plug.child(1); MPlug rz = plug.child(2); rx.getValue(x); ry.getValue(y); rz.getValue(z); MVector result(x,y,z); return result; } else { MGlobal::displayError("Expected 3 children for plug "+MString(plug.name())); MVector result(0,0,0); return result; } }
// ------------------------------------------- MPlug AnimationHelper::getTargetedPlug ( MPlug parentPlug, int index ) { if ( index >= 0 && parentPlug.isCompound() ) { return parentPlug.child ( index ); } else if ( index >= 0 && parentPlug.isArray() ) { return parentPlug.elementByLogicalIndex ( index ); } else return parentPlug; }
void SurfaceAttach::inUVs(MFnDependencyNode &fn) { MPlug inUVPlug = fn.findPlug("inUV"); const std::uint32_t numElements = inUVPlug.numElements(); this->uInputs.resize((size_t)(numElements)); this->vInputs.resize((size_t)(numElements)); for (std::uint32_t i=0; i < numElements; i++){ MPlug uvPlug = inUVPlug.elementByLogicalIndex(i); this->uInputs[i] = uvPlug.child(0).asDouble(); this->vInputs[i] = uvPlug.child(1).asDouble(); } }
MStatus BoxParameterHandler<T>::doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const { typename IECore::TypedParameter<Box<T> >::Ptr p = IECore::runTimeCast<IECore::TypedParameter<Box<T> > >( parameter ); if( !p ) { return MS::kFailure; } if( plug.numChildren() != 2 ) { return MS::kFailure; } MPlug minPlug = plug.child( 0 ); MPlug maxPlug = plug.child( 1 ); if( minPlug.numChildren()!=T::dimensions() || maxPlug.numChildren()!=T::dimensions() ) { return MS::kFailure; } Box<T> v; for( unsigned i=0; i<minPlug.numChildren(); i++ ) { MStatus s = minPlug.child( i ).getValue( v.min[i] ); if( !s ) { return s; } s = maxPlug.child( i ).getValue( v.max[i] ); if( !s ) { return s; } } p->setTypedValue( v ); return MS::kSuccess; }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MObject& node, const String attributeName, MEulerRotation& value ) { MStatus status; MPlug plug = MFnDependencyNode ( node ).findPlug ( attributeName.c_str(), &status ); if ( status != MStatus::kSuccess ) return false; if ( plug.isCompound() && plug.numChildren() >= 3 ) { status = plug.child ( 0 ).getValue ( value.x ); if ( status != MStatus::kSuccess ) return false; status = plug.child ( 1 ).getValue ( value.y ); if ( status != MStatus::kSuccess ) return false; status = plug.child ( 2 ).getValue ( value.z ); if ( status != MStatus::kSuccess ) return false; return true; } else return false; }
int getChildId(MPlug& plug) { if (!plug.isChild()) return -1; MPlug parentPlug = plug.parent(); for (uint chId = 0; chId < parentPlug.numChildren(); chId++) { if (parentPlug.child(chId) == plug) return chId; } return -1; }
void ClassParameterHandler::currentClass( const MPlug &plug, MString &className, int &classVersion, MString &searchPathEnvVar ) { MObject attribute = plug.attribute(); MFnTypedAttribute fnTAttr( attribute ); if ( !fnTAttr.hasObj( attribute ) || fnTAttr.attrType() != MFnData::kStringArray ) { // compatibility for the deprecated compound plug behaviour className = plug.child( 0 ).asString(); classVersion = plug.child( 1 ).asInt(); searchPathEnvVar = plug.child( 2 ).asString(); return; } MFnStringArrayData fnSAD( plug.asMObject() ); if ( fnSAD.length() == 0 ) { className = ""; classVersion = 0; searchPathEnvVar = ""; return; } if ( fnSAD.length() != 3 ) { throw( IECore::InvalidArgumentException( ( plug.name() + " has more than 3 values. Expected name, version, searchPath only." ).asChar() ) ); } MStringArray storedClassInfo = fnSAD.array(); if ( !storedClassInfo[1].isInt() ) { throw( IECore::InvalidArgumentException( ( "Second value of " + plug.name() + " must represent an integer" ).asChar() ) ); } className = storedClassInfo[0]; classVersion = storedClassInfo[1].asInt(); searchPathEnvVar = storedClassInfo[2]; }
MStatus TransformationMatrixParameterHandler<T>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const { typename IECore::TypedParameter<IECore::TransformationMatrix<T> >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter<IECore::TransformationMatrix<T> > >( parameter ); if( !p ) { return MS::kFailure; } IECore::TransformationMatrix<T> tMatrix = p->getTypedValue(); if( tMatrix.rotate.order() != Imath::Euler<T>::XYZ ) { IECore::msg( IECore::Msg::Error, "TransformationMatrixParameterHandler::doSetValue", "The rotation order of the parameter '"+parameter->name()+"' is not XYZ, unable to set value." ); return MS::kFailure; } if( !setVecValues( plug.child( TRANSLATE_INDEX ), tMatrix.translate ) ) return MS::kFailure; if( !setVecValues( plug.child( ROTATE_INDEX ), tMatrix.rotate ) ) return MS::kFailure; if( !setVecValues( plug.child( SCALE_INDEX ), tMatrix.scale ) ) return MS::kFailure; if( !setVecValues( plug.child( SHEAR_INDEX ), tMatrix.shear ) ) return MS::kFailure; if( !setVecValues( plug.child( SCALEPIVOT_INDEX ), tMatrix.scalePivot ) ) return MS::kFailure; if( !setVecValues( plug.child( SCALEPIVOTTRANS_INDEX ), tMatrix.scalePivotTranslation ) ) return MS::kFailure; if( !setVecValues( plug.child( ROTATEPIVOT_INDEX ), tMatrix.rotatePivot ) ) return MS::kFailure; if( !setVecValues( plug.child( ROTATEPIVOTTRANS_INDEX ), tMatrix.rotatePivotTranslation ) ) return MS::kFailure; return MS::kSuccess; }
MPlug FxInternal::GetValuePlug(MPlug& plug) { MFnDependencyNode depNode(GetSite()); MObject oAttribute = plug.attribute(); MFnAttribute fnAttribute(oAttribute); MString name = fnAttribute.name() + MString("Value"); oAttribute= depNode.attribute(name); return plug.child(oAttribute); }
MStatus TransformationMatrixParameterHandler<T>::getVecValues( MPlug vecPlug, Imath::Vec3<T> &values ) const { if( vecPlug.numChildren() != 3 ) { return MS::kFailure; } for( unsigned int i=0; i<3; i++ ) { if( !vecPlug.child(i).getValue( values[i] ) ) { return MS::kFailure; } } return MS::kSuccess; }
void GDExporter::GetUniqueRenderContexts( MFnTransform& transform, std::list<GDRenderContext>& uniqueContexts ) { for(unsigned int i = 0; i < transform.childCount(); ++i) { if( transform.child(i).apiType() == MFn::kMesh ) { MFnMesh childMesh( transform.child(i) ); if( childMesh.isIntermediateObject() ) continue; MDagPath meshPath; childMesh.getPath(meshPath); MFnDependencyNode depNode(meshPath.node()); MStatus fpResult; MPlug gdRenderContextPlug = childMesh.findPlug("GDRenderContext", &fpResult); if( fpResult != MS::kSuccess ) continue; GDRenderContext newContext(gdRenderContextPlug); bool bFound = false; std::list<GDRenderContext>::iterator uniqueIter = uniqueContexts.begin(); for(; uniqueIter != uniqueContexts.end(); ++uniqueIter ) { if( (*uniqueIter) == newContext ) { bFound = true; break; } } if( bFound == false ) uniqueContexts.push_back( newContext ); else gdRenderContextPlug.child(0).setValue( (*uniqueIter).name.c_str() ); } else if( transform.child(i).apiType() == MFn::kTransform ) { MFnTransform childTransform( transform.child(i) ); GetUniqueRenderContexts( childTransform, uniqueContexts ); } } }
MStatus TransformationMatrixParameterHandler<T>::setUnitVecDefaultValues( MPlug vecPlug, Imath::Vec3<T> &defaultValue ) const { if( vecPlug.numChildren() != 3 ) { return MS::kFailure; } MFnUnitAttribute fnU; for( unsigned int i=0; i<3; i++ ) { fnU.setObject( vecPlug.child(i).attribute() ); if( !fnU.setDefault( defaultValue[i] ) ) { return MS::kFailure; } } return MS::kSuccess; }
MStatus TransformationMatrixParameterHandler<T>::doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const { typename IECore::TypedParameter<IECore::TransformationMatrix<T> >::Ptr p = IECore::runTimeCast<IECore::TypedParameter<IECore::TransformationMatrix<T> > >( parameter ); if( !p ) { return MS::kFailure; } IECore::TransformationMatrix<T> tMatrix = p->getTypedValue(); if( tMatrix.rotate.order() != Imath::Euler<T>::XYZ ) { IECore::msg( IECore::Msg::Error, "TransformationMatrixParameterHandler::doSetValue", "The rotation order of the parameter '"+parameter->name()+"' is not XYZ, unable to set value." ); return MS::kFailure; } std::vector<Imath::Vec3<T> > v; v.resize(8); for( unsigned int i=0; i<8; i++ ) { if( !getVecValues( plug.child(i), v[i] ) ) return MS::kFailure; } tMatrix.translate = v[ TRANSLATE_INDEX ]; tMatrix.rotate = Imath::Euler<T>(v[ ROTATE_INDEX ]); tMatrix.scale = v[ SCALE_INDEX ]; tMatrix.shear = v[ SHEAR_INDEX ]; tMatrix.scalePivot = v[ SCALEPIVOT_INDEX ]; tMatrix.scalePivotTranslation = v[ SCALEPIVOTTRANS_INDEX ]; tMatrix.rotatePivot = v[ ROTATEPIVOT_INDEX ]; tMatrix.rotatePivotTranslation = v[ ROTATEPIVOTTRANS_INDEX ]; p->setTypedValue( tMatrix ); return MS::kSuccess; }
MObject getOtherSideNode(const MString& plugName, MObject& thisObject, MStringArray& otherSidePlugNames) { MStatus stat; MObject result = MObject::kNullObj; MFnDependencyNode depFn(thisObject, &stat); if (stat != MStatus::kSuccess) return result; MPlug plug = depFn.findPlug(plugName, &stat); if (stat != MStatus::kSuccess)return result; if (!plug.isConnected()) { int numChildConnects = plug.numConnectedChildren(); if (numChildConnects == 0) return result; else { for (int i = 0; i < numChildConnects; i++) { MPlug child = plug.child(i); MString otherSidePlugName; MObject childObj = getOtherSideNode(child.partialName(false), thisObject, otherSidePlugName); if (childObj != MObject::kNullObj) { otherSidePlugNames.append(otherSidePlugName); result = childObj; } else otherSidePlugNames.append(MString("")); } } } else { MPlugArray plugArray; plug.connectedTo(plugArray, 1, 0, &stat); if (stat != MStatus::kSuccess) return result; if (plugArray.length() == 0) return result; MPlug otherSidePlug = plugArray[0]; result = otherSidePlug.node(); otherSidePlugNames.append(otherSidePlug.name()); } return result; }
void V3Manipulator::getPlugValues( MPlug &plug, double *values ) { if( plug.numChildren() == 3 ) { for( unsigned i = 0; i<3; i++ ) { MPlug child = plug.child( i ); *values = child.asDouble(); values++; } } else { for( unsigned i = 0; i<3; i++ ) { MPlug element = plug.elementByLogicalIndex( i ); *values = element.asDouble(); values++; } } }
void liqRibData::addAdditionalSurfaceParameters( MObject node ) { LIQDEBUGPRINTF("-> scanning for additional rman surface attributes \n"); MStatus status = MS::kSuccess; unsigned i; // work out how many elements there would be in a facevarying array if a mesh or subD // faceVaryingCount is a private data member if ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) { faceVaryingCount = 0; MFnMesh fnMesh( node ); for ( uint pOn = 0; pOn < fnMesh.numPolygons(); pOn++ ) { faceVaryingCount += fnMesh.polygonVertexCount( pOn ); } } // find how many additional MFnDependencyNode nodeFn( node ); // find the attributes MStringArray floatAttributesFound = findAttributesByPrefix( "rmanF", nodeFn ); MStringArray pointAttributesFound = findAttributesByPrefix( "rmanP", nodeFn ); MStringArray vectorAttributesFound = findAttributesByPrefix( "rmanV", nodeFn ); MStringArray normalAttributesFound = findAttributesByPrefix( "rmanN", nodeFn ); MStringArray colorAttributesFound = findAttributesByPrefix( "rmanC", nodeFn ); MStringArray stringAttributesFound = findAttributesByPrefix( "rmanS", nodeFn ); if ( floatAttributesFound.length() > 0 ) { for ( i = 0; i < floatAttributesFound.length(); i++ ) { liqTokenPointer tokenPointerPair; MString cutString = floatAttributesFound[i].substring(5, floatAttributesFound[i].length()); MPlug fPlug = nodeFn.findPlug( floatAttributesFound[i] ); MObject plugObj; status = fPlug.getValue( plugObj ); if ( plugObj.apiType() == MFn::kDoubleArrayData ) { MFnDoubleArrayData fnDoubleArrayData( plugObj ); MDoubleArray doubleArrayData = fnDoubleArrayData.array( &status ); tokenPointerPair.set( cutString.asChar(), rFloat, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, true, false, doubleArrayData.length() ); for( unsigned int kk = 0; kk < doubleArrayData.length(); kk++ ) { tokenPointerPair.setTokenFloat( kk, doubleArrayData[kk] ); } if ( ( type() == MRT_NuCurve ) && ( cutString == MString( "width" ) ) ) { tokenPointerPair.setDetailType( rVarying); } else if ( ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) && ( doubleArrayData.length() == faceVaryingCount ) ) { tokenPointerPair.setDetailType( rFaceVarying); } else { tokenPointerPair.setDetailType( rVertex ); } } else { if( fPlug.isArray() ) { int nbElts = fPlug.evaluateNumElements(); float floatValue; tokenPointerPair.set( cutString.asChar(), rFloat, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, false, true, // philippe :passed as uArray, otherwise it will think it is a single float nbElts ); MPlug elementPlug; for( unsigned int kk = 0; kk < nbElts; kk++ ) { elementPlug = fPlug.elementByPhysicalIndex(kk); elementPlug.getValue( floatValue ); tokenPointerPair.setTokenFloat( kk, floatValue ); } tokenPointerPair.setDetailType( rConstant ); } else { float floatValue; tokenPointerPair.set( cutString.asChar(), rFloat, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, false, false, 0 ); fPlug.getValue( floatValue ); tokenPointerPair.setTokenFloat( 0, floatValue ); tokenPointerPair.setDetailType( rConstant ); } } tokenPointerArray.push_back( tokenPointerPair ); } } if ( pointAttributesFound.length() > 0 ) { for ( i = 0; i < pointAttributesFound.length(); i++ ) { liqTokenPointer tokenPointerPair; MString cutString = pointAttributesFound[i].substring(5, pointAttributesFound[i].length()); MPlug pPlug = nodeFn.findPlug( pointAttributesFound[i] ); MObject plugObj; status = pPlug.getValue( plugObj ); if ( plugObj.apiType() == MFn::kPointArrayData ) { MFnPointArrayData fnPointArrayData( plugObj ); MPointArray pointArrayData = fnPointArrayData.array( &status ); tokenPointerPair.set( cutString.asChar(), rPoint, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, true, false, pointArrayData.length() ); if ( type() == MRT_Nurbs || type() == MRT_NuCurve ) { for ( int kk = 0; kk < pointArrayData.length(); kk++ ) { tokenPointerPair.setTokenFloat( kk, pointArrayData[kk].x, pointArrayData[kk].y, pointArrayData[kk].z, pointArrayData[kk].w ); } } else { for ( int kk = 0; kk < pointArrayData.length(); kk++ ) { tokenPointerPair.setTokenFloat( kk, pointArrayData[kk].x, pointArrayData[kk].y, pointArrayData[kk].z ); } } tokenPointerPair.setDetailType( rVertex ); } else { // Hmmmm float ? double ? float x, y, z; tokenPointerPair.set( cutString.asChar(), rPoint, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, false, false, 0 ); // Hmmm should check as for arrays if we are in nurbs mode : 4 values pPlug.child(0).getValue( x ); pPlug.child(1).getValue( y ); pPlug.child(2).getValue( z ); tokenPointerPair.setTokenFloat( 0, x, y, z ); tokenPointerPair.setDetailType( rConstant ); } tokenPointerArray.push_back( tokenPointerPair ); } } parseVectorAttributes( nodeFn, vectorAttributesFound, rVector ); parseVectorAttributes( nodeFn, normalAttributesFound, rNormal ); parseVectorAttributes( nodeFn, colorAttributesFound, rColor ); if ( stringAttributesFound.length() > 0 ) { for ( i = 0; i < stringAttributesFound.length(); i++ ) { liqTokenPointer tokenPointerPair; MString cutString = stringAttributesFound[i].substring(5, stringAttributesFound[i].length()); MPlug sPlug = nodeFn.findPlug( stringAttributesFound[i] ); MObject plugObj; status = sPlug.getValue( plugObj ); tokenPointerPair.set( cutString.asChar(), rString, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, false, false, 0 ); MString stringVal; sPlug.getValue( stringVal ); tokenPointerPair.setTokenString( 0, stringVal.asChar(), stringVal.length() ); tokenPointerPair.setDetailType( rConstant ); tokenPointerArray.push_back( tokenPointerPair ); } } }
/** * Exports Camera node */ osg::ref_ptr<osg::Node> Camera::exporta(MObject &obj) { // Each camera is exported to a separate file MFnCamera cam(obj); MFnDagNode dn(obj); std::string node_name = dn.name().asChar(); if ( !Config::instance()->getExportDefaultCameras() && ( node_name == "topShape" || node_name == "frontShape" || node_name == "sideShape" || node_name == "perspShape" )) { return NULL; } if ( ! Config::instance()->getExportOrthographicCameras() && cam.isOrtho() ) return NULL; osgViewer::Viewer viewer; // Camera name viewer.setName(dn.name().asChar()); // std::cout << "Exporting Camera " << dn.name().asChar() << std::endl; // Background color MPlug backgroundColor = cam.findPlug("backgroundColor"); float red, green, blue; backgroundColor.child(0).getValue( red ); backgroundColor.child(1).getValue( green ); backgroundColor.child(2).getValue( blue ); viewer.getCamera()->setClearColor( osg::Vec4( red, green, blue, 1.0 ) ); // View matrix (does not work as expected. Transformations are not considered. FIXME!) MPoint meye = cam.eyePoint(MSpace::kPostTransform); MPoint mcenter = cam.centerOfInterestPoint(MSpace::kPostTransform); MPoint mup = cam.upDirection(MSpace::kPostTransform); // std::cout << "eye : " << meye.x << " " << meye.y << " " << meye.z << std::endl; // std::cout << "center : " << mcenter.x << " " << mcenter.y << " " << mcenter.z << std::endl; // std::cout << "up : " << mup.x << " " << mup.y << " " << mup.z << std::endl; osg::Vec3d eye(meye.x, meye.y, meye.z); osg::Vec3d center(mcenter.x, mcenter.y, mcenter.z); osg::Vec3d up(mup.x, mup.y, mup.z); osg::Matrix look_at; look_at.makeLookAt(eye, center, up); // Now we get the camera transformation and apply it to the lookAt matrix osg::Matrix trans; if ( dn.parentCount() > 1 ) { std::cerr << "WARNING: Multiple instanced cameras not currently supported" << std::endl; return NULL; } MObject parent = dn.parent(0); MFnDagNode dn_parent(parent); MFnTransform mfn_trans(parent); mfn_trans.transformationMatrix().get( (double(*)[4]) trans.ptr() ); // Accumulate transformations up to the root while ( dn_parent.parentCount() > 0 ){ if ( dn_parent.parentCount() > 1 ) { std::cerr << "WARNING: Multiple instanced cameras not currently supported" << std::endl; return NULL; } osg::Matrix new_trans; mfn_trans.setObject(dn_parent.parent(0)); mfn_trans.transformationMatrix().get( (double(*)[4]) new_trans.ptr() ); trans *= new_trans; dn_parent.setObject( dn_parent.parent(0) ); } if ( Config::instance()->getYUp2ZUp() ) { osg::Matrix yup2zup; yup2zup.makeRotate( osg::Vec3(0.0, 1.0, 0.0), osg::Vec3(0.0, 0.0, 1.0) ); trans *= yup2zup; } viewer.getCamera()->setViewMatrix( look_at * osg::Matrix::inverse(trans) ); // Projection matrix double l, r, b ,t; // double ar = cam.aspectRatio(); // WARNING: Camera does not know the aspect ratio of the render window // It must be queried in the Render Settings MCommonRenderSettingsData render_settings; MRenderUtil::getCommonRenderSettings(render_settings); float ar = render_settings.deviceAspectRatio; // We use the rendering frustum instead of the viewing frustum cam.getRenderingFrustum(ar, l, r, b, t); double n = cam.nearClippingPlane(); double f = cam.farClippingPlane(); if ( cam.isOrtho() ) { viewer.getCamera()->setProjectionMatrixAsOrtho(l, r, b, t, n, f); } else { viewer.getCamera()->setProjectionMatrixAsFrustum(l, r, b, t, n, f); } // Auto Render Clip Plane -> ComputeNearFarMode MPlug bfcp = cam.findPlug("bestFitClippingPlanes"); bool autoClipPlanes; bfcp.getValue(autoClipPlanes); if ( !autoClipPlanes ) { viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); } // Write camera/viewer config file std::string camera_filename = Config::instance()->getSceneFilePath().getDirectory() + "/" + Config::instance()->getSceneFilePath().getFileBaseName() + "_" + std::string(dn.name().asChar()) + ".osg"; osgDB::writeObjectFile( viewer, camera_filename ); // We do not include the camera in the scene graph, so return NULL return NULL; }
//THIS FUNCTION IS QUITE COMPLICATED BECAUSE //IT HAS TO DEAL WITH MAYA NAME MANGLING! //tokenize the path. //add each token into the element list which tracks the attributes and indices //for each entry added make sure there are no parents left out from maya name mangling. //after the list is populated and missing elements area added //we reiterate and produce the final result. MPlug FxInternal::DecodePlug(const CStringA& plugStr) { MPlug result; MFnDependencyNode depNode(GetSite()); CAtlList<PathDecodeElement> elementList; //tokenize the path int iLastPos=0; int iThisPos=0; CStringA subStr; while( iLastPos= iThisPos, subStr=plugStr.Tokenize(".[]", iThisPos), iThisPos != -1 ) { //char lastChar= subStr[iLastPos]; //char thisChar= subStr[iThisPos]; //are we looking at a named portion? if(iLastPos == 0 || plugStr[iLastPos-1]=='.' || (plugStr[iLastPos-1]==']' && plugStr[iLastPos]=='.')) { //if the name is length zero then it must be the case when // you do last[#]. The situation is caused by the sequence "]." //if we dont have a name we can skip since only 1d arrays are allowed. if(subStr.GetLength() > 0) { //everything we add is going to be based on the current tail. //because we are adding parents, as we find parents we can continue //to add them to this position so that they will order themselves properly POSITION insertPos= elementList.GetTailPosition(); //calculate the cancel condition. //it is the current tail's object if a tail exists otherwise NULL //NULL indicates go all the way to the root MObject cancelObj= MObject::kNullObj; if(elementList.GetCount() > 0) { cancelObj= elementList.GetTail().Attribute.object(); } //get the object we are currently working with MObject thisObj= depNode.attribute(subStr.GetString()); if(thisObj.isNull()) return MPlug();//Critical element of the path was not found...return NULL //add it to the list so that we have something to insertBefore elementList.AddTail(); elementList.GetTail().Name= subStr; elementList.GetTail().Attribute.setObject(thisObj); //walk through all of the parents until we reach cancel condition. //we can add the current element onto the list in the same way. for( MFnAttribute itrAttr( elementList.GetTail().Attribute.parent() ); !itrAttr.object().isNull() && (cancelObj != itrAttr.object()); itrAttr.setObject(itrAttr.parent())) { PathDecodeElement element; element.Attribute.setObject( itrAttr.object() ); //we change the position so that the grandparent is inserted before the parent insertPos= elementList.InsertBefore( insertPos, element); } } } //are we looking at a numbered portion? else if(plugStr[iLastPos-1]=='[' && plugStr[iThisPos-1]==']') { //if so change the array index. elementList.GetTail().IsArray= true; elementList.GetTail().Index = atoi( subStr.GetString() ); } else DXCC_ASSERT(false);//VERY POORLY FORMED STRING } //produce the result plug off of the elementList. bool first= true; for(POSITION pos= elementList.GetHeadPosition(); pos != NULL; elementList.GetNext(pos)) { PathDecodeElement& element= elementList.GetAt(pos); if(first) {//on first one we initialize the result first= false; result= MPlug( GetSite(), element.Attribute.object() ); } else { result= result.child( element.Attribute.object() ); } if(element.IsArray) { result= result.elementByLogicalIndex(element.Index); } if(result.isNull()) return MPlug();//Critical element of the path was not found...return NULL } return result; }