/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SubMeshJS.h"
#include
#include
#include
#include
#include
#include
#include "MeshJS.h"
#include "SceneJS.h"
void* SubMeshJS::GetInstanceImpl(uint32_t id)
{
if (id == SubMeshJS::ID)
return this;
// no id will match
return nullptr;
}
void SubMeshJS::DisposeNative(void* scn)
{
if (disposed_) {
return;
}
disposed_ = true;
LOG_V("SubMeshJS::DisposeNative");
if (auto* sceneJS = static_cast(scn)) {
sceneJS->ReleaseStrongDispose(reinterpret_cast(&scene_));
}
aabbMin_.reset();
aabbMax_.reset();
parentMesh_.Reset();
scene_.Reset();
}
void SubMeshJS::Finalize(napi_env env)
{
DisposeNative(scene_.GetObject().GetJsWrapper());
BaseObject::Finalize(env);
}
napi_value SubMeshJS::Dispose(NapiApi::FunctionContext<>& ctx)
{
// Dispose of the native object. (makes the js object invalid)
if (TrueRootObject* instance = ctx.This().GetRoot()) {
// see if we have "scenejs" as ext (prefer one given as argument)
napi_status stat;
SceneJS* ptr { nullptr };
NapiApi::FunctionContext args(ctx);
if (args) {
if (NapiApi::Object obj = args.Arg<0>()) {
if (napi_value ext = obj.Get("SceneJS")) {
stat = napi_get_value_external(ctx.GetEnv(), ext, (void**)&ptr);
}
}
}
if (!ptr) {
ptr = scene_.GetObject().GetJsWrapper();
}
UnsetNativeObject();
instance->DisposeNative(ptr);
}
return ctx.GetUndefined();
}
void SubMeshJS::Init(napi_env env, napi_value exports)
{
BASE_NS::vector node_props;
using namespace NapiApi;
node_props.push_back(GetSetProperty("name"));
node_props.push_back(GetProperty