Seeking to extract and export the mesh affected by a displacementMap.
The displacement of vertexes is determined by this line in the shader (taken from three.js/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl):
transformed += normalize(objectNormal) * (texture2D(displacementMap, uv).x * displacementScale + displacementBias);
This process displaces a vertex based on the displacementMap, in conjunction with the uv coordinates for that vertex.
I am aiming to generate this mesh/geometry in order to export it at a later time.
For a closer look at the issue, a "demo" has been created here: Github Page Upon clicking 'exportSTL', I would like to obtain the displaced mesh seen in the viewport; however, I am only receiving the undisplaced plane.
I am aware that this occurs because the displacement solely occurs in the shader and does not directly displace the geometry of the plane.
I have yet to come across a method provided by three.js that allows for capturing the shader's changes. Therefore, I am attempting to address this using a function in my "demo.js" file. However, being new to WebGL/three.js, I am encountering difficulties in replicating the shader's actions.
I have encountered exporters that handle morphTargets, but these are not aiding in this situation. After reviewing this question, I experimented with PlaneBufferGeometry, as it closely resembles the shader - yet, this yielded the same outcomes for me. I believe this question was attempting something similar, yet settled on a different approach.
In the end, my goal is to draw on an HTML-canvas that dynamically updates the texture (which is currently functional). Then, users can export the mesh for 3D printing.
Is there a way for three.js to provide me with the modified geometry from the shader? Alternatively, could someone assist in converting the shader line into a more conventional three.js function? Perhaps my current method of obtaining a displaced mesh is completely misguided?
Update - Example is working
Thanks to DeeFisher's example, I am now able to compute the displacement on the CPU, as originally suggested by imerso. Upon visiting the Github Page now, you will find a functional demonstration. I am still attempting to grasp why I must mirror the canvas to achieve the correct displacement in the end, but this is, at worst, a minor inconvenience.