renderIsoSurface = {
const canvas = isoSurfaceCanvas;
const { app, drawCallSurface, drawCallBall } = isoSurfaceApp;
const arcball = new Arcball(canvas);
const refresh = () => {
app.clear();
const modelview = mat4.mul(
[],
mat4.fromTranslation([], [0, 0, -5]),
arcball.transform
);
const projection = mat4.perspective(
[],
(45 * Math.PI) / 180,
canvas.width / canvas.height,
0.01,
100
);
drawCallSurface
.uniform("modelview", modelview)
.uniform("light_dir", vec3.normalize([], [1, 1, 1]))
.uniform("color", [1.0, 0.0, 0.0, 1.0])
.uniform("scaleFactor", 1.0)
.uniform("projection", projection)
.draw();
data.points.forEach((p, i) => {
drawCallBall
.uniform(
"modelview",
mat4.multiply(
[],
modelview,
mat4.multiply(
[],
mat4.fromTranslation([], p),
mat4.fromScaling([], [0.05, 0.05, 0.05])
)
)
)
.uniform("light_dir", vec3.normalize([], [1, 1, 1]))
.uniform("color", i < 8 ? [0, 0, 1, 1] : [1.0, 1.0, 0.0, 1.0])
.uniform("scaleFactor", 1.0)
.uniform("projection", projection)
.draw();
});
};
canvas.onmousedown = (e) =>
arcball.mousedown(e.offsetX, canvas.height - e.offsetY);
canvas.onmousemove = (e) => {
if (e.buttons) {
arcball.mousemove(e.offsetX, canvas.height - e.offsetY);
refresh();
}
};
canvas.onmouseup = (e) => arcball.mouseup();
refresh();
}