Urgent.News

What's breaking now, across thousands of outlets.

Tech

Making three.js bricks look like real LEGO: studio light, hollow undersides and a real wooden table

The first 3D viewer on Mister Blocks drew bricks as coloured boxes with little cylinders on top. It was technically correct and looked like a spreadsheet. Kids building from instructions need to recognise the piece in their hand, so I spent a surprising amount of time making three.js bricks look like real plastic. Here's what made the difference, roughly from biggest to smallest. Tesla…

To create realistic LEGO bricks using three.js, a studio-like lighting setup is essential. This involves using an environment map of a soft grey room with a softbox overhead and side strip lights. The reflection of this light on the ABS plastic bricks results in a gentle sheen on the tops and highlights along every edge. Additionally, color space is crucial; colors must be picked in sRGB, converted to linear for rendering, and then converted back to sRGB when displayed.

Failure to follow these steps can lead to muddy colors. Another important aspect is placing the model on a real table, preferably made of wood. This ground makes the image appear more tangible as opposed to a model floating in a blue void. The table is a top-down photo of the actual wooden table, scaled to fit 1,125 pixels equaling 34 studs (27 cm), and mirrored to eliminate seams.

A dark patch under the model grounds it, while the sun's shadow is tightly fitted around the model for a sharp shadow at the point of contact and a soft shadow further out. The model's underside is drawn to look like real LEGO geometry, with hollow tubes and pins for certain sizes. This feature distinguishes bricks from stacks of plates or tiles.

Geometry is optimized by sharing the same geometry for pieces of the same size and computing outlines only once per size. Covered studs are only drawn when necessary, and each piece has its own mesh. When a piece is in the process of being added, it is not drawn until its corresponding step. This optimization ensures smooth performance even for models with over 1,300 pieces.

Furthermore, small details such as instant piece drops, instant slider adjustments, and smooth animations contribute to a realistic and enjoyable user experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Pact vs Prism: Which Contract Mocking Tool Fits?

Quick answer: Pact and Prism are both used around contracts and mocks, but they start from opposite ends. Pact is consumer-driven: the consumer records the interactions it expects, and those are…

  • Pact is consumer-driven, focusing on expected interactions by a consumer.
  • Prism is spec-driven, using OpenAPI documents to generate mock responses.
  • Choose Pact for consumer interactions as source of truth, Prism for OpenAPI reference.

More from Thursday 12 November →