@@ -147,6 +147,12 @@ void Viewport::setLibrary(const std::string &libName, bool doAsync)
147
147
if (d) {
148
148
anari::retain (d, d);
149
149
150
+ m_device = d;
151
+ if (auto *exts = m_core->loadDeviceExtensions (libName); exts != nullptr )
152
+ m_extensions = *exts;
153
+ else
154
+ m_extensions = {};
155
+
150
156
tsd::logStatus (" [viewport] getting renderer params..." );
151
157
152
158
const char **r_subtypes = anariGetObjectSubtypes (d, ANARI_RENDERER);
@@ -171,8 +177,11 @@ void Viewport::setLibrary(const std::string &libName, bool doAsync)
171
177
}
172
178
173
179
m_perspCamera = anari::newObject<anari::Camera>(d, " perspective" );
174
- m_orthoCamera = anari::newObject<anari::Camera>(d, " orthographic" );
175
- m_omniCamera = anari::newObject<anari::Camera>(d, " omnidirectional" );
180
+ m_currentCamera = m_perspCamera;
181
+ if (m_extensions.ANARI_KHR_CAMERA_ORTHOGRAPHIC )
182
+ m_orthoCamera = anari::newObject<anari::Camera>(d, " orthographic" );
183
+ if (m_extensions.ANARI_KHR_CAMERA_OMNIDIRECTIONAL )
184
+ m_omniCamera = anari::newObject<anari::Camera>(d, " omnidirectional" );
176
185
177
186
tsd::logStatus (" [viewport] populating render index..." );
178
187
@@ -181,8 +190,6 @@ void Viewport::setLibrary(const std::string &libName, bool doAsync)
181
190
182
191
tsd::logStatus (" [viewport] getting scene bounds..." );
183
192
184
- m_device = d;
185
-
186
193
if (g_firstFrame || m_arcball->distance () == inf) {
187
194
resetView (true );
188
195
g_firstFrame = false ;
@@ -327,12 +334,7 @@ void Viewport::updateFrame()
327
334
return ;
328
335
329
336
m_rud.r = m_renderers[m_currentRenderer];
330
- if (m_cameraModel == CameraModel::Orthographic)
331
- m_anariPass->setCamera (m_orthoCamera);
332
- else if (m_cameraModel == CameraModel::Omnidirectional)
333
- m_anariPass->setCamera (m_omniCamera);
334
- else
335
- m_anariPass->setCamera (m_perspCamera);
337
+ m_anariPass->setCamera (m_currentCamera);
336
338
m_anariPass->setRenderer (m_rud.r );
337
339
m_anariPass->setWorld (m_rIdx->world ());
338
340
}
@@ -345,39 +347,47 @@ void Viewport::updateCamera(bool force)
345
347
if ((!force && !m_arcball->hasChanged (m_cameraToken)))
346
348
return ;
347
349
350
+ // perspective camera //
351
+
348
352
anari::setParameter (m_device, m_perspCamera, " position" , m_arcball->eye ());
349
353
anari::setParameter (m_device, m_perspCamera, " direction" , m_arcball->dir ());
350
354
anari::setParameter (m_device, m_perspCamera, " up" , m_arcball->up ());
351
-
352
- anari::setParameter (
353
- m_device, m_orthoCamera, " position" , m_arcball->eye_FixedDistance ());
354
- anari::setParameter (m_device, m_orthoCamera, " direction" , m_arcball->dir ());
355
- anari::setParameter (m_device, m_orthoCamera, " up" , m_arcball->up ());
356
- anari::setParameter (
357
- m_device, m_orthoCamera, " height" , m_arcball->distance () * 0 .75f );
358
-
359
- anari::setParameter (m_device, m_omniCamera, " position" , m_arcball->eye ());
360
- anari::setParameter (m_device, m_omniCamera, " direction" , m_arcball->dir ());
361
- anari::setParameter (m_device, m_omniCamera, " up" , m_arcball->up ());
362
-
363
355
anari::setParameter (m_device,
364
356
m_perspCamera,
365
357
" aspect" ,
366
358
m_viewportSize.x / float (m_viewportSize.y ));
367
- anari::setParameter (m_device,
368
- m_orthoCamera,
369
- " aspect" ,
370
- m_viewportSize.x / float (m_viewportSize.y ));
371
359
anari::setParameter (
372
360
m_device, m_perspCamera, " apertureRadius" , m_apertureRadius);
373
361
anari::setParameter (
374
362
m_device, m_perspCamera, " focusDistance" , m_focusDistance);
375
363
376
364
anari::setParameter (m_device, m_perspCamera, " fovy" , anari::radians (m_fov));
377
-
378
365
anari::commitParameters (m_device, m_perspCamera);
379
- anari::commitParameters (m_device, m_orthoCamera);
380
- anari::commitParameters (m_device, m_omniCamera);
366
+
367
+ // orthographic camera //
368
+
369
+ if (m_orthoCamera) {
370
+ anari::setParameter (
371
+ m_device, m_orthoCamera, " position" , m_arcball->eye_FixedDistance ());
372
+ anari::setParameter (m_device, m_orthoCamera, " direction" , m_arcball->dir ());
373
+ anari::setParameter (m_device, m_orthoCamera, " up" , m_arcball->up ());
374
+ anari::setParameter (
375
+ m_device, m_orthoCamera, " height" , m_arcball->distance () * 0 .75f );
376
+ anari::setParameter (m_device,
377
+ m_orthoCamera,
378
+ " aspect" ,
379
+ m_viewportSize.x / float (m_viewportSize.y ));
380
+ anari::commitParameters (m_device, m_orthoCamera);
381
+ }
382
+
383
+ // omnidirectional camera //
384
+
385
+ if (m_omniCamera) {
386
+ anari::setParameter (m_device, m_omniCamera, " position" , m_arcball->eye ());
387
+ anari::setParameter (m_device, m_omniCamera, " direction" , m_arcball->dir ());
388
+ anari::setParameter (m_device, m_omniCamera, " up" , m_arcball->up ());
389
+ anari::commitParameters (m_device, m_omniCamera);
390
+ }
381
391
382
392
if (m_echoCameraConfig)
383
393
echoCameraConfig ();
@@ -517,7 +527,7 @@ void Viewport::ui_picking()
517
527
518
528
// Pick view center //
519
529
520
- const bool shouldPickCenter = m_cameraModel == CameraModel::Perspective
530
+ const bool shouldPickCenter = m_currentCamera == m_perspCamera
521
531
&& ImGui::IsMouseDoubleClicked (ImGuiMouseButton_Left)
522
532
&& io.KeysDown [GLFW_KEY_LEFT_SHIFT];
523
533
if (shouldPickCenter && ImGui::IsWindowHovered ()) {
@@ -650,15 +660,37 @@ void Viewport::ui_contextMenu()
650
660
ImGui::Text (" Camera:" );
651
661
ImGui::Indent (INDENT_AMOUNT);
652
662
653
- if (ImGui::RadioButton (
654
- " perspective" , &m_cameraModel, CameraModel::Perspective)
655
- || ImGui::RadioButton (
656
- " orthographic" , &m_cameraModel, CameraModel::Orthographic)
657
- || ImGui::RadioButton (
658
- " omnidirectional" , &m_cameraModel, CameraModel::Omnidirectional))
659
- updateFrame ();
663
+ if (ImGui::BeginMenu (" type" )) {
664
+ bool changeType = false ;
665
+ if (ImGui::RadioButton (
666
+ " perspective" , m_currentCamera == m_perspCamera)) {
667
+ m_currentCamera = m_perspCamera;
668
+ changeType = true ;
669
+ }
670
+
671
+ ImGui::BeginDisabled (!m_orthoCamera);
672
+ if (ImGui::RadioButton (" orthographic" ,
673
+ m_orthoCamera && m_currentCamera == m_orthoCamera)) {
674
+ m_currentCamera = m_orthoCamera;
675
+ changeType = true ;
676
+ }
677
+ ImGui::EndDisabled ();
678
+
679
+ ImGui::BeginDisabled (!m_omniCamera);
680
+ if (ImGui::RadioButton (" omnidirectional" ,
681
+ m_omniCamera && m_currentCamera == m_omniCamera)) {
682
+ m_currentCamera = m_omniCamera;
683
+ changeType = true ;
684
+ }
685
+ ImGui::EndDisabled ();
686
+
687
+ if (changeType)
688
+ updateFrame ();
689
+
690
+ ImGui::EndMenu ();
691
+ }
660
692
661
- ImGui::BeginDisabled (m_cameraModel != CameraModel::Perspective );
693
+ ImGui::BeginDisabled (m_currentCamera != m_perspCamera );
662
694
663
695
if (ImGui::SliderFloat (" fov" , &m_fov, 0 .1f , 180 .f ))
664
696
updateCamera (true );
0 commit comments