///
        /// MorphTarget List のElement描画
        ///
        static bool DrawMorphTargetBinding(Rect position, SerializedProperty property,
                                           PreviewSceneManager scene, int height)
        {
            bool changed = false;

            if (scene != null)
            {
                var y    = position.y;
                var rect = new Rect(position.x, y, position.width, height);
                int pathIndex;
                if (ExpressionEditorHelper.StringPopup(rect, property.FindPropertyRelative(nameof(MorphTargetBinding.RelativePath)), scene.SkinnedMeshRendererPathList, out pathIndex))
                {
                    changed = true;
                }

                y   += height;
                rect = new Rect(position.x, y, position.width, height);
                int morphTargetIndex;
                if (ExpressionEditorHelper.IntPopup(rect, property.FindPropertyRelative(nameof(MorphTargetBinding.Index)), scene.GetBlendShapeNames(pathIndex), out morphTargetIndex))
                {
                    changed = true;
                }

                y   += height;
                rect = new Rect(position.x, y, position.width, height);
                if (ExpressionEditorHelper.FloatSlider(rect, property.FindPropertyRelative(nameof(MorphTargetBinding.Weight)), 100))
                {
                    changed = true;
                }
            }
            return(changed);
        }
        ///
        /// BlendShape List のElement描画
        ///
        public static bool DrawBlendShapeBinding(Rect position, SerializedProperty property,
                                                 PreviewSceneManager scene)
        {
            bool changed = false;

            if (scene != null)
            {
                var height = 16;

                var y    = position.y;
                var rect = new Rect(position.x, y, position.width, height);
                int pathIndex;
                if (StringPopup(rect, property.FindPropertyRelative("RelativePath"), scene.SkinnedMeshRendererPathList, out pathIndex))
                {
                    changed = true;
                }

                y   += height;
                rect = new Rect(position.x, y, position.width, height);
                int blendShapeIndex;
                if (IntPopup(rect, property.FindPropertyRelative("Index"), scene.GetBlendShapeNames(pathIndex), out blendShapeIndex))
                {
                    changed = true;
                }

                y   += height;
                rect = new Rect(position.x, y, position.width, height);
                if (FloatSlider(rect, property.FindPropertyRelative("Weight"), 100))
                {
                    changed = true;
                }
            }
            return(changed);
        }
