|

Real-Time Color and Texture Configurator on 3D Models Using Three.js

Real-Time Color and Texture Configurator on 3D Models Using Three.js

Imagine customizing the color of a car, changing furniture finishes, or applying different wall textures to a building—all while viewing the results instantly on an interactive 3D model.

Real-time color and texture configuration makes this possible. Instead of relying on static product images or multiple design samples, users can explore different materials, colors, and finishes directly within a 3D environment.

For developers building interactive 3D web applications, Three.js provides the tools needed to implement object selection, material customization, and real-time visualization directly in a web browser.

At ProtoTech Solutions, we developed a demonstration of a real-time color and texture configurator using Three.js. The application allows users to select individual elements of a 3D model and modify their appearance through an interactive interface.

In this article, we will explore the technical concepts behind the configurator, including how raycasting works, how different model elements are selected, and how colors and textures are applied dynamically.

What Is a Real-Time Color and Texture Configurator?

A real-time color and texture configurator is an interactive 3D application that allows users to modify the visual appearance of a product or model and immediately view the changes.

For example, a user can select a wall in a 3D building model and apply different paint colors, wallpapers, or surface finishes. Similarly, a furniture configurator can offer different fabric patterns, wood textures, and material options.

Depending on the application, users can:

  • Select individual components of a 3D model.
  • Change colors through an interactive color picker.
  • Apply predefined textures and material finishes.
  • Customize multiple components independently.
  • Rotate, zoom, and inspect the configured model.
  • Compare design alternatives before making a decision.

These capabilities are particularly useful for product visualization, architectural design, furniture customization, automotive applications, and online product catalogs.

How Does a Color and Texture Configurator Work in Three.js?

A Three.js-based configurator combines 3D rendering, object selection, and dynamic material updates.

The basic workflow involves four steps:

  1. Load the 3D model: Display the model in a Three.js scene with the appropriate camera, lighting, and materials.
  2. Identify the selected object: Use raycasting to determine which part of the model the user clicks.
  3. Apply the selected configuration: Update the color, texture, or material properties of the selected component.
  4. Render the result: Display the updated model so users can immediately inspect the change.

The complexity depends on how the 3D model is organized and which components can be customized independently.

Let’s examine the implementation in more detail.

1. Selecting Objects in Three.js Using Raycasting

Before changing the appearance of a 3D object, the application must determine which object the user wants to modify.

One of the most common techniques for interactive object selection in Three.js is raycasting.

Raycasting identifies objects intersected by an imaginary ray projected from the camera through a selected point on the screen.

Three.js provides the THREE.Raycaster class to perform this operation.

Step 1: Calculate the Mouse Position

When a user clicks inside the 3D viewer, the application captures the pointer coordinates.

These coordinates must be converted into normalized device coordinates (NDC), where both the X and Y values range from -1 to +1.

When the viewer is embedded inside a specific HTML container, its actual position and dimensions must be considered. Otherwise, object selection can become inaccurate.

const rect = renderer.domElement.getBoundingClientRect();

const mouse = new THREE.Vector2();

mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;

This calculation ensures that the pointer position corresponds correctly to the 3D rendering area, even when the viewer is resized or placed inside a larger webpage.

Step 2: Create a Ray from the Camera

After calculating the pointer position, the next step is to create a ray from the camera through that position.

const raycaster = new THREE.Raycaster();

raycaster.setFromCamera(mouse, camera);

The setFromCamera() method uses the normalized pointer coordinates and the active camera to establish the ray.

Step 3: Identify Intersecting Objects

Once the ray is available, Three.js can determine which objects intersect it.

const intersects = raycaster.intersectObjects(
    model.children,
    true
);

if (intersects.length > 0) {
    const selectedObject = intersects[0].object;
}

The returned intersections are ordered by distance, so the first intersection generally identifies the closest intersected surface.

The recursive parameter allows the raycaster to inspect nested objects within the model hierarchy.

This technique forms the foundation of interactive selection in many 3D configurators, CAD viewers, and web-based visualization applications.

2. Selecting Model Elements at Different Levels

Not every customization requires selecting an entire 3D object.

