渲染SDK 0.1.2
载入中...
搜索中...
未找到
创建3d文字

概述

本教程提供了3d文字创建的教程

描述

通过插件管理模块创建文字插件,支持同时创建多个文字

示例代码

效果图

示例图片

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.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);
//创建文本
auto id = mRender->pluginManage->AddPluginFromType(AMCAXRender::PluginType::kTextLabel);
auto att = mRender->pluginManage->GetProperty<AMCAXRender::TextLabelProp>(id);
att->AddText("hello 1", { 0,0,0 }, { 1,0,0 });
att->AddText("hello 2", { 1,0,0 }, { 1,1,0 });
att->SetFontSize(50);
att->SetOpacity(0.1);
//att->SetTopRender(true);
mRender->pluginManage->SetProperty(id, att);
mRender->cameraManage->ResetCamera();
mRender->entityManage->DoRepaint();
}
Mainwindow::~Mainwindow()
{
}
AMCAX_RENDER_API std::shared_ptr< IRenderComponent > CreateRenderComponent(QWidget *parent)
Create Render Component
@ kTextLabel
Text
定义 Constants.h:226
3D text plugin
定义 PluginProperty.h:142
virtual void AddText(const std::string &text, const std::vector< double > &pos, const std::vector< double > &color)=0
Add text

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.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>

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(Coordinate)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(AMCAXRender )
find_package(Qt6 COMPONENTS Widgets Core Gui 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 Qt6::Core Qt6::Gui Qt6::Widgets)
target_link_libraries(${PROJECT_NAME} PRIVATE AMCAXRender::AMCAXRender)

更多

更多属性请参考 AMCAXRender::TextLabelProp