示例#3
0
        public override void OnInspectorGUI()
        {
            var changed = false;

            serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            PrefabGUI();
            EditorGUILayout.LabelField("Preview Weight");
            var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f);

            if (m_target.IsBinary)
            {
                previewSlider = Mathf.Round(previewSlider);
            }
            if (previewSlider != m_previewSlider)
            {
                m_previewSlider = previewSlider;
                changed         = true;
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            Separator();

            if (m_scene == null)
            {
                if (m_target.Prefab != null)
                {
                    m_scene = UniVRM10.PreviewSceneManager.GetOrCreate(m_target.Prefab);
                    if (m_scene != null)
                    {
                        m_scene.gameObject.SetActive(false);
                    }
                    Bake();
                }
            }

            if (m_scene != null)
            {
                if (m_serializedEditor == null)
                {
                    m_serializedEditor = new SerializedExpressionEditor(serializedObject, m_scene);
                }
                if (m_serializedEditor.Draw(out VRM10Expression bakeValue))
                {
                    changed = true;
                }
                if (changed)
                {
                    m_scene.Bake(bakeValue, m_previewSlider);
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#4
0
 void ClearScene()
 {
     if (m_scene != null)
     {
         //Debug.LogFormat("OnDestroy");
         m_scene.Clean();
         GameObject.DestroyImmediate(m_scene.gameObject);
         m_scene = null;
     }
 }
示例#5
0
 protected virtual void OnDestroy()
 {
     if (m_scene != null)
     {
         //Debug.LogFormat("OnDestroy");
         m_scene.Clean();
         GameObject.DestroyImmediate(m_scene.gameObject);
         m_scene = null;
     }
 }
示例#6
0
        public static PreviewSceneManager GetOrCreate(GameObject prefab)
        {
            if (prefab == null)
            {
                return(null);
            }

            PreviewSceneManager manager = null;

            // if we already instantiated a PreviewInstance previously but just lost the reference, then use that same instance instead of making a new one
            var managers = GameObject.FindObjectsOfType <PreviewSceneManager>();

            foreach (var x in managers)
            {
                if (x.Prefab == prefab)
                {
                    Debug.LogFormat("find {0}", manager);
                    return(manager);
                }
                Debug.LogFormat("destroy {0}", x);
                GameObject.DestroyImmediate(x.gameObject);
            }

            //Debug.Log("new prefab. instanciate");
            // no previous instance detected, so now let's make a fresh one
            // very important: this loads the PreviewInstance prefab and temporarily instantiates it into PreviewInstance
            var go = GameObject.Instantiate(prefab,
                                            prefab.transform.position,
                                            prefab.transform.rotation
                                            );

            go.name = "__PREVIEW_SCENE_MANGER__";
            manager = go.AddComponent <PreviewSceneManager>();
            manager.Initialize(prefab);

            // HideFlags are special editor-only settings that let you have *secret* GameObjects in a scene, or to tell Unity not to save that temporary GameObject as part of the scene
            foreach (var x in go.transform.Traverse())
            {
                x.gameObject.hideFlags = HideFlags.None
                                         | HideFlags.DontSave
                                         //| HideFlags.DontSaveInBuild
#if VRM_DEVELOP
#else
                                         | HideFlags.HideAndDontSave
#endif
                ;
            }

            return(manager);
        }
        public override void OnInspectorGUI()
        {
            if (PreviewSceneManager == null)
            {
                return;
            }
            serializedObject.Update();

            if (m_serializedEditor == null)
            {
                m_serializedEditor = new SerializedExpressionEditor(serializedObject, PreviewSceneManager);
            }

            EditorGUILayout.BeginHorizontal();

            var changed = false;

            EditorGUILayout.BeginVertical();
            base.OnInspectorGUI();
            EditorGUILayout.LabelField("Preview Weight");
            var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f);

            EditorGUILayout.EndVertical();

            if (m_serializedEditor.IsBinary)
            {
                previewSlider = Mathf.Round(previewSlider);
            }

            if (previewSlider != m_previewSlider)
            {
                m_previewSlider = previewSlider;
                changed         = true;
            }

            EditorGUILayout.EndHorizontal();
            Separator();
            // EditorGUILayout.Space();

            if (m_serializedEditor.Draw(out VRM10Expression bakeValue))
            {
                changed = true;
            }

            if (changed && PreviewSceneManager != null)
            {
                PreviewSceneManager.Bake(bakeValue, m_previewSlider);
            }
        }
示例#8
0
        public SerializedBlendShapeEditor(SerializedObject serializedObject, BlendShapeClip targetObject,
                                          PreviewSceneManager previewSceneManager)
        {
            this.m_serializedObject = serializedObject;
            this.m_targetObject     = targetObject;

            //m_thumbnail = serializedObject.FindProperty("Thumbnail");
            m_blendShapeNameProp = serializedObject.FindProperty("BlendShapeName");
            m_presetProp         = serializedObject.FindProperty("Preset");
            m_isBinaryProp       = serializedObject.FindProperty("IsBinary");
            m_ignoreBlinkProp    = serializedObject.FindProperty("IgnoreBlink");
            m_ignoreLookAtProp   = serializedObject.FindProperty("IgnoreLookAt");
            m_ignoreMouthProp    = serializedObject.FindProperty("IgnoreMouth");

            m_valuesProp = serializedObject.FindProperty("Values");

            m_ValuesList = new ReorderableList(serializedObject, m_valuesProp);
            m_ValuesList.elementHeight       = BlendShapeBindingHeight;
            m_ValuesList.drawElementCallback =
                (rect, index, isActive, isFocused) =>
            {
                var element = m_valuesProp.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y      += 2;
                if (BlendShapeClipEditorHelper.DrawBlendShapeBinding(rect, element, previewSceneManager))
                {
                    m_changed = true;
                }
            };

            m_materialsProp      = serializedObject.FindProperty("MaterialValues");
            m_MaterialValuesList = new ReorderableList(serializedObject, m_materialsProp);
            m_MaterialValuesList.elementHeight       = MaterialValueBindingHeight;
            m_MaterialValuesList.drawElementCallback =
                (rect, index, isActive, isFocused) =>
            {
                var element = m_materialsProp.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y      += 2;
                if (BlendShapeClipEditorHelper.DrawMaterialValueBinding(rect, element, previewSceneManager))
                {
                    m_changed = true;
                }
            };

            m_items = previewSceneManager.EnumRenderItems
                      .Where(x => x.SkinnedMeshRenderer != null)
                      .ToArray();
        }
 public ReorderableMorphTargetBindingList(SerializedObject serializedObject, PreviewSceneManager previewSceneManager, int height)
 {
     m_valuesProp = serializedObject.FindProperty(nameof(VRM10Expression.MorphTargetBindings));
     m_ValuesList = new ReorderableList(serializedObject, m_valuesProp);
     m_ValuesList.elementHeight       = height * 3;
     m_ValuesList.drawElementCallback =
         (rect, index, isActive, isFocused) =>
     {
         var element = m_valuesProp.GetArrayElementAtIndex(index);
         rect.height -= 4;
         rect.y      += 2;
         if (DrawMorphTargetBinding(rect, element, previewSceneManager, height))
         {
             m_changed = true;
         }
     };
 }
示例#10
0
        public SerializedExpressionEditor(SerializedObject serializedObject, VRM10Expression targetObject,
                                          PreviewSceneManager previewSceneManager)
        {
            this.m_serializedObject = serializedObject;
            this.m_targetObject     = targetObject;

            m_isBinaryProp     = serializedObject.FindProperty(nameof(targetObject.IsBinary));
            m_ignoreBlinkProp  = serializedObject.FindProperty(nameof(targetObject.OverrideBlink));
            m_ignoreLookAtProp = serializedObject.FindProperty(nameof(targetObject.OverrideLookAt));
            m_ignoreMouthProp  = serializedObject.FindProperty(nameof(targetObject.OverrideMouth));

            m_morphTargetBindings   = new ReorderableMorphTargetBindingList(serializedObject, previewSceneManager, 20);
            m_materialColorBindings = new ReorderableMaterialColorBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
            m_materialUVBindings    = new ReorderableMaterialUVBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);

            m_items = previewSceneManager.EnumRenderItems
                      .Where(x => x.SkinnedMeshRenderer != null)
                      .ToArray();
        }
示例#11
0
 void OnSelected(BlendShapeClip clip)
 {
     if (PreviewSceneManager == null)
     {
         m_clipEditor = null;
     }
     else if (clip != null)
     {
         m_clipEditor = new SerializedBlendShapeEditor(clip, PreviewSceneManager);
         PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue
         {
             BlendShapeBindings    = clip.Values,
             MaterialValueBindings = clip.MaterialValues,
             Weight = 1.0f
         });
     }
     else
     {
         m_clipEditor = null;
         PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue());
     }
 }
