2021-03-13 17:35:25 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
using ConsoleLSystem;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public class Turtle3D : TurtleLSystem {
|
|
|
|
public GameObject obj;
|
|
|
|
public float angle;
|
|
|
|
|
|
|
|
protected override void initLiteralInterpretation() {
|
|
|
|
turtleInterpretation = new Dictionary<string, Func<float[], Tuple<GameObject, Matrix4x4>>>();
|
2021-04-11 15:59:57 +02:00
|
|
|
|
|
|
|
var path = "Assets/Models/{0}.fbx";
|
|
|
|
// obiekty takie jak L, R, l, r symbolizujące kwiaty i liście
|
|
|
|
// wilekie L - liśc
|
|
|
|
var bigL = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigL"), typeof(GameObject));
|
|
|
|
// wielkie R - kwiat
|
|
|
|
var bigR = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigR"), typeof(GameObject));
|
|
|
|
//male l, r odgałęzienia
|
|
|
|
var l = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "l"), typeof(GameObject));
|
|
|
|
var r = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "r"), typeof(GameObject));
|
|
|
|
|
2021-03-13 17:35:25 +01:00
|
|
|
//turtleInterpretation
|
|
|
|
var transformation = Matrix4x4.Translate(new Vector3(0.0f, 0.1f, 0)) * Matrix4x4.Scale(new Vector3 (0.05f, 0.1f, 0.05f));
|
|
|
|
|
|
|
|
turtleInterpretation.Add("+", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, -angle))));
|
|
|
|
turtleInterpretation.Add("-", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, angle))));
|
|
|
|
|
|
|
|
//Wildcard how to represent any other symbol
|
|
|
|
turtleInterpretation.Add("*.*", (float[] args) => new Tuple<GameObject, Matrix4x4>(obj, transformation));
|
2021-04-11 15:59:57 +02:00
|
|
|
|
|
|
|
// & - obrót do góry względem osi X o kąt $\delta$ - args[0] zaiwera infiormacje o kącie powinny być w zmiennej Unity angle
|
|
|
|
// x, y, z
|
|
|
|
turtleInterpretation.Add("$", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0))));
|
|
|
|
// ^ obrót o kąt -1*delta w osi X
|
|
|
|
turtleInterpretation.Add("^", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(-angle, 0, 0))));
|
|
|
|
// \ backslash obrót w prawo roll - obrót względem osi Y o kąt -delata
|
|
|
|
turtleInterpretation.Add("\\", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, -angle, 0))));
|
|
|
|
// / slash forward slash obrót w lewo - kąt -1*delta w osi Y
|
|
|
|
turtleInterpretation.Add("/", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, -angle, 0))));
|
|
|
|
|
2021-03-13 17:35:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|