import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
const scence = new THREE. Scene ( )
const camera = new THREE. PerspectiveCamera ( 45 , window. innerWidth / window. innerHeight, 0.1 , 1000 )
camera. position. set ( 5 , 2 , 2 )
const renderer = new THREE. WebGLRenderer ( )
renderer. setSize ( window. innerWidth / 2 , window. innerHeight / 2 )
document. body. appendChild ( renderer. domElement)
const gltfLoader = new GLTFLoader ( )
gltfLoader. load (
'../public/assets/model/Duck.glb' ,
gltf => {
console. log ( 'gltf-Duck=' , gltf)
scence. add ( gltf. scene)
}
)
const dracoLoader = new DRACOLoader ( )
dracoLoader. setDecoderPath ( '../public/draco/' )
gltfLoader. setDRACOLoader ( dracoLoader)
gltfLoader. load (
'../public/assets/model/city.glb' ,
gltf => {
console. log ( 'gltf-city=' , gltf)
scence. add ( gltf. scene)
}
)
const rgbeLoader = new RGBELoader ( )
rgbeLoader. load ( '../public/assets/texture/Alex_Hart-Nature_Lab_Bones_2k.hdr' , ( envMap ) => {
envMap. mapping = THREE . EquirectangularReflectionMapping
scence. environment = envMap
} )
scence. fog = new THREE. Fog ( 0x999999 , 0.1 , 50 )
scence. background = new THREE. Color ( 0x999999 )
const axesHelper = new THREE. AxesHelper ( 5 )
scence. add ( axesHelper)
const controls = new OrbitControls ( camera, renderer. domElement)
controls. dampingFactor = 0.05
function render ( ) {
controls. update ( )
requestAnimationFrame ( render)
renderer. render ( scence, camera)
}
render ( )