在我的代码中,我使用以下代码创建了 2 个矩阵来存储有关两个不同网格的信息:
Mesh mesh;
MeshFilter filter;
public SphereMesh SphereMesh;
public CubeMesh CubeMesh;
public Material pointMaterial;
public Mesh pointMesh;
public List<Matrix4x4> matrices1 = new List<Matrix4x4>();
public List<Matrix4x4> matrices2 = new List<Matrix4x4>();
[Space]
public float normalOffset = 0f;
public float globalScale = 0.1f;
public Vector3 scale = Vector3.one;
public int matricesNumber = 1; //determines which matrices to store info in
public void StorePoints()
{
Vector3[] vertices = mesh.vertices;
Vector3[] normals = mesh.normals;
Vector3 scaleVector = scale * globalScale;
// Initialize chunk indexes.
int startIndex = 0;
int endIndex = Mathf.Min(1023, mesh.vertexCount);
int pointCount = 0;
while (pointCount < mesh.vertexCount)
{
// Create points for the current chunk.
for (int i = startIndex; i < endIndex; i++)
{
var position = transform.position + transform.rotation * vertices[i] + transform.rotation * (normals[i].normalized * normalOffset);
var rotation = Quaternion.identity;
pointCount++;
if (matricesNumber == 1)
{
matrices1.Add(Matrix4x4.TRS(position, rotation, scaleVector));
}
if (matricesNumber == 2)
{
matrices2.Add(Matrix4x4.TRS(position, rotation, scaleVector));
}
rotation = transform.rotation * Quaternion.LookRotation(normals[i]);
}
// Modify start and end index to the range of the next chunk.
startIndex = endIndex;
endIndex = Mathf.Min(startIndex + 1023, mesh.vertexCount);
}
}
GameObject 以立方体网格开始,此代码将有关网格的信息存储在matrices1
. 在未显示代码的其他地方,我有它,以便网格更改为球体,然后更改matricesnumber
为 2,然后触发上面的代码将新球体网格的信息存储在matrices2
.
这似乎是有效的,因为我可以使用像Graphics.DrawMesh(pointMesh, matrices1[i], pointMaterial, 0);
立方体网格的每个顶点绘制 1 个网格这样的代码。我可以使用同一条线(但使用matrices2[i]
)为 Sphere 网格的每个顶点绘制 1 个网格。
问题:如何matrices1
在屏幕上为立方体网格的每个顶点Lerp
(信息存储在matrices2
我正试图用类似的东西来破解它
float t = Mathf.Clamp((Time.time % 2f) / 2f, 0f, 1f);
matrices1.position.Lerp(matrices1.position, matrices2.position, t);
但显然这是无效代码。解决方案可能是什么?谢谢。