缩放后统一获取网格
unity get mesh after scaling
我试图在缩放游戏对象后从网格中获取缩放的顶点。
游戏对象将在编辑器中缩放打印,但如果我打印网格的顶点,它们将不会缩放。
gameObject.transform.localScale *= 10;
_mesh = gameObject.GetComponent<MeshFilter>().mesh;
//mesh.recalculateAllStuff if it is not done before get the mesh
for (int i = 0; i < _mesh.vertexCount; i++)
{
print(_mesh.vertices) //Not right scale
}
我想知道它是如何工作的。
如果你想要缩放点,我认为这会起作用,本地到世界位置:
var scale = 12f;
gameObject.transform.localScale *= scale;
_mesh = gameObject.GetComponent<MeshFilter>().mesh;
for (int i = 0; i < _mesh.vertexCount; i++)
{
print(transform.TransformPoint(_mesh.vertices[i]));
}
如果您想要相对比例点,请尝试将 _mesh.vertices[i] 分量乘以局部比例矢量分量 - 使用 Vector3.Scale:
我试图在缩放游戏对象后从网格中获取缩放的顶点。 游戏对象将在编辑器中缩放打印,但如果我打印网格的顶点,它们将不会缩放。
gameObject.transform.localScale *= 10;
_mesh = gameObject.GetComponent<MeshFilter>().mesh;
//mesh.recalculateAllStuff if it is not done before get the mesh
for (int i = 0; i < _mesh.vertexCount; i++)
{
print(_mesh.vertices) //Not right scale
}
我想知道它是如何工作的。
如果你想要缩放点,我认为这会起作用,本地到世界位置:
var scale = 12f;
gameObject.transform.localScale *= scale;
_mesh = gameObject.GetComponent<MeshFilter>().mesh;
for (int i = 0; i < _mesh.vertexCount; i++)
{
print(transform.TransformPoint(_mesh.vertices[i]));
}
如果您想要相对比例点,请尝试将 _mesh.vertices[i] 分量乘以局部比例矢量分量 - 使用 Vector3.Scale: