update FilamentViewer for v1.25 texture & shader providers
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "FilamentViewer.hpp"
|
#include "FilamentViewer.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include <filament/Camera.h>
|
#include <filament/Camera.h>
|
||||||
#include <filament/ColorGrading.h>
|
#include <filament/ColorGrading.h>
|
||||||
#include <filament/Engine.h>
|
#include <filament/Engine.h>
|
||||||
@@ -37,6 +38,9 @@
|
|||||||
#include <gltfio/FilamentAsset.h>
|
#include <gltfio/FilamentAsset.h>
|
||||||
#include <gltfio/ResourceLoader.h>
|
#include <gltfio/ResourceLoader.h>
|
||||||
#include <gltfio/Animator.h>
|
#include <gltfio/Animator.h>
|
||||||
|
#include <gltfio/TextureProvider.h>
|
||||||
|
|
||||||
|
#include <gltfio/materials/uberarchive.h>
|
||||||
|
|
||||||
#include <camutils/Manipulator.h>
|
#include <camutils/Manipulator.h>
|
||||||
|
|
||||||
@@ -50,7 +54,7 @@
|
|||||||
#include <math/vec3.h>
|
#include <math/vec3.h>
|
||||||
#include <math/vec4.h>
|
#include <math/vec4.h>
|
||||||
|
|
||||||
#include <image/KtxUtility.h>
|
#include <ktxreader/Ktx1Reader.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -63,11 +67,6 @@ using namespace gltfio;
|
|||||||
using namespace utils;
|
using namespace utils;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
namespace gltfio
|
|
||||||
{
|
|
||||||
MaterialProvider *createUbershaderLoader(filament::Engine *engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace filament
|
namespace filament
|
||||||
{
|
{
|
||||||
class IndirectLight;
|
class IndirectLight;
|
||||||
@@ -154,14 +153,16 @@ namespace polyvox
|
|||||||
|
|
||||||
_view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOptions);
|
_view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOptions);
|
||||||
|
|
||||||
_materialProvider = gltfio::createUbershaderLoader(_engine);
|
_materialProvider = gltfio::createUbershaderProvider(_engine, UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
|
||||||
|
|
||||||
EntityManager &em = EntityManager::get();
|
EntityManager &em = EntityManager::get();
|
||||||
_ncm = new NameComponentManager(em);
|
_ncm = new NameComponentManager(em);
|
||||||
_assetLoader = AssetLoader::create({_engine, _materialProvider, _ncm, &em});
|
_assetLoader = AssetLoader::create({_engine, _materialProvider, _ncm, &em});
|
||||||
_resourceLoader = new ResourceLoader(
|
_resourceLoader = new ResourceLoader(
|
||||||
{.engine = _engine, .normalizeSkinningWeights = true, .recomputeBoundingBoxes = true});
|
{.engine = _engine, .normalizeSkinningWeights = true, .recomputeBoundingBoxes = true});
|
||||||
|
_stbDecoder = createStbProvider(_engine);
|
||||||
|
_resourceLoader->addTextureProvider("image/png", _stbDecoder);
|
||||||
|
_resourceLoader->addTextureProvider("image/jpeg", _stbDecoder);
|
||||||
manipulator =
|
manipulator =
|
||||||
Manipulator<float>::Builder().orbitHomePosition(0.0f, 0.0f, 0.05f).targetPosition(0.0f, 0.0f, 0.0f).build(Mode::ORBIT);
|
Manipulator<float>::Builder().orbitHomePosition(0.0f, 0.0f, 0.05f).targetPosition(0.0f, 0.0f, 0.0f).build(Mode::ORBIT);
|
||||||
_asset = nullptr;
|
_asset = nullptr;
|
||||||
@@ -299,6 +300,8 @@ namespace polyvox
|
|||||||
|
|
||||||
_animator->updateBoneMatrices();
|
_animator->updateBoneMatrices();
|
||||||
|
|
||||||
|
// transformToUnitCube();
|
||||||
|
|
||||||
Log("Successfully loaded GLB.");
|
Log("Successfully loaded GLB.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,9 +429,9 @@ namespace polyvox
|
|||||||
|
|
||||||
ResourceBuffer skyboxBuffer = _loadResource(skyboxPath);
|
ResourceBuffer skyboxBuffer = _loadResource(skyboxPath);
|
||||||
|
|
||||||
image::KtxBundle *skyboxBundle =
|
image::Ktx1Bundle *skyboxBundle =
|
||||||
new image::KtxBundle(static_cast<const uint8_t *>(skyboxBuffer.data), static_cast<uint32_t>(skyboxBuffer.size));
|
new image::Ktx1Bundle(static_cast<const uint8_t *>(skyboxBuffer.data), static_cast<uint32_t>(skyboxBuffer.size));
|
||||||
_skyboxTexture = image::ktx::createTexture(_engine, skyboxBundle, false);
|
_skyboxTexture = ktxreader::Ktx1Reader::createTexture(_engine, skyboxBundle, false);
|
||||||
_skybox = filament::Skybox::Builder().environment(_skyboxTexture).build(*_engine);
|
_skybox = filament::Skybox::Builder().environment(_skyboxTexture).build(*_engine);
|
||||||
|
|
||||||
_scene->setSkybox(_skybox);
|
_scene->setSkybox(_skybox);
|
||||||
@@ -439,11 +442,11 @@ namespace polyvox
|
|||||||
// Load IBL.
|
// Load IBL.
|
||||||
ResourceBuffer iblBuffer = _loadResource(iblPath);
|
ResourceBuffer iblBuffer = _loadResource(iblPath);
|
||||||
|
|
||||||
image::KtxBundle *iblBundle = new image::KtxBundle(
|
image::Ktx1Bundle *iblBundle = new image::Ktx1Bundle(
|
||||||
static_cast<const uint8_t *>(iblBuffer.data), static_cast<uint32_t>(iblBuffer.size));
|
static_cast<const uint8_t *>(iblBuffer.data), static_cast<uint32_t>(iblBuffer.size));
|
||||||
math::float3 harmonics[9];
|
math::float3 harmonics[9];
|
||||||
iblBundle->getSphericalHarmonics(harmonics);
|
iblBundle->getSphericalHarmonics(harmonics);
|
||||||
_iblTexture = image::ktx::createTexture(_engine, iblBundle, false);
|
_iblTexture = ktxreader::Ktx1Reader::createTexture(_engine, iblBundle, false);
|
||||||
_indirectLight = IndirectLight::Builder()
|
_indirectLight = IndirectLight::Builder()
|
||||||
.reflections(_iblTexture)
|
.reflections(_iblTexture)
|
||||||
.irradiance(3, harmonics)
|
.irradiance(3, harmonics)
|
||||||
@@ -496,7 +499,7 @@ namespace polyvox
|
|||||||
{
|
{
|
||||||
if (!_view || !_mainCamera || !_swapChain)
|
if (!_view || !_mainCamera || !_swapChain)
|
||||||
{
|
{
|
||||||
// Log("Not ready for rendering");
|
Log("Not ready for rendering");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ namespace polyvox {
|
|||||||
MaterialProvider* _materialProvider;
|
MaterialProvider* _materialProvider;
|
||||||
|
|
||||||
gltfio::ResourceLoader* _resourceLoader = nullptr;
|
gltfio::ResourceLoader* _resourceLoader = nullptr;
|
||||||
|
gltfio::TextureProvider* _stbDecoder = nullptr;
|
||||||
bool _recomputeAabb = false;
|
bool _recomputeAabb = false;
|
||||||
|
|
||||||
bool _actualSize = false;
|
bool _actualSize = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user