-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.html
209 lines (189 loc) · 8.79 KB
/
render.html
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>graphics</title>
</head>
<link rel="stylesheet" href="render.css">
<body>
<span style="font-size: 30px;cursor: pointer;position: absolute;z-index: 11;color: #ffffff;" onclick="openNav()">☰ Open Menu</span>
<div>
<canvas id="myCanvas" repetition="no-repeat"></canvas>
</div>
<div id="myNav" class="overlay">
<a class="closebtn" onclick="closeNav()">×</a>
<div class="row">
<div>
<button class="toggleButton" id="controlsButton" data-target="controls">Controls</button>
<button class="toggleButton" id="transformsButton" data-target="transforms">Transforms</button>
<button class="toggleButton" id="rasterizationButton" data-target="rasterization">Rasterization</button>
<button class="toggleButton" id="meshButton" data-target="mesh">Select Mesh</button>
<div id="controls">
<h2>Controls</h2>
<h3>W: Translate Up</h3>
<h3>A: Translate Left</h3>
<h3>S: Translate Down</h3>
<h3>D: Translate Right</h3>
<h3>C: Translate Forward</h3>
<h3>Space: Translate Back</h3>
<h3>E: Rotate Up About Y-Axis</h3>
<h3>F: Rotate Down About Y-Axis</h3>
<h3>R: Rotate Up About X-Axis</h3>
<h3>G: Rotate Down About X-Axis</h3>
<h3>T: Rotate Up About Z-Axis</h3>
<h3>H: Rotate Down About Z-Axis</h3>
<a href="https://github.com/HD787/GraphicsEngineWebsite" target="_blank">checkout the source code</a>
</div>
<div id="transforms" class="hidden">
<h2>Transforms</h2>
<p><a href="docs/matrices.html" target="_blank">Homogeneous Matrices</a></p>
<div id="matrixInput">
<div>
<input type="number" value="1">
<input type="number" value="0">
<input type="number" value="0">
<input type="number" value="0">
</div>
<div>
<input type="number" value="0">
<input type="number" value="1">
<input type="number" value="0">
<input type="number" value="0">
</div>
<div>
<input type="number" value="0">
<input type="number" value="0">
<input type="number" value="1">
<input type="number" value="0">
</div>
<div>
<input type="number" value="0">
<input type="number" value="0">
<input type="number" value="0">
<input type="number" value="1">
</div>
<br>
<button onClick="submitNewMatrix()">Add Transform</button>
</div>
<br>
<div>
<p><a href="docs/explode.html" target="_blank">Explode Model</a></p>
<input type="range" class="slider" min="-2.0" max="2.0" value="0.0" step="0.1" oninput="submitNewExplodeScalar(this.value)">
<span id="explodeScalarValue">0.0</span>
</div>
</div>
<div id="rasterization" class="hidden">
<h2>Rasterization</h2>
<div>
<p><a href="docs/lighting.html" target="_blank">Lighting Vector</a></p>
<input id="x" value="0">
<input id="y" value="0">
<input id="z" value="-1">
<button onClick="submitNewLightVector(
document.getElementById('x').value,
document.getElementById('y').value,
document.getElementById('z').value)">
Update Vector</button>
</div>
<div>
<p><a href="docs/colors.html" target="_blank">RGB Values</a></p>
<input id="r" value="127">
<input id="g" value="127">
<input id="b" value="127">
<button
onClick="submitNewColor(
document.getElementById('r').value,
document.getElementById('g').value,
document.getElementById('b').value)">
Change Color</button>
</div>
<br>
<div><button id="renderWireFrame" onClick="changeRenderMode()">Disable Polygon Filling</button></div>
<br>
<div><button id="renderRandomColors" onClick="randomizeColors()">Randomize All Colors</button></div>
</div>
<div id="mesh" class="hidden">
<h2>Select Mesh</h2>
<br>
<div><button id="loadForest"> load Forest </button></div>
<br>
<div><button id="loadCube"> load Cube </button></div>
<br>
</div>
</div>
</div>
<script src="WASM_forestDemo.js"></script>
<script src="globalFuncs.js"></script>
<script>
var wcPtr, ctx, imageData;
var initialize, renderPass, getFrameBuffer, initializeFromObj, deleteWebContext;
var keyStates = {};
var renderMode = 0;
const canvas = document.getElementById('myCanvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
Module.onRuntimeInitialized = () => {
initialize = Module._initialize;
initializeUtahTeapot = Module._initializeUtahTeapot;
initializeFromObj = Module._initializeFromObj;
renderPass = Module._renderPass;
getFrameBuffer = Module._getFrameBuffer;
deleteWebContext = Module._deleteWebContext;
renderPassWireFrame = Module._renderPassWireFrame;
updateExplodeScalar = Module._updateExplodeScalar;
updateColorBuffer = Module._updateColorBuffer;
updateLightVector = Module._updateLightVector;
addMatrixValue = Module._addMatrixValue;
addMatrixSlot = Module._addMatrixSlot;
randomizeColorBuffer = Module._randomizeColorBuffer;
//const misc = Module._misc;
wcPtr = initializeFromObj(canvas.width, canvas.height);
const pixelDataPtr = getFrameBuffer(wcPtr);
const pixelData = new Uint8ClampedArray(Module.HEAPU8.buffer, pixelDataPtr, canvas.width * canvas.height * 4);
ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
imageData = new ImageData(pixelData, canvas.width, canvas.height);
render();
};
window.onerror = function (message, source, lineno, colno, error) {
console.error("Error occurred:", message);
setTimeout(function() {
window.location.reload();
}, 2000);
};
window.addEventListener('keydown', (event) => {
keyStates[event.code] = true;
transform();
});
window.addEventListener('keyup', (event) => {
keyStates[event.code] = false;
});
document.getElementById('loadForest').addEventListener('click', function() {
event.target.blur()
deleteWebContext(wcPtr);
wcPtr = initializeFromObj(canvas.width, canvas.height);
const pixelDataPtr = getFrameBuffer(wcPtr);
const pixelData = new Uint8ClampedArray(Module.HEAPU8.buffer, pixelDataPtr, canvas.width * canvas.height * 4);
render()
});
document.getElementById('loadCube').addEventListener('click', function() {
event.target.blur()
deleteWebContext(wcPtr);
wcPtr = initialize(canvas.width, canvas.height);
const pixelDataPtr = getFrameBuffer(wcPtr);
const pixelData = new Uint8ClampedArray(Module.HEAPU8.buffer, pixelDataPtr, canvas.width * canvas.height * 4);
render();
});
document.querySelectorAll('.toggleButton').forEach(button => {
button.addEventListener('click', changeMenus);
});
function openNav() {
document.getElementById("myNav").style.width = "40%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</body>
</html>