Esempio n. 1
0
        public static List <int[]> makeList(string input, TREE tree)
        {
            string[] sa = input.Split(new string[] { "|" }, System.StringSplitOptions.None);

            List <int[]> range = new List <int[]> ();

            for (int i = 0; i < sa.Length; i++)
            {
                string[] na = sa[i].Split(new string[] { "," }, System.StringSplitOptions.None);
                if (na.Length == 1)
                {
                    int[] toAdd = new int[1];
                    toAdd [0] = int.Parse(na [0]);
                    range.Add(toAdd);
                }
                else
                {
                    int   a     = int.Parse(na [1]);
                    int   b     = int.Parse(na [0]);
                    int[] toAdd = new int[2];
                    toAdd [0] = b;
                    toAdd [1] = a;
                    range.Add(toAdd);
                }
            }

            int[]        Stack      = new int[0];
            List <int[]> StackArray = new List <int[]> ();
            int          index      = 0;

            return(_makeList(range, Stack, StackArray, index, tree));
        }
Esempio n. 2
0
        public void Setup(string[] joints, List <Transformer> args, TREE tree)
        {
            if (joints != null)
            {
                MakeDefaults(joints.Length);
                root = tree.gameObject;

                initialRotation.Clear();
                selectedJoints.Clear();

                for (var i = 0; i < joints.Length; i++)
                {
                    var firstList     = TREEUtils.makeList(joints [i], tree.GetComponent <TREE>());
                    var initRotations = new List <Vector3>();

                    foreach (var t in firstList)
                    {
                        var g = TREEUtils.findJoint(t, 0, root.transform.GetChild(0).gameObject);
                        initRotations.Add(g.transform.localEulerAngles);
                    }

                    initialRotation.Add(initRotations);
                    selectedJoints.Add(firstList);
                }

                Transformers = args;
            }
        }
Esempio n. 3
0
        public static List <List <int[]> > ArgsArrayToJointList(string[] joints, TREE tree)
        {
            GameObject           root           = tree.gameObject;
            List <List <int[]> > SelectedJoints = new List <List <int[]> > ();

            for (int i = 0; i < joints.Length; i++)
            {
                List <int[]> firstList = TREEUtils.makeList(joints[i], tree.GetComponent <TREE>());

                for (int p = 0; p < firstList.Count; p++)
                {
                    GameObject g = TREEUtils.findJoint(firstList[p], 0, root.transform.GetChild(0).gameObject);
                }

                SelectedJoints.Add(firstList);
            }

            return(SelectedJoints);
        }
