forked from andkok/MWS_2021
58 lines
3.1 KiB
C#
58 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using ConsoleLSystem;
|
|
using System;
|
|
|
|
public class AnabaenaTurtle : TurtleLSystem {
|
|
|
|
// funkcja. albo klaska do obrotow bo od kodu oczy krwawią
|
|
|
|
Matrix4x4 anabenaParametricTransformation(float age) {
|
|
return Matrix4x4.TRS(new Vector3(0.1f + age*0.1f, 0, 0),
|
|
// Quaternion.Euler(0,0, UnityEngine.Random.Range(-20, 20)),
|
|
Quaternion.identity,
|
|
new Vector3(0.1f + age*0.1f, 0.1f + age*0.1f, 0.1f + age*0.1f));
|
|
}
|
|
|
|
protected override void initLiteralInterpretation() {
|
|
|
|
turtleInterpretation = new Dictionary<string, Func<float[], Tuple<GameObject, Matrix4x4>>>();
|
|
//turtleInterpretation
|
|
//loading required objects
|
|
var path = "Assets/Models/{0}.fbx";
|
|
var bigL = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigL"), typeof(GameObject));
|
|
var bigR = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigR"), typeof(GameObject));
|
|
var l = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "l"), typeof(GameObject));
|
|
var r = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "r"), typeof(GameObject));
|
|
|
|
//creating functions that are used for interpretation
|
|
turtleInterpretation.Add("l", (float[] args) => new Tuple<GameObject, Matrix4x4>(l, anabenaParametricTransformation(args[0])));
|
|
turtleInterpretation.Add("r", (float[] args) => new Tuple<GameObject, Matrix4x4>(r, anabenaParametricTransformation(args[0])));
|
|
|
|
// ponizszych dwoch nie zminiam bo sa nie uzywane w parametryzowanej Anabenie
|
|
turtleInterpretation.Add("L", (float[] args) => new Tuple<GameObject, Matrix4x4>(bigL, Matrix4x4.Rotate(Quaternion.Euler(0,0, UnityEngine.Random.Range(-20, 20))) * Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f, 0.1f))));
|
|
turtleInterpretation.Add("R", (float[] args) => new Tuple<GameObject, Matrix4x4>(bigR, Matrix4x4.Rotate(Quaternion.Euler(0,0, UnityEngine.Random.Range(-20, 20))) * Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f, 0.1f))));
|
|
|
|
|
|
/*
|
|
NIE MOŻNA DAWAĆ KOMENTARZY OBOK REGUŁ
|
|
|
|
r(a) : a<1 -> r(a+0.1) # analogicznie dla r - w takiej sytuacji Unity po kilku ewoluacjach rzuca błedem, a potem tak zdycha, że tylko restart kompa pomaga
|
|
(po zabiciu procesu przez manager zadań jakiś proces pozostaje i niemozliwe jest ponowne uruchomienie Unity)
|
|
|
|
|
|
NullReferenceException: Object reference not set to an instance of an object
|
|
TurtleLSystem.evaluate () (at Assets/Scripts/TurtleLSystem.cs:75)
|
|
TurtleLSystem.evaluateAndPresent () (at Assets/Scripts/TurtleLSystem.cs:142)
|
|
TurtleEditor.OnInspectorGUI () (at Assets/Editor/TurtleEditor.cs:19)
|
|
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <420b942f64794d4da66420603f126f7b>:0)
|
|
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
|
|
|
|
*/
|
|
|
|
}
|
|
}
|
|
|