Threejs deform mesh from heightmap
Asked Answered
E

1

1

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.

Eba answered 18/9, 2015 at 19:51 Comment(0)
D
3

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

Dyscrasia answered 18/9, 2015 at 19:56 Comment(1)
Oh sweet! I didn't see that example before :)Eba

© 2022 - 2024 — McMap. All rights reserved.