Skip to content

Commit

Permalink
Add orb scene
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jul 20, 2024
1 parent 7e7be06 commit f89f5c0
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions example/utils/MaterialOrbLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { RectAreaLight } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

const ORB_SCENE_URL = 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/usd-shader-ball/usd-shaderball-scene.glb';

function assignWatts( light, watts ) {

// https://github.com/will-ca/glTF-Blender-IO/blob/af9e7f06508a95425b05e485fa83681b268bbdfc/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py#L92-L97
const PBR_WATTS_TO_LUMENS = 683;
const area = light.width * light.height;
const lumens = PBR_WATTS_TO_LUMENS * watts;
light.intensity = lumens / ( area * 4 * Math.PI );

}

export class MaterialOrbSceneLoader {

constructor( manager ) {

this.manager = manager;

}

loadAsync( url = ORB_SCENE_URL, ...rest ) {

return new GLTFLoader( this.manager )
.loadAsync( url, ...rest )
.then( gltf => {

const {
scene,
lights,
cameras,
} = gltf;

const leftLight = new RectAreaLight( 0xffffff, 1, 15, 15 );
assignWatts( leftLight, 6327.84 );
scene.getObjectByName( 'light' ).add( leftLight );

for ( let i = 0; i < 4; i ++ ) {

const light = new RectAreaLight( 0xffffff, 1, 24.36, 24.36 );
assignWatts( leftLight, 11185.5 );
scene.getObjectByName( 'light' + i ).add( light );

}

return {

material: scene.getObjectByName( 'material_surface' ).material,
cameras,
lights,
scene,

};

} );

}

}

0 comments on commit f89f5c0

Please sign in to comment.