示例#1
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;
            }
        }
示例#2
0
        public override void Setup()
        {
//			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);
//				}
//				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);
            rebuild = false;
        }
示例#3
0
//
//	public void setDictionaryName(params int[] name){
//
//	}

        private void _construct()
        {
            GameObject ballMesh = TREEUtils.makePart(trait.ballMesh, trait.material);

            GameObject jointMesh = TREEUtils.makePart(trait.jointMesh, trait.material);

            jointMesh.transform.localPosition = new Vector3(0, .5f, 0);
            jointMesh.transform.localScale    = new Vector3(1, 1, 1);

            scalar       = new GameObject(); // trait.scalar;
            scalar.name  = "scalar";
            rotator      = new GameObject(); //trait.rotator;
            rotator.name = "rotator";

            jointMesh.transform.parent  = scalar.transform;
            scalar.transform.localScale = new Vector3(1, trait.jointScale, 1);

            ballMesh.transform.parent = rotator.transform;

            scalar.transform.parent  = rotator.transform;
            rotator.transform.parent = transform;

            if (trait.endJoint)
            {
                GameObject ballMesh2 = TREEUtils.makePart(trait.ballMesh, trait.material);
                ballMesh2.transform.parent        = rotator.transform;
                ballMesh2.transform.localPosition = new Vector3(0, trait.jointScale, 0);
            }
        }
示例#4
0
文件: TREE.cs 项目: IxxyXR/Tree-VFX
		public void generate(params string[] gene){
			
			genome = GenomeUtils.fixGenome (gene);
			Genome g = GenomeUtils.getGenome (new Genome (), genome);

			Trait t = new Trait();
			t.Apply (trait);
			GameObject tempRoot = makeJoint (t);



			for (int i = 0; i < g.rads[0]; i++) {

				t.jointScale = g.length [0];
				t.offset2 = i;

				GameObject thisRoot = Branch ((int)g.joints [0]-1,tempRoot.transform, t);
				thisRoot.transform.Rotate( new Vector3 (0, i * 360 / g.rads [0], g.angles [0]));

				tempRoot.GetComponent<Joint>().limbs.Add (thisRoot);

				this.GetComponent<Joint>().limbs.Add(thisRoot);

				if(g.joints.Length>1)
					recursiveBranch (g, 1, thisRoot);
			}
			TREEUtils.copyTransforms (tempRoot, root);
			tempRoot.transform.parent = transform;

		}
示例#5
0
        void swapGeo()
        {
            for (int i = 0; i < selectedJoints.Count; i++)
            {
                for (int j = 0; j < selectedJoints [i].Count; j++)
                {
                    GameObject g = TREEUtils.findJoint(selectedJoints [i] [j], 0, tree.transform.GetChild(0).gameObject);
                    GameObject duplicateRotator = Instantiate(jointGeo [i].rotator.transform.GetChild(0)).gameObject;
                    GameObject duplicateScalar  = Instantiate(jointGeo [i].scalar);
                    duplicateScalar.name  = "scalar_" + i + "_" + j;
                    duplicateRotator.name = "rotator" + i + "_" + j;

                    Transform t = g.GetComponent <TREESharp.Joint> ().rotator.transform;

                    TREEUtils.copyTransforms(duplicateScalar, g.GetComponent <TREESharp.Joint> ().scalar.gameObject);
                    TREEUtils.copyTransforms(duplicateRotator, g.GetComponent <TREESharp.Joint> ().rotator.gameObject);

                    Destroy(g.GetComponent <TREESharp.Joint> ().scalar.gameObject);
                    Destroy(g.GetComponent <TREESharp.Joint> ().rotator.transform.GetChild(0).gameObject);
                    duplicateRotator.transform.parent = t;
                    duplicateScalar.transform.parent  = t;

                    g.GetComponent <TREESharp.Joint> ().scalar = duplicateScalar;
//
                    if (g.GetComponent <TREESharp.Joint> ().tip != null)
                    {
                        GameObject tip = Instantiate(jointGeo [i].rotator.transform.GetChild(0)).gameObject;
                        TREEUtils.copyTransforms(tip, g.GetComponent <TREESharp.Joint> ().tip.gameObject);
                        tip.transform.parent = t;
                        Destroy(g.GetComponent <TREESharp.Joint> ().tip);
                    }
                }
            }
        }