示例#12
0
        public SerializedExpressionEditor(SerializedObject serializedObject, VRM10Expression targetObject,
                                          PreviewSceneManager previewSceneManager, EditorStatus status)
        {
            m_status = status;
            this.m_serializedObject = serializedObject;
            this.m_targetObject     = targetObject;

            m_expressionNameProp = serializedObject.FindProperty("expressionName");
            m_presetProp         = serializedObject.FindProperty("Preset");
            m_isBinaryProp       = serializedObject.FindProperty("IsBinary");
            m_ignoreBlinkProp    = serializedObject.FindProperty("IgnoreBlink");
            m_ignoreLookAtProp   = serializedObject.FindProperty("IgnoreLookAt");
            m_ignoreMouthProp    = serializedObject.FindProperty("IgnoreMouth");

            m_morphTargetBindings   = new ReorderableMorphTargetBindingList(serializedObject, previewSceneManager, 20);
            m_materialColorBindings = new ReorderableMaterialColorBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
            m_materialUVBindings    = new ReorderableMaterialUVBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);

            m_items = previewSceneManager.EnumRenderItems
                      .Where(x => x.SkinnedMeshRenderer != null)
                      .ToArray();
        }
示例#13
0
        //const float FACTOR = 0.1f;

        public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene,
                              float yaw, float pitch, Vector3 position)
        {
            if (scene == null)
            {
                return(null);
            }

            using (var fog = new FogScope())
            {
                m_previewUtility.BeginPreview(r, background); // set up the PreviewRenderUtility's mini internal scene

                // setup the ObjectPreview's camera
                scene.SetupCamera(PreviewCamera, scene.TargetPosition, yaw, pitch, position);

                foreach (var item in scene.EnumRenderItems)
                {
                    // now, actually render out the RenderTexture
                    //RenderMeshPreview(previewMesh, skinMeshRender.sharedMaterials);
                    // submesh support, in case the mesh is made of multiple parts
                    int subMeshCount = item.Mesh.subMeshCount;
                    for (int i = 0; i < subMeshCount; i++)
                    {
                        m_previewUtility.DrawMesh(item.Mesh,
                                                  item.Position, item.Rotation,
                                                  item.Materials[i], i);
                    }
                }

                // VERY IMPORTANT: this manually tells the camera to render and produce the render texture
                PreviewCamera.Render();
                //m_previewUtility.Render(false, false);

                // reset the scene's fog from before
                return(m_previewUtility.EndPreview());
            }
        }
