'Combine'에 해당되는 글 1건

  1. 2017/10/10 글뻥 How to combine the meshes in child gameobject?
We had to meet Drawcall problem in Mobile game developing using unity 3D.
You should solve it by 2 combination way.

1. Make shard material.
2. Combine mesh.

I writing down about "Combine mesh"

1. Make next script as CombineChild on Unity3D

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class CombineChild : MonoBehaviour
{
void Start()
{
Matrix4x4 thisTransform = transform.worldToLocalMatrix; 
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 = thisTransform * meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.SetActive(false);
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); //, true, true, true);

transform.GetComponent<MeshFilter>().mesh.RecalculateNormals();
transform.gameObject.SetActive(true);
}
}


2. and Please attach to parent gameobject.

Cheers
2017/10/10 02:42 2017/10/10 02:42