示例#6
0
        public static Hashtable fixGenome(params string[] genes)
        {
            //helper function for generate

            Hashtable nGenome;

            if (genes.Length % 2 != 0)
            {
                Debug.LogWarning("wrong number of arguments");
                return(generateEmptyGenome(0));
            }
            else
            {
                int counter = 0;
                for (int i = 1; i < genes.Length; i += 2)
                {
                    float[] t = TREEUtils.stringToFloatArray(genes [i]);
                    if (counter < t.Length)
                    {
                        counter = t.Length;
                    }
                }

                nGenome = generateEmptyGenome(counter);

                for (int i = 0; i < genes.Length; i += 2)
                {
                    float[] a = TREEUtils.stringToFloatArray((string)genes [i + 1]);
                    float[] b = nGenome [(string)genes [i]] as float[];
                    TREEUtils.mergeArrays(a, b);
                }
            }
            return(nGenome);
        }
示例#7
0
 void Init()
 {
     for (int i = 0; i < selectedJoints.Count; i++)
     {
         for (int j = 0; j < selectedJoints [i].Count; j++)
         {
             GameObject g = TREEUtils.findJoint(selectedJoints[i][j], 0, tree.transform.GetChild(0).gameObject);
             StartCoroutine(Traverse(g));
         }
     }
 }
示例#8
0
        // Use this for initialization
        public override void Setup()
        {
            tree.setDefaultJoint(defaultJoint);

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

            rebuild = false;

            if (tempJoint == null)
            {
                tempJoint = Instantiate(TREEUtils.findJoint(new int[] { 0, 0, 0 }, 0, tree.gameObject).gameObject);
            }

            GameObject g        = TREEUtils.findJoint(new int[] { 0, 0, (int)Random.Range(0, 9) }, 0, tree.gameObject).gameObject;
            GameObject thisRoot = tree.Branch(10, g.transform);

            g.GetComponent <Joint> ().limbs.Add(thisRoot);

            for (int i = 0; i < 10; i++)
            {
                g        = TREEUtils.findJoint(new int[] { 0, 0, (int)Random.Range(0, 9) }, 0, tree.gameObject).gameObject;
                thisRoot = tree.Branch(10, g.transform);
                g.GetComponent <Joint> ().limbs.Add(thisRoot);

                tree.jointDictionary.Clear();
                TREEUtils.makeDictionary(tree.gameObject);
            }

//
//			GameObject p = Instantiate (tempJoint);
//			TREEUtils.appendBranch (g, p);
//
//			tree.jointDictionary.Clear ();
//			TREEUtils.makeDictionary (tree.gameObject);
//
//			p = Instantiate (tempJoint);
//			g = TREEUtils.findJoint (new int[]{ 0, 0, (int)Random.Range(0,10) }, 0, tree.gameObject).gameObject;
//
//			TREEUtils.appendBranch (g, p);

            tree.jointDictionary.Clear();
            TREEUtils.makeDictionary(tree.gameObject);

//			p.transform.Rotate (new Vector3 (30, 30, 30));
        }
示例#9
0
文件: TREE.cs 项目: IxxyXR/Tree-VFX
		public GameObject makeJoint(Trait t){

			if (!defaultJointExists)
				return TREEUtils.JointFactory (t);
			else {
				GameObject G = Instantiate (defaultJoint);
				G.name = "joint_" + t.id;
				Joint J = G.GetComponent<Joint>();
				J.setTrait (t);
				J.setScale (t.jointScale);
				J.joint = t.id;
				return G;
			}
		}
示例#10
0
文件: TREE.cs 项目: dlobser/Sugar
        public void recursiveBranch(Genome g, int counter, GameObject joint)
        {
            GameObject newBranch, kidJoint;

            int end = (int)g.end [counter];

            if ((int)g.end [counter] == -1)
            {
                end = joint.GetComponent <Joint> ().joints + 1;
            }

            if (joint.GetComponent <Joint> ().joints < end)
            {
                end = joint.GetComponent <Joint> ().joints + 1;
            }

            for (int i = (int)g.start[counter]; i < end; i += (int)g.divs[counter])
            {
                kidJoint      = TREEUtils.findJointOnBranch(joint, i);
                kidJoint.name = "branchRoot_" + i;

                int[] jcounter = { ++jCounter };

                for (int j = 0; j < (int)g.rads[counter]; j++)
                {
                    Trait t = new Trait();
                    t.Apply(trait);

                    t.offset  = kidJoint.gameObject.GetComponent <Joint> ().joint;
                    t.offset2 = j;

                    t.jointScale = g.length [counter];

                    newBranch = Branch((int)g.joints [counter] - 1, t);
                    newBranch.transform.parent = kidJoint.transform;
                    TREEUtils.zeroTransforms(newBranch);
                    newBranch.transform.localEulerAngles = (new Vector3(0, j * 360 / g.rads [counter], g.angles [counter]));
                    newBranch.transform.localPosition    = (new Vector3(0, kidJoint.GetComponent <Joint> ().trait.jointScale, 0));
                    kidJoint.GetComponent <Joint> ().limbs.Add(newBranch);
                }
                if (counter + 1 < g.joints.Length)
                {
                    for (int k = 0; k < (int)kidJoint.GetComponent <Joint> ().limbs.Count; k++)
                    {
                        recursiveBranch(g, counter + 1, kidJoint.GetComponent <Joint> ().limbs [k]);
                    }
                }
            }
        }
