Published
Edited
Sep 29, 2021
1 fork
Importers
6 stars
Also listed in…
CAP 4720 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gl = {
const myCanvas = DOM.canvas(width, 600);

const gl = myCanvas.getContext("webgl2");
gl.enable(gl.DEPTH_TEST);
gl.clearColor(0.3, 0.4, 0.5, 1);
return gl;
}
Insert cell
renderObject = () => {
const uniforms = {
// All the Uniform constants used in Shader program must be set here before making a render call.
materialColor: hex2rgb(materialColor),
light:
lightParameters.lightType == "point"
? [...lightPosition, 1]
: [...lightDirection, 0],
viewMatrix: viewMatrix,
projectionMatrix: perspectiveMatrix
};

gl.useProgram(modelProgramInfo.program);
twgl.setUniforms(modelProgramInfo, uniforms);
bufferInfoArray.forEach((bufferInfo) => {
twgl.setBuffersAndAttributes(gl, modelProgramInfo, bufferInfo);
twgl.drawBufferInfo(gl, bufferInfo, gl.TRIANGLES);
});
}
Insert cell
renderLight = () => {
const uniforms = {
// All the Uniform constants used in Shader program must be set here before making a render call.
viewMatrix: viewMatrix,
projectionMatrix: perspectiveMatrix,
modelMatrix: lightModelMatrix
};
gl.useProgram(lightProgramInfo.program);
twgl.setUniforms(lightProgramInfo, uniforms);

twgl.setBuffersAndAttributes(gl, lightProgramInfo, lightBufferInfo);
twgl.drawBufferInfo(gl, lightBufferInfo, gl.TRIANGLES);
}
Insert cell
md`### Shaders and Programs`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
objectDimensions
Insert cell
md `## Rendered Object`
Insert cell
bufferInfoArray = object
.map((d) => ({
position: { numComponents: 3, data: d.sc.positions },
normal: { numComponents: 3, data: d.sc.normals }
}))
.map((vertexAttributes) =>
twgl.createBufferInfoFromArrays(gl, vertexAttributes)
)
Insert cell
lightBufferInfo = {
const sphereVertices = twgl.primitives.createSphereVertices(1, 10, 10);
return twgl.createBufferInfoFromArrays(gl, sphereVertices);
}
Insert cell
Insert cell
objectDimensions = computeModelExtent(object)
Insert cell
md `## Camera Matrices`
Insert cell
Insert cell
objectDimensions
Insert cell
Insert cell
yRotationMatrix = m4.rotationY(toRadian(viewParameters.yAngle))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more