Ejemplo n.º 1
0
    void OnPreprocessModel()
    {
        // Check if this is the first import. If not, skip.
        if (!assetImporter.importSettingsMissing)
        {
            return;
        }

        if (VRCAssetPreImporterSettings.BlendShapeNormals == VRCAssetPreImporterSettings.BlendShapeNormalsMode.Default)
        {
            // Default settings selected, don't do anything
            return;
        }

        LogAction("[VRCAssetPreprocessor] First import of a model, changing import settings.");

        ModelImporter modelImporter = assetImporter as ModelImporter;

        if (VRCAssetPreImporterSettings.BlendShapeNormals == VRCAssetPreImporterSettings.BlendShapeNormalsMode.Import)
        {
            // Enable import blendshape normals automatically
            modelImporter.importBlendShapeNormals = ModelImporterNormals.Import;
        }
        else if (VRCAssetPreImporterSettings.BlendShapeNormals == VRCAssetPreImporterSettings.BlendShapeNormalsMode.None)
        {
            // Disable blendshape normals automatically
            modelImporter.importBlendShapeNormals = ModelImporterNormals.None;
        }
        else
        {
            // Set "legacy blend shapes" enabled automatically
            PropertyInfo legacyBlendShapeNormalsEnabled = modelImporter.GetType().GetProperty("legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes", BindingFlags.NonPublic | BindingFlags.Instance);
            legacyBlendShapeNormalsEnabled.SetValue(modelImporter, true);
        }
    }
        void OnPreprocessModel()
        {
            // Check if this is the first import. If not, skip.
            if (!assetImporter.importSettingsMissing)
            {
                return;
            }

            LogAction("First import of a model, changing import settings.");


            ModelImporter modelImporter = assetImporter as ModelImporter;

            if (ImporterSettings.BlendShapeNormals != ImporterSettingsEnums.BlendShapeNormalsMode.Default)
            {
                if (ImporterSettings.BlendShapeNormals == ImporterSettingsEnums.BlendShapeNormalsMode.Import)
                {
                    // Enable import blendshape normals automatically
                    modelImporter.importBlendShapeNormals = ModelImporterNormals.Import;
                }
                else if (ImporterSettings.BlendShapeNormals == ImporterSettingsEnums.BlendShapeNormalsMode.None)
                {
                    // Disable blendshape normals automatically
                    modelImporter.importBlendShapeNormals = ModelImporterNormals.None;
                }
                else
                {
                    // Set "legacy blend shapes" enabled automatically
                    PropertyInfo legacyBlendShapeNormalsEnabled = modelImporter.GetType().GetProperty("legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes", BindingFlags.NonPublic | BindingFlags.Instance);
                    legacyBlendShapeNormalsEnabled.SetValue(modelImporter, true);
                }
            }

            // tesselating, are we?
            modelImporter.keepQuads = ImporterSettings.KeepQuads;

            modelImporter.importCameras = ImporterSettings.ImportCameras;

            modelImporter.importTangents = (ModelImporterTangents)ImporterSettings.TangentsMode;
        }
Ejemplo n.º 3
0
        public static void SetAllClipAnimationAvatarMask(ModelImporter importer, GetterIsActivatableTransform logic, int at = -1)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            var mask = new AvatarMask();

            mask.transformCount = importer.transformPaths.Length;
            for (int i = 0; i < mask.transformCount; i++)
            {
                var path = importer.transformPaths[i];
                mask.SetTransformPath(i, path);
                mask.SetTransformActive(i, logic(path));
                //mask.SetTransformActive(i, (!System.IO.Path.GetFileName(path).StartsWith("AttachBone_") || Array.IndexOf(importer.humanDescription.skeleton, path) >= 0));
            }

            var so           = new SerializedObject(importer);
            var updateMethod = importer.GetType().GetMethod("UpdateTransformMask", BindingFlags.NonPublic | BindingFlags.Static);

            SetAllClipAnimationAvatarMask(so, mask, updateMethod, at);
            so.ApplyModifiedProperties();
            so.Dispose();
        }
Ejemplo n.º 4
0
    public static void LoadRoleAnimation()
    {
        foreach (var go in Selection.gameObjects)
        {
            var    path     = AssetDatabase.GetAssetPath(go);
            string filename = System.IO.Path.GetFileNameWithoutExtension(path);
            Debug.Log(path);
            ModelImporter mi = AssetImporter.GetAtPath(path) as ModelImporter;

            ModelImporterClipAnimation[] clips = mi.clipAnimations;
            Debug.Log(clips.Length);
            if (clips.Length == 0)
            {
                clips         = new ModelImporterClipAnimation[1];
                clips[0]      = new ModelImporterClipAnimation();
                clips[0].name = filename;

                AnimationClip orgClip = (AnimationClip)AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip));
                clips[0].firstFrame = 0;
                clips[0].lastFrame  = (int)(orgClip.length * orgClip.frameRate);
            }


            for (int i = 0; i < clips.Length; i++)
            {
                ModelImporterClipAnimation mica = clips[i];

                mica.loopTime                = true;
                mica.loopPose                = false;
                mica.lockRootRotation        = false;
                mica.lockRootPositionXZ      = false;
                mica.lockRootHeightY         = false;
                mica.keepOriginalOrientation = false;
                mica.keepOriginalPositionXZ  = false;
                mica.keepOriginalPositionY   = false;
                mica.maskType                = ClipAnimationMaskType.CopyFromOther;
                mica.maskSource              = (UnityEditor.Animations.AvatarMask)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Role/TGRoleAll.mask", typeof(UnityEditor.Animations.AvatarMask));
            }
            mi.motionNodeName = "Root";
            mi.clipAnimations = clips;

            MethodInfo         updateTransformMaskMethod = mi.GetType().GetMethod("UpdateTransformMask", BindingFlags.NonPublic | BindingFlags.Static);
            SerializedObject   serializedObject          = new SerializedObject(mi);
            SerializedProperty clipAnimationsProperty    = serializedObject.FindProperty("m_ClipAnimations");
            for (int i = 0; i < clips.Length; i++)
            {
                SerializedProperty transformMaskProperty = clipAnimationsProperty.GetArrayElementAtIndex(i).FindPropertyRelative("transformMask");
                updateTransformMaskMethod.Invoke(mi, new System.Object[] { mi.clipAnimations[i].maskSource, transformMaskProperty });
            }
            serializedObject.ApplyModifiedProperties();

            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            AssetDatabase.Refresh();


            var assets = AssetDatabase.LoadAllAssetsAtPath(path);
            foreach (var asset in assets)
            {
                if (asset.GetType() == typeof(AnimationClip))
                {
                    Debug.Log(asset.name);
                    if (asset.name.IndexOf("__preview__") >= 0)
                    {
                        continue;
                    }

                    AnimationClip orgClip   = (AnimationClip)asset;
                    AnimationClip placeClip = new AnimationClip();
                    EditorUtility.CopySerialized(orgClip, placeClip);
                    AssetDatabase.CreateAsset(placeClip, System.IO.Path.GetDirectoryName(path) + "/Resources/" + placeClip.name + ".anim");
                }
            }
        }
    }