add removeSkybox

This commit is contained in:
Nick Fisher
2022-07-16 17:34:56 +10:00
parent a8ef628316
commit d512ebd38f
8 changed files with 74 additions and 50 deletions

View File

@@ -59,6 +59,8 @@
#include <chrono>
#include <iostream>
#include <mutex>
#include "Log.h"
using namespace filament;
@@ -259,27 +261,11 @@ namespace polyvox
_scene->addEntities(_asset->getEntities(), _asset->getEntityCount());
};
void FilamentViewer::releaseSourceAssets()
{
Log("Releasing source data");
_asset->releaseSourceData();
}
void FilamentViewer::loadGlb(const char *const uri)
{
Log("Loading GLB at URI %s", uri);
// if (_asset)
// {
// _asset->releaseSourceData();
// _resourceLoader->evictResourceData();
// _scene->removeEntities(_asset->getEntities(), _asset->getEntityCount());
// _assetLoader->destroyAsset(_asset);
// }
// _asset = nullptr;
// _animator = nullptr;
ResourceBuffer rbuf = _loadResource(uri);
_asset = _assetLoader->createAssetFromBinary(
@@ -354,6 +340,8 @@ namespace polyvox
Log("No asset loaded, ignoring call.");
return;
}
mtx.lock();
_resourceLoader->evictResourceData();
_scene->removeEntities(_asset->getEntities(), _asset->getEntityCount());
@@ -362,6 +350,12 @@ namespace polyvox
_animator = nullptr;
_morphAnimationBuffer = nullptr;
_embeddedAnimationBuffer = nullptr;
_view->setCamera(_mainCamera);
mtx.unlock();
}
void FilamentViewer::removeSkybox() {
_scene->setSkybox(nullptr);
}
@@ -384,7 +378,7 @@ namespace polyvox
}
const utils::Entity* cameras = _asset->getCameraEntities();
Log("%d cameras found in current asset", cameraName, count);
Log("%zu cameras found in current asset", cameraName, count);
for(int i=0; i < count; i++) {
auto inst = _ncm->getInstance(cameras[i]);
@@ -411,7 +405,10 @@ namespace polyvox
unique_ptr<vector<string>> FilamentViewer::getAnimationNames()
{
if(!_asset) {
Log("No asset, ignoring call.");
return nullptr;
}
size_t count = _animator->getAnimationCount();
Log("Found %d animations in asset.", count);
@@ -428,6 +425,10 @@ namespace polyvox
unique_ptr<vector<string>> FilamentViewer::getTargetNames(const char *meshName)
{
if(!_asset) {
Log("No asset, ignoring call.");
return nullptr;
}
Log("Retrieving morph target names for mesh %s", meshName);
unique_ptr<vector<string>> names = make_unique<vector<string>>();
const Entity *entities = _asset->getEntities();
@@ -512,20 +513,19 @@ namespace polyvox
void FilamentViewer::render()
{
if (!_view || !_mainCamera || !_swapChain)
{
Log("Not ready for rendering");
return;
}
if (_morphAnimationBuffer)
{
mtx.lock();
if(_asset) {
updateMorphAnimation();
}
if(_embeddedAnimationBuffer) {
updateEmbeddedAnimation();
}
math::float3 eye, target, upward;
manipulator->getLookAt(&eye, &target, &upward);
@@ -537,6 +537,7 @@ namespace polyvox
_renderer->render(_view);
_renderer->endFrame();
}
mtx.unlock();
}
void FilamentViewer::updateViewportAndCameraProjection(int width, int height, float contentScaleFactor)
@@ -607,6 +608,9 @@ namespace polyvox
}
void FilamentViewer::updateEmbeddedAnimation() {
if(!_embeddedAnimationBuffer) {
return;
}
duration<double> dur = duration_cast<duration<double>>(high_resolution_clock::now() - _embeddedAnimationBuffer->lastTime);
float startTime = 0;
if(!_embeddedAnimationBuffer->hasStarted) {

View File

@@ -92,14 +92,16 @@ namespace polyvox {
public:
FilamentViewer(void* layer, LoadResource loadResource, FreeResource freeResource);
~FilamentViewer();
void loadSkybox(const char* const skyboxUri, const char* const iblUri);
void removeSkybox();
void loadGlb(const char* const uri);
void loadGltf(const char* const uri, const char* relativeResourcePath);
void loadSkybox(const char* const skyboxUri, const char* const iblUri);
void removeAsset();
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
void render();
void releaseSourceAssets();
unique_ptr<vector<string>> getTargetNames(const char* meshName);
unique_ptr<vector<string>> getAnimationNames();
Manipulator<float>* manipulator;
@@ -158,8 +160,8 @@ namespace polyvox {
AssetLoader* _assetLoader;
FilamentAsset* _asset = nullptr;
// ResourceBuffer _assetBuffer;
NameComponentManager* _ncm;
std::mutex mtx; // mutex to ensure thread safety when removing assets
Entity _sun;
Texture* _skyboxTexture;
@@ -184,6 +186,7 @@ namespace polyvox {
bool isAnimating;
unique_ptr<MorphAnimationBuffer> _morphAnimationBuffer;
unique_ptr<EmbeddedAnimationBuffer> _embeddedAnimationBuffer;
};