我目前正在使用Three.js中的JavaScript开发游戏。我想知道是否可以为我所拥有的墙壁添加高度地图,以使它们更加逼真(见图片)。一张带有2D墙壁的游戏设计图片。
我看到的所有教程都使用平面而不是矩形。我目前正在使用矩形,不想换成平面,但如果矩形无法解决问题,我也很乐意知道。
我目前正在使用NewObstacle()类来制作我的矩形:
什么是实现高度图的最简单方法?
我看到的所有教程都使用平面而不是矩形。我目前正在使用矩形,不想换成平面,但如果矩形无法解决问题,我也很乐意知道。
我目前正在使用NewObstacle()类来制作我的矩形:
const wallTexture = new THREE.TextureLoader();
const wallTextureTexture = new THREE.MeshBasicMaterial({
map: wallTexture.load('wall_textures/wall_3.jfif')
})
class NewObstacle{
constructor(sizeX, sizeY, sizeZ, xPos, yPos, zPos){
this.sizeX = sizeX
this.sizeY = sizeY
this.sizeZ = sizeZ
this.xPos = xPos
this.yPos = yPos
this.zPos = zPos
}
makeCube(){
const cubeGeometry = new THREE.BoxGeometry(this.sizeX, this.sizeY, this.sizeZ)
this.box = new THREE.Mesh(cubeGeometry, /*new THREE.MeshBasicMaterial({color:
0x505050})*/wallTextureTexture)
this.box.material.transparent = true
this.box.material.opacity = 1
this.box.position.x = this.xPos
this.box.position.y = this.yPos
this.box.position.z = this.zPos
scene.add(this.box)
}
}
displacementScale
滑块,以查看其工作原理。它基本上使用此图像,使白色部分大量位移,黑色部分略微位移。您可以通过单击右下角的< >
图标查看源代码。 - M -