| 1 | using System; | 
 
 
 
 
 | 2 | using System.Collections.Generic; | 
 
 
 
 
 | 3 |  | 
 
 
 
 
 | 4 | namespace Oni.Dae | 
 
 
 
 
 | 5 | { | 
 
 
 
 
 | 6 | internal abstract class Transform | 
 
 
 
 
 | 7 | { | 
 
 
 
 
 | 8 | private string sid; | 
 
 
 
 
 | 9 | private readonly float[] values; | 
 
 
 
 
 | 10 | private Sampler[] animations; | 
 
 
 
 
 | 11 |  | 
 
 
 
 
 | 12 | protected Transform(int valueCount) | 
 
 
 
 
 | 13 | { | 
 
 
 
 
 | 14 | this.values = new float[valueCount]; | 
 
 
 
 
 | 15 | } | 
 
 
 
 
 | 16 |  | 
 
 
 
 
 | 17 | protected Transform(string sid, int valueCount) | 
 
 
 
 
 | 18 | { | 
 
 
 
 
 | 19 | this.sid = sid; | 
 
 
 
 
 | 20 | this.values = new float[valueCount]; | 
 
 
 
 
 | 21 | } | 
 
 
 
 
 | 22 |  | 
 
 
 
 
 | 23 | public string Sid | 
 
 
 
 
 | 24 | { | 
 
 
 
 
 | 25 | get { return sid; } | 
 
 
 
 
 | 26 | set { sid = value; } | 
 
 
 
 
 | 27 | } | 
 
 
 
 
 | 28 |  | 
 
 
 
 
 | 29 | public float[] Values => values; | 
 
 
 
 
 | 30 | public bool HasAnimations => animations != null; | 
 
 
 
 
 | 31 |  | 
 
 
 
 
 | 32 | public Sampler[] Animations | 
 
 
 
 
 | 33 | { | 
 
 
 
 
 | 34 | get | 
 
 
 
 
 | 35 | { | 
 
 
 
 
 | 36 | if (animations == null) | 
 
 
 
 
 | 37 | animations = new Sampler[values.Length]; | 
 
 
 
 
 | 38 |  | 
 
 
 
 
 | 39 | return animations; | 
 
 
 
 
 | 40 | } | 
 
 
 
 
 | 41 | } | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | protected Sampler GetAnimation(int index) | 
 
 
 
 
 | 44 | { | 
 
 
 
 
 | 45 | if (animations == null) | 
 
 
 
 
 | 46 | return null; | 
 
 
 
 
 | 47 |  | 
 
 
 
 
 | 48 | return animations[index]; | 
 
 
 
 
 | 49 | } | 
 
 
 
 
 | 50 |  | 
 
 
 
 
 | 51 | public void BindAnimation(string valueName, Sampler animation) | 
 
 
 
 
 | 52 | { | 
 
 
 
 
 | 53 | if (string.IsNullOrEmpty(valueName)) | 
 
 
 
 
 | 54 | { | 
 
 
 
 
 | 55 | for (int i = 0; i < values.Length; i++) | 
 
 
 
 
 | 56 | BindAnimation(i, animation); | 
 
 
 
 
 | 57 | } | 
 
 
 
 
 | 58 | else | 
 
 
 
 
 | 59 | { | 
 
 
 
 
 | 60 | int valueIndex = ParseValueIndex(valueName); | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 | if (valueIndex != -1) | 
 
 
 
 
 | 63 | BindAnimation(valueIndex, animation); | 
 
 
 
 
 | 64 | } | 
 
 
 
 
 | 65 | } | 
 
 
 
 
 | 66 |  | 
 
 
 
 
 | 67 | private void BindAnimation(int index, Sampler animation) | 
 
 
 
 
 | 68 | { | 
 
 
 
 
 | 69 | if (animation.Inputs.Count == 0 || animation.Inputs[0].Source.Count == 0) | 
 
 
 
 
 | 70 | animation = null; | 
 
 
 
 
 | 71 |  | 
 
 
 
 
 | 72 | if (animation == null && !HasAnimations) | 
 
 
 
 
 | 73 | return; | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 | Animations[index] = animation; | 
 
 
 
 
 | 76 | } | 
 
 
 
 
 | 77 |  | 
 
 
 
 
 | 78 | private int ParseValueIndex(string name) | 
 
 
 
 
 | 79 | { | 
 
 
 
 
 | 80 | if (name[0] == '(') | 
 
 
 
 
 | 81 | { | 
 
 
 
 
 | 82 | int end = name.IndexOf(')', 1); | 
 
 
 
 
 | 83 |  | 
 
 
 
 
 | 84 | if (end == -1) | 
 
 
 
 
 | 85 | return -1; | 
 
 
 
 
 | 86 |  | 
 
 
 
 
 | 87 | return int.Parse(name.Substring(1, end - 1).Trim()); | 
 
 
 
 
 | 88 | } | 
 
 
 
 
 | 89 |  | 
 
 
 
 
 | 90 | return ValueNameToValueIndex(name); | 
 
 
 
 
 | 91 | } | 
 
 
 
 
 | 92 |  | 
 
 
 
 
 | 93 | public abstract int ValueNameToValueIndex(string name); | 
 
 
 
 
 | 94 | public abstract string ValueIndexToValueName(int index); | 
 
 
 
 
 | 95 |  | 
 
 
 
 
 | 96 | public abstract Matrix ToMatrix(); | 
 
 
 
 
 | 97 | } | 
 
 
 
 
 | 98 | } |