void Start() { _systemDatas = new List <TestData>(); { Oisif.LSystemData systemData = new Oisif.LSystemData("FX", new Oisif.SimpleValue(40.0f), 1.1f); systemData.AddRule(new Oisif.SimpleRule('X', ">[-FX]+FX")); _systemDatas.Add(new TestData(systemData, "A simple tree")); } { Oisif.LSystemData systemData = new Oisif.LSystemData("F", new Oisif.SimpleValue(22.5f), 2.3f); systemData.AddRule(new Oisif.SimpleRule('F', "GG+[+F-F-F]-[-F+F+F]")); _systemDatas.Add(new TestData(systemData, "A more complexe tree")); } { Oisif.LSystemData systemData = new Oisif.LSystemData("Y", new Oisif.SimpleValue(40.0f), 1.1f); List <Oisif.StochasticRule.RuleParam> ruleParams = new List <Oisif.StochasticRule.RuleParam>(); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.5f, ">G[+F][-F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.15f, ">G[+F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.15f, ">G[-F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.2f, "GC")); systemData.AddRule(new Oisif.StochasticRule('F', ruleParams)); systemData.AddRule(new Oisif.SimpleRule('Y', ">G[+F][-F]")); _systemDatas.Add(new TestData(systemData, "A simple random tree")); } { Oisif.LSystemData systemData = new Oisif.LSystemData("Y", new Oisif.RangeValue(35.0f, 45.0f), 1.1f); List <Oisif.StochasticRule.RuleParam> ruleParams = new List <Oisif.StochasticRule.RuleParam>(); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.6f, ">G[+F][F][-F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.05f, ">G[+F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.05f, ">G[-F]")); ruleParams.Add(new Oisif.StochasticRule.RuleParam(0.3f, "GC")); systemData.AddRule(new Oisif.StochasticRule('F', ruleParams)); systemData.AddRule(new Oisif.SimpleRule('Y', ">G[+F][Y][-F]")); _systemDatas.Add(new TestData(systemData, "A more complexe random tree")); } _system = new Oisif.LSystem(); _system.Data = _systemDatas[_currentIndex].Data; _interpretor = new Oisif.DrawerInterpretor(); }
void DrawLine(LSystem.Token token, LSystem system) { float lineLength = _lineLength; Vector3 offset = Vector3.zero; Vector3 pointStartA = _currentPosition; Vector3 pointStartB = _currentPosition; bool isParentDrawable = false; if (token.Parent != null) { if (ContainsAction(token.Parent.Sign)) { ActionData data = GetActionData(token.Parent.Sign); isParentDrawable = data.IsDrawable; } } Vector3 pointEndA = _currentPosition; Vector3 pointEndB = _currentPosition + Quaternion.Euler(0f, 0f, _currentAngle) * new Vector3(lineLength, 0f, 0f); if (token.Parent != null) { if (token.IsNewBranch || !isParentDrawable) { lineLength = _lineLength / Mathf.Pow(system.Data.DepthFactor, (system.Depth() - 1)); // Begin of line pointStartA = _currentPosition; pointStartB = _currentPosition; // End of line pointEndA = pointStartA; pointEndB = _currentPosition + Quaternion.Euler(0f, 0f, _currentAngle) * new Vector3(lineLength, 0f, 0f); } else { // Split the current branch float ratioStart = (float)(token.DrawableId - 1) / (float)token.DrawableIdMax; float ratioEnd = (float)token.DrawableId / (float)token.DrawableIdMax; // Begin of line pointStartA = token.Parent.Start + (token.Parent.End - token.Parent.Start) * ratioStart; pointStartB = token.Parent.Start + (token.Parent.End - token.Parent.Start) * ratioEnd; // End of line pointEndA = pointStartA; pointEndB = pointStartB; } } _currentPosition = pointEndB; // if isParentDrawable -> changer l'ordre de dessin _RenderManager.CreateInterpolableLine(token.Depth + token.DrawableId, pointStartA, pointEndA, pointStartB, pointEndB); //Debug.Log("New line - token: " + token.ToString() + " | pointStartA: " + start1.ToString("F2") + " | pointEndA : " + pointEndA.ToString("F2") + " | pointStartB: " + pointStartB.ToString("F2") + " |pointEndB: " + pointEndB.ToString("F2")); token.Start = pointEndA; token.End = pointEndB; _segmentCount++; }
void Move(LSystem.Token token, LSystem system) { float lineLength = _lineLength / Mathf.Pow(system.Data.DepthFactor, (system.Depth() - 1)); _currentPosition = _currentPosition + Quaternion.Euler(0f, 0f, _currentAngle) * new Vector3(lineLength, 0f, 0f); }
void DivideLineLength(LSystem.Token token, LSystem system) { _lineLength /= _lineLengthScaleFactor; }
void MultiplyLineLength(LSystem.Token token, LSystem system) { _lineLength *= _lineLengthScaleFactor; }
void SaveDrawState(LSystem.Token token, LSystem system) { _savedPositions.Push(new DrawState(_currentPosition, _currentAngle, _lineLength, _segmentCount)); }
void DecreaseAngle(LSystem.Token token, LSystem system) { _currentAngle -= system.Data.Angle.Value(); }
public override void Execute(LSystem system) { base.Execute(system); _RenderManager.Expand(); }