Qt 6.3中的新3D粒子功能

New 3D particles features in Qt 6.3

Qt 6.3中的新3D粒子功能

Tuesday February 08, 2022 by Kaj Grönholm | Comments

2022年2月8日星期二 Kaj Grönholm | 评论

Yes, I know, Qt 6.3 isn't out yet. But as the first beta was just released, it is a good time to start speaking about the new features. In this blog post, I will list my three favourite new features available in Qt Quick 3D particles module.

​是的,我知道,Qt 6.3还没有发布。但由于第一个测试版刚刚发布,现在是开始谈论新功能的好时机。在这篇博文中,我将列出Qt Quick 3D粒子模块中我最喜欢的三个新功能。

Custom Shapes

自定义形状

Shapes in Quick 3D particles module define areas where the particles are emitted from or where the particles are attracted to. Most common way to define the shape is using ParticleShape3D and selecting the shape type (Cube, Sphere, Cylinder). Alternatively, if you want to emit particles from an existing 3D model, there is ParticleModelShape3D just for that. These options are often enough, but they don't cover all the needs, so with Qt 6.3 we added a new ParticleCustomShape3D element. This element allows defining exact particle positions of the shape in a simple CBOR format:

​“Quick 3D粒子”模块中的形状定义粒子发射或吸引到的区域。定义形状最常用的方法是使用ParticleShape3D并选择形状类型(立方体、球体、圆柱体)。或者,如果要从现有的3D模型发射粒子,可以使用ParticleModelShape3D。这些选项通常已经足够了,但它们并不能满足所有需求,因此在Qt 6.3中,我们添加了一个新的particleCustomsShape3D元素。该元素允许以简单的CBOR格式定义形状的精确粒子位置:

[
  "QQ3D_SHAPE", // string
  version, // integer
  [
    posX, // float
    posY, // float
    posZ, // float
    posX, // float
    ...
  ]
]

Here is an example application using custom shapes:

下面是一个使用自定义形状的示例应用程序:

https://youtu.be/1ZWSo-GbaoI

To create these shape files, we provide a simple command-line tool called shapegen, which takes in an image and depth, and creates defined amount of positions within those. Here is the help of shapegen tool:

为了创建这些形状文件,我们提供了一个名为shapegen的简单命令行工具,它接收图像和深度,并在其中创建定义数量的位置。以下是shapegen工具的帮助:

C:\qt6_3-install\bin
λ shapegen.exe --help
Usage: shapegen.exe [options]
Tool to generate Qt Quick 3D Particles Custom Shapes

Options:
-?, -h, --help Displays help on commandline options.
--help-all Displays help including Qt specific
options.
-i, --image <file> Input image for the data.
-o, --output <file> Output CBOR file for the shape data.
-d, --depth <number> Depth (z scale) for the data.
-s, --scale <number> Scale used for the image data. Default
1.0
-a, --amount <number> Amount of position data to generate.
-p, --sorting-position <qvector3d> Position to use for sorting. Format "x,
y, z"
-l, --list-cbor Lists CBOR file content.

This tool is still rather simple, but so is the CBOR format so you can also look at the private shape helper class and generate your own custom shapes in any imaginable ways.

​这个工具仍然很简单,但是CBOR格式也很简单,因此您还可以查看private shape helper类,并以任何可以想象的方式生成自己的自定义形状。

Lights Support

灯光支持

To emit 2D texture particles in the Quick 3D scene, you use the SpriteParticle3D elements. With the Qt 6.3, we have added lights support for these sprite particles by defining which lights the particle should be affected by:

​要在Quick 3D场景中发射2D纹理粒子,请使用SpriteArticle3D元素。在Qt 6.3中,我们通过定义粒子应受到哪些灯光的影响,为这些精灵粒子添加了灯光支持:

SpotLight {
  id: lightSpot
  ...
}

PointLight {
  id: lightPoint
  ...
}

SpriteParticle3D {
  id: spriteParticle
  sprite: Texture {
    source: "images/sphere.png"
  }
  lights: [lightSpot, lightPoint]
  ...
}

All the Quick3D light types are supported. With particles, the applied light amount is per-particle and not per-pixel resolution like with the Quick 3D models. This decision was made because particles are usually rather small and to have excellent performance by having the lighting calculated in the vertex shader side.

​支持所有Quick3D灯光类型。对于粒子,应用的光量是每粒子,而不是像Quick 3D模型那样的每像素分辨率。之所以做出这个决定,是因为粒子通常非常小,并且通过在顶点着色器侧计算照明来获得优异的性能。

Here is an example application demonstrating particles with different lights:

下面是一个示例应用程序,演示具有不同灯光的粒子:

https://youtu.be/YZczW8VAX1c

You can take this lighting support into use to make particles blend better with the rest of the 3D scene. And as said, the lights implementation is rather performant so you can use them also on embedded hardware.

可以使用该灯光支持,使粒子更好地与3D场景的其余部分混合。如前所述,lights实现的性能相当好,因此您也可以在嵌入式硬件上使用它们。

Dynamic Bursts

动态爆发

To emit particles in bursts, Quick 3D supports several burst() methods and declarative EmitBurst3D elements. The latter is evaluated (so burst particles generated) at the time the particle system starts. This is optimal for performance as it means burst particles don't need to be generated while the system is running, but it doesn't suit cases where the emitter moves, rotates etc. because bursts will be created with the initial emitter stage. For this reason we have added a new DynamicBurst3D element in Qt 6.3. It is used similarly to EmitBurst3D:

​要以爆发方式发射粒子,Quick 3D支持几种burst()方法和声明性EmitBurst3D元素。在粒子系统启动时,对后者进行评估(从而生成爆裂粒子)。这对性能来说是最佳的,因为这意味着在系统运行时不需要生成爆发粒子,但不适合发射器移动、旋转等情况,因为爆发将在发射器的初始阶段创建。因此,我们在Qt 6.3中添加了一个新的DynamicBurst3D元素。它的用法与EmitBurst3D类似:

ParticleEmitter3D {
  ...
  emitBursts: [
    DynamicBurst3D {
      time: 1000
      amount: 100
    },
    DynamicBurst3D {
      time: 2000
      amount: 200
    }
  ]
}

DynamicBurst3D elements are evaluated at the system runtime, meaning that the above example emits 100 particles at 1s and 200 particles at 2s, with the emitter properties during those exact times. DynamicBurst3D combined with TrailEmitter3D also allows triggering the bursts when the followed particle starts or ends.

​DynamicBurst3D元素在系统运行时进行评估,这意味着上述示例在1s时发射100个粒子,在2s时发射200个粒子,在这些精确时间内具有发射器属性。DynamicBurst3D与TrailEmitter3D的结合还允许在后续粒子开始或结束时触发爆发。

Here is an example application demonstrating dynamic bursts with the trail emitter:

下面是一个示例应用程序,演示了使用轨迹发射器的动态脉冲:

https://youtu.be/YuYOJYXEWv4

All the examples shown in the blog are available with the Qt 6.3 and there are also plenty of other new things and fixes in Qt 6.3. So please download the latest 6.3 release and try for yourself.

​博客中显示的所有示例都可以在Qt6.3中使用,Qt6.3中还有很多其他新功能和修复程序。所以,请下载最新的6.3版本,自己试试。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值