我目前正在用 JavaScript、Three.js 开发一款游戏。我很好奇是否可以在墙上添加高度图,以使它们更加真实(见图)。带有 2D 墙的游戏设计图像。
我见过的所有教程都使用平面而不是矩形。我目前正在使用矩形,并且不想切换,但如果没有矩形的解决方案,我会很高兴知道。
我目前正在使用类 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 = …Run Code Online (Sandbox Code Playgroud)