HdRenderPassSharedPtr const & Hd_TestDriver::GetRenderPass(bool withGuides) { if (withGuides) { if (!_geomAndGuidePass) { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); renderTags.push_back(HdTokens->guide); HdRprimCollection col = HdRprimCollection( HdTokens->geometry, _reprSelector); col.SetRenderTags(renderTags); _geomAndGuidePass = HdRenderPassSharedPtr( new Hd_UnitTestNullRenderPass(&_sceneDelegate->GetRenderIndex(), col)); } return _geomAndGuidePass; } else { if (!_geomPass) { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); HdRprimCollection col = HdRprimCollection( HdTokens->geometry, _reprSelector); col.SetRenderTags(renderTags); _geomPass = HdRenderPassSharedPtr( new Hd_UnitTestNullRenderPass(&_sceneDelegate->GetRenderIndex(), col)); } return _geomPass; } }
void Hd_TestDriver::SetRepr(HdReprSelector const &reprSelector) { _reprSelector = reprSelector; if (_geomAndGuidePass) { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); renderTags.push_back(HdTokens->guide); HdRprimCollection col = HdRprimCollection( HdTokens->geometry, _reprSelector); col.SetRenderTags(renderTags); _geomAndGuidePass->SetRprimCollection(col); } if (_geomPass) { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); HdRprimCollection col = HdRprimCollection( HdTokens->geometry, _reprSelector); col.SetRenderTags(renderTags); _geomPass->SetRprimCollection(col); } }
std::vector<GfBBox3d> PxrUsdKatanaUsdInArgs::ComputeBounds( const UsdPrim& prim) { std::vector<GfBBox3d> ret; std::vector<UsdGeomBBoxCache>& bboxCaches = _bboxCaches.local(); // Initialize the bounding box cache if it hasn't yet been initialized. // bool needsInit = bboxCaches.size() != _motionSampleTimes.size(); if (needsInit) { // XXX: selected purposes should be driven by the UI. // See usdGeom/imageable.h GetPurposeAttr() for allowed values. TfTokenVector includedPurposes; includedPurposes.push_back(UsdGeomTokens->default_); includedPurposes.push_back(UsdGeomTokens->render); bboxCaches.resize(_motionSampleTimes.size(), UsdGeomBBoxCache( _currentTime, includedPurposes, /* useExtentsHint */ true)); for (size_t index = 0; index < _motionSampleTimes.size(); ++index) { double relSampleTime = _motionSampleTimes[index]; double time = _currentTime + relSampleTime; bboxCaches[index].SetTime(time); } } FnKat::DoubleBuilder boundBuilder(6); // There must be one bboxCache per motion sample, for efficiency purposes. if (not TF_VERIFY(bboxCaches.size() == _motionSampleTimes.size())) { return ret; } for (size_t i = 0; i < _motionSampleTimes.size(); i++) { ret.push_back(bboxCaches[i].ComputeUntransformedBound(prim)); } return ret; }
TfTokenVector HdPerfLog::GetCacheNames() { _Lock lock(_mutex); TfTokenVector names; names.reserve(_cacheMap.size()); TF_FOR_ALL(tokCacheIt, _cacheMap) { names.push_back(tokCacheIt->first); }
TfTokenVector UsdMayaShadingModeRegistry::_ListImporters() { TfRegistryManager::GetInstance().SubscribeTo<UsdMayaShadingModeImportContext>(); TfTokenVector ret; ret.reserve(_importReg.size()); for (const auto& e : _importReg) { ret.push_back(e.first); } return ret; }
TfTokenVector UsdMayaShadingModeRegistry::_ListExporters() { UsdMaya_RegistryHelper::LoadShadingModePlugins(); TfRegistryManager::GetInstance().SubscribeTo<UsdMayaShadingModeExportContext>(); TfTokenVector ret; ret.reserve(_exportReg.size()); for (const auto& e : _exportReg) { ret.push_back(e.first); } return ret; }
UsdImaging_TestDriver::UsdImaging_TestDriver(std::string const& usdFilePath) : _engine() , _renderDelegate() , _renderIndex(nullptr) , _delegate(nullptr) , _geometryPass() , _renderPassState() , _stage() { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); _Init(UsdStage::Open(usdFilePath), HdTokens->geometry, HdTokens->hull, renderTags); }
UsdImaging_TestDriver::UsdImaging_TestDriver(UsdStageRefPtr const& usdStage) : _engine() , _renderDelegate() , _renderIndex(nullptr) , _delegate(nullptr) , _geometryPass() , _renderPassState() , _stage() { TfTokenVector renderTags; renderTags.push_back(HdTokens->geometry); _Init(usdStage, HdTokens->geometry, HdTokens->hull, renderTags); }
TfTokenVector UsdMayaAdaptor::SchemaAdaptor::GetAttributeNames() const { if (!*this) { return TfTokenVector(); } TfTokenVector attrNames; for (const SdfAttributeSpecHandle attr : _schemaDef->GetAttributes()) { attrNames.push_back(attr->GetNameToken()); } return attrNames; }
UsdMayaAdaptor::SchemaAdaptor UsdMayaAdaptor::ApplySchemaByName( const TfToken& schemaName, MDGModifier& modifier) { if (!*this) { TF_CODING_ERROR("Adaptor is not valid"); return SchemaAdaptor(); } // Get the schema's TfType; its name should be registered as an alias. const TfType schemaType = TfType::Find<UsdSchemaBase>().FindDerivedByName(schemaName); // Make sure that this is an API schema. Only API schemas can be applied. if (!schemaType.IsA<UsdAPISchemaBase>()) { TF_CODING_ERROR("'%s' is not a registered API schema", schemaName.GetText()); return SchemaAdaptor(); } // Make sure that this is an "apply" schema. if (!UsdSchemaRegistry::GetInstance().IsAppliedAPISchema(schemaType)) { TF_CODING_ERROR("'%s' is not an applied API schema", schemaName.GetText()); return SchemaAdaptor(); } // Get the schema definition. If it's registered, there should be a def. SdfPrimSpecHandle primDef = UsdSchemaRegistry::GetInstance().GetPrimDefinition(schemaName); if (!primDef) { TF_CODING_ERROR("Can't find schema definition for name '%s'", schemaName.GetText()); return SchemaAdaptor(); } // Add to schema list (if not yet present). TfTokenVector currentSchemas = GetAppliedSchemas(); if (std::find(currentSchemas.begin(), currentSchemas.end(), schemaName) == currentSchemas.end()) { currentSchemas.push_back(schemaName); SetMetadata( UsdTokens->apiSchemas, _GetListOpForTokenVector(currentSchemas), modifier); } return SchemaAdaptor(_handle.object(), primDef); }
/* static */ UsdUISceneGraphPrimAPI UsdUISceneGraphPrimAPI::Apply(const UsdStagePtr &stage, const SdfPath &path) { // Ensure we have a valid stage, path and prim if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdUISceneGraphPrimAPI(); } if (path == SdfPath::AbsoluteRootPath()) { TF_CODING_ERROR("Cannot apply an api schema on the pseudoroot"); return UsdUISceneGraphPrimAPI(); } auto prim = stage->GetPrimAtPath(path); if (!prim) { TF_CODING_ERROR("Prim at <%s> does not exist.", path.GetText()); return UsdUISceneGraphPrimAPI(); } TfToken apiName("SceneGraphPrimAPI"); // Get the current listop at the edit target UsdEditTarget editTarget = stage->GetEditTarget(); SdfPrimSpecHandle primSpec = editTarget.GetPrimSpecForScenePath(path); SdfTokenListOp listOp = primSpec->GetInfo(UsdTokens->apiSchemas) .UncheckedGet<SdfTokenListOp>(); // Append our name to the prepend list, if it doesnt exist locally TfTokenVector prepends = listOp.GetPrependedItems(); if (std::find(prepends.begin(), prepends.end(), apiName) != prepends.end()) { return UsdUISceneGraphPrimAPI(); } SdfTokenListOp prependListOp; prepends.push_back(apiName); prependListOp.SetPrependedItems(prepends); auto result = listOp.ApplyOperations(prependListOp); if (!result) { TF_CODING_ERROR("Failed to prepend api name to current listop."); return UsdUISceneGraphPrimAPI(); } // Set the listop at the current edit target and return the API prim primSpec->SetInfo(UsdTokens->apiSchemas, VtValue(*result)); return UsdUISceneGraphPrimAPI(prim); }
TfTokenVector UsdMayaAdaptor::SchemaAdaptor::GetAuthoredAttributeNames() const { if (!*this) { return TfTokenVector(); } MFnDependencyNode node(_handle.object()); TfTokenVector result; for (const SdfAttributeSpecHandle& attr : _schemaDef->GetAttributes()) { std::string mayaAttrName = _GetMayaAttrNameOrAlias(attr); if (node.hasAttribute(mayaAttrName.c_str())) { result.push_back(attr->GetNameToken()); } } return result; }
void My_TestGLDrawing::InitTest() { std::cout << "My_TestGLDrawing::InitTest()\n"; _stage = UsdStage::Open(GetStageFilePath()); SdfPathVector excludedPaths; if (UsdImagingGLEngine::IsHydraEnabled()) { std::cout << "Using HD Renderer.\n"; _engine.reset(new UsdImagingGLEngine( _stage->GetPseudoRoot().GetPath(), excludedPaths)); if (!_GetRenderer().IsEmpty()) { if (!_engine->SetRendererPlugin(_GetRenderer())) { std::cerr << "Couldn't set renderer plugin: " << _GetRenderer().GetText() << std::endl; exit(-1); } else { std::cout << "Renderer plugin: " << _GetRenderer().GetText() << std::endl; } } } else{ std::cout << "Using Reference Renderer.\n"; _engine.reset( new UsdImagingGLEngine(_stage->GetPseudoRoot().GetPath(), excludedPaths)); } std::cout << glGetString(GL_VENDOR) << "\n"; std::cout << glGetString(GL_RENDERER) << "\n"; std::cout << glGetString(GL_VERSION) << "\n"; if (_ShouldFrameAll()) { TfTokenVector purposes; purposes.push_back(UsdGeomTokens->default_); purposes.push_back(UsdGeomTokens->proxy); // Extent hints are sometimes authored as an optimization to avoid // computing bounds, they are particularly useful for some tests where // there is no bound on the first frame. bool useExtentHints = true; UsdGeomBBoxCache bboxCache(UsdTimeCode::Default(), purposes, useExtentHints); GfBBox3d bbox = bboxCache.ComputeWorldBound(_stage->GetPseudoRoot()); GfRange3d world = bbox.ComputeAlignedRange(); GfVec3d worldCenter = (world.GetMin() + world.GetMax()) / 2.0; double worldSize = world.GetSize().GetLength(); std::cerr << "worldCenter: " << worldCenter << "\n"; std::cerr << "worldSize: " << worldSize << "\n"; if (UsdGeomGetStageUpAxis(_stage) == UsdGeomTokens->z) { // transpose y and z centering translation _translate[0] = -worldCenter[0]; _translate[1] = -worldCenter[2]; _translate[2] = -worldCenter[1] - worldSize; } else { _translate[0] = -worldCenter[0]; _translate[1] = -worldCenter[1]; _translate[2] = -worldCenter[2] - worldSize; } } else { _translate[0] = GetTranslate()[0]; _translate[1] = GetTranslate()[1]; _translate[2] = GetTranslate()[2]; } if(IsEnabledTestLighting()) { if(UsdImagingGLEngine::IsHydraEnabled()) { // set same parameter as GlfSimpleLightingContext::SetStateFromOpenGL // OpenGL defaults _lightingContext = GlfSimpleLightingContext::New(); GlfSimpleLight light; if (IsEnabledCameraLight()) { light.SetPosition(GfVec4f(_translate[0], _translate[2], _translate[1], 0)); } else { light.SetPosition(GfVec4f(0, -.5, .5, 0)); } light.SetDiffuse(GfVec4f(1,1,1,1)); light.SetAmbient(GfVec4f(0,0,0,1)); light.SetSpecular(GfVec4f(1,1,1,1)); GlfSimpleLightVector lights; lights.push_back(light); _lightingContext->SetLights(lights); GlfSimpleMaterial material; material.SetAmbient(GfVec4f(0.2, 0.2, 0.2, 1.0)); material.SetDiffuse(GfVec4f(0.8, 0.8, 0.8, 1.0)); material.SetSpecular(GfVec4f(0,0,0,1)); material.SetShininess(0.0001f); _lightingContext->SetMaterial(material); _lightingContext->SetSceneAmbient(GfVec4f(0.2,0.2,0.2,1.0)); } else { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); if (IsEnabledCameraLight()) { float position[4] = {_translate[0], _translate[2], _translate[1], 0}; glLightfv(GL_LIGHT0, GL_POSITION, position); } else { float position[4] = {0,-.5,.5,0}; glLightfv(GL_LIGHT0, GL_POSITION, position); } } } }