public void sanitiseConfiguration(IFormConfiguration formConfiguration) { //RADIUS if (formConfiguration.getBranchPositionDelta().x < 0.2f) { Vector3 v = formConfiguration.getBranchPositionDelta(); v.x = 0.2f; formConfiguration.setBranchPositionDelta(v); } if (formConfiguration.getBranchPositionDelta().x > 1.0f) { Vector3 v = formConfiguration.getBranchPositionDelta(); v.x = 1.0f; formConfiguration.setBranchPositionDelta(v); } //RHUMB ANGLE if (formConfiguration.getStartRotation().x < 0) { Vector3 v = formConfiguration.getStartRotation(); v.x = 0; formConfiguration.setStartRotation(v); } if (formConfiguration.getStartRotation().x > 2f) { Vector3 v = formConfiguration.getStartRotation(); v.x = 2.0f; formConfiguration.setStartRotation(v); } }
public static void saveConfiguration(IFormConfiguration formConfiguration) { string fileSavePath = Application.persistentDataPath + "/FormConfigSlot" + (formConfiguration.getIndex() + 1) + ".xml"; Debug.Log("Save:" + fileSavePath); XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("", "form", ""); //save data root.SetAttribute("branchPositionDeltaX", formConfiguration.getBranchPositionDelta().x.ToString()); root.SetAttribute("branchPositionDeltaY", formConfiguration.getBranchPositionDelta().y.ToString()); root.SetAttribute("branchPositionDeltaZ", formConfiguration.getBranchPositionDelta().z.ToString()); root.SetAttribute("branchTwistDeltaX", formConfiguration.getBranchTwistDelta().x.ToString()); root.SetAttribute("branchTwistDeltaY", formConfiguration.getBranchTwistDelta().y.ToString()); root.SetAttribute("branchTwistDeltaZ", formConfiguration.getBranchTwistDelta().z.ToString()); root.SetAttribute("index", formConfiguration.getIndex().ToString()); root.SetAttribute("mutationStrength", formConfiguration.getMutationStrength().ToString()); root.SetAttribute("scaleBranch", formConfiguration.getScaleBranch().ToString()); root.SetAttribute("scaleDelta", formConfiguration.getScaleDelta().ToString()); root.SetAttribute("scaleTrunk", formConfiguration.getScaleTrunk().ToString()); root.SetAttribute("stackIterations", formConfiguration.getStackIterations().ToString()); root.SetAttribute("stackShapeIndex", formConfiguration.getStackShapeIndex().ToString()); root.SetAttribute("stackStartTwistX", formConfiguration.getStackStartTwist().x.ToString()); root.SetAttribute("stackStartTwistY", formConfiguration.getStackStartTwist().y.ToString()); root.SetAttribute("stackStartTwistZ", formConfiguration.getStackStartTwist().z.ToString()); root.SetAttribute("stackTwistDeltaX", formConfiguration.getStackTwistDelta().x.ToString()); root.SetAttribute("stackTwistDeltaY", formConfiguration.getStackTwistDelta().y.ToString()); root.SetAttribute("stackTwistDeltaZ", formConfiguration.getStackTwistDelta().z.ToString()); root.SetAttribute("startPositionX", formConfiguration.getStartPosition().x.ToString()); root.SetAttribute("startPositionY", formConfiguration.getStartPosition().y.ToString()); root.SetAttribute("startPositionZ", formConfiguration.getStartPosition().z.ToString()); root.SetAttribute("startRotationX", formConfiguration.getStartRotation().x.ToString()); root.SetAttribute("startRotationY", formConfiguration.getStartRotation().y.ToString()); root.SetAttribute("startRotationZ", formConfiguration.getStartRotation().z.ToString()); root.SetAttribute("startScale", formConfiguration.getStartScale().ToString()); root.SetAttribute("trunkIterations", formConfiguration.getTrunkIterations().ToString()); root.SetAttribute("trunkPositionDeltaX", formConfiguration.getTrunkPositionDelta().x.ToString()); root.SetAttribute("trunkPositionDeltaY", formConfiguration.getTrunkPositionDelta().y.ToString()); root.SetAttribute("trunkPositionDeltaZ", formConfiguration.getTrunkPositionDelta().z.ToString()); root.SetAttribute("trunklRotationDeltaX", formConfiguration.getTrunkRotationDelta().x.ToString()); root.SetAttribute("trunklRotationDeltaY", formConfiguration.getTrunkRotationDelta().y.ToString()); root.SetAttribute("trunklRotationDeltaZ", formConfiguration.getTrunkRotationDelta().z.ToString()); xmlDoc.AppendChild(root); //save xmlDoc.Save(fileSavePath); }
public void createTrunk(List <Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); for (int i = 0; i < formConfig.getTrunkIterations(); i++) { formBounds.calculateNewBounds(branchStartPosition); Branch branch = new Branch(i, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); branches.Add(branch); branchStartPosition.x += formConfig.getTrunkPositionDelta().x; branchStartPosition.y += formConfig.getTrunkPositionDelta().y; branchStartPosition.z += formConfig.getTrunkPositionDelta().z; branchStartTwist.x += formConfig.getTrunkRotationDelta().x; branchStartTwist.y += formConfig.getTrunkRotationDelta().y; branchStartTwist.z += formConfig.getTrunkRotationDelta().z; } }
public void createTrunk(List <Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); for (int i = 0; i < formConfig.getTrunkIterations(); i++) { formBounds.calculateNewBounds(branchStartPosition); Branch branch = new Branch(0, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); //magic 0 no offset branches.Add(branch); //set origin to previous start position branchStartOrigin = branchStartPosition; branchStartTwist = GeometryUtility.addDeltaToRotation(branchStartTwist, formConfig.getTrunkRotationDelta()); branchStartPosition = GeometryUtility.addDeltaToPosition(branchStartPosition, formConfig.getTrunkPositionDelta(), 1); } }
public void mutateTrunk(List <Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { int offset = (formConfig.getTrunkIterations() * formConfig.getStackIterations() / 2) * -1; Vector3 branchStartPosition = formConfig.getStartPosition(); branchStartPosition.y = branchStartPosition.y + 10; Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); foreach (Branch branch in branches) { formBounds.calculateNewBounds(branchStartPosition); branch.mutate(offset, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); offset += formConfig.getStackIterations(); } }
public void mutateTrunk(List <Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); int i = 0; foreach (Branch branch in branches) { formBounds.calculateNewBounds(branchStartPosition); branch.mutate(i, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); branchStartPosition.x += formConfig.getTrunkPositionDelta().x; branchStartPosition.y += formConfig.getTrunkPositionDelta().y; branchStartPosition.z += formConfig.getTrunkPositionDelta().z; branchStartTwist.x += formConfig.getTrunkRotationDelta().x; branchStartTwist.y += formConfig.getTrunkRotationDelta().y; branchStartTwist.z += formConfig.getTrunkRotationDelta().z; i++; } }
public void mutateTrunk(List <Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 origin = formConfig.getStartPosition(); foreach (Branch branch in branches) { formBounds.calculateNewBounds(branchStartPosition); branch.mutate(0, formConfig, colourConfig, branchStartPosition, branchStartTwist, origin, formBounds); //set origin to previous start position origin = branchStartPosition; branchStartTwist = GeometryUtility.addDeltaToRotation(branchStartTwist, formConfig.getTrunkRotationDelta()); branchStartPosition = GeometryUtility.addDeltaToPosition(branchStartPosition, formConfig.getTrunkPositionDelta(), 1); } }
public void mutateBranch(List <IStack> stacks, int offset, IFormConfiguration formConfig, ColourConfiguration colourConfig, Vector3 branchStartPosition, Vector3 branchStartTwist, Vector3 origin, FormBounds formBounds) { Vector3 position = origin; Vector3 stackTwist = formConfig.getStackStartTwist(); float radius = formConfig.getBranchPositionDelta().x * 20; float rhumbAngle = formConfig.getStartRotation().x * 0.032f; //colour stuff int iterations = formConfig.getStackIterations(); Color modelColour = new Color(colourConfig.getBaseRed(), colourConfig.getBaseGreen(), colourConfig.getBaseBlue(), 1); //if cycling override base colour if (colourConfig.getCycle()) { modelColour = colourConfig.getCycleColour(); } int i = offset; foreach (IStack stack in stacks) { position.x = formConfig.getStartPosition().x + (radius * (float)Math.Cos(i) / (float)Math.Cosh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.y = formConfig.getStartPosition().y + (radius * (float)Math.Sin(i) / (float)Math.Cosh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.z = formConfig.getStartPosition().z + (radius * (float)Math.Tanh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); formBounds.calculateNewBounds(position); //colour stuff order is important Color stackColour = modelColour; if (colourConfig.getFadeColour()) { //fade colour in stackColour = ColourUtility.fadeModelColour(modelColour, iterations, i - offset); } if (colourConfig.getPulse()) { //do pulse stackColour = colourConfig.getPulseColourForStack(stackColour, i - offset); } stack.mutateTo(position, stackTwist, 0.5f, stackColour); stackTwist = GeometryUtility.addDeltaToRotation(stackTwist, formConfig.getStackTwistDelta()); i++; } }
public IFormConfiguration(IFormConfiguration config) { this.index = config.getIndex(); this.startPosition = config.getStartPosition(); this.startRotation = config.getStartRotation(); this.trunkPositionDelta = config.getTrunkPositionDelta(); this.trunkRotationDelta = config.getTrunkRotationDelta(); this.trunkIterations = config.getTrunkIterations(); this.scaleTrunk = config.getScaleTrunk(); this.branchPositionDelta = config.getBranchPositionDelta(); this.branchTwistDelta = config.getBranchTwistDelta(); this.stackIterations = config.getStackIterations(); this.startScale = config.getStartScale(); this.scaleDelta = config.getScaleDelta(); this.scaleBranch = config.getScaleBranch(); this.stackStartTwist = config.getStackStartTwist(); this.stackTwistDelta = config.getStackTwistDelta(); this.stackShape = config.getStackShape(); this.mutationStrength = config.getMutationStrength(); }
public IFormConfiguration(IFormConfiguration config) { this.index = config.getIndex (); this.startPosition = config.getStartPosition (); this.startRotation = config.getStartRotation (); this.trunkPositionDelta = config.getTrunkPositionDelta (); this.trunkRotationDelta = config.getTrunkRotationDelta (); this.trunkIterations = config.getTrunkIterations (); this.scaleTrunk = config.getScaleTrunk (); this.branchPositionDelta = config.getBranchPositionDelta (); this.branchTwistDelta = config.getBranchTwistDelta (); this.stackIterations = config.getStackIterations (); this.startScale = config.getStartScale (); this.scaleDelta = config.getScaleDelta (); this.scaleBranch = config.getScaleBranch (); this.stackStartTwist = config.getStackStartTwist (); this.stackTwistDelta = config.getStackTwistDelta (); this.stackShape = config.getStackShape (); this.mutationStrength = config.getMutationStrength (); }
public void displayFormBuilderPalette(IFormConfiguration formConfig) { // Make a background box GUI.Box(new Rect(10, 10, 700, 590), "Builder Palette"); bool displayStarfishControls = false; bool displayLoxodromeControls = false; bool displayRingControls = false; if (formConfig.getFormProcessor().GetType() == typeof(StarfishForm)) { displayStarfishControls = true; } else if (formConfig.getFormProcessor().GetType() == typeof(LoxodromeForm)) { displayLoxodromeControls = true; } else if (formConfig.getFormProcessor().GetType() == typeof(RingForm)) { displayRingControls = true; } /* TRUNK */ //start position Vector3 startPosition = formConfig.getStartPosition(); startPositionX = startPosition.x; startPositionY = startPosition.y; startPositionZ = startPosition.z; GUI.Label(new Rect(20, 40, 150, 20), "Trunk Start Position X"); startPositionX = GUI.HorizontalSlider(new Rect(180, 45, 180, 20), startPositionX, -5, 5); GUI.Label(new Rect(20, 70, 150, 20), "Trunk Start Position Y"); startPositionY = GUI.HorizontalSlider(new Rect(180, 75, 180, 20), startPositionY, -5, 5); GUI.Label(new Rect(20, 100, 150, 20), "Trunk Start Position Z"); startPositionZ = GUI.HorizontalSlider(new Rect(180, 105, 180, 20), startPositionZ, -5, 5); startPosition.x = startPositionX; startPosition.y = startPositionY; startPosition.z = startPositionZ; formConfig.setStartPosition(startPosition); // start rotation Vector3 startRotation = formConfig.getStartRotation(); startRotationX = startRotation.x; startRotationY = startRotation.y; startRotationZ = startRotation.z; if (displayLoxodromeControls) { GUI.Label(new Rect(370, 40, 150, 20), "Rhumb Angle"); //startRotationX = GUI.HorizontalSlider (new Rect (520, 45, 180, 20), startRotationX, 0.1f, 2f); startRotationX = GUI.HorizontalSlider(new Rect(520, 45, 180, 20), startRotationX, 0, 2f); } if (displayStarfishControls) { GUI.Label(new Rect(370, 40, 150, 20), "Trunk Start Rotation X"); startRotationX = GUI.HorizontalSlider(new Rect(520, 45, 180, 20), startRotationX, 0, 360); } if (displayStarfishControls || displayRingControls) { GUI.Label(new Rect(370, 70, 150, 20), "Trunk Start Rotation Y"); startRotationY = GUI.HorizontalSlider(new Rect(520, 75, 180, 20), startRotationY, 0, 360); GUI.Label(new Rect(370, 100, 150, 20), "Trunk Start Rotation Z"); startRotationZ = GUI.HorizontalSlider(new Rect(520, 105, 180, 20), startRotationZ, 0, 360); } startRotation.x = startRotationX; startRotation.y = startRotationY; startRotation.z = startRotationZ; formConfig.setStartRotation(startRotation); //trunk position delta Vector3 trunkPositionDelta = formConfig.getTrunkPositionDelta(); trunkPositionDeltaX = trunkPositionDelta.x; trunkPositionDeltaY = trunkPositionDelta.y; trunkPositionDeltaZ = trunkPositionDelta.z; if (displayStarfishControls || displayRingControls) { GUI.Label(new Rect(20, 130, 150, 20), "Trunk Position Delta X"); trunkPositionDeltaX = GUI.HorizontalSlider(new Rect(180, 135, 180, 20), trunkPositionDeltaX, -1, 1); GUI.Label(new Rect(20, 160, 150, 20), "Trunk Position Delta Y"); trunkPositionDeltaY = GUI.HorizontalSlider(new Rect(180, 165, 180, 20), trunkPositionDeltaY, -1, 1); GUI.Label(new Rect(20, 190, 150, 20), "Trunk Position Delta Z"); trunkPositionDeltaZ = GUI.HorizontalSlider(new Rect(180, 195, 180, 20), trunkPositionDeltaZ, -1, 1); } trunkPositionDelta.x = trunkPositionDeltaX; trunkPositionDelta.y = trunkPositionDeltaY; trunkPositionDelta.z = trunkPositionDeltaZ; formConfig.setTrunkPositionDelta(trunkPositionDelta); //trunk rotation delta Vector3 trunkRotatiomnDelta = formConfig.getTrunkRotationDelta(); trunkRotationDeltaX = trunkRotatiomnDelta.x; trunkRotationDeltaY = trunkRotatiomnDelta.y; trunkRotationDeltaZ = trunkRotatiomnDelta.z; if (displayStarfishControls) { GUI.Label(new Rect(20, 220, 150, 20), "Trunk Rotation Delta X"); trunkRotationDeltaX = GUI.HorizontalSlider(new Rect(180, 225, 180, 20), trunkRotationDeltaX, -60, 60); } if (displayStarfishControls || displayRingControls) { GUI.Label(new Rect(20, 250, 150, 20), "Trunk Rotation Delta Y"); trunkRotationDeltaY = GUI.HorizontalSlider(new Rect(180, 255, 180, 20), trunkRotationDeltaY, -60, 60); GUI.Label(new Rect(20, 280, 150, 20), "Trunk Rotation Delta Z"); trunkRotationDeltaZ = GUI.HorizontalSlider(new Rect(180, 285, 180, 20), trunkRotationDeltaZ, -60, 60); } trunkRotatiomnDelta.x = trunkRotationDeltaX; trunkRotatiomnDelta.y = trunkRotationDeltaY; trunkRotatiomnDelta.z = trunkRotationDeltaZ; formConfig.setTrunkRotationDelta(trunkRotatiomnDelta); //trunk iterations trunkIterations = formConfig.getTrunkIterations(); GUI.Label(new Rect(20, 310, 150, 20), "Trunk Iterations *"); trunkIterations = GUI.HorizontalSlider(new Rect(180, 315, 180, 20), trunkIterations, 1, 24); formConfig.setTrunkIterations((int)trunkIterations); /* BRANCH */ //branch position delta Vector3 branchPositionDelta = formConfig.getBranchPositionDelta(); branchPositionDeltaX = branchPositionDelta.x; branchPositionDeltaY = branchPositionDelta.y; branchPositionDeltaZ = branchPositionDelta.z; if (displayRingControls || displayLoxodromeControls) { GUI.Label(new Rect(370, 130, 150, 20), "Radius"); branchPositionDeltaX = GUI.HorizontalSlider(new Rect(520, 135, 180, 20), branchPositionDeltaX, 0.2f, 1); } if (displayStarfishControls) { GUI.Label(new Rect(370, 130, 150, 20), "Branch Position Delta X"); branchPositionDeltaX = GUI.HorizontalSlider(new Rect(520, 135, 180, 20), branchPositionDeltaX, -1, 1); GUI.Label(new Rect(370, 160, 150, 20), "Branch Position Delta Y"); branchPositionDeltaY = GUI.HorizontalSlider(new Rect(520, 165, 180, 20), branchPositionDeltaY, -1, 1); GUI.Label(new Rect(370, 190, 150, 20), "Branch Position Delta Z"); branchPositionDeltaZ = GUI.HorizontalSlider(new Rect(520, 195, 180, 20), branchPositionDeltaZ, -1, 1); } branchPositionDelta.x = branchPositionDeltaX; branchPositionDelta.y = branchPositionDeltaY; branchPositionDelta.z = branchPositionDeltaZ; formConfig.setBranchPositionDelta(branchPositionDelta); //branch rotation delta Vector3 branchRotationDelta = formConfig.getBranchTwistDelta(); branchRotationDeltaX = branchRotationDelta.x; branchRotationDeltaY = branchRotationDelta.y; branchRotationDeltaZ = branchRotationDelta.z; if (displayStarfishControls) { GUI.Label(new Rect(370, 220, 150, 20), "Branch Rotation Delta X"); branchRotationDeltaX = GUI.HorizontalSlider(new Rect(520, 225, 180, 20), branchRotationDeltaX, -30, 30); GUI.Label(new Rect(370, 250, 150, 20), "Branch Rotation Delta Y"); branchRotationDeltaY = GUI.HorizontalSlider(new Rect(520, 255, 180, 20), branchRotationDeltaY, -30, 30); GUI.Label(new Rect(370, 280, 150, 20), "Branch Rotation Delta Z"); branchRotationDeltaZ = GUI.HorizontalSlider(new Rect(520, 285, 180, 20), branchRotationDeltaZ, -30, 30); } branchRotationDelta.x = branchRotationDeltaX; branchRotationDelta.y = branchRotationDeltaY; branchRotationDelta.z = branchRotationDeltaZ; formConfig.setBranchTwistDelta(branchRotationDelta); //branch iterations branchIterations = formConfig.getStackIterations(); GUI.Label(new Rect(370, 310, 150, 20), "Branch Iterations *"); branchIterations = GUI.HorizontalSlider(new Rect(520, 315, 180, 20), branchIterations, 1, 60); formConfig.setStackIterations((int)branchIterations); /* STACK */ //stack start rotation Vector3 stackStartRotation = formConfig.getStackStartTwist(); stackStartRotationX = stackStartRotation.x; stackStartRotationY = stackStartRotation.y; stackStartRotationZ = stackStartRotation.z; GUI.Label(new Rect(20, 340, 150, 20), "Stack Start Rotation X"); stackStartRotationX = GUI.HorizontalSlider(new Rect(180, 345, 180, 20), stackStartRotationX, 0, 360); GUI.Label(new Rect(20, 370, 150, 20), "Stack Start Rotation Y"); stackStartRotationY = GUI.HorizontalSlider(new Rect(180, 375, 180, 20), stackStartRotationY, 0, 360); GUI.Label(new Rect(20, 400, 150, 20), "Stack Start Rotation Z"); stackStartRotationZ = GUI.HorizontalSlider(new Rect(180, 405, 180, 20), stackStartRotationZ, 0, 360); stackStartRotation.x = stackStartRotationX; stackStartRotation.y = stackStartRotationY; stackStartRotation.z = stackStartRotationZ; formConfig.setStackStartTwist(stackStartRotation); //stack rotation delta Vector3 stackRotationDelta = formConfig.getStackTwistDelta(); stackRotationDeltaX = stackRotationDelta.x; stackRotationDeltaY = stackRotationDelta.y; stackRotationDeltaZ = stackRotationDelta.z; GUI.Label(new Rect(370, 340, 150, 20), "Stack Rotation Delta X"); stackRotationDeltaX = GUI.HorizontalSlider(new Rect(520, 345, 180, 20), stackRotationDeltaX, -30, 30); GUI.Label(new Rect(370, 370, 150, 20), "Stack Rotation Delta Y"); stackRotationDeltaY = GUI.HorizontalSlider(new Rect(520, 375, 180, 20), stackRotationDeltaY, -30, 30); GUI.Label(new Rect(370, 400, 150, 20), "Stack Rotation Delta Z"); stackRotationDeltaZ = GUI.HorizontalSlider(new Rect(520, 405, 180, 20), stackRotationDeltaZ, -30, 30); stackRotationDelta.x = stackRotationDeltaX; stackRotationDelta.y = stackRotationDeltaY; stackRotationDelta.z = stackRotationDeltaZ; formConfig.setStackTwistDelta(stackRotationDelta); /* MUTATION STRENGTH */ mutationStrength = formConfig.getMutationStrength(); GUI.Label(new Rect(20, 430, 150, 20), "Mutation Strength"); mutationStrength = GUI.HorizontalSlider(new Rect(180, 435, 180, 20), mutationStrength, 0.5f, 3.5f); formConfig.setMutationStrength(mutationStrength); /* SCALING */ scaling = formConfig.getScaleDelta(); GUI.Label(new Rect(370, 430, 150, 20), "Scaling *"); scaling = GUI.HorizontalSlider(new Rect(520, 435, 180, 20), scaling, 0.9f, 1.1f); formConfig.setScaleDelta(scaling); /* STACK SHAPE */ selectedShape = formConfig.getStackShapeIndex(); selectedShape = GUI.SelectionGrid(new Rect(20, 460, 200, 60), selectedShape, shapeGridStrings, 2); formConfig.setStackShape(selectedShape); /* Form Processor */ if (formConfig.getFormProcessor().GetType() == typeof(StarfishForm)) { selectedFormProcessor = 0; } else if (formConfig.getFormProcessor().GetType() == typeof(LoxodromeForm)) { selectedFormProcessor = 1; } else if (formConfig.getFormProcessor().GetType() == typeof(RingForm)) { selectedFormProcessor = 2; } selectedFormProcessor = GUI.SelectionGrid(new Rect(20, 525, 200, 60), selectedFormProcessor, formProcessorStrings, 2); if (selectedFormProcessor == 0) { formConfig.setFormProcessor(new StarfishForm()); } else if (selectedFormProcessor == 1) { formConfig.setFormProcessor(new LoxodromeForm()); } else if (selectedFormProcessor == 2) { formConfig.setFormProcessor(new RingForm()); } /* Configurations */ selectedConfiguration = formConfig.getIndex(); selectedConfiguration = GUI.SelectionGrid(new Rect(230, 460, 300, 90), selectedConfiguration, configurationGridStrings, 3); if (selectedConfiguration != formConfig.getIndex()) { //selected configuration changed callback.changeSelectedFormConfig(selectedConfiguration); } /* Control buttons */ if (GUI.Button(new Rect(540, 460, 160, 26), "Reset Config")) { formConfig.reset(); } if (GUI.Button(new Rect(540, 490, 160, 26), "Create Form")) { callback.createNewBrush(); } if (GUI.Button(new Rect(540, 520, 160, 26), "Clear Brush")) { callback.clearBrush(); } /* Load and Save buttons */ if (GUI.Button(new Rect(230, 560, 147, 26), "Load")) { ConfigXML.loadConfiguration(formConfig); } if (GUI.Button(new Rect(383, 560, 147, 26), "Save")) { ConfigXML.saveConfiguration(formConfig); } }
public void createTrunk(List<Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { int offset = (formConfig.getTrunkIterations() * formConfig.getStackIterations() / 2) * -1; Vector3 branchStartPosition = formConfig.getStartPosition(); branchStartPosition.y = branchStartPosition.y + 10; Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); for (int i = 0; i < formConfig.getTrunkIterations(); i++) { formBounds.calculateNewBounds(branchStartPosition); Branch branch = new Branch (offset, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); branches.Add(branch); offset += formConfig.getStackIterations(); } }
public void mutateBranch(List<IStack> stacks, int offset, IFormConfiguration formConfig, ColourConfiguration colourConfig, Vector3 branchStartPosition, Vector3 branchStartTwist, Vector3 origin, FormBounds formBounds) { Vector3 position = origin; Vector3 stackTwist = formConfig.getStackStartTwist(); float radius = formConfig.getBranchPositionDelta ().x * 20; float rhumbAngle = formConfig.getStartRotation().x * 0.032f; //colour stuff int iterations = formConfig.getStackIterations(); Color modelColour = new Color (colourConfig.getBaseRed(), colourConfig.getBaseGreen(), colourConfig.getBaseBlue(), 1); //if cycling override base colour if (colourConfig.getCycle ()) { modelColour = colourConfig.getCycleColour(); } int i = offset; foreach (IStack stack in stacks) { position.x = formConfig.getStartPosition().x + (radius * (float) Math.Cos(i) / (float) Math.Cosh (Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.y = formConfig.getStartPosition().y + (radius * (float) Math.Sin(i) / (float) Math.Cosh (Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.z = formConfig.getStartPosition().z + (radius * (float) Math.Tanh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); formBounds.calculateNewBounds(position); //colour stuff order is important Color stackColour = modelColour; if (colourConfig.getFadeColour()) { //fade colour in stackColour = ColourUtility.fadeModelColour(modelColour, iterations, i - offset); } if (colourConfig.getPulse()) { //do pulse stackColour = colourConfig.getPulseColourForStack(stackColour, i - offset); } stack.mutateTo(position, stackTwist, 0.5f, stackColour); stackTwist = GeometryUtility.addDeltaToRotation(stackTwist, formConfig.getStackTwistDelta()); i++; } }
public void createBranch(List<IStack> stacks, int offset, IFormConfiguration formConfig, ColourConfiguration colourConfig, Vector3 branchStartPosition, Vector3 branchStartTwist, Vector3 origin, FormBounds formBounds) { Vector3 position = origin; Vector3 stackTwist = formConfig.getStackStartTwist(); float radius = formConfig.getBranchPositionDelta ().x * 20; float rhumbAngle = formConfig.getStartRotation().x * 0.032f; //colour stuff int iterations = formConfig.getStackIterations(); Color modelColour = new Color (colourConfig.getBaseRed(), colourConfig.getBaseGreen(), colourConfig.getBaseBlue(), 1); //if cycling override base colour if (colourConfig.getCycle ()) { modelColour = colourConfig.getCycleColour(); } for (int i = offset; i < offset + iterations; i++) { position.x = formConfig.getStartPosition().x + (radius * (float) Math.Cos(i) / (float) Math.Cosh (Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.y = formConfig.getStartPosition().y + (radius * (float) Math.Sin(i) / (float) Math.Cosh (Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.z = formConfig.getStartPosition().z + (radius * (float) Math.Tanh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); formBounds.calculateNewBounds(position); //Stack Shape IStack stack = new SimpleStack(); //default if (formConfig.getStackShape() == IFormConfiguration.StackShape.Sphere) { //spehere stack = new SimpleStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Box) { //box stack = new SimpleBoxStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Complex1) { //complex 1 stack = new ComplexStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Complex2) { //complex 2 stack = new ComplexStack2(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.SimpleTorus) { //simple Torus stack = new SimpleTorusStack(); } //colour stuff order is important Color stackColour = modelColour; if (colourConfig.getFadeColour()) { //fade colour in stackColour = ColourUtility.fadeModelColour(modelColour, iterations, i); } if (colourConfig.getPulse()) { //do pulse stackColour = colourConfig.getPulseColourForStack(stackColour, i); } stack.initialise(position, stackTwist, 0.5f, stackColour); stacks.Add(stack); stackTwist = GeometryUtility.addDeltaToRotation(stackTwist, formConfig.getStackTwistDelta()); } }
public static void saveConfiguration(IFormConfiguration formConfiguration) { string fileSavePath = Application.persistentDataPath + "/FormConfigSlot" + (formConfiguration.getIndex() + 1) + ".xml"; Debug.Log ("Save:" + fileSavePath); XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("", "form", ""); //save data root.SetAttribute("branchPositionDeltaX", formConfiguration.getBranchPositionDelta().x.ToString()); root.SetAttribute("branchPositionDeltaY", formConfiguration.getBranchPositionDelta().y.ToString()); root.SetAttribute("branchPositionDeltaZ", formConfiguration.getBranchPositionDelta().z.ToString()); root.SetAttribute("branchTwistDeltaX", formConfiguration.getBranchTwistDelta().x.ToString()); root.SetAttribute("branchTwistDeltaY", formConfiguration.getBranchTwistDelta().y.ToString()); root.SetAttribute("branchTwistDeltaZ", formConfiguration.getBranchTwistDelta().z.ToString()); root.SetAttribute("index", formConfiguration.getIndex().ToString()); root.SetAttribute("mutationStrength", formConfiguration.getMutationStrength().ToString()); root.SetAttribute("scaleBranch", formConfiguration.getScaleBranch().ToString()); root.SetAttribute("scaleDelta", formConfiguration.getScaleDelta().ToString()); root.SetAttribute("scaleTrunk", formConfiguration.getScaleTrunk().ToString()); root.SetAttribute("stackIterations", formConfiguration.getStackIterations().ToString()); root.SetAttribute("stackShapeIndex", formConfiguration.getStackShapeIndex().ToString()); root.SetAttribute("stackStartTwistX", formConfiguration.getStackStartTwist().x.ToString()); root.SetAttribute("stackStartTwistY", formConfiguration.getStackStartTwist().y.ToString()); root.SetAttribute("stackStartTwistZ", formConfiguration.getStackStartTwist().z.ToString()); root.SetAttribute("stackTwistDeltaX", formConfiguration.getStackTwistDelta().x.ToString()); root.SetAttribute("stackTwistDeltaY", formConfiguration.getStackTwistDelta().y.ToString()); root.SetAttribute("stackTwistDeltaZ", formConfiguration.getStackTwistDelta().z.ToString()); root.SetAttribute("startPositionX", formConfiguration.getStartPosition().x.ToString()); root.SetAttribute("startPositionY", formConfiguration.getStartPosition().y.ToString()); root.SetAttribute("startPositionZ", formConfiguration.getStartPosition().z.ToString()); root.SetAttribute("startRotationX", formConfiguration.getStartRotation().x.ToString()); root.SetAttribute("startRotationY", formConfiguration.getStartRotation().y.ToString()); root.SetAttribute("startRotationZ", formConfiguration.getStartRotation().z.ToString()); root.SetAttribute("startScale", formConfiguration.getStartScale().ToString()); root.SetAttribute("trunkIterations", formConfiguration.getTrunkIterations().ToString()); root.SetAttribute("trunkPositionDeltaX", formConfiguration.getTrunkPositionDelta().x.ToString()); root.SetAttribute("trunkPositionDeltaY", formConfiguration.getTrunkPositionDelta().y.ToString()); root.SetAttribute("trunkPositionDeltaZ", formConfiguration.getTrunkPositionDelta().z.ToString()); root.SetAttribute("trunklRotationDeltaX", formConfiguration.getTrunkRotationDelta().x.ToString()); root.SetAttribute("trunklRotationDeltaY", formConfiguration.getTrunkRotationDelta().y.ToString()); root.SetAttribute("trunklRotationDeltaZ", formConfiguration.getTrunkRotationDelta().z.ToString()); xmlDoc.AppendChild(root); //save xmlDoc.Save(fileSavePath); }
public void mutateTrunk(List<Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); int i = 0; foreach (Branch branch in branches) { formBounds.calculateNewBounds(branchStartPosition); branch.mutate(i, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); branchStartPosition.x += formConfig.getTrunkPositionDelta().x; branchStartPosition.y += formConfig.getTrunkPositionDelta().y; branchStartPosition.z += formConfig.getTrunkPositionDelta().z; branchStartTwist.x += formConfig.getTrunkRotationDelta().x; branchStartTwist.y += formConfig.getTrunkRotationDelta().y; branchStartTwist.z += formConfig.getTrunkRotationDelta().z; i++; } }
public void createBranch(List <IStack> stacks, int offset, IFormConfiguration formConfig, ColourConfiguration colourConfig, Vector3 branchStartPosition, Vector3 branchStartTwist, Vector3 origin, FormBounds formBounds) { Vector3 position = origin; Vector3 stackTwist = formConfig.getStackStartTwist(); float radius = formConfig.getBranchPositionDelta().x * 20; float rhumbAngle = formConfig.getStartRotation().x * 0.032f; //colour stuff int iterations = formConfig.getStackIterations(); Color modelColour = new Color(colourConfig.getBaseRed(), colourConfig.getBaseGreen(), colourConfig.getBaseBlue(), 1); //if cycling override base colour if (colourConfig.getCycle()) { modelColour = colourConfig.getCycleColour(); } for (int i = offset; i < offset + iterations; i++) { position.x = formConfig.getStartPosition().x + (radius * (float)Math.Cos(i) / (float)Math.Cosh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.y = formConfig.getStartPosition().y + (radius * (float)Math.Sin(i) / (float)Math.Cosh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); position.z = formConfig.getStartPosition().z + (radius * (float)Math.Tanh(Mathf.Rad2Deg * (Mathf.Deg2Rad * i * rhumbAngle))); formBounds.calculateNewBounds(position); //Stack Shape IStack stack = new SimpleStack(); //default if (formConfig.getStackShape() == IFormConfiguration.StackShape.Sphere) { //spehere stack = new SimpleStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Box) { //box stack = new SimpleBoxStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Complex1) { //complex 1 stack = new ComplexStack(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.Complex2) { //complex 2 stack = new ComplexStack2(); } else if (formConfig.getStackShape() == IFormConfiguration.StackShape.SimpleTorus) { //simple Torus stack = new SimpleTorusStack(); } //colour stuff order is important Color stackColour = modelColour; if (colourConfig.getFadeColour()) { //fade colour in stackColour = ColourUtility.fadeModelColour(modelColour, iterations, i); } if (colourConfig.getPulse()) { //do pulse stackColour = colourConfig.getPulseColourForStack(stackColour, i); } stack.initialise(position, stackTwist, 0.5f, stackColour); stacks.Add(stack); stackTwist = GeometryUtility.addDeltaToRotation(stackTwist, formConfig.getStackTwistDelta()); } }
public void mutateTrunk(List<Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 origin = formConfig.getStartPosition(); foreach (Branch branch in branches) { formBounds.calculateNewBounds(branchStartPosition); branch.mutate(0, formConfig, colourConfig, branchStartPosition, branchStartTwist, origin, formBounds); //set origin to previous start position origin = branchStartPosition; branchStartTwist = GeometryUtility.addDeltaToRotation(branchStartTwist, formConfig.getTrunkRotationDelta()); branchStartPosition = GeometryUtility.addDeltaToPosition(branchStartPosition, formConfig.getTrunkPositionDelta(), 1); } }
public void displayFormBuilderPalette(IFormConfiguration formConfig) { // Make a background box GUI.Box(new Rect(10, 10, 700, 590), "Builder Palette"); bool displayStarfishControls = false; bool displayLoxodromeControls = false; bool displayRingControls = false; if (formConfig.getFormProcessor ().GetType () == typeof(StarfishForm)) { displayStarfishControls = true; } else if (formConfig.getFormProcessor ().GetType () == typeof(LoxodromeForm)) { displayLoxodromeControls = true; } else if (formConfig.getFormProcessor().GetType() == typeof(RingForm)) { displayRingControls = true; } /* TRUNK */ //start position Vector3 startPosition = formConfig.getStartPosition (); startPositionX = startPosition.x; startPositionY = startPosition.y; startPositionZ = startPosition.z; GUI.Label (new Rect (20, 40, 150, 20), "Trunk Start Position X"); startPositionX = GUI.HorizontalSlider (new Rect (180, 45, 180, 20), startPositionX, -5, 5); GUI.Label (new Rect (20, 70, 150, 20), "Trunk Start Position Y"); startPositionY = GUI.HorizontalSlider (new Rect (180, 75, 180, 20), startPositionY, -5, 5); GUI.Label (new Rect (20, 100, 150, 20), "Trunk Start Position Z"); startPositionZ = GUI.HorizontalSlider (new Rect (180, 105, 180, 20), startPositionZ, -5, 5); startPosition.x = startPositionX; startPosition.y = startPositionY; startPosition.z = startPositionZ; formConfig.setStartPosition (startPosition); // start rotation Vector3 startRotation = formConfig.getStartRotation (); startRotationX = startRotation.x; startRotationY = startRotation.y; startRotationZ = startRotation.z; if (displayLoxodromeControls) { GUI.Label (new Rect (370, 40, 150, 20), "Rhumb Angle"); //startRotationX = GUI.HorizontalSlider (new Rect (520, 45, 180, 20), startRotationX, 0.1f, 2f); startRotationX = GUI.HorizontalSlider (new Rect (520, 45, 180, 20), startRotationX, 0, 2f); } if (displayStarfishControls) { GUI.Label (new Rect (370, 40, 150, 20), "Trunk Start Rotation X"); startRotationX = GUI.HorizontalSlider (new Rect (520, 45, 180, 20), startRotationX, 0, 360); } if (displayStarfishControls || displayRingControls) { GUI.Label (new Rect (370, 70, 150, 20), "Trunk Start Rotation Y"); startRotationY = GUI.HorizontalSlider (new Rect (520, 75, 180, 20), startRotationY, 0, 360); GUI.Label (new Rect (370, 100, 150, 20), "Trunk Start Rotation Z"); startRotationZ = GUI.HorizontalSlider (new Rect (520, 105, 180, 20), startRotationZ, 0, 360); } startRotation.x = startRotationX; startRotation.y = startRotationY; startRotation.z = startRotationZ; formConfig.setStartRotation (startRotation); //trunk position delta Vector3 trunkPositionDelta = formConfig.getTrunkPositionDelta (); trunkPositionDeltaX = trunkPositionDelta.x; trunkPositionDeltaY = trunkPositionDelta.y; trunkPositionDeltaZ = trunkPositionDelta.z; if (displayStarfishControls || displayRingControls) { GUI.Label (new Rect (20, 130, 150, 20), "Trunk Position Delta X"); trunkPositionDeltaX = GUI.HorizontalSlider (new Rect (180, 135, 180, 20), trunkPositionDeltaX, -1, 1); GUI.Label (new Rect (20, 160, 150, 20), "Trunk Position Delta Y"); trunkPositionDeltaY = GUI.HorizontalSlider (new Rect (180, 165, 180, 20), trunkPositionDeltaY, -1, 1); GUI.Label (new Rect (20, 190, 150, 20), "Trunk Position Delta Z"); trunkPositionDeltaZ = GUI.HorizontalSlider (new Rect (180, 195, 180, 20), trunkPositionDeltaZ, -1, 1); } trunkPositionDelta.x = trunkPositionDeltaX; trunkPositionDelta.y = trunkPositionDeltaY; trunkPositionDelta.z = trunkPositionDeltaZ; formConfig.setTrunkPositionDelta (trunkPositionDelta); //trunk rotation delta Vector3 trunkRotatiomnDelta = formConfig.getTrunkRotationDelta (); trunkRotationDeltaX = trunkRotatiomnDelta.x; trunkRotationDeltaY = trunkRotatiomnDelta.y; trunkRotationDeltaZ = trunkRotatiomnDelta.z; if (displayStarfishControls) { GUI.Label (new Rect (20, 220, 150, 20), "Trunk Rotation Delta X"); trunkRotationDeltaX = GUI.HorizontalSlider (new Rect (180, 225, 180, 20), trunkRotationDeltaX, -60, 60); } if (displayStarfishControls || displayRingControls) { GUI.Label (new Rect (20, 250, 150, 20), "Trunk Rotation Delta Y"); trunkRotationDeltaY = GUI.HorizontalSlider (new Rect (180, 255, 180, 20), trunkRotationDeltaY, -60, 60); GUI.Label (new Rect (20, 280, 150, 20), "Trunk Rotation Delta Z"); trunkRotationDeltaZ = GUI.HorizontalSlider (new Rect (180, 285, 180, 20), trunkRotationDeltaZ, -60, 60); } trunkRotatiomnDelta.x = trunkRotationDeltaX; trunkRotatiomnDelta.y = trunkRotationDeltaY; trunkRotatiomnDelta.z = trunkRotationDeltaZ; formConfig.setTrunkRotationDelta (trunkRotatiomnDelta); //trunk iterations trunkIterations = formConfig.getTrunkIterations (); GUI.Label (new Rect (20, 310, 150, 20), "Trunk Iterations *"); trunkIterations = GUI.HorizontalSlider (new Rect (180, 315, 180, 20), trunkIterations, 1, 24); formConfig.setTrunkIterations ((int)trunkIterations); /* BRANCH */ //branch position delta Vector3 branchPositionDelta = formConfig.getBranchPositionDelta (); branchPositionDeltaX = branchPositionDelta.x; branchPositionDeltaY = branchPositionDelta.y; branchPositionDeltaZ = branchPositionDelta.z; if (displayRingControls || displayLoxodromeControls) { GUI.Label (new Rect (370, 130, 150, 20), "Radius"); branchPositionDeltaX = GUI.HorizontalSlider (new Rect (520, 135, 180, 20), branchPositionDeltaX, 0.2f, 1); } if (displayStarfishControls) { GUI.Label (new Rect (370, 130, 150, 20), "Branch Position Delta X"); branchPositionDeltaX = GUI.HorizontalSlider (new Rect (520, 135, 180, 20), branchPositionDeltaX, -1, 1); GUI.Label (new Rect (370, 160, 150, 20), "Branch Position Delta Y"); branchPositionDeltaY = GUI.HorizontalSlider (new Rect (520, 165, 180, 20), branchPositionDeltaY, -1, 1); GUI.Label (new Rect (370, 190, 150, 20), "Branch Position Delta Z"); branchPositionDeltaZ = GUI.HorizontalSlider (new Rect (520, 195, 180, 20), branchPositionDeltaZ, -1, 1); } branchPositionDelta.x = branchPositionDeltaX; branchPositionDelta.y = branchPositionDeltaY; branchPositionDelta.z = branchPositionDeltaZ; formConfig.setBranchPositionDelta (branchPositionDelta); //branch rotation delta Vector3 branchRotationDelta = formConfig.getBranchTwistDelta (); branchRotationDeltaX = branchRotationDelta.x; branchRotationDeltaY = branchRotationDelta.y; branchRotationDeltaZ = branchRotationDelta.z; if (displayStarfishControls) { GUI.Label (new Rect (370, 220, 150, 20), "Branch Rotation Delta X"); branchRotationDeltaX = GUI.HorizontalSlider (new Rect (520, 225, 180, 20), branchRotationDeltaX, -30, 30); GUI.Label (new Rect (370, 250, 150, 20), "Branch Rotation Delta Y"); branchRotationDeltaY = GUI.HorizontalSlider (new Rect (520, 255, 180, 20), branchRotationDeltaY, -30, 30); GUI.Label (new Rect (370, 280, 150, 20), "Branch Rotation Delta Z"); branchRotationDeltaZ = GUI.HorizontalSlider (new Rect (520, 285, 180, 20), branchRotationDeltaZ, -30, 30); } branchRotationDelta.x = branchRotationDeltaX; branchRotationDelta.y = branchRotationDeltaY; branchRotationDelta.z = branchRotationDeltaZ; formConfig.setBranchTwistDelta (branchRotationDelta); //branch iterations branchIterations = formConfig.getStackIterations (); GUI.Label (new Rect (370, 310, 150, 20), "Branch Iterations *"); branchIterations = GUI.HorizontalSlider (new Rect (520, 315, 180, 20), branchIterations, 1, 60); formConfig.setStackIterations ((int)branchIterations); /* STACK */ //stack start rotation Vector3 stackStartRotation = formConfig.getStackStartTwist (); stackStartRotationX = stackStartRotation.x; stackStartRotationY = stackStartRotation.y; stackStartRotationZ = stackStartRotation.z; GUI.Label (new Rect (20, 340, 150, 20), "Stack Start Rotation X"); stackStartRotationX = GUI.HorizontalSlider (new Rect (180, 345, 180, 20), stackStartRotationX, 0, 360); GUI.Label (new Rect (20, 370, 150, 20), "Stack Start Rotation Y"); stackStartRotationY = GUI.HorizontalSlider (new Rect (180, 375, 180, 20), stackStartRotationY, 0, 360); GUI.Label (new Rect (20, 400, 150, 20), "Stack Start Rotation Z"); stackStartRotationZ = GUI.HorizontalSlider (new Rect (180, 405, 180, 20), stackStartRotationZ, 0, 360); stackStartRotation.x = stackStartRotationX; stackStartRotation.y = stackStartRotationY; stackStartRotation.z = stackStartRotationZ; formConfig.setStackStartTwist (stackStartRotation); //stack rotation delta Vector3 stackRotationDelta = formConfig.getStackTwistDelta (); stackRotationDeltaX = stackRotationDelta.x; stackRotationDeltaY = stackRotationDelta.y; stackRotationDeltaZ = stackRotationDelta.z; GUI.Label (new Rect (370, 340, 150, 20), "Stack Rotation Delta X"); stackRotationDeltaX = GUI.HorizontalSlider (new Rect (520, 345, 180, 20), stackRotationDeltaX, -30, 30); GUI.Label (new Rect (370, 370, 150, 20), "Stack Rotation Delta Y"); stackRotationDeltaY = GUI.HorizontalSlider (new Rect (520, 375, 180, 20), stackRotationDeltaY, -30, 30); GUI.Label (new Rect (370, 400, 150, 20), "Stack Rotation Delta Z"); stackRotationDeltaZ = GUI.HorizontalSlider (new Rect (520, 405, 180, 20), stackRotationDeltaZ, -30, 30); stackRotationDelta.x = stackRotationDeltaX; stackRotationDelta.y = stackRotationDeltaY; stackRotationDelta.z = stackRotationDeltaZ; formConfig.setStackTwistDelta (stackRotationDelta); /* MUTATION STRENGTH */ mutationStrength = formConfig.getMutationStrength (); GUI.Label (new Rect (20, 430, 150, 20), "Mutation Strength"); mutationStrength = GUI.HorizontalSlider (new Rect (180, 435, 180, 20), mutationStrength, 0.5f, 3.5f); formConfig.setMutationStrength (mutationStrength); /* SCALING */ scaling = formConfig.getScaleDelta (); GUI.Label (new Rect (370, 430, 150, 20), "Scaling *"); scaling = GUI.HorizontalSlider (new Rect (520, 435, 180, 20), scaling, 0.9f, 1.1f); formConfig.setScaleDelta (scaling); /* STACK SHAPE */ selectedShape = formConfig.getStackShapeIndex (); selectedShape = GUI.SelectionGrid (new Rect (20, 460, 200, 60), selectedShape, shapeGridStrings, 2); formConfig.setStackShape (selectedShape); /* Form Processor */ if (formConfig.getFormProcessor().GetType() == typeof(StarfishForm)) { selectedFormProcessor = 0; } else if (formConfig.getFormProcessor().GetType() == typeof(LoxodromeForm)) { selectedFormProcessor = 1; } else if (formConfig.getFormProcessor().GetType() == typeof(RingForm)) { selectedFormProcessor = 2; } selectedFormProcessor = GUI.SelectionGrid (new Rect (20, 525, 200, 60), selectedFormProcessor, formProcessorStrings, 2); if (selectedFormProcessor == 0) { formConfig.setFormProcessor(new StarfishForm()); } else if (selectedFormProcessor == 1) { formConfig.setFormProcessor(new LoxodromeForm()); } else if (selectedFormProcessor == 2) { formConfig.setFormProcessor(new RingForm()); } /* Configurations */ selectedConfiguration = formConfig.getIndex (); selectedConfiguration = GUI.SelectionGrid (new Rect (230, 460, 300, 90), selectedConfiguration, configurationGridStrings, 3); if (selectedConfiguration != formConfig.getIndex ()) { //selected configuration changed callback.changeSelectedFormConfig(selectedConfiguration); } /* Control buttons */ if (GUI.Button(new Rect(540, 460, 160, 26), "Reset Config")) { formConfig.reset(); } if (GUI.Button(new Rect(540, 490, 160, 26), "Create Form")) { callback.createNewBrush(); } if (GUI.Button(new Rect(540, 520, 160, 26), "Clear Brush")) { callback.clearBrush(); } /* Load and Save buttons */ if (GUI.Button(new Rect(230, 560, 147, 26), "Load")) { ConfigXML.loadConfiguration(formConfig); } if (GUI.Button(new Rect(383, 560, 147, 26), "Save")) { ConfigXML.saveConfiguration(formConfig); } }
public void createTrunk(List<Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); for (int i = 0; i < formConfig.getTrunkIterations(); i++) { formBounds.calculateNewBounds(branchStartPosition); Branch branch = new Branch (i, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); branches.Add(branch); branchStartPosition.x += formConfig.getTrunkPositionDelta().x; branchStartPosition.y += formConfig.getTrunkPositionDelta().y; branchStartPosition.z += formConfig.getTrunkPositionDelta().z; branchStartTwist.x += formConfig.getTrunkRotationDelta().x; branchStartTwist.y += formConfig.getTrunkRotationDelta().y; branchStartTwist.z += formConfig.getTrunkRotationDelta().z; } }
public void createTrunk(List<Branch> branches, FormBounds formBounds, IFormConfiguration formConfig, ColourConfiguration colourConfig) { Vector3 branchStartPosition = formConfig.getStartPosition(); Vector3 branchStartTwist = formConfig.getStartRotation(); Vector3 branchStartOrigin = formConfig.getStartPosition(); for (int i = 0; i < formConfig.getTrunkIterations(); i++) { formBounds.calculateNewBounds(branchStartPosition); Branch branch = new Branch (0, formConfig, colourConfig, branchStartPosition, branchStartTwist, branchStartOrigin, formBounds); //magic 0 no offset branches.Add(branch); //set origin to previous start position branchStartOrigin = branchStartPosition; branchStartTwist = GeometryUtility.addDeltaToRotation(branchStartTwist, formConfig.getTrunkRotationDelta()); branchStartPosition = GeometryUtility.addDeltaToPosition(branchStartPosition, formConfig.getTrunkPositionDelta(), 1); } }