1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_RENDER_3D_NODE_IMPL_H
17 #define OHOS_RENDER_3D_NODE_IMPL_H
18 #include <meta/interface/intf_object.h>
19 
20 #include "QuatProxy.h"
21 #include "SceneResourceImpl.h"
22 #include "Vec3Proxy.h"
23 class NodeImpl : public SceneResourceImpl {
24 public:
25     static constexpr uint32_t ID = 2;
26     enum NodeType { NODE = 1, GEOMETRY = 2, CAMERA = 3, LIGHT = 4 };
27 
28     static void RegisterEnums(NapiApi::Object exports);
29 
30 protected:
31     static void GetPropertyDescs(BASE_NS::vector<napi_property_descriptor>& props);
32     NodeImpl(NodeType type);
33     virtual ~NodeImpl();
34 
35     void* GetInstanceImpl(uint32_t id);
36     napi_value GetNodeType(NapiApi::FunctionContext<>& fc);
37 
38     napi_value GetPosition(NapiApi::FunctionContext<>& fc);
39     void SetPosition(NapiApi::FunctionContext<NapiApi::Object>& fc);
40 
41     napi_value GetScale(NapiApi::FunctionContext<>& fc);
42     void SetScale(NapiApi::FunctionContext<NapiApi::Object>& fc);
43 
44     napi_value GetRotation(NapiApi::FunctionContext<>& fc);
45     void SetRotation(NapiApi::FunctionContext<NapiApi::Object>& fc);
46 
47     napi_value GetPath(NapiApi::FunctionContext<>& ctx);
48     napi_value GetParent(NapiApi::FunctionContext<>& ctx);
49 
50     napi_value GetNodeByPath(NapiApi::FunctionContext<BASE_NS::string>& ctx);
51 
52     napi_value GetChildContainer(NapiApi::FunctionContext<>& fc); // returns a container object.
53 
54     napi_value GetVisible(NapiApi::FunctionContext<>& ctx);
55     void SetVisible(NapiApi::FunctionContext<bool>& ctx);
56 
57     napi_value GetLayerMask(NapiApi::FunctionContext<>& ctx);
58 
59     napi_value Dispose(NapiApi::FunctionContext<>& ctx);
60 
61     napi_value GetLayerMaskEnabled(NapiApi::FunctionContext<uint32_t>& ctx);
62     napi_value SetLayerMaskEnabled(NapiApi::FunctionContext<uint32_t, bool>& ctx);
63 
64     napi_value GetCount(NapiApi::FunctionContext<>& ctx);
65     napi_value GetChild(NapiApi::FunctionContext<uint32_t>& ctx);
66 
67     napi_value ClearChildren(NapiApi::FunctionContext<>& ctx);
68     napi_value InsertChildAfter(NapiApi::FunctionContext<NapiApi::Object, NapiApi::Object>& ctx);
69     napi_value AppendChild(NapiApi::FunctionContext<NapiApi::Object>& ctx);
70     napi_value RemoveChild(NapiApi::FunctionContext<NapiApi::Object>& ctx);
71     void ResetNativeObj(NapiApi::FunctionContext<>& ctx, NapiApi::Object& obj);
72 
73 private:
74     NodeType type_;
75     BASE_NS::unique_ptr<Vec3Proxy> posProxy_ { nullptr };
76     BASE_NS::unique_ptr<Vec3Proxy> sclProxy_ { nullptr };
77     BASE_NS::unique_ptr<QuatProxy> rotProxy_ { nullptr };
78 };
79 #endif // OHOS_RENDER_3D_NODE_IMPL_H