Animacja L-Systemów
This commit is contained in:
parent
1bf408f2b5
commit
3f9b965c26
9
Unity Project/Assets/LSystem/Vogel animated.txt
Normal file
9
Unity Project/Assets/LSystem/Vogel animated.txt
Normal file
@ -0,0 +1,9 @@
|
||||
#axiom
|
||||
C(0,0)
|
||||
#F++F++F++
|
||||
#rules
|
||||
C(i,n) : i>=1 -> C(0,n)[+(n*137.5)f(0)S]
|
||||
C(i,n) : i<1 -> C(i+0.1,n+0.1)
|
||||
f(a) -> f((a^2+0.0003)^0.5)
|
||||
#C(i) -> C(i+1)[+(i*137.5)f(0.3*i^0.5)S]
|
||||
#end rules
|
7
Unity Project/Assets/LSystem/Vogel animated.txt.meta
Normal file
7
Unity Project/Assets/LSystem/Vogel animated.txt.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2945726240c5ce8488b2b5d559ab19bf
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
2078
Unity Project/Assets/Scenes/LSystem3DAnimated.unity
Normal file
2078
Unity Project/Assets/Scenes/LSystem3DAnimated.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Unity Project/Assets/Scenes/LSystem3DAnimated.unity.meta
Normal file
7
Unity Project/Assets/Scenes/LSystem3DAnimated.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed3c43e4d80050d4298aba199527f230
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -15,6 +15,10 @@ public class TurtleEditor : Editor
|
||||
turtleLSystem.loadFile();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch ON/OFF animation")) {
|
||||
turtleLSystem.switchAnimation();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Evaluate")) {
|
||||
turtleLSystem.evaluateAndPresent();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5805e7212a5b20b4da42e342c1edaf04
|
||||
guid: 588dc2943fa208d4fb5a22dd70eaae67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
60
Unity Project/Assets/Scripts/Turtle3DAnimated.cs
Normal file
60
Unity Project/Assets/Scripts/Turtle3DAnimated.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using ConsoleLSystem;
|
||||
using System;
|
||||
|
||||
public class Turtle3DAnimated : TurtleLSystem {
|
||||
public GameObject obj;
|
||||
public GameObject sphere;
|
||||
public float angle;
|
||||
|
||||
private Func<float[], Matrix4x4> _roation(Vector3 axis) {
|
||||
Matrix4x4 f(float[] args) {
|
||||
if (args.Length == 0) {
|
||||
return Matrix4x4.Rotate(Quaternion.AngleAxis(angle, axis));
|
||||
}
|
||||
else {
|
||||
return Matrix4x4.Rotate(Quaternion.AngleAxis(args[0], axis));
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
protected override void initLiteralInterpretation() {
|
||||
turtleInterpretation = new Dictionary<string, Func<float[], Tuple<GameObject, Matrix4x4>>>();
|
||||
//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))));
|
||||
|
||||
//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))));
|
||||
|
||||
//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, _roation(Vector3.back)(args) ));
|
||||
turtleInterpretation.Add("-", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, _roation(Vector3.forward)(args)));
|
||||
|
||||
turtleInterpretation.Add("\\", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, _roation(Vector3.down)(args)));
|
||||
turtleInterpretation.Add("/", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, _roation(Vector3.up)(args)));
|
||||
|
||||
turtleInterpretation.Add("^", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, _roation(Vector3.left)(args)));
|
||||
turtleInterpretation.Add("&", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, _roation(Vector3.right)(args)));
|
||||
|
||||
|
||||
turtleInterpretation.Add("f", (float[] args) => new Tuple<GameObject, Matrix4x4>(null, Matrix4x4.Translate(Vector3.up * args[0])));
|
||||
|
||||
turtleInterpretation.Add("S", (float[] args) => new Tuple<GameObject, Matrix4x4>(sphere,Matrix4x4.identity));
|
||||
|
||||
|
||||
//Wildcard how to represent any other symbol
|
||||
//turtleInterpretation.Add("*.*", (float[] args) => new Tuple<GameObject, Matrix4x4>(obj, transformation));
|
||||
}
|
||||
void Update() { base.Update(); }
|
||||
}
|
||||
|
11
Unity Project/Assets/Scripts/Turtle3DAnimated.cs.meta
Normal file
11
Unity Project/Assets/Scripts/Turtle3DAnimated.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4527a053b14070649a36fb06e5a69caf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -8,8 +8,11 @@ using System;
|
||||
|
||||
|
||||
|
||||
abstract public class TurtleLSystem : MonoBehaviour
|
||||
{
|
||||
abstract public class TurtleLSystem : MonoBehaviour {
|
||||
public float speed;
|
||||
private float nextStep;
|
||||
|
||||
|
||||
public string LSystemPath;
|
||||
|
||||
public uint steps;
|
||||
@ -18,6 +21,8 @@ abstract public class TurtleLSystem : MonoBehaviour
|
||||
|
||||
private List<GameObject> gameObjects = new List<GameObject>();
|
||||
|
||||
private bool isAnimationRunning = false;
|
||||
|
||||
private Mesh getCylinder(int quality,float width,float length) {
|
||||
Mesh mesh = new Mesh();
|
||||
//mesh.triangles
|
||||
@ -131,6 +136,7 @@ abstract public class TurtleLSystem : MonoBehaviour
|
||||
}
|
||||
abstract protected void initLiteralInterpretation();
|
||||
public void loadFile() {
|
||||
nextStep = Time.time;
|
||||
clearObjects();
|
||||
var sr = new StreamReader(LSystemPath);
|
||||
evaluator = LSystemFileParser.parseLSystem(sr);
|
||||
@ -147,16 +153,27 @@ abstract public class TurtleLSystem : MonoBehaviour
|
||||
//Instantiate(x,Matrix4x4.identity);
|
||||
}
|
||||
|
||||
public void switchAnimation() {
|
||||
this.isAnimationRunning = !this.isAnimationRunning;
|
||||
nextStep = Time.time;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
void runAnimation() {
|
||||
if (nextStep < Time.time) {
|
||||
for (int i = 0; i < (Time.time - nextStep) * speed; i++) {
|
||||
evaluator.rewrite();
|
||||
}
|
||||
present();
|
||||
nextStep = Time.time + 1/speed;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
if (this.isAnimationRunning){
|
||||
this.runAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ By taki liść wykorzystać w innym projekcie należy go wyeksportować, by to z
|
||||
|
||||
Poszukaj utworzonego modelu i dodaj go do sceny, żeby się upewnić czy faktycznie jest taki sam.
|
||||
|
||||
Możesz zauważyć, że pozycja tekstury wróciła do domyślnej wartości. By to naprawić przeciągnij na dodany model wcześniej stworzony materiał. Nie chcemy za każdym razem dodaniem liścia zmieniać materiału, dlatego zapisz obiekt jako prefab przeciągając go do pola
|
||||
|
||||
## Zadanie domowe
|
||||
|
||||
Zastąp płatki róży z poprzedniego zadania domowego wygenerowanymi przez siebie płatkami za pomocą sweep surface
|
||||
@ -167,4 +169,3 @@ Poniżej znajduje się symboliczna reprezentacja zasad
|
||||
|
||||
|
||||
![rose](Rose\rose_diagram.png)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user