渲染SDK 0.1.2
载入中...
搜索中...
未找到
风格示例

概述

本教程提供了Render SDK风格管理模块的使用教程。

前置条件

如果未初始化SDK,需要通过以下代码初始化

//创建sdk组件
auto mRenderComponent = AMCAXRender::CreateRenderComponent(this);
//创建实体Render
auto mRender = mRenderComponent->CreateBasicRender();
AMCAX_RENDER_API std::shared_ptr< IRenderComponent > CreateRenderComponent(QWidget *parent)
Create Render Component

示例代码

以下代码展示了风格相关的配置。

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(StyleSample)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
add_definitions(-DUSE_AMCAX_KERNEL)
list(APPEND CMAKE_PREFIX_PATH ${AMCAXRender_PATH})
find_package(AMCAXRender )
find_package(Qt6 COMPONENTS Widgets Core Gui REQUIRED)
list(APPEND CMAKE_PREFIX_PATH ${Json_PATH})
find_package(nlohmann_json 3.11.3 REQUIRED)
file(GLOB ALL_UI_FILES *.ui)
file(GLOB ALL_FILES *.cpp *.h)
add_executable(${PROJECT_NAME} ${ALL_UI_FILES} ${ALL_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${AMCAX_components})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets)
target_link_libraries(${PROJECT_NAME} PRIVATE AMCAXRender::AMCAXRender)

main.cpp

#include <QApplication>
#include "Mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Mainwindow w;
w.show();
return a.exec();
}

Mainwindow.h

#pragma once
#include <QWidget>
#include "ui_Mainwindow.h"
#include <AMCAXRender.h>
class Mainwindow : public QWidget
{
Q_OBJECT
public:
Mainwindow(QWidget *parent = nullptr);
~Mainwindow();
private:
Ui::MainwindowClass ui;
std::shared_ptr<AMCAXRender::IRenderComponent> mRenderComponent;
std::shared_ptr<AMCAXRender::CBasicRender> mRender;
};
Component Creation

Mainwindow.cpp

#include "Mainwindow.h"
Mainwindow::Mainwindow(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//初始化
mRenderComponent = AMCAXRender::CreateRenderComponent(this);
mRender = mRenderComponent->CreateBasicRender();
//窗口布局
ui.gridLayout->addWidget(mRender->widget);
//设置坐标系风格
mRender->styleManage->SetMarkerStyle(AMCAXRender::CoordStyle::cubeView);
mRender->styleManage->SetMarkerStyle(AMCAXRender::CoordStyle::sailView);
mRender->styleManage->SetMarkerStyle(AMCAXRender::CoordStyle::cubeView2);
//设置交互风格
mRender->styleManage->SetIneractoinStyle(AMCAXRender::InteractonStyle::interaction_1);
mRender->styleManage->SetIneractoinStyle(AMCAXRender::InteractonStyle::interaction_2);
//设置渲染模式
//Normal:正常模式; Shaded:着色模式; Wireframe:边框模式; NoFrame:无边框模式
mRender->styleManage->SetRenderMode(AMCAXRender::RenderMode::Normal);
//设置坐标系是否开启鼠标交互
mRender->styleManage->SetMarkerInteractive(true);
mRender->styleManage->SetMarkerInteractive(false);
//设置标准平面风格
mRender->styleManage->SetPlaneStyle(AMCAXRender::PlaneStyle::standardPlane);
mRender->styleManage->SetPlaneStyle(AMCAXRender::PlaneStyle::none);
//设置背景色1
mRender->styleManage->SetBackground(1, 0, 0);
//设置背景色2
mRender->styleManage->SetBackground2(0, 1, 0);
//设置是否开启渐进色背景
mRender->styleManage->SetGradientBackground(true);
//设置是否开启拾取效果
mRender->styleManage->SetPickColorEnable(true);
mRender->cameraManage->ResetCamera();
mRender->entityManage->DoRepaint();
}
Mainwindow::~Mainwindow()
{
}
@ Normal
Normal Mode
定义 Constants.h:288
@ cubeView
Cube Style
定义 Constants.h:45
@ cubeView2
Cube Style 2
定义 Constants.h:47
@ sailView
Sail Style
定义 Constants.h:46
@ interaction_1
Style 1
定义 Constants.h:53
@ interaction_2
Style 2
定义 Constants.h:54

Mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainwindowClass</class>
<widget class="QWidget" name="MainwindowClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Mainwindow</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout"/>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

风格预览

更多

更多风格属性请参考 StyleManage.h