Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
Is there a built-in Three.js heightmap function?

I am currently working on a game in JavaScript, in Three.js. I am curious if I can add a height map to the walls that I have to make them more realistic (see image). An image of the game design with the wall that is 2D.

All the tutorials that I have seen use planes instead of rectangles. I am currently using rectangles, and would rather not switch, but if there is no solution with rectangles, I would be happy to know.

I am currently using the class NewObstacle() to make my rectangles:

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)
  }
}

What is the easiest way to implement height maps?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the displacementMap property on the material.

This article states:

Displacement maps are grayscale textures you map to objects to create true surface relief (elevations and depressions) on an otherwise flat object.

First load you texture:

const loader = new THREE.TextureLoader();
const displacement = loader.load('yourfile.extension');

Next you create the material. I recommend using MeshStandardMaterial. This is how you would define your material:

const material = new THREE.MeshStandardMaterial({
    color: 0xff0000, //Red
    displacementMap: displacement,
    displacementScale: 1
});

We already know that displacementMap is going to use the grayscale image to create depressions and elevations on the plane, but the displacementScale is how much the plane is affected by the displacementMap.

That should do it!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!