Exemple #1
0
        public void Dispose()
        {
            geometry.Dispose();
            if (skin != null)
            {
                skin.Dispose();
            }
            if (morph != null)
            {
                morph.Dispose();
            }

            exportUvs = null;
            mesh      = null;
            geometry  = null;
            morph     = null;
            skin      = null;
            obj       = null;
        }
Exemple #2
0
        // Sets all mesh data, if SkinMeshRenderer provided created new Unity Mesh object to bake current pose of mesh
        // also it's stripped down to null parent to get all coordinates correctly
        // After snapshot it's assembled as provided
        private void getComponentsInfo()
        {
            if (type != MeshType.None)
            {
                Transform parent   = obj.transform.parent;
                Vector3   position = obj.transform.localPosition;
                Vector3   euler    = obj.transform.localEulerAngles;
                Vector3   scale    = obj.transform.localScale;
                obj.transform.parent           = null;
                obj.transform.localPosition    = Vector3.zero;
                obj.transform.localEulerAngles = Vector3.zero;
                obj.transform.localScale       = Vector3.one;

                objName = mesh.name;
                if (type == MeshType.Static)
                {
                    recieveShadows = obj.GetComponent <MeshRenderer>().receiveShadows;
                    castShadows    = obj.GetComponent <MeshRenderer>().castShadows;
                    geometry       = new LoziMeshGeometry(mesh, exportVertexColors, exportUvs);
                }
                if (type == MeshType.Skinned)
                {
                    oldMesh = mesh;
                    if (obj.GetComponent <SkinnedMeshRenderer>().rootBone != null)
                    {
                        Transform rootBone         = obj.GetComponent <SkinnedMeshRenderer>().rootBone;
                        Transform rootBoneParent   = rootBone.parent;
                        Vector3   rootBonePosition = rootBone.transform.localPosition;
                        Vector3   rootBoneEuler    = rootBone.transform.localEulerAngles;
                        Vector3   rootBoneScale    = rootBone.transform.localScale;

                        rootBone.parent = null;
                        rootBone.transform.localPosition    = rootBonePosition;
                        rootBone.transform.localEulerAngles = rootBoneEuler;
                        rootBone.transform.localScale       = rootBoneScale;

                        recieveShadows = obj.GetComponent <SkinnedMeshRenderer>().receiveShadows;
                        castShadows    = obj.GetComponent <SkinnedMeshRenderer>().castShadows;

                        mesh = new Mesh();
                        obj.GetComponent <SkinnedMeshRenderer>().BakeMesh(mesh);

                        geometry = new LoziMeshGeometry(mesh, exportVertexColors, exportUvs);
                        skin     = new LoziMeshSkin(obj.GetComponent <SkinnedMeshRenderer>());
                        morph    = new LoziMeshMorpher(obj.GetComponent <SkinnedMeshRenderer>());

                        rootBone.parent = rootBoneParent;
                        rootBone.transform.localPosition    = rootBonePosition;
                        rootBone.transform.localEulerAngles = rootBoneEuler;
                        rootBone.transform.localScale       = rootBoneScale;
                    }
                    else
                    {
                        geometry = new LoziMeshGeometry(mesh, exportVertexColors, exportUvs);
                        morph    = new LoziMeshMorpher(obj.GetComponent <SkinnedMeshRenderer>());
                    }
                    obj.GetComponent <SkinnedMeshRenderer>().sharedMesh = oldMesh;
                }
                obj.transform.parent           = parent;
                obj.transform.localPosition    = position;
                obj.transform.localEulerAngles = euler;
                obj.transform.localScale       = scale;
            }
        }