// Start is called before the first frame update void Start() { LineModule stem_module = new LineModule('F', 0, 1, GrowthList.LINEAR); stem_module.LineWidth = 0.5f; stem_module.LineLength = 5.0f; //MeshModule stem_module = new MeshModule('M', 0, 1, GrowthList.LINEAR); //stem_module.x = 0.1f; //stem_module.y = 1f; //stem_module.z = 0.1f; RotationModule rotation_module = new RotationModule('+', 0, 1, GrowthList.NON_DEVELOPMENTAL, new Vector3(0, 0, 1), 0f, true); SystemModule branch_open_module = new BranchModule('[', 0, 1, GrowthList.NON_DEVELOPMENTAL, true); SystemModule branch_close_module = new BranchModule(']', 0, 1, GrowthList.NON_DEVELOPMENTAL, false); ObjectModule leaf_module = new ObjectModule('O', 0, 1, GrowthList.LOGISTIC, "Prefabs/ModuleObjects/ManilkaraLeaf"); leaf_module.scale = Vector3.one * 2.5f; List <SystemModule> main_axis = new List <SystemModule>(); //main_axis.Add(branch_open_module); main_axis.Add(rotation_module); main_axis.Add(stem_module); main_axis.Add(new ApexModule('2', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/PlatformApex")); //main_axis.Add(branch_close_module); main_axis.Add(new ApexModule('1', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/Apex")); system.Productions.Add('1', main_axis); List <SystemModule> platform_axis = new List <SystemModule>(); platform_axis.Add(branch_open_module); platform_axis.Add(rotation_module); platform_axis.Add(stem_module); platform_axis.Add(new PhysicsMoverModule('3', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/LeafWhorlMover")); platform_axis.Add(branch_close_module); system.Productions.Add('2', platform_axis); List <SystemModule> leaf_whorl = new List <SystemModule>(); leaf_whorl.Add(branch_open_module); for (int i = 0; i < 4; i++) { leaf_whorl.Add(branch_open_module.CopyModule()); leaf_whorl.Add(new RotationModule('+', 0, 1, GrowthList.LINEAR, Vector3.right, -45f, false)); leaf_whorl.Add(leaf_module.CopyModule()); leaf_whorl.Add(branch_close_module.CopyModule()); leaf_whorl.Add(new RotationModule('+', 0, 1, GrowthList.NON_DEVELOPMENTAL, Vector3.up, 90f, false)); } leaf_whorl.Add(branch_close_module); system.Productions.Add('3', leaf_whorl); ApexModule axiom_apex = system.Axiom as ApexModule; turtle.TurtleAnalysis(0f); axiom_apex.Apex.ActivateApex(); }
public override void InstantiateModule(Parametric_Turtle turtle) { PhysicsModule = GameObject.Instantiate(Resources.Load(Path) as GameObject, turtle.transform.parent); //PhysicsModule.transform.localPosition = turtle.transform.localPosition; //PhysicsModule.transform.localRotation = Quaternion.identity; PhysicsModule.GetComponent <ModuleBehaviour>().Module = this; PhysicsModule.GetComponent <PhysicsMover>().MoverController = this; ProximalApex = turtle.apexStack.Peek(); }
//Returns nearest main axis apex public ApexModule GetProximalMainAxisApex(ApexModule am) { ApexModule apex_candidate = am; while (!apex_candidate.MainAxis) { apex_candidate = GetProximalMainAxisApex(am.Parent); } return(apex_candidate); }
public override SystemModule CopyModule() { ApexModule am = ApexModule.CreateInstance <ApexModule>(); am.Symbol = Symbol; am.Age = Age; am.TerminalAge = TerminalAge; am.Growth = Growth; am.ApexPath = ApexPath; am.MainAxis = MainAxis; return(am); }
private void OnTriggerEnter(Collider other) { if (other.GetComponent <CharacterMachine>() != null && !finish) { player_triggered = true; finish = true; if (!rustle_sound.isPlaying) { rustle_sound.Play(); } proximalApex = (Module as PhysicsMoverModule).ProximalApex; proximalApex.Apex.GetComponent <MeshRenderer>().material.color = Color.blue; proximalApex.Parent.Parent.Apex.GetComponent <MeshRenderer>().material.color = Color.cyan; ApexModule siblingApex = null; foreach (ApexModule am in proximalApex.Parent.Parent.Children) { siblingApex = am; if (siblingApex.Children.Contains(proximalApex)) { continue; } else { break; } } if (siblingApex != null) { (siblingApex.Apex as AubrevilleApex).ActivateApex(); } else { Debug.Log("No sibling apex found"); } if (proximalApex.Depth >= Turtle.model.MaxLateralDepth) { Turtle.model.ApicesTriggered[0][Turtle.LateralTrigger] = 1; Turtle.LateralTrigger++; if (Turtle.LateralTrigger >= Turtle.model.BranchWhorls) { Turtle.LateralTrigger = 0; Turtle.model.CurrentLeaderAxisDepth++; ApexModule leader_axis = Turtle.p_l_sys.GetLeaderApex(); (leader_axis.Apex as AubrevilleApex).ActivateApex(); } } } }
private void recurse_tree(ApexModule am) { if (am.Children.Count < 1) { return; } else { foreach (ApexModule amc in am.Children) { Debug.DrawLine(am.Apex.transform.position, amc.Apex.transform.position, Color.red, 3000.0f, false); recurse_tree(amc); } } }
//Returns the underived apical meristem on the leader axis public ApexModule GetLeaderApex() { foreach (SystemModule sm in returnList) { if (sm is ApexModule) { ApexModule am = sm as ApexModule; if (!am.mature && am.MainAxis) { return(am); } } } return(null); }
public override void InstantiateModule(Parametric_Turtle turtle) { this.Parent = turtle.apexStack.Peek(); this.Children = new List <ApexModule>(); this.Parent.Children.Add(this); this.Depth = turtle.DepthCounter; this.Axis = turtle.p_l_sys.GetProximalMainAxisApex(this).Depth; GameObject ModuleObject = GameObject.Instantiate(Resources.Load(ApexPath), turtle.transform.parent) as GameObject; if (ModuleObject.GetComponent <Apex>() != null) { Apex = ModuleObject.GetComponent <Apex>(); Apex.ApexModule = this; } //this.UpdateModule(turtle); //turtle.apexStack.Pop(); }
public new void TurtleAnalysis(float age) { List <SystemModule> word = p_l_sys.returnList; p_l_sys.BaseNode.transform.localRotation = Quaternion.identity; transform.localPosition = new Vector3(initialPosition.x, initialPosition.y, initialPosition.z); saveOrientation = new Quaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w); for (int i = 0; i < word.Count; i++) { SystemModule mod = word[i]; mod.Age += age; mod.Age = Mathf.Clamp(mod.Age, 0, mod.TerminalAge); mod.UpdateModule(this); if (p_l_sys.Productions.ContainsKey(mod.Symbol)) { bool apex_ready = true; if (mod is ApexModule) { ApexModule am = mod as ApexModule; if (am.mature) { apex_ready = false; } else if ((am.MainAxis && am.Depth > model.CurrentLeaderAxisDepth)) { apex_ready = false; } else if (!am.MainAxis && am.Axis >= model.CurrentLeaderAxisDepth) { apex_ready = false; } else if (am.Depth - am.Axis > model.MaxLateralDepth) { apex_ready = false; } } //May need to move this to inside modules so that they can develop independently? if (mod.Age >= mod.TerminalAge && mod.TerminalAge >= 0 && apex_ready) { List <SystemModule> newList = new List <SystemModule>(); for (int j = 0; j < p_l_sys.Productions[mod.Symbol].Count; j++) { SystemModule m = p_l_sys.Productions[mod.Symbol][j].CopyModule(); m.InstantiateModule(this); newList.Add(m); } if (mod is ApexModule) { ApexModule am = mod as ApexModule; am.mature = true; am.Apex.ProximalModules = new List <SystemModule>(newList); } else if (mod is PhysicsMoverModule) { PhysicsMoverModule pmm = mod as PhysicsMoverModule; pmm.ProximalModules = newList; pmm.PhysicsModule.GetComponent <ModuleBehaviour>().ProximalModules = newList; } additionsList.Add(i, newList); } } } apexStack.Clear(); if (additionsList.Count != 0) { p_l_sys.newString = true; int i = -1; foreach (KeyValuePair <int, List <SystemModule> > kvp in additionsList) { if (i == -1) //First iteration { i = kvp.Value.Count; //p_l_sys.returnList.RemoveAt(kvp.Key); p_l_sys.returnList.InsertRange(kvp.Key + 1, kvp.Value); } else //every other { //p_l_sys.returnList.RemoveAt(i + kvp.Key); p_l_sys.returnList.InsertRange(i + kvp.Key + 1, kvp.Value); i += kvp.Value.Count; } } additionsList.Clear(); } transform.rotation = new Quaternion(saveOrientation.x, saveOrientation.y, saveOrientation.z, saveOrientation.w); }
// Start is called before the first frame update void Start() { //Set the axiom's current age to 1 so that it derives at time 0 system.Axiom = new ApexModule('1', 1, 1, GrowthList.LOGISTIC, "Prefabs/ModuleObjects/AubrevilleApex", true); turtle.apexStack.Push(system.Axiom as ApexModule); system.Axiom.InstantiateModule(turtle); ApexModule am = (system.Axiom as ApexModule); am.Children.RemoveAt(am.Children.Count - 1); ObjectModule leaf_module = new ObjectModule('O', 0, 1, GrowthList.LOGISTIC, "Prefabs/ModuleObjects/ManilkaraLeaf"); leaf_module.scale = Vector3.one * 3f; MeshModule stem_module = new MeshModule('F', 0, 1, GrowthList.LINEAR); BezierMeshModule branch_module = new BezierMeshModule('F', 0, 1, GrowthList.LINEAR); branch_module.apposition = true; BezierMeshModule flowering_branch = new BezierMeshModule('F', 0, 1, GrowthList.LINEAR); flowering_branch.height = 0.25f; RotationModule rotation_module = new RotationModule('+', 0, 1, GrowthList.LINEAR, new Vector3(0, 0, 1), 75f); SystemModule branch_open_module = new BranchModule('[', 0, 1, GrowthList.NON_DEVELOPMENTAL, true); SystemModule branch_close_module = new BranchModule(']', 0, 1, GrowthList.NON_DEVELOPMENTAL, false); SystemModule branch_close_module_no_apex = new BranchModule(']', 0, 1, GrowthList.NON_DEVELOPMENTAL, false, false); List <SystemModule> main_axis = new List <SystemModule>(); main_axis.Add(stem_module); for (int i = 0; i < BranchWhorls; i++) { main_axis.Add(branch_open_module); main_axis.Add(new RotationModule('+', 0, 1, GrowthList.NON_DEVELOPMENTAL, new Vector3(0, 1, 0), i * 360f / BranchWhorls)); main_axis.Add(new RotationModule('+', 0, 1, GrowthList.LINEAR, new Vector3(1, 0, 0), 90f)); main_axis.Add(new ApexModule('2', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/AubrevilleApex")); main_axis.Add(branch_close_module); } main_axis.Add(new RotationModule('+', 0, 1, GrowthList.LINEAR, Vector3.up, 45f)); main_axis.Add(branch_open_module.CopyModule()); main_axis.Add(new ApexModule('1', 0, 1, GrowthList.LOGISTIC, "Prefabs/ModuleObjects/AubrevilleApex", true)); main_axis.Add(branch_close_module.CopyModule()); system.Productions.Add('1', main_axis); List <SystemModule> whorl_axis = new List <SystemModule>(); whorl_axis.Add(branch_module.CopyModule()); whorl_axis.Add(branch_open_module.CopyModule()); whorl_axis.Add(new RotationModule('+', 0, 1, GrowthList.LINEAR, new Vector3(1, 0, 0), -90f)); whorl_axis.Add(new ApexModule('3', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/AubrevilleApex")); whorl_axis.Add(branch_close_module.CopyModule()); whorl_axis.Add(branch_open_module.CopyModule()); whorl_axis.Add(new ApexModule('2', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/AubrevilleApex")); whorl_axis.Add(branch_close_module.CopyModule()); system.Productions.Add('2', whorl_axis); List <SystemModule> flowering_axis = new List <SystemModule>(); flowering_axis.Add(flowering_branch.CopyModule()); flowering_axis.Add(new RotationModule('+', 0, 1, GrowthList.NON_DEVELOPMENTAL, Vector3.up, 90f)); flowering_axis.Add(branch_open_module.CopyModule()); flowering_axis.Add(new ApexModule('4', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/AubrevilleApex")); flowering_axis.Add(branch_close_module.CopyModule()); system.Productions.Add('3', flowering_axis); List <SystemModule> leaf_whorl = new List <SystemModule>(); leaf_whorl.Add(new PhysicsMoverModule('M', 0, 1, GrowthList.LINEAR, "Prefabs/ModuleObjects/AubrevilleLeafWhorl")); for (int i = 0; i < 4; i++) { leaf_whorl.Add(branch_open_module.CopyModule()); leaf_whorl.Add(new RotationModule('+', 0, 1, GrowthList.LINEAR, Vector3.right, -45f)); leaf_whorl.Add(leaf_module.CopyModule()); leaf_whorl.Add(branch_close_module_no_apex.CopyModule()); leaf_whorl.Add(new RotationModule('+', 0, 1, GrowthList.NON_DEVELOPMENTAL, Vector3.up, 90f)); } system.Productions.Add('4', leaf_whorl); }
private void DrawDebugTopology() { ApexModule currentApex = system.Axiom as ApexModule; recurse_tree(currentApex); }