Beispiel #1
0
        public static void makeDictionary(GameObject tree, GameObject joint, List <int> stack, List <List <int> > stackArray, int pusher)
        {
            stack.Add(pusher);
            for (int i = 0; i < joint.GetComponent <Joint> ().limbs.Count; i++)
            {
                stack.Add(i);
                int[]        tempStack = stack.ToArray();
                GameObject[] jarr      = new GameObject[0];
                GameObject   g         = joint.GetComponent <Joint> ().limbs [i];
                jarr = findLimbs(g, jarr);

                List <int> tempStack2 = new List <int> ();
                for (int j = 0; j < stack.Count; j++)
                {
                    tempStack2.Add(stack[j]);
                }
                List <int> t2 = new List <int> ();
                for (int j = 0; j < stack.Count; j++)
                {
                    t2.Add(stack[j]);
                }

                stackArray.Add(tempStack2);
                t2.Add(-1);
                List <int[]> t3 = makeList(listToString(t2), tree.GetComponent <TREE> ());

                for (int k = 0; k < t3.Count; k++)
                {
                    string     tempString = arrayToString(t3 [k]);
                    GameObject tempJoint  = findJoint(t3[k], 0, tree);
                    if (tempJoint != null)
                    {
                        tempJoint.GetComponent <Joint> ().dictionaryName = t3 [k];
                        tree.GetComponent <TREE> ().jointDictionary [TREEUtils.arrayToString(t3 [k])] = tempJoint;
                    }
                }

                for (var j = 0; j < jarr.Length; j++)
                {
                    makeDictionary(tree, jarr[j], tempStack2, stackArray, j);
                }

                stack.RemoveAt(stack.Count - 1);
            }

            stack.RemoveAt(stack.Count - 1);
        }
Beispiel #2
0
 public void returnToInitialState()
 {
     for (int i = 0; i < SelectedJoints.Count; i++)
     {
         for (int j = 0; j < SelectedJoints [i].Count; j++)
         {
             GameObject g;
             if (root.GetComponent <TREE>().jointDictionary.Count > 0 && root.GetComponent <TREE>().jointDictionary.ContainsKey(TREEUtils.arrayToString(SelectedJoints[i][j])))
             {
                 g = root.GetComponent <TREE>().jointDictionary[TREEUtils.arrayToString(SelectedJoints[i][j])].gameObject;
             }
             else
             {
                 g = TREEUtils.findJoint(SelectedJoints [i] [j], 0, root.transform.GetChild(0).gameObject);
             }
             if (g != null)
             {
                 g.transform.localEulerAngles = initialRotation [i] [j];
             }
         }
     }
 }
Beispiel #3
0
        public void ReturnToInitialState()
        {
            if (selectedJoints.Count == 0)
            {
                return;
            }

            GameObject g;

            var jointDict = root.GetComponent <TREE>().jointDictionary;

            for (var i = 0; i < selectedJoints.Count; i++)
            {
                for (var j = 0; j < selectedJoints [i].Count; j++)
                {
                    var currentJointKey = TREEUtils.arrayToString(selectedJoints[i][j]);

                    if (jointDict.Count > 0 && jointDict.ContainsKey(currentJointKey))
                    {
                        g = jointDict[currentJointKey].gameObject;
                    }
                    else
                    {
                        g = TREEUtils.findJoint(
                            selectedJoints[i][j],
                            0,
                            root.transform.GetChild(0).gameObject
                            );
                    }

                    if (g != null)
                    {
                        g.transform.localEulerAngles = initialRotation[i][j];
                    }
                }
            }
        }
