1. 实现物体闪烁特效,如下所示:

1.gif

  • 来回改变物体的透明度实现

    2. 代码

    
    var geometry = new THREE.TorusGeometry(10, 1, 16, 100);
    var material = new THREE.MeshStandardMaterial({
    color: 0xffff00,
    transparent: true
    });
    var torus = new THREE.Mesh(geometry, material);
    // 绑定自定义数据
    torus.direction = 'up'
    torus.startVal = 1
    scene.add(torus);

function reader() {
TWEEN.update()
renderer.render(scene, camera)

if (torus.startVal > 1) {
torus.direction = 'down'
}
if (torus.startVal < 0) {
torus.direction = 'up'
}

if (torus.direction === 'up') {
torus.startVal += 0.01
material.opacity = torus.startVal
} else {
torus.startVal -= 0.01
material.opacity = torus.startVal
}
}
animate()

function animate() {
reader()
requestAnimationFrame(animate)
}