Search Unity

Combine mesh position problem

Discussion in 'Scripting' started by augasur, Jul 4, 2013.

  1. augasur

    augasur

    Joined:
    Mar 4, 2012
    Posts:
    133
    Hello,

    I recently started using combine mesh script from Unity Documentation, but I have a problem, my object mesh combines perfectly, but the object position changes to World from local and my object appears near (0,0,0) position, far far away from its real position, where it should be.

    Here is the script which I am using:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4.     @script RequireComponent(MeshFilter)
    5.     @script RequireComponent(MeshRenderer)
    6.    
    7.  
    8.  
    9. function Start () {
    10.  
    11.  
    12.  
    13.      
    14.        
    15.         var meshFilters = GetComponentsInChildren.<MeshFilter>();
    16.         var combine : CombineInstance[] = new CombineInstance[meshFilters.Length];
    17.         for (var i = 0; i < meshFilters.Length; i++){
    18.             combine[i].mesh = meshFilters[i].sharedMesh;
    19.             combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
    20.             meshFilters[i].gameObject.active = false;
    21.         }
    22.        
    23.         transform.GetComponent(MeshFilter).mesh = new Mesh();
    24.        
    25.         transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine);
    26.         transform.gameObject.active = true;
    27.      
    28.        
    29.        
    30.        
    31.        
    32.     }
    33.  

    I have read that people uses InverseTransformPoint http://answers.unity3d.com/questions/305080/modify-position-in-transform-matrix.html# function to fix the position, but I have no idea how to use it. Could give me a hand and help how to sort this problem?
     
    Last edited: Jul 4, 2013
  2. augasur

    augasur

    Joined:
    Mar 4, 2012
    Posts:
    133
    Bump, anyone?
     
  3. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    did problem solve. please share the answer for us