|
34 | 34 | import * as THREE from 'three'; |
35 | 35 |
|
36 | 36 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
| 37 | + import { RGBELoader } from 'three/addons/loaders/RGBELoader.js'; |
37 | 38 | import { USDZLoader } from 'three/addons/loaders/USDZLoader.js'; |
38 | 39 |
|
39 | 40 | let camera, scene, renderer; |
40 | 41 |
|
41 | 42 | init(); |
42 | 43 | animate(); |
43 | 44 |
|
44 | | - function init() { |
| 45 | + async function init() { |
45 | 46 |
|
46 | 47 | 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 ); |
48 | 49 |
|
49 | 50 | scene = new THREE.Scene(); |
50 | | - scene.background = new THREE.Color( 0xeeeeee ); |
51 | 51 |
|
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 |
62 | 52 | renderer = new THREE.WebGLRenderer( { antialias: true } ); |
63 | 53 | renderer.setPixelRatio( window.devicePixelRatio ); |
64 | 54 | renderer.setSize( window.innerWidth, window.innerHeight ); |
| 55 | + renderer.toneMapping = THREE.ACESFilmicToneMapping; |
| 56 | + renderer.toneMappingExposure = 2.0; |
65 | 57 | document.body.appendChild( renderer.domElement ); |
66 | 58 |
|
67 | 59 | const controls = new OrbitControls( camera, renderer.domElement ); |
68 | 60 | controls.minDistance = 1; |
69 | 61 | 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; |
70 | 79 |
|
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; |
73 | 83 |
|
74 | | - scene.add( usd ); |
| 84 | + // model |
75 | 85 |
|
76 | | - } ); |
| 86 | + model.position.y = 0.25; |
| 87 | + model.position.z = - 0.25; |
| 88 | + scene.add( model ); |
77 | 89 |
|
78 | 90 | window.addEventListener( 'resize', onWindowResize ); |
79 | 91 |
|
|
0 commit comments