封装Native侧得OCCT类和对象.

归一化视角切换函数和实现.
修复最大化窗口渲染同步失败问题.
增加模型边界线显示
Next Version:
增加线框,隐藏线框,等功能
This commit is contained in:
JackLee 2026-03-23 20:29:18 +08:00
parent 6a4e702dbd
commit 818662eb96
31 changed files with 636 additions and 620 deletions

View File

@ -32,29 +32,29 @@ add_library(opencax SHARED
NativeEGLOCCT/NativeRender.h
NativeEGLOCCT/NativeRenderThread.h
NativeEGLOCCT/NativeManager.h
NativeEGLOCCT/RenderStruct.h
NativeEGLOCCT/Axis/worldAxis.h
NativeEGLOCCT/Axis/localAxis.h
NativeEGLOCCT/Axis/Axis.h
NativeEGLOCCT/OpenGLGraphicDriver/OpenGLGraphicDriver.h
NativeEGLOCCT/TextStyle/TextStyle.h
NativeEGLOCCT/Viewer/Viewer.h
NativeEGLOCCT/Context/Context.h
NativeEGLOCCT/View/View.h
NativeEGLOCCT/window/window.h
NativeEGLOCCT/Camera/Camera.h
# Cpp Src
NativeEGLOCCT/EGLCore.cpp
NativeEGLOCCT/NativeRender.cpp
NativeEGLOCCT/NativeRenderThread.cpp
NativeEGLOCCT/NativeManager.cpp
NativeEGLOCCT/Axis/worldAxis.cpp
NativeEGLOCCT/Axis/localAxis.cpp
NativeEGLOCCT/OpenGLGraphicDriver/OpenGLGraphicDriver.cpp
NativeEGLOCCT/TextStyle/TextStyle.cpp
NativeEGLOCCT/Viewer/Viewer.cpp
NativeEGLOCCT/Context/Context.cpp
NativeEGLOCCT/View/View.cpp
NativeEGLOCCT/Camera/Camera.cpp
napi_init.cpp )
NativeEGLOCCT/Axis/Axis.cpp
NativeEGLOCCT/window/window.cpp
napi_init.cpp
)
#
find_library(EGL-lib EGL)

View File

@ -0,0 +1,91 @@
//
// Created on 2026/3/23.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Axis.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "AXIS"
#endif
namespace NativeOpenCAX {
Axis::Axis() : axisPlacement(nullptr), axisTrihedron(nullptr) { }
Axis::~Axis() {
}
bool Axis::InitAxis(Handle(AIS_InteractiveContext)& context,AXIS_TYPE _axisType) {
axisType = _axisType;
switch (axisType) {
case WORLD_AXIS:
return InitWorldAxis(context);
break;
case LOCAL_AXIS:
return InitLocalAxis(context);
break;
}
}
bool Axis::InitWorldAxis(Handle(AIS_InteractiveContext)& context) {
try {
// 添加世界坐标系(左下角)
axisPlacement = new Geom_Axis2Placement(gp::XOY());
axisTrihedron = new AIS_Trihedron(axisPlacement);
axisTrihedron->SetSize(100.0); // 小一点,作为指示器
axisTrihedron->SetZLayer(Graphic3d_ZLayerId_TopOSD);
axisTrihedron->SetTransformPersistence(new Graphic3d_TransformPers(Graphic3d_TMF_2d, // 2D 模式
Aspect_TOTP_LEFT_LOWER, // 左下角对齐
Graphic3d_Vec2i(100, 100) // 偏移量(像素)
));
axisTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, Quantity_NOC_RED);
axisTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, Quantity_NOC_GREEN);
axisTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, Quantity_NOC_BLUE);
context->Display(axisTrihedron, 0, 0, false);
HILOG_INFO(NATIVE_TAG, "InitWorldAxis Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitWorldAxis Fail:%{public}d",e.what());
return false;
}
}
bool Axis::InitLocalAxis(Handle(AIS_InteractiveContext)& context) {
try {
// 创建场景中心参考坐标系
axisPlacement = new Geom_Axis2Placement(gp::XOY());
axisTrihedron = new AIS_Trihedron(axisPlacement);
axisTrihedron->SetSize(50.0);
axisTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, Quantity_NOC_RED);
axisTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, Quantity_NOC_GREEN);
axisTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, Quantity_NOC_BLUE);
context->Display(axisTrihedron, 0, 0, true);
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Fail:%{public}d",e.what());
return false;
}
}
void Axis::SetRotationX(float rx){
rotationX=rx;
}
void Axis::SetRotationY(float ry){
rotationX=ry;
}
void Axis::SetRotationZ(float rz){
rotationX=rz;
}
void Axis::SetTranslationX(float tx){
translationX=tx;
}
void Axis::SetTranslationY(float ty){
translationX=ty;
}
void Axis::SetTranslationZ(float tz){
translationX=tz;
}
void Axis::SetZoomLevel(float level){
zoomLevel=level;
}
}

View File

@ -0,0 +1,57 @@
//
// Created on 2026/3/23.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef OPENCAX_AXIS_H
#define OPENCAX_AXIS_H
#include "NativeEGLOCCT/common.h"
#include <AIS_Trihedron.hxx>
#include <AIS_InteractiveContext.hxx>
#include <Geom_Axis2Placement.hxx>
namespace NativeOpenCAX {
enum AXIS_TYPE{
WORLD_AXIS,
LOCAL_AXIS
};
class Axis {
public:
Axis();
~Axis();
bool InitAxis(Handle(AIS_InteractiveContext)& context,AXIS_TYPE _axisType);
void SetRotationX(float x);
void SetRotationY(float y);
void SetRotationZ(float z);
void SetTranslationX(float x);
void SetTranslationY(float y);
void SetTranslationZ(float z);
void SetZoomLevel(float level);
private:
bool InitWorldAxis(Handle(AIS_InteractiveContext)& context);
bool InitLocalAxis(Handle(AIS_InteractiveContext)& context);
private:
AXIS_TYPE axisType;
Handle(Geom_Axis2Placement) axisPlacement;
Handle(AIS_Trihedron) axisTrihedron;
private:
//旋转X轴
float rotationX=0.0f;
//旋转Y轴
float rotationY=0.0f;
//旋转Z轴
float rotationZ=0.0f;
//缩放等级
float zoomLevel=1.0f;
//翻转X轴
float translationX=0.0f;
//翻转Y轴
float translationY=0.0f;
//翻转Z轴
float translationZ=0.0f;
};
}
#endif //OPENCAX_AXIS_H

View File

