Threejs deform mesh from heightmap

假如想象 提交于 2019-12-08 05:45:25

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/32659991/threejs-deform-mesh-from-heightmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!