4 using System.Collections.Generic;
14 SerializedProperty shaderComputeBoneDQ;
15 SerializedProperty shaderDQBlend;
16 SerializedProperty shaderApplyMorph;
17 SerializedProperty bulgeCompensation;
20 SkinnedMeshRenderer smr
24 if (this._smr ==
null)
32 SkinnedMeshRenderer _smr;
34 bool showBlendShapes =
false;
36 enum BoneOrientation {X, Y, Z, negativeX, negativeY, negativeZ}
37 readonly Dictionary<BoneOrientation, Vector3> boneOrientationVectors =
new Dictionary<BoneOrientation, Vector3>();
39 private void OnEnable()
41 this.shaderComputeBoneDQ = this.serializedObject.FindProperty(
"shaderComputeBoneDQ");
42 this.shaderDQBlend = this.serializedObject.FindProperty(
"shaderDQBlend");
43 this.shaderApplyMorph = this.serializedObject.FindProperty(
"shaderApplyMorph");
44 this.bulgeCompensation = this.serializedObject.FindProperty(
"bulgeCompensation");
46 this.boneOrientationVectors.Add(BoneOrientation.X,
new Vector3(1,0,0));
47 this.boneOrientationVectors.Add(BoneOrientation.Y,
new Vector3(0,1,0));
48 this.boneOrientationVectors.Add(BoneOrientation.Z,
new Vector3(0,0,1));
49 this.boneOrientationVectors.Add(BoneOrientation.negativeX,
new Vector3(-1,0,0));
50 this.boneOrientationVectors.Add(BoneOrientation.negativeY,
new Vector3(0,-1,0));
51 this.boneOrientationVectors.Add(BoneOrientation.negativeZ,
new Vector3(0,0,-1));
54 public override void OnInspectorGUI()
56 this.serializedObject.Update();
60 EditorGUILayout.BeginHorizontal();
61 EditorGUILayout.LabelField(
"Mode: ", GUILayout.Width(80));
62 EditorGUILayout.LabelField(Application.isPlaying ?
"Play" :
"Editor", GUILayout.Width(80));
63 EditorGUILayout.EndHorizontal();
65 EditorGUILayout.BeginHorizontal();
66 EditorGUILayout.LabelField(
"DQ skinning: ", GUILayout.Width(80));
67 EditorGUILayout.LabelField(this.dqs.
started ?
"ON" :
"OFF", GUILayout.Width(80));
68 EditorGUILayout.EndHorizontal();
70 EditorGUILayout.Space();
71 this.dqs.
SetViewFrustrumCulling(EditorGUILayout.Toggle(
"View frustrum culling: ",
this.dqs.GetViewFrustrumCulling()));
72 EditorGUILayout.Space();
74 BoneOrientation currentOrientation = BoneOrientation.X;
75 foreach(BoneOrientation orientation
in this.boneOrientationVectors.Keys)
79 currentOrientation = orientation;
83 var newOrientation = (BoneOrientation)EditorGUILayout.EnumPopup(
"Bone orientation: ", currentOrientation);
90 EditorGUILayout.PropertyField(this.bulgeCompensation);
91 EditorGUILayout.Space();
93 this.showBlendShapes = EditorGUILayout.Foldout(this.showBlendShapes,
"Blend shapes");
95 if (this.showBlendShapes)
99 EditorGUI.BeginChangeCheck();
100 Undo.RecordObject(this.dqs.gameObject.GetComponent<SkinnedMeshRenderer>(),
"changed blendshape weights by DualQuaternionSkinner component");
103 for (
int i = 0; i < this.dqs.
mesh.blendShapeCount; i++)
105 EditorGUILayout.BeginHorizontal();
106 EditorGUILayout.LabelField(
" " + this.dqs.
mesh.GetBlendShapeName(i), GUILayout.Width(EditorGUIUtility.labelWidth - 10));
108 EditorGUILayout.EndHorizontal();
113 EditorGUILayout.Space();
115 EditorGUILayout.PropertyField(this.shaderComputeBoneDQ);
116 EditorGUILayout.PropertyField(this.shaderDQBlend);
117 EditorGUILayout.PropertyField(this.shaderApplyMorph);
119 EditorGUILayout.Space();
120 EditorGUILayout.LabelField(
"Problems: ");
122 if (this.CheckProblems() ==
false)
124 EditorGUILayout.LabelField(
"not detected (this is good)");
127 this.serializedObject.ApplyModifiedProperties();
132 var wrapStyle =
new GUIStyle() { wordWrap =
true };
134 if (this.smr.sharedMesh.isReadable ==
false)
136 EditorGUILayout.Space();
137 EditorGUILayout.LabelField(
"Skinned mesh must be read/write enabled (check import settings)", wrapStyle);
141 if (this.smr.rootBone.parent !=
this.dqs.gameObject.transform.parent)
143 EditorGUILayout.Space();
145 EditorGUILayout.BeginHorizontal();
146 EditorGUILayout.LabelField(
"Skinned object and root bone must be children of the same parent", wrapStyle);
147 if (GUILayout.Button(
"auto fix"))
149 Undo.SetTransformParent(
151 this.dqs.gameObject.transform.parent,
152 "Changed root bone's parent by Dual Quaternion Skinner (auto fix)"
154 EditorApplication.RepaintHierarchyWindow();
156 EditorGUILayout.EndHorizontal();
161 foreach(Transform bone
in this.smr.bones)
163 if (bone.localScale != Vector3.one)
165 EditorGUILayout.Space();
167 EditorGUILayout.BeginHorizontal();
168 EditorGUILayout.LabelField(
string.Format(
"Bone scaling not supported: {0}", bone.name), wrapStyle);
169 if (GUILayout.Button(
"auto fix"))
171 Undo.RecordObject(bone,
"Set bone scale to (1,1,1) by Dual Quaternion Skinner (auto fix)");
172 bone.localScale = Vector3.one;
174 EditorGUILayout.EndHorizontal();