md,艹,这玩意得理解,只看代码不管事
效果图
代码
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 { EXRLoader } from 'three/addons/loaders/EXRLoader.js'
import { LogLuvLoader } from 'three/addons/loaders/LogLuvLoader.js'
import { RGBMLoader } from 'three/addons/loaders/RGBMLoader.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 planeGeometry = new THREE.PlaneGeometry(2, 2)
const planeMaterial = new THREE.MeshBasicMaterial({
map: new THREE.TextureLoader().load('../public/assets/texture/sprite0.png'),
side: THREE.DoubleSide,
transparent: true
})
const plane = new THREE.Mesh(planeGeometry, planeMaterial)
plane.renderOrder = 0
scence.add(plane)
const planeGeometry_1 = new THREE.PlaneGeometry(2, 2)
const planeMaterial_1 = new THREE.MeshBasicMaterial({
map: new THREE.TextureLoader().load('../public/assets/texture/lensflare0_alpha.png'),
side: THREE.DoubleSide,
transparent: true
})
const plane_1 = new THREE.Mesh(planeGeometry_1, planeMaterial_1)
plane_1.position.z = 2
plane_1.renderOrder = 1
scence.add(plane_1)
plane.material.depthTest = true
plane.material.depthWrite = true
plane.material.depthFunc = THREE.LessEqualDepth
plane_1.material.depthTest = true
plane_1.material.depthWrite = true
plane_1.material.depthFunc = THREE.LessEqualDepth
const gui = new GUI()
let gui_0 = gui.addFolder('plane')
gui_0.add(plane.material, 'depthTest').name('深度测试').onChange(() => {
plane.material.needsUpdate = true
})
gui_0.add(plane.material, 'depthWrite').name('深度写入').onChange(() => {
plane.material.needsUpdate = true
})
gui_0.add(plane.material, 'depthFunc', {
'THREE.LessEqualDepth': THREE.LessEqualDepth,
'THREE.NeverDepth': THREE.NeverDepth,
'THREE.AlwaysDepth': THREE.AlwaysDepth,
'THREE.GreaterDepth': THREE.GreaterDepth,
})
let gui_1 = gui.addFolder('plane_1')
gui_1.add(plane_1.material, 'depthTest').name('深度测试').onChange(() => {
plane_1.material.needsUpdate = true
})
gui_1.add(plane_1.material, 'depthWrite').name('深度写入').onChange(() => {
plane_1.material.needsUpdate = true
})
gui_1.add(plane_1.material, 'depthFunc', {
'THREE.LessEqualDepth': THREE.LessEqualDepth,
'THREE.NeverDepth': THREE.NeverDepth,
'THREE.AlwaysDepth': THREE.AlwaysDepth,
'THREE.GreaterDepth': THREE.GreaterDepth,
})