I’m building a CAD / engineering-style viewer in Three.js with hundreds of meshes and a fixed set of visualization modes:
- Shaded
- Wireframe
- Hidden Line
- Silhouette / Outline
- Translucent
- Line / Centerline
Current approach (hybrid)
We currently use a mix of two techniques:
1. Pre-created geometry + layers
For example, for Line / Centerline mode, I create the line representation at the time the mesh is created, assign it to a separate layer, and simply toggle visibility by switching the camera layer.
2. Scene traversal + material modification
For other modes (e.g. Translucent), I traverse the scene and modify materials, with reset / restore logic on every mode switch.
Example:
public applyTranslucent(alpha: number = 0.2): void {
this.resetToClean();
this.forEachMesh((mesh) => {
this.modifyMaterials(mesh, (mat) => {
mat.transparent = true;
mat.opacity = alpha;
});
});
}
This works, but adds material state management, traversal cost, and complexity as the number of modes grows.
Proposed approach
We’re considering moving to a pure layer-based approach:
- Pre-create required representations once when geometry is created
- Assign each representation to its own layer
- Switch visualization modes by switching camera layers
- Keep silhouette / outline as a post-processing effect only
This means multiple representations exist in the scene, but only one layer is rendered at a time.
Questions
- Is a layer-based / precomputed representation approach recommended for this type of use case?
- From a scalability and performance perspective, is it generally better to:
- pay an upfront memory cost, or
- traverse the scene and mutate materials on each mode switch?
- Are there any known pitfalls with layers when working with large scenes (hundreds or thousands of meshes)?