Qt C++ 场景图架构核心类详解
在 Qt 的 C++ 场景图架构中,不同模块(如 Qt Widgets、Qt Quick、Qt 3D)提供了各自的场景图实现。核心类及其功能如下:
本文介绍 Qt C++ 场景图架构的核心类,涵盖 Graphics View Framework(2D)、Qt Quick(2D/3D)及 Qt 3D 模块。重点解析 QGraphicsScene、QGraphicsView、QGraphicsItem 等 2D 管理类,以及 QQuickWindow、QSGNode 等渲染节点。内容包含坐标系统、事件处理、性能优化建议及代码示例,适用于桌面应用、动态 UI 及三维渲染开发。

在 Qt 的 C++ 场景图架构中,不同模块(如 Qt Widgets、Qt Quick、Qt 3D)提供了各自的场景图实现。核心类及其功能如下:
QGraphicsItem),负责碰撞检测、事件分发、打印渲染等。支持动态添加/删除项,通过 addItem()、removeItem() 管理。transform()),处理鼠标/键盘事件并映射到场景坐标。可启用 OpenGL 加速(通过 setViewport(QOpenGLWidget*))。QGraphicsRectItem(矩形)、QGraphicsEllipseItem(椭圆)、QGraphicsPixmapItem(图片)、QGraphicsTextItem(文本)、QGraphicsPathItem(路径)等。QGraphicsItem 并重写 boundingRect()(边界矩形)和 paint()(绘制逻辑),支持拖拽、选择、分组(QGraphicsItemGroup)。QGraphicsProxyWidget:嵌入 QWidget 到场景中(如按钮、输入框)。QGraphicsLayout/QGraphicsLayoutItem:布局管理(如水平/垂直布局)。QGraphicsScene::BspTreeIndex:通过二进制空间划分树优化大规模项的碰撞检测。QGraphicsScene 是 Qt 框架中用于管理 2D 图形项(QGraphicsItem)的场景类,是 Qt Graphics View Framework 的核心组成部分之一。它与 QGraphicsView(视图)和 QGraphicsItem(图形项)共同构成一个强大的 2D 图形渲染与交互系统。
QGraphicsScene 的一部分。QGraphicsRectItem、QGraphicsEllipseItem),也可以是自定义子类。三者关系:
QGraphicsView → 显示 → QGraphicsScene → 管理 → 多个 QGraphicsItem
addItem(), removeItem())items(), itemAt())QGraphicsItemGroup)qreal),支持高精度定位。QGraphicsItem 有自己的局部坐标系,可通过 mapToScene() / mapFromScene() 转换。QGraphicsView 接收,然后转发给场景,再由场景分发给合适的 QGraphicsItem。setSelectionArea())、键盘焦点项(setFocusItem())。setSelectionMode())。QGraphicsScene *scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 800, 600); // 设置场景范围
QGraphicsRectItem *rect = scene->addRect(100, 100, 200, 100, QPen(Qt::black), QBrush(Qt::blue));
QGraphicsEllipseItem *ellipse = scene->addEllipse(300, 200, 100, 100, QPen(Qt::red), QBrush(Qt::yellow));
QGraphicsTextItem *text = scene->addText("Hello QGraphicsScene!");
text->setPos(50, 50);
class MyItem : public QGraphicsItem {
public:
QRectF boundingRect() const override { return QRectF(-10, -10, 20, 20); }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { painter->drawEllipse(boundingRect()); }
};
// 使用
MyItem *myItem = new MyItem();
scene->addItem(myItem);
myItem->setPos(400, 300);
void mousePressEvent(QGraphicsSceneMouseEvent *event) override {
qDebug() << "Item clicked at:" << event->pos();
QGraphicsItem::mousePressEvent(event);
}
QGraphicsView *view = new QGraphicsView(scene, this);
view->setRenderHint(QPainter::Antialiasing); // 抗锯齿
view->show();
scene->setSelectionArea(QPainterPath()); // 清除选择
scene->setSelectionMode(QGraphicsScene::MultiSelection); // 多选模式
// 将视图坐标转为场景坐标
QPoint viewPos = view->mapFromGlobal(QCursor::pos());
QPointF scenePos = view->mapToScene(viewPos);
// 获取该位置的图形项
QGraphicsItem *item = scene->itemAt(scenePos, view->transform());
配合 QPropertyAnimation 或 QGraphicsItemAnimation(旧版)实现动画。
重写 dragEnterEvent、dropEvent 等方法支持拖放操作。
childItem->setParentItem(parentItem); // 建立父子关系
子项坐标相对于父项,变换会级联。
通过 collidingItems() 检测与其他项的碰撞(基于 shape() 或 boundingRect())。
update(),尽量批量操作。setCacheMode(QGraphicsItem::DeviceCoordinateCache)。setItemIndexMethod(QGraphicsScene::BspTreeIndex)(默认)加速查找。| 问题 | 解决方案 |
|---|---|
| 图形项不显示 | 检查是否调用了 addItem(),场景矩形是否包含该项 |
| 无法交互 | 确保设置了 ItemIsMovable、ItemIsSelectable 等标志 |
| 坐标混乱 | 理解局部坐标 vs 场景坐标,善用 mapToScene() |
| 性能差 | 启用缓存、减少重绘、使用 BSP 索引 |
QGraphicsView 是 Qt 框架中用于显示和交互 QGraphicsScene 中图形项(QGraphicsItem)的视图组件。它是 Qt Graphics View Framework 的三大核心类之一,另外两个是:
QGraphicsScene:场景容器,管理大量 2D 图形项。QGraphicsItem:所有图形项的基类(如矩形、椭圆、自定义图形等)。QGraphicsItem(s) → QGraphicsScene → QGraphicsView
QGraphicsItem,负责碰撞检测、选中、渲染等逻辑。QGraphicsScene 的内容可视化。#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
// 创建场景
QGraphicsScene scene;
scene.setSceneRect(0, 0, 800, 600);
// 添加一个矩形项
QGraphicsRectItem *rect = scene.addRect(100, 100, 200, 150);
rect->setBrush(Qt::red);
// 创建视图并设置场景
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing); // 抗锯齿
view.setWindowTitle("QGraphicsView 示例");
view.resize(800, 600);
view.show();
return app.exec();
}
// 缩放
view.scale(1.2, 1.2); // 放大 20%
view.resetTransform(); // 重置变换
// 平移(通过设置视口中心)
view.centerOn(400, 300); // 将 (400,300) 居中显示
// 或者使用 scrollContentsBy / translate
更灵活的方式:重写 wheelEvent 实现鼠标滚轮缩放:
void MyGraphicsView::wheelEvent(QWheelEvent *event) {
double scaleFactor = 1.15;
if (event->angleDelta().y() > 0) {
scale(scaleFactor, scaleFactor);
} else {
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
}
view.setRenderHint(QPainter::Antialiasing, true); // 抗锯齿
view.setRenderHint(QPainter::SmoothPixmapTransform, true); // 平滑缩放图片
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); // 更新模式
常用更新模式:
MinimalViewportUpdate(默认):只重绘变化区域。FullViewportUpdate:整个视口重绘(适合复杂动画或透明效果)。view.setDragMode(QGraphicsView::ScrollHandDrag); // 拖拽平移(像手抓着移动)
view.setDragMode(QGraphicsView::RubberBandDrag); // 橡皮筋选择多个项
QGraphicsScene 为基准(通常原点在左上角)。QGraphicsView 窗口为基准(像素坐标)。QGraphicsItem 自身的局部坐标。常用转换函数:
QPointF scenePos = view.mapToScene(viewPos); // 视图 → 场景
QPoint viewPos = view.mapFromScene(scenePos); // 场景 → 视图
重写 drawBackground():
class MyGraphicsView : public QGraphicsView {
protected:
void drawBackground(QPainter *painter, const QRectF &rect) override {
QGraphicsView::drawBackground(painter, rect); // 绘制网格
qreal left = int(rect.left()) - (int(rect.left()) % 20);
qreal top = int(rect.top()) - (int(rect.top()) % 20);
QVarLengthArray<QLineF, 100> lines;
for (qreal x = left; x < rect.right(); x += 20) lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += 20) lines.append(QLineF(rect.left(), y, rect.right(), y));
painter->setPen(QPen(QColor(200, 200, 200), 0));
painter->drawLines(lines.data(), lines.size());
}
};
paint() 中做复杂计算,应提前缓存。QGraphicsItem::setCacheMode(QGraphicsItem::DeviceCoordinateCache) 提升渲染速度。QGraphicsItem(如用 QPicture)。启用 OpenGL(可选):
view.setViewport(new QOpenGLWidget);
QGraphicsItem 是 Qt 框架中用于 2D 图形场景(QGraphicsScene)中的基本图形项类,是所有可放置在 QGraphicsScene 中的图形对象的基类。它是 Qt Graphics View Framework 的核心组成部分之一。
Qt 的 Graphics View Framework 由三部分组成:
QGraphicsView —— 用于显示场景。QGraphicsScene —— 容纳并管理图形项。QGraphicsItem 及其子类 —— 实际绘制的内容。QGraphicsItem 本身是一个抽象基类,通常需要继承它来自定义图形项,或者直接使用 Qt 提供的内置子类,如:
QGraphicsRectItemQGraphicsEllipseItemQGraphicsLineItemQGraphicsPixmapItemQGraphicsTextItemQGraphicsPathItemQGraphicsItem 都有自己的坐标系,原点 (0,0) 通常是其'中心'或左上角(取决于实现)。QGraphicsScene 中的位置。可通过以下函数转换坐标:
QPointF mapToScene(const QPointF &point) const;
QPointF mapFromScene(const QPointF &point) const;
QPointF mapToParent(const QPointF &point) const;
QPointF mapFromParent(const QPointF &point) const;
setPos(x, y) / pos():设置/获取在父项或场景中的位置。setRotation())、缩放(setScale())、剪切等仿射变换。QTransform,通过 setTransform() 可自定义。必须重写以下纯虚函数(如果自定义项):
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
同时需实现:
QRectF boundingRect() const override;
⚠️ 注意:
boundingRect()必须返回该项在本地坐标系中包围盒(包括所有可能绘制内容),用于裁剪和碰撞检测。
可选重写:
QPainterPath shape() const; // 更精确的点击/碰撞区域,默认返回 boundingRect 的路径
QGraphicsItem 支持鼠标、键盘、拖拽等事件,例如:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
要启用 hover 事件,需设置:
setAcceptHoverEvents(true);
要接收键盘事件,需:
setFlag(QGraphicsItem::ItemIsFocusable, true);
setZValue() 控制绘制顺序(值越大越靠前)。collidesWithItem() / collidesWithPath()shape() 路径进行精确检测(比 boundingRect() 更准)通过 setFlag() 设置行为:
setFlag(QGraphicsItem::ItemIsMovable); // 可拖动
setFlag(QGraphicsItem::ItemIsSelectable); // 可被选中
setFlag(QGraphicsItem::ItemIsFocusable); // 可获得焦点
setFlag(QGraphicsItem::ItemClipsToShape); // 裁剪到 shape()
setFlag(QGraphicsItem::ItemSendsGeometryChanges); // 位置/变换改变时触发 itemChange
// myitem.h
#ifndef MYITEM_H
#define MYITEM_H
#include <QGraphicsItem>
#include <QPainter>
class MyItem : public QGraphicsItem {
public:
MyItem();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
};
#endif // MYITEM_H
// myitem.cpp
#include "myitem.h"
#include <QGraphicsSceneMouseEvent>
#include <QCursor>
MyItem::MyItem() {
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
setAcceptHoverEvents(true);
}
QRectF MyItem::boundingRect() const {
return QRectF(-20, -20, 40, 40); // 以 (0,0) 为中心的正方形
}
void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(widget);
painter->setPen(Qt::black);
if (option->state & QStyle::State_Selected) painter->setBrush(Qt::red);
else painter->setBrush(Qt::blue);
painter->drawRect(boundingRect());
}
void MyItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
if (event->button() == Qt::LeftButton) qDebug() << "Item clicked at:" << event->pos();
QGraphicsItem::mousePressEvent(event);
}
使用方式:
QGraphicsScene scene;
MyItem *item = new MyItem();
scene.addItem(item);
item->setPos(100, 100);
QGraphicsView view(&scene);
view.show();
boundingRect() 范围。QGraphicsItemGroup 或缓存(setCacheMode(DeviceCoordinateCache))。paint() 中做耗时操作。prepareGeometryChange() 在修改几何前通知场景。| 类名 | 用途 |
|---|---|
QGraphicsRectItem | 矩形 |
QGraphicsEllipseItem | 椭圆/圆 |
QGraphicsLineItem | 直线 |
QGraphicsPixmapItem | 图像 |
QGraphicsTextItem | 文本 |
QGraphicsPathItem | 自定义路径 |
QGraphicsPolygonItem | 多边形 |
graphicsview/ 目录下的示例(如 elasticnodes, diagramscene)QGraphicsRectItem 是 Qt 框架中用于在 QGraphicsScene 中表示矩形图元(graphics item)的一个类。它是 QGraphicsItem 的子类,专门用于绘制矩形、正方形或带圆角的矩形。
#include <QGraphicsRectItem>QGraphicsRectItem ← QAbstractGraphicsShapeItem ← QGraphicsItem// 默认构造,矩形为 (0, 0, 0, 0)
QGraphicsRectItem(QGraphicsItem *parent = nullptr);
// 指定矩形区域(x, y, width, height)
QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = nullptr);
// 使用 QRectF 构造
QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = nullptr);
注意:
x和y是相对于图元自身坐标系的左上角位置(即局部坐标),不是场景坐标。
void setRect(const QRectF &rect);
void setRect(qreal x, qreal y, qreal width, qreal height);
QRectF rect() const;
void setPen(const QPen &pen); // 设置边框样式
void setBrush(const QBrush &brush); // 设置填充样式
QPen pen() const;
QBrush brush() const;
void setPos(qreal x, qreal y); // 设置在场景中的位置
void setFlag(GraphicsItemFlag flag, bool enabled = true); // 启用交互(如可选、可移动等)
void setZValue(qreal z); // 设置 Z 轴层级(控制重叠顺序)
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
// 创建场景
QGraphicsScene scene;
scene.setSceneRect(-200, -200, 400, 400);
// 创建矩形图元
QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 50);
rect->setPen(QPen(Qt::black, 2));
rect->setBrush(QBrush(Qt::yellow));
// 启用交互
rect->setFlag(QGraphicsItem::ItemIsSelectable);
rect->setFlag(QGraphicsItem::ItemIsMovable);
// 添加到场景
scene.addItem(rect);
// 创建视图并显示
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setWindowTitle("QGraphicsRectItem 示例");
view.resize(500, 500);
view.show();
return app.exec();
}
rect() 定义的是图元的本地坐标。setPos() 设置的是图元在场景中的位置。QGraphicsItemGroup 或自定义 QGraphicsItem 以提升性能。QGraphicsRectItem 本身不发射信号。若需响应点击、移动等事件,可:
mousePressEvent 等虚函数(需继承并自定义类);QGraphicsScene 的信号(如 selectionChanged())间接处理。若你希望矩形中心位于 (100, 100),可以:
rect->setRect(-50, -25, 100, 50); // 以中心为原点
rect->setPos(100, 100);
QGraphicsRectItem 本身不支持圆角。如需圆角,应使用 QGraphicsPathItem + QPainterPath::addRoundedRect()。QPropertyAnimation 可对 pos、rect 等属性做动画(需注册元对象系统属性)。| 类名 | 说明 |
|---|---|
QGraphicsEllipseItem | 椭圆/圆形图元 |
QGraphicsLineItem | 直线图元 |
QGraphicsTextItem | 文本图元 |
QGraphicsPathItem | 任意路径图元(更灵活) |
QQuickWindow 是 Qt Quick 模块中的一个关键类,用于显示基于 QML(Qt Meta-Object Language)构建的用户界面。它是 QWindow 的子类,专为渲染 Qt Quick 内容而设计。
#include <QQuickWindow>QQuickWindow ← QWindow ← QObjectQtQuickQQuickWindow 提供了一个窗口,可以加载并显示一个 QQuickItem(通常是 QQuickView 的根项或直接设置的 contentItem)。它负责管理场景图(Scene Graph)的渲染、事件处理、动画调度等。
#include <QGuiApplication>
#include <QQuickWindow>
#include <QQmlEngine>
#include <QQmlComponent>
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQuickWindow window;
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:/main.qml"));
QObject *obj = component.create();
if (auto item = qobject_cast<QQuickItem*>(obj)) {
window.setContentItem(item);
}
window.show();
return app.exec();
}
注意:通常更常见的是使用
QQuickView(继承自QQuickWindow),它封装了加载 QML 文件的逻辑。
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQuickView view;
view.setSource(QUrl("qrc:/main.qml"));
view.show();
return app.exec();
}
QQuickWindow 使用高效的场景图系统进行 GPU 加速渲染。setFormat() 和 setColor(Qt::transparent) 实现透明背景。| 方法 | 说明 |
|---|---|
setContentItem(QQuickItem *item) | 设置窗口显示的根 QML 项 |
contentItem() | 获取当前内容项 |
setPersistentSceneGraph(bool) | 控制场景图是否在隐藏时保留 |
scheduleRenderJob(...) | 调度自定义渲染任务 |
resetOpenGLState() | 在混合 OpenGL 渲染时重置状态 |
QQuickWindow 本身不自动加载 QML 文件,需手动创建 QQmlComponent 或使用 QQuickView。QWidget::createWindowContainer() 包装 QQuickWindow。QQuickWindow 是主要的 UI 显示载体。QSGNode 是 Qt Quick Scene Graph(场景图)系统中的一个核心类,用于表示场景图中的节点。Qt Quick 使用场景图(Scene Graph)作为其底层渲染架构,以高效地渲染用户界面。QSGNode 是所有场景图节点的基类。
QSGGeometryNode、QSGTransformNode、QSGClipNode 等)来构建具体的渲染内容。| 子类 | 用途 |
|---|---|
QSGGeometryNode | 表示具有几何形状和材质(着色器/纹理)的可渲染对象,常用于自定义绘制。 |
QSGTransformNode | 应用仿射变换(如平移、旋转、缩放)到其子节点。 |
QSGClipNode | 定义裁剪区域,限制子节点的绘制范围。 |
QSGRootNode | 场景图的根节点。 |
QSGOpacityNode | 控制子树的透明度。 |
QSGNode 可以避免不必要的重建,提升性能。自定义 QQuickItem 渲染
当你继承 QQuickItem 并重写 updatePaintNode() 方法时,需要返回一个 QSGNode*(通常是 QSGGeometryNode),用于描述如何渲染该 Item。
QSGNode *MyItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) {
QSGGeometryNode *node = static_cast<QSGGeometryNode *>(oldNode);
if (!node) {
node = new QSGGeometryNode; // 设置 geometry 和 material
} // 更新 geometry 或 transform
return node;
}
QSGNode 及其子类通常在渲染线程中访问,因此在 UI 线程中修改节点时需谨慎(通常通过 updatePaintNode 安全地同步)。QQuickItem 是 Qt Quick 模块中的一个核心类,用于表示 Qt Quick 场景图(Scene Graph)中的可视项(visual item)。它是所有可视 QML 元素(如 Rectangle、Image、Text 等)在 C++ 层的基类。
#include <QQuickItem>QObjectQQuickPaintedItem、QQuickFramebufferObject、自定义 QML 类型等Qt QuickTimer、Behavior)都对应一个 QQuickItem 实例。x, y, width, height 等属性。rotation)、缩放(scale)、变换原点(transformOrigin)等。mapToItem(), mapFromItem())。mousePressEvent(QMouseEvent *)mouseMoveEvent(QMouseEvent *)touchEvent(QTouchEvent *)hoverEnterEvent(QHoverEvent *)keyPressEvent(QKeyEvent *)(需先设置 focus: true)QQuickPaintedItem 并重写 paint() 方法(使用 QPainter)。updatePaintNode()),但这更复杂。qmlRegisterType() 将 C++ 类注册为 QML 类型。Q_PROPERTY 暴露属性到 QML。Q_INVOKABLE 或 Q_SLOT 暴露方法。// myitem.h
#include <QQuickPaintedItem>
#include <QColor>
class MyItem : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
MyItem(QQuickItem *parent = nullptr) : QQuickPaintedItem(parent) {}
void paint(QPainter *painter) override { painter->fillRect(boundingRect(), m_color); }
QColor color() const { return m_color; }
void setColor(const QColor &c) {
if (m_color != c) {
m_color = c;
emit colorChanged();
update(); // 触发重绘
}
}
signals:
void colorChanged();
private:
QColor m_color = Qt::red;
};
在 main.cpp 中注册:
qmlRegisterType<MyItem>("MyModule", 1, 0, "MyItem");
在 QML 中使用:
import MyModule 1.0
MyItem {
width: 100
height: 100
color: "blue"
}
QQuickItem 的大多数方法应在 GUI 线程中调用。update() 或在 paint() 中做复杂计算会影响性能。QQuickItem 支持父子结构,子项的坐标相对于父项。Qt Quick 3D 是 Qt 框架中的一个模块,用于在 Qt Quick 应用程序中创建和渲染 3D 内容。它将 3D 图形与 Qt Quick 的声明式 UI 编程模型无缝集成,使开发者能够使用 QML(Qt Meta-Object Language)轻松构建具有 3D 元素的现代用户界面。
.mesh(Qt 自定义格式)、.gltf / .glb(推荐)、.obj 等模型。PropertyAnimation、NumberAnimation 等对 3D 对象属性(如位置、旋转)进行动画。import QtQuick
import QtQuick.Window
import QtQuick3D
Window {
width: 800
height: 600
visible: true
title: "Qt Quick 3D 示例"
View3D {
anchors.fill: parent
camera: camera
PerspectiveCamera {
id: camera
position: Qt.vector3d(0, 0, 600)
}
DirectionalLight {
position: Qt.vector3d(500, 500, 500)
color: "#ffffff"
brightness: 1.0
}
Model {
source: "#Cube" // 内置立方体
position: Qt.vector3d(0, 0, 0)
scale: Qt.vector3d(200, 200, 200)
materials: DefaultMaterial {
diffuseColor: "steelblue"
}
}
}
}
| 组件 | 说明 |
|---|---|
View3D | 3D 渲染视口 |
PerspectiveCamera / OrthographicCamera | 相机类型 |
Model | 表示 3D 模型(可加载外部文件或使用内置形状) |
DefaultMaterial / PrincipledMaterial | 材质系统(后者支持完整 PBR) |
DirectionalLight / PointLight / SpotLight | 光源类型 |
Model {
source: "models/car.glb"
materials: PrincipledMaterial {
baseColor: "red"
metalness: 0.8
roughness: 0.2
}
}
注意:需确保模型路径正确,并在
.pro文件中包含资源(若打包进应用)。
InstanceList)渲染大量相同对象。View3D 的 renderMode(如 Overlay vs Underlay)。simple3d, dynamicmaterials, instancing)
微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online
将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online