For example, a user may want to change the color of a single furniture component, apply a texture to one wall surface, or customize a complete group of related components.

In our Three.js configurator demonstration, we explored three selection levels:

  • Mesh-level selection
  • Face-level selection
  • Group-level selection

Each selection mode provides a different level of control over the 3D model.

A. Mesh-Level Selection

Mesh-level selection allows users to select an individual mesh from the loaded 3D model.

A mesh represents geometry rendered with one or more materials. It can correspond to an individual product component, architectural element, or mechanical part.

For example, a furniture model may contain separate meshes for the seat, backrest, legs, and armrests.

Using raycasting, the application identifies the intersected mesh and highlights it to indicate selection.

const selectedMesh = intersects[0].object;

if (selectedMesh.isMesh) {
    // Highlight or customize the selected mesh
}

Once selected, the mesh can receive a new material color or texture.

Practical application: Allowing customers to choose different colors for individual cabinet doors, furniture components, or automotive parts.

B. Face-Level Selection

Face-level selection provides more detailed control by identifying the specific triangle of a mesh that the user clicks.

Unlike mesh selection, which targets the entire mesh, face-level interaction can identify a particular part of its geometry.

Three.js raycasting provides the faceIndex property, which identifies the intersected triangle.

const intersection = intersects[0];

const selectedMesh = intersection.object;
const selectedFaceIndex = intersection.faceIndex;

However, identifying a face and independently changing its material are two different operations.

In modern Three.js applications using BufferGeometry, individual surface customization may require additional geometry processing, material groups, vertex colors, or texture-based techniques.

For example, if a wall is represented as a single mesh, changing only one portion of that wall may require separating the relevant geometry or assigning dedicated material regions.

Practical application: Applying different finishes to selected surfaces of architectural models or customizing specific regions of a product.

C. Group-Level Selection

Complex 3D models frequently contain multiple meshes organized under parent groups.

Three.js provides THREE.Group to organize related objects within a scene.

For example, a complete kitchen cabinet assembly may contain individual meshes for doors, handles, panels, and shelves.

Instead of customizing every mesh individually, users may want to select the entire cabinet assembly.

To achieve this, the application can traverse the selected mesh’s parent hierarchy and identify the relevant group.

let selectedGroup = selectedMesh.parent;

while (
    selectedGroup &&
    !selectedGroup.isGroup
) {
    selectedGroup = selectedGroup.parent;
}

Once the appropriate group is identified, the application can traverse its descendant meshes and apply the selected material changes.

For complex models, meaningful group names or metadata help distinguish individual product assemblies from general scene containers.

Practical application: Applying a common finish to an entire furniture assembly, modular product component, or architectural section.

Multiple Object Selection

Our configurator demonstration also supports selecting multiple model elements using Ctrl + Click.

This interaction allows users to choose multiple components and apply a common color or texture without repeating the same operation individually.

For example, users could select several wall panels and apply the same finish to all of them.

In a complete application, the selection logic should also handle deselection, visual highlighting, and restoration of the original appearance when necessary.

3. Applying Colors to Selected 3D Objects

Once the desired model component has been selected, users can modify its appearance through a color picker.

Three.js materials expose color properties that can be updated at runtime.

For example, the following code changes the selected mesh’s material color:

selectedMesh.material.color.set("#2878B5");

If the application allows users to pick a color dynamically, the selected value can be passed directly to the material.

function updateColor(mesh, selectedColor) {
    mesh.material.color.set(selectedColor);
}

The updated color is reflected in the rendered model.

An important implementation detail: If multiple meshes share the same material instance, changing that material’s color may affect all of them.

When independent customization is required, developers should assign separate material instances or clone the shared material before modifying it.

For example:

selectedMesh.material =
    selectedMesh.material.clone();

selectedMesh.material.color.set("#2878B5");

This approach assumes a mesh with a single material and should be adapted for meshes with multiple materials.

For ordinary material color changes, manually setting material.needsUpdate = true is generally unnecessary. That flag is primarily needed for changes that affect material shader configuration.

4. Applying Textures to Selected 3D Objects

Colors are useful for basic customization, but many products require detailed surface finishes.

