From 7116dba79fc1a3f285d584f7bb9e2b611eea906d Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 25 Mar 2024 21:13:41 +0900 Subject: [PATCH] Fix support for ies textures --- src/core/DynamicPathTracingSceneGenerator.js | 20 ++++++++++++++++++-- src/core/WebGLPathTracer.js | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/DynamicPathTracingSceneGenerator.js b/src/core/DynamicPathTracingSceneGenerator.js index 5c940c9f7..1f50f5147 100644 --- a/src/core/DynamicPathTracingSceneGenerator.js +++ b/src/core/DynamicPathTracingSceneGenerator.js @@ -31,6 +31,7 @@ function getTextures( materials ) { function getLights( objects ) { const lights = []; + const iesSet = new Set(); for ( let i = 0, l = objects.length; i < l; i ++ ) { objects[ i ].traverse( c => { @@ -46,6 +47,12 @@ function getLights( objects ) { lights.push( c ); + if ( c.iesTexture ) { + + iesSet.add( c.iesTexture ); + + } + } } @@ -54,7 +61,15 @@ function getLights( objects ) { } - return lights; + const iesTextures = Array.from( iesSet ).sort( ( a, b ) => { + + if ( a.uuid < b.uuid ) return 1; + if ( a.uuid > b.uuid ) return - 1; + return 0; + + } ); + + return { lights, iesTextures }; } @@ -174,7 +189,7 @@ export class DynamicPathTracingSceneGenerator { const result = staticGeometryGenerator.generate( geometry ); const materials = result.materials; const textures = getTextures( materials ); - const lights = getLights( objects ); + const { lights, iesTextures } = getLights( objects ); if ( result.changeType !== NO_CHANGE ) { @@ -223,6 +238,7 @@ export class DynamicPathTracingSceneGenerator { bvhChanged: result.changeType !== NO_CHANGE, bvh: this.bvh, lights, + iesTextures, geometry, materials, textures, diff --git a/src/core/WebGLPathTracer.js b/src/core/WebGLPathTracer.js index dd855f17a..ecfe14127 100644 --- a/src/core/WebGLPathTracer.js +++ b/src/core/WebGLPathTracer.js @@ -234,6 +234,7 @@ export class WebGLPathTracer { const { lights, + iesTextures, materials, textures, geometry, @@ -248,7 +249,8 @@ export class WebGLPathTracer { const textureSize = this.textureSize; // update scene information - material.lights.updateFrom( lights ); + material.lights.updateFrom( lights, iesTextures ); + material.iesProfiles.updateFrom( renderer, iesTextures ); material.lightCount = lights.length; material.textures.setTextures( renderer, textureSize.x, textureSize.y, textures ); material.materials.updateFrom( materials, textures );