Beispiel #4
0
        public void Animate(float timer)
        {
            GameObject g;
            var        jointDict = root.GetComponent <TREE>().jointDictionary;

            for (var i = 0; i < selectedJoints.Count; i++)
            {
                for (var j = 0; j < selectedJoints[i].Count; j++)
                {
                    var currentJointKey = TREEUtils.arrayToString(selectedJoints[i][j]);

                    if (jointDict.Count > 0 && jointDict.ContainsKey(currentJointKey))
                    {
                        g = jointDict[currentJointKey].gameObject;
                    }
                    else
                    {
                        g = TREEUtils.findJoint(
                            selectedJoints[i][j],
                            0,
                            root.transform.GetChild(0).gameObject
                            );
                    }

                    if (g != null)
                    {
                        var joint        = g.GetComponent <Joint>();
                        var jointNumber  = joint.joint;
                        var jointOffset  = joint.offset;
                        var jointOffset2 = joint.offset2;
                        var init         = initialRotation[i][j];

                        sinRotate    = Vector3.zero;
                        noiseRotate  = Vector3.zero;
                        rotateOffset = Vector3.zero;
                        sinScale     = Vector3.zero;

                        var xform = Transformers[i];

                        rotate = xform.Rotation;

                        if (xform.SinMultiplyR.x != 0 || xform.SinMultiplyR.y != 0 || xform.SinMultiplyR.z != 0)
                        {
                            sinRotate.x =
                                (xform.SinMultiply * jointNumber + xform.SinMultiplyR.x) * Mathf.Sin(
                                    xform.SinSpeedR.x * timer + xform.SinOffsetR.x +
                                    xform.SinOffsetAxialR.x * jointOffset +
                                    xform.SinOffsetAxialA.x * jointOffset2 +
                                    xform.SinFrequencyR.x * jointNumber);

                            sinRotate.y = (xform.SinMultiply * jointNumber + xform.SinMultiplyR.y) * Mathf.Sin(
                                xform.SinSpeedR.y * timer + xform.SinOffsetR.y +
                                xform.SinOffsetAxialR.y * jointOffset +
                                xform.SinOffsetAxialA.y * jointOffset2 +
                                xform.SinFrequencyR.y * jointNumber);

                            sinRotate.z = (xform.SinMultiply * jointNumber + xform.SinMultiplyR.z) * Mathf.Sin(
                                xform.SinSpeedR.z * timer + xform.SinOffsetR.z +
                                xform.SinOffsetAxialR.z * jointOffset +
                                xform.SinOffsetAxialA.z * jointOffset2 + xform.SinFrequencyR.z * jointNumber);
                        }

                        if (xform.NoiseMultiply.x != 0 || xform.NoiseMultiply.y != 0 || xform.NoiseMultiply.z != 0)
                        {
                            noiseRotate.x = (xform.NoiseJointMultiply * jointNumber + xform.NoiseMultiply.x) * TREEUtils.Noise(
                                xform.NoiseSpeed.x * -timer + xform.NoiseOffset.x +
                                xform.NoiseRootOffset.x * jointOffset +
                                xform.NoiseOffsetAxial.x * jointOffset2 +
                                xform.NoiseFrequency.x * jointNumber);

                            noiseRotate.y = (xform.NoiseJointMultiply * jointNumber + xform.NoiseMultiply.y) * TREEUtils.Noise(
                                xform.NoiseSpeed.y * -timer + xform.NoiseOffset.y +
                                xform.NoiseRootOffset.y * jointOffset +
                                xform.NoiseOffsetAxial.y * jointOffset2 +
                                xform.NoiseFrequency.y * jointNumber);

                            noiseRotate.z = (xform.NoiseJointMultiply * jointNumber + xform.NoiseMultiply.z) * TREEUtils.Noise(
                                xform.NoiseSpeed.z * -timer + xform.NoiseOffset.z +
                                xform.NoiseRootOffset.z * jointOffset +
                                xform.NoiseOffsetAxial.z * jointOffset2 + xform.NoiseFrequency.z * jointNumber);
                        }

                        if (xform.SinMultiplyS.x != 0 || xform.SinMultiplyS.y != 0 || xform.SinMultiplyS.z != 0)
                        {
                            sinScale.x = (
                                xform.SinScaleMult * jointNumber +
                                xform.SinMultiplyS.x) * Mathf.Sin(
                                xform.SinSpeedS.x * timer +
                                xform.SinOffsetS.x +
                                xform.SinOffsetFromRootOffset.x * jointOffset +
                                xform.SinFrequencyS.x * jointNumber
                                );

                            sinScale.y = (
                                xform.SinScaleMult * jointNumber +
                                xform.SinMultiplyS.y) * Mathf.Sin(
                                xform.SinSpeedS.y * timer +
                                xform.SinOffsetS.y +
                                xform.SinOffsetFromRootOffset.y * jointOffset +
                                xform.SinFrequencyS.y * jointNumber);

                            sinScale.z = (
                                xform.SinScaleMult * jointNumber +
                                xform.SinMultiplyS.z) * Mathf.Sin(
                                xform.SinSpeedS.z * timer +
                                xform.SinOffsetS.z +
                                xform.SinOffsetFromRootOffset.z * jointOffset +
                                xform.SinFrequencyS.z * jointNumber
                                );
                        }

                        if (xform.SinUniformScale)
                        {
                            sinScale.Set(sinScale.x, sinScale.x, sinScale.x);
                        }

                        if (xform.Length != 0f)
                        {
                            if (joint.childJoint != null)
                            {
                                var off = (
                                    xform.LengthMult * jointNumber +
                                    xform.SinMultiplyLength) *
                                          Mathf.Sin(
                                    xform.SinSpeedLength * timer +
                                    xform.SinOffsetLength +
                                    xform.SinRootOffsetLength * jointOffset +
                                    xform.SinAxisOffsetLength * jointOffset2 +
                                    xform.SinFrequencyLength * jointNumber
                                    );
                                joint.childJoint.transform.localPosition = new Vector3(0, xform.Length + off, 0);                                 // ????
                                var sc = joint.scalar.transform.localScale;
                                joint.scalar.transform.localScale = new Vector3(sc.x, xform.Length + off, sc.z);
                            }
                        }

                        rotateOffset = xform.OffsetRotation * timer;
                        g.transform.localEulerAngles = rotate + init + sinRotate + noiseRotate + rotateOffset;

                        // g.transform.Rotate (rotateOffset.x,rotateOffset.y,rotateOffset.z);
                        scale.Set(
                            xform.Scale + xform.ScaleXY.x,
                            xform.Scale + xform.ScaleXY.y,
                            xform.Scale + xform.ScaleXY.z
                            );

                        var overallScale = sinScale + scale;

                        if (xform.SinColor != Color.black)
                        {
                            var initCol = new Color(
                                xform.SinColor.r,
                                xform.SinColor.g,
                                xform.SinColor.b
                                );

                            float hue, s, v;
                            Color.RGBToHSV(initCol, out hue, out s, out v);
                            var off =
                                (xform.LengthColorMult * jointNumber + xform.SinMultiplyColor) * Mathf.Sin(
                                    xform.SinSpeedColor * timer +
                                    xform.SinOffsetColor + xform.SinRootOffsetColor * jointOffset +
                                    xform.SinAxisOffsetColor * jointOffset2 +
                                    xform.SinFrequencyColor * jointNumber
                                    );
                            var fOff = off - Mathf.Floor(off);

                            if (fOff < 0)
                            {
                                fOff -= Mathf.Floor(off);
                            }

                            foreach (Transform child in joint.scalar.transform)
                            {
                                var meshRenderer = child.gameObject.GetComponent <MeshRenderer>();
                                if (meshRenderer != null)
                                {
                                    float alpha = meshRenderer.material.color.a;
                                    Color color = Color.HSVToRGB(fOff, 1, 1);
                                    color.a = alpha;
                                    meshRenderer.material.color = color;
                                }
                            }

                            foreach (Transform child in joint.scalar.transform)
                            {
                                var meshRenderer = child.gameObject.GetComponent <MeshRenderer>();
                                if (meshRenderer != null)
                                {
                                    float alpha = meshRenderer.material.color.a;
                                    Color color = Color.HSVToRGB(fOff, 1, 1);
                                    color.a = alpha;
                                    meshRenderer.material.color = color;
                                }
                            }

                            foreach (Transform child in joint.rotator.transform)
                            {
                                var meshRenderer = child.gameObject.GetComponent <MeshRenderer>();
                                if (meshRenderer != null)
                                {
                                    float alpha = meshRenderer.material.color.a;
                                    Color color = Color.HSVToRGB(fOff, 1, 1);
                                    color.a = alpha;
                                    meshRenderer.material.color = color;
                                }
                            }
                            // g.GetComponent<Joint>().scalar.transform.GetChild (0).GetComponent<MeshRenderer> ().material.color = Color.HSVToRGB (fOff, 1, 1);
                        }

                        if (!overallScale.Equals(Vector3.one))
                        {
                            g.transform.localScale = overallScale;
                            // Vector3.Scale(overallScale , new Vector3 (Transforms [i] ["sx"], Transforms [i] ["sy"], Transforms [i] ["sz"]));
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public void Animate(float timer)
        {
            for (int i = 0; i < SelectedJoints.Count; i++)
            {
                for (int j = 0; j < SelectedJoints [i].Count; j++)
                {
                    GameObject g;
                    if (root.GetComponent <TREE>().jointDictionary.Count > 0 && root.GetComponent <TREE>().jointDictionary.ContainsKey(TREEUtils.arrayToString(SelectedJoints[i][j])))
                    {
                        g = root.GetComponent <TREE>().jointDictionary[TREEUtils.arrayToString(SelectedJoints[i][j])].gameObject;
                    }
                    else
                    {
                        g = TREEUtils.findJoint(SelectedJoints [i] [j], 0, root.transform.GetChild(0).gameObject);
                    }

                    if (g != null)
                    {
                        int     jointNumber  = g.GetComponent <Joint> ().joint;
                        int     jointOffset  = g.GetComponent <Joint> ().offset;
                        int     jointOffset2 = g.GetComponent <Joint> ().offset2;
                        Vector3 init         = initialRotation [i] [j];

                        sinRotate    = Vector3.zero;
                        noiseRotate  = Vector3.zero;
                        rotateOffset = Vector3.zero;
                        sinScale     = Vector3.zero;

                        rotate.Set(
                            Transforms[i]["rx"],
                            Transforms[i]["ry"],
                            Transforms[i]["rz"]
                            );


                        if (Transforms [i] ["smrx"] != 0 || Transforms [i] ["smry"] != 0 || Transforms [i] ["smrz"] != 0)
                        {
                            sinRotate.Set(
                                ((Transforms [i] ["sMult"] * jointNumber) + Transforms [i] ["smrx"]) * Mathf.Sin(((Transforms [i] ["ssrx"] * timer + Transforms [i] ["sorx"] + (Transforms [i] ["srorx"] * jointOffset) + (Transforms [i] ["saorx"] * jointOffset2)) + (Transforms [i] ["sfrx"] * jointNumber))),
                                ((Transforms [i] ["sMult"] * jointNumber) + Transforms [i] ["smry"]) * Mathf.Sin(((Transforms [i] ["ssry"] * timer + Transforms [i] ["sory"] + (Transforms [i] ["srory"] * jointOffset) + (Transforms [i] ["saory"] * jointOffset2)) + (Transforms [i] ["sfry"] * jointNumber))),
                                ((Transforms [i] ["sMult"] * jointNumber) + Transforms [i] ["smrz"]) * Mathf.Sin(((Transforms [i] ["ssrz"] * timer + Transforms [i] ["sorz"] + (Transforms [i] ["srorz"] * jointOffset) + (Transforms [i] ["saorz"] * jointOffset2)) + (Transforms [i] ["sfrz"] * jointNumber)))
                                );
                        }
                        if (Transforms [i] ["nmrx"] != 0 || Transforms [i] ["nmry"] != 0 || Transforms [i] ["nmrz"] != 0)
                        {
                            noiseRotate.Set(
                                ((Transforms [i] ["nMult"] * jointNumber) + Transforms [i] ["nmrx"]) * TREEUtils.Noise(((Transforms [i] ["nsrx"] * -timer + Transforms [i] ["norx"] + (Transforms [i] ["nrorx"] * jointOffset) + (Transforms [i] ["naorx"] * jointOffset2)) + (Transforms [i] ["nfrx"] * jointNumber))),
                                ((Transforms [i] ["nMult"] * jointNumber) + Transforms [i] ["nmry"]) * TREEUtils.Noise(((Transforms [i] ["nsry"] * -timer + Transforms [i] ["nory"] + (Transforms [i] ["nrory"] * jointOffset) + (Transforms [i] ["naory"] * jointOffset2)) + (Transforms [i] ["nfry"] * jointNumber))),
                                ((Transforms [i] ["nMult"] * jointNumber) + Transforms [i] ["nmrz"]) * TREEUtils.Noise(((Transforms [i] ["nsrz"] * -timer + Transforms [i] ["norz"] + (Transforms [i] ["nrorz"] * jointOffset) + (Transforms [i] ["naorz"] * jointOffset2)) + (Transforms [i] ["nfrz"] * jointNumber)))
                                );
                        }


                        if (Transforms [i] ["smsx"] != 0 || Transforms [i] ["smsy"] != 0 || Transforms [i] ["smsz"] != 0)
                        {
                            sinScale.Set(
                                ((Transforms [i] ["ssMult"] * jointNumber) + Transforms [i] ["smsx"]) * Mathf.Sin(((Transforms [i] ["sssx"] * timer + Transforms [i] ["sosx"] + (Transforms [i] ["srosx"] * jointOffset)) + (Transforms [i] ["sfsx"] * jointNumber))),
                                ((Transforms [i] ["ssMult"] * jointNumber) + Transforms [i] ["smsy"]) * Mathf.Sin(((Transforms [i] ["sssy"] * timer + Transforms [i] ["sosy"] + (Transforms [i] ["srosy"] * jointOffset)) + (Transforms [i] ["sfsy"] * jointNumber))),
                                ((Transforms [i] ["ssMult"] * jointNumber) + Transforms [i] ["smsz"]) * Mathf.Sin(((Transforms [i] ["sssz"] * timer + Transforms [i] ["sosz"] + (Transforms [i] ["srosz"] * jointOffset)) + (Transforms [i] ["sfsz"] * jointNumber)))
                                );
                        }

                        if (Transforms [i] ["sus"] != 0)
                        {
                            sinScale.Set(sinScale.x, sinScale.x, sinScale.x);
                        }

                        if (Transforms [i] ["length"] != 0)
                        {
                            if (g.GetComponent <Joint> ().childJoint != null)
                            {
                                float off;
                                off = ((Transforms [i] ["lMult"] * jointNumber) + Transforms [i] ["sml"]) * Mathf.Sin(((Transforms [i] ["ssl"] * timer + Transforms [i] ["sol"] + (Transforms [i] ["srol"] * jointOffset) + (Transforms [i] ["saol"] * jointOffset2)) + (Transforms [i] ["sfl"] * jointNumber)));
                                g.GetComponent <Joint> ().childJoint.transform.localPosition = new Vector3(0, Transforms [i] ["length"] + off, 0);
                                Vector3 sc = g.GetComponent <Joint> ().scalar.transform.localScale;
                                g.GetComponent <Joint> ().scalar.transform.localScale = new Vector3(sc.x, Transforms [i] ["length"] + off, sc.z);
                            }
                        }


                        rotateOffset.Set(Transforms [i] ["orx"] * timer, Transforms [i] ["ory"] * timer, Transforms [i] ["orz"] * timer);
                        g.transform.localEulerAngles = rotate + init + sinRotate + noiseRotate + rotateOffset;

                        //				g.transform.Rotate (rotateOffset.x,rotateOffset.y,rotateOffset.z);
                        scale.Set(Transforms [i] ["scale"] + Transforms [i] ["sx"], Transforms [i] ["scale"] + Transforms [i] ["sy"], Transforms [i] ["scale"] + Transforms [i] ["sz"]);
                        Vector3 overallScale = sinScale + scale;

                        if (Transforms [i] ["cr"] != 0 || Transforms [i] ["cg"] != 0 || Transforms [i] ["cb"] != 0)
                        {
                            Color initCol = new Color(
                                Transforms [i] ["cr"],
                                Transforms [i] ["cg"],
                                Transforms [i] ["cb"]);
                            float hue, S, V;
                            Color.RGBToHSV(initCol, out hue, out S, out V);
                            float off  = ((Transforms [i] ["cMult"] * jointNumber) + Transforms [i] ["smc"]) * Mathf.Sin(((Transforms [i] ["ssc"] * timer + Transforms [i] ["soc"] + (Transforms [i] ["sroc"] * jointOffset) + (Transforms [i] ["saoc"] * jointOffset2)) + (Transforms [i] ["sfc"] * jointNumber)));
                            float fOff = off - Mathf.Floor(off);
                            if (fOff < 0)
                            {
                                fOff -= Mathf.Floor(off);
                            }
                            for (int k = 0; k < g.GetComponent <Joint> ().scalar.transform.childCount; k++)
                            {
                                if (g.GetComponent <Joint> ().scalar.transform.GetChild(k).GetComponent <MeshRenderer> () != null)
                                {
                                    g.GetComponent <Joint> ().scalar.transform.GetChild(k).GetComponent <MeshRenderer> ().material.color = Color.HSVToRGB(fOff, 1, 1);
                                }
                                ;
                            }
                            for (int k = 0; k < g.GetComponent <Joint> ().rotator.transform.childCount; k++)
                            {
                                if (g.GetComponent <Joint> ().rotator.transform.GetChild(k).GetComponent <MeshRenderer> () != null)
                                {
                                    g.GetComponent <Joint> ().rotator.transform.GetChild(k).GetComponent <MeshRenderer> ().material.color = Color.HSVToRGB(fOff, 1, 1);
                                }
                                ;
                            }
//							g.GetComponent<Joint> ().scalar.transform.GetChild (0).GetComponent<MeshRenderer> ().material.color = Color.HSVToRGB (fOff, 1, 1);
                        }

                        if (!overallScale.Equals(Vector3.one))
                        {
                            g.transform.localScale = overallScale;                            // Vector3.Scale(overallScale , new Vector3 (Transforms [i] ["sx"], Transforms [i] ["sy"], Transforms [i] ["sz"]));
                        }
                    }
                }
            }
        }