如何联合游戏对象网格?
How to unite gameobject meshes?
因为我用 unity 编辑器制作了我的房子,所以我无法删除这个网格边框。我试过 MeshCombiner 但它只是将所有网格连接在一个网格边界仍然存在。我知道我可以用 Blender 或类似的东西制作它,但是有没有人可以从 unity 中删除?
也许您正在寻找 CombineMeshes。一个例子是
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour {
void Start() {
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}
因为我用 unity 编辑器制作了我的房子,所以我无法删除这个网格边框。我试过 MeshCombiner 但它只是将所有网格连接在一个网格边界仍然存在。我知道我可以用 Blender 或类似的东西制作它,但是有没有人可以从 unity 中删除?
也许您正在寻找 CombineMeshes。一个例子是
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour {
void Start() {
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}