| 1 |
/* |
| 2 |
* Copyright (C) 2018 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
/* |
| 18 |
* JS BINDINGS DESIGN |
| 19 |
* ------------------ |
| 20 |
* |
| 21 |
* The purpose of filament-js is to offer a first-class JavaScript interface to the core Filament |
| 22 |
* classes: Engine, Renderer, Texture, etc. |
| 23 |
* |
| 24 |
* Emscripten offers two ways to binding JavaScript to C++: embind and WebIDL. We chose embind. |
| 25 |
* |
| 26 |
* With WebIDL, we would need to author WebIDL files and generate opaque C++ from the IDL, which |
| 27 |
* complicates the build process and ultimately results in the same amount of code. Using embind is |
| 28 |
* more direct and controllable. |
| 29 |
* |
| 30 |
* For nested classes, we use $ as the separator character because embind does not support nested |
| 31 |
* classes and it would transform dot separators into $ anyway. By using $, we at least make |
| 32 |
* this explicit rather than mysterious. |
| 33 |
*/ |
| 34 |
|
| 35 |
#include <filameshio/MeshReader.h> |
| 36 |
|
| 37 |
#include <filament/BufferObject.h> |
| 38 |
#include <filament/Camera.h> |
| 39 |
#include <filament/ColorGrading.h> |
| 40 |
#include <filament/Engine.h> |
| 41 |
#include <filament/Frustum.h> |
| 42 |
#include <filament/IndexBuffer.h> |
| 43 |
#include <filament/IndirectLight.h> |
| 44 |
#include <filament/LightManager.h> |
| 45 |
#include <filament/Material.h> |
| 46 |
#include <filament/MaterialInstance.h> |
| 47 |
#include <filament/RenderableManager.h> |
| 48 |
#include <filament/Renderer.h> |
| 49 |
#include <filament/RenderTarget.h> |
| 50 |
#include <filament/Scene.h> |
| 51 |
#include <filament/Skybox.h> |
| 52 |
#include <filament/SwapChain.h> |
| 53 |
#include <filament/Texture.h> |
| 54 |
#include <filament/TransformManager.h> |
| 55 |
#include <filament/VertexBuffer.h> |
| 56 |
#include <filament/View.h> |
| 57 |
#include <filament/Viewport.h> |
| 58 |
|
| 59 |
#include <geometry/SurfaceOrientation.h> |
| 60 |
|
| 61 |
#include <viewer/SimpleViewer.h> |
| 62 |
|
| 63 |
#include <gltfio/Animator.h> |
| 64 |
#include <gltfio/AssetLoader.h> |
| 65 |
#include <gltfio/FilamentAsset.h> |
| 66 |
#include <gltfio/FilamentInstance.h> |
| 67 |
#include <gltfio/Image.h> |
| 68 |
#include <gltfio/MaterialProvider.h> |
| 69 |
#include <gltfio/ResourceLoader.h> |
| 70 |
|
| 71 |
#include <image/KtxBundle.h> |
| 72 |
#include <image/KtxUtility.h> |
| 73 |
|
| 74 |
#include <math/vec2.h> |
| 75 |
#include <math/vec3.h> |
| 76 |
#include <math/vec4.h> |
| 77 |
#include <math/mat4.h> |
| 78 |
|
| 79 |
#include <utils/EntityManager.h> |
| 80 |
#include <utils/NameComponentManager.h> |
| 81 |
#include <utils/Log.h> |
| 82 |
|
| 83 |
#include <emscripten.h> |
| 84 |
#include <emscripten/bind.h> |
| 85 |
|
| 86 |
// Avoid warnings for deprecated Filament APIs. |
| 87 |
#pragma clang diagnostic push |
| 88 |
#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 89 |
|
| 90 |
using namespace emscripten; |
| 91 |
using namespace filament; |
| 92 |
using namespace filamesh; |
| 93 |
using namespace geometry; |
| 94 |
using namespace gltfio; |
| 95 |
using namespace image; |
| 96 |
|
| 97 |
using namespace filament::viewer; |
| 98 |
|
| 99 |
namespace em = emscripten; |
| 100 |
|
| 101 |
#if __has_feature(cxx_rtti) |
| 102 |
#error Filament JS bindings require RTTI to be disabled. |
| 103 |
#endif |
| 104 |
|
| 105 |
// Many methods require a thin layer of C++ glue which is elegantly expressed with a lambda. |
| 106 |
// However, passing a bare lambda into embind's daisy chain requires a cast to a function pointer. |
| 107 |
#define EMBIND_LAMBDA(retval, arglist, impl) (retval (*) arglist) [] arglist impl |
| 108 |
|
| 109 |
// Builder functions that return "this" have verbose binding declarations, this macro reduces |
| 110 |
// the amount of boilerplate. |
| 111 |
#define BUILDER_FUNCTION(name, btype, arglist, impl) \ |
| 112 |
function(name, EMBIND_LAMBDA(btype*, arglist, impl), allow_raw_pointers()) |
| 113 |
|
| 114 |
// Explicit instantiation of emscripten::internal::raw_destructor is required for binding classes |
| 115 |
// that have non-public destructors. To prevent leaks, do not include pass-by-value types here. |
| 116 |
#define BIND(T) template<> void raw_destructor<T>(T* ptr) {} |
| 117 |
namespace emscripten { |
| 118 |
namespace internal { |
| 119 |
BIND(Animator) |
| 120 |
BIND(AssetLoader) |
| 121 |
BIND(BufferObject) |
| 122 |
BIND(Camera) |
| 123 |
BIND(ColorGrading) |
| 124 |
BIND(Engine) |
| 125 |
BIND(FilamentAsset) |
| 126 |
BIND(FilamentInstance) |
| 127 |
BIND(IndexBuffer) |
| 128 |
BIND(IndirectLight) |
| 129 |
BIND(LightManager) |
| 130 |
BIND(Material) |
| 131 |
BIND(MaterialInstance) |
| 132 |
BIND(RenderableManager) |
| 133 |
BIND(Renderer) |
| 134 |
BIND(RenderTarget) |
| 135 |
BIND(Scene) |
| 136 |
BIND(Skybox) |
| 137 |
BIND(SwapChain) |
| 138 |
BIND(Texture) |
| 139 |
BIND(TransformManager) |
| 140 |
BIND(utils::EntityManager) |
| 141 |
BIND(VertexBuffer) |
| 142 |
BIND(View) |
| 143 |
|
| 144 |
// embind is missing a template definition for "noexcept" methods, so |
| 145 |
// we're supplying it ourselves while waiting for the upstream fix. |
| 146 |
template<typename ClassType, typename ReturnType, typename... Args> |
| 147 |
struct RegisterClassMethod<ReturnType (ClassType::*)(Args...) noexcept> { |
| 148 |
|
| 149 |
template <typename CT, typename... Policies> |
| 150 |
static void invoke(const char* methodName, |
| 151 |
ReturnType (ClassType::*memberFunction)(Args...) noexcept) { |
| 152 |
auto invoker = &MethodInvoker<decltype(memberFunction), ReturnType, ClassType*, Args...>::invoke; |
| 153 |
|
| 154 |
typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, AllowedRawPointer<ClassType>, Args...> args; |
| 155 |
_embind_register_class_function( |
| 156 |
TypeID<ClassType>::get(), |
| 157 |
methodName, |
| 158 |
args.getCount(), |
| 159 |
args.getTypes(), |
| 160 |
getSignature(invoker), |
| 161 |
reinterpret_cast<GenericFunction>(invoker), |
| 162 |
getContext(memberFunction), |
| 163 |
isPureVirtual<Policies...>::value); |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
// embind is missing a template definition for "const noexcept" methods, so |
| 168 |
// we're supplying it ourselves while waiting for the upstream fix. |
| 169 |
template<typename ClassType, typename ReturnType, typename... Args> |
| 170 |
struct RegisterClassMethod<ReturnType (ClassType::*)(Args...) const noexcept> { |
| 171 |
|
| 172 |
template <typename CT, typename... Policies> |
| 173 |
static void invoke(const char* methodName, |
| 174 |
ReturnType (ClassType::*memberFunction)(Args...) const noexcept) { |
| 175 |
auto invoker = &MethodInvoker<decltype(memberFunction), ReturnType, const ClassType*, Args...>::invoke; |
| 176 |
|
| 177 |
typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, AllowedRawPointer<const ClassType>, Args...> args; |
| 178 |
_embind_register_class_function( |
| 179 |
TypeID<ClassType>::get(), |
| 180 |
methodName, |
| 181 |
args.getCount(), |
| 182 |
args.getTypes(), |
| 183 |
getSignature(invoker), |
| 184 |
reinterpret_cast<GenericFunction>(invoker), |
| 185 |
getContext(memberFunction), |
| 186 |
isPureVirtual<Policies...>::value); |
| 187 |
} |
| 188 |
}; |
| 189 |
|
| 190 |
} |
| 191 |
} |
| 192 |
#undef BIND |
| 193 |
|
| 194 |
namespace { |
| 195 |
|
| 196 |
// For convenience, declare terse private aliases to nested types. This lets us avoid extremely |
| 197 |
// verbose binding declarations. |
| 198 |
using ColorBuilder = ColorGrading::Builder; |
| 199 |
using IblBuilder = IndirectLight::Builder; |
| 200 |
using IndexBuilder = IndexBuffer::Builder; |
| 201 |
using LightBuilder = LightManager::Builder; |
| 202 |
using MatBuilder = Material::Builder; |
| 203 |
using RenderableBuilder = RenderableManager::Builder; |
| 204 |
using RenderTargetBuilder = RenderTarget::Builder; |
| 205 |
using SkyBuilder = Skybox::Builder; |
| 206 |
using SurfaceBuilder = SurfaceOrientation::Builder; |
| 207 |
using TexBuilder = Texture::Builder; |
| 208 |
using VertexBuilder = VertexBuffer::Builder; |
| 209 |
using BufferBuilder = BufferObject::Builder; |
| 210 |
|
| 211 |
// We avoid directly exposing backend::BufferDescriptor because embind does not support move |
| 212 |
// semantics and void* doesn't make sense to JavaScript anyway. This little wrapper class is exposed |
| 213 |
// to JavaScript as "driver$BufferDescriptor", but clients will normally use our "Filament.Buffer" |
| 214 |
// helper function (implemented in utilities.js) |
| 215 |
struct BufferDescriptor { |
| 216 |
BufferDescriptor() {} |
| 217 |
// This form is used when JavaScript sends a buffer into WASM. |
| 218 |
BufferDescriptor(uint32_t byteLength) { |
| 219 |
this->bd.reset(new backend::BufferDescriptor(malloc(byteLength), byteLength, |
| 220 |
[](void* buffer, size_t size, void* user) { free(buffer); })); |
| 221 |
} |
| 222 |
// This form is used when WASM needs to return a buffer to JavaScript. |
| 223 |
BufferDescriptor(uint8_t* data, uint32_t size) { |
| 224 |
this->bd.reset(new backend::BufferDescriptor(data, size)); |
| 225 |
} |
| 226 |
val getBytes() { |
| 227 |
unsigned char *byteBuffer = (unsigned char*) bd->buffer; |
| 228 |
size_t bufferLength = bd->size; |
| 229 |
return val(typed_memory_view(bufferLength, byteBuffer)); |
| 230 |
} |
| 231 |
// In order to match its JavaScript counterpart, the Buffer wrapper needs to use reference |
| 232 |
// counting, and the easiest way to achieve that is with shared_ptr. |
| 233 |
std::shared_ptr<backend::BufferDescriptor> bd; |
| 234 |
}; |
| 235 |
|
| 236 |
// Exposed to JavaScript as "driver$PixelBufferDescriptor", but clients will normally use the |
| 237 |
// PixelBuffer or CompressedPixelBuffer helper functions (implemented in utilities.js) |
| 238 |
struct PixelBufferDescriptor { |
| 239 |
PixelBufferDescriptor(uint32_t byteLength, backend::PixelDataFormat fmt, backend::PixelDataType dtype) { |
| 240 |
this->pbd.reset(new backend::PixelBufferDescriptor(malloc(byteLength), byteLength, |
| 241 |
fmt, dtype, [](void* buffer, size_t size, void* user) { free(buffer); })); |
| 242 |
} |
| 243 |
// Note that embind allows overloading based on number of arguments, but not on types. |
| 244 |
// It's fine to have two constructors but they can't both have the same number of arguments. |
| 245 |
PixelBufferDescriptor(uint32_t byteLength, backend::CompressedPixelDataType cdtype, int imageSize, |
| 246 |
bool compressed) { |
| 247 |
assert(compressed == true); |
| 248 |
// For compressed cubemaps, the image size should be one-sixth the size of the entire blob. |
| 249 |
assert(imageSize == byteLength || imageSize == byteLength / 6); |
| 250 |
this->pbd.reset(new backend::PixelBufferDescriptor(malloc(byteLength), byteLength, |
| 251 |
cdtype, imageSize, [](void* buffer, size_t size, void* user) { free(buffer); })); |
| 252 |
} |
| 253 |
val getBytes() { |
| 254 |
unsigned char* byteBuffer = (unsigned char*) pbd->buffer; |
| 255 |
size_t bufferLength = pbd->size; |
| 256 |
return val(typed_memory_view(bufferLength, byteBuffer)); |
| 257 |
} |
| 258 |
// In order to match its JavaScript counterpart, the Buffer wrapper needs to use reference |
| 259 |
// counting, and the easiest way to achieve that is with shared_ptr. |
| 260 |
std::shared_ptr<backend::PixelBufferDescriptor> pbd; |
| 261 |
}; |
| 262 |
|
| 263 |
// Small structure whose sole purpose is to return decoded image data to JavaScript. |
| 264 |
struct DecodedImage { |
| 265 |
int width; |
| 266 |
int height; |
| 267 |
int encoded_ncomp; |
| 268 |
int decoded_ncomp; |
| 269 |
BufferDescriptor decoded_data; |
| 270 |
}; |
| 271 |
|
| 272 |
// JavaScript clients should call [createTextureFromPng] rather than calling this directly. |
| 273 |
DecodedImage decodeImage(BufferDescriptor encoded_data, int requested_ncomp) { |
| 274 |
DecodedImage result; |
| 275 |
stbi_uc* decoded_data = stbi_load_from_memory( |
| 276 |
(stbi_uc const *) encoded_data.bd->buffer, |
| 277 |
encoded_data.bd->size, |
| 278 |
&result.width, |
| 279 |
&result.height, |
| 280 |
&result.encoded_ncomp, |
| 281 |
requested_ncomp); |
| 282 |
const uint32_t decoded_size = result.width * result.height * requested_ncomp; |
| 283 |
result.decoded_data = BufferDescriptor(decoded_data, decoded_size); |
| 284 |
result.decoded_data.bd->setCallback([](void* buffer, size_t size, void* user) { |
| 285 |
stbi_image_free(buffer); |
| 286 |
}); |
| 287 |
result.decoded_ncomp = requested_ncomp; |
| 288 |
return result; |
| 289 |
} |
| 290 |
|
| 291 |
} // anonymous namespace |
| 292 |
|
| 293 |
EMSCRIPTEN_BINDINGS(jsbindings) { |
| 294 |
|
| 295 |
// MATH TYPES |
| 296 |
// ---------- |
| 297 |
// Individual JavaScript objects for math types would be too heavy, so instead we simply accept |
| 298 |
// array-like data using embind's "value_array" feature. We do not expose all our math functions |
| 299 |
// under the assumption that JS clients will use glMatrix or something similar for math. |
| 300 |
|
| 301 |
value_array<filament::math::float2>("float2") |
| 302 |
.element(&filament::math::float2::x) |
| 303 |
.element(&filament::math::float2::y); |
| 304 |
|
| 305 |
value_array<filament::math::float3>("float3") |
| 306 |
.element(&filament::math::float3::x) |
| 307 |
.element(&filament::math::float3::y) |
| 308 |
.element(&filament::math::float3::z); |
| 309 |
|
| 310 |
value_array<filament::math::float4>("float4") |
| 311 |
.element(&filament::math::float4::x) |
| 312 |
.element(&filament::math::float4::y) |
| 313 |
.element(&filament::math::float4::z) |
| 314 |
.element(&filament::math::float4::w); |
| 315 |
|
| 316 |
value_array<filament::math::double2>("double2") |
| 317 |
.element(&filament::math::double2::x) |
| 318 |
.element(&filament::math::double2::y); |
| 319 |
|
| 320 |
value_array<filament::math::double3>("double3") |
| 321 |
.element(&filament::math::double3::x) |
| 322 |
.element(&filament::math::double3::y) |
| 323 |
.element(&filament::math::double3::z); |
| 324 |
|
| 325 |
value_array<filament::math::double4>("double4") |
| 326 |
.element(&filament::math::double4::x) |
| 327 |
.element(&filament::math::double4::y) |
| 328 |
.element(&filament::math::double4::z) |
| 329 |
.element(&filament::math::double4::w); |
| 330 |
|
| 331 |
value_array<filament::math::quat>("quat") |
| 332 |
.element(&filament::math::quat::x) |
| 333 |
.element(&filament::math::quat::y) |
| 334 |
.element(&filament::math::quat::z) |
| 335 |
.element(&filament::math::quat::w); |
| 336 |
|
| 337 |
value_array<Viewport>("Viewport") |
| 338 |
.element(&Viewport::left) |
| 339 |
.element(&Viewport::bottom) |
| 340 |
.element(&Viewport::width) |
| 341 |
.element(&Viewport::height); |
| 342 |
|
| 343 |
value_array<KtxBlobIndex>("KtxBlobIndex") |
| 344 |
.element(&KtxBlobIndex::mipLevel) |
| 345 |
.element(&KtxBlobIndex::arrayIndex) |
| 346 |
.element(&KtxBlobIndex::cubeFace); |
| 347 |
|
| 348 |
value_object<Box>("Box") |
| 349 |
.field("center", &Box::center) |
| 350 |
.field("halfExtent", &Box::halfExtent); |
| 351 |
|
| 352 |
value_object<filament::Aabb>("Aabb") |
| 353 |
.field("min", &filament::Aabb::min) |
| 354 |
.field("max", &filament::Aabb::max); |
| 355 |
|
| 356 |
value_object<filament::Renderer::ClearOptions>("Renderer$ClearOptions") |
| 357 |
.field("clearColor", &filament::Renderer::ClearOptions::clearColor) |
| 358 |
.field("clear", &filament::Renderer::ClearOptions::clear) |
| 359 |
.field("discard", &filament::Renderer::ClearOptions::discard); |
| 360 |
|
| 361 |
value_object<filament::View::AmbientOcclusionOptions>("View$AmbientOcclusionOptions") |
| 362 |
.field("radius", &filament::View::AmbientOcclusionOptions::radius) |
| 363 |
.field("power", &filament::View::AmbientOcclusionOptions::power) |
| 364 |
.field("bias", &filament::View::AmbientOcclusionOptions::bias) |
| 365 |
.field("resolution", &filament::View::AmbientOcclusionOptions::resolution) |
| 366 |
.field("intensity", &filament::View::AmbientOcclusionOptions::intensity) |
| 367 |
.field("quality", &filament::View::AmbientOcclusionOptions::quality); |
| 368 |
|
| 369 |
value_object<filament::View::DepthOfFieldOptions>("View$DepthOfFieldOptions") |
| 370 |
.field("focusDistance", &filament::View::DepthOfFieldOptions::focusDistance) |
| 371 |
.field("cocScale", &filament::View::DepthOfFieldOptions::cocScale) |
| 372 |
.field("maxApertureDiameter", &filament::View::DepthOfFieldOptions::maxApertureDiameter) |
| 373 |
.field("enabled", &filament::View::DepthOfFieldOptions::enabled) |
| 374 |
.field("filter", &filament::View::DepthOfFieldOptions::filter) |
| 375 |
.field("nativeResolution", &filament::View::DepthOfFieldOptions::nativeResolution) |
| 376 |
.field("foregroundRingCount", &filament::View::DepthOfFieldOptions::foregroundRingCount) |
| 377 |
.field("backgroundRingCount", &filament::View::DepthOfFieldOptions::backgroundRingCount) |
| 378 |
.field("fastGatherRingCount", &filament::View::DepthOfFieldOptions::fastGatherRingCount) |
| 379 |
.field("maxForegroundCOC", &filament::View::DepthOfFieldOptions::maxForegroundCOC) |
| 380 |
.field("maxBackgroundCOC", &filament::View::DepthOfFieldOptions::maxBackgroundCOC); |
| 381 |
|
| 382 |
value_object<filament::View::BloomOptions>("View$BloomOptions") |
| 383 |
.field("dirtStrength", &filament::View::BloomOptions::dirtStrength) |
| 384 |
.field("strength", &filament::View::BloomOptions::strength) |
| 385 |
.field("resolution", &filament::View::BloomOptions::resolution) |
| 386 |
.field("anamorphism", &filament::View::BloomOptions::anamorphism) |
| 387 |
.field("levels", &filament::View::BloomOptions::levels) |
| 388 |
.field("threshold", &filament::View::BloomOptions::threshold) |
| 389 |
.field("enabled", &filament::View::BloomOptions::enabled) |
| 390 |
.field("blendMode", &filament::View::BloomOptions::blendMode) |
| 391 |
.field("highlight", &filament::View::BloomOptions::highlight) |
| 392 |
.field("lensFlare", &filament::View::BloomOptions::lensFlare) |
| 393 |
.field("starburst", &filament::View::BloomOptions::starburst) |
| 394 |
.field("chromaticAberration", &filament::View::BloomOptions::chromaticAberration) |
| 395 |
.field("ghostCount", &filament::View::BloomOptions::ghostCount) |
| 396 |
.field("ghostSpacing", &filament::View::BloomOptions::ghostSpacing) |
| 397 |
.field("ghostThreshold", &filament::View::BloomOptions::ghostThreshold) |
| 398 |
.field("haloThickness", &filament::View::BloomOptions::haloThickness) |
| 399 |
.field("haloRadius", &filament::View::BloomOptions::haloRadius) |
| 400 |
.field("haloThreshold", &filament::View::BloomOptions::haloThreshold); |
| 401 |
|
| 402 |
// TODO: add support for dirt texture in BloomOptions. |
| 403 |
// Note that simply including the field in the above list causes binding errors for nullptr. |
| 404 |
|
| 405 |
value_object<filament::View::FogOptions>("View$FogOptions") |
| 406 |
.field("distance", &filament::View::FogOptions::distance) |
| 407 |
.field("maximumOpacity", &filament::View::FogOptions::maximumOpacity) |
| 408 |
.field("height", &filament::View::FogOptions::height) |
| 409 |
.field("heightFalloff", &filament::View::FogOptions::heightFalloff) |
| 410 |
.field("color", &filament::View::FogOptions::color) |
| 411 |
.field("density", &filament::View::FogOptions::density) |
| 412 |
.field("inScatteringStart", &filament::View::FogOptions::inScatteringStart) |
| 413 |
.field("inScatteringSize", &filament::View::FogOptions::inScatteringSize) |
| 414 |
.field("fogColorFromIbl", &filament::View::FogOptions::fogColorFromIbl) |
| 415 |
.field("enabled", &filament::View::FogOptions::enabled); |
| 416 |
|
| 417 |
value_object<filament::View::VignetteOptions>("View$VignetteOptions") |
| 418 |
.field("midPoint", &filament::View::VignetteOptions::midPoint) |
| 419 |
.field("roundness", &filament::View::VignetteOptions::roundness) |
| 420 |
.field("feather", &filament::View::VignetteOptions::feather) |
| 421 |
.field("color", &filament::View::VignetteOptions::color) |
| 422 |
.field("enabled", &filament::View::VignetteOptions::enabled); |
| 423 |
|
| 424 |
value_object<LightManager::ShadowOptions>("LightManager$ShadowOptions") |
| 425 |
.field("mapSize", &LightManager::ShadowOptions::mapSize) |
| 426 |
.field("shadowCascades", &LightManager::ShadowOptions::shadowCascades) |
| 427 |
.field("constantBias", &LightManager::ShadowOptions::constantBias) |
| 428 |
.field("normalBias", &LightManager::ShadowOptions::normalBias) |
| 429 |
.field("shadowFar", &LightManager::ShadowOptions::shadowFar) |
| 430 |
.field("shadowNearHint", &LightManager::ShadowOptions::shadowNearHint) |
| 431 |
.field("shadowFarHint", &LightManager::ShadowOptions::shadowFarHint) |
| 432 |
.field("stable", &LightManager::ShadowOptions::stable) |
| 433 |
.field("polygonOffsetConstant", &LightManager::ShadowOptions::polygonOffsetConstant) |
| 434 |
.field("polygonOffsetSlope", &LightManager::ShadowOptions::polygonOffsetSlope) |
| 435 |
.field("screenSpaceContactShadows", &LightManager::ShadowOptions::screenSpaceContactShadows) |
| 436 |
.field("stepCount", &LightManager::ShadowOptions::stepCount) |
| 437 |
.field("maxShadowDistance", &LightManager::ShadowOptions::maxShadowDistance); |
| 438 |
|
| 439 |
// In JavaScript, a flat contiguous representation is best for matrices (see gl-matrix) so we |
| 440 |
// need to define a small wrapper here. |
| 441 |
|
| 442 |
struct flatmat4 { |
| 443 |
filament::math::mat4f m; |
| 444 |
float& operator[](int i) { return m[i / 4][i % 4]; } |
| 445 |
}; |
| 446 |
|
| 447 |
value_array<flatmat4>("mat4") |
| 448 |
.element(em::index< 0>()).element(em::index< 1>()).element(em::index< 2>()).element(em::index< 3>()) |
| 449 |
.element(em::index< 4>()).element(em::index< 5>()).element(em::index< 6>()).element(em::index< 7>()) |
| 450 |
.element(em::index< 8>()).element(em::index< 9>()).element(em::index<10>()).element(em::index<11>()) |
| 451 |
.element(em::index<12>()).element(em::index<13>()).element(em::index<14>()).element(em::index<15>()); |
| 452 |
|
| 453 |
struct flatmat3 { |
| 454 |
filament::math::mat3f m; |
| 455 |
float& operator[](int i) { return m[i / 3][i % 3]; } |
| 456 |
}; |
| 457 |
|
| 458 |
value_array<flatmat3>("mat3") |
| 459 |
.element(em::index<0>()).element(em::index<1>()).element(em::index<2>()) |
| 460 |
.element(em::index<3>()).element(em::index<4>()).element(em::index<5>()) |
| 461 |
.element(em::index<6>()).element(em::index<7>()).element(em::index<8>()); |
| 462 |
|
| 463 |
value_object<RenderableManager::Bone>("RenderableManager$Bone") |
| 464 |
.field("unitQuaternion", &RenderableManager::Bone::unitQuaternion) |
| 465 |
.field("translation", &RenderableManager::Bone::translation); |
| 466 |
|
| 467 |
// VECTOR TYPES |
| 468 |
// ------------ |
| 469 |
|
| 470 |
using EntityVector = std::vector<utils::Entity>; |
| 471 |
|
| 472 |
register_vector<std::string>("RegistryKeys"); |
| 473 |
register_vector<utils::Entity>("EntityVector"); |
| 474 |
register_vector<FilamentInstance*>("AssetInstanceVector"); |
| 475 |
register_vector<const MaterialInstance*>("MaterialInstanceVector"); |
| 476 |
|
| 477 |
// CORE FILAMENT CLASSES |
| 478 |
// --------------------- |
| 479 |
|
| 480 |
/// Engine ::core class:: Central manager and resource owner. |
| 481 |
class_<Engine>("Engine") |
| 482 |
.class_function("_create", (Engine* (*)()) [] { |
| 483 |
EM_ASM_INT({ |
| 484 |
const options = window.filament_glOptions; |
| 485 |
const context = window.filament_glContext; |
| 486 |
const handle = GL.registerContext(context, options); |
| 487 |
window.filament_contextHandle = handle; |
| 488 |
GL.makeContextCurrent(handle); |
| 489 |
}); |
| 490 |
return Engine::create(); |
| 491 |
}, allow_raw_pointers()) |
| 492 |
|
| 493 |
.function("_execute", EMBIND_LAMBDA(void, (Engine* engine), { |
| 494 |
EM_ASM_INT({ |
| 495 |
const handle = window.filament_contextHandle; |
| 496 |
GL.makeContextCurrent(handle); |
| 497 |
}); |
| 498 |
engine->execute(); |
| 499 |
}), allow_raw_pointers()) |
| 500 |
|
| 501 |
/// destroy ::static method:: Destroys an engine instance and cleans up resources. |
| 502 |
/// engine ::argument:: the instance to destroy |
| 503 |
.class_function("destroy", (void (*)(Engine*)) [] |
| 504 |
(Engine* engine) { Engine::destroy(&engine); }, allow_raw_pointers()) |
| 505 |
|
| 506 |
/// getTransformManager ::method:: |
| 507 |
/// ::retval:: an instance of [TransformManager] |
| 508 |
.function("getTransformManager", EMBIND_LAMBDA(TransformManager*, (Engine* engine), { |
| 509 |
return &engine->getTransformManager(); |
| 510 |
}), allow_raw_pointers()) |
| 511 |
|
| 512 |
/// getLightManager ::method:: |
| 513 |
/// ::retval:: an instance of [LightManager] |
| 514 |
.function("getLightManager", EMBIND_LAMBDA(LightManager*, (Engine* engine), { |
| 515 |
return &engine->getLightManager(); |
| 516 |
}), allow_raw_pointers()) |
| 517 |
|
| 518 |
/// getRenderableManager ::method:: |
| 519 |
/// ::retval:: an instance of [RenderableManager] |
| 520 |
.function("getRenderableManager", EMBIND_LAMBDA(RenderableManager*, (Engine* engine), { |
| 521 |
return &engine->getRenderableManager(); |
| 522 |
}), allow_raw_pointers()) |
| 523 |
|
| 524 |
/// getEntityManager ::method:: |
| 525 |
/// ::retval:: an instance of [utils::EntityManager] |
| 526 |
.function("getEntityManager", EMBIND_LAMBDA(utils::EntityManager*, (Engine* engine), { |
| 527 |
return &engine->getEntityManager(); |
| 528 |
}), allow_raw_pointers()) |
| 529 |
|
| 530 |
/// createSwapChain ::method:: |
| 531 |
/// ::retval:: an instance of [SwapChain] |
| 532 |
.function("createSwapChain", (SwapChain* (*)(Engine*)) [] |
| 533 |
(Engine* engine) { return engine->createSwapChain(nullptr); }, |
| 534 |
allow_raw_pointers()) |
| 535 |
/// destroySwapChain ::method:: |
| 536 |
/// swapChain ::argument:: an instance of [SwapChain] |
| 537 |
.function("destroySwapChain", (void (*)(Engine*, SwapChain*)) [] |
| 538 |
(Engine* engine, SwapChain* swapChain) { engine->destroy(swapChain); }, |
| 539 |
allow_raw_pointers()) |
| 540 |
|
| 541 |
/// createRenderer ::method:: |
| 542 |
/// ::retval:: an instance of [Renderer] |
| 543 |
.function("createRenderer", &Engine::createRenderer, allow_raw_pointers()) |
| 544 |
/// destroyRenderer ::method:: |
| 545 |
/// renderer ::argument:: an instance of [Renderer] |
| 546 |
.function("destroyRenderer", (void (*)(Engine*, Renderer*)) [] |
| 547 |
(Engine* engine, Renderer* renderer) { engine->destroy(renderer); }, |
| 548 |
allow_raw_pointers()) |
| 549 |
|
| 550 |
/// createView ::method:: |
| 551 |
/// ::retval:: an instance of [View] |
| 552 |
.function("createView", &Engine::createView, allow_raw_pointers()) |
| 553 |
/// destroyView ::method:: |
| 554 |
/// view ::argument:: an instance of [View] |
| 555 |
.function("destroyView", (void (*)(Engine*, View*)) [] |
| 556 |
(Engine* engine, View* view) { engine->destroy(view); }, |
| 557 |
allow_raw_pointers()) |
| 558 |
|
| 559 |
/// createScene ::method:: |
| 560 |
/// ::retval:: an instance of [Scene] |
| 561 |
.function("createScene", &Engine::createScene, allow_raw_pointers()) |
| 562 |
/// destroyScene ::method:: |
| 563 |
/// scene ::argument:: an instance of [Scene] |
| 564 |
.function("destroyScene", (void (*)(Engine*, Scene*)) [] |
| 565 |
(Engine* engine, Scene* scene) { engine->destroy(scene); }, |
| 566 |
allow_raw_pointers()) |
| 567 |
|
| 568 |
/// createCamera ::method:: |
| 569 |
/// entity ::argument:: the [Entity] to add the camera component to |
| 570 |
/// ::retval:: an instance of [Camera] |
| 571 |
.function("createCamera", select_overload<Camera*(utils::Entity entity)>(&Engine::createCamera), |
| 572 |
allow_raw_pointers()) |
| 573 |
/// getCameraComponent ::method:: |
| 574 |
/// ::retval:: an instance of [Camera] |
| 575 |
.function("getCameraComponent", &Engine::getCameraComponent, allow_raw_pointers()) |
| 576 |
/// destroyCameraComponent ::method:: |
| 577 |
/// camera ::argument:: an [Entity] with a camera component |
| 578 |
.function("destroyCameraComponent", (void (*)(Engine*, utils::Entity)) [] |
| 579 |
(Engine* engine, utils::Entity camera) { engine->destroyCameraComponent(camera); }, |
| 580 |
allow_raw_pointers()) |
| 581 |
|
| 582 |
.function("_createMaterial", EMBIND_LAMBDA(Material*, (Engine* engine, BufferDescriptor mbd), { |
| 583 |
return Material::Builder().package(mbd.bd->buffer, mbd.bd->size).build(*engine); |
| 584 |
}), allow_raw_pointers()) |
| 585 |
/// destroyMaterial ::method:: |
| 586 |
/// material ::argument:: an instance of [Material] |
| 587 |
.function("destroyMaterial", (void (*)(Engine*, Material*)) [] |
| 588 |
(Engine* engine, Material* mat) { engine->destroy(mat); }, |
| 589 |
allow_raw_pointers()) |
| 590 |
|
| 591 |
/// destroyEntity ::method:: |
| 592 |
/// entity ::argument:: an [Entity] |
| 593 |
.function("destroyEntity", (void (*)(Engine*, utils::Entity)) [] |
| 594 |
(Engine* engine, utils::Entity entity) { engine->destroy(entity); }, |
| 595 |
allow_raw_pointers()) |
| 596 |
/// destroyColorGrading ::method:: |
| 597 |
/// entity ::argument:: an [ColorGrading] |
| 598 |
.function("destroyColorGrading", (void (*)(Engine*, ColorGrading*)) [] |
| 599 |
(Engine* engine, ColorGrading* colorGrading) { engine->destroy(colorGrading); }, |
| 600 |
allow_raw_pointers()) |
| 601 |
/// destroyIndexBuffer ::method:: |
| 602 |
/// ib ::argument:: the [IndexBuffer] to destroy |
| 603 |
.function("destroyIndexBuffer", (void (*)(Engine*, IndexBuffer*)) [] |
| 604 |
(Engine* engine, IndexBuffer* ib) { engine->destroy(ib); }, |
| 605 |
allow_raw_pointers()) |
| 606 |
/// destroyIndirectLight ::method:: |
| 607 |
/// light ::argument:: the [IndirectLight] to destroy |
| 608 |
.function("destroyIndirectLight", (void (*)(Engine*, IndirectLight*)) [] |
| 609 |
(Engine* engine, IndirectLight* light) { engine->destroy(light); }, |
| 610 |
allow_raw_pointers()) |
| 611 |
/// destroyMaterial ::method:: |
| 612 |
/// instance ::argument:: the [MaterialInstance] to destroy |
| 613 |
.function("destroyMaterialInstance", (void (*)(Engine*, MaterialInstance*)) [] |
| 614 |
(Engine* engine, MaterialInstance* mi) { engine->destroy(mi); }, |
| 615 |
allow_raw_pointers()) |
| 616 |
/// destroyRenderTarget ::method:: |
| 617 |
/// rt ::argument:: the [RenderTarget] to destroy |
| 618 |
.function("destroyRenderTarget", (void (*)(Engine*, RenderTarget*)) [] |
| 619 |
(Engine* engine, RenderTarget* rt) { engine->destroy(rt); }, |
| 620 |
allow_raw_pointers()) |
| 621 |
/// destroySkybox ::method:: |
| 622 |
/// skybox ::argument:: the [Skybox] to destroy |
| 623 |
.function("destroySkybox", (void (*)(Engine*, Skybox*)) [] |
| 624 |
(Engine* engine, Skybox* sky) { engine->destroy(sky); }, |
| 625 |
allow_raw_pointers()) |
| 626 |
/// destroyTexture ::method:: |
| 627 |
/// texture ::argument:: the [Texture] to destroy |
| 628 |
.function("destroyTexture", (void (*)(Engine*, Texture*)) [] |
| 629 |
(Engine* engine, Texture* tex) { engine->destroy(tex); }, |
| 630 |
allow_raw_pointers()) |
| 631 |
/// destroyVertexBuffer ::method:: |
| 632 |
/// vb ::argument:: the [VertexBuffer] to destroy |
| 633 |
.function("destroyVertexBuffer", (void (*)(Engine*, VertexBuffer*)) [] |
| 634 |
(Engine* engine, VertexBuffer* vb) { engine->destroy(vb); }, |
| 635 |
allow_raw_pointers()); |
| 636 |
|
| 637 |
/// SwapChain ::core class:: Represents the platform's native rendering surface. |
| 638 |
/// See also the [Engine] methods `createSwapChain` and `destroySwapChain`. |
| 639 |
class_<SwapChain>("SwapChain"); |
| 640 |
|
| 641 |
/// Renderer ::core class:: Represents the platform's native window. |
| 642 |
/// See also the [Engine] methods `createRenderer` and `destroyRenderer`. |
| 643 |
class_<Renderer>("Renderer") |
| 644 |
.function("renderView", &Renderer::render, allow_raw_pointers()) |
| 645 |
.function("renderStandaloneView", &Renderer::renderStandaloneView, allow_raw_pointers()) |
| 646 |
/// render ::method:: requests rendering for a single frame on the given [View] |
| 647 |
/// swapChain ::argument:: the [SwapChain] corresponding to the canvas |
| 648 |
/// view ::argument:: the [View] corresponding to the canvas |
| 649 |
.function("render", EMBIND_LAMBDA(void, (Renderer* self, SwapChain* swapChain, View* view), { |
| 650 |
auto engine = self->getEngine(); |
| 651 |
if (self->beginFrame(swapChain)) { |
| 652 |
self->render(view); |
| 653 |
self->endFrame(); |
| 654 |
} |
| 655 |
engine->execute(); |
| 656 |
}), allow_raw_pointers()) |
| 657 |
.function("_setClearOptions", &Renderer::setClearOptions, allow_raw_pointers()) |
| 658 |
.function("beginFrame", EMBIND_LAMBDA(bool, (Renderer* self, SwapChain* swapChain), { |
| 659 |
return self->beginFrame(swapChain); |
| 660 |
}), allow_raw_pointers()) |
| 661 |
.function("endFrame", &Renderer::endFrame, allow_raw_pointers()); |
| 662 |
|
| 663 |
/// View ::core class:: Encompasses all the state needed for rendering a Scene. |
| 664 |
/// A view is associated with a particular [Scene], [Camera], and viewport. |
| 665 |
/// See also the [Engine] methods `createView` and `destroyView`. |
| 666 |
class_<View>("View") |
| 667 |
.function("setScene", &View::setScene, allow_raw_pointers()) |
| 668 |
.function("setCamera", &View::setCamera, allow_raw_pointers()) |
| 669 |
.function("setColorGrading", &View::setColorGrading, allow_raw_pointers()) |
| 670 |
.function("setBlendMode", &View::setBlendMode) |
| 671 |
.function("getBlendMode", &View::getBlendMode) |
| 672 |
.function("getViewport", &View::getViewport) |
| 673 |
.function("setViewport", &View::setViewport) |
| 674 |
.function("setVisibleLayers", &View::setVisibleLayers) |
| 675 |
.function("setPostProcessingEnabled", &View::setPostProcessingEnabled) |
| 676 |
.function("_setAmbientOcclusionOptions", &View::setAmbientOcclusionOptions) |
| 677 |
.function("_setDepthOfFieldOptions", &View::setDepthOfFieldOptions) |
| 678 |
.function("_setBloomOptions", &View::setBloomOptions) |
| 679 |
.function("_setFogOptions", &View::setFogOptions) |
| 680 |
.function("_setVignetteOptions", &View::setVignetteOptions) |
| 681 |
.function("setAmbientOcclusion", &View::setAmbientOcclusion) |
| 682 |
.function("getAmbientOcclusion", &View::getAmbientOcclusion) |
| 683 |
.function("setAntiAliasing", &View::setAntiAliasing) |
| 684 |
.function("getAntiAliasing", &View::getAntiAliasing) |
| 685 |
.function("setSampleCount", &View::setSampleCount) |
| 686 |
.function("setRenderTarget", EMBIND_LAMBDA(void, (View* self, RenderTarget* renderTarget), { |
| 687 |
self->setRenderTarget(renderTarget); |
| 688 |
}), allow_raw_pointers()); |
| 689 |
|
| 690 |
/// Scene ::core class:: Flat container of renderables and lights. |
| 691 |
/// See also the [Engine] methods `createScene` and `destroyScene`. |
| 692 |
class_<Scene>("Scene") |
| 693 |
.function("addEntity", &Scene::addEntity) |
| 694 |
|
| 695 |
.function("_addEntities", EMBIND_LAMBDA(void, (Scene* self, EntityVector entities), { |
| 696 |
self->addEntities(entities.data(), entities.size()); |
| 697 |
}), allow_raw_pointers()) |
| 698 |
|
| 699 |
.function("_removeEntities", EMBIND_LAMBDA(void, (Scene* self, EntityVector entities), { |
| 700 |
self->removeEntities(entities.data(), entities.size()); |
| 701 |
}), allow_raw_pointers()) |
| 702 |
|
| 703 |
.function("hasEntity", &Scene::hasEntity) |
| 704 |
.function("remove", &Scene::remove) |
| 705 |
.function("setSkybox", &Scene::setSkybox, allow_raw_pointers()) |
| 706 |
.function("setIndirectLight", &Scene::setIndirectLight, allow_raw_pointers()) |
| 707 |
.function("getRenderableCount", &Scene::getRenderableCount) |
| 708 |
.function("getLightCount", &Scene::getLightCount); |
| 709 |
|
| 710 |
/// Frustum ::core class:: Represents the six planes of a truncated viewing pyramid |
| 711 |
class_<Frustum>("Frustum") |
| 712 |
.constructor(EMBIND_LAMBDA(Frustum*, (flatmat4 m), { |
| 713 |
return new Frustum(m.m); |
| 714 |
}), allow_raw_pointers()) |
| 715 |
|
| 716 |
.function("setProjection", EMBIND_LAMBDA(void, (Frustum* self, flatmat4 m), { |
| 717 |
self->setProjection(m.m); |
| 718 |
}), allow_raw_pointers()) |
| 719 |
|
| 720 |
.function("getNormalizedPlane", &Frustum::getNormalizedPlane) |
| 721 |
|
| 722 |
.function("intersectsBox", EMBIND_LAMBDA(bool, (Frustum* self, const Box& box), { |
| 723 |
return self->intersects(box); |
| 724 |
}), allow_raw_pointers()) |
| 725 |
|
| 726 |
.function("intersectsSphere", EMBIND_LAMBDA(bool, (Frustum* self, const filament::math::float4& sphere), { |
| 727 |
return self->intersects(sphere); |
| 728 |
}), allow_raw_pointers()); |
| 729 |
|
| 730 |
/// Camera ::core class:: Represents the eye through which the scene is viewed. |
| 731 |
/// See also the [Engine] methods `createCamera` and `destroyCamera`. |
| 732 |
class_<Camera>("Camera") |
| 733 |
.function("setProjection", EMBIND_LAMBDA(void, (Camera* self, Camera::Projection projection, |
| 734 |
double left, double right, double bottom, double top, double near, double far), { |
| 735 |
self->setProjection(projection, left, right, bottom, top, near, far); |
| 736 |
}), allow_raw_pointers()) |
| 737 |
|
| 738 |
.function("setProjectionFov", EMBIND_LAMBDA(void, (Camera* self, |
| 739 |
double fovInDegrees, double aspect, double near, double far, Camera::Fov direction), { |
| 740 |
self->setProjection(fovInDegrees, aspect, near, far, direction); |
| 741 |
}), allow_raw_pointers()) |
| 742 |
|
| 743 |
.function("setLensProjection", &Camera::setLensProjection) |
| 744 |
|
| 745 |
.function("setCustomProjection", EMBIND_LAMBDA(void, (Camera* self, |
| 746 |
flatmat4 m, double near, double far), { |
| 747 |
self->setCustomProjection(filament::math::mat4(m.m), near, far); |
| 748 |
}), allow_raw_pointers()) |
| 749 |
|
| 750 |
.function("setScaling", EMBIND_LAMBDA(void, (Camera* self, math::double2 scaling), { |
| 751 |
self->setScaling(scaling); |
| 752 |
}), allow_raw_pointers()) |
| 753 |
|
| 754 |
.function("getProjectionMatrix", EMBIND_LAMBDA(flatmat4, (Camera* self), { |
| 755 |
return flatmat4 { filament::math::mat4f(self->getProjectionMatrix()) }; |
| 756 |
}), allow_raw_pointers()) |
| 757 |
|
| 758 |
.function("getCullingProjectionMatrix", EMBIND_LAMBDA(flatmat4, (Camera* self), { |
| 759 |
return flatmat4 { filament::math::mat4f(self->getCullingProjectionMatrix()) }; |
| 760 |
}), allow_raw_pointers()) |
| 761 |
|
| 762 |
.function("getScaling", &Camera::getScaling) |
| 763 |
|
| 764 |
.function("getNear", &Camera::getNear) |
| 765 |
.function("getCullingFar", &Camera::getCullingFar) |
| 766 |
|
| 767 |
.function("setModelMatrix", EMBIND_LAMBDA(void, (Camera* self, flatmat4 m), { |
| 768 |
self->setModelMatrix(m.m); |
| 769 |
}), allow_raw_pointers()) |
| 770 |
|
| 771 |
.function("lookAt", EMBIND_LAMBDA(void, (Camera* self, |
| 772 |
const math::float3& eye, |
| 773 |
const math::float3& center, |
| 774 |
const math::float3& up), { |
| 775 |
self->lookAt(eye, center, up); |
| 776 |
}), allow_raw_pointers()) |
| 777 |
|
| 778 |
.function("getModelMatrix", EMBIND_LAMBDA(flatmat4, (Camera* self), { |
| 779 |
return flatmat4 { self->getModelMatrix() }; |
| 780 |
}), allow_raw_pointers()) |
| 781 |
|
| 782 |
.function("getViewMatrix", EMBIND_LAMBDA(flatmat4, (Camera* self), { |
| 783 |
return flatmat4 { self->getViewMatrix() }; |
| 784 |
}), allow_raw_pointers()) |
| 785 |
|
| 786 |
.function("getPosition", &Camera::getPosition) |
| 787 |
.function("getLeftVector", &Camera::getLeftVector) |
| 788 |
.function("getUpVector", &Camera::getUpVector) |
| 789 |
.function("getForwardVector", &Camera::getForwardVector) |
| 790 |
.function("getFrustum", &Camera::getFrustum) |
| 791 |
.function("setExposure", (void(Camera::*)(float, float, float)) &Camera::setExposure) |
| 792 |
.function("setExposureDirect", (void(Camera::*)(float)) &Camera::setExposure) |
| 793 |
.function("getAperture", &Camera::getAperture) |
| 794 |
.function("getShutterSpeed", &Camera::getShutterSpeed) |
| 795 |
.function("getSensitivity", &Camera::getSensitivity) |
| 796 |
.function("setFocusDistance", &Camera::setFocusDistance) |
| 797 |
.function("getFocusDistance", &Camera::getFocusDistance) |
| 798 |
.function("getFocalLength", &Camera::getFocalLength) |
| 799 |
|
| 800 |
.class_function("computeEffectiveFocalLength", &Camera::computeEffectiveFocalLength) |
| 801 |
.class_function("computeEffectiveFov", &Camera::computeEffectiveFov) |
| 802 |
|
| 803 |
.class_function("inverseProjection", (flatmat4 (*)(flatmat4)) [] (flatmat4 m) { |
| 804 |
return flatmat4 { filament::math::mat4f(Camera::inverseProjection(m.m)) }; |
| 805 |
}, allow_raw_pointers()); |
| 806 |
|
| 807 |
class_<ColorGrading>("ColorGrading") |
| 808 |
.class_function("Builder", (ColorBuilder (*)()) [] { return ColorBuilder(); }); |
| 809 |
|
| 810 |
class_<ColorBuilder>("ColorGrading$Builder") |
| 811 |
.function("_build", EMBIND_LAMBDA(ColorGrading*, (ColorBuilder* builder, Engine* engine), { |
| 812 |
return builder->build(*engine); |
| 813 |
}), allow_raw_pointers()) |
| 814 |
|
| 815 |
.BUILDER_FUNCTION("quality", ColorBuilder, (ColorBuilder* builder, |
| 816 |
ColorGrading::QualityLevel ql), { |
| 817 |
return &builder->quality(ql); |
| 818 |
}) |
| 819 |
|
| 820 |
.BUILDER_FUNCTION("toneMapping", ColorBuilder, (ColorBuilder* builder, |
| 821 |
ColorGrading::ToneMapping tm), { |
| 822 |
return &builder->toneMapping(tm); |
| 823 |
}) |
| 824 |
|
| 825 |
.BUILDER_FUNCTION("whiteBalance", ColorBuilder, (ColorBuilder* builder, float temp, |
| 826 |
float tint), { |
| 827 |
return &builder->whiteBalance(temp, tint); |
| 828 |
}) |
| 829 |
|
| 830 |
.BUILDER_FUNCTION("channelMixer", ColorBuilder, (ColorBuilder* builder, |
| 831 |
filament::math::float3 red, |
| 832 |
filament::math::float3 green, |
| 833 |
filament::math::float3 blue), { |
| 834 |
return &builder->channelMixer(red, green, blue); |
| 835 |
}) |
| 836 |
|
| 837 |
.BUILDER_FUNCTION("shadowsMidtonesHighlights", ColorBuilder, (ColorBuilder* builder, |
| 838 |
filament::math::float4 shadows, |
| 839 |
filament::math::float4 midtones, |
| 840 |
filament::math::float4 highlights, |
| 841 |
filament::math::float4 ranges), { |
| 842 |
return &builder->shadowsMidtonesHighlights(shadows, midtones, highlights, ranges); |
| 843 |
}) |
| 844 |
|
| 845 |
.BUILDER_FUNCTION("slopeOffsetPower", ColorBuilder, (ColorBuilder* builder, |
| 846 |
math::float3 slope, math::float3 offset, math::float3 power), { |
| 847 |
return &builder->slopeOffsetPower(slope, offset, power); |
| 848 |
}) |
| 849 |
|
| 850 |
.BUILDER_FUNCTION("contrast", ColorBuilder, (ColorBuilder* builder, float contrast), { |
| 851 |
return &builder->contrast(contrast); |
| 852 |
}) |
| 853 |
|
| 854 |
.BUILDER_FUNCTION("vibrance", ColorBuilder, (ColorBuilder* builder, float vibrance), { |
| 855 |
return &builder->vibrance(vibrance); |
| 856 |
}) |
| 857 |
|
| 858 |
.BUILDER_FUNCTION("saturation", ColorBuilder, (ColorBuilder* builder, float saturation), { |
| 859 |
return &builder->saturation(saturation); |
| 860 |
}) |
| 861 |
|
| 862 |
.BUILDER_FUNCTION("curves", ColorBuilder, (ColorBuilder* builder, math::float3 shadowGamma, |
| 863 |
math::float3 midPoint, math::float3 highlightScale), { |
| 864 |
return &builder->curves(shadowGamma, midPoint, highlightScale); |
| 865 |
}); |
| 866 |
|
| 867 |
class_<RenderTargetBuilder>("RenderTarget$Builder") |
| 868 |
.BUILDER_FUNCTION("texture", RenderTargetBuilder, (RenderTargetBuilder* builder, |
| 869 |
RenderTarget::AttachmentPoint attachment, Texture* tex), { |
| 870 |
return &builder->texture(attachment, tex); }) |
| 871 |
|
| 872 |
.BUILDER_FUNCTION("mipLevel", RenderTargetBuilder, (RenderTargetBuilder* builder, |
| 873 |
RenderTarget::AttachmentPoint attachment, uint8_t level), { |
| 874 |
return &builder->mipLevel(attachment, level); }) |
| 875 |
|
| 876 |
.BUILDER_FUNCTION("face", RenderTargetBuilder, (RenderTargetBuilder* builder, |
| 877 |
RenderTarget::AttachmentPoint attachment, Texture::CubemapFace face), { |
| 878 |
return &builder->face(attachment, face); }) |
| 879 |
|
| 880 |
.BUILDER_FUNCTION("layer", RenderTargetBuilder, (RenderTargetBuilder* builder, |
| 881 |
RenderTarget::AttachmentPoint attachment, uint32_t layer), { |
| 882 |
return &builder->layer(attachment, layer); }) |
| 883 |
|
| 884 |
.function("_build", EMBIND_LAMBDA(RenderTarget*, (RenderTargetBuilder* builder, Engine* engine), { |
| 885 |
return builder->build(*engine); |
| 886 |
}), allow_raw_pointers()); |
| 887 |
|
| 888 |
class_<RenderTarget>("RenderTarget") |
| 889 |
.class_function("Builder", (RenderTargetBuilder (*)()) [] () { |
| 890 |
return RenderTarget::Builder(); |
| 891 |
}) |
| 892 |
.function("getMipLevel", &RenderTarget::getMipLevel) |
| 893 |
.function("getFace", &RenderTarget::getFace) |
| 894 |
.function("getLayer", &RenderTarget::getLayer); |
| 895 |
|
| 896 |
class_<RenderableBuilder>("RenderableManager$Builder") |
| 897 |
.BUILDER_FUNCTION("geometry", RenderableBuilder, (RenderableBuilder* builder, |
| 898 |
size_t index, |
| 899 |
RenderableManager::PrimitiveType type, |
| 900 |
VertexBuffer* vertices, |
| 901 |
IndexBuffer* indices), { |
| 902 |
return &builder->geometry(index, type, vertices, indices); }) |
| 903 |
|
| 904 |
.BUILDER_FUNCTION("geometryOffset", RenderableBuilder, (RenderableBuilder* builder, |
| 905 |
size_t index, |
| 906 |
RenderableManager::PrimitiveType type, |
| 907 |
VertexBuffer* vertices, |
| 908 |
IndexBuffer* indices, |
| 909 |
size_t offset, |
| 910 |
size_t count), { |
| 911 |
return &builder->geometry(index, type, vertices, indices, offset, count); }) |
| 912 |
|
| 913 |
.BUILDER_FUNCTION("geometryMinMax", RenderableBuilder, (RenderableBuilder* builder, |
| 914 |
size_t index, |
| 915 |
RenderableManager::PrimitiveType type, |
| 916 |
VertexBuffer* vertices, |
| 917 |
IndexBuffer* indices, |
| 918 |
size_t offset, |
| 919 |
size_t minIndex, |
| 920 |
size_t maxIndex, |
| 921 |
size_t count), { |
| 922 |
return &builder->geometry(index, type, vertices, indices, offset, minIndex, maxIndex, count); }) |
| 923 |
|
| 924 |
.BUILDER_FUNCTION("material", RenderableBuilder, (RenderableBuilder* builder, |
| 925 |
size_t index, MaterialInstance* mi), { |
| 926 |
return &builder->material(index, mi); }) |
| 927 |
|
| 928 |
.BUILDER_FUNCTION("boundingBox", RenderableBuilder, (RenderableBuilder* builder, Box box), { |
| 929 |
return &builder->boundingBox(box); }) |
| 930 |
|
| 931 |
.BUILDER_FUNCTION("layerMask", RenderableBuilder, (RenderableBuilder* builder, uint8_t select, |
| 932 |
uint8_t values), { |
| 933 |
return &builder->layerMask(select, values); }) |
| 934 |
|
| 935 |
.BUILDER_FUNCTION("priority", RenderableBuilder, (RenderableBuilder* builder, uint8_t value), { |
| 936 |
return &builder->priority(value); }) |
| 937 |
|
| 938 |
.BUILDER_FUNCTION("culling", RenderableBuilder, (RenderableBuilder* builder, bool enable), { |
| 939 |
return &builder->culling(enable); }) |
| 940 |
|
| 941 |
.BUILDER_FUNCTION("castShadows", RenderableBuilder, (RenderableBuilder* builder, bool enable), { |
| 942 |
return &builder->castShadows(enable); }) |
| 943 |
|
| 944 |
.BUILDER_FUNCTION("receiveShadows", RenderableBuilder, (RenderableBuilder* builder, bool enable), { |
| 945 |
return &builder->receiveShadows(enable); }) |
| 946 |
|
| 947 |
.BUILDER_FUNCTION("skinning", RenderableBuilder, (RenderableBuilder* builder, size_t boneCount), { |
| 948 |
return &builder->skinning(boneCount); }) |
| 949 |
|
| 950 |
.BUILDER_FUNCTION("skinningBones", RenderableBuilder, (RenderableBuilder* builder, |
| 951 |
emscripten::val transforms), { |
| 952 |
auto nbones = transforms["length"].as<size_t>(); |
| 953 |
std::vector<RenderableManager::Bone> bones(nbones); |
| 954 |
for (size_t i = 0; i < nbones; i++) { |
| 955 |
bones[i] = transforms[i].as<RenderableManager::Bone>(); |
| 956 |
} |
| 957 |
return &builder->skinning(bones.size(), bones.data()); |
| 958 |
}) |
| 959 |
|
| 960 |
.BUILDER_FUNCTION("skinningMatrices", RenderableBuilder, (RenderableBuilder* builder, |
| 961 |
emscripten::val transforms), { |
| 962 |
auto nbones = transforms["length"].as<size_t>(); |
| 963 |
std::vector<filament::math::mat4f> matrices(nbones); |
| 964 |
for (size_t i = 0; i < nbones; i++) { |
| 965 |
matrices[i] = transforms[i].as<flatmat4>().m; |
| 966 |
} |
| 967 |
return &builder->skinning(matrices.size(), matrices.data()); |
| 968 |
}) |
| 969 |
|
| 970 |
.BUILDER_FUNCTION("morphing", RenderableBuilder, (RenderableBuilder* builder, bool enable), { |
| 971 |
return &builder->morphing(enable); }) |
| 972 |
|
| 973 |
.BUILDER_FUNCTION("blendOrder", RenderableBuilder, |
| 974 |
(RenderableBuilder* builder, size_t index, uint16_t order), { |
| 975 |
return &builder->blendOrder(index, order); }) |
| 976 |
|
| 977 |
.function("_build", EMBIND_LAMBDA(int, (RenderableBuilder* builder, |
| 978 |
Engine* engine, utils::Entity entity), { |
| 979 |
return (int) builder->build(*engine, entity); |
| 980 |
}), allow_raw_pointers()); |
| 981 |
|
| 982 |
/// RenderableManager ::core class:: Allows access to properties of drawable objects. |
| 983 |
class_<RenderableManager>("RenderableManager") |
| 984 |
.function("hasComponent", &RenderableManager::hasComponent) |
| 985 |
|
| 986 |
/// getInstance ::method:: Gets an instance of the renderable component for an entity. |
| 987 |
/// entity ::argument:: an [Entity] |
| 988 |
/// ::retval:: a renderable component |
| 989 |
.function("getInstance", &RenderableManager::getInstance) |
| 990 |
|
| 991 |
.class_function("Builder", (RenderableBuilder (*)(int)) [] (int n) { |
| 992 |
return RenderableBuilder(n); |
| 993 |
}) |
| 994 |
|
| 995 |
.function("destroy", &RenderableManager::destroy) |
| 996 |
.function("setAxisAlignedBoundingBox", &RenderableManager::setAxisAlignedBoundingBox) |
| 997 |
.function("setLayerMask", &RenderableManager::setLayerMask) |
| 998 |
.function("setPriority", &RenderableManager::setPriority) |
| 999 |
.function("setCastShadows", &RenderableManager::setCastShadows) |
| 1000 |
.function("setReceiveShadows", &RenderableManager::setReceiveShadows) |
| 1001 |
.function("isShadowCaster", &RenderableManager::isShadowCaster) |
| 1002 |
.function("isShadowReceiver", &RenderableManager::isShadowReceiver) |
| 1003 |
|
| 1004 |
.function("setBones", EMBIND_LAMBDA(void, (RenderableManager* self, |
| 1005 |
RenderableManager::Instance instance, emscripten::val transforms, size_t offset), { |
| 1006 |
auto nbones = transforms["length"].as<size_t>(); |
| 1007 |
std::vector<RenderableManager::Bone> bones(nbones); |
| 1008 |
for (size_t i = 0; i < nbones; i++) { |
| 1009 |
bones[i] = transforms[i].as<RenderableManager::Bone>(); |
| 1010 |
} |
| 1011 |
self->setBones(instance, bones.data(), bones.size(), offset); |
| 1012 |
}), allow_raw_pointers()) |
| 1013 |
|
| 1014 |
.function("setBonesFromMatrices", EMBIND_LAMBDA(void, (RenderableManager* self, |
| 1015 |
RenderableManager::Instance instance, emscripten::val transforms, size_t offset), { |
| 1016 |
auto nbones = transforms["length"].as<size_t>(); |
| 1017 |
std::vector<filament::math::mat4f> bones(nbones); |
| 1018 |
for (size_t i = 0; i < nbones; i++) { |
| 1019 |
bones[i] = transforms[i].as<flatmat4>().m; |
| 1020 |
} |
| 1021 |
self->setBones(instance, bones.data(), bones.size(), offset); |
| 1022 |
}), allow_raw_pointers()) |
| 1023 |
|
| 1024 |
// NOTE: this cannot take a float4 due to a binding issue. |
| 1025 |
.function("setMorphWeights", EMBIND_LAMBDA(void, (RenderableManager* self, |
| 1026 |
RenderableManager::Instance instance, float x, float y, float z, float w), { |
| 1027 |
self->setMorphWeights(instance, {x, y, z, w}); |
| 1028 |
}), allow_raw_pointers()) |
| 1029 |
|
| 1030 |
.function("getAxisAlignedBoundingBox", &RenderableManager::getAxisAlignedBoundingBox) |
| 1031 |
.function("getPrimitiveCount", &RenderableManager::getPrimitiveCount) |
| 1032 |
.function("setMaterialInstanceAt", &RenderableManager::setMaterialInstanceAt, |
| 1033 |
allow_raw_pointers()) |
| 1034 |
.function("getMaterialInstanceAt", &RenderableManager::getMaterialInstanceAt, |
| 1035 |
allow_raw_pointers()) |
| 1036 |
|
| 1037 |
.function("setGeometryAt", EMBIND_LAMBDA(void, (RenderableManager* self, |
| 1038 |
RenderableManager::Instance instance, size_t primitiveIndex, |
| 1039 |
RenderableManager::PrimitiveType type, VertexBuffer* vertices, IndexBuffer* indices, |
| 1040 |
size_t offset, size_t count), { |
| 1041 |
self->setGeometryAt(instance, primitiveIndex, type, vertices, indices, offset, count); |
| 1042 |
}), allow_raw_pointers()) |
| 1043 |
|
| 1044 |
.function("setGeometryRangeAt", EMBIND_LAMBDA(void, (RenderableManager* self, |
| 1045 |
RenderableManager::Instance instance, size_t primitiveIndex, |
| 1046 |
RenderableManager::PrimitiveType type, size_t offset, size_t count), { |
| 1047 |
self->setGeometryAt(instance, primitiveIndex, type, offset, count); |
| 1048 |
}), allow_raw_pointers()) |
| 1049 |
|
| 1050 |
.function("setBlendOrderAt", &RenderableManager::setBlendOrderAt) |
| 1051 |
|
| 1052 |
.function("getEnabledAttributesAt", EMBIND_LAMBDA(uint32_t, (RenderableManager* self, |
| 1053 |
RenderableManager::Instance instance, size_t primitiveIndex), { |
| 1054 |
return self->getEnabledAttributesAt(instance, primitiveIndex).getValue(); |
| 1055 |
}), allow_raw_pointers()); |
| 1056 |
|
| 1057 |
/// RenderableManager$Instance ::class:: Component instance returned by [RenderableManager] |
| 1058 |
/// Be sure to call the instance's `delete` method when you're done with it. |
| 1059 |
class_<RenderableManager::Instance>("RenderableManager$Instance"); |
| 1060 |
/// delete ::method:: Frees an instance obtained via `getInstance` |
| 1061 |
|
| 1062 |
/// TransformManager ::core class:: Adds transform components to entities. |
| 1063 |
class_<TransformManager>("TransformManager") |
| 1064 |
.function("hasComponent", &TransformManager::hasComponent) |
| 1065 |
|
| 1066 |
/// getInstance ::method:: Gets an instance representing the transform component for an entity. |
| 1067 |
/// entity ::argument:: an [Entity] |
| 1068 |
/// ::retval:: a transform component that can be passed to `setTransform`. |
| 1069 |
.function("getInstance", &TransformManager::getInstance) |
| 1070 |
|
| 1071 |
.function("create", EMBIND_LAMBDA(void, |
| 1072 |
(TransformManager* self, utils::Entity entity), { |
| 1073 |
self->create(entity); |
| 1074 |
}), allow_raw_pointers()) |
| 1075 |
|
| 1076 |
.function("destroy", &TransformManager::destroy) |
| 1077 |
.function("setParent", &TransformManager::setParent) |
| 1078 |
.function("getParent", &TransformManager::getParent) |
| 1079 |
|
| 1080 |
.function("getChildren", EMBIND_LAMBDA(EntityVector, |
| 1081 |
(TransformManager* self, TransformManager::Instance instance), { |
| 1082 |
EntityVector result(self->getChildCount(instance)); |
| 1083 |
self->getChildren(instance, result.data(), result.size()); |
| 1084 |
return result; |
| 1085 |
}), allow_raw_pointers()) |
| 1086 |
|
| 1087 |
/// setTransform ::method:: Sets the mat4 value of a transform component. |
| 1088 |
/// instance ::argument:: The transform instance of entity, obtained via `getInstance`. |
| 1089 |
/// matrix ::argument:: Array of 16 numbers (mat4) |
| 1090 |
.function("setTransform", EMBIND_LAMBDA(void, |
| 1091 |
(TransformManager* self, TransformManager::Instance instance, flatmat4 m), { |
| 1092 |
self->setTransform(instance, m.m); }), allow_raw_pointers()) |
| 1093 |
|
| 1094 |
.function("getTransform", EMBIND_LAMBDA(flatmat4, |
| 1095 |
(TransformManager* self, TransformManager::Instance instance), { |
| 1096 |
return flatmat4 { self->getTransform(instance) } ; }), allow_raw_pointers()) |
| 1097 |
|
| 1098 |
.function("getWorldTransform", EMBIND_LAMBDA(flatmat4, |
| 1099 |
(TransformManager* self, TransformManager::Instance instance), { |
| 1100 |
return flatmat4 { self->getTransform(instance) } ; }), allow_raw_pointers()) |
| 1101 |
|
| 1102 |
.function("openLocalTransformTransaction", &TransformManager::openLocalTransformTransaction) |
| 1103 |
.function("commitLocalTransformTransaction", |
| 1104 |
&TransformManager::commitLocalTransformTransaction); |
| 1105 |
|
| 1106 |
/// TransformManager$Instance ::class:: Component instance returned by [TransformManager] |
| 1107 |
/// Be sure to call the instance's `delete` method when you're done with it. |
| 1108 |
class_<TransformManager::Instance>("TransformManager$Instance"); |
| 1109 |
/// delete ::method:: Frees an instance obtained via `getInstance` |
| 1110 |
|
| 1111 |
class_<LightBuilder>("LightManager$Builder") |
| 1112 |
.function("_build", EMBIND_LAMBDA(int, (LightBuilder* builder, |
| 1113 |
Engine* engine, utils::Entity entity), { |
| 1114 |
return (int) builder->build(*engine, entity); |
| 1115 |
}), allow_raw_pointers()) |
| 1116 |
.BUILDER_FUNCTION("castShadows", LightBuilder, (LightBuilder* builder, bool enable), { |
| 1117 |
return &builder->castShadows(enable); }) |
| 1118 |
.BUILDER_FUNCTION("_shadowOptions", LightBuilder, (LightBuilder* builder, |
| 1119 |
LightManager::ShadowOptions options), { |
| 1120 |
return &builder->shadowOptions(options); }) |
| 1121 |
.BUILDER_FUNCTION("castLight", LightBuilder, (LightBuilder* builder, bool enable), { |
| 1122 |
return &builder->castLight(enable); }) |
| 1123 |
.BUILDER_FUNCTION("position", LightBuilder, (LightBuilder* builder, filament::math::float3 value), { |
| 1124 |
return &builder->position(value); }) |
| 1125 |
.BUILDER_FUNCTION("direction", LightBuilder, (LightBuilder* builder, filament::math::float3 value), { |
| 1126 |
return &builder->direction(value); }) |
| 1127 |
.BUILDER_FUNCTION("color", LightBuilder, (LightBuilder* builder, filament::math::float3 value), { |
| 1128 |
return &builder->color(value); }) |
| 1129 |
.BUILDER_FUNCTION("intensity", LightBuilder, (LightBuilder* builder, float value), { |
| 1130 |
return &builder->intensity(value); }) |
| 1131 |
.BUILDER_FUNCTION("falloff", LightBuilder, (LightBuilder* builder, float value), { |
| 1132 |
return &builder->falloff(value); }) |
| 1133 |
.BUILDER_FUNCTION("spotLightCone", LightBuilder, |
| 1134 |
(LightBuilder* builder, float inner, float outer), { |
| 1135 |
return &builder->spotLightCone(inner, outer); }) |
| 1136 |
.BUILDER_FUNCTION("sunAngularRadius", LightBuilder, |
| 1137 |
(LightBuilder* builder, float value), { return &builder->sunAngularRadius(value); }) |
| 1138 |
.BUILDER_FUNCTION("sunHaloSize", LightBuilder, |
| 1139 |
(LightBuilder* builder, float value), { return &builder->sunHaloSize(value); }) |
| 1140 |
.BUILDER_FUNCTION("sunHaloFalloff", LightBuilder, |
| 1141 |
(LightBuilder* builder, float value), { return &builder->sunHaloFalloff(value); }); |
| 1142 |
|
| 1143 |
class_<LightManager>("LightManager") |
| 1144 |
.function("hasComponent", &LightManager::hasComponent) |
| 1145 |
|
| 1146 |
/// getInstance ::method:: Gets an instance of the light component for an entity. |
| 1147 |
/// entity ::argument:: an [Entity] |
| 1148 |
/// ::retval:: a light source component |
| 1149 |
.function("getInstance", &LightManager::getInstance) |
| 1150 |
|
| 1151 |
.class_function("Builder", (LightBuilder (*)(LightManager::Type)) [] (LightManager::Type lt) { |
| 1152 |
return LightBuilder(lt); }) |
| 1153 |
|
| 1154 |
.function("getType", &LightManager::getType) |
| 1155 |
.function("isDirectional", &LightManager::isDirectional) |
| 1156 |
.function("isPointLight", &LightManager::isPointLight) |
| 1157 |
.function("isSpotLight", &LightManager::isSpotLight) |
| 1158 |
.function("setPosition", &LightManager::setPosition) |
| 1159 |
.function("getPosition", &LightManager::getPosition) |
| 1160 |
.function("setDirection", &LightManager::setDirection) |
| 1161 |
.function("getDirection", &LightManager::getDirection) |
| 1162 |
.function("setColor", &LightManager::setColor) |
| 1163 |
.function("getColor", &LightManager::getColor) |
| 1164 |
|
| 1165 |
.function("setIntensity", EMBIND_LAMBDA(void, (LightManager* self, |
| 1166 |
LightManager::Instance instance, float intensity), { |
| 1167 |
self->setIntensity(instance, intensity); |
| 1168 |
}), allow_raw_pointers()) |
| 1169 |
|
| 1170 |
.function("setIntensityEnergy", EMBIND_LAMBDA(void, (LightManager* self, |
| 1171 |
LightManager::Instance instance, float watts, float efficiency), { |
| 1172 |
self->setIntensity(instance, watts, efficiency); |
| 1173 |
}), allow_raw_pointers()) |
| 1174 |
|
| 1175 |
.function("getIntensity", &LightManager::getIntensity) |
| 1176 |
.function("setFalloff", &LightManager::setFalloff) |
| 1177 |
.function("getFalloff", &LightManager::getFalloff) |
| 1178 |
.function("_setShadowOptions", &LightManager::setShadowOptions) |
| 1179 |
.function("setSpotLightCone", &LightManager::setSpotLightCone) |
| 1180 |
.function("setSunAngularRadius", &LightManager::setSunAngularRadius) |
| 1181 |
.function("getSunAngularRadius", &LightManager::getSunAngularRadius) |
| 1182 |
.function("setSunHaloSize", &LightManager::setSunHaloSize) |
| 1183 |
.function("getSunHaloSize", &LightManager::getSunHaloSize) |
| 1184 |
.function("setSunHaloFalloff", &LightManager::setSunHaloFalloff) |
| 1185 |
.function("getSunHaloFalloff", &LightManager::getSunHaloFalloff) |
| 1186 |
.function("setShadowCaster", &LightManager::setShadowCaster) |
| 1187 |
.function("isShadowCaster", &LightManager::isShadowCaster) |
| 1188 |
; |
| 1189 |
|
| 1190 |
/// LightManager$Instance ::class:: Component instance returned by [LightManager] |
| 1191 |
/// Be sure to call the instance's `delete` method when you're done with it. |
| 1192 |
class_<LightManager::Instance>("LightManager$Instance"); |
| 1193 |
/// delete ::method:: Frees an instance obtained via `getInstance` |
| 1194 |
|
| 1195 |
class_<BufferBuilder>("BufferObject$Builder") |
| 1196 |
.function("_build", EMBIND_LAMBDA(BufferObject*, (BufferBuilder* builder, Engine* engine), { |
| 1197 |
return builder->build(*engine); |
| 1198 |
}), allow_raw_pointers()) |
| 1199 |
.BUILDER_FUNCTION("bindingType", BufferBuilder, (BufferBuilder* builder, |
| 1200 |
BufferObject::BindingType bt), { |
| 1201 |
return &builder->bindingType(bt); }) |
| 1202 |
.BUILDER_FUNCTION("size", BufferBuilder, (BufferBuilder* builder, int byteCount), { |
| 1203 |
return &builder->size(byteCount); }); |
| 1204 |
|
| 1205 |
/// BufferObject ::core class:: Represents a single GPU buffer. |
| 1206 |
class_<BufferObject>("BufferObject") |
| 1207 |
.class_function("Builder", (BufferBuilder (*)()) [] { return BufferBuilder(); }) |
| 1208 |
.function("getByteCount", &BufferObject::getByteCount) |
| 1209 |
.function("_setBuffer", EMBIND_LAMBDA(void, (BufferObject* self, |
| 1210 |
Engine* engine, BufferDescriptor bd, uint32_t byteOffset), { |
| 1211 |
self->setBuffer(*engine, std::move(*bd.bd), byteOffset); |
| 1212 |
}), allow_raw_pointers()); |
| 1213 |
|
| 1214 |
class_<VertexBuilder>("VertexBuffer$Builder") |
| 1215 |
.function("_build", EMBIND_LAMBDA(VertexBuffer*, (VertexBuilder* builder, Engine* engine), { |
| 1216 |
return builder->build(*engine); |
| 1217 |
}), allow_raw_pointers()) |
| 1218 |
.BUILDER_FUNCTION("attribute", VertexBuilder, (VertexBuilder* builder, |
| 1219 |
VertexAttribute attr, |
| 1220 |
uint8_t bufferIndex, |
| 1221 |
VertexBuffer::AttributeType attrType, |
| 1222 |
uint32_t byteOffset, |
| 1223 |
uint8_t byteStride), { |
| 1224 |
return &builder->attribute(attr, bufferIndex, attrType, byteOffset, byteStride); }) |
| 1225 |
.BUILDER_FUNCTION("vertexCount", VertexBuilder, (VertexBuilder* builder, int count), { |
| 1226 |
return &builder->vertexCount(count); }) |
| 1227 |
.BUILDER_FUNCTION("enableBufferObjects", VertexBuilder, (VertexBuilder* builder, bool enable), { |
| 1228 |
return &builder->enableBufferObjects(enable); }) |
| 1229 |
.BUILDER_FUNCTION("normalized", VertexBuilder, (VertexBuilder* builder, |
| 1230 |
VertexAttribute attrib), { |
| 1231 |
return &builder->normalized(attrib); }) |
| 1232 |
.BUILDER_FUNCTION("normalizedIf", VertexBuilder, (VertexBuilder* builder, |
| 1233 |
VertexAttribute attrib, bool normalized), { |
| 1234 |
return &builder->normalized(attrib, normalized); }) |
| 1235 |
.BUILDER_FUNCTION("bufferCount", VertexBuilder, (VertexBuilder* builder, int count), { |
| 1236 |
return &builder->bufferCount(count); }); |
| 1237 |
|
| 1238 |
/// VertexBuffer ::core class:: Bundle of buffers and associated vertex attributes. |
| 1239 |
class_<VertexBuffer>("VertexBuffer") |
| 1240 |
.class_function("Builder", (VertexBuilder (*)()) [] { return VertexBuilder(); }) |
| 1241 |
.function("setBufferObjectAt", &VertexBuffer::setBufferObjectAt, allow_raw_pointers()) |
| 1242 |
.function("_setBufferAt", EMBIND_LAMBDA(void, (VertexBuffer* self, |
| 1243 |
Engine* engine, uint8_t bufferIndex, BufferDescriptor vbd, uint32_t byteOffset), { |
| 1244 |
self->setBufferAt(*engine, bufferIndex, std::move(*vbd.bd), byteOffset); |
| 1245 |
}), allow_raw_pointers()); |
| 1246 |
|
| 1247 |
class_<IndexBuilder>("IndexBuffer$Builder") |
| 1248 |
.function("_build", EMBIND_LAMBDA(IndexBuffer*, (IndexBuilder* builder, Engine* engine), { |
| 1249 |
return builder->build(*engine); |
| 1250 |
}), allow_raw_pointers()) |
| 1251 |
.BUILDER_FUNCTION("indexCount", IndexBuilder, (IndexBuilder* builder, int count), { |
| 1252 |
return &builder->indexCount(count); }) |
| 1253 |
.BUILDER_FUNCTION("bufferType", IndexBuilder, (IndexBuilder* builder, |
| 1254 |
IndexBuffer::IndexType indexType), { |
| 1255 |
return &builder->bufferType(indexType); }); |
| 1256 |
|
| 1257 |
/// IndexBuffer ::core class:: Array of 16-bit or 32-bit unsigned integers consumed by the GPU. |
| 1258 |
class_<IndexBuffer>("IndexBuffer") |
| 1259 |
.class_function("Builder", (IndexBuilder (*)()) [] { return IndexBuilder(); }) |
| 1260 |
.function("_setBuffer", EMBIND_LAMBDA(void, (IndexBuffer* self, |
| 1261 |
Engine* engine, BufferDescriptor ibd, uint32_t byteOffset), { |
| 1262 |
self->setBuffer(*engine, std::move(*ibd.bd), byteOffset); |
| 1263 |
}), allow_raw_pointers()); |
| 1264 |
|
| 1265 |
class_<Material>("Material") |
| 1266 |
.function("getDefaultInstance", |
| 1267 |
select_overload<MaterialInstance*(void)>(&Material::getDefaultInstance), |
| 1268 |
allow_raw_pointers()) |
| 1269 |
.function("createInstance", EMBIND_LAMBDA(MaterialInstance*, (Material* self), { |
| 1270 |
return self->createInstance(); }), allow_raw_pointers()) |
| 1271 |
.function("createNamedInstance", EMBIND_LAMBDA(MaterialInstance*, |
| 1272 |
(Material* self, std::string name), { |
| 1273 |
return self->createInstance(name.c_str()); }), allow_raw_pointers()) |
| 1274 |
.function("getName", EMBIND_LAMBDA(std::string, (Material* self), { |
| 1275 |
return std::string(self->getName()); |
| 1276 |
}), allow_raw_pointers()); |
| 1277 |
|
| 1278 |
class_<MaterialInstance>("MaterialInstance") |
| 1279 |
.function("getName", EMBIND_LAMBDA(std::string, (MaterialInstance* self), { |
| 1280 |
return std::string(self->getName()); |
| 1281 |
}), allow_raw_pointers()) |
| 1282 |
.function("setBoolParameter", EMBIND_LAMBDA(void, |
| 1283 |
(MaterialInstance* self, std::string name, bool value), { |
| 1284 |
self->setParameter(name.c_str(), value); }), allow_raw_pointers()) |
| 1285 |
.function("setFloatParameter", EMBIND_LAMBDA(void, |
| 1286 |
(MaterialInstance* self, std::string name, float value), { |
| 1287 |
self->setParameter(name.c_str(), value); }), allow_raw_pointers()) |
| 1288 |
.function("setFloat2Parameter", EMBIND_LAMBDA(void, |
| 1289 |
(MaterialInstance* self, std::string name, filament::math::float2 value), { |
| 1290 |
self->setParameter(name.c_str(), value); }), allow_raw_pointers()) |
| 1291 |
.function("setFloat3Parameter", EMBIND_LAMBDA(void, |
| 1292 |
(MaterialInstance* self, std::string name, filament::math::float3 value), { |
| 1293 |
self->setParameter(name.c_str(), value); }), allow_raw_pointers()) |
| 1294 |
.function("setFloat4Parameter", EMBIND_LAMBDA(void, |
| 1295 |
(MaterialInstance* self, std::string name, filament::math::float4 value), { |
| 1296 |
self->setParameter(name.c_str(), value); }), allow_raw_pointers()) |
| 1297 |
.function("setTextureParameter", EMBIND_LAMBDA(void, |
| 1298 |
(MaterialInstance* self, std::string name, Texture* value, TextureSampler sampler), { |
| 1299 |
self->setParameter(name.c_str(), value, sampler); }), allow_raw_pointers()) |
| 1300 |
.function("setColor3Parameter", EMBIND_LAMBDA(void, |
| 1301 |
(MaterialInstance* self, std::string name, RgbType type, filament::math::float3 value), { |
| 1302 |
self->setParameter(name.c_str(), type, value); }), allow_raw_pointers()) |
| 1303 |
.function("setColor4Parameter", EMBIND_LAMBDA(void, |
| 1304 |
(MaterialInstance* self, std::string name, RgbaType type, filament::math::float4 value), { |
| 1305 |
self->setParameter(name.c_str(), type, value); }), allow_raw_pointers()) |
| 1306 |
.function("setPolygonOffset", &MaterialInstance::setPolygonOffset) |
| 1307 |
.function("setMaskThreshold", &MaterialInstance::setMaskThreshold) |
| 1308 |
.function("setDoubleSided", &MaterialInstance::setDoubleSided) |
| 1309 |
.function("setCullingMode", &MaterialInstance::setCullingMode) |
| 1310 |
.function("setColorWrite", &MaterialInstance::setColorWrite) |
| 1311 |
.function("setDepthWrite", &MaterialInstance::setDepthWrite) |
| 1312 |
.function("setDepthCulling", &MaterialInstance::setDepthCulling); |
| 1313 |
|
| 1314 |
class_<TextureSampler>("TextureSampler") |
| 1315 |
.constructor<backend::SamplerMinFilter, backend::SamplerMagFilter, backend::SamplerWrapMode>() |
| 1316 |
.function("setAnisotropy", &TextureSampler::setAnisotropy) |
| 1317 |
.function("setCompareMode", &TextureSampler::setCompareMode); |
| 1318 |
|
| 1319 |
/// Texture ::core class:: 2D image or cubemap that can be sampled by the GPU, possibly mipmapped. |
| 1320 |
class_<Texture>("Texture") |
| 1321 |
.class_function("Builder", (TexBuilder (*)()) [] { return TexBuilder(); }) |
| 1322 |
.function("generateMipmaps", &Texture::generateMipmaps) |
| 1323 |
.function("_setImage", EMBIND_LAMBDA(void, (Texture* self, |
| 1324 |
Engine* engine, uint8_t level, PixelBufferDescriptor pbd), { |
| 1325 |
self->setImage(*engine, level, std::move(*pbd.pbd)); |
| 1326 |
}), allow_raw_pointers()) |
| 1327 |
.function("_setImageCube", EMBIND_LAMBDA(void, (Texture* self, |
| 1328 |
Engine* engine, uint8_t level, PixelBufferDescriptor pbd), { |
| 1329 |
uint32_t faceSize = pbd.pbd->size / 6; |
| 1330 |
Texture::FaceOffsets offsets(faceSize); |
| 1331 |
self->setImage(*engine, level, std::move(*pbd.pbd), offsets); |
| 1332 |
}), allow_raw_pointers()); |
| 1333 |
|
| 1334 |
class_<TexBuilder>("Texture$Builder") |
| 1335 |
.function("_build", EMBIND_LAMBDA(Texture*, (TexBuilder* builder, Engine* engine), { |
| 1336 |
return builder->build(*engine); |
| 1337 |
}), allow_raw_pointers()) |
| 1338 |
.BUILDER_FUNCTION("width", TexBuilder, (TexBuilder* builder, uint32_t width), { |
| 1339 |
return &builder->width(width); }) |
| 1340 |
.BUILDER_FUNCTION("height", TexBuilder, (TexBuilder* builder, uint32_t height), { |
| 1341 |
return &builder->height(height); }) |
| 1342 |
.BUILDER_FUNCTION("depth", TexBuilder, (TexBuilder* builder, uint32_t depth), { |
| 1343 |
return &builder->depth(depth); }) |
| 1344 |
.BUILDER_FUNCTION("levels", TexBuilder, (TexBuilder* builder, uint8_t levels), { |
| 1345 |
return &builder->levels(levels); }) |
| 1346 |
.BUILDER_FUNCTION("sampler", TexBuilder, (TexBuilder* builder, Texture::Sampler target), { |
| 1347 |
return &builder->sampler(target); }) |
| 1348 |
.BUILDER_FUNCTION("format", TexBuilder, (TexBuilder* builder, Texture::InternalFormat fmt), { |
| 1349 |
return &builder->format(fmt); }) |
| 1350 |
|
| 1351 |
// This takes a bitfield that can be composed by or'ing constants. |
| 1352 |
// - JS clients should use the value member, as in: "Texture$Usage.SAMPLEABLE.value". |
| 1353 |
// - TypeScript clients can simply say "TextureUsage.SAMPLEABLE" (note the lack of $) |
| 1354 |
.BUILDER_FUNCTION("usage", TexBuilder, (TexBuilder* builder, uint8_t usage), { |
| 1355 |
return &builder->usage((Texture::Usage)usage); }); |
| 1356 |
|
| 1357 |
class_<IndirectLight>("IndirectLight") |
| 1358 |
.class_function("Builder", (IblBuilder (*)()) [] { return IblBuilder(); }) |
| 1359 |
.function("setIntensity", &IndirectLight::setIntensity) |
| 1360 |
.function("getIntensity", &IndirectLight::getIntensity) |
| 1361 |
.function("setRotation", EMBIND_LAMBDA(void, (IndirectLight* self, flatmat3 value), { |
| 1362 |
return self->setRotation(value.m); |
| 1363 |
}), allow_raw_pointers()) |
| 1364 |
.function("getRotation", EMBIND_LAMBDA(flatmat3, (IndirectLight* self), { |
| 1365 |
return flatmat3 { self->getRotation() }; |
| 1366 |
}), allow_raw_pointers()) |
| 1367 |
.function("getReflectionsTexture", EMBIND_LAMBDA(Texture*, (IndirectLight* self), { |
| 1368 |
return (Texture*) self->getReflectionsTexture(); // cast away const to appease embind |
| 1369 |
}), allow_raw_pointers()) |
| 1370 |
.function("getIrradianceTexture", EMBIND_LAMBDA(Texture*, (IndirectLight* self), { |
| 1371 |
return (Texture*) self->getIrradianceTexture(); // cast away const to appease embind |
| 1372 |
}), allow_raw_pointers()) |
| 1373 |
.class_function("getDirectionEstimate", EMBIND_LAMBDA(filament::math::float3, (val ta), { |
| 1374 |
size_t nfloats = ta["length"].as<size_t>(); |
| 1375 |
std::vector<float> floats(nfloats); |
| 1376 |
for (size_t i = 0; i < nfloats; i++) { |
| 1377 |
floats[i] = ta[i].as<float>(); |
| 1378 |
} |
| 1379 |
return IndirectLight::getDirectionEstimate((filament::math::float3*) floats.data()); |
| 1380 |
}), allow_raw_pointers()) |
| 1381 |
.class_function("getColorEstimate", EMBIND_LAMBDA(filament::math::float4, (val ta, |
| 1382 |
filament::math::float3 dir), { |
| 1383 |
size_t nfloats = ta["length"].as<size_t>(); |
| 1384 |
std::vector<float> floats(nfloats); |
| 1385 |
for (size_t i = 0; i < nfloats; i++) { |
| 1386 |
floats[i] = ta[i].as<float>(); |
| 1387 |
} |
| 1388 |
return IndirectLight::getColorEstimate((filament::math::float3*) floats.data(), dir); |
| 1389 |
}), allow_raw_pointers()); |
| 1390 |
|
| 1391 |
class_<IblBuilder>("IndirectLight$Builder") |
| 1392 |
.function("_build", EMBIND_LAMBDA(IndirectLight*, (IblBuilder* builder, Engine* engine), { |
| 1393 |
return builder->build(*engine); |
| 1394 |
}), allow_raw_pointers()) |
| 1395 |
.BUILDER_FUNCTION("reflections", IblBuilder, (IblBuilder* builder, Texture const* cubemap), { |
| 1396 |
return &builder->reflections(cubemap); }) |
| 1397 |
.BUILDER_FUNCTION("irradianceTex", IblBuilder, (IblBuilder* builder, Texture const* cubemap), { |
| 1398 |
return &builder->irradiance(cubemap); }) |
| 1399 |
.BUILDER_FUNCTION("irradianceSh", IblBuilder, (IblBuilder* builder, uint8_t nbands, val ta), { |
| 1400 |
// This is not efficient but consuming a BufferDescriptor would be overkill. |
| 1401 |
size_t nfloats = ta["length"].as<size_t>(); |
| 1402 |
if (nfloats != nbands * nbands * 3) { |
| 1403 |
printf("Received %zu floats for spherical harmonics, expected %d.", nfloats, nbands); |
| 1404 |
return builder; |
| 1405 |
} |
| 1406 |
std::vector<float> floats(nfloats); |
| 1407 |
for (size_t i = 0; i < nfloats; i++) { |
| 1408 |
floats[i] = ta[i].as<float>(); |
| 1409 |
} |
| 1410 |
return &builder->irradiance(nbands, (filament::math::float3 const*) floats.data()); }) |
| 1411 |
.BUILDER_FUNCTION("intensity", IblBuilder, (IblBuilder* builder, float value), { |
| 1412 |
return &builder->intensity(value); }) |
| 1413 |
.BUILDER_FUNCTION("rotation", IblBuilder, (IblBuilder* builder, flatmat3 value), { |
| 1414 |
return &builder->rotation(value.m); }); |
| 1415 |
|
| 1416 |
class_<Skybox>("Skybox") |
| 1417 |
.class_function("Builder", (SkyBuilder (*)()) [] { return SkyBuilder(); }) |
| 1418 |
.function("setColor", &Skybox::setColor) |
| 1419 |
.function("getTexture", EMBIND_LAMBDA(Texture*, (Skybox* skybox), { |
| 1420 |
return (Texture*) skybox->getTexture(); // cast away const to appease embind |
| 1421 |
}), allow_raw_pointers()); |
| 1422 |
|
| 1423 |
class_<SkyBuilder>("Skybox$Builder") |
| 1424 |
.function("_build", EMBIND_LAMBDA(Skybox*, (SkyBuilder* builder, Engine* engine), { |
| 1425 |
return builder->build(*engine); |
| 1426 |
}), allow_raw_pointers()) |
| 1427 |
.BUILDER_FUNCTION("color", SkyBuilder, (SkyBuilder* builder, filament::math::float4 color), { |
| 1428 |
return &builder->color(color); }) |
| 1429 |
.BUILDER_FUNCTION("environment", SkyBuilder, (SkyBuilder* builder, Texture* cubemap), { |
| 1430 |
return &builder->environment(cubemap); }) |
| 1431 |
.BUILDER_FUNCTION("showSun", SkyBuilder, (SkyBuilder* builder, bool show), { |
| 1432 |
return &builder->showSun(show); }); |
| 1433 |
|
| 1434 |
// UTILS TYPES |
| 1435 |
// ----------- |
| 1436 |
|
| 1437 |
/// Entity ::core class:: Handle to an object consisting of a set of components. |
| 1438 |
/// To create an entity with no components, use [EntityManager]. |
| 1439 |
/// TODO: It would be better to expose these as JS numbers rather than as JS objects. |
| 1440 |
/// This would also be more consistent with Filament's Java bindings. |
| 1441 |
class_<utils::Entity>("Entity") |
| 1442 |
.function("getId", &utils::Entity::getId); |
| 1443 |
/// delete ::method:: Frees an entity. |
| 1444 |
|
| 1445 |
/// EntityManager ::core class:: Singleton used for constructing entities in Filament's ECS. |
| 1446 |
class_<utils::EntityManager>("EntityManager") |
| 1447 |
/// get ::static method:: Gets the singleton entity manager instance. |
| 1448 |
/// ::retval:: the one and only entity manager |
| 1449 |
.class_function("get", (utils::EntityManager* (*)()) [] |
| 1450 |
{ return &utils::EntityManager::get(); }, allow_raw_pointers()) |
| 1451 |
|
| 1452 |
#if FILAMENT_UTILS_TRACK_ENTITIES |
| 1453 |
.function("getActiveEntityCount", EMBIND_LAMBDA(size_t, (utils::EntityManager* self), { |
| 1454 |
return self->getActiveEntities().size(); |
| 1455 |
}), allow_raw_pointers()) |
| 1456 |
#endif |
| 1457 |
|
| 1458 |
/// create ::method:: |
| 1459 |
/// ::retval:: an [Entity] without any components |
| 1460 |
.function("create", select_overload<utils::Entity()>(&utils::EntityManager::create)) |
| 1461 |
.function("destroy", select_overload<void(utils::Entity)>(&utils::EntityManager::destroy)); |
| 1462 |
|
| 1463 |
// DRIVER TYPES |
| 1464 |
// ------------ |
| 1465 |
|
| 1466 |
/// BufferDescriptor ::class:: Low level buffer wrapper. |
| 1467 |
/// Clients should use the [Buffer] helper function to contruct BufferDescriptor objects. |
| 1468 |
class_<BufferDescriptor>("driver$BufferDescriptor") |
| 1469 |
.constructor<uint32_t>() |
| 1470 |
/// getBytes ::method:: Gets a view of the WASM heap referenced by the buffer descriptor. |
| 1471 |
/// ::retval:: Uint8Array |
| 1472 |
.function("getBytes", &BufferDescriptor::getBytes); |
| 1473 |
|
| 1474 |
/// PixelBufferDescriptor ::class:: Low level pixel buffer wrapper. |
| 1475 |
/// Clients should use the [PixelBuffer] helper function to contruct PixelBufferDescriptor objects. |
| 1476 |
class_<PixelBufferDescriptor>("driver$PixelBufferDescriptor") |
| 1477 |
.constructor<uint32_t, backend::PixelDataFormat, backend::PixelDataType>() |
| 1478 |
.constructor<uint32_t, backend::CompressedPixelDataType, int, bool>() |
| 1479 |
/// getBytes ::method:: Gets a view of the WASM heap referenced by the buffer descriptor. |
| 1480 |
/// ::retval:: Uint8Array |
| 1481 |
.function("getBytes", &PixelBufferDescriptor::getBytes); |
| 1482 |
|
| 1483 |
// HELPER TYPES |
| 1484 |
// ------------ |
| 1485 |
|
| 1486 |
/// KtxBundle ::class:: In-memory representation of a KTX file. |
| 1487 |
/// Most clients should use one of the `create*FromKtx` utility methods in the JavaScript [Engine] |
| 1488 |
/// wrapper rather than interacting with `KtxBundle` directly. |
| 1489 |
class_<KtxBundle>("KtxBundle") |
| 1490 |
.constructor(EMBIND_LAMBDA(KtxBundle*, (BufferDescriptor kbd), { |
| 1491 |
return new KtxBundle((uint8_t*) kbd.bd->buffer, (uint32_t) kbd.bd->size); |
| 1492 |
})) |
| 1493 |
|
| 1494 |
/// info ::method:: Obtains properties of the KTX header. |
| 1495 |
/// ::retval:: The [KtxInfo] property accessor object. |
| 1496 |
.function("getNumMipLevels", &KtxBundle::getNumMipLevels) |
| 1497 |
|
| 1498 |
/// getArrayLength ::method:: Obtains length of the texture array. |
| 1499 |
/// ::retval:: The number of elements in the texture array |
| 1500 |
.function("getArrayLength", &KtxBundle::getArrayLength) |
| 1501 |
|
| 1502 |
/// getInternalFormat ::method:: |
| 1503 |
/// srgb ::argument:: boolean that forces the resulting format to SRGB if possible. |
| 1504 |
/// ::retval:: [Texture$InternalFormat] |
| 1505 |
/// Returns "undefined" if no valid Filament enumerant exists. |
| 1506 |
.function("getInternalFormat", |
| 1507 |
EMBIND_LAMBDA(Texture::InternalFormat, (KtxBundle* self, bool srgb), { |
| 1508 |
auto result = ktx::toTextureFormat(self->info()); |
| 1509 |
if (srgb) { |
| 1510 |
if (result == Texture::InternalFormat::RGB8) { |
| 1511 |
result = Texture::InternalFormat::SRGB8; |
| 1512 |
} |
| 1513 |
if (result == Texture::InternalFormat::RGBA8) { |
| 1514 |
result = Texture::InternalFormat::SRGB8_A8; |
| 1515 |
} |
| 1516 |
} |
| 1517 |
return result; |
| 1518 |
}), allow_raw_pointers()) |
| 1519 |
|
| 1520 |
/// getPixelDataFormat ::method:: |
| 1521 |
/// ::retval:: [PixelDataFormat] |
| 1522 |
/// Returns "undefined" if no valid Filament enumerant exists. |
| 1523 |
.function("getPixelDataFormat", |
| 1524 |
EMBIND_LAMBDA(backend::PixelDataFormat, (KtxBundle* self), { |
| 1525 |
return ktx::toPixelDataFormat(self->getInfo()); |
| 1526 |
}), allow_raw_pointers()) |
| 1527 |
|
| 1528 |
/// getPixelDataType ::method:: |
| 1529 |
/// ::retval:: [PixelDataType] |
| 1530 |
/// Returns "undefined" if no valid Filament enumerant exists. |
| 1531 |
.function("getPixelDataType", |
| 1532 |
EMBIND_LAMBDA(backend::PixelDataType, (KtxBundle* self), { |
| 1533 |
return ktx::toPixelDataType(self->getInfo()); |
| 1534 |
}), allow_raw_pointers()) |
| 1535 |
|
| 1536 |
/// getCompressedPixelDataType ::method:: |
| 1537 |
/// ::retval:: [CompressedPixelDataType] |
| 1538 |
/// Returns "undefined" if no valid Filament enumerant exists. |
| 1539 |
.function("getCompressedPixelDataType", |
| 1540 |
EMBIND_LAMBDA(backend::CompressedPixelDataType, (KtxBundle* self), { |
| 1541 |
return ktx::toCompressedPixelDataType(self->getInfo()); |
| 1542 |
}), allow_raw_pointers()) |
| 1543 |
|
| 1544 |
/// isCompressed ::method:: |
| 1545 |
/// Per spec, compressed textures in KTX always have their glFormat field set to 0. |
| 1546 |
/// ::retval:: boolean |
| 1547 |
.function("isCompressed", EMBIND_LAMBDA(bool, (KtxBundle* self), { |
| 1548 |
return ktx::isCompressed(self->getInfo()); |
| 1549 |
}), allow_raw_pointers()) |
| 1550 |
|
| 1551 |
.function("isCubemap", &KtxBundle::isCubemap) |
| 1552 |
.function("_getBlob", EMBIND_LAMBDA(BufferDescriptor, (KtxBundle* self, KtxBlobIndex index), { |
| 1553 |
uint8_t* data; |
| 1554 |
uint32_t size; |
| 1555 |
self->getBlob(index, &data, &size); |
| 1556 |
return BufferDescriptor(data, size); |
| 1557 |
}), allow_raw_pointers()) |
| 1558 |
.function("_getCubeBlob", EMBIND_LAMBDA(BufferDescriptor, |
| 1559 |
(KtxBundle* self, uint32_t miplevel), { |
| 1560 |
uint8_t* data; |
| 1561 |
uint32_t size; |
| 1562 |
self->getBlob({miplevel}, &data, &size); |
| 1563 |
return BufferDescriptor(data, size * 6); |
| 1564 |
}), allow_raw_pointers()) |
| 1565 |
|
| 1566 |
/// info ::method:: Obtains properties of the KTX header. |
| 1567 |
/// ::retval:: The [KtxInfo] property accessor object. |
| 1568 |
.function("info", &KtxBundle::info) |
| 1569 |
|
| 1570 |
/// getMetadata ::method:: Obtains arbitrary metadata from the KTX file. |
| 1571 |
/// key ::argument:: string |
| 1572 |
/// ::retval:: string |
| 1573 |
.function("getMetadata", EMBIND_LAMBDA(std::string, (KtxBundle* self, std::string key), { |
| 1574 |
return std::string(self->getMetadata(key.c_str())); |
| 1575 |
}), allow_raw_pointers()); |
| 1576 |
|
| 1577 |
function("ktx$createTexture", EMBIND_LAMBDA(Texture*, |
| 1578 |
(Engine* engine, const KtxBundle& ktx, bool srgb), { |
| 1579 |
return ktx::createTexture(engine, ktx, srgb, nullptr, nullptr); |
| 1580 |
}), allow_raw_pointers()); |
| 1581 |
|
| 1582 |
/// KtxInfo ::class:: Property accessor for KTX header. |
| 1583 |
/// For example, `ktxbundle.info().pixelWidth`. See the |
| 1584 |
/// [KTX spec](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) for the list of |
| 1585 |
/// properties. |
| 1586 |
class_<KtxInfo>("KtxInfo") |
| 1587 |
.property("endianness", &KtxInfo::endianness) |
| 1588 |
.property("glType", &KtxInfo::glType) |
| 1589 |
.property("glTypeSize", &KtxInfo::glTypeSize) |
| 1590 |
.property("glFormat", &KtxInfo::glFormat) |
| 1591 |
.property("glInternalFormat", &KtxInfo::glInternalFormat) |
| 1592 |
.property("glBaseInternalFormat", &KtxInfo::glBaseInternalFormat) |
| 1593 |
.property("pixelWidth", &KtxInfo::pixelWidth) |
| 1594 |
.property("pixelHeight", &KtxInfo::pixelHeight) |
| 1595 |
.property("pixelDepth", &KtxInfo::pixelDepth); |
| 1596 |
|
| 1597 |
class_<MeshReader::MaterialRegistry>("MeshReader$MaterialRegistry") |
| 1598 |
.constructor<>() |
| 1599 |
.function("size", &MeshReader::MaterialRegistry::numRegistered) |
| 1600 |
.function("get", EMBIND_LAMBDA(val, (MeshReader::MaterialRegistry* self, std::string k), { |
| 1601 |
const utils::CString name(k.c_str(), k.size()); |
| 1602 |
auto i = self->getMaterialInstance(name); |
| 1603 |
if (i == nullptr) { |
| 1604 |
return val::undefined(); |
| 1605 |
} else { |
| 1606 |
return val(i); |
| 1607 |
} |
| 1608 |
}), allow_raw_pointers()) |
| 1609 |
.function("set", EMBIND_LAMBDA(void, (MeshReader::MaterialRegistry* self, std::string k, filament::MaterialInstance* v), { |
| 1610 |
const utils::CString name(k.c_str(), k.size()); |
| 1611 |
self->registerMaterialInstance(name, v); |
| 1612 |
}), allow_raw_pointers()) |
| 1613 |
.function("keys", EMBIND_LAMBDA(std::vector<std::string>, (MeshReader::MaterialRegistry* self), { |
| 1614 |
std::vector<utils::CString> names(self->numRegistered()); |
| 1615 |
self->getRegisteredMaterialNames(names.data()); |
| 1616 |
std::vector<std::string> result(self->numRegistered()); |
| 1617 |
for (const auto& name : names) { |
| 1618 |
result.emplace_back(name.c_str()); |
| 1619 |
} |
| 1620 |
return result; |
| 1621 |
}), allow_raw_pointers()); |
| 1622 |
|
| 1623 |
// MeshReader ::class:: Simple parser for filamesh files. |
| 1624 |
// JavaScript clients are encouraged to use the [loadFilamesh] helper function instead of using |
| 1625 |
// this class directly. |
| 1626 |
class_<MeshReader>("MeshReader") |
| 1627 |
// loadMeshFromBuffer ::static method:: Parses a filamesh buffer. |
| 1628 |
// engine ::argument:: [Engine] |
| 1629 |
// buffer ::argument:: [Buffer] |
| 1630 |
// materials ::argument:: [MeshReader$MaterialRegistry] |
| 1631 |
// ::retval:: the [MeshReader$Mesh] object |
| 1632 |
.class_function("loadMeshFromBuffer", EMBIND_LAMBDA(MeshReader::Mesh, |
| 1633 |
(Engine* engine, BufferDescriptor buffer, MeshReader::MaterialRegistry& matreg), { |
| 1634 |
// This destruction lambda is called for the vertex buffer AND index buffer, so release |
| 1635 |
// CPU memory only after both have been uploaded to the GPU. |
| 1636 |
struct Bundle { int count; BufferDescriptor buffer; }; |
| 1637 |
Bundle* bundle = new Bundle({ .count = 0, .buffer = buffer }); |
| 1638 |
const auto destructor = [](void* buffer, size_t size, void* user) { |
| 1639 |
Bundle* bundle = (Bundle*) user; |
| 1640 |
if (++bundle->count == 2) { |
| 1641 |
delete bundle; |
| 1642 |
} |
| 1643 |
}; |
| 1644 |
// Parse the filamesh buffer. This creates the VB, IB, and renderable. |
| 1645 |
return MeshReader::loadMeshFromBuffer( |
| 1646 |
engine, buffer.bd->buffer, |
| 1647 |
destructor, bundle, matreg); |
| 1648 |
}), allow_raw_pointers()); |
| 1649 |
|
| 1650 |
// MeshReader$Mesh ::class:: Property accessor for objects created by [MeshReader]. |
| 1651 |
// This exposes three getter methods: `renderable()`, `vertexBuffer()`, and `indexBuffer()`. These |
| 1652 |
// are of type [Entity], [VertexBuffer], and [IndexBuffer]. JavaScript clients are encouraged to |
| 1653 |
// use the [loadFilamesh] helper function instead of using this class directly. |
| 1654 |
class_<MeshReader::Mesh>("MeshReader$Mesh") |
| 1655 |
.function("renderable", EMBIND_LAMBDA(utils::Entity, (MeshReader::Mesh mesh), { |
| 1656 |
return mesh.renderable; |
| 1657 |
}), allow_raw_pointers()) |
| 1658 |
.function("vertexBuffer", EMBIND_LAMBDA(VertexBuffer*, (MeshReader::Mesh mesh), { |
| 1659 |
return mesh.vertexBuffer; |
| 1660 |
}), allow_raw_pointers()) |
| 1661 |
.function("indexBuffer", EMBIND_LAMBDA(IndexBuffer*, (MeshReader::Mesh mesh), { |
| 1662 |
return mesh.indexBuffer; |
| 1663 |
}), allow_raw_pointers()); |
| 1664 |
|
| 1665 |
// Clients should call [createTextureFromPng] (et al) rather than using decodeImage directly. |
| 1666 |
|
| 1667 |
function("decodeImage", &decodeImage); |
| 1668 |
|
| 1669 |
class_<DecodedImage>("DecodedImage") |
| 1670 |
.property("width", &DecodedImage::width) |
| 1671 |
.property("height", &DecodedImage::height) |
| 1672 |
.property("data", &DecodedImage::decoded_data); |
| 1673 |
|
| 1674 |
class_<SurfaceBuilder>("SurfaceOrientation$Builder") |
| 1675 |
|
| 1676 |
.constructor<>() |
| 1677 |
|
| 1678 |
.BUILDER_FUNCTION("vertexCount", SurfaceBuilder, (SurfaceBuilder* builder, size_t nverts), { |
| 1679 |
return &builder->vertexCount(nverts); |
| 1680 |
}) |
| 1681 |
|
| 1682 |
.BUILDER_FUNCTION("_normals", SurfaceBuilder, (SurfaceBuilder* builder, |
| 1683 |
intptr_t data, int stride), { |
| 1684 |
return &builder->normals((const filament::math::float3*) data, stride); |
| 1685 |
}) |
| 1686 |
|
| 1687 |
.BUILDER_FUNCTION("_tangents", SurfaceBuilder, (SurfaceBuilder* builder, |
| 1688 |
intptr_t data, int stride), { |
| 1689 |
return &builder->tangents((const filament::math::float4*) data, stride); |
| 1690 |
}) |
| 1691 |
|
| 1692 |
.BUILDER_FUNCTION("_uvs", SurfaceBuilder, (SurfaceBuilder* builder, intptr_t data, int stride), { |
| 1693 |
return &builder->uvs((const filament::math::float2*) data, stride); |
| 1694 |
}) |
| 1695 |
|
| 1696 |
.BUILDER_FUNCTION("_positions", SurfaceBuilder, (SurfaceBuilder* builder, |
| 1697 |
intptr_t data, int stride), { |
| 1698 |
return &builder->positions((const filament::math::float3*) data, stride); |
| 1699 |
}) |
| 1700 |
|
| 1701 |
.BUILDER_FUNCTION("triangleCount", SurfaceBuilder, (SurfaceBuilder* builder, size_t n), { |
| 1702 |
return &builder->triangleCount(n); |
| 1703 |
}) |
| 1704 |
|
| 1705 |
.BUILDER_FUNCTION("_triangles16", SurfaceBuilder, (SurfaceBuilder* builder, intptr_t data), { |
| 1706 |
return &builder->triangles((filament::math::ushort3*) data); |
| 1707 |
}) |
| 1708 |
|
| 1709 |
.BUILDER_FUNCTION("_triangles32", SurfaceBuilder, (SurfaceBuilder* builder, intptr_t data), { |
| 1710 |
return &builder->triangles((filament::math::uint3*) data); |
| 1711 |
}) |
| 1712 |
|
| 1713 |
.function("_build", EMBIND_LAMBDA(SurfaceOrientation*, (SurfaceBuilder* builder), { |
| 1714 |
return builder->build(); |
| 1715 |
}), allow_raw_pointers()); |
| 1716 |
|
| 1717 |
class_<SurfaceOrientation>("SurfaceOrientation") |
| 1718 |
.function("_getQuats", EMBIND_LAMBDA(void, (SurfaceOrientation* self, |
| 1719 |
intptr_t out, size_t quatCount, VertexBuffer::AttributeType attrtype), { |
| 1720 |
switch (attrtype) { |
| 1721 |
case VertexBuffer::AttributeType::FLOAT4: { |
| 1722 |
self->getQuats((filament::math::quatf*) out, quatCount); |
| 1723 |
break; |
| 1724 |
} |
| 1725 |
case VertexBuffer::AttributeType::HALF4: { |
| 1726 |
self->getQuats((filament::math::quath*) out, quatCount); |
| 1727 |
break; |
| 1728 |
} |
| 1729 |
case VertexBuffer::AttributeType::SHORT4: { |
| 1730 |
self->getQuats((filament::math::short4*) out, quatCount); |
| 1731 |
break; |
| 1732 |
} |
| 1733 |
default: |
| 1734 |
utils::slog.e << "Unsupported quaternion type." << utils::io::endl; |
| 1735 |
} |
| 1736 |
}), allow_raw_pointers()); |
| 1737 |
|
| 1738 |
class_<Animator>("gltfio$Animator") |
| 1739 |
.function("applyAnimation", &Animator::applyAnimation) |
| 1740 |
.function("updateBoneMatrices", &Animator::updateBoneMatrices) |
| 1741 |
.function("getAnimationCount", &Animator::getAnimationCount) |
| 1742 |
.function("getAnimationDuration", &Animator::getAnimationDuration) |
| 1743 |
.function("getAnimationName", EMBIND_LAMBDA(std::string, (Animator* self, size_t index), { |
| 1744 |
return std::string(self->getAnimationName(index)); |
| 1745 |
}), allow_raw_pointers()); |
| 1746 |
|
| 1747 |
class_<FilamentAsset>("gltfio$FilamentAsset") |
| 1748 |
.function("_getEntities", EMBIND_LAMBDA(EntityVector, (FilamentAsset* self), { |
| 1749 |
const utils::Entity* ptr = self->getEntities(); |
| 1750 |
return EntityVector(ptr, ptr + self->getEntityCount()); |
| 1751 |
}), allow_raw_pointers()) |
| 1752 |
|
| 1753 |
.function("_getEntitiesByName", EMBIND_LAMBDA(EntityVector, (FilamentAsset* self, std::string name), { |
| 1754 |
EntityVector result(self->getEntitiesByName(name.c_str(), nullptr, 0)); |
| 1755 |
self->getEntitiesByName(name.c_str(), result.data(), result.size()); |
| 1756 |
return result; |
| 1757 |
}), allow_raw_pointers()) |
| 1758 |
|
| 1759 |
.function("_getEntitiesByPrefix", EMBIND_LAMBDA(EntityVector, (FilamentAsset* self, std::string prefix), { |
| 1760 |
EntityVector result(self->getEntitiesByPrefix(prefix.c_str(), nullptr, 0)); |
| 1761 |
self->getEntitiesByPrefix(prefix.c_str(), result.data(), result.size()); |
| 1762 |
return result; |
| 1763 |
}), allow_raw_pointers()) |
| 1764 |
|
| 1765 |
.function("getFirstEntityByName", EMBIND_LAMBDA(utils::Entity, (FilamentAsset* self, std::string name), { |
| 1766 |
return self->getFirstEntityByName(name.c_str()); |
| 1767 |
}), allow_raw_pointers()) |
| 1768 |
|
| 1769 |
.function("_getLightEntities", EMBIND_LAMBDA(EntityVector, (FilamentAsset* self), { |
| 1770 |
const utils::Entity* ptr = self->getLightEntities(); |
| 1771 |
return EntityVector(ptr, ptr + self->getLightEntityCount()); |
| 1772 |
}), allow_raw_pointers()) |
| 1773 |
|
| 1774 |
.function("_getCameraEntities", EMBIND_LAMBDA(EntityVector, (FilamentAsset* self), { |
| 1775 |
const utils::Entity* ptr = self->getCameraEntities(); |
| 1776 |
return EntityVector(ptr, ptr + self->getCameraEntityCount()); |
| 1777 |
}), allow_raw_pointers()) |
| 1778 |
|
| 1779 |
.function("getRoot", &FilamentAsset::getRoot) |
| 1780 |
|
| 1781 |
.function("popRenderable", &FilamentAsset::popRenderable) |
| 1782 |
|
| 1783 |
.function("getMaterialInstances", EMBIND_LAMBDA(std::vector<const MaterialInstance*>, |
| 1784 |
(FilamentAsset* self), { |
| 1785 |
const filament::MaterialInstance* const* ptr = self->getMaterialInstances(); |
| 1786 |
return std::vector<const MaterialInstance*>(ptr, ptr + self->getMaterialInstanceCount()); |
| 1787 |
}), allow_raw_pointers()) |
| 1788 |
|
| 1789 |
.function("_getAssetInstances", EMBIND_LAMBDA(std::vector<FilamentInstance*>, |
| 1790 |
(FilamentAsset* self), { |
| 1791 |
FilamentInstance** ptr = self->getAssetInstances(); |
| 1792 |
return std::vector<FilamentInstance*>(ptr, ptr + self->getAssetInstanceCount()); |
| 1793 |
}), allow_raw_pointers()) |
| 1794 |
|
| 1795 |
.function("getResourceUris", EMBIND_LAMBDA(std::vector<std::string>, (FilamentAsset* self), { |
| 1796 |
std::vector<std::string> retval; |
| 1797 |
auto uris = self->getResourceUris(); |
| 1798 |
for (size_t i = 0, len = self->getResourceUriCount(); i < len; ++i) { |
| 1799 |
retval.push_back(uris[i]); |
| 1800 |
} |
| 1801 |
return retval; |
| 1802 |
}), allow_raw_pointers()) |
| 1803 |
|
| 1804 |
.function("getBoundingBox", &FilamentAsset::getBoundingBox) |
| 1805 |
.function("getName", EMBIND_LAMBDA(std::string, (FilamentAsset* self, utils::Entity entity), { |
| 1806 |
return std::string(self->getName(entity)); |
| 1807 |
}), allow_raw_pointers()) |
| 1808 |
.function("getAnimator", &FilamentAsset::getAnimator, allow_raw_pointers()) |
| 1809 |
.function("getWireframe", &FilamentAsset::getWireframe) |
| 1810 |
.function("getEngine", &FilamentAsset::getEngine, allow_raw_pointers()) |
| 1811 |
.function("releaseSourceData", &FilamentAsset::releaseSourceData); |
| 1812 |
|
| 1813 |
class_<FilamentInstance>("gltfio$FilamentInstance") |
| 1814 |
.function("getEntities", EMBIND_LAMBDA(EntityVector, (FilamentInstance* self), { |
| 1815 |
const utils::Entity* ptr = self->getEntities(); |
| 1816 |
return EntityVector(ptr, ptr + self->getEntityCount()); |
| 1817 |
}), allow_raw_pointers()) |
| 1818 |
|
| 1819 |
.function("getRoot", &FilamentInstance::getRoot) |
| 1820 |
.function("getAnimator", &FilamentInstance::getAnimator, allow_raw_pointers()); |
| 1821 |
|
| 1822 |
// This little wrapper exists to get around RTTI requirements in embind. |
| 1823 |
struct UbershaderLoader { |
| 1824 |
MaterialProvider* provider; |
| 1825 |
void destroyMaterials() { provider->destroyMaterials(); } |
| 1826 |
}; |
| 1827 |
|
| 1828 |
class_<UbershaderLoader>("gltfio$UbershaderLoader") |
| 1829 |
.constructor(EMBIND_LAMBDA(UbershaderLoader, (Engine* engine), { |
| 1830 |
return UbershaderLoader { createUbershaderLoader(engine) }; |
| 1831 |
})) |
| 1832 |
.function("destroyMaterials", &UbershaderLoader::destroyMaterials); |
| 1833 |
|
| 1834 |
class_<AssetLoader>("gltfio$AssetLoader") |
| 1835 |
|
| 1836 |
.constructor(EMBIND_LAMBDA(AssetLoader*, (Engine* engine, UbershaderLoader materials), { |
| 1837 |
auto names = new utils::NameComponentManager(utils::EntityManager::get()); |
| 1838 |
return AssetLoader::create({ engine, materials.provider, names }); |
| 1839 |
}), allow_raw_pointers()) |
| 1840 |
|
| 1841 |
/// createAssetFromJson ::method:: |
| 1842 |
/// buffer ::argument:: asset string, or Uint8Array, or [Buffer] |
| 1843 |
/// ::retval:: an instance of [FilamentAsset] |
| 1844 |
.function("_createAssetFromJson", EMBIND_LAMBDA(FilamentAsset*, |
| 1845 |
(AssetLoader* self, BufferDescriptor buffer), { |
| 1846 |
return self->createAssetFromJson((const uint8_t*) buffer.bd->buffer, buffer.bd->size); |
| 1847 |
}), allow_raw_pointers()) |
| 1848 |
|
| 1849 |
/// createAssetFromBinary ::method:: |
| 1850 |
/// buffer ::argument:: asset string, or Uint8Array, or [Buffer] |
| 1851 |
/// ::retval:: an instance of [FilamentAsset] |
| 1852 |
.function("_createAssetFromBinary", EMBIND_LAMBDA(FilamentAsset*, |
| 1853 |
(AssetLoader* self, BufferDescriptor buffer), { |
| 1854 |
return self->createAssetFromBinary((const uint8_t*) buffer.bd->buffer, buffer.bd->size); |
| 1855 |
}), allow_raw_pointers()) |
| 1856 |
|
| 1857 |
/// createInstancedAsset ::method:: |
| 1858 |
/// buffer ::argument:: asset string, or Uint8Array, or [Buffer] |
| 1859 |
/// ::retval:: an instance of [FilamentAsset] |
| 1860 |
.function("_createInstancedAsset", EMBIND_LAMBDA(FilamentAsset*, |
| 1861 |
(AssetLoader* self, BufferDescriptor buffer, int numInstances), { |
| 1862 |
// Ignore the returned instances, they can be extracted from the asset. |
| 1863 |
std::vector<FilamentInstance*> instances; |
| 1864 |
return self->createInstancedAsset((const uint8_t*) buffer.bd->buffer, |
| 1865 |
buffer.bd->size, instances.data(), numInstances); |
| 1866 |
}), allow_raw_pointers()) |
| 1867 |
|
| 1868 |
// createInstance ::method:: |
| 1869 |
// Adds a new instance to an instanced asset. |
| 1870 |
.function("createInstance", &AssetLoader::createInstance, allow_raw_pointers()) |
| 1871 |
|
| 1872 |
// destroyAsset ::method:: |
| 1873 |
// Destroys the given asset and all of its associated Filament objects. This includes |
| 1874 |
// components, material instances, vertex buffers, index buffers, and textures. |
| 1875 |
// asset ::argument:: the Filament asset created using AssetLoader |
| 1876 |
.function("destroyAsset", &AssetLoader::destroyAsset, allow_raw_pointers()); |
| 1877 |
|
| 1878 |
class_<ResourceLoader>("gltfio$ResourceLoader") |
| 1879 |
.constructor(EMBIND_LAMBDA(ResourceLoader*, (Engine* engine, bool normalizeSkinningWeights, |
| 1880 |
bool recomputeBoundingBoxes), { |
| 1881 |
return new ResourceLoader({ |
| 1882 |
.engine = engine, |
| 1883 |
.gltfPath = nullptr, |
| 1884 |
.normalizeSkinningWeights = normalizeSkinningWeights, |
| 1885 |
.recomputeBoundingBoxes = recomputeBoundingBoxes |
| 1886 |
}); |
| 1887 |
}), allow_raw_pointers()) |
| 1888 |
|
| 1889 |
.function("addResourceData", EMBIND_LAMBDA(void, (ResourceLoader* self, std::string url, |
| 1890 |
BufferDescriptor buffer), { |
| 1891 |
self->addResourceData(url.c_str(), std::move(*buffer.bd)); |
| 1892 |
}), allow_raw_pointers()) |
| 1893 |
|
| 1894 |
.function("hasResourceData", EMBIND_LAMBDA(bool, (ResourceLoader* self, std::string url), { |
| 1895 |
return self->hasResourceData(url.c_str()); |
| 1896 |
}), allow_raw_pointers()) |
| 1897 |
|
| 1898 |
.function("loadResources", EMBIND_LAMBDA(bool, (ResourceLoader* self, FilamentAsset* asset), { |
| 1899 |
return self->loadResources(asset); |
| 1900 |
}), allow_raw_pointers()) |
| 1901 |
|
| 1902 |
.function("asyncBeginLoad", EMBIND_LAMBDA(bool, (ResourceLoader* self, FilamentAsset* asset), { |
| 1903 |
return self->asyncBeginLoad(asset); |
| 1904 |
}), allow_raw_pointers()) |
| 1905 |
|
| 1906 |
.function("asyncGetLoadProgress", &ResourceLoader::asyncGetLoadProgress) |
| 1907 |
.function("asyncUpdateLoad", &ResourceLoader::asyncUpdateLoad); |
| 1908 |
|
| 1909 |
class_<Settings>("Settings"); |
| 1910 |
|
| 1911 |
class_<JsonSerializer>("JsonSerializer") |
| 1912 |
.constructor<>() |
| 1913 |
.function("writeJson", &JsonSerializer::writeJson); |
| 1914 |
|
| 1915 |
class_<SimpleViewer>("SimpleViewer") |
| 1916 |
.constructor<Engine*, Scene*, View*, int>() |
| 1917 |
.function("renderUserInterface", &SimpleViewer::renderUserInterface, allow_raw_pointers()) |
| 1918 |
.function("getSettings", &SimpleViewer::getSettings) |
| 1919 |
.function("mouseEvent", &SimpleViewer::mouseEvent) |
| 1920 |
.function("keyDownEvent", &SimpleViewer::keyDownEvent) |
| 1921 |
.function("keyUpEvent", &SimpleViewer::keyUpEvent) |
| 1922 |
.function("keyPressEvent", &SimpleViewer::keyPressEvent); |
| 1923 |
|
| 1924 |
function("fitIntoUnitCube", EMBIND_LAMBDA(flatmat4, (Aabb box, float zoffset), { |
| 1925 |
return flatmat4 { fitIntoUnitCube(box, zoffset) }; |
| 1926 |
})); |
| 1927 |
|
| 1928 |
function("multiplyMatrices", EMBIND_LAMBDA(flatmat4, (flatmat4 a, flatmat4 b), { |
| 1929 |
return flatmat4 { a.m * b.m }; |
| 1930 |
})); |
| 1931 |
|
| 1932 |
} // EMSCRIPTEN_BINDINGS |
| 1933 |
|
| 1934 |
#pragma clang diagnostic pop |