I have been facing a difficult challenge for some time now, struggling to achieve my goal while unsure if I am on the right path.
The Objective
My current project involves developing a three.js web application that loads JavaScript models and assigns custom materials using three.js. Specifically, I am focusing on creating natural lighting effects (including Global Illumination and Ambient Occlusion) on a house model by dynamically toggling the visibility of objects in different combinations. However, the issue arises when objects are moved independently, causing sticky shadows due to pre-baked lighting and ambient occlusion textures rendered in three.js without any real-time light sources.
The Dilemma
To address this problem, I have alternate texture maps available for various combinations of lighting. My approach involves updating specific faces' textures during runtime to display shadow-free textures when necessary, rather than relying on predefined textures with baked shadows.
Current Strategy
After extensive research, I have identified two key findings:
To update textures dynamically, I must utilize THREE.MeshFaceMaterial with multiple alternative materials and reference their indices later.
Changing individual faces' materials at runtime is not feasible; instead, modifying an entire material affects all connected faces sharing that material index.
I am attempting to implement a solution outlined in this example: (WebGL / Three.js Different materials on one complex object (grid)).
1) Implementation Issues
While I have successfully altered face colors dynamically, changing textures proves problematic. When applying THREE.MeshFaceMaterial to a geometry, the mesh displays random colors instead of the intended texture. Debugging tools can help identify the source of this issue, as checking the DOM structure reveals proper material assignment without errors.
2) Alternative Approaches
If I manage to resolve the texture updating challenges, ensuring seamless transitions between varying textures remains a concern. Will incorporating vertex colors or custom shaders be required to blend textures smoothly? Additionally, exploring solutions like light mapping and texture blending may offer insights, yet they seem unrelated to my immediate needs of dynamic lighting adjustments.
As a novice in game development practices, I seek advice on refining my approach to overcome these obstacles efficiently. How would an experienced game developer tackle this particular challenge?