add setFirstCamera method to FilamentViewer
This commit is contained in:
@@ -155,7 +155,6 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource,
|
|||||||
.build(*_engine, _sun);
|
.build(*_engine, _sun);
|
||||||
_scene->addEntity(_sun);
|
_scene->addEntity(_sun);
|
||||||
|
|
||||||
|
|
||||||
_sceneAssetLoader = new SceneAssetLoader(_loadResource,
|
_sceneAssetLoader = new SceneAssetLoader(_loadResource,
|
||||||
_freeResource,
|
_freeResource,
|
||||||
_assetLoader,
|
_assetLoader,
|
||||||
@@ -372,11 +371,27 @@ void FilamentViewer::removeAsset(SceneAsset *asset) {
|
|||||||
mtx.unlock();
|
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].
|
/// Sets the active camera to the GLTF camera node specified by [name].
|
||||||
/// N.B. Blender will generally export a three-node hierarchy -
|
/// N.B. Blender will generally export a three-node hierarchy -
|
||||||
/// Camera1->Camera_Orientation->Camera2. The correct name will be the
|
/// Camera1->Camera_Orientation->Camera2. The correct name will be the Camera_Orientation.
|
||||||
/// grandchild (i.e. Camera2 in this scenario).
|
|
||||||
///
|
///
|
||||||
bool FilamentViewer::setCamera(SceneAsset *asset, const char *cameraName) {
|
bool FilamentViewer::setCamera(SceneAsset *asset, const char *cameraName) {
|
||||||
Log("Attempting to set camera to %s.", 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 Viewport &vp = _view->getViewport();
|
||||||
const double aspect = (double)vp.width / vp.height;
|
const double aspect = (double)vp.width / vp.height;
|
||||||
|
|
||||||
Log("Camera focal length : %f aspect %f", camera->getFocalLength(),
|
const float aperture = camera->getAperture();
|
||||||
aspect);
|
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});
|
camera->setScaling({1.0 / aspect, 1.0});
|
||||||
Log("Successfully set camera.");
|
Log("Successfully set camera.");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ namespace polyvox {
|
|||||||
|
|
||||||
Manipulator<float>* manipulator;
|
Manipulator<float>* manipulator;
|
||||||
|
|
||||||
|
bool setFirstCamera(SceneAsset* asset);
|
||||||
bool setCamera(SceneAsset* asset, const char* nodeName);
|
bool setCamera(SceneAsset* asset, const char* nodeName);
|
||||||
void destroySwapChain();
|
void destroySwapChain();
|
||||||
void createSwapChain(void* surface);
|
void createSwapChain(void* surface);
|
||||||
|
|||||||
Reference in New Issue
Block a user