Add Camera Guide viewport toggle (stageView.py DrawCameraGuides port)
Adds a per-viewport "Camera Guide" toggle (default off) that draws a full frustum wireframe box (near quad + far quad + 4 connecting edges) in oracle orange for every non-active UsdGeomCamera prim, matching usdview's displayCameraOracles behaviour. Uses GfFrustum::ComputeCorners() and the same 24-index line layout as DrawCameraGuides. Toggle exposed in the right-click context menu and gear popup; persists to INI as ShowCameraGuide. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -166,6 +166,7 @@ void main() { outColor = color; }
|
||||
|
||||
UsdSceneRenderer::UsdSceneRenderer()
|
||||
: m_showGrid(true)
|
||||
, m_showCameraGuide(false)
|
||||
, m_aaEnabled(false)
|
||||
, m_backgroundColor(0.15f, 0.15f, 0.15f)
|
||||
, m_shadingMode(ShadingMode::SmoothShaded)
|
||||
@@ -1464,6 +1465,26 @@ void UsdSceneRenderer::BuildCameraWireframeLines(const pxr::GfCamera& gfCam,
|
||||
push(arrowBase, arrowTip);
|
||||
}
|
||||
|
||||
// Builds near quad + far quad + 4 connecting edges for the full GfFrustum.
|
||||
// Mirrors stageView.py DrawCameraGuides: corners via GfFrustum::ComputeCorners(),
|
||||
// line pairs via the same 24-index layout. Appends 24 XYZ float triples.
|
||||
static void BuildCameraGuideLines(const pxr::GfCamera& gfCam,
|
||||
std::vector<float>& outVerts)
|
||||
{
|
||||
const std::vector<pxr::GfVec3d> c = gfCam.GetFrustum().ComputeCorners();
|
||||
// 0=LBN 1=RBN 2=LTN 3=RTN 4=LBF 5=RBF 6=LTF 7=RTF
|
||||
static const int kIdx[24] = {
|
||||
0,1, 1,3, 3,2, 2,0, // near quad
|
||||
4,5, 5,7, 7,6, 6,4, // far quad
|
||||
3,7, 0,4, 1,5, 2,6 // connecting edges
|
||||
};
|
||||
for (int i : kIdx) {
|
||||
outVerts.push_back(static_cast<float>(c[i][0]));
|
||||
outVerts.push_back(static_cast<float>(c[i][1]));
|
||||
outVerts.push_back(static_cast<float>(c[i][2]));
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// DrawCameraWireframes
|
||||
// ===========================================================================
|
||||
@@ -1518,6 +1539,8 @@ void UsdSceneRenderer::DrawCameraWireframes(
|
||||
|
||||
pxr::GfMatrix4f vp = pxr::GfMatrix4f(viewProjMatrix);
|
||||
|
||||
std::vector<float> guideVerts; // accumulates frustum oracle lines
|
||||
|
||||
for (const auto& camPath : m_cachedCameraPaths) {
|
||||
pxr::UsdPrim prim = stage->GetPrimAtPath(camPath);
|
||||
if (!prim) continue;
|
||||
@@ -1553,6 +1576,23 @@ void UsdSceneRenderer::DrawCameraWireframes(
|
||||
glBindVertexArray(m_camWireVAO);
|
||||
glDrawArrays(GL_LINES, 0, vertCount);
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Accumulate full-frustum oracle lines for non-active cameras (stageView.DrawCameraGuides)
|
||||
if (m_showCameraGuide && !isActive)
|
||||
BuildCameraGuideLines(gfCam, guideVerts);
|
||||
}
|
||||
|
||||
// Draw all camera guide frustum boxes in one call (oracle orange from stageView.py)
|
||||
if (m_showCameraGuide && !guideVerts.empty()) {
|
||||
glUniform4f(m_bboxUniformColor, 0.82745f, 0.39608f, 0.16471f, 1.0f);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_camWireVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
static_cast<GLsizeiptr>(guideVerts.size() * sizeof(float)),
|
||||
guideVerts.data(), GL_DYNAMIC_DRAW);
|
||||
glUniformMatrix4fv(m_bboxUniformMVP, 1, GL_TRUE, vp.GetArray());
|
||||
glBindVertexArray(m_camWireVAO);
|
||||
glDrawArrays(GL_LINES, 0, static_cast<int>(guideVerts.size() / 3));
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
// Restore GL state
|
||||
|
||||
Reference in New Issue
Block a user