Esempio n. 4
0
        public void Setup(string[] joints, string[] args, TREE tree)
        {
            //		if (!defaultsMade) {
            if (joints != null)
            {
                makeDefaults(joints.Length);
                root         = tree.gameObject;
                defaultsMade = true;
                //		}

                initialRotation.Clear();
                SelectedJoints.Clear();

                for (int i = 0; i < joints.Length; i++)
                {
                    List <int[]>   firstList     = TREEUtils.makeList(joints [i], tree.GetComponent <TREE> ());
                    List <Vector3> initRotations = new List <Vector3> ();

                    for (int p = 0; p < firstList.Count; p++)
                    {
                        GameObject g = TREEUtils.findJoint(firstList [p], 0, root.transform.GetChild(0).gameObject);
                        initRotations.Add(g.transform.localEulerAngles);
                    }

                    initialRotation.Add(initRotations);
                    SelectedJoints.Add(firstList);

                    string[] arg = args [i].Split(new string[] { "," }, System.StringSplitOptions.None);
                    for (int j = 0; j < arg.Length; j++)
                    {
                        string[] a = arg [j].Split(new string[] { ":" }, System.StringSplitOptions.None);
                        if (a.Length > 1)
                        {
                            Transforms [i] [a [0]] = float.Parse(a [1]);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public void Build()
        {
            if (autoPopulate)
            {
                if (mods.Length > 0)
                {
                    mods = new TREEMod[0];
                }
                mods = GetComponents <TREEMod> ();
            }
            if (this.GetComponent <Joint> () != null)
            {
                if (this.GetComponent <Joint> ().limbs.Count > 0)
                {
                    this.GetComponent <Joint> ().limbs.Clear();
                }
            }
            if (this.gameObject.GetComponent <TREE> () == null)
            {
                tree = this.gameObject.AddComponent <TREE> ();
            }
            else
            {
                for (int i = 0; i < this.transform.childCount; i++)
                {
                    Destroy(this.transform.GetChild(0).gameObject);
                }
                DestroyImmediate(tree);
                tree = this.gameObject.AddComponent <TREE> ();
            }
            for (int i = 0; i < mods.Length; i++)
            {
                mods [i].tree    = tree;
                mods [i].animate = false;
            }

            StartCoroutine(reBuild());
            rebuild = false;
        }
Esempio n. 6
0
        public void buildTree()
        {
            if (GetComponent <Joint> () != null)
            {
                if (GetComponent <Joint>().limbs.Count > 0)
                {
                    GetComponent <Joint>().limbs.Clear();
                }
            }

            if (gameObject.GetComponent <TREE>() == null)
            {
                tree = gameObject.AddComponent <TREE>();
            }
            else
            {
                for (int i = 0; i < transform.childCount; i++)
                {
                    Destroy(transform.GetChild(0).gameObject);
                }
                tree = GetComponent <TREE>();
            }

            tree.setDefaultJoint(defaultJoint);

            tree.generate(
                "joints", joints,
                "rads", rads,
                "angles", angles,
                "length", length,
                "divs", divs,
                "start", start,
                "end", end
                );

            tree.jointDictionary.Clear();
            TREEUtils.makeDictionary(tree.gameObject);
        }
Esempio n. 7
0
        public static List <int[]> _makeList(List <int[]> range, int[] stack, List <int[]> stackArray, int Index, TREE tree)
        {
            testCounter += Time.deltaTime;

            if (Index < range.Count)
            {
                int i = Index;

                if (range [i].Length > 1 && i != range.Count - 1)
                {
                    for (int j = range [i] [0]; j <= range [i] [range [i].Length - 1]; j++)
                    {
                        stack = intPush(stack, j);
                        int[] tempStack = makeTempStack(stack);
                        _makeList(range, tempStack, stackArray, i + 1, tree);
                        stack = intPop(stack);
                    }
                }

                else if (range[i][0] == -1 && i % 2 == 0 && i != range.Count - 1)
                {
                    int[] tempStack = makeTempStack(stack);
                    tempStack = intPush(tempStack, 0);

                    GameObject[] jarr = new GameObject[0];
                    GameObject   g    = findJoint(tempStack, 0, tree.transform.GetChild(0).gameObject);
                    jarr = findLimbs(g, jarr);

                    for (int j = 0; j < jarr.Length; j++)
                    {
                        stack     = intPush(stack, j);
                        tempStack = makeTempStack(stack);
                        _makeList(range, tempStack, stackArray, i + 1, tree);
                        stack = intPop(stack);
                    }
                }

                else if (range[i][0] == -1 && i % 2 != 0 && i != range.Count - 1)
                {
                    int[] tempStack = makeTempStack(stack);

                    GameObject[] jarr = new GameObject[0];
                    GameObject   g    = findJoint(tempStack, 0, tree.transform.GetChild(0).gameObject);
                    jarr = findLimbs(g, jarr);

                    List <GameObject> limbs = jarr[0].GetComponent <Joint>().limbs;

                    for (int j = 0; j < limbs.Count; j++)
                    {
                        stack = intPush(stack, j);
                        int[] tempStack2 = makeTempStack(stack);
                        _makeList(range, tempStack2, stackArray, i + 1, tree);
                        stack = intPop(stack);
                    }
                }

                else if (range[i][0] == -2 && i == range.Count - 1 ||
                         range[i][0] == -1 && i == range.Count - 1 ||
                         range[i][0] == -3 && i == range.Count - 1)
                {
                    int[] tempStack = makeTempStack(stack);

                    tempStack = intPush(tempStack, 0);

                    GameObject g = findJoint(tempStack, 0, tree.transform.GetChild(0).gameObject);
//					if (g != null) {
                    int joints = 0;
                    if (g != null)
                    {
                        joints = g.gameObject.GetComponent <Joint> ().joints;
                    }

                    int min = 0;
                    int max = joints + 1;

                    if (range [i] [0] == -2)
                    {
                        min = 1;
                    }

                    if (range [i] [0] == -3)
                    {
                        min = max - 1;
                    }

                    for (var j = min; j < max; j++)
                    {
                        stack     = intPush(stack, j);
                        tempStack = makeTempStack(stack);
                        for (var k = 0; k < stack.Length; k++)
                        {
                            tempStack [k] = stack [k];
                        }

                        _makeList(range, tempStack, stackArray, i + 1, tree);
                        stack = intPop(stack);
                    }
//					}
                }

                else if (i == range.Count - 1)
                {
                    int[] tempStack = makeTempStack(stack);

                    tempStack = intPush(tempStack, 0);

                    int min = range[i][0];
                    int max = range [i] [0];
                    if (range[i].Length > 1)
                    {
                        max = range[i][1];
                    }

                    GameObject g      = findJoint(tempStack, 0, tree.transform.GetChild(0).gameObject);
                    int        joints = g.gameObject.GetComponent <Joint> ().joints;

                    if (min > joints + 1)
                    {
                        min = joints + 1;
                    }
                    if (max > joints + 1)
                    {
                        max = joints + 1;
                    }

                    for (int j = min; j <= max; j++)
                    {
                        if (range[i][0] == -2)
                        {
                            j++;
                        }

                        stack = intPush(stack, j);

                        tempStack = makeTempStack(stack);

                        _makeList(range, tempStack, stackArray, i + 1, tree);
                        stack = intPop(stack);
                    }
                }
                else
                {
                    stack = intPush(stack, range [i] [0]);

                    int[] tempStack = makeTempStack(stack);

                    _makeList(range, stack, stackArray, i + 1, tree);
                    stack = intPop(stack);
                }
            }
            else
            {
                stackArray.Add(stack);
            }

            return(stackArray);
        }