bool UsdGeomPointInstancer::ComputeExtentAtTime( VtVec3fArray* extent, const UsdTimeCode time, const UsdTimeCode baseTime) const { if (!extent) { TF_WARN("%s -- null container passed to ComputeExtentAtTime()", GetPrim().GetPath().GetText()); return false; } VtIntArray protoIndices; if (!GetProtoIndicesAttr().Get(&protoIndices, time)) { TF_WARN("%s -- no prototype indices", GetPrim().GetPath().GetText()); return false; } const std::vector<bool> mask = ComputeMaskAtTime(time); if (!mask.empty() && mask.size() != protoIndices.size()) { TF_WARN("%s -- mask.size() [%zu] != protoIndices.size() [%zu]", GetPrim().GetPath().GetText(), mask.size(), protoIndices.size()); return false; } const UsdRelationship prototypes = GetPrototypesRel(); SdfPathVector protoPaths; if (!prototypes.GetTargets(&protoPaths) || protoPaths.empty()) { TF_WARN("%s -- no prototypes", GetPrim().GetPath().GetText()); return false; } // verify that all the protoIndices are in bounds. TF_FOR_ALL(iter, protoIndices) { const int protoIndex = *iter; if (protoIndex < 0 || static_cast<size_t>(protoIndex) >= protoPaths.size()) { TF_WARN("%s -- invalid prototype index: %d. Should be in [0, %zu)", GetPrim().GetPath().GetText(), protoIndex, protoPaths.size()); return false; } } // Note that we do NOT apply any masking when computing the instance // transforms. This is so that for a particular instance we can determine // both its transform and its prototype. Otherwise, the instanceTransforms // array would have masked instances culled out and we would lose the // mapping to the prototypes. // Masked instances will be culled before being applied to the extent below. VtMatrix4dArray instanceTransforms; if (!ComputeInstanceTransformsAtTime(&instanceTransforms, time, baseTime, IncludeProtoXform, IgnoreMask)) { TF_WARN("%s -- could not compute instance transforms", GetPrim().GetPath().GetText()); return false; } UsdStageWeakPtr stage = GetPrim().GetStage(); const TfTokenVector purposes { UsdGeomTokens->default_, UsdGeomTokens->proxy, UsdGeomTokens->render }; UsdGeomBBoxCache bboxCache(time, purposes); bboxCache.SetTime(time); GfRange3d extentRange; for (size_t instanceId = 0; instanceId < protoIndices.size(); ++instanceId) { if (!mask.empty() && !mask[instanceId]) { continue; } const int protoIndex = protoIndices[instanceId]; const SdfPath& protoPath = protoPaths[protoIndex]; const UsdPrim& protoPrim = stage->GetPrimAtPath(protoPath); // Get the prototype bounding box. GfBBox3d thisBounds = bboxCache.ComputeUntransformedBound(protoPrim); // Apply the instance transform. thisBounds.Transform(instanceTransforms[instanceId]); extentRange.UnionWith(thisBounds.ComputeAlignedRange()); } const GfVec3d extentMin = extentRange.GetMin(); const GfVec3d extentMax = extentRange.GetMax(); *extent = VtVec3fArray(2); (*extent)[0] = GfVec3f(extentMin[0], extentMin[1], extentMin[2]); (*extent)[1] = GfVec3f(extentMax[0], extentMax[1], extentMax[2]); return true; }
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); } } } }