• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NODE_IMPL_H
17 #define NODE_IMPL_H
18 #include <meta/interface/intf_object.h>
19 #include <scene/interface/intf_node.h>
20 
21 #include "QuatProxy.h"
22 #include "SceneResourceImpl.h"
23 #include "Vec3Proxy.h"
24 class NodeImpl : public SceneResourceImpl {
25 public:
26     static constexpr uint32_t ID = 2;
27     enum NodeType { NODE = 1, GEOMETRY = 2, CAMERA = 3, LIGHT = 4, TEXT = 5 };
28 
29     static void RegisterEnums(NapiApi::Object exports);
30 
31     bool IsAttached();
32     void Attached(bool attached);
33 
34 protected:
35     static void GetPropertyDescs(BASE_NS::vector<napi_property_descriptor>& props);
36     NodeImpl(NodeType type);
37     virtual ~NodeImpl();
38 
39     void* GetInstanceImpl(uint32_t id);
40     napi_value GetNodeType(NapiApi::FunctionContext<>& fc);
41 
42     napi_value GetNodeName(NapiApi::FunctionContext<>& fc);
43     void SetNodeName(NapiApi::FunctionContext<BASE_NS::string>& fc);
44 
45     napi_value GetPosition(NapiApi::FunctionContext<>& fc);
46     void SetPosition(NapiApi::FunctionContext<NapiApi::Object>& fc);
47 
48     napi_value GetScale(NapiApi::FunctionContext<>& fc);
49     void SetScale(NapiApi::FunctionContext<NapiApi::Object>& fc);
50 
51     napi_value GetRotation(NapiApi::FunctionContext<>& fc);
52     void SetRotation(NapiApi::FunctionContext<NapiApi::Object>& fc);
53 
54     napi_value GetPath(NapiApi::FunctionContext<>& ctx);
55     napi_value GetParent(NapiApi::FunctionContext<>& ctx);
56 
57     napi_value GetNodeByPath(NapiApi::FunctionContext<BASE_NS::string>& ctx);
58     napi_value GetComponent(NapiApi::FunctionContext<BASE_NS::string>& ctx);
59 
60     napi_value GetChildContainer(NapiApi::FunctionContext<>& fc); // returns a container object.
61 
62     napi_value GetVisible(NapiApi::FunctionContext<>& ctx);
63     void SetVisible(NapiApi::FunctionContext<bool>& ctx);
64 
65     napi_value GetLayerMask(NapiApi::FunctionContext<>& ctx);
66 
67     napi_value Dispose(NapiApi::FunctionContext<>& ctx);
68 
69     napi_value GetLayerMaskEnabled(NapiApi::FunctionContext<uint32_t>& ctx);
70     napi_value SetLayerMaskEnabled(NapiApi::FunctionContext<uint32_t, bool>& ctx);
71 
72     napi_value GetCount(NapiApi::FunctionContext<>& ctx);
73     napi_value GetChild(NapiApi::FunctionContext<uint32_t>& ctx);
74 
75     napi_value ClearChildren(NapiApi::FunctionContext<>& ctx);
76     napi_value InsertChildAfter(NapiApi::FunctionContext<NapiApi::Object, NapiApi::Object>& ctx);
77     napi_value AppendChild(NapiApi::FunctionContext<NapiApi::Object>& ctx);
78     napi_value RemoveChild(NapiApi::FunctionContext<NapiApi::Object>& ctx);
79 
80 private:
81     bool attached_ = false;
82     NodeType type_;
83     BASE_NS::unique_ptr<Vec3Proxy> posProxy_ { nullptr };
84     BASE_NS::unique_ptr<Vec3Proxy> sclProxy_ { nullptr };
85     BASE_NS::unique_ptr<QuatProxy> rotProxy_ { nullptr };
86 };
87 #endif
88