From 90fe9ffe46feeadbbda37b4310c4f46f8ce64ab8 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Sun, 12 Apr 2026 22:49:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Reander=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/CMakeLists.txt | 5 +- .../src/main/cpp/NativeEGLOCCT/NativeMgr.cpp | 7 +- .../main/cpp/NativeEGLOCCT/OCCTMgr/Render.cpp | 66 +++++++++---------- .../main/cpp/NativeEGLOCCT/OCCTMgr/Render.h | 16 ++--- .../cpp/NativeEGLOCCT/V3d/V3dCamera/README.md | 4 ++ .../V3dCa.cpp => V3dCamera/V3dCamera.cpp} | 37 +++++++++-- .../{V3dCa/V3dCa.h => V3dCamera/V3dCamera.h} | 10 +-- .../cpp/NativeEGLOCCT/V3d/V3dView/V3dView.cpp | 22 +------ .../cpp/NativeEGLOCCT/V3d/V3dView/V3dView.h | 2 +- 9 files changed, 92 insertions(+), 77 deletions(-) create mode 100644 entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/README.md rename entry/src/main/cpp/NativeEGLOCCT/V3d/{V3dCa/V3dCa.cpp => V3dCamera/V3dCamera.cpp} (72%) rename entry/src/main/cpp/NativeEGLOCCT/V3d/{V3dCa/V3dCa.h => V3dCamera/V3dCamera.h} (75%) diff --git a/entry/src/main/cpp/CMakeLists.txt b/entry/src/main/cpp/CMakeLists.txt index 5e6d1790..6efb6869 100644 --- a/entry/src/main/cpp/CMakeLists.txt +++ b/entry/src/main/cpp/CMakeLists.txt @@ -57,11 +57,12 @@ add_library(opencax SHARED NativeEGLOCCT/V3d/V3dCtx/V3dCtx.h NativeEGLOCCT/V3d/V3dView/V3dView.h NativeEGLOCCT/V3d/V3dWin/V3dWin.h - NativeEGLOCCT/V3d/V3dCa/V3dCa.h + NativeEGLOCCT/V3d/V3dCamera/V3dCamera.h NativeEGLOCCT/V3d/V3dDrawer/V3dDrawer.h NativeEGLOCCT/V3d/V3dTri/V3dTri.h NativeEGLOCCT/V3d/V3dTri/V3dWCSTri.h NativeEGLOCCT/V3d/V3dTri/V3dTriCube.h + # Cpp Src NativeEGLOCCT/EGLMgr/EGLCore.cpp NativeEGLOCCT/EGLMgr/EGLSubCore.cpp @@ -73,7 +74,7 @@ add_library(opencax SHARED NativeEGLOCCT/V3d/V3dViewer/V3dViewer.cpp NativeEGLOCCT/V3d/V3dCtx/V3dCtx.cpp NativeEGLOCCT/V3d/V3dView/V3dView.cpp - NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp + NativeEGLOCCT/V3d/V3dCamera/V3dCamera.cpp NativeEGLOCCT/V3d/V3dWin/V3dWin.cpp NativeEGLOCCT/V3d/V3dDrawer/V3dDrawer.cpp NativeEGLOCCT/V3d/V3dTri/V3dTri.cpp diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp index 695b91a1..0f86684a 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp @@ -193,7 +193,7 @@ void NativeMgr::OnMouseEvent(OH_NativeXComponent *comp, void *win) { return; } //Test Mouse MIDDLE_BUTTON Long Press - //HILOG_WARN(NATIVE_TAG, "ExtraMouseEventInfo:%{public}s",extra); + HILOG_WARN(NATIVE_TAG, "ExtraMouseEventInfo:%{public}d",extra); std::lock_guard lock(mapMutex); //通过时间戳判断事件唯一性.保证单一时间戳只触发一次事件 if(mouseEvent.timestamp==NativeMgr::timestamp){ @@ -214,7 +214,8 @@ void NativeMgr::OnMouseEvent(OH_NativeXComponent *comp, void *win) { HILOG_INFO(NATIVE_TAG, "ALLAction:%{public}d",mouseEvent.action); HILOG_INFO(NATIVE_TAG, "ALLTimestamp:%{public}d",mouseEvent.timestamp); } - + //鼠标滚轮缩放实现 + //以下代码为采用按住鼠标右键不放进行Move改变Carmera的旋转视角 //旋转视角分为三种模式: //自由模式.基于世界坐标系0,0,0 @@ -345,7 +346,7 @@ ArkUI_NodeHandle CreateNodeHandle(void* userData) { // 注册XComponent回调函数 OH_NativeXComponent_RegisterCallback(nativeXComponent, &NativeMgr::xSurfaceTouchEventCallBack); //注册XComponent组件鼠标回调事件 - //OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &NativeMgr::xMouseEventCallBack); + OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &NativeMgr::xMouseEventCallBack); // nodeAPI->registerNodeEvent(xc, NODE_ON_MOUSE, 1, &xc); // nodeAPI->registerNodeEvent(xc, NODE_ON_AXIS, 1, &xc); // nodeAPI->addNodeEventReceiver(xc, [](ArkUI_NodeEvent *event) { diff --git a/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.cpp b/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.cpp index 53d9d3b5..a7b3b4c4 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.cpp @@ -15,13 +15,13 @@ width(0), height(0), v3dTri(new V3dTri), v3dTriCube(new V3dTriCube), -v3dcr(new V3dCa), -v3dctx(new V3dCtx), -v3dogd(new V3dOGD), -v3dview(new V3dView), -v3ddrawer(new V3dDrawer), -v3dviewer(new V3dViewer), -v3dwin(new V3dWin) +v3dCamera(new V3dCamera), +v3dCtx(new V3dCtx), +v3dOgd(new V3dOGD), +v3dView(new V3dView), +v3dDrawer(new V3dDrawer), +v3dViewer(new V3dViewer), +v3dWin(new V3dWin) { width = w; height = h; @@ -31,58 +31,58 @@ Render::~Render() { shapes_.clear(); } bool Render::init(EGLDisplay eglDisp,EGLContext ctx,EGLConfig eglConfig) { //初始化OpenGL - if (!v3dogd->InitV3dOGD(eglDisp,ctx,eglConfig)) { + if (!v3dOgd->InitV3dOGD(eglDisp,ctx,eglConfig)) { HILOG_ERROR(NATIVE_TAG, "Init GraphicDriver Fail!"); return false; } //初始化视口管理 - if (!v3dviewer->InitV3dViewer(v3dogd->graphicDriver)) { + if (!v3dViewer->InitV3dViewer(v3dOgd->graphicDriver)) { HILOG_ERROR(NATIVE_TAG, "Init Viewer Fail!"); return false; } //初始化OCCT内部上下文 - if (!v3dctx->InitV3dCtx(v3dviewer->viewer)) { + if (!v3dCtx->InitV3dCtx(v3dViewer->viewer)) { HILOG_ERROR(NATIVE_TAG, "Init Ctx Fail!"); return false; }else{ //初始化OCCT上下文的Drawer(全局属性设置) - v3ddrawer->InitV3dAllAspect(v3dctx->ctx); + v3dDrawer->InitV3dAllAspect(v3dCtx->ctx); } //初始化绑定Window - if (!v3dwin->InitV3dWin(width, height)) { + if (!v3dWin->InitV3dWin(width, height)) { HILOG_ERROR(NATIVE_TAG, "Init Window Fail!"); return false; } //初始化视图 - if (!v3dview->InitV3dView(v3dviewer->viewer,ctx,v3dwin->win)) { + if (!v3dView->InitV3dView(v3dViewer->viewer,ctx,v3dWin->win)) { HILOG_ERROR(NATIVE_TAG, "Init View Fail!"); return false; } else { - v3dview->InitViewOption(); + v3dView->InitViewOption(); } - if (!v3dcr->InitV3dCa(v3dview->view)) { + if (!v3dCamera->InitV3dCamera(v3dView->view)) { HILOG_ERROR(NATIVE_TAG, "Init Camera Fail!"); return false; } //初始化世界坐标系 - if (!v3dTri->InitV3dTri(v3dctx->ctx)) { + if (!v3dTri->InitV3dTri(v3dCtx->ctx)) { HILOG_ERROR(NATIVE_TAG, "Init AXIS Fail!"); return false; } //初始化正方体视角切换指示器 - if (!v3dTriCube->InitV3dTriCube(v3dctx->ctx)) { + if (!v3dTriCube->InitV3dTriCube(v3dCtx->ctx)) { HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!"); return false; } //InitDevText(); - v3dview->ResetView(); + v3dView->ResetView(); return true; } bool Render::loadModel(const std::string &filePath) { // 清除现有模型 for (auto &shape : shapes_) { - v3dctx->ctx->Remove(shape, false); + v3dCtx->ctx->Remove(shape, false); } shapes_.clear(); @@ -120,14 +120,14 @@ bool Render::loadModel(const std::string &filePath) { // 设置材质 Handle(Prs3d_Drawer) drawer = aisShape->Attributes(); drawer->SetFaceBoundaryDraw(true); - drawer->SetWireAspect(v3ddrawer->v3d_LineAspect); - drawer->SetShadingAspect(v3ddrawer->v3d_ShadingAspect); - v3dctx->ctx->Display(aisShape, true); + drawer->SetWireAspect(v3dDrawer->v3d_LineAspect); + drawer->SetShadingAspect(v3dDrawer->v3d_ShadingAspect); + v3dCtx->ctx->Display(aisShape, true); shapes_.push_back(aisShape); } } - v3dview->view->ZFitAll(); - v3dview->ResetView(); + v3dView->view->ZFitAll(); + v3dView->ResetView(); OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadModel", "Successfully loaded STEP file with %{public}d shapes", numShapes); return true; @@ -140,28 +140,28 @@ void Render::setTranslation(float tx, float ty) { } void Render::render() { - if (v3dview->view.IsNull()) { + if (v3dView->view.IsNull()) { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render", "View Is Null"); return; } - v3dview->MustBeResized(); - v3dview->Redraw(); + v3dView->MustBeResized(); + v3dView->Redraw(); } void Render::resize(int w, int h) { HILOG_ERROR(NATIVE_TAG, "InPut Size:%{public}d,%{public}d", w, h); - v3dwin->Resize(w, h); + v3dWin->Resize(w, h); } -void Render::setRotation(float xAngle, float yAngle) { v3dcr->SetRotation(xAngle, yAngle); } +void Render::setRotation(float xAngle, float yAngle) { v3dCamera->SetRotation(xAngle, yAngle); } void Render::setZoomLevel(float zoom) { v3dTri->SetZoomLevel(std::max(0.1f, std::min(zoom, 5.0f))); // 限制缩放范围 } -void Render::setClearColor(float r, float g, float b, float a) { v3dview->SetClearColor(r, g, b, a); } -void Render::resetView() { v3dview->ResetView(); } +void Render::setClearColor(float r, float g, float b, float a) { v3dView->SetClearColor(r, g, b, a); } +void Render::resetView() { v3dView->ResetView(); } void Render::SwitchView(std::string str) { - v3dview->SwitchView(str); + v3dCamera->SwitchView(str); } void Render::InitDevText(){ Handle(AIS_TextLabel) aTextLabel = new AIS_TextLabel(); @@ -169,7 +169,7 @@ void Render::InitDevText(){ aTextLabel->SetText(chinese_array); gp_Pnt position(0-(width/3), 0-(height/3), 0.0); // 例如,在原点 aTextLabel->SetPosition(position); - v3dctx->ctx->Display(aTextLabel, Standard_True); + v3dCtx->ctx->Display(aTextLabel, Standard_True); HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->FontName().ToCString()); HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->Attributes()->TextAspect()->Aspect()->Font().ToCString()); } diff --git a/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.h b/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.h index 59907fc6..079ad0b1 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.h +++ b/entry/src/main/cpp/NativeEGLOCCT/OCCTMgr/Render.h @@ -16,7 +16,7 @@ #include "../V3d/V3dTri/V3dTri.h" #include "../V3d/V3dTri/V3dTriCube.h" -#include "../V3d/V3dCa/V3dCa.h" +#include "../V3d/V3dCamera/V3dCamera.h" #include "../V3d/V3dCtx/V3dCtx.h" #include "../V3d/V3dOGD/V3dOGD.h" #include "../V3d/V3dWin/V3dWin.h" @@ -49,13 +49,13 @@ private: int height; V3dTri* v3dTri; V3dTriCube* v3dTriCube; - V3dCa* v3dcr; - V3dCtx* v3dctx; - V3dOGD* v3dogd; - V3dDrawer* v3ddrawer; - V3dView* v3dview; - V3dViewer* v3dviewer; - V3dWin* v3dwin; + V3dCamera* v3dCamera; + V3dCtx* v3dCtx; + V3dOGD* v3dOgd; + V3dDrawer* v3dDrawer; + V3dView* v3dView; + V3dViewer* v3dViewer; + V3dWin* v3dWin; std::vector shapes_; }; } // namespace NativeRender diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/README.md b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/README.md new file mode 100644 index 00000000..49f59d92 --- /dev/null +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/README.md @@ -0,0 +1,4 @@ +V3dCamera 为相机主类型,包含相机对象,后期可以扩展多相机切换
+V3dAnimCamera为相机运动动画对象,可以执行多种相机动画,包括相机移动,旋转等
+ + diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.cpp similarity index 72% rename from entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp rename to entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.cpp index 0df66d92..e136db92 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.cpp @@ -4,7 +4,7 @@ // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, // please include "napi/native_api.h". -#include "V3dCa.h" +#include "V3dCamera.h" #ifndef NATIVE_TAG #define NATIVE_TAG "CAMERA" @@ -12,10 +12,15 @@ namespace NativeOpenCAX { -V3dCa::V3dCa() : camera(nullptr) {} -V3dCa::~V3dCa() {} -bool V3dCa::InitV3dCa(Handle(V3d_View)& view) { +V3dCamera::V3dCamera() : +camera(nullptr) +{ + +} +V3dCamera::~V3dCamera() {} +bool V3dCamera::InitV3dCamera(Handle(V3d_View)& _view) { try { + view=_view; camera = new Graphic3d_Camera; // 将角度转换为弧度并计算对应的缩放因子 camera->SetFOVy(45.0); @@ -30,7 +35,29 @@ bool V3dCa::InitV3dCa(Handle(V3d_View)& view) { return false; } } -void V3dCa::SetRotation(float xAngle, float yAngle) { +//切换视图 +void V3dCamera::SwitchView(std::string nView) { + V3d_TypeOfOrientation tV3d; + if (nView == "CMD_VIEW_FRONT") { + tV3d = V3d_Yneg; + } else if (nView == "CMD_VIEW_TOP") { + tV3d = V3d_Zpos; + } else if (nView == "CMD_VIEW_LEFT_SIDE") { + tV3d = V3d_Xneg; + } else if (nView == "CMD_VIEW_RIGHT_SIDE") { + tV3d = V3d_Xpos; + } else if (nView == "CMD_VIEW_BOTTOM") { + tV3d = V3d_Zneg; + } else if (nView == "CMD_VIEW_REAR") { + tV3d = V3d_Ypos; + } else if (nView == "CMD_VIEW_ISO") { + tV3d = V3d_XposYnegZpos; + } else if (nView == "CMD_VIEW_DIM") { + tV3d = V3d_XposYposZpos; + } + view->SetProj(tV3d); +} +void V3dCamera::SetRotation(float xAngle, float yAngle) { gp_Pnt currentEye = camera->Eye(); gp_Pnt currentCenter = camera->Center(); gp_Dir currentUp = camera->Up(); diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.h b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.h similarity index 75% rename from entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.h rename to entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.h index 2a0c28f1..649194ef 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.h +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCamera/V3dCamera.h @@ -12,14 +12,16 @@ #include namespace NativeOpenCAX { -class V3dCa{ +class V3dCamera{ public: - V3dCa(); - ~V3dCa(); - bool InitV3dCa(Handle(V3d_View)& view); + V3dCamera(); + ~V3dCamera(); + bool InitV3dCamera(Handle(V3d_View)& view); + void SwitchView(std::string view); void SetRotation(float xAngle, float yAngle); public: Handle(Graphic3d_Camera) camera; + Handle(V3d_View) view; }; } // namespace NativeOpenCAX diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.cpp b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.cpp index a1fd245a..065580e6 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.cpp @@ -76,25 +76,5 @@ void V3dView::ResetView() { } } -void V3dView::SwitchView(std::string nView) { - V3d_TypeOfOrientation tV3d; - if (nView == "CMD_VIEW_FRONT") { - tV3d = V3d_Yneg; - } else if (nView == "CMD_VIEW_TOP") { - tV3d = V3d_Zpos; - } else if (nView == "CMD_VIEW_LEFT_SIDE") { - tV3d = V3d_Xneg; - } else if (nView == "CMD_VIEW_RIGHT_SIDE") { - tV3d = V3d_Xpos; - } else if (nView == "CMD_VIEW_BOTTOM") { - tV3d = V3d_Zneg; - } else if (nView == "CMD_VIEW_REAR") { - tV3d = V3d_Ypos; - } else if (nView == "CMD_VIEW_ISO") { - tV3d = V3d_XposYnegZpos; - } else if (nView == "CMD_VIEW_DIM") { - tV3d = V3d_XposYposZpos; - } - view->SetProj(tV3d); -} + } \ No newline at end of file diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.h b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.h index 16e37704..19ceebff 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.h +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dView/V3dView.h @@ -26,7 +26,7 @@ public: void MustBeResized(); void Redraw(); void ResetView(); - void SwitchView(std::string view); + public: Handle(V3d_View) view; Quantity_Color clearColor;