提示:文章写完后,目次可以主动生成,怎样生成可参考右边的资助文档
前言
课程回顾:
模型的加载
GLTFLoader
环境贴图实现;
CubeTextureLoader
LDR:低动态范围
backgroundBlurriness:设置背景含糊 (不生效 为什么?)
backgroundIntensity: 设置背景强度,设置的是背景亮度 (不生效 为什么?)
HDRI : 等距矩形环境贴图
怎样加载使用HDRI文件?
RGBE :赤色 ,绿色 ,蓝色 ,指数:存储的是亮度 (重点)
我们需要使用RGBELoader。"RGBE"代表"红绿蓝指数",指数存储亮度
这是“HDR”格式的编码。
THREE.EquirectangularReflectionMapping // 等距型反射
THREE.EquirectangularRefractionMapping // 折射透明
HDRI 缺点
文件加载渲染较大
建议只对光照使用HDRI
?上面实现中有一个题目,怎样办理环境贴图对模型的影响
1.blender怎样生成环田地图?
在blender制作
2.使用NVIDA Canvas生成环田地图
https://www.nvidia.cn/studio/canvas/
类型:exr后缀
扩展名是.exr,而不是.hdr。我们导出的文件也是存储的颜色范围的“HDR”图像,但编码不同
EXR还可以存储层,并具有alpha通道
3. 环境贴图 (收费)
https://skybox.blockadelabs.com/
时间环田地图
真实的光 : 怎样让甜甜圈模型 产生光?
需要创建自己的立方体纹理,更textureLoad差不多,在每一帧中做处置惩罚;因此使用webgl立方体渲染器目的
这个时间模型还是黑色
需要一个特殊的相机。 如果想要渲染就需要一个相机进行拍摄
WebGLCubeRenderTarget
分成办理相机渲染,决定显示什么
object.layers.enable(..)将添加一个图层
object.layers.disable(...)将移除一个图层
object.layers.set(...)将主动启用一个图层并禁用全部其他图层
一、代码
- import * as THREE from 'three'
- import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'
- import GUI from 'lil-gui'
- import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
- import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js'
- import {EXRLoader} from 'three/examples/jsm/loaders/EXRLoader.js'
- import { Mapping, Mesh } from 'three'
- /*
- * Loaders
- */
- const gltfLoader = new GLTFLoader()
- const cubeTextrueLoader = new THREE.CubeTextureLoader()
- const rgbeLoader = new RGBELoader()
- const exrLoader = new EXRLoader()
- const textureLoader = new THREE.TextureLoader()
- /**
- * gui
- */
- const gui = new GUI()
- const global = {
- }
- // Canvas
- const canvas = document.querySelector('canvas.webgl')
- /**
- * scene
- */
- const scene = new THREE.Scene()
- /*
- Updata all materials
- */
- const updateAllMaterials = () => {
- scene.traverse((child)=>{ // 遍历
- if(child.isMesh && child.material.isMeshStandardMaterial){
- child.material.envMapIntensity = global.envMapIntensity
- }
- })
- }
- /*
- environmentMap 环境贴图
- */
- scene.backgroundBlurriness = 0
- scene.backgroundIntensity = 1
- // global intensity
- global.envMapIntensity = 1 // 环境贴图强度
- gui
- .add(global,'envMapIntensity')
- .min(0)
- .max(10)
- .step(0.001)
- .onChange(updateAllMaterials)
- gui
- .add(scene, 'backgroundBlurriness')
- .min(0)
- .max(1)
- .step(0.001)
- gui
- .add(scene, 'backgroundIntensity')
- .min(0)
- .max(10)
- .step(0.001)
-
- // LDR cube texture 环境贴图的实现
- // const environmentMap = cubeTextrueLoader.load([
- // '/environmentMaps/2/px.png',
- // '/environmentMaps/2/nx.png',
- // '/environmentMaps/2/py.png',
- // '/environmentMaps/2/ny.png',
- // '/environmentMaps/2/pz.png',
- // '/environmentMaps/2/nz.png',
- // ])
- // scene.environment = environmentMap // 可以实现场景中每一个网格材质对于场景起到作用
- // scene.background = environmentMap // 将环境贴图应用到场景中
- // HDR (RGBA) equirectangular
- // rgbeLoader.load(
- // '/environmentMaps/测试hdr生成全景3.hdr',
- // (environmentMap)=>{
- // environmentMap.mapping = THREE.EquirectangularReflectionMapping
- // scene.background = environmentMap
- // scene.environment = environmentMap
- // }
- // )
- // HDR (EXR) equirectangular
- // exrLoader.load('/environmentMaps/nvidiaCanvas-4k.exr',(environmentMap)=>{
- // environmentMap.mapping = THREE.EquirectangularReflectionMapping
- // scene.background = environmentMap
- // scene.environment = environmentMap
- // })
- // LDR equirectangular
- // const environmentMap = textureLoader.load('') //没资源
- // environmentMap.mapping = THREE.EquirectangularReflectionMapping
- // environmentMap.colorSpace = THREE.SRGBColorSpace
- // scene.background = environmentMap
- // scene.environment = environmentMap
- // Ground projected skybox
- // rgbeLoader.load('/environmentMaps/1/little_paris_eiffel_tower_8k.hdr',(environmentMap)=>{
- // environmentMap.mapping = THREE.EquirectangularReflectionMapping
- // scene.environment = environmentMap
- // scene.background = environmentMap
- // })
- /*
- Real time environment map
- */
- const environmentMap = textureLoader.load('/environmentMaps/blockadesLabsSkybox/interior_views_cozy_wood_cabin_with_cauldron_and_p.jpg')
- environmentMap.mapping = THREE.EquirectangularReflectionMapping
- environmentMap.colorSpace = THREE.SRGBColorSpace
- scene.background = environmentMap
- /*
- holyDount
- */
- const holyDonut = new THREE.Mesh(
- new THREE.TorusGeometry(8,0.5),
- new THREE.MeshBasicMaterial({color:new THREE.Color(10, 4, 2)})
- )
- holyDonut.layers.enable(1) // 分层启用
- holyDonut.position.y = 3.5
- scene.add(holyDonut)
- /*
- cube render target
- */
- const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(
- 256, // 分辨率
- { // 渲染目标的选项
- type:THREE.FloatType // 类型
- }
- )
- scene.environment = cubeRenderTarget.texture // 使用自己的纹理
- // Cube Camera
- const cubeCamera = new THREE.CubeCamera(0.1,100,cubeRenderTarget) // 要每一帧渲染
- cubeCamera.layers.set(1) // 设置相机分成
- /**
- * torus knot
- */
- const torusKnot = new THREE.Mesh(
- new THREE.TorusKnotGeometry(1, 0.4, 100, 16),
- new THREE.MeshStandardMaterial({
- roughness: 0,
- metalness: 1,
- color: 0xaaaaaa
- })
- )
- torusKnot.position.x = -4
- torusKnot.position.y = 4
- scene.add(torusKnot)
- /*
- * Models
- */
- gltfLoader.load(
- '/models/FlightHelmet/glTF/FlightHelmet.gltf',
- (gltf)=>{
- gltf.scene.scale.set(10,10,10)
- scene.add(gltf.scene)
- updateAllMaterials()
- }
- )
- /**
- * Sizes
- */
- const sizes = {
- width: window.innerWidth,
- height: window.innerHeight
- }
- window.addEventListener('resize', () => {
- // Update sizes
- sizes.width = window.innerWidth
- sizes.height = window.innerHeight
- // Update camera
- camera.aspect = sizes.width / sizes.height
- camera.updateProjectionMatrix()
- // Update renderer
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- })
- /**
- * camera
- */
- const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
- camera.position.set(- 8, 4, 8)
- scene.add(camera)
- /**
- * renderer
- */
- const renderer = new THREE.WebGLRenderer({
- canvas: canvas
- })
- // renderer.shadowMap.enabled = true
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- /**
- * control
- */
- const controls = new OrbitControls(camera, canvas)
- controls.target.y = 3.5
- controls.enableDamping = true
- /**
- * tick
- */
- const clock = new THREE.Clock()
- const tick = () => {
- // Time
- const elapsedTime = clock.getElapsedTime()
- if(holyDonut){
- holyDonut.rotation.x = Math.sin(elapsedTime) * 2
- cubeCamera.update(renderer, scene)
- }
- controls.update()
- renderer.render(scene, camera)
- requestAnimationFrame(tick)
- }
- tick()
复制代码 二、知识点
1.LDR
- import * as THREE from 'three'
- import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'
- import GUI from 'lil-gui'
- import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
- import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js'
- import {EXRLoader} from 'three/examples/jsm/loaders/EXRLoader.js'
- import { Mapping, Mesh } from 'three'
- /*
- * Loaders
- */
- const gltfLoader = new GLTFLoader()
- const cubeTextrueLoader = new THREE.CubeTextureLoader()
- const rgbeLoader = new RGBELoader()
- const exrLoader = new EXRLoader()
- const textureLoader = new THREE.TextureLoader()
- /**
- * gui
- */
- const gui = new GUI()
- const global = {
- }
- // Canvas
- const canvas = document.querySelector('canvas.webgl')
- /**
- * scene
- */
- const scene = new THREE.Scene()
- /*
- Updata all materials
- */
- const updateAllMaterials = () => {
- scene.traverse((child)=>{ // 遍历
- if(child.isMesh && child.material.isMeshStandardMaterial){
- child.material.envMapIntensity = global.envMapIntensity
- }
- })
- }
- /*
- environmentMap 环境贴图
- */
- scene.backgroundBlurriness = 0
- scene.backgroundIntensity = 1
- // global intensity
- global.envMapIntensity = 1 // 环境贴图强度
- gui
- .add(global,'envMapIntensity')
- .min(0)
- .max(10)
- .step(0.001)
- .onChange(updateAllMaterials)
- gui
- .add(scene, 'backgroundBlurriness')
- .min(0)
- .max(1)
- .step(0.001)
- gui
- .add(scene, 'backgroundIntensity')
- .min(0)
- .max(10)
- .step(0.001)
-
- // LDR cube texture 环境贴图的实现
- const environmentMap = cubeTextrueLoader.load([
- '/environmentMaps/2/px.png',
- '/environmentMaps/2/nx.png',
- '/environmentMaps/2/py.png',
- '/environmentMaps/2/ny.png',
- '/environmentMaps/2/pz.png',
- '/environmentMaps/2/nz.png',
- ])
- scene.environment = environmentMap // 可以实现场景中每一个网格材质对于场景起到作用
- scene.background = environmentMap // 将环境贴图应用到场景中
- /**
- * torus knot
- */
- const torusKnot = new THREE.Mesh(
- new THREE.TorusKnotGeometry(1, 0.4, 100, 16),
- new THREE.MeshStandardMaterial({
- roughness: 0,
- metalness: 1,
- color: 0xaaaaaa
- })
- )
- torusKnot.position.x = -4
- torusKnot.position.y = 4
- scene.add(torusKnot)
- /*
- * Models
- */
- gltfLoader.load(
- '/models/FlightHelmet/glTF/FlightHelmet.gltf',
- (gltf)=>{
- gltf.scene.scale.set(10,10,10)
- scene.add(gltf.scene)
- updateAllMaterials()
- }
- )
- /**
- * Sizes
- */
- const sizes = {
- width: window.innerWidth,
- height: window.innerHeight
- }
- window.addEventListener('resize', () => {
- // Update sizes
- sizes.width = window.innerWidth
- sizes.height = window.innerHeight
- // Update camera
- camera.aspect = sizes.width / sizes.height
- camera.updateProjectionMatrix()
- // Update renderer
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- })
- /**
- * camera
- */
- const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
- camera.position.set(- 8, 4, 8)
- scene.add(camera)
- /**
- * renderer
- */
- const renderer = new THREE.WebGLRenderer({
- canvas: canvas
- })
- // renderer.shadowMap.enabled = true
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- /**
- * control
- */
- const controls = new OrbitControls(camera, canvas)
- controls.target.y = 3.5
- controls.enableDamping = true
- /**
- * tick
- */
- const clock = new THREE.Clock()
- const tick = () => {
- // Time
- const elapsedTime = clock.getElapsedTime()
- controls.update()
- renderer.render(scene, camera)
- requestAnimationFrame(tick)
- }
- tick()
复制代码
2.HDR (RGBA)
- import * as THREE from 'three'
- import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'
- import GUI from 'lil-gui'
- import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
- import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js'
- import {EXRLoader} from 'three/examples/jsm/loaders/EXRLoader.js'
- import { Mapping, Mesh } from 'three'
- /*
- * Loaders
- */
- const gltfLoader = new GLTFLoader()
- const cubeTextrueLoader = new THREE.CubeTextureLoader()
- const rgbeLoader = new RGBELoader()
- const exrLoader = new EXRLoader()
- const textureLoader = new THREE.TextureLoader()
- /**
- * gui
- */
- const gui = new GUI()
- const global = {
- }
- // Canvas
- const canvas = document.querySelector('canvas.webgl')
- /**
- * scene
- */
- const scene = new THREE.Scene()
- /*
- Updata all materials
- */
- const updateAllMaterials = () => {
- scene.traverse((child)=>{ // 遍历
- if(child.isMesh && child.material.isMeshStandardMaterial){
- child.material.envMapIntensity = global.envMapIntensity
- }
- })
- }
- /*
- environmentMap 环境贴图
- */
- scene.backgroundBlurriness = 0
- scene.backgroundIntensity = 1
- // global intensity
- global.envMapIntensity = 1 // 环境贴图强度
- gui
- .add(global,'envMapIntensity')
- .min(0)
- .max(10)
- .step(0.001)
- .onChange(updateAllMaterials)
- gui
- .add(scene, 'backgroundBlurriness')
- .min(0)
- .max(1)
- .step(0.001)
- gui
- .add(scene, 'backgroundIntensity')
- .min(0)
- .max(10)
- .step(0.001)
-
- // HDR (RGBA) equirectangular
- rgbeLoader.load(
- '/environmentMaps/测试hdr生成全景3.hdr',
- (environmentMap)=>{
- environmentMap.mapping = THREE.EquirectangularReflectionMapping
- scene.background = environmentMap
- scene.environment = environmentMap
- }
- )
- /**
- * torus knot
- */
- const torusKnot = new THREE.Mesh(
- new THREE.TorusKnotGeometry(1, 0.4, 100, 16),
- new THREE.MeshStandardMaterial({
- roughness: 0,
- metalness: 1,
- color: 0xaaaaaa
- })
- )
- torusKnot.position.x = -4
- torusKnot.position.y = 4
- scene.add(torusKnot)
- /*
- * Models
- */
- gltfLoader.load(
- '/models/FlightHelmet/glTF/FlightHelmet.gltf',
- (gltf)=>{
- gltf.scene.scale.set(10,10,10)
- scene.add(gltf.scene)
- updateAllMaterials()
- }
- )
- /**
- * Sizes
- */
- const sizes = {
- width: window.innerWidth,
- height: window.innerHeight
- }
- window.addEventListener('resize', () => {
- // Update sizes
- sizes.width = window.innerWidth
- sizes.height = window.innerHeight
- // Update camera
- camera.aspect = sizes.width / sizes.height
- camera.updateProjectionMatrix()
- // Update renderer
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- })
- /**
- * camera
- */
- const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
- camera.position.set(- 8, 4, 8)
- scene.add(camera)
- /**
- * renderer
- */
- const renderer = new THREE.WebGLRenderer({
- canvas: canvas
- })
- // renderer.shadowMap.enabled = true
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- /**
- * control
- */
- const controls = new OrbitControls(camera, canvas)
- controls.target.y = 3.5
- controls.enableDamping = true
- /**
- * tick
- */
- const clock = new THREE.Clock()
- const tick = () => {
- // Time
- const elapsedTime = clock.getElapsedTime()
- controls.update()
- renderer.render(scene, camera)
- requestAnimationFrame(tick)
- }
- tick()
复制代码
3.HDR (EXR)
- import * as THREE from 'three'
- import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'
- import GUI from 'lil-gui'
- import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
- import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js'
- import {EXRLoader} from 'three/examples/jsm/loaders/EXRLoader.js'
- import { Mapping, Mesh } from 'three'
- /*
- * Loaders
- */
- const gltfLoader = new GLTFLoader()
- const cubeTextrueLoader = new THREE.CubeTextureLoader()
- const rgbeLoader = new RGBELoader()
- const exrLoader = new EXRLoader()
- const textureLoader = new THREE.TextureLoader()
- /**
- * gui
- */
- const gui = new GUI()
- const global = {
- }
- // Canvas
- const canvas = document.querySelector('canvas.webgl')
- /**
- * scene
- */
- const scene = new THREE.Scene()
- /*
- Updata all materials
- */
- const updateAllMaterials = () => {
- scene.traverse((child)=>{ // 遍历
- if(child.isMesh && child.material.isMeshStandardMaterial){
- child.material.envMapIntensity = global.envMapIntensity
- }
- })
- }
- /*
- environmentMap 环境贴图
- */
- scene.backgroundBlurriness = 0
- scene.backgroundIntensity = 1
- // global intensity
- global.envMapIntensity = 1 // 环境贴图强度
- gui
- .add(global,'envMapIntensity')
- .min(0)
- .max(10)
- .step(0.001)
- .onChange(updateAllMaterials)
- gui
- .add(scene, 'backgroundBlurriness')
- .min(0)
- .max(1)
- .step(0.001)
- gui
- .add(scene, 'backgroundIntensity')
- .min(0)
- .max(10)
- .step(0.001)
-
- // HDR (EXR) equirectangular
- exrLoader.load('/environmentMaps/nvidiaCanvas-4k.exr',(environmentMap)=>{
- environmentMap.mapping = THREE.EquirectangularReflectionMapping
- scene.background = environmentMap
- scene.environment = environmentMap
- })
- /**
- * torus knot
- */
- const torusKnot = new THREE.Mesh(
- new THREE.TorusKnotGeometry(1, 0.4, 100, 16),
- new THREE.MeshStandardMaterial({
- roughness: 0,
- metalness: 1,
- color: 0xaaaaaa
- })
- )
- torusKnot.position.x = -4
- torusKnot.position.y = 4
- scene.add(torusKnot)
- /*
- * Models
- */
- gltfLoader.load(
- '/models/FlightHelmet/glTF/FlightHelmet.gltf',
- (gltf)=>{
- gltf.scene.scale.set(10,10,10)
- scene.add(gltf.scene)
- updateAllMaterials()
- }
- )
- /**
- * Sizes
- */
- const sizes = {
- width: window.innerWidth,
- height: window.innerHeight
- }
- window.addEventListener('resize', () => {
- // Update sizes
- sizes.width = window.innerWidth
- sizes.height = window.innerHeight
- // Update camera
- camera.aspect = sizes.width / sizes.height
- camera.updateProjectionMatrix()
- // Update renderer
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- })
- /**
- * camera
- */
- const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
- camera.position.set(- 8, 4, 8)
- scene.add(camera)
- /**
- * renderer
- */
- const renderer = new THREE.WebGLRenderer({
- canvas: canvas
- })
- // renderer.shadowMap.enabled = true
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- /**
- * control
- */
- const controls = new OrbitControls(camera, canvas)
- controls.target.y = 3.5
- controls.enableDamping = true
- /**
- * tick
- */
- const clock = new THREE.Clock()
- const tick = () => {
- // Time
- const elapsedTime = clock.getElapsedTime()
- controls.update()
- renderer.render(scene, camera)
- requestAnimationFrame(tick)
- }
- tick()
复制代码
4.时间环田地图
- import * as THREE from 'three'
- import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'
- import GUI from 'lil-gui'
- import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js'
- import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js'
- import {EXRLoader} from 'three/examples/jsm/loaders/EXRLoader.js'
- import { Mapping, Mesh } from 'three'
- /*
- * Loaders
- */
- const gltfLoader = new GLTFLoader()
- const cubeTextrueLoader = new THREE.CubeTextureLoader()
- const rgbeLoader = new RGBELoader()
- const exrLoader = new EXRLoader()
- const textureLoader = new THREE.TextureLoader()
- /**
- * gui
- */
- const gui = new GUI()
- const global = {
- }
- // Canvas
- const canvas = document.querySelector('canvas.webgl')
- /**
- * scene
- */
- const scene = new THREE.Scene()
- /*
- Updata all materials
- */
- const updateAllMaterials = () => {
- scene.traverse((child)=>{ // 遍历
- if(child.isMesh && child.material.isMeshStandardMaterial){
- child.material.envMapIntensity = global.envMapIntensity
- }
- })
- }
- /*
- environmentMap 环境贴图
- */
- scene.backgroundBlurriness = 0
- scene.backgroundIntensity = 1
- // global intensity
- global.envMapIntensity = 1 // 环境贴图强度
- gui
- .add(global,'envMapIntensity')
- .min(0)
- .max(10)
- .step(0.001)
- .onChange(updateAllMaterials)
- gui
- .add(scene, 'backgroundBlurriness')
- .min(0)
- .max(1)
- .step(0.001)
- gui
- .add(scene, 'backgroundIntensity')
- .min(0)
- .max(10)
- .step(0.001)
-
- /*
- Real time environment map
- */
- const environmentMap = textureLoader.load('/environmentMaps/blockadesLabsSkybox/interior_views_cozy_wood_cabin_with_cauldron_and_p.jpg')
- environmentMap.mapping = THREE.EquirectangularReflectionMapping
- environmentMap.colorSpace = THREE.SRGBColorSpace
- scene.background = environmentMap
- /*
- holyDount
- */
- const holyDonut = new THREE.Mesh(
- new THREE.TorusGeometry(8,0.5),
- new THREE.MeshBasicMaterial({color:new THREE.Color(10, 4, 2)})
- )
- holyDonut.layers.enable(1) // 分层启用
- holyDonut.position.y = 3.5
- scene.add(holyDonut)
- /*
- cube render target
- */
- const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(
- 256, // 分辨率
- { // 渲染目标的选项
- type:THREE.FloatType // 类型
- }
- )
- scene.environment = cubeRenderTarget.texture // 使用自己的纹理
- // Cube Camera
- const cubeCamera = new THREE.CubeCamera(0.1,100,cubeRenderTarget) // 要每一帧渲染
- cubeCamera.layers.set(1) // 设置相机分成
- /**
- * torus knot
- */
- const torusKnot = new THREE.Mesh(
- new THREE.TorusKnotGeometry(1, 0.4, 100, 16),
- new THREE.MeshStandardMaterial({
- roughness: 0,
- metalness: 1,
- color: 0xaaaaaa
- })
- )
- torusKnot.position.x = -4
- torusKnot.position.y = 4
- scene.add(torusKnot)
- /*
- * Models
- */
- gltfLoader.load(
- '/models/FlightHelmet/glTF/FlightHelmet.gltf',
- (gltf)=>{
- gltf.scene.scale.set(10,10,10)
- scene.add(gltf.scene)
- updateAllMaterials()
- }
- )
- /**
- * Sizes
- */
- const sizes = {
- width: window.innerWidth,
- height: window.innerHeight
- }
- window.addEventListener('resize', () => {
- // Update sizes
- sizes.width = window.innerWidth
- sizes.height = window.innerHeight
- // Update camera
- camera.aspect = sizes.width / sizes.height
- camera.updateProjectionMatrix()
- // Update renderer
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- })
- /**
- * camera
- */
- const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
- camera.position.set(- 8, 4, 8)
- scene.add(camera)
- /**
- * renderer
- */
- const renderer = new THREE.WebGLRenderer({
- canvas: canvas
- })
- // renderer.shadowMap.enabled = true
- // renderer.shadowMap.type = THREE.PCFSoftShadowMap
- renderer.setSize(sizes.width, sizes.height)
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
- /**
- * control
- */
- const controls = new OrbitControls(camera, canvas)
- controls.target.y = 3.5
- controls.enableDamping = true
- /**
- * tick
- */
- const clock = new THREE.Clock()
- const tick = () => {
- // Time
- const elapsedTime = clock.getElapsedTime()
- if(holyDonut){
- holyDonut.rotation.x = Math.sin(elapsedTime) * 2
- cubeCamera.update(renderer, scene)
- }
- controls.update()
- renderer.render(scene, camera)
- requestAnimationFrame(tick)
- }
- tick()
复制代码 真实时间环田地图
总结
环田地图多种加载方式,以及用法。尚有关于环田地图资源怎样探求,怎么自己在blender制作环田地图等
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |