Merge branch 'master' of github.com:nmfisher/polyvox_filament
This commit is contained in:
@@ -141,12 +141,13 @@ extern "C" {
|
||||
((FilamentViewer*)viewer)->grabEnd();
|
||||
}
|
||||
|
||||
void apply_weights(void* asset, float* const weights, int count) {
|
||||
((SceneAsset*)asset)->setMorphTargetWeights(weights, count);
|
||||
void apply_weights(void* asset, const char* const entityName, float* const weights, int count) {
|
||||
((SceneAsset*)asset)->setMorphTargetWeights(entityName, weights, count);
|
||||
}
|
||||
|
||||
void set_animation(
|
||||
void* asset,
|
||||
const char* const entityName,
|
||||
const float* const morphData,
|
||||
int numMorphWeights,
|
||||
const BoneAnimation* const boneAnimations,
|
||||
@@ -154,6 +155,7 @@ extern "C" {
|
||||
int numFrames,
|
||||
float frameLengthInMs) {
|
||||
((SceneAsset*)asset)->setAnimation(
|
||||
entityName,
|
||||
morphData,
|
||||
numMorphWeights,
|
||||
boneAnimations,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/TransformManager.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <filament/RenderableManager.h>
|
||||
|
||||
#include <gltfio/Animator.h>
|
||||
#include <gltfio/AssetLoader.h>
|
||||
@@ -48,15 +49,12 @@ SceneAsset::~SceneAsset() {
|
||||
}
|
||||
}
|
||||
|
||||
void SceneAsset::setMorphTargetWeights(float *weights, int count) {
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
for (size_t i = 0, c = _asset->getEntityCount(); i != c; ++i) {
|
||||
auto inst = rm.getInstance(_asset->getEntities()[i]);
|
||||
rm.setMorphWeights(inst, weights, count);
|
||||
}
|
||||
void SceneAsset::setMorphTargetWeights(const char* const entityName, float *weights, int count) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void SceneAsset::setAnimation(
|
||||
const char* entityName,
|
||||
const float* const morphData,
|
||||
int numMorphWeights,
|
||||
const BoneAnimation* const boneAnimations,
|
||||
@@ -107,13 +105,31 @@ void SceneAsset::setAnimation(
|
||||
frameData
|
||||
));
|
||||
}
|
||||
_runtimeAnimationBuffer = std::make_unique<RuntimeAnimation>(
|
||||
morphData,
|
||||
numMorphWeights,
|
||||
transforms,
|
||||
numFrames,
|
||||
frameLengthInMs
|
||||
);
|
||||
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
Instance inst;
|
||||
for (size_t i = 0, c = _asset->getEntityCount(); i != c; ++i) {
|
||||
auto entity = _asset->getEntities()[i];
|
||||
auto name = _ncm->getName(_ncm->getInstance(entity));
|
||||
|
||||
if(strcmp(entityName,name)==0) {
|
||||
inst = rm.getInstance(_asset->getEntities()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!inst) {
|
||||
Log("Warning: failed to find Renderable instance for entity %s", entityName);
|
||||
} else {
|
||||
|
||||
_runtimeAnimationBuffer = std::make_unique<RuntimeAnimation>(
|
||||
inst,
|
||||
morphData,
|
||||
numMorphWeights,
|
||||
transforms,
|
||||
numFrames,
|
||||
frameLengthInMs
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneAsset::updateAnimations() {
|
||||
@@ -142,12 +158,15 @@ void SceneAsset::updateRuntimeAnimation() {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
if (frameNumber > _runtimeAnimationBuffer->frameNumber) {
|
||||
_runtimeAnimationBuffer->frameNumber = frameNumber;
|
||||
if(_runtimeAnimationBuffer->mMorphFrameData) {
|
||||
auto morphFramePtrOffset = frameNumber * _runtimeAnimationBuffer->mNumMorphWeights;
|
||||
setMorphTargetWeights(_runtimeAnimationBuffer->mMorphFrameData + morphFramePtrOffset,
|
||||
_runtimeAnimationBuffer->mNumMorphWeights);
|
||||
rm.setMorphWeights(
|
||||
_runtimeAnimationBuffer->mInstance,
|
||||
_runtimeAnimationBuffer->mMorphFrameData + morphFramePtrOffset,
|
||||
_runtimeAnimationBuffer->mNumMorphWeights);
|
||||
}
|
||||
|
||||
if(_runtimeAnimationBuffer->mTargets->size() > 0) {
|
||||
|
||||
@@ -97,9 +97,6 @@ SceneAsset *SceneAssetLoader::fromGlb(const char *uri) {
|
||||
_scene->addEntities(asset->getEntities(), entityCount);
|
||||
|
||||
Log("Added %d entities to scene", entityCount);
|
||||
|
||||
size_t lightEntityCount = asset->getLightEntityCount();
|
||||
Log("Found %d light entities in scene.", lightEntityCount );
|
||||
|
||||
_resourceLoader->loadResources(asset);
|
||||
|
||||
@@ -115,6 +112,10 @@ SceneAsset *SceneAssetLoader::fromGlb(const char *uri) {
|
||||
rm.setCulling(entityInstance, true);
|
||||
}
|
||||
|
||||
auto lights = asset->getLightEntities();
|
||||
_scene->addEntities(lights, asset->getLightEntityCount());
|
||||
|
||||
Log("Added %d lights to scene from asset", asset->getLightEntityCount());
|
||||
|
||||
FilamentInstance* inst = asset->getInstance();
|
||||
inst->getAnimator()->updateBoneMatrices();
|
||||
@@ -131,8 +132,15 @@ SceneAsset *SceneAssetLoader::fromGlb(const char *uri) {
|
||||
}
|
||||
|
||||
void SceneAssetLoader::remove(SceneAsset *asset) {
|
||||
|
||||
Log("Removing asset and all associated entities/lights.");
|
||||
|
||||
_scene->removeEntities(asset->_asset->getEntities(),
|
||||
asset->_asset->getEntityCount());
|
||||
|
||||
_scene->removeEntities(asset->getLightEntities(),
|
||||
asset->getLightEntityCount());
|
||||
|
||||
_resourceLoader->evictResourceData();
|
||||
_assetLoader->destroyAsset(asset->_asset);
|
||||
delete asset;
|
||||
|
||||
Reference in New Issue
Block a user