A 3D engine in Scratch works by storing objects as points in 3D space. Each point has x, y, and z coordinates. x controls left and right, y controls up and down, and z controls forward and backward. Scratch cannot render real 3D graphics, so projects use math to simulate them on a 2D screen. A wireframe model is made from points connected by lines. A cube, for example, has 8 corner points and 12 edges. Scratch calculates where each 3D point appears on the 2D screen, then draws lines between connected points using the Pen extension. To rotate objects, the engine changes point coordinates using sine and cosine. Rotate around the Y axis: newX = xcos(a) - zsin(a) newZ = xsin(a) + zcos(a) Rotate around the X axis: newY = ycos(a) - zsin(a) newZ = ysin(a) + zcos(a) Rotate around the Z axis: newX = xcos(a) - ysin(a) newY = xsin(a) + ycos(a) In these equations, “a” is the rotation angle. Changing the angle every frame makes objects spin smoothly. After rotation, points are converted from 3D into 2D screen positions. Perspective makes distant objects look smaller. screenX = x * fov / z screenY = y * fov / z “fov” means field of view. Dividing by z creates depth. Large z values make objects appear farther away, while small z values make objects appear closer. Wireframes only show edges, so engines fill triangles to create solid surfaces. Models are split into triangles because triangles are always flat and easy to calculate. Scratch fills triangles by drawing many horizontal lines between edges using the Pen extension. Without depth sorting, distant surfaces can draw over nearby ones. Many Scratch engines sort triangles by average z value and draw the farthest ones first. This is called the Painter’s Algorithm. Perspective breaks when z is 0 or negative because division by zero causes huge distortions. screenX = x / z If z = 0, the result becomes infinite. To prevent this, engines use a near clipping plane. if z < 1 then hide point For lines and triangles, engines cut shapes at the clipping plane before drawing them. This prevents stretched polygons and broken rendering. Every frame, a Scratch 3D engine loads model points, rotates them, moves them relative to the camera, clips invalid geometry, applies perspective projection, sorts triangles by depth, and finally draws wireframes or filled triangles. Repeating this process many times per second creates smooth 3D motion.