add moveCameraToAsset

This commit is contained in:
Nick Fisher
2023-09-25 22:30:07 +08:00
parent 64cfea2952
commit 833022e4e0
15 changed files with 79 additions and 13 deletions

View File

@@ -81,6 +81,8 @@ namespace polyvox {
void setBackgroundImage(const char* resourcePath, bool fillHeight);
void clearBackgroundImage();
void setBackgroundImagePosition(float x, float y, bool clamp);
void moveCameraToAsset(EntityId entityId);
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
void setCameraPosition(float x, float y, float z);
void setCameraRotation(float rads, float x, float y, float z);

View File

@@ -89,6 +89,7 @@ void transform_to_unit_cube(void* assetManager, EntityId asset);
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
void set_scale(void* assetManager, EntityId asset, float scale);
void move_camera_to_asset(const void* const viewer, EntityId asset);
void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity);
void set_camera_position(const void* const viewer, float x, float y, float z);
void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z);

View File

@@ -21,7 +21,6 @@
#include "Log.hpp"
#include "AssetManager.hpp"
#include "material/StandardMaterialProvider.hpp"
#include "material/UnlitMaterialProvider.hpp"
#include "material/FileMaterialProvider.hpp"
#include "gltfio/materials/uberarchive.h"

View File

@@ -113,7 +113,7 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
#if TARGET_OS_IPHONE
_engine = Engine::create(Engine::Backend::METAL);
#else
_engine = Engine::create(Engine::Backend::OPENGL, nullptr, (void*)context, nullptr);
_engine = Engine::create(Engine::Backend::OPENGL); //L, nullptr, (void*)context, nullptr);
#endif
_renderer = _engine->createRenderer();
@@ -870,9 +870,23 @@ void FilamentViewer::setCameraPosition(float x, float y, float z) {
cam.setModelMatrix(_cameraPosition * _cameraRotation);
}
void FilamentViewer::moveCameraToAsset(EntityId entityId) {
auto asset = _assetManager->getAssetByEntityId(entityId);
if(!asset) {
Log("Failed to find asset attached to specified entity id.");
return;
}
const filament::Aabb bb = asset->mAsset->getBoundingBox();
Camera& cam =_view->getCamera();
_cameraPosition = math::mat4f::translation(bb.getCorners());
_cameraRotation = math::mat4f();
cam.setModelMatrix(_cameraPosition * _cameraRotation);
}
void FilamentViewer::setCameraRotation(float rads, float x, float y, float z) {
Camera& cam =_view->getCamera();
_cameraRotation = math::mat4f::rotation(rads, math::float3(x,y,z));
cam.setModelMatrix(_cameraPosition * _cameraRotation);
}

View File

@@ -97,6 +97,10 @@ extern "C" {
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
}
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset) {
((FilamentViewer*)viewer)->moveCameraToAsset(asset, asset);
}
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
((FilamentViewer*)viewer)->setCameraFocusDistance(distance);
}