I’ve looked at many user questions and reader discussions about wireframes in both Discourse and Stackoverflow. But I am still pretty fogged about to actually implement a wireframe at all and with a toggle in my lil-gui interface.
I would really like to implement an edges-only option (no diagonals in the triangles) that makes the underlying geometry disappear. See this discussion:
And this one:
However, I would be extremely grateful for an explanation of just this example:
It seems that in the absence of an explicit handler, lil-gui toggles the property of the material specified as a boolean, in this case material.wireframe = true/false;
The implementation should be somewhere inside lil-gui library code.
Thank you for your answer.
I think the user interaction through lil-gui is working. I just don’t know how to transform a given geometry such as a cube so that the wireframe appears.
You don’t need to transform the geometry. When you set the material’s wireframe property to true, the same geometry will be rendered as a wireframe instead of a solid surface.
A geometry is a collection of points, you can render them in three different modes: points, lines and triangles, setting material.wireframe = true tells the GPU to render lines.
Mesh is a combination of a geometry and a material.
There are Mesh materials, they can be used to render a solid or a wireframe.
The pattern for using a Mesh materials is:
const geo = new THREE.BoxGeometry(...);
const mat = new THREE.MeshPhongMaterial(...); // to produce a wireframe MeshPhongMaterial( { wireframe: true })
const mesh = = new THREE.Mesh(geo, mat);
scene.add(mesh);
Materials that have Line in their name are for drawing lines only, you don’t need to use wireframe property, and you use Line instead of Mesh, the pattern is:
const geo = new THREE.BufferGeometry();
const vertices = [...]; // the list of all points coordinates from the BoxGeometry above
geo.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
const mat = new THREE.LineBasicMaterial(...);
const line = new THREE.Line(geo, mat);
scene.add(line);