WebGL: expose fitIntoUnitCube to JS.

This commit is contained in:
Philip Rideout
2021-04-04 21:38:08 -07:00
parent fe94f935f1
commit b95d91a65e
5 changed files with 17 additions and 5 deletions
+2 -1
View File
@@ -31,6 +31,7 @@
#include <utils/Entity.h>
#include <math/mat4.h>
#include <math/vec3.h>
namespace filagui {
@@ -243,7 +244,7 @@ private:
float mCurvePlot[1024 * 3];
};
filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds);
filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds, float zoffset);
} // namespace viewer
} // namespace filament
+3 -3
View File
@@ -42,7 +42,7 @@ using namespace filament::math;
namespace filament {
namespace viewer {
filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds) {
filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds, float zoffset) {
using namespace filament::math;
auto minpt = bounds.min;
auto maxpt = bounds.max;
@@ -51,7 +51,7 @@ filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds) {
maxExtent = std::max(maxExtent, maxpt.z - minpt.z);
float scaleFactor = 2.0f / maxExtent;
float3 center = (minpt + maxpt) / 2.0f;
center.z += 4.0f / scaleFactor;
center.z += zoffset / scaleFactor;
return mat4f::scaling(float3(scaleFactor)) * mat4f::translation(-center);
}
@@ -348,7 +348,7 @@ void SimpleViewer::populateScene(FilamentAsset* asset, bool scale,
if (scale) {
auto& tcm = mEngine->getTransformManager();
auto root = tcm.getInstance(mAsset->getRoot());
filament::math::mat4f transform = fitIntoUnitCube(mAsset->getBoundingBox());
filament::math::mat4f transform = fitIntoUnitCube(mAsset->getBoundingBox(), 4);
tcm.setTransform(root, transform);
}
+1 -1
View File
@@ -261,7 +261,7 @@ static void createGroundPlane(Engine* engine, Scene* scene, App& app) {
Aabb aabb = app.asset->getBoundingBox();
if (!app.actualSize) {
mat4f transform = fitIntoUnitCube(aabb);
mat4f transform = fitIntoUnitCube(aabb, 4);
aabb = aabb.transform(transform);
}
+3
View File
@@ -143,6 +143,9 @@ export interface View$VignetteOptions {
enabled?: boolean;
}
export function fitIntoUnitCube(box: Aabb): mat4;
export function multiplyMatrices(a: mat4, b: mat4): mat4;
// Clients should use the [PixelBuffer/CompressedPixelBuffer] helper function to contruct PixelBufferDescriptor objects.
export class driver$PixelBufferDescriptor {
constructor(byteLength: number, format: PixelDataFormat, datatype: PixelDataType);
+8
View File
@@ -1903,6 +1903,14 @@ class_<SimpleViewer>("SimpleViewer")
.function("keyUpEvent", &SimpleViewer::keyUpEvent)
.function("keyPressEvent", &SimpleViewer::keyPressEvent);
function("fitIntoUnitCube", EMBIND_LAMBDA(flatmat4, (Aabb box, float zoffset), {
return flatmat4 { fitIntoUnitCube(box, zoffset) };
}));
function("multiplyMatrices", EMBIND_LAMBDA(flatmat4, (flatmat4 a, flatmat4 b), {
return flatmat4 { a.m * b.m };
}));
} // EMSCRIPTEN_BINDINGS
#pragma clang diagnostic pop