summaryrefslogtreecommitdiff
path: root/public/gl/model
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-01-19 14:32:58 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-01-19 14:32:58 -0500
commitf70007d58b8c135b7ea79a273b6772a37a541e11 (patch)
tree6379b9c7c9224d8f7f0c1ddc560f653791dd9750 /public/gl/model
parentcube working (diff)
downloadwebgl-f70007d58b8c135b7ea79a273b6772a37a541e11.tar.gz
webgl-f70007d58b8c135b7ea79a273b6772a37a541e11.tar.bz2
webgl-f70007d58b8c135b7ea79a273b6772a37a541e11.zip
changes
Diffstat (limited to 'public/gl/model')
-rw-r--r--public/gl/model/Cube.js117
1 files changed, 57 insertions, 60 deletions
diff --git a/public/gl/model/Cube.js b/public/gl/model/Cube.js
index 824984b..8583afb 100644
--- a/public/gl/model/Cube.js
+++ b/public/gl/model/Cube.js
@@ -1,68 +1,65 @@
import { Mesh } from '../core/Mesh.js'
-export class Cube {
+export const Cube = () => {
- constructor() {
+ const data = [
+ -1.0, 1.0, -1.0, 0.5, 0.5, 0.5,
+ -1.0, 1.0, 1.0, 0.5, 0.5, 0.5,
+ 1.0, 1.0, 1.0, 0.5, 0.5, 0.5,
+ 1.0, 1.0, -1.0, 0.5, 0.5, 0.5,
+ -1.0, 1.0, 1.0, 0.75, 0.25, 0.5,
+ -1.0, -1.0, 1.0, 0.75, 0.25, 0.5,
+ -1.0, -1.0, -1.0, 0.75, 0.25, 0.5,
+ -1.0, 1.0, -1.0, 0.75, 0.25, 0.5,
+ 1.0, 1.0, 1.0, 0.25, 0.25, 0.75,
+ 1.0, -1.0, 1.0, 0.25, 0.25, 0.75,
+ 1.0, -1.0, -1.0, 0.25, 0.25, 0.75,
+ 1.0, 1.0, -1.0, 0.25, 0.25, 0.75,
+ 1.0, 1.0, 1.0, 1.0, 0.0, 0.15,
+ 1.0, -1.0, 1.0, 1.0, 0.0, 0.15,
+ -1.0, -1.0, 1.0, 1.0, 0.0, 0.15,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, 1.0, 0.5, 0.5, 1.0,
- 1.0, -1.0, -1.0, 0.5, 0.5, 1.0,
- ];
-
- this.indicies = [
- 0, 1, 2,
- 0, 2, 3,
- 5, 4, 6,
- 6, 4, 7,
- 8, 9, 10,
- 8, 10, 11,
- 13, 12, 14,
- 15, 14, 12,
- 16, 17, 18,
- 16, 18, 19,
- 21, 20, 22,
- 22, 20, 23
- ];
-
- this.verticies = []
- this.colors = []
- for (let x = 0; x < this.indicies.length; x++) {
- var i = this.indicies[x]
- this.verticies.push(this.data[i * 6 + 2])
- this.verticies.push(this.data[i * 6 + 1])
- this.verticies.push(this.data[i * 6 + 0])
- this.colors.push(this.data[i * 6 + 3])
- this.colors.push(this.data[i * 6 + 4])
- this.colors.push(this.data[i * 6 + 5])
- }
-
- this.mesh = new Mesh(this.indicies.length)
- .store(this.verticies, 3)
- .store(this.colors, 3)
- .finish()
+ const indicies = [
+ 0, 1, 2,
+ 0, 2, 3,
+ 5, 4, 6,
+ 6, 4, 7,
+ 8, 9, 10,
+ 8, 10, 11,
+ 13, 12, 14,
+ 15, 14, 12,
+ 16, 17, 18,
+ 16, 18, 19,
+ 21, 20, 22,
+ 22, 20, 23
+ ];
+ const verticies = []
+ const colors = []
+
+ for (let x = 0; x < indicies.length; x++) {
+ var i = indicies[x]
+ verticies.push(data[i * 6 + 2])
+ verticies.push(data[i * 6 + 1])
+ verticies.push(data[i * 6 + 0])
+ colors.push(data[i * 6 + 3])
+ colors.push(data[i * 6 + 4])
+ colors.push(data[i * 6 + 5])
}
+ return new Mesh(indicies.length)
+ .store(verticies, 3)
+ .store(colors, 3)
+ .finish()
+
} \ No newline at end of file