ProceduralTree RandomTree(Vector3 pos, int iterations) { //binary tree //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { {"0", "1B[[0R-]0R+]" } }); //Lopsided binary tree //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { { "0", "1B[[10R-]0R+]" } }); //simple vine LSystem lSystem = new LSystem("1R10", new Dictionary <string, string> { { "1", "1BR[0-]1" } }); //triple vine //LSystem lSystem = new LSystem("10", new Dictionary<string, string> { { "1", "1BR[0R-][0+][0L-]1" } }); //Trinary tree //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { {"0", "1[[0R-][1B0+][0R+]]" } }); //Trinary tree lopsided //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { {"0", "1B[110R-][10R][0R+]" } }); //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { {"0", "1RB[110-][10][0+]" } }); //alternating binary tree //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { { "+", "-" }, { "-", "+" }, { "0", "1B[[0R+]0L+]" } }); //alternating trinary tree <3 //LSystem lSystem = new LSystem("0", new Dictionary<string, string> { { "R", "L" }, { "L", "R" }, { "0", "1[[0L+][10-][0R+]]" } }); float startRotation = prng.Next(0, 360); float branchRotateAngle = SampleBellCurveInRange(0f, 180f); float branchBendAngle = SampleBellCurveInRange(0f, 90f); float branchLengthDefault = SampleBellCurveInRange(1f, 4f); float branchDefaultWidth = SampleBellCurveInRange(0.5f, 2f); float taperWidth = SampleBellCurveInRange(0.1f, 0.5f); float taperHeight = SampleBellCurveInRange(0f, 0.5f); Vector3 bias = RandomNormalizedVector(); float biasStrength = SampleBellCurveInRange(0f, 0.2f); GameObject treeBase = new GameObject("TreeBase"); treeBase.transform.Rotate(treeBase.transform.up, startRotation); treeBase.transform.position = pos; treeBase.transform.parent = transform; ProceduralTree tree = treeBase.AddComponent <ProceduralTree>(); tree.ConstructProceduralTree(lSystem, iterations, branchRotateAngle, branchBendAngle, branchLengthDefault, branchDefaultWidth, taperWidth, taperHeight, bias, biasStrength, branchBody, leafBody); return(tree); }
public FoliageGenerator(ProceduralTree tree, Mesh mesh, float scale) : base(mesh) { if (tree.FoliageStyle == FoliageStyle.None) { return; } var colors = tree.FoliageColors; int numColors = colors.Length; if (numColors > 0) { int colorIndex = URandom.Range(0, numColors); color = colors[colorIndex]; } else { color = Palette.GREEN; } width = tree.FoliageWidth + Random.Range(-1, 1) * tree.FoliageWidthVariance; width = Mathf.Max(MIN_SIZE, width * scale); height = tree.FoliageHeight + Random.Range(-1, 1) * tree.FoliageHeightVariance; height = Mathf.Max(MIN_SIZE, height * scale); }
/// <summary> /// Creates a GameObject from an ARTree /// </summary> /// <param name="tree"></param> /// <returns></returns> private GameObject CreateTreeGameobject(ARTree tree) { GameObject g = Instantiate(rootTree) as GameObject; ProceduralTree script = g.GetComponent <ProceduralTree>(); script.Seed = tree.seed; script.MaxNumVertices = tree.maxNumVertices; script.NumberOfSides = tree.numberOfSides; script.BaseRadius = tree.baseRadius; script.RadiusStep = tree.radiusStep; script.MinimumRadius = tree.minimumRadius; script.BranchRoundness = tree.branchRoundness; script.SegmentLength = tree.segmentLength; script.Twisting = tree.twisting; script.BranchProbability = tree.branchProbability; script.growthPercent = 1.0f;// tree.growthPercent; // Set correct leaf-material tree.ConvertToTexture(); Material m = new Material(Shader.Find("Custom/LeafShader")); m.mainTexture = tree.leafTexture; script.leafMaterial = m; // Change texture on leafs GameObject leaf = g.transform.GetChild(0).gameObject; leaf.GetComponent <ChangeLeafTexture>().ChangeTexture(); g.AddComponent <TimeStampHolder>().TimeStamp = tree.timeStamp; // Set the propper tree texture Renderer treeR = g.GetComponent <Renderer>(); string textureName = tree.materialName; // tree.materialName is textureName; if (textureName == "bark3") // Oak { Debug.Log("BARK3"); treeR.material.mainTexture = barkTextures[0]; } else if (textureName == "bark1") // Rainbow { Debug.Log("BARK1"); treeR.material.mainTexture = barkTextures[1]; } else // Birch { Debug.Log("BIRCH!!!"); g.AddComponent <ProceduralBark>(); ProceduralBark b = g.GetComponent <ProceduralBark>(); b.freq = 0.08f; b.lacunarity = 3.38f; b.gain = -0.78f; b.GenerateTexture(); } return(g); }
public TreeGenerator(ProceduralTree tree, Mesh mesh, TreeGenerator parent = null) : base(mesh, parent) { this.tree = tree; twisting = tree.Twisting; barkColor = tree.BarkColor; foliageType = tree.FoliageStyle; }
public TrunkGenerator(ProceduralTree tree, Mesh mesh) : base(tree, mesh) { numSides = tree.NumSides; height = tree.Height; expectedNumSegments = tree.NumSegments; baseRadius = tree.Thickness; stumpChance = tree.StumpChance; woodColor = tree.WoodColor; }
// Use this for initialization void Start() { foreach (Transform child in transform) { if (child.tag == "Tree") { tree = child.GetComponent <ProceduralTree>(); treeMaterial = child.GetComponent <Renderer>(); } } treesToAdd = new List <ARTree>(); treesToRemove = new List <ARTree>(); DatabaseHandler.NewTreeAdded += AddTreeToAdd; DatabaseHandler.NewTreeToRemove += AddTreeToRemove; }
// спавним дерево по x и y void RollNSpawn(int x, int y) { float h = terrain.SampleHeight(new Vector3(x, 0, y)); // вытаскивая высоту из карты высот ландшафта // копируя префаб ProceduralTree placement = (Instantiate(tree, terrain.transform) as GameObject).GetComponent <ProceduralTree>(); placement.transform.position = new Vector3(x, h, y); // и рандомля пачку параметров placement.transform.localScale = new Vector3(Roll(scale), Roll(scale), Roll(scale)); placement.SegmentLength = Roll(segmentLength); placement.Twisting = Roll(twisting); placement.BaseRadius = Roll(baseRadius); placement.MinimumRadius = Roll(minimumRadius); placement.BranchRoundness = Roll(roudness); placement.Renderer.material = materials[Random.Range(0, 4)]; // после чего обновляя меш у дерева placement.ForceUpdate(); }
public BranchGenerator(ProceduralTree tree, Mesh mesh, TrunkGenerator parent, Vector3 position, Vector3 direction, float radius, float segmentLength, int numSegments) : base(tree, mesh, parent) { this.position = position; initialRadius = radius; initialRotation = Quaternion.FromToRotation(Vector3.up, direction); float t = Mathf.InverseLerp( ProceduralTree.MIN_THICKNESS, ProceduralTree.MAX_THICKNESS, initialRadius ); numSides = (int)Mathf.Floor( Mathf.Lerp(ProceduralTree.MIN_ROUNDNESS, ProceduralTree.MAX_ROUNDNESS, t) ); this.segmentLength = segmentLength; this.numSegments = numSegments; this.foliageScale = initialRadius / tree.Thickness; }
public RoundLeavesGenerator(ProceduralTree tree, Mesh mesh, float scale) : base(tree, mesh, scale) { }
public ConiferousLeavesGenerator(ProceduralTree tree, Mesh mesh, float scale, Vector3[] positions, Quaternion[] rotations, float[] radiuses) : base(tree, mesh, scale) { this.positions = positions; this.rotations = rotations; this.radiuses = radiuses; }
private void OnEnable() { tree = target as ProceduralTree; }