35 lines
2.2 KiB
C#
35 lines
2.2 KiB
C#
|
krypusing 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>>>();
|
||
|
//turtleInterpretation
|
||
|
|
||
|
//loading required objects
|
||
|
var path = "Assets/Models/{0}.fbx";
|
||
|
var L = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "leaf"), typeof(GameObject));
|
||
|
var F = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "Flower"), typeof(GameObject));
|
||
|
|
||
|
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))));
|
||
|
turtleInterpretation.Add("&", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(-angle, 0, 0))));
|
||
|
turtleInterpretation.Add("^", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0))));
|
||
|
turtleInterpretation.Add("\\", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, -angle, 0))));
|
||
|
turtleInterpretation.Add("/", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Rotate(Quaternion.Euler(0, angle, 0))));
|
||
|
|
||
|
//Wildcard how to represent any other symbol
|
||
|
turtleInterpretation.Add("*.*", (float[] args) => new Tuple<GameObject, Matrix4x4>(obj, Matrix4x4.Translate(new Vector3(0.0f, 0.3f, 0)) * Matrix4x4.Scale(new Vector3(0.05f, 0.3f, 0.05f))));
|
||
|
turtleInterpretation.Add("L", (float[] args) => new Tuple<GameObject, Matrix4x4>(L, Matrix4x4.Translate(new Vector3(0.0f, 0.0f, -0.05f)) * Matrix4x4.Scale(new Vector3(1.5f, 1.0f, 1.0f))));
|
||
|
turtleInterpretation.Add("F", (float[] args) => new Tuple<GameObject, Matrix4x4>(F, Matrix4x4.Translate(new Vector3(0.0f, 0.0f, 0)) * Matrix4x4.Scale(new Vector3(0.3f, 0.5f, 0.3f))));
|
||
|
}
|
||
|
}
|
||
|
|