问题描述
您好,我正在使用这个人的脚本 https://www.youtube.com/watch? v = wYAlky1aZn4 合并网格物体是因为游戏滞后",或者当游戏运行不平稳时调用的名称.我有带有两个不同网格的34 * 124多维数据集,如果将脚本放在具有34 * 20子级的对象(我之前提到的相同的多维数据集)上,但是如果将其放在具有32 * 124子级的对象上,则所有工作都完美就会将它们变成看起来像34 * 20的立方体.
Hello I am using this guy's script https://www.youtube.com/watch?v=wYAlky1aZn4to combine meshes because the game is "lagging" or whatever it's called when the when it doesn't run smooth. I have 34*124 cubes with two different meshes and all works perfect if I put the script on a object with 34*20 childern (the same cubes that I mentioned before) but if I put it on the object that has 32*124 children it turnes them into something that looks like it has 34*20 cubes.
基本上,如果我将脚本放在更幼稚的东西上,它将变成更小的东西.
Basically it if I put the script on something that has more childern it turns it into something smaller.
这是视频中的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CombineMeshes : MonoBehaviour {
public void Combine(){
Quaternion oldRot = transform.rotation;
Vector3 oldPos = transform.position;
transform.rotation = Quaternion.identity;
transform.position = Vector3.zero;
MeshFilter[] filters = GetComponentsInChildren<MeshFilter> ();
Mesh finalMesh = new Mesh ();
CombineInstance[] combiners = new CombineInstance[filters.Length];
for (int a = 0; a < filters.Length; a++) {
if (filters [a].transform == transform) {
continue;
}
combiners [a].subMeshIndex = 0;
combiners [a].mesh = filters [a].sharedMesh;
combiners [a].transform = filters [a].transform.localToWorldMatrix;
}
finalMesh.CombineMeshes (combiners);
GetComponent<MeshFilter> ().sharedMesh = finalMesh;
transform.rotation = oldRot;
transform.position = oldPos;
for (int a= 0; a < transform.childCount; a++) {
transform.GetChild (a).gameObject.SetActive (false);
}
}
}
推荐答案
这正是您遇到的顶点限制问题.设置后,1个网格只能具有34*20*96 = 65.280
顶点.之后,您需要另一个网格. 124*34*96
使404,736
并超出限制.因此,您需要将网格的格式更改为UInt32
.如果延迟仍然存在,我可以尝试进一步提供帮助.祝你好运!
That is exactly the vertex limit problem you are having. With your set up 1 mesh can have only 34*20*96 = 65.280
vertices. After that you need another mesh. 124*34*96
makes 404,736
and is over the limit. Therefore, you need to change format of your mesh to UInt32
. If the lag continues i can try to help further. Good luck!
这篇关于网格组合器统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!