diff options
| -rw-r--r-- | Animations/TaSTT_Backplate_Resize_00_to_50.anim (renamed from Animations/TaSTT_Backplate_Expand_00_to_50.anim) | 2 | ||||
| -rw-r--r-- | Animations/TaSTT_Backplate_Resize_100_to_50.anim (renamed from Animations/TaSTT_Backplate_Expand_50_to_100.anim) | 126 | ||||
| -rw-r--r-- | Animations/TaSTT_Backplate_Resize_50_to_00.anim (renamed from Animations/TaSTT_Backplate_Shrink_50_to_00.anim) | 2 | ||||
| -rw-r--r-- | Animations/TaSTT_Backplate_Resize_50_to_100.anim (renamed from Animations/TaSTT_Backplate_Shrink_100_to_50.anim) | 126 | ||||
| -rw-r--r-- | TaSTT.shader | 48 | ||||
| -rw-r--r-- | TaSTT_texture.png | bin | 111292 -> 276085 bytes | |||
| -rw-r--r-- | TaSTT_texture.xcf | bin | 330316 -> 768218 bytes | |||
| -rw-r--r-- | generate.sh | 6 | ||||
| -rw-r--r-- | generate_fx.py | 328 | ||||
| -rw-r--r-- | generate_params.py | 13 | ||||
| -rw-r--r-- | generate_utils.py | 11 | ||||
| -rw-r--r-- | lorum_ipsum.txt | 1 | ||||
| -rw-r--r-- | osc_ctrl.py | 181 |
13 files changed, 478 insertions, 366 deletions
diff --git a/Animations/TaSTT_Backplate_Expand_00_to_50.anim b/Animations/TaSTT_Backplate_Resize_00_to_50.anim index a58f1e6..cfc9354 100644 --- a/Animations/TaSTT_Backplate_Expand_00_to_50.anim +++ b/Animations/TaSTT_Backplate_Resize_00_to_50.anim @@ -6,7 +6,7 @@ AnimationClip: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: TaSTT_Backplate_Expand_00_to_50 + m_Name: TaSTT_Backplate_Resize_00_to_50 serializedVersion: 6 m_Legacy: 0 m_Compressed: 0 diff --git a/Animations/TaSTT_Backplate_Expand_50_to_100.anim b/Animations/TaSTT_Backplate_Resize_100_to_50.anim index bf48cfc..94475b3 100644 --- a/Animations/TaSTT_Backplate_Expand_50_to_100.anim +++ b/Animations/TaSTT_Backplate_Resize_100_to_50.anim @@ -6,7 +6,7 @@ AnimationClip: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: TaSTT_Backplate_Expand_50_to_100 + m_Name: TaSTT_Backplate_Resize_100_to_50 serializedVersion: 6 m_Legacy: 0 m_Compressed: 0 @@ -22,34 +22,6 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 50 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 0.5 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: blendShape.TaSTT_Hide_Backplate - path: CustomSTT - classID: 137 - script: {fileID: 0} - - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 value: 1 inSlope: Infinity outSlope: Infinity @@ -73,6 +45,34 @@ AnimationClip: path: CustomSTT classID: 1 script: {fileID: 0} + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 136 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.5 + value: 50 + inSlope: 0 + outSlope: 0 + tangentMode: 136 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: blendShape.TaSTT_Hide_Backplate + path: CustomSTT + classID: 137 + script: {fileID: 0} m_PPtrCurves: [] m_SampleRate: 60 m_WrapMode: 0 @@ -83,17 +83,17 @@ AnimationClip: genericBindings: - serializedVersion: 2 path: 2794480623 - attribute: 2468111145 + attribute: 2086281974 script: {fileID: 0} - typeID: 137 - customType: 20 + typeID: 1 + customType: 0 isPPtrCurve: 0 - serializedVersion: 2 path: 2794480623 - attribute: 2086281974 + attribute: 2468111145 script: {fileID: 0} - typeID: 1 - customType: 0 + typeID: 137 + customType: 20 isPPtrCurve: 0 pptrCurveMapping: [] m_AnimationClipSettings: @@ -122,34 +122,6 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 50 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 0.5 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: blendShape.TaSTT_Hide_Backplate - path: CustomSTT - classID: 137 - script: {fileID: 0} - - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 value: 1 inSlope: Infinity outSlope: Infinity @@ -173,6 +145,34 @@ AnimationClip: path: CustomSTT classID: 1 script: {fileID: 0} + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 136 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.5 + value: 50 + inSlope: 0 + outSlope: 0 + tangentMode: 136 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: blendShape.TaSTT_Hide_Backplate + path: CustomSTT + classID: 137 + script: {fileID: 0} m_EulerEditorCurves: [] m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 diff --git a/Animations/TaSTT_Backplate_Shrink_50_to_00.anim b/Animations/TaSTT_Backplate_Resize_50_to_00.anim index 1fcacab..35b622e 100644 --- a/Animations/TaSTT_Backplate_Shrink_50_to_00.anim +++ b/Animations/TaSTT_Backplate_Resize_50_to_00.anim @@ -6,7 +6,7 @@ AnimationClip: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: TaSTT_Backplate_Shrink_50_to_00 + m_Name: TaSTT_Backplate_Resize_50_to_00 serializedVersion: 6 m_Legacy: 0 m_Compressed: 0 diff --git a/Animations/TaSTT_Backplate_Shrink_100_to_50.anim b/Animations/TaSTT_Backplate_Resize_50_to_100.anim index bf0edc4..964b279 100644 --- a/Animations/TaSTT_Backplate_Shrink_100_to_50.anim +++ b/Animations/TaSTT_Backplate_Resize_50_to_100.anim @@ -6,7 +6,7 @@ AnimationClip: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: TaSTT_Backplate_Shrink_100_to_50 + m_Name: TaSTT_Backplate_Resize_50_to_100 serializedVersion: 6 m_Legacy: 0 m_Compressed: 0 @@ -22,56 +22,56 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 - inSlope: Infinity - outSlope: Infinity - tangentMode: 103 + value: 50 + inSlope: 0 + outSlope: 0 + tangentMode: 136 weightedMode: 0 - inWeight: 0 - outWeight: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 - serializedVersion: 3 time: 0.5 - value: 1 - inSlope: Infinity - outSlope: Infinity - tangentMode: 103 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 136 weightedMode: 0 - inWeight: 0 - outWeight: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: m_IsActive + attribute: blendShape.TaSTT_Hide_Backplate path: CustomSTT - classID: 1 + classID: 137 script: {fileID: 0} - curve: serializedVersion: 2 m_Curve: - serializedVersion: 3 time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 + value: 1 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 + inWeight: 0 + outWeight: 0 - serializedVersion: 3 time: 0.5 - value: 50 - inSlope: 0 - outSlope: 0 - tangentMode: 136 + value: 1 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 + inWeight: 0 + outWeight: 0 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: blendShape.TaSTT_Hide_Backplate + attribute: m_IsActive path: CustomSTT - classID: 137 + classID: 1 script: {fileID: 0} m_PPtrCurves: [] m_SampleRate: 60 @@ -83,17 +83,17 @@ AnimationClip: genericBindings: - serializedVersion: 2 path: 2794480623 - attribute: 2086281974 + attribute: 2468111145 script: {fileID: 0} - typeID: 1 - customType: 0 + typeID: 137 + customType: 20 isPPtrCurve: 0 - serializedVersion: 2 path: 2794480623 - attribute: 2468111145 + attribute: 2086281974 script: {fileID: 0} - typeID: 137 - customType: 20 + typeID: 1 + customType: 0 isPPtrCurve: 0 pptrCurveMapping: [] m_AnimationClipSettings: @@ -122,56 +122,56 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 - inSlope: Infinity - outSlope: Infinity - tangentMode: 103 + value: 50 + inSlope: 0 + outSlope: 0 + tangentMode: 136 weightedMode: 0 - inWeight: 0 - outWeight: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 - serializedVersion: 3 time: 0.5 - value: 1 - inSlope: Infinity - outSlope: Infinity - tangentMode: 103 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 136 weightedMode: 0 - inWeight: 0 - outWeight: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: m_IsActive + attribute: blendShape.TaSTT_Hide_Backplate path: CustomSTT - classID: 1 + classID: 137 script: {fileID: 0} - curve: serializedVersion: 2 m_Curve: - serializedVersion: 3 time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 + value: 1 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 + inWeight: 0 + outWeight: 0 - serializedVersion: 3 time: 0.5 - value: 50 - inSlope: 0 - outSlope: 0 - tangentMode: 136 + value: 1 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 + inWeight: 0 + outWeight: 0 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: blendShape.TaSTT_Hide_Backplate + attribute: m_IsActive path: CustomSTT - classID: 137 + classID: 1 script: {fileID: 0} m_EulerEditorCurves: [] m_HasGenericRootTransform: 0 diff --git a/TaSTT.shader b/TaSTT.shader index 3e1e19a..fb16779 100644 --- a/TaSTT.shader +++ b/TaSTT.shader @@ -1,4 +1,4 @@ -Shader "Unlit/my_shader"
+Shader "Unlit/TaSTT"
{
Properties
{
@@ -108,6 +108,8 @@ Pass
{
+ Blend SrcAlpha OneMinusSrcAlpha
+
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
@@ -127,7 +129,8 @@ float4 vertex : SV_POSITION;
};
- sampler2D _MainTex;
+ Texture2D _MainTex;
+ SamplerState sampler_linear_repeat;
float4 _MainTex_ST;
float _Letter_Row00_Col00;
@@ -237,44 +240,31 @@ // Write the nth letter in the current cell and return the value of the
// pixel.
- float2 GetLetter(v2f i, float nth_letter)
+ float2 GetLetter(v2f i, int nth_letter)
{
// UV spans from [0,1] to [0,1].
// 'U' is horizontal; cols.
// 'V' is vertical; rows.
//
// I want to divide the mesh into an m x n grid.
- // Thus given UV, I need to know a few things:
- // 1. What grid cell I'm in. This is simply u * m, v * n.
- float CHAR_ROWS = 6.0;
- float CHAR_COLS = 16.0;
- float CHAR_COL = floor(i.uv.x * CHAR_COLS);
- float CHAR_ROW = floor(i.uv.y * CHAR_ROWS);
+ // I want to know what grid cell I'm in. This is simply u * m, v * n.
+ int CHAR_ROWS = 6;
+ int CHAR_COLS = 16;
// OK, I know what cell I'm in. Now I need to know how far across it I
- // am.
- float CHAR_FRAC_COL = fmod(i.uv.x, 1.0 / CHAR_COLS) / (1.0 / CHAR_COLS);
- float CHAR_FRAC_ROW = fmod(i.uv.y, 1.0 / CHAR_ROWS) / (1.0 / CHAR_ROWS);
-
- // TODO(yum_food) figure out what's causing the outlines around letters
- // and remove this. This simply reduces the size of the outlines.
- float kappa = 0.01;
- if (CHAR_FRAC_COL < kappa || CHAR_FRAC_ROW < kappa ||
- CHAR_FRAC_COL > 1 - kappa || CHAR_FRAC_ROW > 1 - kappa) {
- return float2(0, 0);
- }
+ // am. Produce a float in the range [0, CHAR_COLS).
+ float CHAR_FRAC_COL = i.uv.x * CHAR_COLS - floor(i.uv.x * CHAR_COLS);
+ float CHAR_FRAC_ROW = i.uv.y * CHAR_ROWS - floor(i.uv.y * CHAR_ROWS);
+ // This is the number of rows and columns in the actual texture.
float LETTER_COLS = 26.6;
float LETTER_ROWS = 11.4;
+
float LETTER_COL = fmod(nth_letter, floor(LETTER_COLS));
float LETTER_ROW = floor(LETTER_ROWS) - floor(nth_letter / floor(LETTER_COLS));
- float LETTER_UV_WD = (1.0 / LETTER_COLS);
- float LETTER_UV_COL = (LETTER_UV_WD * LETTER_COL);
- float LETTER_UV_HT = (1.0 / LETTER_ROWS);
- float LETTER_UV_ROW = (LETTER_UV_HT * LETTER_ROW);
- LETTER_UV_ROW += LETTER_UV_HT * CHAR_FRAC_ROW - LETTER_UV_HT * 0.6;
- LETTER_UV_COL += LETTER_UV_WD * CHAR_FRAC_COL;
+ float LETTER_UV_ROW = (LETTER_ROW + CHAR_FRAC_ROW - 0.6) / LETTER_ROWS;
+ float LETTER_UV_COL = (LETTER_COL + CHAR_FRAC_COL) / LETTER_COLS;
float2 uv;
uv.x = LETTER_UV_COL;
@@ -505,11 +495,7 @@ {
float letter = GetLetterParameter(i);
float2 uv = GetLetter(i, letter);
- fixed4 ret = tex2D(_MainTex, uv);
- if (uv.x == 0 || uv.y == 0 || uv.x == 1 || uv.y == 1) {
- ret.xyz = 0;
- ret.w = 0;
- }
+ fixed4 ret = _MainTex.Sample(sampler_linear_repeat, uv);
return ret;
}
ENDCG
diff --git a/TaSTT_texture.png b/TaSTT_texture.png Binary files differindex cf86821..804500c 100644 --- a/TaSTT_texture.png +++ b/TaSTT_texture.png diff --git a/TaSTT_texture.xcf b/TaSTT_texture.xcf Binary files differindex 7c84e56..a980f5d 100644 --- a/TaSTT_texture.xcf +++ b/TaSTT_texture.xcf diff --git a/generate.sh b/generate.sh index a476f24..2d668b0 100644 --- a/generate.sh +++ b/generate.sh @@ -6,12 +6,14 @@ set -o xtrace echo 'Generating animations' -./generate_animations +./generate_animations.sh +set +o xtrace echo 'Tab into unity and wait for it to import animations, then press enter.' echo echo 'This is necessary because the FX layer will reference animations by ' -echo 'their Unity GUID which is generated during import.' +echo 'their Unity GUID, which is generated during import.' +set -o xtrace read -r line echo 'Generating FX layer' diff --git a/generate_fx.py b/generate_fx.py index 28d6550..36779b7 100644 --- a/generate_fx.py +++ b/generate_fx.py @@ -17,6 +17,8 @@ from generate_utils import replaceMacros from generate_utils import getDummyParam +from generate_utils import getResize0Param +from generate_utils import getResize1Param from generate_utils import getLayerParam from generate_utils import getSelectParam from generate_utils import getEnableParam @@ -25,6 +27,8 @@ from generate_utils import getAnimationPath from generate_utils import NUM_LAYERS from generate_utils import CHARS_PER_CELL +import generate_utils + # To debug, I recommend setting these values low and manually moving things # around in the animator. Then run using Lyuma's avatar 3.0 emulator. NUM_LETTERS=80 @@ -113,120 +117,6 @@ ANIMATOR_LAYER_TASTT = """ m_Controller: {fileID: %ANIMATOR_HEADER_U2%} """[1:][:-1] -GROUP_NAMES = [ - "_Letter_Row00_Col00_03", - "_Letter_Row00_Col04_07", - "_Letter_Row00_Col08_11", - "_Letter_Row00_Col12_13", - "_Letter_Row01_Col00_03", - "_Letter_Row01_Col04_07", - "_Letter_Row01_Col08_11", - "_Letter_Row01_Col12_13", - "_Letter_Row02_Col00_03", - "_Letter_Row02_Col04_07", - "_Letter_Row02_Col08_11", - "_Letter_Row02_Col12_13", - "_Letter_Row03_Col00_03", - "_Letter_Row03_Col04_07", - "_Letter_Row03_Col08_11", - "_Letter_Row03_Col12_13", - "_Letter_Row04_Col00_03", - "_Letter_Row04_Col04_07", - "_Letter_Row04_Col08_11", - "_Letter_Row04_Col12_13", - "_Letter_Row05_Col00_03", - "_Letter_Row05_Col04_07", - "_Letter_Row05_Col08_11", - "_Letter_Row05_Col12_13", - ] - -CELL_NAMES = [ - "_Letter_Row00_Col00", - "_Letter_Row00_Col01", - "_Letter_Row00_Col02", - "_Letter_Row00_Col03", - "_Letter_Row00_Col04", - "_Letter_Row00_Col05", - "_Letter_Row00_Col06", - "_Letter_Row00_Col07", - "_Letter_Row00_Col08", - "_Letter_Row00_Col09", - "_Letter_Row00_Col10", - "_Letter_Row00_Col11", - "_Letter_Row00_Col12", - "_Letter_Row00_Col13", - "_Letter_Row01_Col00", - "_Letter_Row01_Col01", - "_Letter_Row01_Col02", - "_Letter_Row01_Col03", - "_Letter_Row01_Col04", - "_Letter_Row01_Col05", - "_Letter_Row01_Col06", - "_Letter_Row01_Col07", - "_Letter_Row01_Col08", - "_Letter_Row01_Col09", - "_Letter_Row01_Col10", - "_Letter_Row01_Col11", - "_Letter_Row01_Col12", - "_Letter_Row01_Col13", - "_Letter_Row02_Col00", - "_Letter_Row02_Col01", - "_Letter_Row02_Col02", - "_Letter_Row02_Col03", - "_Letter_Row02_Col04", - "_Letter_Row02_Col05", - "_Letter_Row02_Col06", - "_Letter_Row02_Col07", - "_Letter_Row02_Col08", - "_Letter_Row02_Col09", - "_Letter_Row02_Col10", - "_Letter_Row02_Col11", - "_Letter_Row02_Col12", - "_Letter_Row02_Col13", - "_Letter_Row03_Col00", - "_Letter_Row03_Col01", - "_Letter_Row03_Col02", - "_Letter_Row03_Col03", - "_Letter_Row03_Col04", - "_Letter_Row03_Col05", - "_Letter_Row03_Col06", - "_Letter_Row03_Col07", - "_Letter_Row03_Col08", - "_Letter_Row03_Col09", - "_Letter_Row03_Col10", - "_Letter_Row03_Col11", - "_Letter_Row03_Col12", - "_Letter_Row03_Col13", - "_Letter_Row04_Col00", - "_Letter_Row04_Col01", - "_Letter_Row04_Col02", - "_Letter_Row04_Col03", - "_Letter_Row04_Col04", - "_Letter_Row04_Col05", - "_Letter_Row04_Col06", - "_Letter_Row04_Col07", - "_Letter_Row04_Col08", - "_Letter_Row04_Col09", - "_Letter_Row04_Col10", - "_Letter_Row04_Col11", - "_Letter_Row04_Col12", - "_Letter_Row04_Col13", - "_Letter_Row05_Col00", - "_Letter_Row05_Col01", - "_Letter_Row05_Col02", - "_Letter_Row05_Col03", - "_Letter_Row05_Col04", - "_Letter_Row05_Col05", - "_Letter_Row05_Col06", - "_Letter_Row05_Col07", - "_Letter_Row05_Col08", - "_Letter_Row05_Col09", - "_Letter_Row05_Col10", - "_Letter_Row05_Col11", - "_Letter_Row05_Col12", - "_Letter_Row05_Col13", - ] - def genAnimator(state): print(replaceMacros(ANIMATOR_HEADER, params)) print(ANIMATOR_PARAMETER_HEADER) @@ -234,6 +124,15 @@ def genAnimator(state): params["ANIMATOR_PARAMETER_NAME"] = getDummyParam() print(replaceMacros(ANIMATOR_PARAMETER_BOOL, params)) + params["ANIMATOR_PARAMETER_NAME"] = generate_utils.getResizeEnableParam() + print(replaceMacros(ANIMATOR_PARAMETER_BOOL, params)) + + params["ANIMATOR_PARAMETER_NAME"] = generate_utils.getResize0Param() + print(replaceMacros(ANIMATOR_PARAMETER_BOOL, params)) + + params["ANIMATOR_PARAMETER_NAME"] = generate_utils.getResize1Param() + print(replaceMacros(ANIMATOR_PARAMETER_BOOL, params)) + for i in range(0, NUM_LAYERS): params["ANIMATOR_PARAMETER_NAME"] = getLayerParam(i) print(replaceMacros(ANIMATOR_PARAMETER_INT, params)) @@ -258,6 +157,11 @@ def genAnimator(state): params["TASTT_LAYER_U2"] = params[getLayerParam(i) + "_LAYER_U2"] params["TASTT_LAYER_NAME"] = getLayerParam(i) print(replaceMacros(ANIMATOR_LAYER_TASTT, params)) + + params["TASTT_RESIZE_LAYER_U2"] = get_u2("1107", state) + params["TASTT_LAYER_U2"] = params["TASTT_RESIZE_LAYER_U2"] + params["TASTT_LAYER_NAME"] = "TaSTT_Resize" + print(replaceMacros(ANIMATOR_LAYER_TASTT, params)) genAnimator(state) TASTT_LAYER_HEADER = """ @@ -363,36 +267,6 @@ AnimatorState: m_TimeParameter: """[1:][:-1] -TASTT_UNARY_STATE = """ ---- !u!%ANIMATOR_STATE_U% &%TASTT_STATE_U2% -AnimatorState: - serializedVersion: 6 - m_ObjectHideFlags: 1 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: %TASTT_STATE_NAME% - m_Speed: 1 - m_CycleOffset: 0 - m_Transitions: - - {fileID: %TASTT_STATE_TRANSITION_U2%} - m_StateMachineBehaviours: [] - m_Position: {x: 50, y: 50, z: 0} - m_IKOnFeet: 0 - m_WriteDefaultValues: 0 - m_Mirror: 0 - m_SpeedParameterActive: 0 - m_MirrorParameterActive: 0 - m_CycleOffsetParameterActive: 0 - m_TimeParameterActive: 0 - m_Motion: {fileID: 0} - m_Tag: - m_SpeedParameter: - m_MirrorParameter: - m_CycleOffsetParameter: - m_TimeParameter: -"""[1:][:-1] - TASTT_NARY_STATE_HEADER = """ --- !u!%ANIMATOR_STATE_U% &%TASTT_STATE_U2% AnimatorState: @@ -437,7 +311,7 @@ TASTT_NARY_STATE_FOOTER = """ # %TASTT_ROW_STATE_U2% - address of row state we're transitioning to # A bizarre quirk: when branching false, m_ConditionMode = 2; else # m_ConditionMode = 1. -TASTT_BOOL_STATE_TRANSITION = """ +TASTT_BOOL_STATE_UNARY_TRANSITION = """ --- !u!1101 &%TASTT_STATE_TRANSITION_U2% AnimatorStateTransition: m_ObjectHideFlags: 1 @@ -465,6 +339,37 @@ AnimatorStateTransition: m_CanTransitionToSelf: 1 """[1:][:-1] +TASTT_BOOL_STATE_BINARY_TRANSITION = """ +--- !u!1101 &%TASTT_STATE_TRANSITION_U2% +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: %MODE0% + m_ConditionEvent: %BOOL_PARAM0% + m_EventTreshold: %THRESHOLD0% + - m_ConditionMode: %MODE1% + m_ConditionEvent: %BOOL_PARAM1% + m_EventTreshold: %THRESHOLD1% + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: %DST_STATE_U2%} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 1.0 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 +"""[1:][:-1] + TASTT_INT_STATE_TRANSITION = """ --- !u!1101 &%TASTT_STATE_TRANSITION_U2% AnimatorStateTransition: @@ -483,7 +388,7 @@ AnimatorStateTransition: m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0.02 + m_TransitionDuration: 0.1 m_TransitionOffset: 0 m_ExitTime: 0.75 m_HasExitTime: 0 @@ -500,7 +405,7 @@ AnimatorStateTransition: # %TASTT_ANIM_GUID%: GUID of the animation to play # %TASTT_RESTART_TRANSITION_U2%: U2 of transition back to # TaSTT_Do_Nothing. -TASTT_LETTER_STATE = """ +TASTT_ANIM_STATE = """ --- !u!1102 &%TASTT_STATE_U2% AnimatorState: serializedVersion: 6 @@ -564,7 +469,7 @@ def getAnimationGuid(anim_meta_filename): if "guid" in line: return line.split()[1] -def getDefaultStateName(which_layer): +def getDefaultStateName(): return "TaSTT_Do_Nothing" def getActiveStateName(which_layer): @@ -582,30 +487,33 @@ def getS2StateName(which_layer, s0, s1, s2): def getLetterStateName(which_layer, s0, s1, s2, letter): return "TaSTT_S%02d_S%02d_S%02d_L%03d" % (s0, s1, s2, letter) +def getResizeStateName(e0, e1): + return "TaSTT_Resize_E%d_E%d" % (e0, e1) + def genTasttLayer(state, which_layer): # Generate return-home transition params["TASTT_RETURN_HOME_TRANSITION_%02d_U2" % which_layer] = get_u2("1101", state) params["TASTT_STATE_TRANSITION_U2"] = params["TASTT_RETURN_HOME_TRANSITION_%02d_U2" % which_layer] params["BOOL_PARAM"] = getDummyParam() params["THRESHOLD"] = str(0) - params["MODE"] = str(2) # See comment above TASTT_BOOL_STATE_TRANSITION. - params["DEFAULT_STATE_U2"] = get_u2("1102", state) - params["DST_STATE_U2"] = params["DEFAULT_STATE_U2"] - print(replaceMacros(TASTT_BOOL_STATE_TRANSITION, params)) + params["MODE"] = str(2) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. + params["TASTT_DEFAULT_STATE_U2"] = get_u2("1102", state) + params["DST_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) # Default state. - params["TASTT_STATE_U2"] = params["DEFAULT_STATE_U2"] - params["TASTT_STATE_NAME"] = getDefaultStateName(which_layer) + params["TASTT_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] + params["TASTT_STATE_NAME"] = getDefaultStateName() params["TASTT_STATE_TRANSITION_U2"] = get_u2("1101", state) print(replaceMacros(TASTT_UNARY_STATE, params)) # Active state transition. params["BOOL_PARAM"] = getEnableParam(which_layer) params["THRESHOLD"] = str(1) - params["MODE"] = str(1) # See comment above TASTT_BOOL_STATE_TRANSITION. + params["MODE"] = str(1) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. params["ACTIVE_STATE_U2"] = get_u2("1102", state) params["DST_STATE_U2"] = params["ACTIVE_STATE_U2"] - print(replaceMacros(TASTT_BOOL_STATE_TRANSITION, params)) + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) # Active state. params["TASTT_STATE_U2"] = params["ACTIVE_STATE_U2"] @@ -621,10 +529,10 @@ def genTasttLayer(state, which_layer): params["TASTT_STATE_TRANSITION_U2"] = params[getS0StateName(which_layer, s0) + "_TRANSITION_U2"] params["BOOL_PARAM"] = getSelectParam(which_layer, 0) params["THRESHOLD"] = str(s0) - params["MODE"] = str(2 - s0) # See comment above TASTT_BOOL_STATE_TRANSITION. + params["MODE"] = str(2 - s0) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. params[getS0StateName(which_layer, s0) + "_U2"] = get_u2("1102", state) params["DST_STATE_U2"] = params[getS0StateName(which_layer, s0) + "_U2"] - print(replaceMacros(TASTT_BOOL_STATE_TRANSITION, params)) + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) # S0 state. for s0 in range(0,2): @@ -642,10 +550,10 @@ def genTasttLayer(state, which_layer): params["TASTT_STATE_TRANSITION_U2"] = params[getS1StateName(which_layer, s0, s1) + "_TRANSITION_U2"] params["BOOL_PARAM"] = getSelectParam(which_layer, 1) params["THRESHOLD"] = str(s1) - params["MODE"] = str(2 - s1) # See comment above TASTT_BOOL_STATE_TRANSITION. + params["MODE"] = str(2 - s1) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. params[getS1StateName(which_layer, s0, s1) + "_U2"] = get_u2("1102", state) params["DST_STATE_U2"] = params[getS1StateName(which_layer, s0, s1) + "_U2"] - print(replaceMacros(TASTT_BOOL_STATE_TRANSITION, params)) + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) # S1 state. for s0 in range(0,2): @@ -665,10 +573,10 @@ def genTasttLayer(state, which_layer): params["TASTT_STATE_TRANSITION_U2"] = params[getS2StateName(which_layer, s0, s1, s2) + "_TRANSITION_U2"] params["BOOL_PARAM"] = getSelectParam(which_layer, 2) params["THRESHOLD"] = str(s2) - params["MODE"] = str(2 - s2) # See comment above TASTT_BOOL_STATE_TRANSITION. + params["MODE"] = str(2 - s2) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. params[getS2StateName(which_layer, s0, s1, s2) + "_U2"] = get_u2("1102", state) params["DST_STATE_U2"] = params[getS2StateName(which_layer, s0, s1, s2) + "_U2"] - print(replaceMacros(TASTT_BOOL_STATE_TRANSITION, params)) + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) # S2 state. for s0 in range(0,2): @@ -705,7 +613,7 @@ def genTasttLayer(state, which_layer): params["TASTT_STATE_TRANSITION_U2"] = params["TASTT_RETURN_HOME_TRANSITION_%02d_U2" % which_layer] anim_meta_filename = getAnimationPath(getShaderParam(which_layer, s0, s1, s2), letter) + ".meta" params["TASTT_ANIM_GUID"] = getAnimationGuid(anim_meta_filename) - print(replaceMacros(TASTT_LETTER_STATE, params)) + print(replaceMacros(TASTT_ANIM_STATE, params)) # TaSTT layer. params["TASTT_LAYER_U2"] = params[getLayerParam(which_layer) + "_LAYER_U2"] @@ -713,7 +621,7 @@ def genTasttLayer(state, which_layer): params["TASTT_LAYER_NAME"] = getLayerParam(which_layer) print(replaceMacros(TASTT_LAYER_HEADER, params)) - params["TASTT_STATE_U2"] = params["DEFAULT_STATE_U2"] + params["TASTT_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] print(replaceMacros(TASTT_LAYER_HEADER_CHILD_STATE, params)) params["TASTT_STATE_U2"] = params["ACTIVE_STATE_U2"] @@ -741,8 +649,98 @@ def genTasttLayer(state, which_layer): params["TASTT_STATE_U2"] = params[getLetterStateName(which_layer, s0, s1, s2, letter) + "_U2"] print(replaceMacros(TASTT_LAYER_HEADER_CHILD_STATE, params)) - params["TASTT_DEFAULT_STATE_U2"] = params["DEFAULT_STATE_U2"] + params["TASTT_DEFAULT_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] print(replaceMacros(TASTT_LAYER_FOOTER, params)) for i in range(0, NUM_LAYERS): genTasttLayer(state, i) + +def genTasttResizeLayer(state): + # Generate return-home transition + params["TASTT_RETURN_HOME_TRANSITION_U2"] = get_u2("1101", state) + params["TASTT_STATE_TRANSITION_U2"] = params["TASTT_RETURN_HOME_TRANSITION_U2"] + params["BOOL_PARAM"] = getDummyParam() + params["THRESHOLD"] = str(0) + params["MODE"] = str(2) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. + params["TASTT_DEFAULT_STATE_U2"] = get_u2("1102", state) + params["DST_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) + + # Default state. + params["TASTT_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] + params["TASTT_STATE_NAME"] = getDefaultStateName() + params["TASTT_STATE_TRANSITION_U2"] = get_u2("1101", state) + print(replaceMacros(TASTT_UNARY_STATE, params)) + + # Active state transition. + params["BOOL_PARAM"] = generate_utils.getResizeEnableParam() + params["THRESHOLD"] = str(1) + params["MODE"] = str(1) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. + params["ACTIVE_STATE_U2"] = get_u2("1102", state) + params["DST_STATE_U2"] = params["ACTIVE_STATE_U2"] + print(replaceMacros(TASTT_BOOL_STATE_UNARY_TRANSITION, params)) + + # Active state. + params["TASTT_STATE_U2"] = params["ACTIVE_STATE_U2"] + params["TASTT_STATE_NAME"] = "TaSTT_Resize_Enabled" + print(replaceMacros(TASTT_NARY_STATE_HEADER, params)) + + for e0 in range(0, 2): + for e1 in range(0, 2): + params[getResizeStateName(e0, e1) + "_TRANSITION_U2"] = get_u2("1101", state) + params["TASTT_STATE_TRANSITION_U2"] = params[getResizeStateName(e0, e1) + "_TRANSITION_U2"] + print(replaceMacros(TASTT_NARY_STATE_HEADER_TRANSITION, params)) + + print(replaceMacros(TASTT_NARY_STATE_FOOTER, params)) + + # Animation transitions. + for e0 in range(0, 2): + params["THRESHOLD0"] = str(e0) + params["BOOL_PARAM0"] = generate_utils.getResize0Param() + params["MODE0"] = str(2 - e0) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. + for e1 in range(0, 2): + params["THRESHOLD1"] = str(e1) + params["BOOL_PARAM1"] = generate_utils.getResize1Param() + params["MODE1"] = str(2 - e1) # See comment above TASTT_BOOL_STATE_UNARY_TRANSITION. + + params["TASTT_STATE_TRANSITION_U2"] = params[getResizeStateName(e0, e1) + "_TRANSITION_U2"] + + params[getResizeStateName(e0, e1) + "_U2"] = get_u2("1102", state) + params["DST_STATE_U2"] = params[getResizeStateName(e0, e1) + "_U2"] + + print(replaceMacros(TASTT_BOOL_STATE_BINARY_TRANSITION, params)) + + # Animation states. + for e0 in range(0, 2): + for e1 in range(0, 2): + params["TASTT_STATE_NAME"] = getResizeStateName(e0, e1) + params["TASTT_STATE_U2"] = params[getResizeStateName(e0, e1) + "_U2"] + params["TASTT_STATE_TRANSITION_U2"] = params["TASTT_RETURN_HOME_TRANSITION_U2"] + anim_meta_filename="Animations/" + if e0 == 0 and e1 == 0: + anim_meta_filename += "TaSTT_Backplate_Resize_00_to_50.anim.meta" + elif e0 == 0 and e1 == 1: + anim_meta_filename += "TaSTT_Backplate_Resize_50_to_100.anim.meta" + elif e0 == 1 and e1 == 0: + anim_meta_filename += "TaSTT_Backplate_Resize_100_to_50.anim.meta" + elif e0 == 1 and e1 == 1: + anim_meta_filename += "TaSTT_Backplate_Resize_50_to_00.anim.meta" + params["TASTT_ANIM_GUID"] = getAnimationGuid(anim_meta_filename) + print(replaceMacros(TASTT_ANIM_STATE, params)) + + # Layer + params["TASTT_LAYER_U2"] = params["TASTT_RESIZE_LAYER_U2"] + params["TASTT_LAYER_NAME"] = params["TASTT_LAYER_NAME"] + print(replaceMacros(TASTT_LAYER_HEADER, params)) + + params["TASTT_STATE_U2"] = params["TASTT_DEFAULT_STATE_U2"] + print(replaceMacros(TASTT_LAYER_HEADER_CHILD_STATE, params)) + params["TASTT_STATE_U2"] = params["ACTIVE_STATE_U2"] + print(replaceMacros(TASTT_LAYER_HEADER_CHILD_STATE, params)) + for e0 in range(0, 2): + for e1 in range(0, 2): + params["TASTT_STATE_U2"] = params[getResizeStateName(e0, e1) + "_U2"] + print(replaceMacros(TASTT_LAYER_HEADER_CHILD_STATE, params)) + print(replaceMacros(TASTT_LAYER_FOOTER, params)) + +genTasttResizeLayer(state) diff --git a/generate_params.py b/generate_params.py index 665a439..bb7fcdf 100644 --- a/generate_params.py +++ b/generate_params.py @@ -39,9 +39,16 @@ BOOL_PARAM = """ params = {} print(generate_utils.replaceMacros(PARAM_HEADER, params)) -# Implementation detail. We use this parameter to return from the terminal -# state of the FX layer to the starting state. -params["PARAM_NAME"] = "TaSTT_Dummy" +params["PARAM_NAME"] = generate_utils.getDummyParam() +print(generate_utils.replaceMacros(BOOL_PARAM, params)) + +params["PARAM_NAME"] = generate_utils.getResizeEnableParam() +print(generate_utils.replaceMacros(BOOL_PARAM, params)) + +params["PARAM_NAME"] = generate_utils.getResize0Param() +print(generate_utils.replaceMacros(BOOL_PARAM, params)) + +params["PARAM_NAME"] = generate_utils.getResize1Param() print(generate_utils.replaceMacros(BOOL_PARAM, params)) for i in range(0, generate_utils.NUM_LAYERS): diff --git a/generate_utils.py b/generate_utils.py index e50a656..74fd095 100644 --- a/generate_utils.py +++ b/generate_utils.py @@ -19,9 +19,20 @@ NUM_LAYERS=ceil((BOARD_ROWS * BOARD_COLS) / (2**INDEX_BITS)) # 1 bit: enable bit (turns layer off while we index to a new slot) NUM_PARAM_BITS=(NUM_LAYERS * (8 + INDEX_BITS + 1)) +# Implementation detail. We use this parameter to return from the terminal +# state of the FX layer to the starting state. def getDummyParam(): return "TaSTT_Dummy" +def getResizeEnableParam(): + return "TaSTT_Resize_Enable" + +def getResize0Param(): + return "TaSTT_Resize_0" + +def getResize1Param(): + return "TaSTT_Resize_1" + # Each layer controls a group of cells. There's only one letter per layer, thus # this is also the name of the parameter which sets the letter for a layer. def getLayerParam(which_layer): diff --git a/lorum_ipsum.txt b/lorum_ipsum.txt new file mode 100644 index 0000000..42b0fe1 --- /dev/null +++ b/lorum_ipsum.txt @@ -0,0 +1 @@ +A spectre is haunting Europe-the spectre of Communism. All the Powers of old Europe have entered into a holy alliance to exorcise this spectre: Pope and Czar, Metternich and Guizot, French Radicals and German police-spies. Where is the party in opposition that has not been decried as Communistic by its opponents in power? Where is the Opposition that has not hurled back the branding reproach of Communism, against the more advanced opposition parties, as well as against its reactionary adversaries? Two things result from this fact. I. Communism is already acknowledged by all European Powers to be itself a Power. II. It is high time that Communists should openly, in the face of the whole world, publish their views, their aims, their tendencies, and meet this nursery tale of the Spectre of Communism with a Manifesto of the party itself. To this end, Communists of various nationalities have assembled in London, and sketched the following Manifesto, to be published in the English, French, German, Italian, Flemish and Danish languages.
diff --git a/osc_ctrl.py b/osc_ctrl.py index 23b63c2..fcb2445 100644 --- a/osc_ctrl.py +++ b/osc_ctrl.py @@ -4,6 +4,7 @@ import argparse import random import time import fileinput +import generate_utils from pythonosc import udp_client from math import ceil @@ -16,8 +17,8 @@ from generate_utils import NUM_LAYERS from generate_utils import BOARD_ROWS from generate_utils import BOARD_COLS -#MSG_DELAY_S=0.3 -MSG_DELAY_S=0.1 +#CELL_TX_TIME_S=1.0 +CELL_TX_TIME_S=0.6 def usage(): print("python3 -m pip install python-osc") @@ -30,30 +31,57 @@ args = parser.parse_args() client = udp_client.SimpleUDPClient(args.i, args.p) +class EvilGlobalState(): + # Mapping from ascii char to encoded byte. + encoding = {} +state = EvilGlobalState() + +def generateEncoding(state): + for i in range(0, 26): + state.encoding[chr(ord('A') + i)] = i + for i in range(26, 52): + state.encoding[chr(ord('a') + i - 26)] = i + for i in range(52, 62): + state.encoding[chr(ord('0') + i - 52)] = i + state.encoding[','] = 62 + state.encoding['.'] = 63 + state.encoding[' '] = 64 + state.encoding['?'] = 65 + state.encoding['!'] = 66 + state.encoding[';'] = 67 + state.encoding[':'] = 68 + state.encoding['-'] = 69 + state.encoding['_'] = 70 + state.encoding["'"] = 71 + state.encoding['"'] = 72 + def encodeMessage(lines): result = [] for line in lines: for char in line: - char_int = ord(char) - if char_int >= ord('A') and char_int <= ord('Z'): - result.append(ord(char) - ord('A')) - elif char >= 'a' and char <= 'z': - result.append((ord(char) - ord('a')) + 26) - elif char >= '0' and char <= '9': - result.append((ord(char) - ord('0')) + 52) - elif char == '.': - result.append(63) - elif char == ',': - result.append(62) - elif char == ' ': - result.append(64) - # Pad message with spaces so that it overwrites any leftover text. - result += [65] * (BOARD_COLS - len(line)) + result.append(state.encoding[char]) + result += [state.encoding[' ']] * (BOARD_COLS - len(line)) #print("Encoded message: {}".format(result)) return result +def updateCell(cell_idx, letter_encoded, s0, s1, s2): + addr="/avatar/parameters/" + getLayerParam(cell_idx) + client.send_message(addr, letter_encoded) + + addr="/avatar/parameters/" + getSelectParam(cell_idx, 0) + client.send_message(addr, s0) + + addr="/avatar/parameters/" + getSelectParam(cell_idx, 1) + client.send_message(addr, s1) + + addr="/avatar/parameters/" + getSelectParam(cell_idx, 2) + client.send_message(addr, s2) + +# Send a cell all at once. # `which_cell` is an integer in the range [0,8). -def sendMessageCell(msg_cell, which_cell): +def sendMessageCellDiscrete(msg_cell, which_cell): + # Really long messages just wrap back around. + which_cell = (which_cell % 8) s0 = ((floor(which_cell / 4) % 2) == 1) s1 = ((floor(which_cell / 2) % 2) == 1) @@ -62,22 +90,10 @@ def sendMessageCell(msg_cell, which_cell): print("Cell s0/s1/s2: {}/{}/{}".format(s0,s1,s2)) # Seek each layer to the current cell. for i in range(0, len(msg_cell)): - print("Board index: {}".format(getBoardIndex(i, s0, s1, s2))) - - addr="/avatar/parameters/" + getLayerParam(i) - client.send_message(addr, msg_cell[i]) - - addr="/avatar/parameters/" + getSelectParam(i, 0) - client.send_message(addr, (floor(which_cell / 4) % 2) == 1) - - addr="/avatar/parameters/" + getSelectParam(i, 1) - client.send_message(addr, (floor(which_cell / 2) % 2) == 1) - - addr="/avatar/parameters/" + getSelectParam(i, 2) - client.send_message(addr, (which_cell % 2) == 1) + updateCell(i, msg_cell[i], s0, s1, s2) # Wait for convergence. - time.sleep(MSG_DELAY_S) + time.sleep(CELL_TX_TIME_S / 3.0) # Enable each layer. # TODO(yum_food) for some reason, if we don't active every layer, the @@ -87,7 +103,7 @@ def sendMessageCell(msg_cell, which_cell): client.send_message(addr, True) # Wait for convergence. - time.sleep(MSG_DELAY_S) + time.sleep(CELL_TX_TIME_S / 3.0) # Disable each layer. for i in range(0, NUM_LAYERS): @@ -95,7 +111,50 @@ def sendMessageCell(msg_cell, which_cell): client.send_message(addr, False) # Wait for convergence. - time.sleep(MSG_DELAY_S) + time.sleep(CELL_TX_TIME_S / 3.0) + +# Send a cell smoothly spread out over the course of CELL_TX_TIME_S. +# `which_cell` is an integer in the range [0,8). +# TODO(yum_food) because we can only reliably update entire cells at once, +# this method does not work :( +def sendMessageCellContinuous(msg_cell, which_cell): + s0 = ((floor(which_cell / 4) % 2) == 1) + s1 = ((floor(which_cell / 2) % 2) == 1) + s2 = ((floor(which_cell / 1) % 2) == 1) + + time_quanta = 100 + dt = CELL_TX_TIME_S / (time_quanta * 1.0) + + # key: time quantum \elem [0, 100) + # value: idx to handle + update_times = {} + enable_times = {} + disable_times = {} + + for i in range(0, len(msg_cell)): + update_time = int(((i / NUM_LAYERS) + 0.000) * time_quanta) % time_quanta + enable_time = int(((i / NUM_LAYERS) + 0.333) * time_quanta) % time_quanta + disable_time = int(((i / NUM_LAYERS) + 0.666) * time_quanta) % time_quanta + + update_times[update_time] = i + enable_times[enable_time] = i + disable_times[disable_time] = i + + for t in range(0, time_quanta): + if t in update_times: + which_cell = update_times[t] + print("which cell: {}".format(which_cell)) + updateCell(which_cell, msg_cell[which_cell], s0, s1, s2) + if t in enable_times: + which_cell = enable_times[t] + addr="/avatar/parameters/" + getEnableParam(which_cell) + client.send_message(addr, True) + if t in disable_times: + which_cell = disable_times[t] + addr="/avatar/parameters/" + getEnableParam(which_cell) + client.send_message(addr, False) + + time.sleep(dt) # The board is broken down into contiguous collections of characters called # cells. Each cell contains `NUM_LAYERS` characters. We can update one cell @@ -139,19 +198,67 @@ def sendMessage(msg): print("Encoded message: {}".format(msg)) + openBoard() + n_cells = ceil(msg_len / NUM_LAYERS) print("n_cells: {}".format(n_cells)) for cell in range(0, n_cells): - # Really long messages just wrap back around. - cell = cell % NUM_LAYERS + cell_begin = cell * NUM_LAYERS + cell_end = (cell + 1) * NUM_LAYERS + cell_msg = msg[cell_begin:cell_end] + print("Send cell {}".format(cell)) + sendMessageCellDiscrete(cell_msg, cell) + + closeBoard() +def sendRawMessage(msg): + n_cells = ceil(len(msg) / NUM_LAYERS) + for cell in range(0, n_cells): cell_begin = cell * NUM_LAYERS cell_end = (cell + 1) * NUM_LAYERS cell_msg = msg[cell_begin:cell_end] print("Send cell {}".format(cell)) - sendMessageCell(cell_msg, cell) + sendMessageCellDiscrete(cell_msg, cell) + +def clear(): + sendRawMessage([state.encoding[' ']] * BOARD_ROWS * BOARD_COLS) + +def openBoard(): + addr="/avatar/parameters/" + generate_utils.getResize0Param() + client.send_message(addr, False) + addr="/avatar/parameters/" + generate_utils.getResize1Param() + client.send_message(addr, False) + + time.sleep(0.1) + + addr="/avatar/parameters/" + generate_utils.getResizeEnableParam() + client.send_message(addr, True) + + time.sleep(0.1) + + addr="/avatar/parameters/" + generate_utils.getResizeEnableParam() + client.send_message(addr, False) + +def closeBoard(): + addr="/avatar/parameters/" + generate_utils.getResize0Param() + client.send_message(addr, True) + addr="/avatar/parameters/" + generate_utils.getResize1Param() + client.send_message(addr, True) + + time.sleep(0.1) + + addr="/avatar/parameters/" + generate_utils.getResizeEnableParam() + client.send_message(addr, True) + + time.sleep(0.1) + + addr="/avatar/parameters/" + generate_utils.getResizeEnableParam() + client.send_message(addr, False) if __name__ == "__main__": + generateEncoding(state) + clear() + for line in fileinput.input(): sendMessage(line) |
