-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
140 lines (114 loc) · 2.64 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
let angle = 45
let texturesMap
let objectsMap
let lightingMap
let gameStart = true
let cam1
function preload() {
objectsMap = ModelLoader().objectsMap
texturesMap = ModelLoader().texturesMap
lightingMap = ModelLoader().lightingMap
}
function setup() {
window.canvas = createCanvas(windowWidth, windowHeight, WEBGL)
cam1 = createCamera()
}
function loadRoom() {
let room = {
w: 500,
h: 500,
leftTransparent: false,
rightTransparent: false,
frontTransparent: true,
backTransparent: false,
wallHeight: 250,
center: 250,
}
// frustum(); what the hell was this for?
// Draw a floor
push()
translate(0, 120, 0)
rotateX(PI / 2)
texture(texturesMap["wood"])
plane(room.w, room.h)
pop()
push ()
translate(0, 120, 0)
texture(texturesMap["wood"])
let c = color(255, 0, 0);
directionalLight(c, 0, 1, 0);
// last parameter, position sets the light’s position using a p5.Vector object. For example, pointLight(255, 0, 0, lightPos)
cylinder(1000, 1);
pop()
// Draw a ceiling
push()
translate(0, -115, 0)
rotateX(PI / 2)
texture(texturesMap["wood"])
plane(room.w, room.h)
pop()
// Draw the walls
//RIGHT
push()
fill(150)
translate(room.w + -room.center, 0, 0)
rotateY(PI / 2)
texture(texturesMap["brick"])
plane(room.w, room.wallHeight)
pop()
//LEFT
push()
translate(-room.w + room.center, 0, 0)
rotateY(PI / 2)
texture(texturesMap["brick"])
plane(room.w, room.wallHeight) // Left wall
pop()
//Back
push()
translate(0, 0, - room.center)
rotateY(PI)
texture(texturesMap["brick"])
plane(room.w, room.wallHeight) // Left wall
pop()
// Front facing player
push()
if( room.frontTransparent ) blendMode('exclusion')
translate(0, 0, + room.center)
rotateY(PI)
texture(texturesMap["brick"])
plane(room.w, room.wallHeight) // Left wall
pop()
}
function loadObjects() {
if (window.targetobjects) {
const {coordinates, rotation, scale: scale_, textures, id} = window.targetobjects
const convertRotation = (r) => devTools().degrees_to_radians(r)
push()
translate(coordinates[0],coordinates[1], coordinates[2])
rotateX(convertRotation(rotation[0]))
rotateY(convertRotation(rotation[1]))
rotateZ(convertRotation(rotation[2]))
scale(scale_)
texture(texturesMap[textures])
model(objectsMap[id])
pop()
}
}
function loadGlobalLights() {
if (window.targetlighting) {
const {type, color: colors_, } = window.targetlighting
if(type === "ambient") {
ambientLight(colors_[0], colors_[1], colors_[2], 1);
specularMaterial(250);
}
}
}
function draw() {
background(0)
noStroke();
loadGlobalLights();
loadRoom();
// blendMode(EXCLUSION); for making glass
loadObjects();
firstPerson(cam1)
}