support relative setPosition, add hardware keyboard listener + control, log FPS
This commit is contained in:
@@ -38,7 +38,7 @@ namespace polyvox
|
||||
void transformToUnitCube(EntityId e);
|
||||
inline void updateTransform(EntityId e);
|
||||
void setScale(EntityId e, float scale);
|
||||
void setPosition(EntityId e, float x, float y, float z);
|
||||
void setPosition(EntityId e, float x, float y, float z, bool relative);
|
||||
void setRotation(EntityId e, float rads, float x, float y, float z);
|
||||
const utils::Entity *getCameraEntities(EntityId e);
|
||||
size_t getCameraEntityCount(EntityId e);
|
||||
|
||||
@@ -200,11 +200,15 @@ namespace polyvox
|
||||
void loadTextureFromPath(string path);
|
||||
void savePng(void* data, size_t size, int frameNumber);
|
||||
|
||||
time_point_t _startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
time_point_t _recordingStartTime = std::chrono::high_resolution_clock::now();
|
||||
time_point_t _fpsCounterStartTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
bool _recording = false;
|
||||
std::string _recordingOutputDirectory = std::string("/tmp");
|
||||
std::mutex _recordingMutex;
|
||||
double _cumulativeAnimationUpdateTime = 0;
|
||||
int _frameCount = 0;
|
||||
int _skippedFrames = 0;
|
||||
};
|
||||
|
||||
struct FrameCallbackData {
|
||||
|
||||
@@ -146,7 +146,7 @@ extern "C"
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_material_color(void *assetManager, EntityId asset, const char *meshName, int materialIndex, const float r, const float g, const float b, const float a);
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void *assetManager, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void *assetManager, EntityId asset, float rads, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void *assetManager, EntityId asset, float scale);
|
||||
|
||||
@@ -183,6 +183,7 @@ extern "C"
|
||||
FLUTTER_PLUGIN_EXPORT void set_recording_output_directory(void *const viewer, const char* outputDirectory);
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy();
|
||||
FLUTTER_PLUGIN_EXPORT void flutter_filament_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1184,7 +1184,7 @@ namespace polyvox
|
||||
updateTransform(asset);
|
||||
}
|
||||
|
||||
void AssetManager::setPosition(EntityId entity, float x, float y, float z)
|
||||
void AssetManager::setPosition(EntityId entity, float x, float y, float z, bool relative)
|
||||
{
|
||||
const auto &pos = _entityIdLookup.find(entity);
|
||||
if (pos == _entityIdLookup.end())
|
||||
@@ -1193,7 +1193,14 @@ namespace polyvox
|
||||
return;
|
||||
}
|
||||
auto &asset = _assets[pos->second];
|
||||
asset.position = math::mat4f::translation(math::float3(x, y, z));
|
||||
if(relative) {
|
||||
asset.position[3][0] += x;
|
||||
asset.position[3][1] += y;
|
||||
asset.position[3][2] += z;
|
||||
} else {
|
||||
asset.position = math::mat4f::translation(math::float3(x, y, z));
|
||||
}
|
||||
|
||||
updateTransform(asset);
|
||||
}
|
||||
|
||||
|
||||
@@ -1005,9 +1005,6 @@ namespace polyvox
|
||||
}
|
||||
}
|
||||
|
||||
double _elapsed = 0;
|
||||
int _frameCount = 0;
|
||||
int _skippedFrames = 0;
|
||||
|
||||
void FilamentViewer::render(
|
||||
uint64_t frameTimeInNanos,
|
||||
@@ -1022,21 +1019,30 @@ namespace polyvox
|
||||
return;
|
||||
}
|
||||
|
||||
if (_frameCount == 60)
|
||||
{
|
||||
// Log("1 sec average for asset animation update %f", _elapsed / 60);
|
||||
Log("Skipped frames : %d", _skippedFrames);
|
||||
_elapsed = 0;
|
||||
// if (_frameCount == 60)
|
||||
// {
|
||||
// Log("Skipped frames : %d", _skippedFrames);
|
||||
// _elapsed = 0;
|
||||
// _frameCount = 0;
|
||||
// _skippedFrames = 0;
|
||||
// }
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto secsSinceLastFpsCheck = float(std::chrono::duration_cast<std::chrono::seconds>(now - _fpsCounterStartTime).count());
|
||||
|
||||
if(secsSinceLastFpsCheck >= 1) {
|
||||
auto fps = _frameCount / secsSinceLastFpsCheck;
|
||||
Log("%ffps (_frameCount %d, secs since last check %f)", fps, _frameCount, secsSinceLastFpsCheck);
|
||||
// Log("1 sec average for asset animation update %f", _elapsed / _frameCount);
|
||||
_frameCount = 0;
|
||||
_skippedFrames = 0;
|
||||
_fpsCounterStartTime = now;
|
||||
}
|
||||
|
||||
Timer tmr;
|
||||
|
||||
_assetManager->updateAnimations();
|
||||
|
||||
_elapsed += tmr.elapsed();
|
||||
_frameCount++;
|
||||
_cumulativeAnimationUpdateTime += tmr.elapsed();
|
||||
|
||||
// if a manipulator is active, update the active camera orientation
|
||||
if(_manipulator) {
|
||||
@@ -1068,6 +1074,8 @@ namespace polyvox
|
||||
if (beginFrame)
|
||||
{
|
||||
_renderer->render(_view);
|
||||
_frameCount++;
|
||||
|
||||
|
||||
if(_recording) {
|
||||
Viewport const &vp = _view->getViewport();
|
||||
@@ -1081,7 +1089,7 @@ namespace polyvox
|
||||
};
|
||||
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - _startTime).count());
|
||||
auto elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - _recordingStartTime).count());
|
||||
|
||||
auto frameNumber = uint32_t(floor(elapsed / _frameInterval));
|
||||
|
||||
@@ -1161,7 +1169,7 @@ namespace polyvox
|
||||
this->_recording = recording;
|
||||
if(recording) {
|
||||
_tp = new flutter_filament::ThreadPool(8);
|
||||
_startTime = std::chrono::high_resolution_clock::now();
|
||||
_recordingStartTime = std::chrono::high_resolution_clock::now();
|
||||
} else {
|
||||
delete _tp;
|
||||
}
|
||||
|
||||
@@ -470,9 +470,9 @@ extern "C"
|
||||
((AssetManager *)assetManager)->transformToUnitCube(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z)
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *assetManager, EntityId asset, float x, float y, float z, bool relative)
|
||||
{
|
||||
((AssetManager *)assetManager)->setPosition(asset, x, y, z);
|
||||
((AssetManager *)assetManager)->setPosition(asset, x, y, z, relative);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void *assetManager, EntityId asset, float rads, float x, float y, float z)
|
||||
|
||||
Reference in New Issue
Block a user