add GLB view
This commit is contained in:
@@ -153,7 +153,6 @@ FilamentViewer::FilamentViewer(
|
|||||||
fadeShaderResources.data,
|
fadeShaderResources.data,
|
||||||
fadeShaderResources.size,
|
fadeShaderResources.size,
|
||||||
_engine);
|
_engine);
|
||||||
// _freeResource((void*)rb.data, rb.size, nullptr); <- TODO this is being freed too early, need to pass to callback?
|
|
||||||
// } else {
|
// } else {
|
||||||
// _materialProvider = foo::createUbershaderLoader(_engine);
|
// _materialProvider = foo::createUbershaderLoader(_engine);
|
||||||
// }
|
// }
|
||||||
@@ -164,7 +163,7 @@ FilamentViewer::FilamentViewer(
|
|||||||
{.engine = _engine, .normalizeSkinningWeights = true, .recomputeBoundingBoxes = false});
|
{.engine = _engine, .normalizeSkinningWeights = true, .recomputeBoundingBoxes = false});
|
||||||
|
|
||||||
manipulator =
|
manipulator =
|
||||||
Manipulator<float>::Builder().orbitHomePosition(0.0f, 0.0f, 0.0f).targetPosition(0.0f, 0.0f, 0).build(Mode::ORBIT);
|
Manipulator<float>::Builder().orbitHomePosition(0.0f, -1.4f, 1.0f).targetPosition(0.0f, -0.5f, 0.75f).build(Mode::ORBIT);
|
||||||
_asset = nullptr;
|
_asset = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -218,25 +217,31 @@ void FilamentViewer::animateWeights(float* data, int numWeights, int length, flo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::loadGlb(const char* const uri) {
|
void FilamentViewer::loadGlb(const char* const uri) {
|
||||||
|
|
||||||
|
std::cerr << "Loading GLB at URI " << uri << std::endl;
|
||||||
|
|
||||||
if(_asset) {
|
if(_asset) {
|
||||||
_resourceLoader->evictResourceData();
|
_resourceLoader->evictResourceData();
|
||||||
_scene->removeEntities(_asset->getEntities(), _asset->getEntityCount());
|
_scene->removeEntities(_asset->getEntities(), _asset->getEntityCount());
|
||||||
_assetLoader->destroyAsset(_asset);
|
_assetLoader->destroyAsset(_asset);
|
||||||
}
|
}
|
||||||
_asset = nullptr;
|
_asset = nullptr;
|
||||||
_animator = nullptr;
|
_animator = nullptr;
|
||||||
|
|
||||||
ResourceBuffer rbuf = _loadResource(uri);
|
ResourceBuffer rbuf = _loadResource(uri);
|
||||||
|
|
||||||
// Parse the glTF file and create Filament entities.
|
_asset = _assetLoader->createAssetFromBinary(
|
||||||
_asset = _assetLoader->createAssetFromJson((uint8_t*)rbuf.data, rbuf.size);
|
(const uint8_t*)rbuf.data, rbuf.size);
|
||||||
|
|
||||||
|
if (!_asset) {
|
||||||
|
std::cerr << "Unknown error loading GLB asset." << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!_asset) {
|
_scene->addEntities(_asset->getEntities(), _asset->getEntityCount());
|
||||||
std::cerr << "Unable to parse asset" << std::endl;
|
_resourceLoader->loadResources(_asset);
|
||||||
exit(1);
|
_animator = _asset->getAnimator();
|
||||||
}
|
|
||||||
|
|
||||||
_resourceLoader->loadResources(_asset);
|
|
||||||
const Entity* entities = _asset->getEntities();
|
const Entity* entities = _asset->getEntities();
|
||||||
RenderableManager& rm = _engine->getRenderableManager();
|
RenderableManager& rm = _engine->getRenderableManager();
|
||||||
for(int i =0; i< _asset->getEntityCount(); i++) {
|
for(int i =0; i< _asset->getEntityCount(); i++) {
|
||||||
@@ -245,14 +250,11 @@ void FilamentViewer::loadGlb(const char* const uri) {
|
|||||||
rm.setCulling(inst, false);
|
rm.setCulling(inst, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_animator = _asset->getAnimator();
|
|
||||||
|
|
||||||
_scene->addEntities(_asset->getEntities(), _asset->getEntityCount());
|
|
||||||
|
|
||||||
|
|
||||||
_freeResource((void*)rbuf.data, rbuf.size, nullptr);
|
_freeResource((void*)rbuf.data, rbuf.size, nullptr);
|
||||||
|
|
||||||
transformToUnitCube();
|
transformToUnitCube();
|
||||||
|
|
||||||
|
std::cerr << "Successfully loaded GLB." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::loadGltf(const char* const uri, const char* const relativeResourcePath) {
|
void FilamentViewer::loadGltf(const char* const uri, const char* const relativeResourcePath) {
|
||||||
@@ -284,15 +286,22 @@ void FilamentViewer::loadGltf(const char* const uri, const char* const relativeR
|
|||||||
|
|
||||||
StringList FilamentViewer::getTargetNames(const char* meshName) {
|
StringList FilamentViewer::getTargetNames(const char* meshName) {
|
||||||
FFilamentAsset* asset = (FFilamentAsset*)_asset;
|
FFilamentAsset* asset = (FFilamentAsset*)_asset;
|
||||||
|
|
||||||
NodeMap &sourceNodes = asset->isInstanced() ? asset->mInstances[0]->nodeMap
|
NodeMap &sourceNodes = asset->isInstanced() ? asset->mInstances[0]->nodeMap
|
||||||
: asset->mNodeMap;
|
: asset->mNodeMap;
|
||||||
|
FilamentInstance** instances = asset->getAssetInstances();
|
||||||
|
std::cout << "Fetching morph target names for mesh " << meshName;
|
||||||
for (auto pair : sourceNodes) {
|
for (auto pair : sourceNodes) {
|
||||||
cgltf_node const *node = pair.first;
|
cgltf_node const *node = pair.first;
|
||||||
cgltf_mesh const *mesh = node->mesh;
|
cgltf_mesh const *mesh = node->mesh;
|
||||||
|
|
||||||
if (mesh && strcmp(meshName, mesh->name) == 0) {
|
if (mesh) {
|
||||||
return StringList((const char**)mesh->target_names, (int) mesh->target_names_count);
|
std::cout << "Mesh : " << mesh->name;
|
||||||
|
if(strcmp(meshName, mesh->name) == 0) {
|
||||||
|
return StringList((const char**)mesh->target_names, (int) mesh->target_names_count);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << "No mesh attached to node";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return StringList(nullptr, 0);
|
return StringList(nullptr, 0);
|
||||||
@@ -374,7 +383,7 @@ void FilamentViewer::loadSkybox(const char* const skyboxPath, const char* const
|
|||||||
LightManager::Builder(LightManager::Type::DIRECTIONAL)
|
LightManager::Builder(LightManager::Type::DIRECTIONAL)
|
||||||
.color(Color::cct(6500.0f))
|
.color(Color::cct(6500.0f))
|
||||||
.intensity(100000.0f)
|
.intensity(100000.0f)
|
||||||
.direction(math::float3(0.0f, -1.0f, 0.0f))
|
.direction(math::float3(0.0f, 1.0f, 0.0f))
|
||||||
.castShadows(true)
|
.castShadows(true)
|
||||||
.build(*_engine, _sun);
|
.build(*_engine, _sun);
|
||||||
_scene->addEntity(_sun);
|
_scene->addEntity(_sun);
|
||||||
|
|||||||
Reference in New Issue
Block a user