Skip to content

Commit 281b459

Browse files
committed
Wire up 'Show Union Jack Lines' button.
1 parent 4ead383 commit 281b459

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<label for="lightPosZ">Light position Z: </label>
113113
<input id="lightPosZ" type="range" value="-40" min="-200" max="0" step="any"/><br/>
114114
<br/>
115-
<input type="checkbox" id="showLines" name="showLines" />
115+
<input type="checkbox" id="showLines" name="showLines" checked/>
116116
<label for="showLines">Show Union Jack Lines</label><br/>
117117
<input type="checkbox" id="showHeatmap" name="showHeatmap" checked/>
118118
<label for="showHeatmap">Show Heatmap</label><br/>

moody.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ let lastMappedPosition = null
749749
let cumulativeZoomFactor = 1
750750
let zMultiplier = -1
751751
let buffers = null
752+
let showLines = true
752753
let showHeatmap = true
753754
let lightingOn = true
754755

@@ -781,6 +782,7 @@ function initialize3DTableGraphic(moodyReport, tableModelMatrix) {
781782
buffers = getBuffers(gl, moodyReport, zMultiplier)
782783
})
783784

785+
document.getElementById("showLines").addEventListener("change", event => showLines = event.target.checked)
784786
document.getElementById("showHeatmap").addEventListener("change", event => showHeatmap = event.target.checked)
785787
document.getElementById("lightingOn").addEventListener("change", event => lightingOn = event.target.checked)
786788

@@ -895,6 +897,7 @@ function initialize3DTableGraphic(moodyReport, tableModelMatrix) {
895897
lightPos: gl.getUniformLocation(shaderProgram, "lightPos"),
896898
lightPower: gl.getUniformLocation(shaderProgram, "lightPower"),
897899
sampler: gl.getUniformLocation(shaderProgram, "sampler"),
900+
showLines: gl.getUniformLocation(shaderProgram, "showLines"),
898901
showHeatmap: gl.getUniformLocation(shaderProgram, "showHeatmap"),
899902
lightingOn: gl.getUniformLocation(shaderProgram, "lightingOn"),
900903
},
@@ -956,6 +959,7 @@ function drawTableSurface(moodyReport, gl, programInfo, buffers, tableModelMatri
956959
gl.activeTexture(gl.TEXTURE0)
957960
gl.bindTexture(gl.TEXTURE_2D, texture)
958961
gl.uniform1i(programInfo.uniformLocations.sampler, 0)
962+
gl.uniform1i(programInfo.uniformLocations.showLines, showLines)
959963
gl.uniform1i(programInfo.uniformLocations.showHeatmap, showHeatmap)
960964
gl.uniform1i(programInfo.uniformLocations.lightingOn, lightingOn)
961965

@@ -1042,14 +1046,19 @@ const fsSource = `#version 300 es
10421046
uniform vec3 lightPos;
10431047
uniform float lightPower;
10441048
uniform sampler2D sampler;
1049+
uniform bool showLines;
10451050
uniform bool showHeatmap;
10461051
uniform bool lightingOn;
10471052
out vec4 outputColor;
10481053
10491054
void main() {
10501055
if (vVertexType == 0.0) {
10511056
// This vertex belongs to one of the Union jack Moody lines.
1052-
outputColor = color;
1057+
if (showLines) {
1058+
outputColor = color;
1059+
} else {
1060+
discard;
1061+
}
10531062
} else {
10541063
// This vertex belongs to the table mesh.
10551064
vec3 normal = normalize(normalInterp);
@@ -1075,7 +1084,6 @@ const fsSource = `#version 300 es
10751084
// apply gamma correction (assume ambientColor, diffuseColor and specColor
10761085
// have been linearized, i.e. have no gamma correction in them)
10771086
vec3 colorGammaCorrected = pow(colorLinear, vec3(1.0 / screenGamma));
1078-
// Show the table with a granite texture:
10791087
if (!showHeatmap) {
10801088
if (lightingOn) {
10811089
outputColor = texture(sampler, textureCoord) * vec4(colorGammaCorrected, 1.0);
@@ -1084,6 +1092,7 @@ const fsSource = `#version 300 es
10841092
}
10851093
} else {
10861094
if (lightingOn) {
1095+
// No heatmap - show the table with a granite texture.
10871096
outputColor = vec4(color.rgb * colorGammaCorrected, 1.0);
10881097
} else {
10891098
outputColor = color;
@@ -1155,7 +1164,7 @@ function getPositionBuffer(gl, moodyReport, zMultiplier) {
11551164
const numRepeatsX = 1
11561165
const numRepeatsY = numRepeatsX * tableSurfaceRatio
11571166
// Map [minX, maxX] => [0, 1] and [minY, maxY] => [0, 1]
1158-
// (val - A)*(b-a)/(B-A) + a
1167+
// (val - A) * (b - a) / (B - A) + a
11591168
const triangleTextureCoords = triangulation.map((triangle, index) => [
11601169
((triangle.v0.x - maxX) * (numRepeatsX + 1)) / (maxX - minX), ((triangle.v0.y - maxY) * (numRepeatsY + 1)) / (maxY - minY),
11611170
((triangle.v1.x - maxX) * (numRepeatsX + 1)) / (maxX - minX), ((triangle.v1.y - maxY) * (numRepeatsY + 1)) / (maxY - minY),

0 commit comments

Comments
 (0)