A texture can represent wood grain, marble, wallpaper, fabric patterns, metal finishes, or other visual details.

Three.js provides the TextureLoader class to load image-based textures and apply them to 3D materials.

Step 1: Load the Texture

const textureLoader = new THREE.TextureLoader();

const texture = textureLoader.load(
    "textures/wood-finish.jpg"
);

texture.colorSpace = THREE.SRGBColorSpace;

Using the appropriate color space helps display color textures correctly.

Step 2: Apply the Texture to the Selected Mesh

Once loaded, the texture can be assigned to the material’s map property.

selectedMesh.material.map = texture;

selectedMesh.material.needsUpdate = true;

Setting needsUpdate is relevant when enabling texture mapping on a material that previously had no map.

The renderer then uses the texture to determine the surface appearance.

Step 3: Adjust Texture Mapping

The appearance of a texture depends on the model’s UV coordinates, which determine how a 2D image is mapped onto a 3D surface.

For applications such as wall coverings, flooring, and furniture finishes, developers may need to control texture repetition, rotation, and alignment.

For example:

texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;

texture.repeat.set(2, 2);

This repeats the texture across the corresponding UV range rather than stretching it once over the entire surface.

Proper UV mapping is essential for achieving consistent and visually accurate results.

For product configurators that require realistic materials, texture mapping can be combined with physically based rendering (PBR) materials, including roughness, metalness, and normal maps.

5. Real-Time Visualization and User Interaction

A major advantage of using Three.js is that users can explore material changes within an interactive 3D environment.

After selecting a color or texture, users can rotate the model, zoom into specific components, and inspect how different finishes appear under the scene’s lighting conditions.

For example, a customer configuring a cabinet may want to examine how a wood finish looks on the doors, side panels, and shelves before finalizing the design.

To make this experience practical, developers should consider several factors:

Model organization: Separate customizable components into meaningful meshes or groups.

Material management: Prevent unintended changes to components that share material instances.

Visual feedback: Clearly highlight selected objects without permanently changing their original materials.

Performance: Optimize model geometry, textures, and rendering operations to maintain smooth interaction.

Usability: Provide intuitive selection controls, predefined finish options, and ways to reset or compare configurations.

These considerations become increasingly important when moving from a technical demonstration to a production-ready 3D application.

From a Material Configurator to a Complete 3D Product Configurator

A color and texture configurator focuses primarily on a model’s visual appearance.

However, the same technical foundation can be extended into a complete 3D product configuration application.

Depending on business requirements, additional capabilities may include:

  • Parametric configuration: Adjust product dimensions and geometry.
  • Component customization: Add, remove, or replace product components.
  • Configuration rules: Prevent incompatible or invalid combinations.
  • Dynamic pricing: Calculate prices based on selected product options.
  • Bill of materials: Generate component information for configured products.
  • Business system integration: Connect the configurator with eCommerce platforms, ERP systems, or quotation applications.

For engineering and manufacturing businesses, these capabilities can connect customer preferences with product specifications and downstream workflows.

The key is to build the configurator around the actual product structure and configuration requirements rather than treating visualization as a standalone feature.

Conclusion

Building a real-time color and texture configurator with Three.js demonstrates how interactive 3D technologies can transform the way users explore and customize products.

By combining raycasting, mesh and group selection, dynamic material updates, and texture mapping, developers can create applications that make product visualization more interactive and intuitive.

While these features can begin as a relatively simple Three.js demonstration, the same concepts can support advanced product configurators for architecture, furniture, automotive, manufacturing, and eCommerce applications.

The most effective implementations combine accurate 3D visualization with well-organized model data, reliable configuration logic, and a straightforward user experience.

At ProtoTech Solutions, we specialize in developing custom 3D visualization applications and interactive product configurators using Three.js and other advanced 3D technologies.

Whether you need a custom Three.js application or a ready-to-integrate 3D product configurator, we can help turn your requirements into a practical, scalable solution.

Ready to bring your products to life in 3D?

Explore our Three.js Development Services and 3D Product Configurator Development Services, or contact our team to discuss your project requirements.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *