Ejemplo n.º 1
0
        SkinnedMeshRenderer _Erase(GameObject go)
        {
            if (go == null)
            {
                Debug.LogWarning("select root object in hierarchy");
                return(null);
            }
            if (m_skinnedMesh == null)
            {
                Debug.LogWarning("no skinnedmesh");
                return(null);
            }

            var bones      = m_skinnedMesh.bones;
            var eraseBones = m_eraseBones
                             .Where(x => x.Erase)
                             .Select(x => Array.IndexOf(bones, x.Bone))
                             .ToArray();

            var meshNode = new GameObject(BONE_MESH_ERASER_NAME);

            meshNode.transform.SetParent(go.transform, false);

            var erased = meshNode.AddComponent <SkinnedMeshRenderer>();

            erased.sharedMesh      = BoneMeshEraser.CreateErasedMesh(m_skinnedMesh.sharedMesh, eraseBones);
            erased.sharedMaterials = m_skinnedMesh.sharedMaterials;
            erased.bones           = m_skinnedMesh.bones;

            return(erased);
        }
Ejemplo n.º 2
0
        private static bool Execute(GameObject root, SkinnedMeshRenderer smr, List <BoneMeshEraser.EraseBone> eraseBones)
        {
            var bones = smr.bones;

            var meshNode = new GameObject(BONE_MESH_ERASER_NAME);

            meshNode.transform.SetParent(root.transform, false);

            var erased = meshNode.AddComponent <SkinnedMeshRenderer>();

            erased.sharedMesh = BoneMeshEraser.CreateErasedMesh(smr.sharedMesh, eraseBones
                                                                .Where(x => x.Erase)
                                                                .Select(x => Array.IndexOf(bones, x.Bone))
                                                                .ToArray());
            erased.sharedMaterials = smr.sharedMaterials;
            erased.bones           = smr.bones;


            // save mesh to Assets
            var assetPath = string.Format("{0}{1}", root.name, ASSET_SUFFIX);
            var prefab    = GetPrefab(root);

            if (prefab != null)
            {
                var prefabPath = AssetDatabase.GetAssetPath(prefab);
                assetPath = string.Format("{0}/{1}{2}",
                                          Path.GetDirectoryName(prefabPath),
                                          Path.GetFileNameWithoutExtension(prefabPath),
                                          ASSET_SUFFIX
                                          );
            }
            Debug.LogFormat("CreateAsset: {0}", assetPath);
            AssetDatabase.CreateAsset(erased.sharedMesh, assetPath);

            // destroy BoneMeshEraser in the source
            foreach (var skinnedMesh in root.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                if (skinnedMesh.gameObject.name == BONE_MESH_ERASER_NAME)
                {
                    GameObject.DestroyImmediate(skinnedMesh.gameObject);
                }
            }

            // destroy the original mesh in the copied GameObject
            var outputObject = GameObject.Instantiate(root);

            outputObject.name = outputObject.name + "_bone_mesh_erase";
            foreach (var skinnedMesh in outputObject.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                if (skinnedMesh.sharedMesh == smr.sharedMesh)
                {
                    GameObject.DestroyImmediate(skinnedMesh);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        private SkinnedMeshRenderer Remove(GameObject go)
        {
            var bones      = _cSkinnedMesh.bones;
            var eraseBones = _eraseBones
                             .Where(x => x.Erase)
                             .Select(x => Array.IndexOf(bones, x.Bone))
                             .ToArray();

            var meshNode = new GameObject(BoneMeshEraserWizard.BONE_MESH_ERASER_NAME);

            meshNode.transform.SetParent(go.transform, false);

            var erased = meshNode.AddComponent <SkinnedMeshRenderer>();

            erased.sharedMesh      = BoneMeshEraser.CreateErasedMesh(_cSkinnedMesh.sharedMesh, eraseBones);
            erased.sharedMaterials = _cSkinnedMesh.sharedMaterials;
            erased.bones           = _cSkinnedMesh.bones;

            return(erased);
        }