Skip to content

Commit 1724aae

Browse files
authored
feat: expose orthographic camera projection (#339)
## Description Filament already supports orthographic cameras through `Camera::setProjection(Camera::Projection::ORTHO, ...)`, but react-native-filament currently only exposes the perspective helpers through the JS camera wrapper. This PR bridges that existing Filament API so React Native callers can configure an orthographic projection without dropping down to native code. ## Changes - Adds `camera.setOrthographicProjection(left, right, bottom, top, near, far)` to the native Camera wrapper. - Registers the new method with the JSI hybrid object. - Adds the method to the `RNFCamera` TypeScript interface. ## Testing - Ran `yarn check-all` from `package/`. - Verified C++ formatting ran after installing the missing `clang-format` local dependency. - Verified ESLint and TypeScript completed successfully.
1 parent b422470 commit 1724aae

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

package/cpp/core/RNFCameraWrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ void margelo::CameraWrapper::loadHybridMethods() {
66
registerHybridMethod("lookAt", &CameraWrapper::lookAt, this);
77
registerHybridMethod("setLensProjection", &CameraWrapper::setLensProjection, this);
88
registerHybridMethod("setProjection", &CameraWrapper::setProjection, this);
9+
registerHybridMethod("setOrthographicProjection", &CameraWrapper::setOrthographicProjection, this);
910
}
1011

1112
void margelo::CameraWrapper::lookAtCameraManipulator(std::shared_ptr<ManipulatorWrapper> cameraManipulator) {
@@ -37,3 +38,7 @@ void margelo::CameraWrapper::setProjection(double fovInDegrees, double aspect, d
3738
pointee()->setProjection(static_cast<float>(fovInDegrees), static_cast<float>(aspect), static_cast<float>(near), static_cast<float>(far),
3839
direction);
3940
}
41+
42+
void margelo::CameraWrapper::setOrthographicProjection(double left, double right, double bottom, double top, double near, double far) {
43+
pointee()->setProjection(Camera::Projection::ORTHO, left, right, bottom, top, near, far);
44+
}

package/cpp/core/RNFCameraWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CameraWrapper : public PointerHolder<Camera> {
1818
void lookAt(std::vector<double> eye, std::vector<double> center, std::vector<double> up);
1919
void setLensProjection(double fov, double aspect, double near, double far);
2020
void setProjection(double fovInDegrees, double aspect, double near, double far, std::string directionStr);
21+
void setOrthographicProjection(double left, double right, double bottom, double top, double near, double far);
2122
// Convenience methods
2223
void lookAtCameraManipulator(std::shared_ptr<ManipulatorWrapper> cameraManipulator);
2324
};

package/src/types/Camera.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ export interface RNFCamera extends PointerHolder {
9898
* @see Fov.
9999
*/
100100
setProjection(fov: number, aspect: number, near: number, far: number): void
101+
102+
/**
103+
* Sets an orthographic projection matrix from six clip planes.
104+
*
105+
* @param left distance in world units from the camera to the left plane.
106+
* @param right distance in world units from the camera to the right plane.
107+
* @param bottom distance in world units from the camera to the bottom plane.
108+
* @param top distance in world units from the camera to the top plane.
109+
* @param near distance in world units from the camera to the near plane. near != far.
110+
* @param far distance in world units from the camera to the far plane. far != near.
111+
*/
112+
setOrthographicProjection(left: number, right: number, bottom: number, top: number, near: number, far: number): void
101113
}

0 commit comments

Comments
 (0)