Skip to content

Commit ac50cd3

Browse files
committed
2 parents a9c3a38 + 5fe02e7 commit ac50cd3

File tree

1 file changed

+304
-2
lines changed

1 file changed

+304
-2
lines changed

README.md

Lines changed: 304 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,309 @@
1-
# Readme
2-
31
[![Java CI with Maven](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/maven.yml/badge.svg)](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/maven.yml)
42
[![CodeQL Advanced](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/codeql.yml/badge.svg)](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/codeql.yml)
53
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/5d913b2c5d064bee83780eefee17f400)](https://app.codacy.com/gh/ArtifactForms/MeshLibCore/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
64
[![Maintainability](https://api.codeclimate.com/v1/badges/c860a89479fdedd6be77/maintainability)](https://codeclimate.com/github/ArtifactForms/MeshLibCore/maintainability)
75
[![Maven Package](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/ArtifactForms/MeshLibCore/actions/workflows/maven-publish.yml)
6+
7+
# Artifact Forms
8+
9+
A _JAVA_ library to construct and manipulate geometry in Three-dimensional space.
10+
11+
## Background / Intension
12+
13+
This Java library began as a hobby project in 2015/2016. I started it to deepen my understanding of creating and manipulating 3D geometry. This built upon knowledge I gained from an earlier internship with product design students. During that time, I was introduced to the programming language Processing.
14+
15+
Processing captivated me from the start. Designed for visual learners, Processing is a great tool to get started with programming. You can learn more at processing.org. While Processing isn't strictly necessary, the library's core functionality is independent of the Processing environment. However, Processing offers a convenient way to visualize constructed meshes through its rendering pipeline, which leverages JAVA, JAVA2D, and OPENGL.
16+
17+
## Status Quo
18+
Currently, my primary focus is on refining the user documentation. As my understanding of code structure and architecture has evolved, I've been actively refactoring the codebase to maintain its cleanliness and organization. Smaller additions are made periodically.
19+
20+
The Processing-specific rendering components are housed in a separate repository, representing another ongoing project.
21+
22+
In essence, this codebase serves as a platform for learning and working with legacy code. I've embraced the challenge of working with existing code, viewing it as an opportunity to explore new testing approaches. Constructing tests around legacy code for refactoring purposes is a fascinating and valuable endeavor, in my opinion, an essential practice.
23+
24+
## Future
25+
26+
The scope of related topics is vast, and my list of potential features is accordingly expansive. Some of these are outlined under 'Planned Features'.
27+
28+
## Core Features
29+
30+
* **3D Geometry Creation and Manipulation** Build a wide range of 3D shapes and modify them using various operations.
31+
* **Customizable Mesh Creation:** Create custom shapes using a variety of mesh creation tools and modifiers.
32+
* **Extensible Framework:** Easily add new features and functionalities to the library.
33+
* **OBJ File Import and Export:** Import and export 3D models in the OBJ file format.
34+
35+
## Showcase
36+
37+
The following images are showing the library in action.
38+
39+
![](documentation/images/lib_showcase_1.png)
40+
Subdivision is so beautiful and satisfying too look at.
41+
42+
![](/documentation/images/lib_showcase_2.png)
43+
bend bend bend mesh...
44+
45+
![](documentation/images/lib_showcase_3.png)
46+
Throwing some conway operations on a cube seed.
47+
48+
## Core elements
49+
50+
- Mesh3D
51+
- Face3D
52+
- Edge3D
53+
- [Creators](#creators)
54+
- Modifiers
55+
56+
## Coordinate System
57+
58+
The library is build up on a left-handed coordinate system.
59+
The decision was justified by using the 'Processing' rendering pipeline in the first place.
60+
But the core library is highly decoupled from the 'Processing' environment.
61+
So the library could be used independently.
62+
63+
## Mesh3D
64+
65+
The following example shows how to work with the base mesh class. For this purpose we want to create a simple quad. The quad has four vertices, one for each
66+
corner. To make things a bit more explanatory we compose the quad out of two triangular faces. **Important:** This is just an example to illustrate the base concepts. The library already provides a convenient way to construct primitives and more complex shapes. But we dive into this at a later point. For now
67+
let's keep things simple. But also keep in mind that it might be useful to construct shapes by yourself in some cases.
68+
69+
```
70+
(-1, 0, -1) (1, 0, -1)
71+
o--------------o
72+
| . |
73+
| . |
74+
| . |
75+
| . |
76+
| . |
77+
o--------------o
78+
(-1, 0, 1) (1, 0, 1)
79+
```
80+
81+
### Mesh3D Object
82+
83+
The base class for all shapes is `mesh.Mesh3D`.
84+
85+
```java
86+
import mesh.Mesh3D;
87+
88+
Mesh3D mesh = new Mesh3D();
89+
```
90+
91+
### Vertex Coordinates
92+
93+
Next we determine the shape's coordinates in Three-Dimensional space. In this case the shape lies flat on the xz plane, so each y-coordinate is 0.0f.
94+
95+
```java
96+
mesh.add(new Vector3f(1, 0, -1));
97+
mesh.add(new Vector3f(1, 0, 1);
98+
mesh.add(new Vector3f(-1, 0, 1);
99+
mesh.add(new Vector3f(-1, 0, -1);
100+
```
101+
102+
Alternatively use `addVertex(x, y, z)`
103+
104+
```java
105+
mesh.addVertex(1, 0, -1);
106+
mesh.addVertex(1, 0, 1);
107+
mesh.addVertex(-1, 0, 1);
108+
mesh.addVertex(-1, 0, -1);
109+
```
110+
111+
### Construct Faces
112+
113+
The added vertices are now at an indexed position within the mesh.
114+
115+
```
116+
3 0
117+
o--------------o
118+
| . |
119+
| . |
120+
| . |
121+
| . |
122+
| . |
123+
o--------------o
124+
2 1
125+
```
126+
127+
Knowing the index of each vertex makes adding faces a piece of cake. We only have to take care of the winding order. In this case the winding order
128+
is counter-clockwise with all face normals pointing up towards negative y.
129+
130+
```java
131+
mesh.addFace(0, 1, 3);
132+
mesh.addFace(1, 2, 3);
133+
```
134+
135+
![](documentation/images/quad_example.png)
136+
137+
### Modify the mesh
138+
139+
Now we have a mesh constisting of four vertices and two triangular faces. This could be retrieved by using:
140+
141+
```java
142+
int vertexCount = mesh.getVertexCount();
143+
int faceCount = mesh.getFaceCount();
144+
```
145+
146+
We can modify the present mesh by using so called _Modifiers_. Each modifier derives from the root interface `IMeshModifier`.
147+
148+
```java
149+
package mesh.modifier;
150+
151+
import mesh.Mesh3D;
152+
153+
public interface IMeshModifier {
154+
155+
public Mesh3D modify(Mesh3D mesh);
156+
157+
}
158+
```
159+
160+
Let's say we would like to give our mesh some thickness.
161+
To achieve this we use the _SolidifyModifier_.
162+
163+
```java
164+
SolidifyModifier modifier = new SolidifyModifier();
165+
modifier.setThickness(0.5f);
166+
modifier.modify(mesh);
167+
```
168+
169+
## Creators
170+
171+
Effortless Shape Creation with Mesh Creators
172+
173+
The library provides a variety of Mesh Creators to simplify the construction of various shapes. These creators employ the Factory Method or Builder design pattern, allowing for a flexible and streamlined approach.
174+
175+
While similar to a classic builder, Mesh Creators offer a unique combination of features:
176+
177+
* **Getters and Setters:** Access and modify the creator's internal state using getters and setters, providing fine-grained control over the mesh creation process.
178+
* **Chaining is not supported:**
179+
180+
With over 100 Mesh Creators categorized for easy access, you can quickly and efficiently build a wide range of 3D shapes. For a comprehensive overview, refer to our documentation: [Mesh Creators](documentation/documentation.md)
181+
182+
Core of Mesh Creators: The IMeshCreator Interface
183+
184+
Every Mesh Creator in the library adheres to the IMeshCreator interface. The following code snippet illustrates this foundational interface:
185+
186+
```java
187+
package mesh.creator;
188+
189+
import mesh.Mesh3D;
190+
191+
public interface IMeshCreator {
192+
193+
public Mesh3D create();
194+
195+
}
196+
```
197+
198+
To get a little more specific we can plug the quad example code into a custom creator to illustrate the overall concept.
199+
Let's have a look at our example code again.
200+
201+
```java
202+
import mesh.Mesh3D;
203+
import mesh.creator.IMeshCreator;
204+
205+
Mesh3D mesh = new Mesh3d();
206+
mesh.addVertex(1, 0, -1);
207+
mesh.addVertex(1, 0, 1);
208+
mesh.addVertex(-1, 0, 1);
209+
mesh.addVertex(-1, 0, -1);
210+
mesh.addFace(0, 1, 3);
211+
mesh.addFace(1, 2, 3);
212+
```
213+
214+
First we move our example code into the factory method of a custom mesh creator class and simply return the mesh.
215+
216+
```java
217+
import mesh.Mesh3D;
218+
import mesh.creator.IMeshCreator;
219+
220+
public class MyQuadCreator implements IMeshCreator {
221+
222+
public Mesh3D create() {
223+
Mesh3D mesh = new Mesh3d();
224+
mesh.addVertex(1, 0, -1);
225+
mesh.addVertex(1, 0, 1);
226+
mesh.addVertex(-1, 0, 1);
227+
mesh.addVertex(-1, 0, -1);
228+
mesh.addFace(0, 1, 3);
229+
mesh.addFace(1, 2, 3);
230+
return mesh;
231+
}
232+
233+
}
234+
```
235+
236+
Let's assume we want to generalize the code a bit further. We introduce a parameter for the vertex coordinates named _halfSize_.
237+
238+
```java
239+
import mesh.Mesh3D;
240+
241+
public class MyQuadCreator implements IMeshCreator {
242+
243+
private float halfSize;
244+
private Mesh3D mesh;
245+
246+
public Mesh3D create() {
247+
initializeMesh();
248+
createVertices();
249+
createFaces();
250+
return mesh;
251+
}
252+
253+
private void initializeMesh() {
254+
mesh = new Mesh3D();
255+
}
256+
257+
private void createVertices() {
258+
addVertex(halfSize, 0, -halfSize);
259+
addVertex(halfSize, 0, halfSize);
260+
addVertex(-halfSize, 0, halfSize);
261+
addVertex(-halfSize, 0, -halfSize);
262+
}
263+
264+
private void createFaces() {
265+
addFace(0, 1, 3);
266+
addFace(1, 2, 3);
267+
}
268+
269+
private void addVertex(float x, float y, float z) {
270+
mesh.addVertex(x, y, z);
271+
}
272+
273+
private void addFace(int... indices) {
274+
mesh.add(new Face3D(indices));
275+
}
276+
277+
public void setSize(float size) {
278+
halfSize = size / 2.0f;
279+
}
280+
281+
public float getSize() {
282+
return halfSize * 2;
283+
}
284+
285+
}
286+
```
287+
288+
Now we can use our creator the following way:
289+
290+
```java
291+
Mesh3D mesh;
292+
MyQuadCreator creator = new MyQuadCreator();
293+
creator.setSize(4);
294+
mesh = creator.create();
295+
```
296+
297+
This explains the overall concept of mesh creators pretty well. You should now have an idea how to use existing creators and implement your own custom ones.
298+
See also: [Mesh Creators](documentation/documentation.md)
299+
300+
## Planed features
301+
302+
- Convex Hull
303+
- Poisson-Disc Sampling
304+
- Marching Cubes
305+
306+
## Licence
307+
308+
[MIT](https://github.com/ArtifactForms/MeshLibCore/blob/master/LICENSE) License Copyright (c) 2022 Simon Dietz
309+

0 commit comments

Comments
 (0)