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 NAMED_IMPL_H 17 #define NAMED_IMPL_H 18 #include <napi_api.h> 19 class SceneResourceImpl { 20 public: 21 static constexpr uint32_t ID = 1; 22 enum SceneResourceType { 23 /** 24 * The resource is an Unknow. 25 */ 26 UNKNOWN = 0, 27 /** 28 * The resource is an Node. 29 */ 30 NODE = 1, 31 /** 32 * The resource is an Environment. 33 */ 34 ENVIRONMENT = 2, 35 /** 36 * The resource is a Material. 37 */ 38 MATERIAL = 3, 39 /** 40 * The resource is a Mesh. 41 */ 42 MESH = 4, 43 /** 44 * The resource is an Animation. 45 */ 46 ANIMATION = 5, 47 /** 48 * The resource is a Shader. 49 */ 50 SHADER = 6, 51 52 /** 53 * The resource is a Image. 54 */ 55 IMAGE = 7, 56 /** 57 * The resource is a MeshResource. 58 */ 59 MESH_RESOURCE = 8, 60 }; 61 SceneResourceImpl(SceneResourceType type); 62 virtual ~SceneResourceImpl(); 63 static void RegisterEnums(NapiApi::Object exports); 64 65 void* GetInstanceImpl(uint32_t id); 66 67 protected: 68 static void GetPropertyDescs(BASE_NS::vector<napi_property_descriptor>& props); 69 70 void SetUri(NapiApi::StrongRef uri); 71 napi_value GetObjectType(NapiApi::FunctionContext<>& ctx); 72 napi_value GetName(NapiApi::FunctionContext<>& ctx); 73 void SetName(NapiApi::FunctionContext<BASE_NS::string>& ctx); 74 napi_value GetUri(NapiApi::FunctionContext<>& ctx); 75 napi_value Dispose(NapiApi::FunctionContext<>& ctx); 76 77 NapiApi::WeakRef scene_; 78 NapiApi::StrongRef uri_; 79 80 // returns false if owning scene has been destroyed. 81 bool validateSceneRef(); 82 83 private: 84 SceneResourceType type_; 85 }; 86 #endif 87