18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci#include "AnimationJS.h" 168bf80f4bSopenharmony_ci#include "CameraJS.h" 178bf80f4bSopenharmony_ci#include "EnvironmentJS.h" 188bf80f4bSopenharmony_ci#include "GeometryJS.h" 198bf80f4bSopenharmony_ci#include "ImageJS.h" 208bf80f4bSopenharmony_ci#include "LightJS.h" 218bf80f4bSopenharmony_ci#include "MaterialJS.h" 228bf80f4bSopenharmony_ci#include "MeshJS.h" 238bf80f4bSopenharmony_ci#include "NodeJS.h" 248bf80f4bSopenharmony_ci#include "PostProcJS.h" 258bf80f4bSopenharmony_ci#include "SceneJS.h" 268bf80f4bSopenharmony_ci#include "ShaderJS.h" 278bf80f4bSopenharmony_ci#include "SubMeshJS.h" 288bf80f4bSopenharmony_ci#include "ToneMapJS.h" 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_civoid RegisterClasses(napi_env env, napi_value exports) 318bf80f4bSopenharmony_ci{ 328bf80f4bSopenharmony_ci napi_status status; 338bf80f4bSopenharmony_ci napi_value zero; 348bf80f4bSopenharmony_ci napi_value one; 358bf80f4bSopenharmony_ci NapiApi::MyInstanceState* mis; 368bf80f4bSopenharmony_ci napi_get_instance_data(env, (void**)&mis); 378bf80f4bSopenharmony_ci 388bf80f4bSopenharmony_ci status = napi_create_double(env, 0.0, &zero); 398bf80f4bSopenharmony_ci status = napi_create_double(env, 1.0, &one); 408bf80f4bSopenharmony_ci 418bf80f4bSopenharmony_ci // Declare color class 428bf80f4bSopenharmony_ci { 438bf80f4bSopenharmony_ci /// Color 448bf80f4bSopenharmony_ci auto colorCtor = [](napi_env e, napi_callback_info c) -> napi_value { return {}; }; 458bf80f4bSopenharmony_ci 468bf80f4bSopenharmony_ci // clang-format off 478bf80f4bSopenharmony_ci napi_property_descriptor desc4[] = { 488bf80f4bSopenharmony_ci {"r", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 498bf80f4bSopenharmony_ci {"g", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 508bf80f4bSopenharmony_ci {"b", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 518bf80f4bSopenharmony_ci {"a", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr} 528bf80f4bSopenharmony_ci }; 538bf80f4bSopenharmony_ci // clang-format on 548bf80f4bSopenharmony_ci napi_value color_class = nullptr; 558bf80f4bSopenharmony_ci status = napi_define_class( 568bf80f4bSopenharmony_ci env, "Color", NAPI_AUTO_LENGTH, colorCtor, nullptr, BASE_NS::countof(desc4), desc4, &color_class); 578bf80f4bSopenharmony_ci mis->StoreCtor("Color", color_class); 588bf80f4bSopenharmony_ci } 598bf80f4bSopenharmony_ci // Declare math classes.. "simply" for now. 608bf80f4bSopenharmony_ci { 618bf80f4bSopenharmony_ci /// Vec 628bf80f4bSopenharmony_ci auto vec3Ctor = [](napi_env e, napi_callback_info c) -> napi_value { return {}; }; 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ci // clang-format off 658bf80f4bSopenharmony_ci napi_property_descriptor desc3[] = { 668bf80f4bSopenharmony_ci {"x", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 678bf80f4bSopenharmony_ci {"y", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 688bf80f4bSopenharmony_ci {"z", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr} 698bf80f4bSopenharmony_ci }; 708bf80f4bSopenharmony_ci // clang-format on 718bf80f4bSopenharmony_ci napi_value vec3_class = nullptr; 728bf80f4bSopenharmony_ci status = napi_define_class( 738bf80f4bSopenharmony_ci env, "Vec3", NAPI_AUTO_LENGTH, vec3Ctor, nullptr, BASE_NS::countof(desc3), desc3, &vec3_class); 748bf80f4bSopenharmony_ci mis->StoreCtor("Vec3", vec3_class); 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci /// Vec4 778bf80f4bSopenharmony_ci auto vec4Ctor = [](napi_env e, napi_callback_info c) -> napi_value { return {}; }; 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ci // clang-format off 808bf80f4bSopenharmony_ci napi_property_descriptor desc4[] = { 818bf80f4bSopenharmony_ci {"x", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 828bf80f4bSopenharmony_ci {"y", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 838bf80f4bSopenharmony_ci {"z", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 848bf80f4bSopenharmony_ci {"w", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr} 858bf80f4bSopenharmony_ci }; 868bf80f4bSopenharmony_ci // clang-format on 878bf80f4bSopenharmony_ci napi_value vec4_class = nullptr; 888bf80f4bSopenharmony_ci status = napi_define_class( 898bf80f4bSopenharmony_ci env, "Vec4", NAPI_AUTO_LENGTH, vec4Ctor, nullptr, BASE_NS::countof(desc4), desc4, &vec4_class); 908bf80f4bSopenharmony_ci mis->StoreCtor("Vec4", vec4_class); 918bf80f4bSopenharmony_ci 928bf80f4bSopenharmony_ci /// Quaternion 938bf80f4bSopenharmony_ci auto QuatCtor = [](napi_env e, napi_callback_info c) -> napi_value { return {}; }; 948bf80f4bSopenharmony_ci 958bf80f4bSopenharmony_ci // clang-format off 968bf80f4bSopenharmony_ci napi_property_descriptor qdesc[] = { 978bf80f4bSopenharmony_ci {"x", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 988bf80f4bSopenharmony_ci {"y", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 998bf80f4bSopenharmony_ci {"z", nullptr, nullptr, nullptr, nullptr, zero, napi_default_jsproperty, nullptr}, 1008bf80f4bSopenharmony_ci {"w", nullptr, nullptr, nullptr, nullptr, one, napi_default_jsproperty, nullptr} 1018bf80f4bSopenharmony_ci }; 1028bf80f4bSopenharmony_ci // clang-format on 1038bf80f4bSopenharmony_ci napi_value quaternion_class = nullptr; 1048bf80f4bSopenharmony_ci status = napi_define_class( 1058bf80f4bSopenharmony_ci env, "Quaternion", NAPI_AUTO_LENGTH, QuatCtor, nullptr, BASE_NS::countof(qdesc), qdesc, &quaternion_class); 1068bf80f4bSopenharmony_ci mis->StoreCtor("Quaternion", quaternion_class); 1078bf80f4bSopenharmony_ci } 1088bf80f4bSopenharmony_ci 1098bf80f4bSopenharmony_ci napi_value scene3dNS = exports; 1108bf80f4bSopenharmony_ci SceneJS::Init(env, scene3dNS); 1118bf80f4bSopenharmony_ci NodeJS::Init(env, scene3dNS); 1128bf80f4bSopenharmony_ci CameraJS::Init(env, scene3dNS); 1138bf80f4bSopenharmony_ci EnvironmentJS::Init(env, scene3dNS); 1148bf80f4bSopenharmony_ci PointLightJS::Init(env, scene3dNS); 1158bf80f4bSopenharmony_ci DirectionalLightJS::Init(env, scene3dNS); 1168bf80f4bSopenharmony_ci SpotLightJS::Init(env, scene3dNS); 1178bf80f4bSopenharmony_ci GeometryJS::Init(env, scene3dNS); 1188bf80f4bSopenharmony_ci MeshJS::Init(env, scene3dNS); 1198bf80f4bSopenharmony_ci SubMeshJS::Init(env, scene3dNS); 1208bf80f4bSopenharmony_ci ShaderMaterialJS::Init(env, scene3dNS); 1218bf80f4bSopenharmony_ci ImageJS::Init(env, scene3dNS); 1228bf80f4bSopenharmony_ci PostProcJS::Init(env, scene3dNS); 1238bf80f4bSopenharmony_ci ToneMapJS::Init(env, scene3dNS); 1248bf80f4bSopenharmony_ci ShaderJS::Init(env, scene3dNS); 1258bf80f4bSopenharmony_ci AnimationJS::Init(env, scene3dNS); 1268bf80f4bSopenharmony_ci 1278bf80f4bSopenharmony_ci BaseLight::RegisterEnums({ env, scene3dNS }); 1288bf80f4bSopenharmony_ci NodeImpl::RegisterEnums({ env, scene3dNS }); 1298bf80f4bSopenharmony_ci SceneResourceImpl::RegisterEnums({ env, scene3dNS }); 1308bf80f4bSopenharmony_ci}