An introduction to 3d graphics on the web
.my-cool-design {
background: red;
border: 1px solid black;
color: white;
}<div class="my-cool-design">
Hello World
</div><svg width="391" height="391" viewBox="-70.5 -70.5 391 391">
<rect fill="#fff" stroke="#000" x="-70" y="-70" width="390" height="390"/>
<g opacity="0.8">
<rect x="25" y="25" width="200" height="200" fill="lime"
stroke-width="4" stroke="pink" />
<circle cx="125" cy="125" r="75" fill="orange" />
<polyline points="50,150 50,200 200,200 200,100" stroke="red"
stroke-width="4" fill="none" />
<line x1="50" y1="50" x2="200" y2="200" stroke="blue" stroke-width="4" />
</g>
</svg>const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.arc(75, 75, 50, 0, Math.PI * 2, true); // Outer circle
ctx.moveTo(110, 75);
ctx.arc(75, 75, 35, 0, Math.PI, false); // Mouth (clockwise)
ctx.moveTo(65, 65);
ctx.arc(60, 65, 5, 0, Math.PI * 2, true); // Left eye
ctx.moveTo(95, 65);
ctx.arc(90, 65, 5, 0, Math.PI * 2, true); // Right eye
ctx.stroke();
class CheckerboardPainter {
paint(ctx, geom, properties) {
const colors = ['red', 'green', 'blue'];
const size = 32;
for(let y = 0; y < geom.height/size; y++) {
for(let x = 0; x < geom.width/size; x++) {
const color = colors[(x + y) % colors.length];
ctx.beginPath();
ctx.fillStyle = color;
ctx.rect(x * size, y * size, size, size);
ctx.fill();
}
}
}
}
registerPaint('checkerboard', CheckerboardPainter)<style>
textarea {
background-image: paint(checkerboard);
}
</style>
<textarea></textarea>
<script>
CSS.paintWorklet.addModule('checkerboard.js');
</script>
This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space.
Scenes allow you to set up what and where is to be rendered by three.js. This is where you place objects, lights and cameras.
Class representing triangular polygon mesh-based objects and composed of two concepts:
Like in our real world, our virtual universe needs lighting for us to observe its component elements.
Thus, lighting is an important actor in our application. Without light, it would usually be impossible to view 3D objects in a scene.
There exists a large, diverse range of light classes
The Camera is an indispensable element of all Three.JS applications. We use this special object from the scene to define the position and observational angle of the point of view.
A camera that uses perspective projection.
This projection mode is designed to mimic the way the human eye sees. It is the most common projection mode used for rendering a 3D scene.
Represents the 3D engine that will be used to generate the 3D rendering in our Scene, from the point of view of a Camera.
There are several types of Renderer, Most used one is the WebGLRenderer
Demos