Added parametric growing anabeana task

This commit is contained in:
Bartosz Hejduk 2021-04-11 14:38:00 +02:00
parent c4a240581b
commit a11af3cb00
5 changed files with 76 additions and 9 deletions

View File

@ -0,0 +1,12 @@
#axiom
l(1)
#rules
#L->lR
l(a) : a>= 1 -> l(0)r(0.5)
#R->Lr
r(a) : a>= 1 -> l(0.5)r(0)
#l->L
l(a) : a < 1 -> l(a+0.1)
#r->R
r(a) : a < 1 -> r(a+0.1)
#end rules

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 26c541885e070b74c8c955b8f2681864
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +1,12 @@
using System.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using ConsoleLSystem;
using System;
public class AnabaenaTurtle : TurtleLSystem {
private static readonly System.Random random = new System.Random();
protected override void initLiteralInterpretation() {
public class AnabaenaTurtle : TurtleLSystem
{
protected override void initLiteralInterpretation()
{
turtleInterpretation = new Dictionary<string, Func<float[], Tuple<GameObject, Matrix4x4>>>();
//turtleInterpretation
@ -27,4 +24,3 @@ public class AnabaenaTurtle : TurtleLSystem {
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))));
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class AnabaenaTurtleParametric : TurtleLSystem
{
Matrix4x4 AnabeanaParametricTransform(float age)
{
return Matrix4x4.TRS(
new Vector3(
0.1f + age * 0.1f,
0.0f,
0.0f),
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, AnabeanaParametricTransform(args[0])));
turtleInterpretation.Add("r", (float[] args) => new Tuple<GameObject, Matrix4x4>(r, AnabeanaParametricTransform(args[0])));
//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))));
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4bb2d4d5cae2fbf45b0aa3980c9a8e96
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: