Skip to content

Commit

Permalink
Merge pull request #63 from ioramastudio/master
Browse files Browse the repository at this point in the history
SkinnedMeshOut
  • Loading branch information
hoodihoon authored Sep 8, 2023
2 parents 08dd640 + 23a2561 commit 79dee74
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Assets/Klak/Wiring/Basic/Accumulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Accumulator : NodeBase
public float reset {
set {
if (!enabled) return;
_floatValue = 0;
_floatValue = value;
_valueEvent.Invoke(_floatValue);
}
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Klak/Wiring/Basic/FloatAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void TogglePause()

void Start()
{
_isPlaying = _playOnStart;
if (_playOnStart)
_isPlaying = true;
_timeScale = 1;
}

Expand Down
46 changes: 46 additions & 0 deletions Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs
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 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.

2 changes: 1 addition & 1 deletion Assets/Klak/Wiring/Input/BoolInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BoolInput : NodeBase
#region Private members

PropertyInfo _propertyInfo;
float _value;
float _value = float.MaxValue;

void OnEnable()
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Klak/Wiring/Input/FloatInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class FloatInput : NodeBase
#region Private members

PropertyInfo _propertyInfo;
float _value;
float _value = float.MaxValue;

void OnEnable()
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Klak/Wiring/Input/FloatValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public float floatValue {

#endregion

float _prevValue;
float _prevValue = float.MinValue;

#region Monobehaviour

Expand Down
2 changes: 1 addition & 1 deletion Assets/Klak/Wiring/Input/IntInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class IntInput : NodeBase
#region Private members

PropertyInfo _propertyInfo;
float _value;
float _value = float.MaxValue;

void OnEnable()
{
Expand Down
33 changes: 33 additions & 0 deletions Assets/Klak/Wiring/Output/SkinnedMeshOut.cs
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
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Output/SkinnedMeshOut.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79dee74

Please sign in to comment.