// // Created on 2026/3/6. // // Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, // please include "napi/native_api.h". #include "V3dView.h" #include "Quantity_NameOfColor.hxx" #include "V3d_TypeOfAxe.hxx" #include "V3d_TypeOfVisualization.hxx" #ifndef NATIVE_TAG #define NATIVE_TAG "VIEW" #endif namespace NativeOpenCAX { V3dView::V3dView() : view(nullptr) {} V3dView::~V3dView() {} bool V3dView::InitV3dView(Handle(V3d_Viewer) & viewer,EGLContext ctx,Handle(Aspect_NeutralWindow)& win) { try { view = viewer->CreateView(); view->SetWindow(win, ctx); HILOG_INFO(NATIVE_TAG, "InitView Done"); return true; } catch (std::exception &e) { HILOG_INFO(NATIVE_TAG, "InitView Fail:%{public}d", e.what()); return false; } } void V3dView::InitViewOption() { // 设置渲染参数 view->SetImmediateUpdate(false); view->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION; view->ChangeRenderingParams().IsShadowEnabled = Standard_False; view->ChangeRenderingParams().IsReflectionEnabled = Standard_False; //抗锯齿开启后字体无法显示 //view->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True; //view->ChangeRenderingParams().Resolution = 2; // 设置背景渐变 view->SetBgGradientColors(Quantity_Color(Quantity_NOC_GRAY), Quantity_Color(Quantity_NOC_BLACK), Aspect_GFM_VER, // 垂直渐变 false); // 设置默认相机位置 view->SetProj(V3d_XposYnegZpos); view->FitAll(0.05, false); // 可选:显示坐标轴 view->ZBufferTriedronSetup(); // 调整相机视角 view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Perspective); view->SetBackgroundColor(Quantity_NOC_GRAY90); //左下角默认坐标系 view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_ANTIQUEWHITE, 0.3, V3d_ZBUFFER); view->Trihedron(false)->LabelAspect(V3d_Y)->SetHeight(50); view->Trihedron(false)->LabelAspect(V3d_X)->SetHeight(50); view->Trihedron(false)->LabelAspect(V3d_Z)->SetHeight(50); view->SetBackgroundColor(Quantity_NOC_GRAY90); } void V3dView::SetClearColor(float r, float g, float b, float a) { clearColor = Quantity_Color(r, g, b, Quantity_TOC_RGB); if (!view.IsNull()) { view->SetBackgroundColor(clearColor); } } void V3dView::MustBeResized() { view->MustBeResized(); } void V3dView::Redraw() { view->Redraw(); } void V3dView::ResetView() { if (!view.IsNull()) { view->SetProj(V3d_XposYnegZpos); view->FitAll(0.05, false); } } }