如何将变换应用于网格几何 [英] How to apply transformations to mesh geometry

查看:127
本文介绍了如何将变换应用于网格几何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Qt3D上,实体可以具有以下两个组成部分:

On Qt3D, an entity can have these two components:

  1. Qt3DRender::QGeometryRenderer组件,其中包含网格几何数据,例如顶点位置法线.
  2. Qt3DCore::QTransform组件,包含旋转翻译缩放比例.
  1. Qt3DRender::QGeometryRenderer component which contains the mesh geometry data like vertex positions and normals.
  2. Qt3DCore::QTransform component which contains the rotations, translations and scalings.


我打算将所有变换应用于网格几何,将网格数据导出为STL.我的意思是,所有旋转和平移都必须应用于顶点位置...


I intend to export the mesh data as STL with all the transformations applied to mesh geometry. I mean, all rotations and translations need to be applied to vertex positions...

当我访问网格几何数据时,如下所示,转换不会应用于几何.

When I access the mesh geometry data, like below, the transformations are not applied to geometry.

mesh->geometry()->attributes().at(i)->buffer()->data();

如何将变换应用于几何?

Qt3DCore::QTransform组件为我提供了 4x4矩阵,但是我的顶点位置是3x1,我不知道如何将此4x4矩阵应用于我的3x1顶点位置.

The Qt3DCore::QTransform component gives me a 4x4 Matrix, but my vertex positions are 3x1, I don't know how to apply this 4x4 matrix into my 3x1 vertex positions.

推荐答案

从转换的数学角度来看,要使用4x4转换矩阵转换矢量,所有内容都必须放在

From the math of transformations, to transform a vector with a 4x4 transformation matrix, everything has to be in homogeneous coordinates. You do this by adding a fourth component to the vector and setting it to one and then just multiply it with the (already homogeneous) 4x4 matrix. so:

QVector3D oldVec = QVector3D(x,y,z);     //this is your 3x1 vertex position
QVector4D newVec = QVector4D(oldVec.x(), oldVec.y(), oldVec.z(), 1);    //added 1 as fourth component
QVector4D transformedVec = matrix*newVec;    //matrix is your 4x4 transformation matrix
//transformedVec is now what you need but with the fourth component still being the 1, so we just leave it out:
QVector3D transformedVec3D = QVector3D(transformedVec.x(), transformedVec.y(), transformedVec.z());

要了解有关其背后的数学的更多信息,可以查看此链接.

To read more about the math behind it, you can check out this link.

这篇关于如何将变换应用于网格几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