Keith M
Keith M

Reputation: 1239

Threejs deform mesh from heightmap

How can I go about deforming an already created mesh with a heightmap in three.js? I did a few searches and couldn't find anything, so I'm asking here.

Upvotes: 1

Views: 2799

Answers (1)

Falk Thiele
Falk Thiele

Reputation: 4494

You are lucky, three.js-r72 introduced vertex displacement in the MeshPhongMaterial. You set the displacement map like a normalMap:

var displacementMap = THREE.ImageUtils.loadTexture( "textures/ninja/displacement.jpg" );

var material = new THREE.MeshPhongMaterial( {
                color: 0x0a0100,
                //...
                displacementMap: displacementMap,
                displacementScale: 2.436143,
                displacementBias: - 0.428408,
            } );

scale: The amount of displacement, "how tall are your spikes"

bias: Shift the center up or down

Official Example: http://threejs.org/examples/#webgl_materials_displacementmap

Upvotes: 3

Related Questions