# Replace Faces Node [Original Proposal] The `Replace Faces` node copies geometry data to all selected faces. Every geometry copy is deformed according to the shape of the face. Optionally, the individual copies can be connected. ![](https://hackmd.io/_uploads/H1iYIfub6.png) ## Inputs * `Mesh`: The faces in this mesh are replaced with other data. * `Selection`: The faces in the mesh that should be replaced. * `Instances`: Every selected face is replaced by the data of one of these instances. Each instance can contain arbitrary mesh, point cloud or curve data. * `Pick Index`: An index per face that decides which instance is used in each face. * `Root Corner`: A corner in every selected face that is considered the "root". This allows controlling how each instance is fit into a face. * `Normal`: A normal per face corner that determines the local deformation in each face. * `Merge`: If enabled, merge geometry elements between original faces. ## Use Cases * Subdivide after Extrude. * Adaptive Subdivision. * "Tesselation" (see [Tissue](https://docs.blender.org/manual/en/latest/addons/mesh/tissue.html) addon). * Allows replacing a face with arbitrary topology. Together with a "Dissolve Edges" node, it can also be used to replace multiple faces with new topology. * Generate curves on a surface. * Probably much more. ## Deformation There are many different ways to deform a geometry according to a face (unfortunately). The node should be able to replace triangles, quads and arbitrarily sized ngons. In general, the deformation algorithm has the following parameters: * Inputs: * Position to deform. * Number of vertices in the current face. * Corner positions of the face. * Corner normals of the face. * Outputs: * New position. The source instances that are duplicated are expected to be in some normalized form. There needs to be a standard polygon with every possible number of vertices. These standard polygons will likely just be the output of the `Mesh Circle` and maybe the `Grid` node. If an instance matches this standard form exactly, it is expected to line up exactly with the original face. ![](https://hackmd.io/_uploads/r1-8lX_ZT.png) The deformation generally works by first computing relative coordinates of the position with respect to the standard polygon. Then these relative coordinates are converted back to absolute coordinates based on the deformed polygon in the source mesh. The tricky thing is to define what these relative coordinates are. We might need different modes for different use-cases. Here are some possible ideas: * For triangles only: * Barycentric coordinates. * For quads only: * ![](https://hackmd.io/_uploads/S1ofGmOZ6.png) * For arbitrary ngons (including triangles and quads): * Use a standardized triangulation and use barycentric coordinates in each triangle. * Here it's important that the triangulation does not depend on the vertex positions generally, because that leads to sudden jumps when the input mesh is animated. Requirements for the deformation: * Points on the vertices/edges of the standard polygon are still on the vertices/edges of the deformed polygon. This is important so that the new geometry can be merged with other existing geometry. * Points above/below vertices/edges of the standard polygon are still above/below the vertices/edges of the deformed polygon according to the normal. This is also important for merging. * Within the face, the deformation should be continuous, ideally smooth if possible. ## Merging Merging the new geometry with existing geometry is important for many modelling use cases. In some cases, the merging could also be done by a separate `Merge by Distance` node, but that's generally slower and also does not cover all use cases. Different kinds of merges have to be considered: * ![](https://hackmd.io/_uploads/S1t7HmOWp.png) * ![](https://hackmd.io/_uploads/BkwLHX_-a.png) * ![](https://hackmd.io/_uploads/Hy1oSX_W6.png) * ![](https://hackmd.io/_uploads/rJ2xLQu-p.png) * ![](https://hackmd.io/_uploads/BJbPUmOZa.png) Doing merging in this node directly can likely be implemented relatively efficiently, because we don't have to build a global kd tree. Instead, one can precompute what has to be merged per instance (or instance pair) and reuse that information everywhere. ## Root Corner The root corner determines how each polygon in the source mesh is mapped to the corresponding standard polygon (the one with the same number of vertices). This can be used to control the "rotation" of the replacement. ![](https://hackmd.io/_uploads/r1MkDm_Wa.png) ## Attribute Propagation Attributes are propagated from the source mesh as well as from the instances.