using UnityEngine; using System.Collections; using System; public class DeformScript : MonoBehaviour { private const float ONE_HALF = 0.5f; private const float BODY_YAW_ROTATION = 90.0f; private const float AMOUNT_OF_PERLIN_NOISE = 0.8f; private const float MAX_STRENGTH = 5.0f; //-------------------------------------- // names for the poses //-------------------------------------- // private const int NEUTRAL_POSE = 0; // private const int LOW_POSE = 1; // private const int HIGH_POSE = 2; // private const int CLOSED_POSE = 3; // private const int OPEN_POSE = 4; private const int NUM_POSES = 5; //--------------------------------------------- // names for the joints //--------------------------------------------- private const int HIP_JOINT = 0; private const int LEFT_UPPER_LEG_JOINT = 1; private const int LEFT_LOWER_LEG_JOINT = 2; private const int LEFT_FOOT_JOINT = 3; private const int LEFT_BALL_JOINT = 4; private const int LEFT_TOE_JOINT = 5; private const int RIGHT_UPPER_LEG_JOINT = 6; private const int RIGHT_LOWER_LEG_JOINT = 7; private const int RIGHT_FOOT_JOINT = 8; private const int RIGHT_BALL_JOINT = 9; private const int RIGHT_TOE_JOINT = 10; private const int SPINE_1_JOINT = 11; private const int SPINE_2_JOINT = 12; private const int SPINE_3_JOINT = 13; private const int SHOULDER_JOINT = 14; private const int LEFT_SHOULDER_BLADE_JOINT = 15; private const int LEFT_UPPER_ARM_JOINT = 16; private const int LEFT_LOWER_ARM_JOINT = 17; private const int LEFT_WRIST_JOINT = 18; private const int LEFT_GRIP_JOINT = 19; private const int LEFT_FINGERS_JOINT = 20; private const int LEFT_THUMB_BASE_JOINT = 21; private const int LEFT_THUMB_BEND_JOINT = 22; private const int LEFT_THUMB_TIP_JOINT = 23; private const int RIGHT_SHOULDER_BLADE_JOINT = 24; private const int RIGHT_UPPER_ARM_JOINT = 25; private const int RIGHT_LOWER_ARM_JOINT = 26; private const int RIGHT_WRIST_JOINT = 27; private const int RIGHT_GRIP_JOINT = 28; private const int RIGHT_FINGERS_JOINT = 29; private const int RIGHT_THUMB_BASE_JOINT = 30; private const int RIGHT_THUMB_BEND_JOINT = 31; private const int RIGHT_THUMB_TIP_JOINT = 32; private const int NECK_JOINT = 33; private const int HEAD_JOINT = 34; private const int NUM_JOINTS = 35; //--------------------------------------------- // names for the emotions //--------------------------------------------- private const int NEUTRAL = 0; private const int HAPPINESS = 1; private const int PRIDE = 2; private const int SADNESS = 3; private const int FEAR = 4; private const int ANGER = 5; private const int CONTEMPT = 6; private const int SHAME = 7; private const int GUILT = 8; private const int NUM_EMOTIONS = 9; private static string[] emotions = new string[NUM_EMOTIONS] {"Neutral", "Happiness", "Pride", "Sadness", "Fear", "Anger", "Contempt", "Shame", "Guilt"}; // set up currentSelection at a scope that allows for initial selection one time string currentSelection = emotions[0]; public Transform[] joints; public float publicTwist = 0.5f; // need to ask about this public float publicSideBend = 0.5f; // here business //--------------------------------------------- // settings for the GUI boxes //--------------------------------------------- private const int guiRectHeight = 210; private const int guiRectWidth = 250; private const int guiRecty = 480; private Rect guiRect1 = new Rect( 20, guiRecty, guiRectWidth, guiRectHeight ); private Rect guiRect2 = new Rect( 500, guiRecty, guiRectWidth, guiRectHeight ); private Pose[] pose = new Pose[ NUM_POSES ]; private DelsarteAvatar avatar = new DelsarteAvatar(); public string avatarName; //----------------------------------------------- // names for the Delsarte grand and sub divisions //----------------------------------------------- private const int CONCENTRIC = 1; private const int NORMAL = 2; private const int EXCENTRIC = 3; //--------------------------------------------------------- //-------------------------------- // SelectList class - a custom GUI object that provides a linked set of checkboxes // http://www.unifycommunity.com/wiki/index.php?title=SelectList //-------------------------------- public static object SelectList( ICollection list, object selected, GUIStyle defaultStyle, GUIStyle selectedStyle ) { foreach( object item in list ) { if( GUILayout.Button( item.ToString(), ( selected == item ) ? selectedStyle : defaultStyle ) ) { if( selected == item ) // Clicked an already selected item. Deselect. { selected = null; } else { selected = item; } } } return selected; } public delegate bool OnListItemGUI( object item, bool selected, ICollection list ); public static object SelectList( ICollection list, object selected, OnListItemGUI itemHandler ) { ArrayList itemList; itemList = new ArrayList( list ); foreach( object item in itemList ) { if( itemHandler( item, item == selected, list ) ) { selected = item; } else if( selected == item ) // If we *were* selected, but aren't any more then deselect { selected = null; } } return selected; } //-------------------------------- // Pose class //-------------------------------- class Pose { float[] yaw = new float[ NUM_JOINTS ]; float[] pitch = new float[ NUM_JOINTS ]; float[] roll = new float[ NUM_JOINTS ]; public Pose() { for (int j=0; j