int MakeBranch(VStructure s, int depth, int originID, int parentID, Vector2 parentPosition, float angle, float length) { var position = parentPosition + Utilities.Angle2Vector(angle) * length; var currentID = s.AddParticle(position, 0.1f); s.AddEdge(parentID, currentID, 0.1f, _branchGradient.Evaluate(Random.Range(0f, 1f))); depth--; if (depth > 0) { var branchAngle = (Random.Range(0f, 1f) < 0.5f ? _subBranchAngle : -_subBranchAngle) * Mathf.Rad2Deg; var branchDir = Utilities.Angle2Vector(angle + branchAngle) * length * _subBranchLengthMutiplier; var branchID = s.AddParticle(branchDir + position, 0.2f, _leafGradient.Evaluate(Random.Range(0f, 1f))); s.AddEdge(currentID, branchID, 0.1f, _branchGradient.Evaluate(Random.Range(0f, 1f))); s.AddEdge(parentID, branchID, 0.025f, _branchGradient.Evaluate(Random.Range(0f, 1f))); var nextID = MakeBranch(s, depth, originID, currentID, position, angle, length * _lengthDamping); s.AddEdge(parentID, nextID, 0.025f, _branchGradient.Evaluate(Random.Range(0f, 1f))); } return(currentID); }
VStructure Build() { var s = new VStructure(); var stepSize = Mathf.PI * 2f / resolution; // パーティクル for (var i = 0; i < resolution; ++i) { var step = stepSize * i; var x = Mathf.Cos(step) * radius; var y = Mathf.Sin(step) * radius; s.AddParticle(new Vector2(x, y), 0.2f); } // エッジ for (var i = 0; i < resolution; ++i) { // 前後のつなぎ s.AddEdge(i, (i + 1) % resolution); // 支持棒 for (var j = 0; j < supports.Length; ++j) { var i2 = (i + supports[j]) % resolution; s.AddEdge(i, i2); } } return(s); }
public override VStructure CreateStructure(Matrix4x4 toWorld) { var s = new VStructure(); var stepSize = Mathf.PI * 2f / resolution; // パーティクル for (var i = 0; i < resolution; ++i) { var step = stepSize * i; var x = Mathf.Cos(step) * radius; var y = Mathf.Sin(step) * radius; s.AddParticle(toWorld.MultiplyPoint3x4(new Vector2(x, y)), 0.2f); } // エッジ for (var i = 0; i < resolution; ++i) { // 前後のつなぎ s.AddEdge(i, (i + 1) % resolution); // 支持棒 for (var j = 0; j < supports.Length; ++j) { var i2 = (i + supports[j]) % resolution; s.AddEdge(i, i2); } } return(s); }
public override VStructure CreateStructure(Matrix4x4 toWorld) { var s = new VStructure(); var position = toWorld.MultiplyPoint3x4(Vector2.zero); var angle = 90f * Mathf.Deg2Rad; var origin = s.AddParticle(position, 0.5f); var next = MakeBranch(s, _maxDepth, origin, origin, position, angle, _baseLength); s.AddAfterStep(new VPin(origin, s.GetParticlePosition(origin))); s.AddAfterStep(new VPin(next, s.GetParticlePosition(next))); return(s); }
public override VStructure CreateStructure(Matrix4x4 toWorld) { var s = new VStructure(); // まずは使用する座標のリストを作成 var positions = new Vector2[_mainBranchResolution]; Vector2 position = new Vector2(0f, 0f); positions[0] = toWorld.MultiplyPoint3x4(position); float length = baseLength; float angle = baseAngle; for (var i = 1; i < _mainBranchResolution; ++i) { var t = (float)i / _mainBranchResolution; var lengthMultiplier = _mainBranchLengthMultiplierhCurve.Evaluate(t); var deltaAngle = (_inverseMainBranchDeltaAngle ? -1 : 1) * _mainBranchDeltaAngleCurve.Evaluate(t); length = baseLength * lengthMultiplier; angle += deltaAngle; position += Utilities.Angle2Vector(angle * Mathf.Deg2Rad) * length; positions[i] = toWorld.MultiplyPoint3x4(position); } // 座標を元にパーティクルとエッジを追加 for (var i = 0; i < positions.Length; ++i) { var t = (float)i / positions.Length; s.AddParticle( positions[i], _baseLeafSize * _leafSizeMultiplierCurve.Evaluate(t), _leafGradient.Evaluate(Random.Range(0f, 1f)) ); } // エッジの作成 for (var i = 1; i < positions.Length; ++i) { s.AddEdge(i - 1, i, _mainBranchWidth, _mainBranchGradient.Evaluate(Random.Range(0f, 1f))); // サポートの作成 for (var j = 0; j < _supportEdges.Length; ++j) { var t = _supportEdges[j]; if (i >= t.supportInterval) { s.AddEdge(i - t.supportInterval, i, t.supportWidth, _mainBranchGradient.Evaluate(Random.Range(0f, 1f))); } } } // 根本をピンどめ s.AddAfterStep(new VPin(0, positions[0])); s.AddAfterStep(new VPin(1, positions[1])); return(s); }
/// <summary> /// 枝を一つ作成する /// </summary> /// <returns></returns> int MakeBranch( VStructure structure, int depth, int parentID, Vector2 parentPosition, float angle, float length) { // パーティクルの大きさは幹と葉で分ける var size = 0f; Color32 color; if (depth == 1) { // 葉 size = Random.Range(_minSize, _maxSize); color = _leafColor.Evaluate(Random.Range(0f, 1f)); } else { // 幹 size = 0f; color = _branchColor; } var position = parentPosition + Utilities.Angle2Vector(angle) * length; var currentID = structure.AddParticle(position, size, color); structure.AddEdge(parentID, currentID, _branchWidth, _branchColor); depth--; // 最大深度未満の場合は次の枝へ if (depth > 0) { // child.hide = true; // branch A int aID; if ((length * Random.Range(1f, 2f)) / _initialLength > lengthBranchAThreshold) { aID = MakeBranch(structure, depth, currentID, position, angle + Random.Range(angleOffsetMin, angleOffsetMax), length * Random.Range(lengthMin1, lengthMax1)); } else { aID = MakeBranch(structure, depth, currentID, position, angle + Random.Range(angleOffsetMin, angleOffsetMax), length * Random.Range(lengthMin2, lengthMax2)); } // branch B int bID; if ((length * Random.Range(1f, 2f)) / _initialLength > lengthBranchBThreshold) { bID = MakeBranch(structure, depth, currentID, position, angle - Random.Range(angleOffsetMin, angleOffsetMax), length * Random.Range(lengthMin1, lengthMax1)); } else { bID = MakeBranch(structure, depth, currentID, position, angle - Random.Range(angleOffsetMin, angleOffsetMax), length * Random.Range(lengthMin2, lengthMax2)); } structure.AddEdge(currentID, aID, _branchWidth); structure.AddEdge(currentID, bID, _branchWidth); structure.AddEdge(parentID, aID, 0.025f, _branchColor); structure.AddEdge(parentID, bID, 0.025f, _branchColor); structure.AddEdge(aID, bID, 0.025f, _branchColor); } return(currentID); }