Skip to content

Latest commit

 

History

History
220 lines (183 loc) · 14.4 KB

README.md

File metadata and controls

220 lines (183 loc) · 14.4 KB

Artificial Creation: An OpenGL-Based Generative Tool for 3D Objects

Table of contents

  1. Introduction
    1. Background Information
  2. Usage
    1. Installing Dependencies
    2. Running the Project
  3. Features
  4. FAQ
  5. External Materials
  6. Glossary
  7. References

Introduction

Procedural generation has been extensively studied .
Generation of 3D objects is a fascinating but challenging task that can be achieved using L-systems - a mathematical model created by Astrid Lindenmayer. L-systems are using a series of algorithms originally developed to simulate the growth of living organisms. They have been used for decades in games, films, visualisation purposes and other fields. This tool will allow you to bring your ideas to life - visualise them and save your creations.

Background Information

To be able to take full advantage of this project let's first understand what L-systems actually are and how they are being visualised. The idea is pretty simple - we start with a simple structure and apply rules to it to achieve more complex objects.

Drawing Basic Elements

Let's say we have a stem:
Stem
now we create a rule.

Rule 1: If you see a stem, add a branch to it.

We need a way to formally define this. To do so we introduce the concept of axiom and symbols. In our example the axiom will be the stem which visually is represented by a line being drawn forward.
We can then represent the stem using the symbol S and the drawing forward operation using the symbol F.
We can define the rule of adding a branch as drawing a forward symbol under an angle.
To represent an angle we will use + for left and - for right. Let's call a rule R.

Axiom -> SR
S -> F
R -> -F

Rule 1 Applied to the Stem

'Pushing' and 'Popping'

Let's add another branch that will go to the left.
We should add a rule L -> +F and change the axiom to Axiom -> SRL, right?

Axiom -> SRL
S -> F
R -> -F
L -> +F

Rule 1 Applied to the Stem
Well not exactly.
What happened here is that we started added the new branch to the previous branch. But what we really want is to apply it to the stem.
This introduces us to the concept of brackets.

The symbol [ and ] allow us to 'push' and 'pop' a state. This basically means that we are keeping track of where we are while applying the rules.
As we will go higher and higher in the structure it will become much harder to keep track of where we are in the structure so we will use the square brackets as placeholders to be able to find our way back if we want to make any changes on the lower levels.
Let's try this:

Axiom -> S[R]L
S -> F
R -> -F
L -> +F

This basically means:

Draw the stem, push the state of the next commands onto the stack - branch right, pop the state, we are now back to the state from before 'R' now branch left.

Et voilà, our mini 'plant' structure is there:
Rule 1 Applied to the Stem

List of Transformations

As we are working in a 3D space we will be using not only left and right rotations but also pitch and roll. To better understand the concept of these 3D transformations please refer to this link.
In L-systems we define these rotations using the following symbols (constants):

Symbol Interpretation
F move forward and draw a line
f move forward without drawing a line
+ turn left by angle δ
- turn right by angle δ
& pitch down by angle δ
^ turn left by angle δ
\ turn left by angle δ
/ turn left by angle δ
| turn around (180°)

Which can be visualised as follows:

Where R_(δ) represents the 3D rotation matrices.

Usage

This project is a graphics 3D procedural generation tool created using OpenGL. It is written in C++ and is using several third-party libraries, including GLFW, GLAD, and GLM (the full list can be found in the External Materials section. To build and run the project, follow the instructions below.

Installing Dependencies

The project dependencies are managed automatically by gitfetch, which allows for automatic installation of all dependencies, configures and integrates them into the project.

Running the Project

  1. Clone the repository:
git clone https://gitlab.com/sc20tmv/finalyearproject.git
  1. Build the project:
cd project
mkdir build && cd build
cmake ..
make
  1. Run the project:
./project

Features

L-system Parameters:

  • Generations − the number of generation the L-system is producing, it can either be inputted by pressing '+' and '-' buttons, as text or changed using the slider.
  • Angle − the angle used by the turtle when interpreting the system, it can either be inputted as text or changed using the slider.
  • Contextual/Parametric Input − the user is able to change the rules to match the input format for the contextual and parametric L-systems with the deterministic grammar input mode being the default.

Shape Parameters:

  • Length and Width − change the length and width of the shape;
  • Colour and Texture − change the rule's shape colour or apply a texture to it;
    Developmental Surface Models allow you to additionally specify the angle that will be used when generating the shape.
    The texture feature is yet not implemented for developmental surface models.

Other Parameters:

  • Camera − you can adjust the position of the camera and the object (in x, y, z coordinates)
    additionally the button Center Object will automatically realign the object;
  • Lighting − you can adjust the position of the light source, its colour and strength;
  • Dark/Light Mode − allows to switch background colours: black (dark mode) and white (light mode) are available;
  • Export/Import − save created meshes and import OBJ objects into the program using this feature.
    The default folder for saving and loading these files is in the main directory and is called objects.
    When specifying the object's name, ignore the .obj extension.

This file is under development; further sections, examples and figures will be added.

FAQ

What kind of 3D models can I create using this software?

You are able to generate deterministic and context-sensitive L-systems.

Do I need programming experience to use this software?

No, this software provides a user-friendly environment.

How are errors or invalid inputs handled?

Incorrect input will not be processed - nothing will happen.

Can I import or export the models?

Yes, for further instructions refer to the Features section.

What operating systems is the software compatible with?

The software was tested on macOS and Linux environments, it should be running and compiling correctly on Windows.

External Materials

Shader, Checkpoint, Error, Shader, Mesh, the struct MeshData and the function loadOBJ classes were used (after obtaining permission) from the material of COMP3811 module.

Used L-systems productions sources: 1, 9, 10, 11, 12}.

