Esempio n. 1
0
        /// <summary>
        /// ビルドしてミックスする
        /// </summary>
        /// <returns></returns>
        RefStructure BuildAndMix()
        {
            var mat = transform.localToWorldMatrix;
            var a   = _a.Build(mat);
            var b   = _b.Build(mat);

            var dst = DistanceMixer.Mix(a, b, 10f, _edgeBuilder);

            return(dst);
        }
Esempio n. 2
0
        /// <summary>
        /// 枝を再起的に生成する
        /// </summary>
        /// <param name="s"></param>
        /// <param name="depth"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        RefParticle MakeBranch(int depth, int maxDepth, RefParticle parent, float angle)
        {
            var t = depth / (float)maxDepth;

            angle += (_branchAngleCurve.Evaluate(t) * _branchAngleFactor) * Mathf.Deg2Rad;
            var dir    = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
            var length = _branchLengthCurve.Evaluate(t) * _branchLengthFactor;

            var pos     = parent.position + dir * length;
            var current = _branchParticleBuilder.Add(_s, pos, t);

            _branchEdgeBuilder.Add(_s, parent, current, t);

            if (depth > maxDepth)
            {
                return(current);
            }
            else
            {
                var child = MakeBranch(++depth, maxDepth, current, angle);

                // 枝を伸ばせる場合は枝を伸ばす
                if (_subBranchArchitect && _connectionEdgeBuilder)
                {
                    // Debug.Log("before: " + _s.GetParticleCount());
                    var subBranchMatrix = Matrix4x4.TRS(pos, Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.forward), Vector3.one);
                    var branch          = _subBranchArchitect.Build(subBranchMatrix);
                    // var branch = _subBranchArchitect.Build(Matrix4x4.identity);
                    // Debug.Log(branch.GetParticleCount());
                    _s = DistanceMixer.Mix(_s, branch, 3f, _connectionEdgeBuilder);
                    // Debug.Log("after: " + _s.GetParticleCount());
                }

                return(child);
            }
        }