add model/view matrix getters & manipulator options

This commit is contained in:
Nick Fisher
2023-11-03 15:20:15 +08:00
parent 83469e93b9
commit 58a9542121
18 changed files with 833 additions and 553 deletions

View File

@@ -41,149 +41,148 @@ using namespace camutils;
typedef int32_t EntityId;
namespace polyvox {
namespace polyvox
{
enum ToneMapping {
ACES, FILMIC, LINEAR
};
class FilamentViewer {
public:
FilamentViewer(const void* context, const ResourceLoaderWrapper* const resourceLoaderWrapper, void* const platform=nullptr, const char* uberArchivePath=nullptr);
~FilamentViewer();
void setToneMapping(ToneMapping toneMapping);
void setBloom(float strength);
void loadSkybox(const char* const skyboxUri);
void removeSkybox();
void loadIbl(const char* const iblUri, float intensity);
void removeIbl();
void removeAsset(EntityId asset);
// removes all add assets from the current scene
void clearAssets();
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
void render(
uint64_t frameTimeInNanos,
void* pixelBuffer,
void (*callback)(void *buf, size_t size, void *data),
void* data
);
void setFrameInterval(float interval);
bool setCamera(EntityId asset, const char* nodeName);
void createSwapChain(const void* surface, uint32_t width, uint32_t height);
void destroySwapChain();
void createRenderTarget(intptr_t textureId, uint32_t width,uint32_t height);
Renderer* getRenderer();
void setBackgroundColor(const float r, const float g, const float b, const float a);
void setBackgroundImage(const char* resourcePath, bool fillHeight);
void clearBackgroundImage();
void setBackgroundImagePosition(float x, float y, bool clamp);
void moveCameraToAsset(EntityId entityId);
void setViewFrustumCulling(bool enabled);
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);
void setCameraModelMatrix(const float* const matrix);
void setCameraFocalLength(float fl);
void setCameraFocusDistance(float focusDistance);
void grabBegin(float x, float y, bool pan);
void grabUpdate(float x, float y);
void grabEnd();
void scrollBegin();
void scrollUpdate(float x, float y, float delta);
void scrollEnd();
int32_t addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
void removeLight(EntityId entityId);
void clearLights();
void setPostProcessing(bool enabled);
void pick(uint32_t x, uint32_t y, EntityId* entityId);
AssetManager* const getAssetManager() {
return (AssetManager* const) _assetManager;
}
private:
void createImageRenderable();
void loadResources(std::string relativeResourcePath);
void cleanup();
bool _panning = false;
float _startX;
float _startY;
math::mat4f _cameraPosition;
math::mat4f _cameraRotation;
const ResourceLoaderWrapper* const _resourceLoaderWrapper;
Scene* _scene = nullptr;
View* _view = nullptr;
Engine* _engine = nullptr;
// a default camera that we add to every scene
Camera* _mainCamera = nullptr;
Renderer* _renderer = nullptr;
RenderTarget* _rt = nullptr;
Texture* _rtColor = nullptr;
Texture* _rtDepth = nullptr;
SwapChain* _swapChain = nullptr;
AssetManager* _assetManager = nullptr;
NameComponentManager* _ncm = nullptr;
std::mutex mtx; // mutex to ensure thread safety when removing assets
vector<utils::Entity> _lights;
Texture* _skyboxTexture = nullptr;
Skybox* _skybox = nullptr;
Texture* _iblTexture = nullptr;
IndirectLight* _indirectLight = nullptr;
bool _recomputeAabb = false;
bool _actualSize = false;
float _cameraFocalLength = 28.0f;
float _cameraFocusDistance = 0.0f;
ColorGrading *colorGrading = nullptr;
// background image properties
uint32_t _imageHeight = 0;
uint32_t _imageWidth = 0;
mat4f _imageScale;
Texture* _imageTexture = nullptr;
utils::Entity* _imageEntity = nullptr;
VertexBuffer* _imageVb = nullptr;
IndexBuffer* _imageIb = nullptr;
Material* _imageMaterial = nullptr;
TextureSampler _imageSampler;
void loadKtx2Texture(string path, ResourceBuffer data);
void loadKtxTexture(string path, ResourceBuffer data);
void loadPngTexture(string path, ResourceBuffer data);
void loadTextureFromPath(string path);
Manipulator<double>* _manipulator = nullptr;
void _createManipulator();
uint32_t _lastFrameTimeInNanos;
enum ToneMapping
{
ACES,
FILMIC,
LINEAR
};
class FilamentViewer
{
public:
FilamentViewer(const void *context, const ResourceLoaderWrapper *const resourceLoaderWrapper, void *const platform = nullptr, const char *uberArchivePath = nullptr);
~FilamentViewer();
void setToneMapping(ToneMapping toneMapping);
void setBloom(float strength);
void loadSkybox(const char *const skyboxUri);
void removeSkybox();
void loadIbl(const char *const iblUri, float intensity);
void removeIbl();
void removeAsset(EntityId asset);
void clearAssets();
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
void render(
uint64_t frameTimeInNanos,
void *pixelBuffer,
void (*callback)(void *buf, size_t size, void *data),
void *data);
void setFrameInterval(float interval);
bool setCamera(EntityId asset, const char *nodeName);
void createSwapChain(const void *surface, uint32_t width, uint32_t height);
void destroySwapChain();
void createRenderTarget(intptr_t textureId, uint32_t width, uint32_t height);
Renderer *getRenderer();
void setBackgroundColor(const float r, const float g, const float b, const float a);
void setBackgroundImage(const char *resourcePath, bool fillHeight);
void clearBackgroundImage();
void setBackgroundImagePosition(float x, float y, bool clamp);
// Camera methods
void moveCameraToAsset(EntityId entityId);
void setViewFrustumCulling(bool enabled);
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);
const math::mat4 getCameraModelMatrix();
const math::mat4 getCameraViewMatrix();
void setCameraModelMatrix(const float *const matrix);
void setCameraFocalLength(float fl);
void setCameraFocusDistance(float focusDistance);
void setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
void grabBegin(float x, float y, bool pan);
void grabUpdate(float x, float y);
void grabEnd();
void scrollBegin();
void scrollUpdate(float x, float y, float delta);
void scrollEnd();
void pick(uint32_t x, uint32_t y, EntityId *entityId);
EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
void removeLight(EntityId entityId);
void clearLights();
void setPostProcessing(bool enabled);
AssetManager *const getAssetManager()
{
return (AssetManager *const)_assetManager;
}
private:
const ResourceLoaderWrapper *const _resourceLoaderWrapper;
Scene *_scene = nullptr;
View *_view = nullptr;
Engine *_engine = nullptr;
Renderer *_renderer = nullptr;
RenderTarget *_rt = nullptr;
Texture *_rtColor = nullptr;
Texture *_rtDepth = nullptr;
SwapChain *_swapChain = nullptr;
AssetManager *_assetManager = nullptr;
NameComponentManager *_ncm = nullptr;
std::mutex mtx; // mutex to ensure thread safety when removing assets
vector<utils::Entity> _lights;
Texture *_skyboxTexture = nullptr;
Skybox *_skybox = nullptr;
Texture *_iblTexture = nullptr;
IndirectLight *_indirectLight = nullptr;
bool _recomputeAabb = false;
bool _actualSize = false;
// Camera properties
Camera *_mainCamera = nullptr; // the default camera added to every scene. If you want the *active* camera, access via View.
float _cameraFocalLength = 28.0f;
float _cameraFocusDistance = 0.0f;
Manipulator<double> *_manipulator = nullptr;
filament::camutils::Mode _manipulatorMode;
double _orbitSpeedX = 0.01;
double _orbitSpeedY = 0.01;
double _zoomSpeed = 0.01;
math::mat4f _cameraPosition;
math::mat4f _cameraRotation;
ColorGrading *colorGrading = nullptr;
// background image properties
uint32_t _imageHeight = 0;
uint32_t _imageWidth = 0;
mat4f _imageScale;
Texture *_imageTexture = nullptr;
utils::Entity *_imageEntity = nullptr;
VertexBuffer *_imageVb = nullptr;
IndexBuffer *_imageIb = nullptr;
Material *_imageMaterial = nullptr;
TextureSampler _imageSampler;
void loadKtx2Texture(string path, ResourceBuffer data);
void loadKtxTexture(string path, ResourceBuffer data);
void loadPngTexture(string path, ResourceBuffer data);
void loadTextureFromPath(string path);
uint32_t _lastFrameTimeInNanos;
};
}

View File

@@ -47,11 +47,11 @@
#include "ResourceBuffer.hpp"
typedef int32_t EntityId;
typedef int32_t ManipulatorMode;
#ifdef __cplusplus
extern "C" {
#endif
typedef int32_t EntityId;
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* const context, const ResourceLoaderWrapper* const loader, void* const platform, const char* uberArchivePath);
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer(const void* const viewer);
@@ -140,14 +140,23 @@ FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId a
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z);
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);
// Camera methods
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset);
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled);
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity);
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void* const viewer, float x, float y, float z);
FLUTTER_PLUGIN_EXPORT void get_camera_position(const void* const viewer);
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z);
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, const float *const matrix);
FLUTTER_PLUGIN_EXPORT const double* const get_camera_model_matrix(const void* const viewer);
FLUTTER_PLUGIN_EXPORT const double* const get_camera_view_matrix(const void* const viewer);
FLUTTER_PLUGIN_EXPORT const double* const get_camera_projection_matrix(const void* const viewer);
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength);
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float focusDistance);
FLUTTER_PLUGIN_EXPORT void set_camera_manipulator_options(const void* const viewer, ManipulatorMode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName);
FLUTTER_PLUGIN_EXPORT void set_post_processing(void* const viewer, bool enabled);