@ -1,32 +0,0 @@
//
// 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 "LocalAxis.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitLocalAxis"
#endif
namespace NativeOpenCAX {
bool InitLocalAxis(RenderOption& opt) {
if (opt.localAxisPlacement.IsNull()) {
// 创建场景中心参考坐标系
opt.localAxisPlacement = new Geom_Axis2Placement(gp::XOY());
opt.localAxis = new AIS_Trihedron(opt.localAxisPlacement);
opt.localAxis->SetSize(50.0);
opt.localAxis->SetDatumPartColor(Prs3d_DP_XAxis,Quantity_NOC_RED);
opt.localAxis->SetDatumPartColor(Prs3d_DP_YAxis,Quantity_NOC_GREEN);
opt.localAxis->SetDatumPartColor(Prs3d_DP_ZAxis,Quantity_NOC_BLUE);
opt.context->Display(opt.localAxis, 0, 0, true);
HILOG_INFO(NATIVE_TAG,"InitLocalAxis Done");
return true;
}
return false;
}
void ChangeLocalAxis() {
}
}

View File

@ -1,15 +0,0 @@
//
// 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".
#ifndef OPENCAX_LOCALAXIS_H
#define OPENCAX_LOCALAXIS_H
#include "../RenderStruct.h"
namespace NativeOpenCAX {
bool InitLocalAxis(RenderOption& opt);
void ChangeLocalAxis();
}
#endif //OPENCAX_LOCALAXIS_H

View File

@ -1,40 +0,0 @@
//
// 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 "WorldAxis.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitWorldAxis"
#endif
namespace NativeOpenCAX {
bool InitWorldAxis(RenderOption& opt) {
if (opt.worldAxisPlacement.IsNull()) {
// 添加世界坐标系(左下角)
opt.worldAxisPlacement = new Geom_Axis2Placement(gp::XOY());
opt.worldAxis = new AIS_Trihedron(opt.worldAxisPlacement);
opt.worldAxis->SetSize(100.0); // 小一点,作为指示器
opt.worldAxis->SetZLayer(Graphic3d_ZLayerId_TopOSD);
opt.worldAxis->SetTransformPersistence(
new Graphic3d_TransformPers(
Graphic3d_TMF_2d, // 2D 模式
Aspect_TOTP_LEFT_LOWER, // 左下角对齐
Graphic3d_Vec2i(100, 100) // 偏移量(像素)
)
);
opt.worldAxis->SetDatumPartColor(Prs3d_DP_XAxis,Quantity_NOC_RED);
opt.worldAxis->SetDatumPartColor(Prs3d_DP_YAxis,Quantity_NOC_GREEN);
opt.worldAxis->SetDatumPartColor(Prs3d_DP_ZAxis,Quantity_NOC_BLUE);
opt.context->Display(opt.worldAxis, 0, 0, false);
HILOG_INFO(NATIVE_TAG,"InitWorldAxis Done");
return true;
}
return false;
}
void ChangeWorldAxis() {
}
}

View File

@ -1,15 +0,0 @@
//
// 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".
#ifndef OPENCAX_WORLDAXIS_H
#define OPENCAX_WORLDAXIS_H
#include "../RenderStruct.h"
#include <Prs3d_DatumParts.hxx>
namespace NativeOpenCAX {
bool InitWorldAxis(RenderOption& opt);
void ChangeWorldAxis();
}
#endif //OPENCAX_WORLDAXIS_H

View File

