void liqBoundingBoxLocator::draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { MFnDagNode dagFn( thisMObject() ); MFnDagNode transFn( dagFn.parent( 0 ) ); MStatus stat; bool drawBox( 0 ); MPlug plug = dagFn.findPlug( "drawBox", stat ); if ( stat == MS::kSuccess ) plug.getValue( drawBox ); if ( !drawBox ) return; MDoubleArray bb( 6 ); MGlobal::executeCommand( MString( "exactWorldBoundingBox " ) + transFn.fullPathName(), bb ); pts = shared_array< MPoint >( new MPoint[ 8 ] ); pts[0].x = bb[0]; pts[0].y = bb[4]; pts[0].z = bb[2]; pts[1].x = bb[0]; pts[1].y = bb[4]; pts[1].z = bb[5]; pts[2].x = bb[3]; pts[2].y = bb[4]; pts[2].z = bb[5]; pts[3].x = bb[3]; pts[3].y = bb[4]; pts[3].z = bb[2]; pts[4].x = bb[0]; pts[4].y = bb[1]; pts[4].z = bb[2]; pts[5].x = bb[0]; pts[5].y = bb[1]; pts[5].z = bb[5]; pts[6].x = bb[3]; pts[6].y = bb[1]; pts[6].z = bb[5]; pts[7].x = bb[3]; pts[7].y = bb[1]; pts[7].z = bb[2]; MMatrix m( path.inclusiveMatrix() ); for( unsigned i( 0 ); i < 8; i++ ) pts[i] *= m.inverse(); // draw box view.beginGL(); view.setDrawColor( MColor( .57f, 0, .57f ) ); glPushAttrib( GL_CURRENT_BIT ); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[0].x, (float)pts[0].y, (float)pts[0].z ); glVertex3f( (float)pts[1].x, (float)pts[1].y, (float)pts[1].z ); glVertex3f( (float)pts[2].x, (float)pts[2].y, (float)pts[2].z ); glVertex3f( (float)pts[3].x, (float)pts[3].y, (float)pts[3].z ); glVertex3f( (float)pts[0].x, (float)pts[0].y, (float)pts[0].z ); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[4].x, (float)pts[4].y, (float)pts[4].z ); glVertex3f( (float)pts[5].x, (float)pts[5].y, (float)pts[5].z ); glVertex3f( (float)pts[6].x, (float)pts[6].y, (float)pts[6].z ); glVertex3f( (float)pts[7].x, (float)pts[7].y, (float)pts[7].z ); glVertex3f( (float)pts[4].x, (float)pts[4].y, (float)pts[4].z ); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[0].x, (float)pts[0].y, (float)pts[0].z ); glVertex3f( (float)pts[4].x, (float)pts[4].y, (float)pts[4].z ); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[1].x, (float)pts[1].y, (float)pts[1].z ); glVertex3f( (float)pts[5].x, (float)pts[5].y, (float)pts[5].z ); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[2].x, (float)pts[2].y, (float)pts[2].z ); glVertex3f( (float)pts[6].x, (float)pts[6].y, (float)pts[6].z ); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f( (float)pts[3].x, (float)pts[3].y, (float)pts[3].z ); glVertex3f( (float)pts[7].x, (float)pts[7].y, (float)pts[7].z ); glEnd(); view.endGL(); }
TfToken usdWriteJob::writeVariants(const UsdPrim &usdRootPrim) { // Init parameters for filtering and setting the active variant std::string defaultModelingVariant; // Get the usdVariantRootPrimPath (optionally filter by renderLayer prefix) MayaPrimWriterPtr firstPrimWriterPtr = *mJobCtx.mMayaPrimWriterList.begin(); std::string firstPrimWriterPathStr( firstPrimWriterPtr->getDagPath().fullPathName().asChar() ); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), '|', '/'); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), ':', '_'); // replace namespace ":" with "_" SdfPath usdVariantRootPrimPath(firstPrimWriterPathStr); usdVariantRootPrimPath = usdVariantRootPrimPath.GetPrefixes()[0]; // Create a new usdVariantRootPrim and reference the Base Model UsdRootPrim // This is done for reasons as described above under mArgs.usdModelRootOverridePath UsdPrim usdVariantRootPrim = mJobCtx.mStage->DefinePrim(usdVariantRootPrimPath); TfToken defaultPrim = usdVariantRootPrim.GetName(); usdVariantRootPrim.GetReferences().AppendInternalReference(usdRootPrim.GetPath()); usdVariantRootPrim.SetActive(true); usdRootPrim.SetActive(false); // Loop over all the renderLayers for (unsigned int ir=0; ir < mRenderLayerObjs.length(); ++ir) { SdfPathTable<bool> tableOfActivePaths; MFnRenderLayer renderLayerFn( mRenderLayerObjs[ir] ); MString renderLayerName = renderLayerFn.name(); std::string variantName(renderLayerName.asChar()); // Determine default variant. Currently unsupported //MPlug renderLayerDisplayOrderPlug = renderLayerFn.findPlug("displayOrder", true); //int renderLayerDisplayOrder = renderLayerDisplayOrderPlug.asShort(); // The Maya default RenderLayer is also the default modeling variant if (mRenderLayerObjs[ir] == MFnRenderLayer::defaultRenderLayer()) { defaultModelingVariant=variantName; } // Make the renderlayer being looped the current one MGlobal::executeCommand(MString("editRenderLayerGlobals -currentRenderLayer ")+ renderLayerName, false, false); // == ModelingVariants == // Identify prims to activate // Put prims and parent prims in a SdfPathTable // Then use that membership to determine if a prim should be Active. // It has to be done this way since SetActive(false) disables access to all child prims. MObjectArray renderLayerMemberObjs; renderLayerFn.listMembers(renderLayerMemberObjs); std::vector< SdfPath > activePaths; for (unsigned int im=0; im < renderLayerMemberObjs.length(); ++im) { MFnDagNode dagFn(renderLayerMemberObjs[im]); MDagPath dagPath; dagFn.getPath(dagPath); dagPath.extendToShape(); SdfPath usdPrimPath; if (!TfMapLookup(mDagPathToUsdPathMap, dagPath, &usdPrimPath)) { continue; } usdPrimPath = usdPrimPath.ReplacePrefix(usdPrimPath.GetPrefixes()[0], usdVariantRootPrimPath); // Convert base to variant usdPrimPath tableOfActivePaths[usdPrimPath] = true; activePaths.push_back(usdPrimPath); //UsdPrim usdPrim = mStage->GetPrimAtPath(usdPrimPath); //usdPrim.SetActive(true); } if (!tableOfActivePaths.empty()) { { // == BEG: Scope for Variant EditContext // Create the variantSet and variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSets().AppendVariantSet("modelingVariant"); modelingVariantSet.AppendVariant(variantName); modelingVariantSet.SetVariantSelection(variantName); // Set the Edit Context UsdEditTarget editTarget = modelingVariantSet.GetVariantEditTarget(); UsdEditContext editContext(mJobCtx.mStage, editTarget); // == Activate/Deactivate UsdPrims UsdPrimRange rng = UsdPrimRange::AllPrims(mJobCtx.mStage->GetPseudoRoot()); std::vector<UsdPrim> primsToDeactivate; for (auto it = rng.begin(); it != rng.end(); ++it) { UsdPrim usdPrim = *it; // For all xformable usdPrims... if (usdPrim && usdPrim.IsA<UsdGeomXformable>()) { bool isActive=false; for (size_t j=0;j<activePaths.size();j++) { //primPathD.HasPrefix(primPathA); SdfPath activePath=activePaths[j]; if (usdPrim.GetPath().HasPrefix(activePath) || activePath.HasPrefix(usdPrim.GetPath())) { isActive=true; break; } } if (isActive==false) { primsToDeactivate.push_back(usdPrim); it.PruneChildren(); } } } // Now deactivate the prims (done outside of the UsdPrimRange // so not to modify the iterator while in the loop) for ( UsdPrim const& prim : primsToDeactivate ) { prim.SetActive(false); } } // == END: Scope for Variant EditContext } } // END: RenderLayer iterations // Set the default modeling variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSet("modelingVariant"); if (modelingVariantSet.IsValid()) { modelingVariantSet.SetVariantSelection(defaultModelingVariant); } return defaultPrim; }