Three.js - 我可以对几何体“应用"位置、旋转和缩放吗? [英] Three.js - Can I 'apply' position, rotation, and scale to the geometry?

查看:36
本文介绍了Three.js - 我可以对几何体“应用"位置、旋转和缩放吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编辑对象的位置、旋转和缩放向量,然后将它们应用"到几何体,这会将这些向量归零,但保留变换.

I'd like to edit an object's position, rotation, and scale vectors, then 'apply' them to the geometry, which would zero-out those vectors, but retain the transformation.

例如,假设我导入一个边长为 1 的立方体.立方体的最小和最大顶点位于 (0, 0, 0)(1, 1, 1).我将对象的比例设置为 (2, 2, 2) 然后将变换应用到几何体.

For example, let's say I import a cube with a side-length of 1. The min and max vertices of the cube are located at (0, 0, 0) and (1, 1, 1). I set the object's scale to (2, 2, 2) and then apply the transformation to the geometry.

应用后,比例重置为 (1, 1, 1) 并且立方体的最小和最大顶点为 (0, 0, 0)(2, 2, 2),分别.

After applying, the scale is reset to (1, 1, 1) and the min and max vertices of the cube are (0, 0, 0) and (2, 2, 2), respectively.

是否有一些内置的方法可以做到这一点?

Is there some built-in way to do this?

推荐答案

您可以直接将对象的变换应用于对象的几何图形,然后像这样重置位置、旋转和缩放:

You can apply an object's transform to the object's geometry directly, and then reset the position, rotation, and scale like so:

object.updateMatrix();

object.geometry.applyMatrix( object.matrix );

object.position.set( 0, 0, 0 );
object.rotation.set( 0, 0, 0 );
object.scale.set( 1, 1, 1 );
object.updateMatrix();

three.js r.69

three.js r.69

这篇关于Three.js - 我可以对几何体“应用"位置、旋转和缩放吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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