Esempio n. 1
0
        public static List <MeshUtility.MeshIntegrationResult> Integrate(GameObject prefab)
        {
            Undo.RecordObject(prefab, "Mesh Integration");
            var instance = SkinnedMeshUtility.InstantiatePrefab(prefab);


            var clips = new List <BlendShapeClip>();
            var proxy = instance.GetComponent <VRMBlendShapeProxy>();

            if (proxy != null && proxy.BlendShapeAvatar != null)
            {
                clips = proxy.BlendShapeAvatar.Clips;
            }
            foreach (var clip in clips)
            {
                Undo.RecordObject(clip, "Mesh Integration");
            }

            // Backup Exists
            BackupVrmPrefab(prefab);

            // Execute
            var results = VRMMeshIntegratorUtility.Integrate(instance, clips);

            foreach (var res in results)
            {
                if (res.IntegratedRenderer == null)
                {
                    continue;
                }

                SaveMeshAsset(res.IntegratedRenderer.sharedMesh, instance, res.IntegratedRenderer.gameObject.name);
                Undo.RegisterCreatedObjectUndo(res.IntegratedRenderer.gameObject, "Integrate Renderers");
            }

            // destroy source renderers
            foreach (var res in results)
            {
                foreach (var renderer in res.SourceSkinnedMeshRenderers)
                {
                    Undo.RecordObject(renderer.gameObject, "Deactivate old renderer");
                    renderer.gameObject.SetActive(false);
                }

                foreach (var renderer in res.SourceMeshRenderers)
                {
                    Undo.RecordObject(renderer.gameObject, "Deactivate old renderer");
                    renderer.gameObject.SetActive(false);
                }
            }

            // Apply to Prefab
            SkinnedMeshUtility.ApplyChangesToPrefab(instance);
            Object.DestroyImmediate(instance);

            return(results);
        }
Esempio n. 2
0
        private static string GetRootPrefabPath(GameObject go)
        {
            var prefab    = SkinnedMeshUtility.IsPrefab(go) ? go : SkinnedMeshUtility.GetPrefab(go);
            var assetPath = "";

            if (prefab != null)
            {
                var prefabPath = AssetDatabase.GetAssetPath(prefab);
                assetPath = string.Format("{0}/", Path.GetDirectoryName(prefabPath));
            }
            else
            {
                assetPath = string.Format("Assets/");
            }
            assetPath = assetPath.Replace(@"\", @"/");
            return(assetPath);
        }
Esempio n. 3
0
        private static void BackupVrmPrefab(GameObject rootPrefab)
        {
            var proxy = rootPrefab.GetComponent <VRMBlendShapeProxy>();

            var srcAvatar = proxy.BlendShapeAvatar;
            var dstAvatar = (BlendShapeAvatar)BackupAsset(srcAvatar, rootPrefab);

            var clipMapper = srcAvatar.Clips.ToDictionary(x => x, x => (BlendShapeClip)BackupAsset(x, rootPrefab));

            dstAvatar.Clips = clipMapper.Values.ToList();

            var dstPrefab   = BackupAsset(rootPrefab, rootPrefab);
            var dstInstance = SkinnedMeshUtility.InstantiatePrefab(dstPrefab);

            dstInstance.GetComponent <VRMBlendShapeProxy>().BlendShapeAvatar = dstAvatar;
            SkinnedMeshUtility.ApplyChangesToPrefab(dstInstance);
            Object.DestroyImmediate(dstInstance);
        }
Esempio n. 4
0
        private static void Foo()
        {
            var go = Selection.activeObject as GameObject;

            Debug.Log(SkinnedMeshUtility.IsPrefab(go));
        }
Esempio n. 5
0
 private static bool ExportValidate()
 {
     return(Selection.activeObject != null &&
            Selection.activeObject is GameObject &&
            SkinnedMeshUtility.IsPrefab(Selection.activeObject));
 }
Esempio n. 6
0
 public static bool IntegrateValidation()
 {
     return(Selection.activeObject != null &&
            Selection.activeObject is GameObject &&
            SkinnedMeshUtility.IsPrefab(Selection.activeObject));
 }