1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_ADAPTER_WRAPPER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_ADAPTER_WRAPPER_H 18 19 #include <memory> 20 21 #include "custom/shader_input_buffer.h" 22 #include "ohos/texture_layer.h" 23 #include "widget_adapter.h" 24 25 #include "base/geometry/animatable_float.h" 26 #include "base/geometry/ng/offset_t.h" 27 #include "base/geometry/ng/size_t.h" 28 #include "base/geometry/quaternion.h" 29 #include "base/geometry/vec3.h" 30 #include "core/components_ng/pattern/model/model_paint_property.h" 31 #include "core/components_ng/pattern/model/model_touch_handler.h" 32 33 namespace OHOS::Ace::NG { 34 35 struct CameraProperty { 36 Render3D::Position position_; 37 Render3D::Vec3 lookAt_ { 0.0f, 0.0f, 0.0f }; 38 Render3D::Vec3 up_ { 0.0f, 1.0f, 0.0f }; 39 Render3D::Quaternion rotation_ { std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), 40 std::numeric_limits<float>::max(), std::numeric_limits<float>::max() }; 41 float near_ = 0.5f; 42 float far_ = 50.0f; 43 float fov_ = 60.0f; 44 }; 45 46 class ModelAdapterWrapper : public virtual AceType { 47 DECLARE_ACE_TYPE(ModelAdapterWrapper, AceType) 48 public: 49 using PaintFinishCallback = std::function<void()>; 50 51 ModelAdapterWrapper(uint32_t key, Render3D::SurfaceType surfaceType, const std::string& bundleName, 52 const std::string& moduleName); 53 ~ModelAdapterWrapper() override; 54 55 void SetPaintFinishCallback(PaintFinishCallback callback); 56 bool NeedsRepaint(); 57 bool HandleTouchEvent(const TouchEventInfo& info, const RefPtr<ModelPaintProperty>& modelPaintProperty); 58 59 void OnPaint3D(const RefPtr<ModelPaintProperty>& modelPaintProperty); 60 void OnPaintFinish(); 61 void OnRebuildFrame(RefPtr<RenderContext>& context); 62 void OnAttachToFrameNode(const RefPtr<RenderContext>& context); 63 void OnDirtyLayoutWrapperSwap(float offsetX, float offsetY, float width, float height, float scale, 64 bool recreateWindow); 65 void OnDirtyLayoutWrapperSwap(const Render3D::WindowChangeInfo& windowChangeInfo); 66 void OnPaint3DSceneTexture(SkCanvas* skCanvas); 67 void Deinit(); 68 GetSurfaceType()69 OHOS::Render3D::SurfaceType GetSurfaceType() 70 { 71 return surfaceType_; 72 } 73 74 private: 75 void CreateTextureLayer(); 76 void CreateWidgetAdapter(); 77 78 uint32_t GetKey(); 79 void Initialize(); 80 void UnloadSceneAndBackground(); 81 void DrawFrame(); 82 void UpdateCamera(const RefPtr<ModelPaintProperty>& modelPaintProperty); 83 void UpdateLights(const RefPtr<ModelPaintProperty>& modelPaintProperty); 84 void UpdateGLTFAnimations(const RefPtr<ModelPaintProperty>& modelPaintProperty); 85 void UpdateGeometries(const RefPtr<ModelPaintProperty>& modelPaintProperty); 86 void UpdateScene(const RefPtr<ModelPaintProperty>& modelPaintProperty); 87 void UpdateEnviroment(const RefPtr<ModelPaintProperty>& modelPaintProperty); 88 void UpdateCustomRender(const RefPtr<ModelPaintProperty>& modelPaintProperty); 89 void UpdateShaderPath(const RefPtr<ModelPaintProperty>& modelPaintProperty); 90 void UpdateImageTexturePaths(const RefPtr<ModelPaintProperty>& modelPaintProperty); 91 void UpdateShaderInputBuffers(const RefPtr<ModelPaintProperty>& modelPaintProperty); 92 void HandleCameraMove(const Render3D::PointerEvent& event); 93 Render3D::HapInfo SetHapInfo(); 94 95 uint32_t key_ = UINT32_MAX; 96 PaintFinishCallback callback_ = nullptr; 97 bool needsSyncPaint_ = true; 98 bool needsRepaint_ = true; 99 100 std::shared_ptr<Render3D::WidgetAdapter> widgetAdapter_; 101 std::unique_ptr<Render3D::TextureLayer> textureLayer_; 102 RefPtr<ModelTouchHandler> touchHandler_; 103 Render3D::SurfaceType surfaceType_; 104 105 std::string bundleName_; 106 std::string moduleName_; 107 ACE_DISALLOW_COPY_AND_MOVE(ModelAdapterWrapper); 108 }; 109 } // namespace OHOS::Ace::NG 110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_ADAPTER_WRAPPER_H 111