Skip to content

Commit e9c15b9

Browse files
committed
Updates
1 parent 5fc7b55 commit e9c15b9

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

example/materialDatabase.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
AgXToneMapping,
3-
Box3,
43
Scene,
54
Vector3,
65
WebGLRenderer,
@@ -14,9 +13,9 @@ import { MaterialOrbSceneLoader } from './utils/MaterialOrbLoader.js';
1413
import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js';
1514

1615
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';
1817

19-
let pathTracer, renderer, controls, shellMaterial;
18+
let pathTracer, renderer, controls, material;
2019
let camera, database, scene;
2120
let 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

122124
function 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

172180
function 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
}

example/utils/MaterialOrbLoader.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MeshPhysicalMaterial, MeshStandardMaterial, RectAreaLight } from 'three';
1+
import { MeshPhysicalMaterial, RectAreaLight, SRGBColorSpace } from 'three';
22
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
33

44
// TODO: this scene should technically be rendered at a 1000x smaller scale
@@ -50,23 +50,18 @@ export class MaterialOrbSceneLoader {
5050
camera.fov *= 2.0;
5151
camera.updateProjectionMatrix();
5252

53-
// TODO: if we don't set these we seem to have some kind of race condition causing
54-
// emission on the object core
53+
// some objects in the scene use 16 bit float vertex colors so we disable them here
5554
scene.traverse( c => {
5655

5756
if ( c.material ) {
5857

59-
c.material.emissive.set( 0, 0, 0 );
60-
c.material.emissiveIntensity = 0;
58+
c.material.vertexColors = false;
6159

6260
}
6361

64-
if ( c.material ) {
62+
if ( c.name === 'sss_bars' ) {
6563

66-
const newMat = new MeshStandardMaterial();
67-
newMat.color.copy( c.material.color );
68-
newMat.map = c.material.map;
69-
c.material = newMat;
64+
c.material.color.setRGB( 0.18, 0.18, 0.18, SRGBColorSpace );
7065

7166
}
7267

0 commit comments

Comments
 (0)