Skip to content

Commit 1c85c95

Browse files
committedSep 28, 2023
Improved USDZLoader example.
1 parent d6c8dd0 commit 1c85c95

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed
 
-1.94 KB
Loading

‎examples/webgl_loader_usdz.html

+29-17
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,58 @@
3434
import * as THREE from 'three';
3535

3636
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
37+
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
3738
import { USDZLoader } from 'three/addons/loaders/USDZLoader.js';
3839

3940
let camera, scene, renderer;
4041

4142
init();
4243
animate();
4344

44-
function init() {
45+
async function init() {
4546

4647
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 );
47-
camera.position.set( 0, 0.75, - 1 );
48+
camera.position.set( 0, 0.75, - 1.5 );
4849

4950
scene = new THREE.Scene();
50-
scene.background = new THREE.Color( 0xeeeeee );
5151

52-
scene.add( new THREE.GridHelper( 2, 4, 0xc1c1c1, 0x8d8d8d ) );
53-
54-
const light = new THREE.DirectionalLight( 0xffffff, 3 );
55-
light.position.set( 1, 1, 1 );
56-
scene.add( light );
57-
58-
const light2 = new THREE.HemisphereLight( 0xffffff, 0xc1c1c1, 3 );
59-
scene.add( light2 );
60-
61-
// renderer
6252
renderer = new THREE.WebGLRenderer( { antialias: true } );
6353
renderer.setPixelRatio( window.devicePixelRatio );
6454
renderer.setSize( window.innerWidth, window.innerHeight );
55+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
56+
renderer.toneMappingExposure = 2.0;
6557
document.body.appendChild( renderer.domElement );
6658

6759
const controls = new OrbitControls( camera, renderer.domElement );
6860
controls.minDistance = 1;
6961
controls.maxDistance = 8;
62+
// controls.target.y = 15;
63+
// controls.update();
64+
65+
const rgbeLoader = new RGBELoader()
66+
.setPath( 'textures/equirectangular/' );
67+
68+
const usdzLoader = new USDZLoader()
69+
.setPath( 'models/usdz/' );
70+
71+
const [ texture, model ] = await Promise.all( [
72+
rgbeLoader.loadAsync( 'venice_sunset_1k.hdr' ),
73+
usdzLoader.loadAsync( 'saeukkang.usdz' ),
74+
] );
75+
76+
// environment
77+
78+
texture.mapping = THREE.EquirectangularReflectionMapping;
7079

71-
const loader = new USDZLoader();
72-
loader.load( 'models/usdz/saeukkang.usdz', function ( usd ) {
80+
scene.background = texture;
81+
scene.backgroundBlurriness = 0.5;
82+
scene.environment = texture;
7383

74-
scene.add( usd );
84+
// model
7585

76-
} );
86+
model.position.y = 0.25;
87+
model.position.z = - 0.25;
88+
scene.add( model );
7789

7890
window.addEventListener( 'resize', onWindowResize );
7991

0 commit comments

Comments
 (0)
Please sign in to comment.