Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 7 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,11 @@
Joe Klinger - Procedural Graphics - Project 3 L-Systems

The objective of this assignment is to create an L System parser and generate interesting looking plants. Start by forking and then cloning this repository: [https://github.com/CIS700-Procedural-Graphics/Project3-LSystems](https://github.com/CIS700-Procedural-Graphics/Project3-LSystems)
This project is an L-system parser implemented by yours truly.

# L-System Parser
Extra features:
- Shadows (using Three JS)
- Custom objs - particularly the leaves, modeled by me

lsystem.js contains classes for L-system, Rule, and LinkedList. Here’s our suggested structure:
The grammar rules can be viewed in Turtle.js.

**The Symbol Nodes/Linked List:**

Rather than representing our symbols as a string like in many L-system implementations, we prefer to use a linked list. This allows us to store additional information about each symbol at time of parsing (e.g. what iteration was this symbol added in?) Since we’re adding and replacing symbols at each iteration, we also save on the overhead of creating and destroying strings, since linked lists of course make it easy to add and remove nodes. You should write a Linked List class with Nodes that contain at least the following information:

- The next node in the linked list
- The previous node in the linked list
- The grammar symbol at theis point in the overal string

We also recommend that you write the following functions to interact with your linked list:

- A function to symmetrically link two nodes together (e.g. Node A’s next is Node B, and Node B’s prev is Node A)
- A function to expand one of the symbol nodes of the linked list by replacing it with several new nodes. This function should look at the list of rules associated with the symbol in the linked list’s grammar dictionary, then generate a uniform random number between 0 and 1 in order to determine which of the Rules should be used to expand the symbol node. You will refer to a Rule’s probability and compare it to your random number in order to determine which Rule should be chosen.

**Rules:**

These are containers for the preconditions, postconditions and probability of a single replacement operation. They should operate on a symbol node in your linked list.

**L-system:**

This is the parser, which will loop through your linked list of symbol nodes and apply rules at each iteration.

Implement the following functions in L-System so that you can apply grammar rules to your axiom given some number of iterations. More details and implementation suggestions about functions can be found in the TODO comments

- `stringToLinkedList(input_string)`
- `linkedListToString(linkedList)`
- `replaceNode(linkedList, node, replacementString)`
- `doIterations(num)`

## Turtle

`turtle.js` has a function called renderSymbol that takes in a single node of a linked list and performs an operation to change the turtle’s state based on the symbol contained in the node. Usually, the turtle’s change in state will result in some sort of rendering output, such as drawing a cylinder when the turtle moves forward. We have provided you with a few example functions to illustrate how to write your own functions to be called by renderSymbol; these functions are rotateTurtle, moveTurtle, moveForward, and makeCylinder. If you inspect the constructor of the Turtle class, you can see how to associate an operation with a grammar symbol.

- Modify turtle.js to support operations associated with the symbols `[` and `]`
- When you parse `[` you need to store the current turtle state somewhere
- When you parse `]` you need to set your turtle’s state to the most recently stored state. Think of this a pushing and popping turtle states on and off a stack. For example, given `F[+F][-F]`, the turtle should draw a Y shape. Note that your program must be capable of storing many turtle states at once in a stack.

- In addition to operations for `[` and `]`, you must invent operations for any three symbols of your choosing.


## Interactivity

Using dat.GUI and the examples provided in the reference code, make some aspect of your demo an interactive variable. For example, you could modify:

1. the axiom
2. Your input grammer rules and their probability
3. the angle of rotation of the turtle
4. the size or color or material of the cylinder the turtle draws, etc!

## L-System Plants

Design a grammar for a new procedural plant! As the preceding parts of this assignment are basic computer science tasks, this is where you should spend the bulk of your time on this assignment. Come up with new grammar rules and include screenshots of your plants in your README. For inspiration, take a look at Example 7: Fractal Plant in Wikipedia: https://en.wikipedia.org/wiki/L-system Your procedural plant must have the following features

1. Grow in 3D. Take advantage of three.js!
2. Have flowers or leaves that are added as a part of the grammar
3. Variation. Different instances of your plant should look distinctly different!
4. A twist. Broccoli trees are cool and all, but we hope to see sometime a little more surprising in your grammars

# Publishing Your code

Running `npm run deploy` will automatically build your project and push it to gh-pages where it will be visible at `username.github.io/repo-name`. NOTE: You MUST commit AND push all changes to your MASTER branch before doing this or you may lose your work. The `git` command must also be available in your terminal or command prompt. If you're using Windows, it's a good idea to use Git Bash.
http://learningthreejs.com/blog/2012/01/20/casting-shadows/
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>HW2: LSystems</title>
<title>HW3: LSystems</title>
<style>
html, body {
margin: 0;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"gl-matrix": "^2.3.2",
"stats-js": "^1.0.0-alpha1",
"three": "^0.82.1",
"three-obj-loader": "^1.0.2",
"three-orbit-controls": "^82.1.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions res/OBJs/leaf.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
newmtl initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
208 changes: 208 additions & 0 deletions res/OBJs/leaf.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# This file uses centimeters as units for non-parametric coordinates.

mtllib leafModel.mtl
g default
v -0.558203 0.468282 0.283367
v -0.559605 0.387353 -0.333788
v -0.208264 0.482137 0.380682
v -0.167904 0.421021 -0.473463
v -0.460343 0.247707 0.001527
v -0.017143 0.257986 0.001272
v 0.977490 0.062557 0.001352
v 0.442338 0.401378 0.362225
v 0.446832 0.184975 0.001005
v 0.365100 0.344507 -0.401175
v -0.958702 0.296676 0.067452
v -0.979058 0.230942 0.001352
v -0.953753 0.291088 -0.079012
v -0.460343 0.274004 0.001527
v -0.017143 0.312138 -0.002838
v -0.167904 0.447317 -0.473463
v -0.559605 0.413649 -0.333788
v 0.447164 0.238911 0.004221
v 0.365100 0.370803 -0.401175
v -0.553566 0.494103 0.281566
v -0.203626 0.508995 0.365114
v 0.446975 0.427003 0.358566
v 0.977490 0.088853 0.001352
v -0.979058 0.257238 0.001352
v -0.958702 0.322973 0.067452
v -0.953753 0.317385 -0.079012
vt 0.000000 0.000000
vt 0.000000 1.000000
vt 0.500222 0.000000
vt 0.500222 1.000000
vt 0.000000 0.498648
vt 0.500222 0.498648
vt 1.000000 0.498648
vt 0.813282 0.000000
vt 0.813282 0.498648
vt 0.813282 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.498648
vt 0.500222 0.498648
vt 0.500222 1.000000
vt 0.000000 1.000000
vt 0.813282 0.498648
vt 0.813282 1.000000
vt 0.000000 0.000000
vt 0.500222 0.000000
vt 0.813282 0.000000
vt 1.000000 0.498648
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.500222 1.000000
vt 0.000000 1.000000
vt 0.813282 1.000000
vt 0.000000 0.000000
vt 0.500222 0.000000
vt 0.813282 0.000000
vt 1.000000 0.498648
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn -0.024343 0.943873 0.329411
vn -0.024343 0.943873 0.329411
vn -0.024343 0.943873 0.329411
vn -0.024343 0.943873 0.329411
vn 0.123195 0.957909 0.259295
vn 0.123195 0.957909 0.259295
vn 0.123195 0.957909 0.259295
vn 0.123195 0.957909 0.259295
vn -0.002109 0.840531 -0.541759
vn -0.002109 0.840531 -0.541759
vn -0.002109 0.840531 -0.541759
vn -0.002109 0.840531 -0.541759
vn 0.123919 0.888629 -0.441569
vn 0.123919 0.888629 -0.441569
vn 0.123919 0.888629 -0.441569
vn 0.123919 0.888629 -0.441569
vn 0.240165 0.857477 -0.455032
vn 0.240165 0.857477 -0.455032
vn 0.240165 0.857477 -0.455032
vn 0.264909 0.931458 0.249417
vn 0.264909 0.931458 0.249417
vn 0.264909 0.931458 0.249417
vn -0.008696 0.770149 -0.637805
vn -0.008696 0.770149 -0.637805
vn -0.008696 0.770149 -0.637805
vn -0.008696 0.770149 -0.637805
vn 0.008793 0.901873 0.431911
vn 0.008793 0.901873 0.431911
vn 0.008793 0.901873 0.431911
vn 0.008793 0.901873 0.431911
vn -0.008903 -0.937603 -0.347593
vn -0.008903 -0.937603 -0.347593
vn -0.008903 -0.937603 -0.347593
vn -0.008903 -0.937603 -0.347593
vn -0.118477 -0.941676 -0.314977
vn -0.118477 -0.941676 -0.314977
vn -0.118477 -0.941675 -0.314977
vn -0.118477 -0.941676 -0.314977
vn -0.041231 -0.837335 0.545133
vn -0.041231 -0.837335 0.545133
vn -0.041231 -0.837335 0.545133
vn -0.041231 -0.837335 0.545133
vn -0.111412 -0.866746 0.486147
vn -0.111412 -0.866746 0.486147
vn -0.111412 -0.866746 0.486147
vn -0.111412 -0.866746 0.486147
vn -0.194683 -0.842489 0.502305
vn -0.194683 -0.842489 0.502305
vn -0.194683 -0.842489 0.502305
vn -0.212563 -0.922337 -0.322664
vn -0.212563 -0.922337 -0.322664
vn -0.212563 -0.922337 -0.322664
vn 0.008417 -0.771232 0.636499
vn 0.008417 -0.771232 0.636499
vn 0.008417 -0.771232 0.636499
vn 0.008417 -0.771232 0.636499
vn -0.008793 -0.901873 -0.431911
vn -0.008793 -0.901873 -0.431911
vn -0.008793 -0.901873 -0.431911
vn -0.008793 -0.901873 -0.431911
vn -0.335870 0.000000 -0.941908
vn -0.335870 0.000000 -0.941908
vn -0.335870 0.000000 -0.941908
vn -0.335870 0.000000 -0.941908
vn 0.134393 0.000000 -0.990928
vn 0.134393 0.000000 -0.990928
vn 0.134393 0.000000 -0.990928
vn 0.134393 0.000000 -0.990928
vn -0.248232 0.342479 0.906140
vn -0.248232 0.342479 0.906140
vn -0.248232 0.342479 0.906140
vn -0.248232 0.342479 0.906140
vn 0.059858 0.334046 0.940654
vn 0.059858 0.334046 0.940654
vn 0.059858 0.334046 0.940654
vn 0.059858 0.334046 0.940654
vn 0.562304 0.008052 0.826892
vn 0.562304 0.008052 0.826892
vn 0.562304 0.008052 0.826892
vn 0.562304 0.008052 0.826892
vn 0.549273 0.000000 -0.835643
vn 0.549273 0.000000 -0.835643
vn 0.549273 0.000000 -0.835643
vn 0.549273 0.000000 -0.835643
vn -0.955707 0.000000 0.294318
vn -0.955707 0.000000 0.294318
vn -0.955707 0.000000 0.294318
vn -0.955707 0.000000 0.294318
vn -0.493885 0.073881 0.866383
vn -0.493885 0.073881 0.866383
vn -0.493885 0.073881 0.866383
vn -0.493885 0.073881 0.866383
vn -0.542861 0.000000 -0.839823
vn -0.542861 0.000000 -0.839823
vn -0.542861 0.000000 -0.839823
vn -0.542861 0.000000 -0.839823
vn -0.953830 0.000000 -0.300348
vn -0.953830 0.000000 -0.300348
vn -0.953830 0.000000 -0.300348
vn -0.953830 0.000000 -0.300348
s off
g pPlane1
usemtl initialShadingGroup
f 14/5/1 15/6/2 16/37/3 17/38/4
f 15/6/5 18/9/6 19/39/7 16/37/8
f 20/40/9 21/41/10 15/6/11 14/5/12
f 21/41/13 22/42/14 18/9/15 15/6/16
f 22/42/17 23/43/18 18/9/19
f 19/39/20 18/9/21 23/43/22
f 25/45/23 20/46/24 14/12/25 24/44/26
f 14/15/27 17/47/28 26/48/29 24/49/30
f 5/19/31 2/22/32 4/21/33 6/20/34
f 6/20/35 4/21/36 10/24/37 9/23/38
f 1/25/39 5/19/40 6/20/41 3/26/42
f 3/26/43 6/20/44 9/23/45 8/27/46
f 8/27/47 9/23/48 7/28/49
f 10/24/50 7/28/51 9/23/52
f 1/29/53 11/32/54 12/31/55 5/30/56
f 5/33/57 12/36/58 13/35/59 2/34/60
f 4/4/61 2/2/62 17/38/63 16/37/64
f 10/10/65 4/4/66 16/37/67 19/39/68
f 1/1/69 3/3/70 21/41/71 20/40/72
f 3/3/73 8/8/74 22/42/75 21/41/76
f 22/42/77 8/8/78 7/7/79 23/43/80
f 23/43/81 7/7/82 10/10/83 19/39/84
f 12/13/85 11/14/86 25/45/87 24/44/88
f 11/14/89 1/11/90 20/46/91 25/45/92
f 2/16/93 13/17/94 26/48/95 17/47/96
f 13/17/97 12/18/98 24/49/99 26/48/100
Binary file added res/images/skymap/nx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/images/skymap/ny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/images/skymap/nz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/images/skymap/px.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/images/skymap/py.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/images/skymap/pz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function init(callback, update) {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.shadowMap.enabled = true; // added by Joe Klinger
renderer.shadowMap.type = THREE.PCFSoftShadowMap; //https://threejs.org/docs/?q=light#Reference/Lights.Shadows/DirectionalLightShadow
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x020202, 0);
Expand Down
Loading