-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from ioramastudio/master
SkinnedMeshOut
- Loading branch information
Showing
10 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace Klak.Wiring | ||
{ | ||
[CanEditMultipleObjects] | ||
[CustomEditor(typeof(SkinnedMeshOut))] | ||
public class SkinnedMeshOutEditor : Editor | ||
{ | ||
SerializedProperty _skinnedMesh; | ||
SerializedProperty _blendShapeIndex; | ||
|
||
void OnEnable() | ||
{ | ||
_skinnedMesh = serializedObject.FindProperty("_skinnedMesh"); | ||
_blendShapeIndex = serializedObject.FindProperty("_blendShapeIndex"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.PropertyField(_skinnedMesh); | ||
|
||
SkinnedMeshRenderer skinnedMesh = _skinnedMesh.objectReferenceValue as SkinnedMeshRenderer; | ||
if (skinnedMesh) | ||
{ | ||
string[] blendShapeNames = GetBlendShapeNames(skinnedMesh.gameObject); | ||
_blendShapeIndex.intValue = EditorGUILayout.Popup("Blend Shape Index", _blendShapeIndex.intValue, blendShapeNames); | ||
} | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
|
||
public string[] GetBlendShapeNames(GameObject obj) | ||
{ | ||
SkinnedMeshRenderer head = obj.GetComponent<SkinnedMeshRenderer>(); | ||
Mesh m = head.sharedMesh; | ||
string[] names = new string[m.blendShapeCount]; | ||
for (int i = 0; i < m.blendShapeCount; i++) | ||
names[i] = m.GetBlendShapeName(i); | ||
|
||
return names; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using UnityEngine; | ||
|
||
namespace Klak.Wiring | ||
{ | ||
[AddComponentMenu("Klak/Wiring/Output/Component/Skinned Mesh Out")] | ||
public class SkinnedMeshOut : NodeBase | ||
{ | ||
#region Editable properties | ||
|
||
[SerializeField] | ||
SkinnedMeshRenderer _skinnedMesh; | ||
|
||
[SerializeField] | ||
int _blendShapeIndex; | ||
|
||
#endregion | ||
|
||
int blendShapeCount; | ||
|
||
#region Node I/O | ||
|
||
[Inlet] | ||
public float weight { | ||
set { | ||
if (!enabled || _skinnedMesh == null) return; | ||
float w = Mathf.Clamp(value * 100, 0, 100); | ||
_skinnedMesh.SetBlendShapeWeight(_blendShapeIndex, w); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.