blog games developers documentation portfolio gallery



Mesh GameObject.GetSimplifiedMesh(float maxWeight, bool recalcNormals, float removeSmallParts, int nrOfSteps = 1)

Retrieves the sharedMesh from the first MeshFilter or SkinnedMeshRenderer it finds in it's hierarchy and creates a compressed copy for it. The new Mesh is returned. See SetUpLODLevelsWithLODSwitcher for a description of the compression process.

recalcNormals is a bool that is best set to true unless your original mesh has specific normals that should be left alone.

Whenyou use a bigger weight, the result will probably better when the algorithm is allowed to achieve the compression in multiple steps. The number of steps (default 1 can be set to a higher value. The more steps, the longer the process takes, but the better the result.

public class MyEditorPopup : EditorWindow {

void OnGUI() {
if(GUILayout.Button("Compress mesh")) {
Mesh mesh = null;
try {
mesh = Selection.activeGameObject.GetSimplifiedMesh(0.3f, true, 1f);
} catch(Exception e) {
if(mesh != null) {
string meshPath = AssetDatabase.GenerateUniqueAssetPath("Assets/Models/" + + "_Compressed" + ".asset");
AssetDatabase.CreateAsset(mesh, meshPath);
Debug.Log("Your mesh was saved as "+meshPath+" in the project folder");

follow us