- Home /
Combine Meshes Problem
Hello,
I would like to use the Combine Meshes script provided by Unity in order to optimize my game. The problem is that my parent to which I am attaching this script,after combining the meshes, it's changing its position. I read a few answered questions
http://answers.unity3d.com/questions/305080/modify-position-in-transform-matrix.html
but I couldn't understand.
@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)
function Start () {
var meshFilters = GetComponentsInChildren(MeshFilter);
var combine : CombineInstance[] = new CombineInstance[meshFilters.length];
for ( i = 0; i < meshFilters.length; i++){
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
}
transform.GetComponent(MeshFilter).mesh = new Mesh();
transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
How can I cache the position before combining the meshes and then restore it as for my objects to remain untouched ?
did the unity provided code problem solve? i am having same position problem
Answer by AMDAndrew · Dec 28, 2012 at 11:16 AM
Ok, A better way of combining meshes can be found here.
The package is called Draw Call Optimizer,it can be downloaded from Asset Store and if it has errors follow the link http://answers.unity3d.com/questions/370306/no-overload-for-method-x-takes-1-arguments.html
A$$anonymous$$D, something to bear in $$anonymous$$d. Sometimes you have to - for goodness sake - SPLIT meshes.
A typical example is you have a large field (warfield, soccer field, whatever!)
It's actually better to split the bastard up in to a dozen smaller pieces. Then, the various occlusion systems can work better.
Essentially, if something is far away, or even worse, behind the camera! - you don't want to be rendering it right.
So for this reason, in different types of projects and problems, you have to SPLIT meshes, for goodness sake. It's a hassle.
This is something like verbal harrasment. I can't apply any occlusion system because I have the free version. Secondary I have wooden rails and stairs. Why would I split meshes here ?
And finally in the 3rd way my draw calls reduce from 700 to 500 - +10 FPS
A$$anonymous$$, lol sorry you don't have Pro Version. TBC< many times you have to write your OWN occlusion system. Also TBC, I just meant "bear in $$anonymous$$d that" in some projects you $$anonymous$$AY HAVE TO split a mesh!!
It sounds like in this one you've got it perfor$$anonymous$$g awesomely !
Answer by Brain-_-Fail · May 22, 2020 at 05:56 AM
You can check out my tool on the unity asset store "Poly Few" which is a complete optimization solution for Unity aimed at making high quality complex 3d scenes render efficiently. With integrated features like mesh simplification, automatic LOD generation, mesh combining and material combining, you can greatly improve the performance of your game by lowering the Polygon Count, DrawCalls and SetPass calls with a few clicks and, without the need of writing even a single line of code.