feature!:

This is a breaking change needed to fully implement instancing and stencil highlighting.

Previously, users would work directly with entities (on the Dart side, ThermionEntity), e.g.

final entity = await viewer.loadGlb("some.glb");

However, Filament "entities" are a lower-level abstraction.

Loading a glTF file, for example, inserts multiple entities into the scene.

For example, each mesh, light, and camera within a glTF asset will be assigned an entity. A top-level (non-renderable) entity will also be created for the glTF asset, which can be used to transform the entire hierarchy.

"Asset" is a better representation for loading/inserting objects into the scene; think of this as a bundle of entities.

Unless you need to work directly with transforms, instancing, materials and renderables, you can work directly with ThermionAsset.
This commit is contained in:
Nick Fisher
2024-11-21 15:04:10 +08:00
parent 9ada6aae64
commit ed444b0615
195 changed files with 18061 additions and 12628 deletions

View File

@@ -0,0 +1,84 @@
#include <filament/View.h>
#include <filament/Viewport.h>
#include <filament/Engine.h>
#include <filament/ToneMapper.h>
#include <filament/ColorGrading.h>
#include <filament/Camera.h>
#include <utils/Entity.h>
#include "c_api/ThermionDartApi.h"
#include "c_api/TCamera.h"
#include "Log.hpp"
#include "MathUtils.hpp"
#ifdef __cplusplus
namespace thermion
{
extern "C"
{
using namespace filament;
#endif
EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera *tCamera, double4x4 projectionMatrix, double near, double far)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
camera->setCustomProjection(convert_double4x4_to_mat4(projectionMatrix), near, far);
}
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera *tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return convert_mat4_to_double4x4(camera->getModelMatrix());
}
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return convert_mat4_to_double4x4(camera->getViewMatrix());
}
EMSCRIPTEN_KEEPALIVE EntityId Camera_getEntity(TCamera *tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return utils::Entity::smuggle(camera->getEntity());
}
EMSCRIPTEN_KEEPALIVE double Camera_getFocalLength(TCamera *const tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return camera->getFocalLength() * 1000.0;
}
EMSCRIPTEN_KEEPALIVE double Camera_getNear(TCamera *const tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return camera->getNear();
}
EMSCRIPTEN_KEEPALIVE double Camera_getCullingFar(TCamera *const tCamera)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
return camera->getCullingFar();
}
EMSCRIPTEN_KEEPALIVE void Camera_setProjection(TCamera *const tCamera, Projection projection, double left, double right,
double bottom, double top,
double near, double far)
{
auto *camera = reinterpret_cast<Camera *>(tCamera);
filament::Camera::Projection filamentProjection;
switch(projection) {
case Projection::Orthographic:
filamentProjection = filament::Camera::Projection::ORTHO;
case Projection::Perspective:
filamentProjection = filament::Camera::Projection::PERSPECTIVE;
}
camera->setProjection(filamentProjection, left, right, bottom, top, near, far);
}
#ifdef __cplusplus
}
}
#endif