示例#14
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            base.OnInspectorGUI();

            m_mode = GUILayout.Toolbar(m_mode, MODES);
            switch (m_mode)
            {
            case 0:
                m_selector.SelectGUI();
                if (m_clipEditor != null)
                {
                    Separator();
                    var result = m_clipEditor.Draw();
                    if (result.Changed)
                    {
                        PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue
                        {
                            BlendShapeBindings    = result.BlendShapeBindings,
                            MaterialValueBindings = result.MaterialValueBindings,
                            Weight = 1.0f,
                        });
                    }
                }
                break;

            case 1:
                m_clipList.DoLayoutList();
                break;

            default:
                throw new NotImplementedException();
            }

            serializedObject.ApplyModifiedProperties();
        }
        ///
        /// Material List のElement描画
        ///
        public static bool DrawMaterialValueBinding(Rect position, SerializedProperty property,
                                                    PreviewSceneManager scene)
        {
            bool changed = false;

            if (scene != null)
            {
                var height = 16;

                var y    = position.y;
                var rect = new Rect(position.x, y, position.width, height);
                int materialIndex;
                if (StringPopup(rect, property.FindPropertyRelative("MaterialName"), scene.MaterialNames, out materialIndex))
                {
                    changed = true;
                }

                if (materialIndex >= 0)
                {
                    var materialItem = scene.GetMaterialItem(scene.MaterialNames[materialIndex]);
                    if (materialItem != null)
                    {
                        y   += height;
                        rect = new Rect(position.x, y, position.width, height);

                        // プロパティ名のポップアップ
                        int propIndex;
                        if (StringPopup(rect, property.FindPropertyRelative("ValueName"), materialItem.PropNames, out propIndex))
                        {
                            changed = true;
                        }

                        if (propIndex >= 0)
                        {
                            // 有効なプロパティ名が選択された
                            var propItem = materialItem.PropMap[materialItem.PropNames[propIndex]];
                            {
                                switch (propItem.PropertyType)
                                {
                                case ShaderUtil.ShaderPropertyType.Color:
                                {
                                    property.FindPropertyRelative("BaseValue").vector4Value = propItem.DefaultValues;

                                    // max
                                    y   += height;
                                    rect = new Rect(position.x, y, position.width, height);
                                    if (ColorProp(rect, property.FindPropertyRelative("TargetValue")))
                                    {
                                        changed = true;
                                    }
                                }
                                break;

                                case ShaderUtil.ShaderPropertyType.TexEnv:
                                {
                                    property.FindPropertyRelative("BaseValue").vector4Value = propItem.DefaultValues;

                                    // max
                                    y   += height;
                                    rect = new Rect(position.x, y, position.width, height);
                                    if (OffsetProp(rect, property.FindPropertyRelative("TargetValue")))
                                    {
                                        changed = true;
                                    }
                                }
                                break;
                                }
                            }
                        }
                    }
                }
            }
            return(changed);
        }
        public override void OnInspectorGUI()
        {
            if (PreviewSceneManager == null)
            {
                return;
            }
            serializedObject.Update();

            if (m_serializedEditor == null)
            {
                m_serializedEditor = new SerializedBlendShapeEditor(serializedObject, PreviewSceneManager);
                //m_thumbnailProp = serializedObject.FindProperty("Thumbnail");
                m_isBinaryProp = serializedObject.FindProperty("IsBinary");
            }

            EditorGUILayout.BeginHorizontal();

            /*
             * int thumbnailSize = 96;
             * var objectReferenceValue = EditorGUILayout.ObjectField(m_thumbnailProp.objectReferenceValue, typeof(Texture), false,
             *  GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize));
             * if (m_thumbnailProp.objectReferenceValue != objectReferenceValue)
             * {
             *  m_thumbnailProp.objectReferenceValue = objectReferenceValue;
             *  serializedObject.ApplyModifiedProperties();
             * }
             */

            var changed = false;

            EditorGUILayout.BeginVertical();
            base.OnInspectorGUI();
            EditorGUILayout.LabelField("Preview Weight");
            var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f);

            GUI.enabled = PreviewTexture != null;

            /*
             * if (GUILayout.Button("save thumbnail"))
             * {
             *  //var ext = "jpg";
             *  var ext = "png";
             *  var asset = UnityPath.FromAsset(target);
             *  var path = EditorUtility.SaveFilePanel(
             *                 "save thumbnail",
             *                 asset.Parent.FullPath,
             *                 string.Format("{0}.{1}", asset.FileNameWithoutExtension, ext),
             *                 ext);
             *  if (!string.IsNullOrEmpty(path))
             *  {
             *      var thumbnail = SaveResizedImage(PreviewTexture, UnityPath.FromFullpath(path),
             *      BlendShapeClipDrawer.ThumbnailSize);
             *      m_thumbnailProp.objectReferenceValue = thumbnail;
             *      serializedObject.ApplyModifiedProperties();
             *  }
             * }
             */
            GUI.enabled = true;
            EditorGUILayout.EndVertical();

            if (m_isBinaryProp.boolValue)
            {
                previewSlider = Mathf.Round(previewSlider);
            }
            if (previewSlider != m_previewSlider)
            {
                m_previewSlider = previewSlider;
                changed         = true;
            }

            EditorGUILayout.EndHorizontal();
            Separator();
            EditorGUILayout.Space();

            var result = m_serializedEditor.Draw();

            if ((changed || result.Changed) && PreviewSceneManager != null)
            {
                PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue
                {
                    BlendShapeBindings    = result.BlendShapeBindings,
                    MaterialValueBindings = result.MaterialValueBindings,
                    Weight = m_previewSlider
                });
            }
        }
 public SerializedBlendShapeEditor(SerializedObject serializedObject,
                                   PreviewSceneManager previewSceneManager) : this(
         serializedObject, (BlendShapeClip)serializedObject.targetObject, previewSceneManager, EditorStatus.Default)
 {
 }
 public SerializedBlendShapeEditor(BlendShapeClip blendShapeClip,
                                   PreviewSceneManager previewSceneManager, EditorStatus status) : this(
         new SerializedObject(blendShapeClip), blendShapeClip, previewSceneManager, status)
 {
 }
示例#19
0
 public SerializedExpressionEditor(SerializedObject serializedObject,
                                   PreviewSceneManager previewSceneManager) : this(
         serializedObject, (VRM10Expression)serializedObject.targetObject, previewSceneManager, EditorStatus.Default)
 {
 }
示例#20
0
 public SerializedExpressionEditor(VRM10Expression expression,
                                   PreviewSceneManager previewSceneManager, EditorStatus status) : this(
         new SerializedObject(expression), expression, previewSceneManager, status)
 {
 }