1 /* 2 * Copyright (C) 2023 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 CORE_UTIL_SCENE_UTIL_H 17 #define CORE_UTIL_SCENE_UTIL_H 18 19 #include <3d/ecs/components/light_component.h> 20 #include <3d/util/intf_scene_util.h> 21 #include <base/containers/string_view.h> 22 #include <base/math/quaternion.h> 23 #include <base/math/vector.h> 24 #include <core/namespace.h> 25 26 CORE3D_BEGIN_NAMESPACE() 27 class IGraphicsContext; 28 29 class SceneUtil : public ISceneUtil { 30 public: 31 explicit SceneUtil(IGraphicsContext& graphicsContext); 32 ~SceneUtil() override = default; 33 34 CORE_NS::Entity CreateCamera(CORE_NS::IEcs& ecs, const BASE_NS::Math::Vec3& position, 35 const BASE_NS::Math::Quat& rotation, float zNear, float zFar, float fovDegrees) const override; 36 void UpdateCameraViewport( 37 CORE_NS::IEcs& ecs, CORE_NS::Entity entity, const BASE_NS::Math::UVec2& renderResolution) const override; 38 void UpdateCameraViewport(CORE_NS::IEcs& ecs, CORE_NS::Entity entity, const BASE_NS::Math::UVec2& renderResolution, 39 bool autoAspect, float fovY, float orthoScale) const override; 40 41 CORE_NS::Entity CreateLight(CORE_NS::IEcs& ecs, const LightComponent& lightComponent, 42 const BASE_NS::Math::Vec3& position, const BASE_NS::Math::Quat& rotation) const override; 43 44 /** Reflection plane object */ 45 struct ReflectionPlane { 46 // Reflection plane entity. 47 CORE_NS::Entity entity; 48 // Reflection plane mesh. 49 CORE_NS::Entity mesh; 50 // Reflection plane material. 51 CORE_NS::Entity material; 52 // Reflection plane color target. 53 CORE_NS::EntityReference colorTarget; 54 // Reflection plane depth target. 55 CORE_NS::EntityReference depthTarget; 56 }; 57 58 void CreateReflectionPlaneComponent(CORE_NS::IEcs& ecs, const CORE_NS::Entity& nodeEntity) override; 59 60 IAnimationPlayback* RetargetSkinAnimation(CORE_NS::IEcs& ecs, CORE_NS::Entity targetEntity, 61 CORE_NS::Entity sourceEntity, CORE_NS::Entity animationEntity) const override; 62 63 void GetDefaultMaterialShaderData(CORE_NS::IEcs& ecs, const ISceneUtil::MaterialShaderInfo& info, 64 MaterialComponent::Shader& materialShader, MaterialComponent::Shader& depthShader) const override; 65 void GetDefaultMaterialShaderData(CORE_NS::IEcs& ecs, const ISceneUtil::MaterialShaderInfo& info, 66 const BASE_NS::string_view renderSlot, MaterialComponent::Shader& shader) const override; 67 68 private: 69 IGraphicsContext& graphicsContext_; 70 }; 71 CORE3D_END_NAMESPACE() 72 73 #endif // CORE_UTIL_SCENE_UTIL_H 74