Inspiration for:

  • some of the L-system classes were inspired by the implementation of the project: 13
  • some of the element in the Camera and Window classes were inspired by the implementation of the project: 14
  • the function getArcballVec taken from the tutorial: 20
  • the function loadTexture were implemented using the tutorials:21

External libraries: ImGui, Glad and GLFW3 (for project setup), GLM (for vector and matrix operations), STB (image processing).
Texture files: 15, 16, 17, 18.
Font: Noto Sans 19.

Glossary

L-system: A type of formal grammar used to generate complex and detailed geometric structures.1
Axiom: The starting symbol for an L-system.1
Rule: A set of instructions that define how a variable should replaced.3
Iteration: A single step (generation) in the growth (application of rules) of an L-system.
Production: In the context of L-systems used interchangeably with Rule.3
Parameter: A value that can be adjusted to affect and modify the behavior and final output of an L-system. 4
Turtle graphics: A method of interpreting L-systems by drawing variables as a series of movement commands. 5
Fractal: A geometric pattern that is self-similar at different scales.6
Stochastic L-system: An L-system using probability and randomness in the set of rules.7
OBJ File: 3D object file type used in graphics that stored information about the geometry, texture, and materials of an object.8
Export: In the project's context: The process of saving a 3D model into a file in a format that can be used to share it and import it into another application.
Import: In the project's context: The process of loading a 3D model from a file.

References

1 Prusinkiewicz, P., & Lindenmayer, A. (2004). Algorithmic beauty of plants (2nd ed.). Springer. Retrieved from http://algorithmicbotany.org/papers/abop/abop.pdf
2 L-system. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/L-system
3 L-system. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/L-system#L-system_structure
4 L-system. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/L-system#Parametric_grammars
5 Turtle graphics. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/Turtle_graphics
6 Fractal. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/Fractal
7 L-system. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/L-system#Stochastic_grammars
8 Wavefront .obj file. Wikipedia. Wikimedia Foundation, 29 Mar. 2022. https://en.wikipedia.org/wiki/Wavefront_.obj_file

9 Prusinkiewicz, P., 1987. Applications of L-systems to computer imagery. In: Ehrig, H., Nagl, M., Rosenfeld, A. and Rozenberg, G. eds., Graph Grammars and Their Application to Computer Science; Third International Workshop. Springer-Verlag, Berlin, pp.534-548. doi: 10.1007/3-540-18405-5_40.
10 Hogeweg, P. and Hesper, B., 1974. A model study on biomorphological description. Pattern Recognition, 6, pp.165-179.
11 SideFX. (n.d.). L-System Node. Houdini Documentation. Retrieved April 8, 2023, from https://www.sidefx.com/docs/houdini/nodes/sop/lsystem.html.
12 Bourke, P. (1991). L-System User Notes (Version 2.5). Retrieved from http://paulbourke.net/fractals/lsys/.
13 Muhlich, J. (2021). Pomegranate. [GitHub repository]. GitHub. Retrieved from https://github.com/i-yam-jeremy/pomegranate/tree/d53ea831e8050801ba5bac828ff70e1c72b79903.
14 SaferGo. (2021). CroissantVulkanRenderer [GitHub repository]. GitHub. Retrieved from https://github.com/SaferGo/CroissantVulkanRenderer/tree/main/src/CroissantRenderer.
15 Zorak-Art. (n.d.). Stylized grass texture. Retrieved from https://skfb.ly/oyyGU. Licensed under CC Attribution-NonCommercial-NoDerivs 4.0 International (CC BY-NC-ND 4.0).
16 Pixnio. (2023). Bark Texture Wood. Retrieved from https://pixnio.com/textures-and-patterns/tree-bark-cortex/bark-texture-wood. Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Generic (CC BY-NC-SA 2.0).
17 Slater, K. (2023). Tree Bark Picture. Retrieved from https://commons.wikimedia.org/wiki/File:Tree_Bark_Picture.JPG. Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).
18 Unknown. (2023). Free Texture Tree Bark (22820701). Retrieved from https://commons.wikimedia.org/wiki/File:Free_Texture_Tree_Bark_(22820701).jpeg. Licensed under Creative Commons Attribution 3.0 Unported (CC BY 3.0).
19 Google. (2014). Noto Sans. Retrieved from https://www.google.com/get/noto/. Licensed under the SIL Open Font License, Version 1.1.
20 Wikibooks. (2021). OpenGL Programming/Modern OpenGL Tutorial Arcball. Retrieved April 30, 2023, from https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball
21 LearnOpenGL. (n.d.). Getting started/Textures. Retrieved April 30, 2023, from https://learnopengl.com/Getting-started/Textures