Skip to content

Commit 1d0c54c

Browse files
authored
Merge pull request #714 from AntonPalmqvist/materialDatabase-v2
Updated materialDatabase to use Physically Based API v2.0
2 parents ce052c1 + 58f398a commit 1d0c54c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

example/materialDatabase.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getScaledSettings } from './utils/getScaledSettings.js';
1212
import { MaterialOrbSceneLoader } from './utils/MaterialOrbSceneLoader.js';
1313
import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js';
1414

15-
const DB_URL = 'https://api.physicallybased.info/materials';
15+
const DB_URL = 'https://api.physicallybased.info/v2/materials';
1616
const CREDITS = 'Materials courtesy of "physicallybased.info"</br>Material orb model courtesy of USD Working Group';
1717

1818
let pathTracer, renderer, controls, material;
@@ -81,7 +81,7 @@ async function init() {
8181

8282
// database set up
8383
database = {};
84-
dbJson.forEach( mat => database[ mat.name ] = mat );
84+
dbJson.data.forEach( mat => database[ mat.name ] = mat );
8585
params.material = Object.keys( database )[ 0 ];
8686

8787
// initialize scene
@@ -138,7 +138,7 @@ function applyMaterialInfo( info, material ) {
138138
material.iridescenceThicknessRange = [ 0, 0 ];
139139

140140
// apply database values
141-
if ( info.specularColor ) material.specularColor.setRGB( ...info.specularColor );
141+
if ( info.specularColor ) material.specularColor.setRGB( ...info.specularColor[ 0 ].color[ 0 ].color );
142142
if ( 'metalness' in info ) material.metalness = info.metalness;
143143
if ( 'roughness' in info ) material.roughness = info.roughness;
144144
if ( 'ior' in info ) material.ior = info.ior;
@@ -147,15 +147,15 @@ function applyMaterialInfo( info, material ) {
147147

148148
material.iridescence = 1.0;
149149
material.iridescenceIOR = info.thinFilmIor;
150-
material.iridescenceThicknessRange = [ info.thinFilmThickness, info.thinFilmThickness ];
150+
material.iridescenceThicknessRange = [ info.thinFilmThickness[ 2 ] ?? info.thinFilmThickness[ 0 ], info.thinFilmThickness[ 2 ] ?? info.thinFilmThickness[ 0 ] ];
151151

152152
}
153153

154154
if ( material.transmission ) {
155155

156156
if ( info.color ) {
157157

158-
material.attenuationColor.setRGB( ...info.color );
158+
material.attenuationColor.setRGB( ...info.color[ 0 ].color );
159159

160160
}
161161

@@ -173,13 +173,13 @@ function applyMaterialInfo( info, material ) {
173173

174174
if ( info.color ) {
175175

176-
material.color.setRGB( ...info.color );
176+
material.color.setRGB( ...info.color[ 0 ].color );
177177

178178
}
179179

180180
}
181181

182-
imgEl.src = info.reference[ 0 ];
182+
imgEl.src = Object.values( info.images[ 1 ] )[ 0 ];
183183

184184
}
185185

0 commit comments

Comments
 (0)