1
1
import {
2
2
AgXToneMapping ,
3
- Box3 ,
4
3
Scene ,
5
4
Vector3 ,
6
5
WebGLRenderer ,
@@ -14,9 +13,9 @@ import { MaterialOrbSceneLoader } from './utils/MaterialOrbLoader.js';
14
13
import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js' ;
15
14
16
15
const 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 ' ;
18
17
19
- let pathTracer , renderer , controls , shellMaterial ;
18
+ let pathTracer , renderer , controls , material ;
20
19
let camera , database , scene ;
21
20
let loader , imgEl ;
22
21
@@ -65,15 +64,18 @@ async function init() {
65
64
// scene initialization
66
65
scene . add ( orb . scene ) ;
67
66
camera = orb . camera ;
68
- shellMaterial = orb . material ;
67
+ material = orb . material ;
69
68
69
+ // move camera to the scene
70
70
scene . attach ( camera ) ;
71
71
camera . removeFromParent ( ) ;
72
- camera . updateMatrixWorld ( ) ;
73
72
74
- const fwd = new Vector3 ( 0 , 0 , - 1 ) . transformDirection ( camera . matrixWorld ) . normalize ( ) ;
73
+ // controls
75
74
controls = new OrbitControls ( camera , renderer . domElement ) ;
76
75
controls . addEventListener ( 'change' , ( ) => pathTracer . updateCamera ( ) ) ;
76
+
77
+ // shift target
78
+ const fwd = new Vector3 ( 0 , 0 , - 1 ) . transformDirection ( camera . matrixWorld ) . normalize ( ) ;
77
79
controls . target . copy ( camera . position ) . addScaledVector ( fwd , 25 ) ;
78
80
controls . update ( ) ;
79
81
@@ -121,6 +123,7 @@ function onResize() {
121
123
122
124
function applyMaterialInfo ( info , material ) {
123
125
126
+ // defaults
124
127
material . color . set ( 0xffffff ) ;
125
128
material . transmission = 0.0 ;
126
129
material . attenuationDistance = Infinity ;
@@ -134,6 +137,7 @@ function applyMaterialInfo( info, material ) {
134
137
material . iridescenceIOR = 1.0 ;
135
138
material . iridescenceThicknessRange = [ 0 , 0 ] ;
136
139
140
+ // apply database values
137
141
if ( info . specularColor ) material . specularColor . setRGB ( ...info . specularColor ) ;
138
142
if ( 'metalness' in info ) material . metalness = info . metalness ;
139
143
if ( 'roughness' in info ) material . roughness = info . roughness ;
@@ -161,7 +165,11 @@ function applyMaterialInfo( info, material ) {
161
165
162
166
} else {
163
167
164
- if ( info . color ) material . color . setRGB ( ...info . color ) ;
168
+ if ( info . color ) {
169
+
170
+ material . color . setRGB ( ...info . color ) ;
171
+
172
+ }
165
173
166
174
}
167
175
@@ -171,7 +179,7 @@ function applyMaterialInfo( info, material ) {
171
179
172
180
function onParamsChange ( ) {
173
181
174
- applyMaterialInfo ( database [ params . material ] , shellMaterial ) ;
182
+ applyMaterialInfo ( database [ params . material ] , material ) ;
175
183
176
184
pathTracer . multipleImportanceSampling = params . multipleImportanceSampling ;
177
185
pathTracer . renderScale = params . renderScale ;
@@ -184,7 +192,6 @@ function animate() {
184
192
185
193
requestAnimationFrame ( animate ) ;
186
194
pathTracer . renderSample ( ) ;
187
- // renderer.render( scene, camera );
188
195
loader . setSamples ( pathTracer . samples , pathTracer . isCompiling ) ;
189
196
190
197
}
0 commit comments