import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js'
import * as TWEEN from 'three/examples/jsm/libs/tween.module.js'
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js'
import { DDSLoader } from 'three/examples/jsm/loaders/DDSLoader.js'
import { TGALoader } from 'three/addons/loaders/TGALoader.js'
const scence = new THREE. Scene ( ) const camera = new THREE. PerspectiveCamera ( 45 , window. innerWidth / window. innerHeight, 0.1 , 1000 )
camera. position. set ( 2 , 2 , 5 )
camera. lookAt ( 0 , 0 , 0 ) const renderer = new THREE. WebGLRenderer ( { antialias : true
} )
renderer. setSize ( window. innerWidth, window. innerHeight)
document. body. appendChild ( renderer. domElement)
const axesHelper = new THREE. AxesHelper ( 5 )
scence. add ( axesHelper) const controls = new OrbitControls ( camera, renderer. domElement)
controls. dampingFactor = 0.05
function animate ( ) { controls. update ( ) requestAnimationFrame ( animate) renderer. render ( scence, camera) TWEEN . update ( )
}
animate ( )
const textureLoader = new THREE. TextureLoader ( )
let texture = textureLoader. load ( '../public/assets/texture/brick/brick_diffuse.jpg' ) let planeGeometry = new THREE. PlaneGeometry ( 1 , 1 )
let material = new THREE. MeshBasicMaterial ( { color : 0xffffff , map : texture, transparent : true
} )
const plane = new THREE. Mesh ( planeGeometry, material)
scence. add ( plane)
texture. colorSpace = THREE . SRGBColorSpacetexture. minFilter = THREE . LinearMipMapLinearFilter
let maxAnisotropy = renderer. capabilities. getMaxAnisotropy ( )
texture. anisotropy = 4
console. log ( '纹理的各项异性级别maxAnisotropy= ' , maxAnisotropy)
let ktx2Loader = new KTX2Loader ( )
ktx2Loader. setTranscoderPath ( '../public/basis/' ) . detectSupport ( renderer)
let ktx2Texture = ktx2Loader. load ( '../public/assets/texture/opt/ktx2/Alex_Hart-Nature_Lab_Bones_2k_uastc-mip-triangle.ktx2' , texture => { texture. magFilter = THREE . LinearFiltertexture. minFilter = THREE . LinearMipMapLinearFiltertexture. anisotropy = 16 texture. needsUpdate = true scence. background = texturescence. environment = textureplane. material. map = texture
} )
renderer. toneMapping = THREE . ACESFilmicToneMapping
renderer. toneMappingExposure = 1 const gui = new GUI ( )
gui. add ( renderer, 'toneMapping' , { '无色调映射' :直接输出HDR 颜色值(如果支持)No : THREE . NoToneMapping, '线性色调映射' :将HDR 颜色值,线性地缩放到LDR 范围Linear : THREE . LinearToneMapping, 'Reinhard色调映射' :一种流行的HDR 到LDR 的映射方法,能够保持颜色和亮度的对比度;可以更好地处理高亮度的区域,它根据整个图像的平均亮度来调整每个像素的亮度。Reinhard : THREE . ReinhardToneMapping, 'Cineon色调映射' :模仿电影胶片的效果Cineon : THREE . CineonToneMapping, 'ACESFilmic色调映射' :基于电影工业标准ACES 的色调映射算法,旨在提供更自然的色彩和亮度过渡ACESFilmic : THREE . ACESFilmicToneMapping} ) gui. add ( renderer, 'toneMappingExposure' , 0 , 3 , 0.1 )