Hyperspeedcube icon indicating copy to clipboard operation
Hyperspeedcube copied to clipboard

3D twist gizmo ignores "show frontfaces" and "show backfaces" settings

Open HactarCE opened this issue 1 year ago • 0 comments

Guide

This will actually be nontrivial to do because the gizmo triangles are not oriented. The easiest way to do this is to specify tangent vectors for twist gizmo vertices, since the compute shader is already using them on the GPU to decide which verts to cull. (We've just ignoring the result for gizmo vertices because they don't currently have tangent vectors.)

  1. In hyperpuzzle/src/puzzle/mesh.rs, in Mesh::add_gizmo_vertex(), add tangent vectors to the mesh (similar to add_puzzle_vertex() above). You'll have to add a parameter uv_tangents: [impl VectorRef; 2].
  2. In hyperpuzzle/src/builder/twist_system.rs, in TwistSystemBuilder::build_gizmo(), on the let vertex_map line, compute the two tangent vectors for the polygon of the twist gizmo. The error handling will be easier if you convert the functional-style flat_map() and map() into traditional for loops. Use space.get(polygon).as_face()?.tangent_vectors()? to get the tangent vectors for the polygon.
  3. Make sure the tangent vectors are facing the right way relative to some point inside the polyhedron, which you can get by averaging all vertices of the polyhedron (probably something like space.get(polyhedron).vertex_set()). See hyperpuzzle/src/builder/shape.rs build_shape_polygons() for an example. It's a good idea to make the triangles face the right way in 3D too, since that'll help with #58. Feel free to factor out parts into hyperpuzzle/src/util.rs if you can find a nice way to do it.
  4. That should just work?

HactarCE avatar Nov 25 '24 06:11 HactarCE