unity网格合并后位置会变

根据官网介绍的mesh.combinemesh中的范例,做了个简单的网格合并的demo,但程序运行后物体的位置发生了变化,研究了好几天都没结果,这是怎么回事啊~~
官网范例如下:

 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;
    }
}
查看全部
qq_14843195
qq_14843195
2015/04/16 01:53
  • 网格合并
  • unity3d
  • 点赞
  • 收藏
  • 回答
    私信

2个回复