不给newScence添加background、environment时
给newScence添加background、environment时
源码
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 { 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 ( 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
let rgbeLoader = new RGBELoader ( )
rgbeLoader. load ( '../public/assets/texture/Alex_Hart-Nature_Lab_Bones_2k.hdr' , envMap => {
envMap. mapping = THREE . EquirectangularRefractionMapping
` 第一个场景 `
scence. background = envMap
scence. environment = envMap
` 第二个场景 ` 【可以注掉newScence的background、environment试试,newScence的背景就成了黑色的了】
newScence. background = envMap
newScence. environment = envMap
} )
` 创建环形结的几何体 `
new THREE. TorusKnotGeometry ( radius, tube, radialSegments, tubularSegments)
radius:环形(Torus)的半径,即:环形中心到环形表面的距离;这个值越大,环形就越大。
tube ( 管半径) : 环形上的管道的半径,这个值决定了环形表面的厚度。
radialSegments ( 径向分段数) :环形沿着其半径的分段数。这个值越大,环形的边缘就越平滑。
tubularSegments ( 管分段数) :管道沿着其长度的分段数。这个值也影响表面的平滑度,但它是沿着环形的周长方向。
const geometry = new THREE. TorusKnotGeometry ( 5 , 1 , 100 , 16 )
const material = new THREE. MeshPhysicalMaterial ( {
side : THREE . DoubleSide
} )
const torusKnot = new THREE. Mesh ( geometry, material)
scence. add ( torusKnot)
const newScence = new THREE. Scene ( )
const geometry_1 = new THREE. TorusKnotGeometry ( 5 , 1 , 100 , 16 )
const material_1 = new THREE. MeshBasicMaterial ( {
wireframe : true
} )
const torusKnot_1 = new THREE. Mesh ( geometry_1, material_1)
newScence. add ( torusKnot_1)
let params = {
scissorWidth : window. innerWidth / 2
}
function animate ( ) {
controls. update ( )
requestAnimationFrame ( animate)
` 启用或禁用裁剪检测,若启用,则,只有在裁剪区域的像色才会受影响 `
renderer. setScissorTest ( true )
`
设置裁剪区域
0,0:代表的是,裁剪区域的左上角坐标,这意着裁剪区域的起点与渲染目标(通常是canvas)的左上角对齐。
params.scissorWidth:是裁剪区域的宽度,它决定了裁剪区域在水平方向上的大小。
window.innerHeight:是裁剪区域的高度,这里使用浏览器窗口的内部高度。
意味着,裁剪区域的高度将随浏览器窗口高度的变化而变化,
这样能确保,渲染内容能够覆盖整个视窗的垂直高度。
`
renderer. setScissor ( 0 , 0 , params. scissorWidth, window. innerHeight)
renderer. render ( scence, camera)
renderer. setScissor ( params. scissorWidth, 0 , window. innerWidth - params. scissorWidth, window. innerHeight)
renderer. render ( newScence, camera)
renderer. setScissorTest ( false )
TWEEN . update ( )
}
animate ( )
const gui = new GUI ( )
gui. add ( params, 'scissorWidth' , 0 , window. innerWidth)