Skip to content

Commit

Permalink
temporarily remove blendshape viewer to see if that's the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
enitimeago committed Feb 1, 2024
1 parent ebb25b1 commit 1b25d26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 322 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using enitimeago.NonDestructiveMMD.vendor;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand All @@ -10,7 +8,7 @@

namespace enitimeago.NonDestructiveMMD
{
public class MappingsEditorWindow : BlendshapeViewerEditorWindowBase
public class MappingsEditorWindow : EditorWindow
{
private CommonChecks _commonChecks;
private BlendShapeMappings _dataSource = null;
Expand Down Expand Up @@ -80,7 +78,11 @@ private void OnGUI()
return;
}
var visemeSkinnedMesh = avatar.VisemeSkinnedMesh;
UsingSkinnedMesh(visemeSkinnedMesh);
if (visemeSkinnedMesh == null)
{
GUILayout.Label("Avatar has no face skin mesh!");
return;
}
_faceBlendShapes.Clear();
for (int i = 0; i < visemeSkinnedMesh.sharedMesh.blendShapeCount; i++)
{
Expand All @@ -96,14 +98,6 @@ private void OnGUI()
GUILayout.EndHorizontal();
}

private void OnFocus()
{
if (!autoUpdateOnFocus) return;
if (skinnedMesh == null) return;
if (!HasGenerationParamsChanged()) return;
TryExecuteUpdate();
}

private void DrawLeftPane()
{
GUILayout.BeginVertical("box", GUILayout.Width(150), GUILayout.ExpandHeight(true));
Expand Down Expand Up @@ -133,97 +127,39 @@ private void DrawRightPane()
{
GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

_rightPaneScroll = GUILayout.BeginScrollView(_rightPaneScroll);

if (_currentMmdKeyIndex >= 0 && _faceBlendShapes.Any())
{
GUILayout.Label(string.Format(L.Tr("MappingsEditorWindow:SelectBlendShapeFor"), MMDBlendShapes.Names[_currentMmdKeyIndex]));

var italicLabelStyle = new GUIStyle(GUI.skin.label);
italicLabelStyle.fontStyle = FontStyle.Italic;

// https://forum.unity.com/threads/how-get-packageinfo-by-name-and-version.761936/#post-9171308
var blendshapeViewerPackage = AssetDatabase
.FindAssets("package")
.Select(AssetDatabase.GUIDToAssetPath)
.Where(x => x.EndsWith("package.json"))
.Where(x => AssetDatabase.LoadAssetAtPath<TextAsset>(x) != null)
.Select(s => AssetDatabase.LoadAssetAtPath<TextAsset>(s).text)
.Select(JObject.Parse)
.FirstOrDefault(j => (string)j["name"] == "dev.hai-vr.blendshape-viewer");
GUILayout.Label($"Avatar previews powered by Blendshape Viewer {(string)blendshapeViewerPackage["version"]}", italicLabelStyle);

var serializedObject = new SerializedObject(this);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(showDifferences)));
if (SystemInfo.supportsComputeShaders)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(useComputeShader)));
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.IntSlider(serializedObject.FindProperty(nameof(thumbnailSize)), 100, 300);

EditorGUI.BeginDisabledGroup(skinnedMesh == null || AnimationMode.InAnimationMode());
if (GUILayout.Button("Update"))
{
TryExecuteUpdate();
}
EditorGUI.EndDisabledGroup();

serializedObject.ApplyModifiedProperties();

_rightPaneScroll = GUILayout.BeginScrollView(_rightPaneScroll);

string selectedBlendShape;
_knownBlendShapeMappings.TryGetValue(_currentMmdKeyIndex, out selectedBlendShape);

var width = Mathf.Max(thumbnailSize, MinWidth);
var mod = Mathf.Max(1, (int)position.width / (width + 15));
var shown = 1;
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("None", string.IsNullOrEmpty(selectedBlendShape) ? _hasValueStyle : _defaultStyle))
if (GUILayout.Button("None", string.IsNullOrEmpty(selectedBlendShape) ? _selectedStyle : _defaultStyle))
{
Debug.Log("Unselected blendshape");
_knownBlendShapeMappings.Remove(_currentMmdKeyIndex);
_dataSource.RemoveBlendShapeMapping(MMDBlendShapes.Names[_currentMmdKeyIndex]);
}
for (int i = 0; i < _faceBlendShapes.Count; i++)
{
string blendShapeName = _faceBlendShapes[i];
var texture2D = i < tex2ds.Length ? tex2ds[i] : null;
if (shown % mod == 0)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
}

var buttonStyle = new GUIStyle(blendShapeName == selectedBlendShape ? _hasValueStyle : _defaultStyle);
buttonStyle.imagePosition = ImagePosition.ImageAbove;
var buttonContent = new GUIContent();
buttonContent.image = texture2D;
buttonContent.text = blendShapeName;
if (GUILayout.Button(buttonContent, buttonStyle, GUILayout.Width(width - 25)))
foreach (var blendShapeName in _faceBlendShapes)
{
if (GUILayout.Button(blendShapeName, blendShapeName == selectedBlendShape ? _hasValueStyle : _defaultStyle))
{
Debug.Log("Selected blendshape: " + blendShapeName);
_knownBlendShapeMappings[_currentMmdKeyIndex] = blendShapeName;
_dataSource.SetBlendShapeMapping(MMDBlendShapes.Names[_currentMmdKeyIndex], blendShapeName);
}

if ((shown + 1) % mod == 0 || i == _faceBlendShapes.Count - 1)
{
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}

shown++;
}

GUILayout.EndScrollView();
}
else
{
GUILayout.Label(L.Tr("MappingsEditorWindow:SelectMMDMorph"));
}

GUILayout.EndScrollView();

GUILayout.EndVertical();
}

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1b25d26

Please sign in to comment.