@ -7,101 +7,68 @@
#include "Camera.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitCamera"
#define NATIVE_TAG "CAMERA"
#endif
namespace NativeOpenCAX {
bool InitCamera(RenderOption &opt) {
if (opt.camera.IsNull()) {
// 设置相机参数
opt.camera = opt.view->Camera();
opt.camera->SetFOVy(45.0); // 使用正确的FOV设置API
opt.camera->SetZRange(1.0, 1000.0);
Camera::Camera() : camera(nullptr) {}
Camera::~Camera() {}
bool Camera::InitCamera(Handle(V3d_View)& view) {
try {
camera = new Graphic3d_Camera;
camera->SetFOVy(30.0);
camera->SetZRange(1.0, 1000.0);
view->SetCamera(camera);
HILOG_INFO(NATIVE_TAG, "InitCamera Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitCamera Fail:%{public}d", e.what());
return false;
}
return false;
}
void Camera::SetRotation(float xAngle, float yAngle) {
gp_Pnt currentEye = camera->Eye();
gp_Pnt currentCenter = camera->Center();
gp_Dir currentUp = camera->Up();
// 计算当前的视线方向和距离
gp_Vec viewDir = currentCenter.XYZ() - currentEye.XYZ();
double distance = viewDir.Magnitude();
gp_Pnt rotationCenter = currentCenter; // 旋转中心设为当前目标点
// 创建旋转增量
gp_Quaternion rotX, rotY;
// 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec)
gp_Vec xRotationAxis = camera->Direction().XYZ().Crossed(currentUp.XYZ()); // 叉积得到X旋转轴
if (xRotationAxis.Magnitude() > gp::Resolution()) { // 防止零向量导致的无效四元数
rotX.SetVectorAndAngle(xRotationAxis, xAngle * M_PI / 180.0);
} else {
rotX.SetIdent(); // 如果叉积为零,则无旋转
}
// 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec)
gp_Vec yRotationAxis = currentUp.XYZ(); // Y旋转轴就是当前的Up方向
if (yRotationAxis.Magnitude() > gp::Resolution()) {
rotY.SetVectorAndAngle(yRotationAxis, yAngle * M_PI / 180.0);
} else {
rotY.SetIdent(); // 如果Up向量无效则无旋转
}
// 组合旋转
gp_Quaternion totalRotation = rotY * rotX;
// 应用旋转到眼睛位置
gp_Vec newViewDir = totalRotation * viewDir.Normalized();
gp_Pnt newEye = rotationCenter.XYZ() - newViewDir.XYZ() * distance;
// 计算新的 Up 方向
gp_Dir newUp = totalRotation * currentUp;
// 设置新相机参数
camera->SetEye(newEye);
camera->SetCenter(rotationCenter);
camera->SetUp(newUp);
HILOG_ERROR(NATIVE_TAG,"Rotation");
}
// 主视图 (Front View)
void FrontView(RenderOption &opt) {
opt.view->SetProj(V3d_XposYposZneg); // 先设置坐标系Y向上是常用选择
opt.view->SetAt(0, 0, 0); // 设置目标点为中心
opt.view->SetEye(0, 0, 1);
opt.view->FitAll();
opt.view->Redraw();
}
// 俯视图 (Top View)
void TopView(RenderOption &opt) {
opt.view->SetProj(V3d_XposYnegZpos);
opt.view->SetAt(0, 0, 0);
opt.view->SetEye(0, -1, 0);
opt.view->FitAll();
opt.view->Redraw();
}
// 左视图 (Left View)
// 观察方向为 -X, Z轴向上
void LeftSideView(RenderOption &opt) {
opt.view->SetProj(V3d_XnegYnegZpos);
opt.view->SetAt(0, 0, 0);
opt.view->SetEye(1, 0, 0); // 从 X 轴正方向向左看
opt.view->FitAll();
opt.view->Redraw();
}
// 右视图 (Right View)
// 观察方向为 +X, Z轴向上
void RightSideView(RenderOption &opt) {
opt.view->SetProj(V3d_XposYnegZpos);
opt.view->SetAt(0, 0, 0);
opt.view->SetEye(-1, 0, 0); // 从 X 轴负方向向右看
opt.view->FitAll();
opt.view->Redraw();
}
// 仰视图 (Bottom View)
// 观察方向为 +Y, Z轴向上
void BottomView(RenderOption &opt) {
opt.view->SetProj(V3d_XposYposZpos);
opt.view->SetAt(0, 0, 0);
opt.view->SetEye(0, 1, 0);
opt.view->FitAll();
opt.view->Redraw();
}
// 后视图 (Back View)
// 观察方向为 +Z, Y轴向上
void RearView(RenderOption &opt) {
opt.view->SetProj(V3d_XnegYposZpos);
opt.view->SetAt(0, 0, 0);
opt.view->SetEye(0, 0, -1); // 从 Z 轴负方向向前看
opt.view->FitAll();
opt.view->Redraw();
}
// 正等轴测图 (Isometric View)
void ISOView(RenderOption &opt) {
opt.view->SetProj(V3d_XposYposZpos); // 先重置一个标准方向作为参考
opt.view->SetAt(0, 0, 0); // 观察目标点
// 经典的等轴测视角,从 (1, 1, 1) 方向看过去
double dist = 1000.0; // 距离,影响缩放
opt.view->SetEye(dist, dist, dist);
// 为了美观,通常还需要将视角调整为框满模型
opt.view->FitAll();
opt.view->Redraw();
}
// 正二等轴测图 (Diametric View)
void DIMView(RenderOption &opt) {
opt.view->SetAt(0, 0, 0);
double dist = 1000.0;
opt.view->SetEye(-dist, -dist, dist * 0.5);
opt.view->FitAll();
opt.view->Redraw();
}
void ChangeCarmera() {}
}
} // namespace NativeOpenCAX

View File

@ -6,21 +6,22 @@
#ifndef OPENCAX_CAMERA_H
#define OPENCAX_CAMERA_H
#include "../RenderStruct.h"
#include "NativeEGLOCCT/common.h"
#include <V3d_View.hxx>
#include <Graphic3d_Camera.hxx>
#include <gp_Quaternion.hxx>
namespace NativeOpenCAX {
bool InitCamera(RenderOption &opt);
void ChangeCamera();
void FrontView(RenderOption &opt);
void TopView(RenderOption &opt);
void LeftSideView(RenderOption &opt);
void RightSideView(RenderOption &opt);
void BottomView(RenderOption &opt);
void RearView(RenderOption &opt);
void ISOView(RenderOption &opt);
void DIMView(RenderOption &opt);
class Camera{
public:
Camera();
~Camera();
bool InitCamera(Handle(V3d_View)& view);
void SetRotation(float xAngle, float yAngle);
public:
Handle(Graphic3d_Camera) camera;
};
} // namespace NativeOpenCAX
#endif // OPENCAX_CAMERA_H

View File

@ -7,21 +7,23 @@
#include "Context.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitCtx"
#define NATIVE_TAG "CONTEXT"
#endif
namespace NativeOpenCAX {
bool InitCtx(RenderOption& opt) {
if (opt.context.IsNull()) {
opt.context = new AIS_InteractiveContext(opt.viewer);
opt.context->SetDisplayMode(AIS_Shaded, Standard_False); // 默认使用着色模式
HILOG_INFO(NATIVE_TAG,"InitCtx Done");
Context::Context() : context(nullptr) {}
Context::~Context() {}
bool Context::InitContext(Handle(V3d_Viewer)& viewer) {
try {
context = new AIS_InteractiveContext(viewer);
context->SetDisplayMode(AIS_Shaded, Standard_False); // 默认使用着色模式
HILOG_INFO(NATIVE_TAG, "InitCtx Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitCtx Fail:%{public}d", e.what());
return false;
}
return false;
}
void ChangeCtx(){
}
}

View File

@ -7,12 +7,20 @@
#ifndef OPENCAX_CONTEXT_H
#define OPENCAX_CONTEXT_H
#include "../RenderStruct.h"
#include "NativeEGLOCCT/common.h"
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
namespace NativeOpenCAX{
bool InitCtx(RenderOption& opt);
void ChangeCtx();
class Context{
public:
Context();
~Context();
bool InitContext(Handle(V3d_Viewer)& viewer);
public:
Handle(AIS_InteractiveContext) context;
};
}
#endif //OPENCAX_CONTEXT_H

View File

@ -162,15 +162,21 @@ void NativeManager::OnSurfaceDestroyed(OH_NativeXComponent *component, void *win
}
}
}
uint64_t width,height;
void NativeManager::OnSurfaceChanged(OH_NativeXComponent *component, void *window) {
OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
int64_t id = 0;
{
if(width==width_ && height==height_){
return;
}
std::lock_guard<std::mutex> lock(mapMutex);
if (renderThreadMap.find(id) != renderThreadMap.end()) {
HILOG_ERROR(NATIVE_TAG,"uint32_t Size:%{public}dX%{public}d",width_,height_);
renderThreadMap[id]->resizeWindow(width_, height_);
width=width_;
height=height_;
}
}
}

View File

@ -1,4 +1,5 @@
#include "NativeRender.h"
#include "STEPControl_Reader.hxx"
#ifndef NATIVE_TAG
#define NATIVE_TAG "NativeRender"
@ -7,49 +8,67 @@
static std::mutex renderMutex;
namespace NativeOpenCAX {
NativeRender::NativeRender()
NativeRender::NativeRender(int w, int h):
width(0),
height(0),
mAxis(new Axis),
nAxis(new Axis),
cr(new Camera),
ctx(new Context),
ogd(new OpenGlGraphicDriver),
ts(new TextStyle),
vw(new View),
vr(new Viewer),
win(new Window)
{
width=w;
height=h;
}
NativeRender::~NativeRender() {
shapes_.clear();
}
bool NativeRender::init(int width, int height,EGLCore* eglCore) {
rendOption.eglCore=eglCore;
rendOption.width=width;
rendOption.height=height;
if(!InitGraphicDriver(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitGraphicDriver Fail!");
bool NativeRender::init(EGLCore& _eglCore) {
eglCore=_eglCore;
if(!ogd->InitOpenGlGraphicDriver(eglCore)){
HILOG_ERROR(NATIVE_TAG,"Init GraphicDriver Fail!");
return false;
}
if(!InitTextSyle(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitTextSyle Fail!");
if(!ts->InitTextStyle()){
HILOG_ERROR(NATIVE_TAG,"Init TextSyle Fail!");
return false;
}
if(!InitViewer(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitViewer Fail!");
if(!vr->InitViewer(ogd->graphicDriver)){
HILOG_ERROR(NATIVE_TAG,"Init Viewer Fail!");
return false;
}
if(!InitCtx(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitCtx Fail!");
if(!ctx->InitContext(vr->viewer)){
HILOG_ERROR(NATIVE_TAG,"Init Ctx Fail!");
return false;
}
if(!InitWorldAxis(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitWorldAxis Fail!");
if(!mAxis->InitAxis(ctx->context, AXIS_TYPE::WORLD_AXIS)){
HILOG_ERROR(NATIVE_TAG,"Init WORLD_AXIS Fail!");
return false;
}
if(!InitLocalAxis(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitLocalAxis Fail!");
if(!nAxis->InitAxis(ctx->context, AXIS_TYPE::LOCAL_AXIS)){
HILOG_ERROR(NATIVE_TAG,"Init LOCAL_AXIS Fail!");
return false;
}
if(!InitView(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitView Fail!");
if(!win->InitWindow(width,height)){
HILOG_ERROR(NATIVE_TAG,"Init Window Fail!");
return false;
}
if(!InitCamera(rendOption)){
HILOG_ERROR(NATIVE_TAG,"InitCamera Fail!");
if(!vw->InitView(vr->viewer)){
HILOG_ERROR(NATIVE_TAG,"Init View Fail!");
return false;
}else{
vw->SetViewOption();
vw->SetText(ts->text);
vw->SetWin(win->window);
}
if(!cr->InitCamera(vw->view)){
HILOG_ERROR(NATIVE_TAG,"Init Camera Fail!");
return false;
}
return true;
@ -58,7 +77,7 @@ bool NativeRender::init(int width, int height,EGLCore* eglCore) {
bool NativeRender::loadModel(const std::string& filePath) {
// 清除现有模型
for (auto& shape : shapes_) {
rendOption.context->Remove(shape, Standard_False);
ctx->context->Remove(shape, Standard_False);
}
shapes_.clear();
@ -97,6 +116,12 @@ bool NativeRender::loadModel(const std::string& filePath) {
// 设置材质
Handle(Prs3d_Drawer) drawer = aisShape->Attributes();
Handle(Prs3d_ShadingAspect) shadingAspect = new Prs3d_ShadingAspect();
aisShape->SetDisplayMode(1);
Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(
Quantity_NOC_BLACK, // 颜色,例如黑色
Aspect_TOL_SOLID, // 线型
2.0 // 线宽
);
// 随机颜色
int colorIndex = i % 7;
@ -111,152 +136,59 @@ bool NativeRender::loadModel(const std::string& filePath) {
case 6: color = Quantity_NOC_ORANGE; break;
default: color = Quantity_NOC_WHITE;
}
shadingAspect->SetColor(color);
shadingAspect->SetMaterial(Graphic3d_NOM_PLASTIC);
drawer->SetFaceBoundaryDraw(Standard_True);
drawer->SetWireAspect(aLineAspect);
drawer->SetShadingAspect(shadingAspect);
rendOption.context->Display(aisShape, Standard_True);
ctx->context->Display(aisShape, Standard_True);
shapes_.push_back(aisShape);
}
}
// 调整相机到合适位置
rendOption.view->FitAll(0.5, Standard_True);
rendOption.view->ZFitAll();
vw->view->FitAll(0.5, Standard_True);
vw->view->ZFitAll();
vw->ResetView();
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadModel","Successfully loaded STEP file with %{public}d shapes",numShapes);
return true;
}
//setTranslation
void NativeRender::setTranslation(float x, float y) {
axis.translationX = x;
axis.translationY = y;
void NativeRender::setTranslation(float tx, float ty) {
nAxis->SetTranslationX(tx);
nAxis->SetTranslationY(ty);
}
void NativeRender::render() {
if (rendOption.view.IsNull()) {
if (vw->view.IsNull()) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render","View Is Null");
return;
}
// 执行渲染
rendOption.view->Redraw();
vw->MustBeResized();
vw->Redraw();
}
void NativeRender::resize(int width, int height) {
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",width,height);
rendOption.width = width;
rendOption.height = height;
if (!rendOption.view.IsNull()) {
rendOption.window->SetSize(rendOption.width, rendOption.height);
rendOption.window->DoResize();
rendOption.view->MustBeResized();
rendOption.view->Redraw();
Standard_Integer theWidth;
Standard_Integer theHeight;
rendOption.window->Size(theWidth,theHeight);
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",theWidth,theHeight);
}
void NativeRender::resize(int w, int h) {
HILOG_ERROR(NATIVE_TAG,"InPut Size:%{public}d,%{public}d",w,h);
win->Resize(w,h);
}
void NativeRender::setRotation(float xAngle, float yAngle) {
//axis.rotationX = xAngle;
//axis.rotationY = yAngle;
if (rendOption.view.IsNull()) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "addRotationDelta", "View Is Null");
return;
}
//Handle(Graphic3d_Camera) camera = rendOption.view->Camera();
// --- 方案一:直接对相机进行增量旋转 ---
// 这种方式模拟了“轨道”行为,绕着相机看向的目标点旋转。
// 获取当前相机状态
gp_Pnt currentEye = rendOption.camera->Eye();
gp_Pnt currentCenter = rendOption.camera->Center();
gp_Dir currentUp = rendOption.camera->Up();
// 计算当前的视线方向和距离
gp_Vec viewDir = currentCenter.XYZ() - currentEye.XYZ();
double distance = viewDir.Magnitude();
gp_Pnt rotationCenter = currentCenter; // 旋转中心设为当前目标点
// 创建旋转增量
gp_Quaternion rotX, rotY;
// 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec)
gp_Vec xRotationAxis = rendOption.camera->Direction().XYZ().Crossed(currentUp.XYZ()); // 叉积得到X旋转轴
if (xRotationAxis.Magnitude() > gp::Resolution()) { // 防止零向量导致的无效四元数
rotX.SetVectorAndAngle(xRotationAxis, xAngle * M_PI / 180.0);
} else {
rotX.SetIdent(); // 如果叉积为零,则无旋转
}
// 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec)
gp_Vec yRotationAxis = currentUp.XYZ(); // Y旋转轴就是当前的Up方向
if (yRotationAxis.Magnitude() > gp::Resolution()) {
rotY.SetVectorAndAngle(yRotationAxis, yAngle * M_PI / 180.0);
} else {
rotY.SetIdent(); // 如果Up向量无效则无旋转
}
// 组合旋转
gp_Quaternion totalRotation = rotY * rotX;
// 应用旋转到眼睛位置
gp_Vec newViewDir = totalRotation * viewDir.Normalized();
gp_Pnt newEye = rotationCenter.XYZ() - newViewDir.XYZ() * distance;
// 计算新的 Up 方向
gp_Dir newUp = totalRotation * currentUp;
// 设置新相机参数
rendOption.camera->SetEye(newEye);
rendOption.camera->SetCenter(rotationCenter);
rendOption.camera->SetUp(newUp);
HILOG_ERROR(NATIVE_TAG,"Rotation");
//rendOption.view->Redraw();
cr->SetRotation(xAngle, yAngle);
}
void NativeRender::setZoomLevel(float zoom) {
axis.zoomLevel = std::max(0.1f, std::min(zoom, 5.0f)); // 限制缩放范围
nAxis->SetZoomLevel(std::max(0.1f, std::min(zoom, 5.0f))); // 限制缩放范围
}
void NativeRender::setClearColor(float r, float g, float b, float a){
vw->SetClearColor( r, g, b, a);
}
void NativeRender::resetView() {
axis.rotationX = 0.0f;
axis.rotationY = 0.0f;
axis.zoomLevel = 1.0f;
if (!rendOption.view.IsNull()) {
rendOption.view->SetProj(V3d_XposYnegZpos);
rendOption.view->FitAll(0.05, Standard_False);
}
vw->ResetView();
}
void NativeRender::SwitchView(std::string view){
vw->SwitchView(view);
}
void NativeRender::setClearColor(float r, float g, float b, float a) {
rendOption.clearColor = Quantity_Color(r, g, b, Quantity_TOC_RGB);
if (!rendOption.view.IsNull()) {
rendOption.view->SetBackgroundColor(rendOption.clearColor);
}
}
void NativeRender::SetFrontView(){
FrontView(rendOption);
}
void NativeRender::SetTopView(){
TopView(rendOption);
}
void NativeRender::SetLeftSideView(){
LeftSideView(rendOption);
}
void NativeRender::SetRightSideView(){
RightSideView(rendOption);
}
void NativeRender::SetBottomView(){
BottomView(rendOption);
}
void NativeRender::SetRearView(){
RearView(rendOption);
}
void NativeRender::SetISOView(){
ISOView(rendOption);
}
void NativeRender::SetDIMView(){
DIMView(rendOption);
}
} // namespace NativeRenderer

View File

@ -4,28 +4,33 @@
#include <string>
#include <vector>
#include "AIS_Shape.hxx"
#include "NativeEGLOCCT/Window/Window.h"
#include "common.h"
#include "EGLCore.h"
#include <Standard_Handle.hxx>
#include "Context/Context.h"
#include <gp_Trsf.hxx>
#include <gp_EulerSequence.hxx>
#include <gp_Quaternion.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include "Axis/Axis.h"
#include "Camera/Camera.h"
#include "Axis/WorldAxis.h"
#include "Axis/LocalAxis.h"
#include "Context/Context.h"
#include "OpenGLGraphicDriver/OpenGLGraphicDriver.h"
#include "TextStyle/TextStyle.h"
#include "View/View.h"
#include "Viewer/Viewer.h"
#include <gp_Trsf.hxx>
#include <gp_EulerSequence.hxx>
#include <gp_Quaternion.hxx>
#include "Viewer/Viewer.h"
namespace NativeOpenCAX {
class NativeRender {
public:
NativeRender();
NativeRender(int width, int height);
~NativeRender();
bool init(int width, int height,EGLCore* eglCore);
bool init(EGLCore& eglCore);
bool loadModel(const std::string& filePath);
void render();
void resize(int width, int height);
@ -36,6 +41,7 @@ public:
void setTranslation(float x, float y);
void setCameraRotationMode(bool state);
//视图
void SwitchView(std::string);
void SetFrontView();
void SetTopView();
void SetLeftSideView();
@ -45,8 +51,19 @@ public:
void SetISOView();
void SetDIMView();
private:
RenderOption rendOption;
AxisOption axis;
int width;
int height;
EGLCore eglCore;
Axis* mAxis;
Axis* nAxis;
Camera* cr;
Context* ctx;
OpenGlGraphicDriver* ogd;
TextStyle* ts;
View* vw;
Viewer* vr;
Window* win;
std::vector<Handle(AIS_Shape)> shapes_;
};
} // namespace NativeRender

View File

@ -12,6 +12,7 @@ NativeRenderThread::NativeRenderThread()
windowHeight_(720)
{
eglCore_ = new EGLCore();
renderer_= new NativeRender(windowWidth_,windowHeight_);
}
NativeRenderThread::~NativeRenderThread() {
@ -56,7 +57,7 @@ void NativeRenderThread::renderLoop() {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
}
// 初始化OCCT渲染器
if (!renderer_.init(windowWidth_, windowHeight_,eglCore_)) {
if (!renderer_->init(*eglCore_)) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer");
eglCore_->destroy();
}
@ -79,48 +80,27 @@ void NativeRenderThread::renderLoop() {
if (hasCommand) {
switch (command.type) {
case CMD_LOAD_MODEL:
renderer_.loadModel(command.param1);
renderer_->loadModel(command.param1);
break;
case CMD_SET_ROTATION:
renderer_.setRotation(command.param2, command.param3);
renderer_->setRotation(command.param2, command.param3);
break;
case CMD_SET_TRANSLATION:
renderer_.setTranslation(command.param2, command.param3);
renderer_->setTranslation(command.param2, command.param3);
break;
case CMD_RESET_VIEW:
renderer_.resetView();
renderer_->resetView();
break;
case CMD_SET_CLEAR_COLOR:
renderer_.setClearColor(command.param2, command.param3, command.param4, command.param5);
renderer_->setClearColor(command.param2, command.param3, command.param4, command.param5);
break;
case CMD_RESIZE:
windowWidth_ = static_cast<int>(command.param2);
windowHeight_ = static_cast<int>(command.param3);
renderer_.resize(windowWidth_, windowHeight_);
renderer_->resize(windowWidth_, windowHeight_);
break;
case CMD_VIEW_FRONT:
renderer_.SetFrontView();
break;
case CMD_VIEW_TOP:
renderer_.SetFrontView();
break;
case CMD_VIEW_LEFT_SIDE:
renderer_.SetFrontView();
break;
case CMD_VIEW_RIGHT_SIDE:
renderer_.SetFrontView();
break;
case CMD_VIEW_BOTTOM:
renderer_.SetFrontView();
break;
case CMD_VIEW_REAR:
renderer_.SetFrontView();
break;
case CMD_VIEW_ISO:
renderer_.SetFrontView();
break;
case CMD_VIEW_DIM:
renderer_.SetFrontView();
case CMD_SWITCH_VIEW:
renderer_->SwitchView(command.param1);
break;
case CMD_EXIT:
isRunning_ = false;
@ -132,7 +112,7 @@ void NativeRenderThread::renderLoop() {
}
// 渲染
eglCore_->makeCurrent();
renderer_.render();
renderer_->render();
eglCore_->swapBuffers();
// 调用渲染完成回调
Callback callback;
@ -146,7 +126,7 @@ void NativeRenderThread::renderLoop() {
}
// 控制帧率
usleep(8333); // ~60 FPS
usleep(16667); // ~60 FPS
}
}
@ -183,32 +163,9 @@ void NativeRenderThread::resetView() {
}
void NativeRenderThread::swicthView(std::string strView) {
std::lock_guard<std::mutex> lock(commandMutex_);
CommandType cmdType;
if(strView=="CMD_VIEW_FRONT"){
cmdType=CMD_VIEW_FRONT;
}
if(strView=="CMD_VIEW_TOP"){
cmdType=CMD_VIEW_TOP;
}
if(strView=="CMD_VIEW_LEFT_SIDE"){
cmdType=CMD_VIEW_LEFT_SIDE;
}
if(strView=="CMD_VIEW_RIGHT_SIDE"){
cmdType=CMD_VIEW_RIGHT_SIDE;
}
if(strView=="CMD_VIEW_BOTTOM"){
cmdType=CMD_VIEW_BOTTOM;
}
if(strView=="CMD_VIEW_REAR"){
cmdType=CMD_VIEW_REAR;
}
if(strView=="CMD_VIEW_ISO"){
cmdType=CMD_VIEW_ISO;
}
if(strView=="CMD_VIEW_DIM"){
cmdType=CMD_VIEW_DIM;
}
commandQueue_.push(RenderCommand(cmdType));
RenderCommand cmd(CMD_SWITCH_VIEW);
cmd.param1 = strView;
commandQueue_.push(RenderCommand(cmd));
commandCondition_.notify_one();
}
void NativeRenderThread::setClearColor(float r, float g, float b, float a) {

View File

@ -39,7 +39,7 @@ private:
OHNativeWindow* nativeWindow_;
EGLCore* eglCore_;
NativeRender renderer_;
NativeRender* renderer_;
std::mutex commandMutex_;
std::condition_variable commandCondition_;
@ -51,15 +51,7 @@ private:
CMD_RESET_VIEW,
CMD_SET_CLEAR_COLOR,
CMD_RESIZE,
//视图枚举
CMD_VIEW_FRONT,
CMD_VIEW_TOP,
CMD_VIEW_LEFT_SIDE,
CMD_VIEW_RIGHT_SIDE,
CMD_VIEW_BOTTOM,
CMD_VIEW_REAR,
CMD_VIEW_ISO,
CMD_VIEW_DIM,
CMD_SWITCH_VIEW,
CMD_EXIT
};

View File

@ -7,24 +7,29 @@
#include "OpenGLGraphicDriver.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitGraphicDriver"
#define NATIVE_TAG "GRAPHIC_DRIVER"
#endif
namespace NativeOpenCAX{
namespace NativeOpenCAX {
bool InitGraphicDriver(RenderOption &opt){
if (opt.graphicDriver.IsNull()) {
opt.displayConnection=new Aspect_DisplayConnection();
opt.graphicDriver = new OpenGl_GraphicDriver(opt.displayConnection,Standard_False);
opt.graphicDriver->ChangeOptions().buffersNoSwap = Standard_True;
opt.graphicDriver->InitEglContext(eglGetCurrentDisplay(), eglGetCurrentContext(), opt.eglCore->getConfig());
HILOG_INFO(NATIVE_TAG,"InitGraphicDriver Done");
OpenGlGraphicDriver::OpenGlGraphicDriver() : graphicDriver(nullptr), displayConnection(nullptr) {}
OpenGlGraphicDriver::~OpenGlGraphicDriver() {}
bool OpenGlGraphicDriver::InitOpenGlGraphicDriver(EGLCore& eglCore) {
try {
displayConnection = new Aspect_DisplayConnection();
graphicDriver = new OpenGl_GraphicDriver(displayConnection, Standard_False);
graphicDriver->ChangeOptions().buffersNoSwap = Standard_True;
graphicDriver->InitEglContext(eglGetCurrentDisplay(), eglGetCurrentContext(), eglCore.getConfig());
HILOG_INFO(NATIVE_TAG, "InitGraphicDriver Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitGraphicDriver Fail:%{public}d", e.what());
return false;
}catch (...) {
HILOG_ERROR(NATIVE_TAG, "InitGraphicDriver unknown exception occurred when creating Aspect_DisplayConnection.");
return false;
}
return false;
}
void ChangeGraphicDriver(){
}
}
} // namespace NativeOpenCAX

View File

@ -7,12 +7,23 @@
#ifndef OPENCAX_OPENGLGRAPHICDRIVER_H
#define OPENCAX_OPENGLGRAPHICDRIVER_H
#include "../RenderStruct.h"
#include <EGL/egl.h>
#include "NativeEGLOCCT/EGLCore.h"
#include "NativeEGLOCCT/common.h"
#include <OpenGl_GraphicDriver.hxx>
#include <Graphic3d_GraphicDriver.hxx>
namespace NativeOpenCAX{
class OpenGlGraphicDriver{
public:
OpenGlGraphicDriver();
~OpenGlGraphicDriver();
bool InitOpenGlGraphicDriver(EGLCore& eglCore);
public:
Handle(OpenGl_GraphicDriver) graphicDriver;
Handle(Aspect_DisplayConnection) displayConnection;
};
bool InitGraphicDriver(RenderOption &opt);
void ChangeGraphicDriver();
}
#endif //OPENCAX_OPENGLGRAPHICDRIVER_H

View File

@ -1,83 +0,0 @@
//
// 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".
#ifndef OPENCAX_REDCOMMON_H
#define OPENCAX_REDCOMMON_H
#include "common.h"
#include <cstdio>
#include <cmath>
#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <Font_NameOfFont.hxx>
#include <Aspect_NeutralWindow.hxx>
#include <Aspect_TypeOfTriedronPosition.hxx>
#include <Geom_Axis2Placement.hxx>
#include <OpenGl_Window.hxx>
#include <OSD_Environment.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Trihedron.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_InteractiveContext.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_TextAspect.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Graphic3d_ZLayerSettings.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <Graphic3d_NameOfMaterial.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <V3d_TypeOfOrientation.hxx>
#include "EGLCore.h"
#include <STEPControl_Reader.hxx>
namespace NativeOpenCAX {
struct RenderOption{
int width;
int height;
Quantity_Color clearColor;
EGLCore* eglCore;
Handle(OpenGl_GraphicDriver) graphicDriver;
Handle(Aspect_DisplayConnection) displayConnection;
Handle(Aspect_NeutralWindow) window;
Handle(V3d_Viewer) viewer;
Handle(V3d_View) view;
Handle(Graphic3d_Camera) camera;
Handle(AIS_InteractiveContext) context;
Handle(Prs3d_TextAspect) text;
Handle(Geom_Axis2Placement) worldAxisPlacement;
Handle(Geom_Axis2Placement) localAxisPlacement;
Handle(AIS_Trihedron) worldAxis;
Handle(AIS_Trihedron) localAxis;
};
struct AxisOption{
//旋转X轴
float rotationX=0.0f;
//旋转Y轴
float rotationY=0.0f;
//旋转Z轴
float rotationZ=0.0f;
//缩放等级
float zoomLevel=1.0f;
//翻转X轴
float translationX=0.0f;
//翻转Y轴
float translationY=0.0f;
//翻转Z轴
float translationZ=0.0f;
};
}
#endif //OPENCAX_REDCOMMON_H

View File

@ -7,30 +7,32 @@
#include "TextStyle.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitTextSyle"
#define NATIVE_TAG "TEXTSTYLE"
#endif
namespace NativeOpenCAX {
bool InitTextSyle(RenderOption& opt) {
if (opt.text.IsNull()) {
opt.text = new Prs3d_TextAspect();
opt.text->SetFont(Font_NOF_ASCII_MONO);
opt.text->SetHeight(12);
opt.text->Aspect()->SetColor(Quantity_NOC_GRAY95);
opt.text->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
opt.text->Aspect()->SetDisplayType(Aspect_TODT_SHADOW);
opt.text->Aspect()->SetTextFontAspect(Font_FA_Bold);
opt.text->Aspect()->SetTextZoomable(false);
opt.text->SetHorizontalJustification(Graphic3d_HTA_LEFT);
opt.text->SetVerticalJustification(Graphic3d_VTA_BOTTOM);
HILOG_INFO(NATIVE_TAG,"InitTextSyle Done");
return true;
}
return false;
}
void ChangeTextSyle(){
TextStyle::TextStyle() : text(nullptr) {}
TextStyle::~TextStyle() {}
bool TextStyle::InitTextStyle() {
try {
text = new Prs3d_TextAspect();
text->SetFont(Font_NOF_ASCII_MONO);
text->SetHeight(12);
text->Aspect()->SetColor(Quantity_NOC_GRAY95);
text->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
text->Aspect()->SetDisplayType(Aspect_TODT_SHADOW);
text->Aspect()->SetTextFontAspect(Font_FA_Bold);
text->Aspect()->SetTextZoomable(false);
text->SetHorizontalJustification(Graphic3d_HTA_LEFT);
text->SetVerticalJustification(Graphic3d_VTA_BOTTOM);
HILOG_INFO(NATIVE_TAG, "InitTextSyle Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitTextSyle Fail:%{public}d", e.what());
return false;
}
}
}

View File

@ -7,12 +7,19 @@
#ifndef OPENCAX_TEXTSTYLE_H
#define OPENCAX_TEXTSTYLE_H
#include "../RenderStruct.h"
#include "NativeEGLOCCT/common.h"
#include "Font_NameOfFont.hxx"
#include <Prs3d_TextAspect.hxx>
namespace NativeOpenCAX{
bool InitTextSyle(RenderOption& opt);
void ChangeTextSyle();
class TextStyle{
public:
TextStyle();
~TextStyle();
bool InitTextStyle();
public:
Handle(Prs3d_TextAspect) text;
};
}
#endif //OPENCAX_TEXTSTYLE_H

View File

@ -7,47 +7,87 @@
#include "View.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitView"
#define NATIVE_TAG "VIEW"
#endif
namespace NativeOpenCAX {
bool InitView(RenderOption& opt) {
View::View() : view(nullptr) {}
View::~View() {}
if (opt.window.IsNull()) {
opt.window = new Aspect_NeutralWindow();
opt.window->SetSize(opt.width, opt.height);
opt.view = opt.viewer->CreateView();
// 设置渲染参数
opt.view->SetImmediateUpdate(false);
// view_->ChangeRenderingParams().ToShowStats = true;
// view_->ChangeRenderingParams().Resolution = (unsigned int )(96.0 * displayPixelRatio() + 0.5);
opt.view->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
opt.view->ChangeRenderingParams().IsShadowEnabled = Standard_False;
opt.view->ChangeRenderingParams().IsReflectionEnabled = Standard_False;
opt.view->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
opt.view->ChangeRenderingParams().Resolution = 2;
opt.view->ChangeRenderingParams().StatsTextAspect = opt.text->Aspect();
opt.view->ChangeRenderingParams().StatsTextHeight = opt.text->Height();
// 设置背景渐变
opt.view->SetBgGradientColors(Quantity_Color(Quantity_NOC_GRAY), Quantity_Color(Quantity_NOC_BLACK),
Aspect_GFM_VER, // 垂直渐变
Standard_False);
// 设置默认相机位置
opt.view->SetProj(V3d_XposYnegZpos);
// 可选:显示坐标轴
opt.view->ZBufferTriedronSetup();
// 调整相机视角
opt.view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
opt.view->SetBackgroundColor(Quantity_NOC_GRAY90);
opt.view->MustBeResized();
opt.view->SetWindow(opt.window,(Aspect_RenderingContext )eglGetCurrentContext());
opt.view->RedrawImmediate();
HILOG_INFO(NATIVE_TAG,"InitView Done");
bool View::InitView(Handle(V3d_Viewer) & viewer) {
try {
view = viewer->CreateView();
HILOG_INFO(NATIVE_TAG, "InitView Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitView Fail:%{public}d", e.what());
return false;
}
return false;
}
void View::SetViewOption() {
// 设置渲染参数
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, // 垂直渐变
Standard_False);
// 设置默认相机位置
view->SetProj(V3d_XposYnegZpos);
// 可选:显示坐标轴
view->ZBufferTriedronSetup();
// 调整相机视角
view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
view->SetBackgroundColor(Quantity_NOC_GRAY90);
}
void ChangeView() {}
void View::SetText(Handle(Prs3d_TextAspect) & text) {
view->ChangeRenderingParams().StatsTextAspect = text->Aspect();
view->ChangeRenderingParams().StatsTextHeight = text->Height();
}
void View::SetWin(Handle(Aspect_NeutralWindow) & win) {
view->SetWindow(win, (Aspect_RenderingContext)eglGetCurrentContext());
}
void View::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 View::MustBeResized() { view->MustBeResized(); }
void View::Redraw() { view->Redraw(); }
void View::ResetView() {
if (!view.IsNull()) {
view->SetProj(V3d_XposYnegZpos);
view->FitAll(0.05, Standard_False);
}
}
void View::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);
}
}

View File

@ -7,12 +7,37 @@
#ifndef OPENCAX_VIEW_H
#define OPENCAX_VIEW_H
#include "../RenderStruct.h"
#include "NativeEGLOCCT/common.h"
#include <V3d_View.hxx>
#include <Aspect_NeutralWindow.hxx>
namespace NativeOpenCAX{
bool InitView(RenderOption& opt);
void ChangeView();
class View{
public:
View();
~View();
bool InitView(Handle(V3d_Viewer)& viewer);
void SetViewOption();
void SetWin(Handle(Aspect_NeutralWindow)& win);
void SetText(Handle(Prs3d_TextAspect)& text);
void SetClearColor(float r, float g, float b, float a);
void MustBeResized();
void Redraw();
void ResetView();
void SwitchView(std::string view);
// void FrontView();
// void TopView();
// void LeftSideView();
// void RightSideView();
// void BottomView();
// void RearView();
// void ISOView();
// void DIMView();
public:
Handle(V3d_View) view;
Quantity_Color clearColor;
};
}
#endif //OPENCAX_VIEW_H

View File

@ -7,22 +7,25 @@
#include "Viewer.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "InitViewer"
#define NATIVE_TAG "VIEWER"
#endif
namespace NativeOpenCAX {
bool InitViewer(RenderOption &opt) {
// 创建V3d_Viewer
if (opt.viewer.IsNull()) {
opt.viewer = new V3d_Viewer(opt.graphicDriver);
opt.viewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
opt.viewer->SetDefaultLights();
opt.viewer->SetLightOn();
HILOG_INFO(NATIVE_TAG,"InitViewer Done");
Viewer::Viewer() : viewer(nullptr) {}
Viewer::~Viewer() {}
bool Viewer::InitViewer(Handle(OpenGl_GraphicDriver)& graphicDriver) {
try {
viewer = new V3d_Viewer(graphicDriver);
viewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
viewer->SetDefaultLights();
viewer->SetLightOn();
HILOG_INFO(NATIVE_TAG, "InitViewer Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitViewer Fail:%{public}d", e.what());
return false;
}
return false;
}
void ChangeViewer() {}
}

View File

@ -7,12 +7,20 @@
#ifndef OPENCAX_VIEWER_H
#define OPENCAX_VIEWER_H
#include "../RenderStruct.h"
#include "NativeEGLOCCT/common.h"
#include <V3d_Viewer.hxx>
#include <OpenGl_GraphicDriver.hxx>
namespace NativeOpenCAX{
bool InitViewer(RenderOption& opt);
void ChangeViewer();
class Viewer{
public:
Viewer();
~Viewer();
bool InitViewer(Handle(OpenGl_GraphicDriver)& graphicDriver);
public:
Handle(V3d_Viewer) viewer;
};
}
#endif //OPENCAX_VIEWER_H

View File

@ -0,0 +1,34 @@
//
// Created on 2026/3/23.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Window.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "WINDOW"
#endif
namespace NativeOpenCAX {
Window::Window():window(nullptr){
}
Window::~Window(){
}
bool Window::InitWindow(Standard_Integer& width, Standard_Integer& height){
if(window.IsNull()){
window = new Aspect_NeutralWindow();
window->SetSize(width, height);
HILOG_INFO(NATIVE_TAG, "Init Window Done");
return true;
}
HILOG_INFO(NATIVE_TAG, "Init Window Done");
return false;
}
void Window::Resize(int w, int h) {
window->SetSize(w, h);
window->DoResize();
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",w,h);
}
}

View File

@ -0,0 +1,27 @@
//
// Created on 2026/3/23.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef OPENCAX_WINDOW_H
#define OPENCAX_WINDOW_H
#include "NativeEGLOCCT/common.h"
#include <Standard_TypeDef.hxx>
#include <Aspect_NeutralWindow.hxx>
namespace NativeOpenCAX {
class Window {
public:
Window();
~Window();
bool InitWindow(Standard_Integer& width,Standard_Integer& height);
void Resize(int w, int h);
public:
Handle(Aspect_NeutralWindow) window;
};
}
#endif //OPENCAX_WINDOW_H

View File

@ -23,6 +23,7 @@
#include <napi/native_api.h>
#include "hilog/log.h"
#include <thread>
#include <exception>
/**
LOG_APP
LOG_ERROR

View File

@ -66,7 +66,7 @@ export default class EntryAbility extends UIAbility {
// if Size Change save to AppStorage
mainWinInfo.mainWindowWidth=ListenerData.width;
mainWinInfo.mainWindowHeight=ListenerData.height;
console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
console.info('Succeeded in enabling the listener for window size changes. Data:'+ListenerData.width,ListenerData.height);
});
});

View File

@ -18,6 +18,14 @@ export let DevModel:TitleModel= {
cmName:"开发模式",cmPage:"",cmTips:"",cmEvents:[
[[{grpName:'工具矩阵',grpBtn:[
{eModel:[ModelType.BASE],eName:"加载模型",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"Execute_LoadModel"},
{eModel:[ModelType.BASE],eName:"正等轴测图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_ISO"},
{eModel:[ModelType.BASE],eName:"正二等轴测图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_DIM"},
{eModel:[ModelType.BASE],eName:"前视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_FRONT"},
{eModel:[ModelType.BASE],eName:"后视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_REAR"},
{eModel:[ModelType.BASE],eName:"左视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_LEFT_SIDE"},
{eModel:[ModelType.BASE],eName:"右视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_RIGHT_SIDE"},
{eModel:[ModelType.BASE],eName:"俯视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_TOP"},
{eModel:[ModelType.BASE],eName:"仰视图",eNamed:"",ePage:'',eIcon:"base_new_file",eTips:"",eEvent:"CMD_VIEW_BOTTOM"},
[
{eModel:[ModelType.BASE],eName:"创建子窗体",eNamed:"",ePage:'pages/EventSubWindow/SWExtrude',eIcon:"base_new_file",eTips:"",eEvent:"Execute_CreateSubWindow"},
{eModel:[ModelType.BASE],eName:"关闭子窗体",eNamed:"",ePage:'pages/EventSubWindow/SWExtrude',eIcon:"base_new_file",eTips:"",eEvent:"Execute_ExitSubWindow"},

View File

@ -3,9 +3,9 @@ import { ModelType } from "./ModelType";
//视图选择布局数据
export let SwitchView:Array<TitleButton>=[
{eModel:[ModelType.BASE],eName:"正二轴测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_tri",eTips:"正二轴测图",eEvent:"CMD_VIEW_DIM"},
{eModel:[ModelType.BASE],eName:"俯视图",eNamed:"",ePage:'',eIcon:"base_view_top",eTips:"俯视图",eEvent:"CMD_VIEW_TOP"},
{eModel:[ModelType.BASE],eName:"正等测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_iso",eTips:"正等测图",eEvent:"CMD_VIEW_ISO"},
{eModel:[ModelType.BASE],eName:"俯视图",eNamed:"",ePage:'',eIcon:"base_view_top",eTips:"俯视图",eEvent:"CMD_VIEW_TOP"},
{eModel:[ModelType.BASE],eName:"正二轴测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_tri",eTips:"正二轴测图",eEvent:"CMD_VIEW_DIM"},
{eModel:[ModelType.BASE],eName:"左视图",eNamed:"",ePage:'',eIcon:"base_view_left",eTips:"左视图",eEvent:"CMD_VIEW_LEFT_SIDE"},
{eModel:[ModelType.BASE],eName:"前视图",eNamed:"",ePage:'',eIcon:"base_view_front",eTips:"前视图",eEvent:"CMD_VIEW_FRONT"},