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); }