Esempio n. 1
0
        private static Mesh RemoveRotation(Mesh mesh, Matrix4x4 targetRotationMatrix, bool merge)
        {
            Mesh[]            meshes           = MeshUtils.Separate(mesh);
            CombineInstance[] combineInstances = new CombineInstance[meshes.Length];
            for (int i = 0; i < meshes.Length; ++i)
            {
                CombineInstance removeRotation = new CombineInstance();
                removeRotation.mesh         = meshes[i];
                removeRotation.subMeshIndex = 0;
                removeRotation.transform    = targetRotationMatrix;
                combineInstances[i]         = removeRotation;
            }

            //got final mesh without rotation
            mesh = new Mesh();
            mesh.CombineMeshes(combineInstances, merge);
            mesh.RecalculateBounds();
            return(mesh);
        }
Esempio n. 2
0
        private static List <Mesh> GetColliderMeshes(GameObject obj)
        {
            List <Mesh> meshes = new List <Mesh>();

            Collider[] allColliders = obj.GetComponents <Collider>();

            if (allColliders.Length == 0)
            {
                MeshFilter f = obj.GetComponent <MeshFilter>();
                if (f != null)
                {
                    //UNCOMMENT TO INCLUDE OBJECT MESH TO COLLIDER
                    //meshes.AddRange(Separate(f.sharedMesh));
                }
            }
            else
            {
                for (int i = 0; i < allColliders.Length; ++i)
                {
                    MeshCollider meshCollider = allColliders[i] as MeshCollider;
                    if (meshCollider != null)
                    {
                        meshes.AddRange(MeshUtils.Separate(meshCollider.sharedMesh));
                    }
                    else
                    {
                        //Use object's mesh if there is no meshcollider
                        MeshFilter f = obj.GetComponent <MeshFilter>();
                        if (f != null)
                        {
                            meshes.AddRange(MeshUtils.Separate(f.sharedMesh));
                        }
                    }
                }
            }

            return(meshes);
        }
 public void ToCenterOffMass()
 {
     transform.position = MeshUtils.CenterOfMass(m_origin.Target.gameObject);
 }
 public void ToBoundsCenter()
 {
     transform.position = MeshUtils.BoundsCenter(m_origin.Target.gameObject);
 }
Esempio n. 5
0
 public static void SaveMesh()
 {
     GameObject[] selectedObjects = Selection.gameObjects;
     MeshUtils.SaveMesh(selectedObjects, "Battlehub/");
 }