11import {
22 AgXToneMapping ,
3- Box3 ,
43 Scene ,
54 Vector3 ,
65 WebGLRenderer ,
@@ -14,9 +13,9 @@ import { MaterialOrbSceneLoader } from './utils/MaterialOrbLoader.js';
1413import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js' ;
1514
1615const DB_URL = 'https://api.physicallybased.info/materials' ;
17- const CREDITS = 'Materials courtesy of "physicallybased.info"' ;
16+ const CREDITS = 'Materials courtesy of "physicallybased.info"</br>Material sphere courtesy of USD Working Group ' ;
1817
19- let pathTracer , renderer , controls , shellMaterial ;
18+ let pathTracer , renderer , controls , material ;
2019let camera , database , scene ;
2120let loader , imgEl ;
2221
@@ -65,15 +64,18 @@ async function init() {
6564 // scene initialization
6665 scene . add ( orb . scene ) ;
6766 camera = orb . camera ;
68- shellMaterial = orb . material ;
67+ material = orb . material ;
6968
69+ // move camera to the scene
7070 scene . attach ( camera ) ;
7171 camera . removeFromParent ( ) ;
72- camera . updateMatrixWorld ( ) ;
7372
74- const fwd = new Vector3 ( 0 , 0 , - 1 ) . transformDirection ( camera . matrixWorld ) . normalize ( ) ;
73+ // controls
7574 controls = new OrbitControls ( camera , renderer . domElement ) ;
7675 controls . addEventListener ( 'change' , ( ) => pathTracer . updateCamera ( ) ) ;
76+
77+ // shift target
78+ const fwd = new Vector3 ( 0 , 0 , - 1 ) . transformDirection ( camera . matrixWorld ) . normalize ( ) ;
7779 controls . target . copy ( camera . position ) . addScaledVector ( fwd , 25 ) ;
7880 controls . update ( ) ;
7981
@@ -121,6 +123,7 @@ function onResize() {
121123
122124function applyMaterialInfo ( info , material ) {
123125
126+ // defaults
124127 material . color . set ( 0xffffff ) ;
125128 material . transmission = 0.0 ;
126129 material . attenuationDistance = Infinity ;
@@ -134,6 +137,7 @@ function applyMaterialInfo( info, material ) {
134137 material . iridescenceIOR = 1.0 ;
135138 material . iridescenceThicknessRange = [ 0 , 0 ] ;
136139
140+ // apply database values
137141 if ( info . specularColor ) material . specularColor . setRGB ( ...info . specularColor ) ;
138142 if ( 'metalness' in info ) material . metalness = info . metalness ;
139143 if ( 'roughness' in info ) material . roughness = info . roughness ;
@@ -161,7 +165,11 @@ function applyMaterialInfo( info, material ) {
161165
162166 } else {
163167
164- if ( info . color ) material . color . setRGB ( ...info . color ) ;
168+ if ( info . color ) {
169+
170+ material . color . setRGB ( ...info . color ) ;
171+
172+ }
165173
166174 }
167175
@@ -171,7 +179,7 @@ function applyMaterialInfo( info, material ) {
171179
172180function onParamsChange ( ) {
173181
174- applyMaterialInfo ( database [ params . material ] , shellMaterial ) ;
182+ applyMaterialInfo ( database [ params . material ] , material ) ;
175183
176184 pathTracer . multipleImportanceSampling = params . multipleImportanceSampling ;
177185 pathTracer . renderScale = params . renderScale ;
@@ -184,7 +192,6 @@ function animate() {
184192
185193 requestAnimationFrame ( animate ) ;
186194 pathTracer . renderSample ( ) ;
187- // renderer.render( scene, camera );
188195 loader . setSamples ( pathTracer . samples , pathTracer . isCompiling ) ;
189196
190197}
0 commit comments