示例#11
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);
        }
示例#12
0
        void swapGeo()
        {
            for (int i = 0; i < selectedJoints.Count; i++)
            {
                for (int j = 0; j < selectedJoints [i].Count; j++)
                {
                    GameObject g         = TREEUtils.findJoint(selectedJoints [i] [j], 0, tree.transform.GetChild(0).gameObject);
                    Joint      J         = g.GetComponent <Joint> ();
                    Joint      thisJoint = Instantiate(jointGeo [i]);
                    thisJoint.transform.parent = g.transform.parent;
//					TREEUtils.copyTransforms (jointGeo [i].GetComponent<GameObject>(), g);
                    thisJoint.transform.position   = new Vector3(g.transform.position.x, g.transform.position.y, g.transform.position.z);
                    thisJoint.transform.rotation   = new Quaternion(g.transform.rotation.x, g.transform.rotation.y, g.transform.rotation.z, g.transform.rotation.w);
                    thisJoint.transform.localScale = new Vector3(g.transform.localScale.x, g.transform.localScale.y, g.transform.localScale.z);
                    if (J.childJoint != null)
                    {
                        thisJoint.childJoint          = J.childJoint;
                        J.childJoint.transform.parent = thisJoint.transform;
                    }
                    thisJoint.dictionaryName = J.dictionaryName;
                    thisJoint.scalar.transform.localScale = J.scalar.transform.localScale;



                    thisJoint.joint   = J.joint;
                    thisJoint.joints  = J.joints;
                    thisJoint.offset  = J.offset;
                    thisJoint.offset2 = J.offset2;

                    if (g.transform.parent != null)
                    {
                        Debug.Log(thisJoint.gameObject.name);
                        g.transform.parent.GetComponent <Joint> ().childJoint = thisJoint.gameObject;
                    }

                    for (int k = 0; k < J.limbs.Count; k++)
                    {
                        thisJoint.limbs.Add(J.limbs [k]);
                        J.limbs [k].transform.parent = thisJoint.transform;
                    }

                    Destroy(g);
                }
            }
        }
示例#13
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);
        }
示例#14
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];
             }
         }
     }
 }
示例#15
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]);
                        }
                    }
                }
            }
        }
示例#16
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);
        }
示例#17
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];
                    }
                }
            }
        }
示例#18
0
        public static Hashtable generateEmptyGenome(int amount)
        {
            Hashtable genome = new Hashtable();

            float[] joints = new float[amount];
            TREEUtils.fillArray(6, joints);
            genome.Add("joints", joints);
            float[] divs = new float[amount];
            TREEUtils.fillArray(1, divs);
            genome.Add("divs", divs);
            genome.Add("rads", new float[amount]);
            float[] length = new float[amount];
            TREEUtils.fillArray(1, length);
            genome.Add("length", length);
            float[] angles = new float[amount];
            TREEUtils.fillArray(30, angles);
            genome.Add("angles", angles);
            genome.Add("start", new float[amount]);
            genome.Add("width", new float[amount]);
            float[] end = new float[amount];
            TREEUtils.fillArray(-1, end);
            genome.Add("end", end);
            return(genome);
        }
示例#19
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"]));
                        }
                    }
                }
            }
        }
示例#20
0
 public override void Setup()
 {
     selectedJoints = TREEUtils.ArgsArrayToJointList(selectJoints, tree);
     swapGeo();
     rebuild = false;
 }
示例#21
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"]));
                        }
                    }
                }
            }
        }
示例#22
0
 public override void Setup()
 {
     selectedJoints = TREEUtils.ArgsArrayToJointList(new string[] { "0|-1|0" }, tree);
     rebuild        = false;
     Init();
 }