From 4aef34b2ae4e2bdad6acca33fa4a49a39c508195 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 16 Aug 2022 11:32:03 +1000 Subject: [PATCH] add setFirstCamera method to FilamentViewer --- ios/src/FilamentViewer.cpp | 31 ++++++++++++++++++++++++++----- ios/src/FilamentViewer.hpp | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index 43d1eaab..79998481 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -154,7 +154,6 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource, // .castShadows(true) .build(*_engine, _sun); _scene->addEntity(_sun); - _sceneAssetLoader = new SceneAssetLoader(_loadResource, _freeResource, @@ -372,11 +371,27 @@ void FilamentViewer::removeAsset(SceneAsset *asset) { mtx.unlock(); } +/// +/// Sets the active camera to the first GLTF camera node found in the hierarchy. +/// Useful when your asset only has one camera. +/// +bool FilamentViewer::setFirstCamera(SceneAsset *asset) { + size_t count = asset->getCameraEntityCount(); + if (count == 0) { + Log("Failed, no cameras found in current asset."); + return false; + } + const utils::Entity *cameras = asset->getCameraEntities(); + Log("%zu cameras found in asset", count); + auto inst = _ncm->getInstance(cameras[0]); + const char *name = _ncm->getName(inst); + return setCamera(asset, name); +} + /// /// Sets the active camera to the GLTF camera node specified by [name]. /// N.B. Blender will generally export a three-node hierarchy - -/// Camera1->Camera_Orientation->Camera2. The correct name will be the -/// grandchild (i.e. Camera2 in this scenario). +/// Camera1->Camera_Orientation->Camera2. The correct name will be the Camera_Orientation. /// bool FilamentViewer::setCamera(SceneAsset *asset, const char *cameraName) { Log("Attempting to set camera to %s.", cameraName); @@ -401,8 +416,14 @@ bool FilamentViewer::setCamera(SceneAsset *asset, const char *cameraName) { const Viewport &vp = _view->getViewport(); const double aspect = (double)vp.width / vp.height; - Log("Camera focal length : %f aspect %f", camera->getFocalLength(), - aspect); + const float aperture = camera->getAperture(); + const float shutterSpeed = camera->getShutterSpeed(); + const float sens = camera->getSensitivity(); + + // camera->setExposure(1.0f); + + Log("Camera focal length : %f aspect %f aperture %f shutter %f sensitivity %f", camera->getFocalLength(), + aspect, aperture, shutterSpeed, sens); camera->setScaling({1.0 / aspect, 1.0}); Log("Successfully set camera."); return true; diff --git a/ios/src/FilamentViewer.hpp b/ios/src/FilamentViewer.hpp index 4ec61913..0d9cbab1 100644 --- a/ios/src/FilamentViewer.hpp +++ b/ios/src/FilamentViewer.hpp @@ -65,6 +65,7 @@ namespace polyvox { Manipulator* manipulator; + bool setFirstCamera(SceneAsset* asset); bool setCamera(SceneAsset* asset, const char* nodeName); void destroySwapChain(); void createSwapChain(void* surface);