/// Compute a directional weight for each vertex to be used for the morph operation.
Compute a directional weight for each vertex to be used for the morph operation.
Compute a directional weight for each vertex to be used for the morph operation .
fn compute_weights(mesh: &Mesh, start_vertex_id: VertexID, start_point: &Vec3) -> HashMap<VertexID, Vec3>
{
    static SQR_MAX_DISTANCE: f64 = 1.0;
    // Use the smoothstep function to get a smooth morphing
    let smoothstep_function = |sqr_distance| {
        let x = sqr_distance / SQR_MAX_DISTANCE;
        1.0 - x*x*(3.0 - 2.0 * x)
    };
    // Visit all the vertices close to the start vertex.
    let mut weights = HashMap::new();
    let mut to_be_tested = vec![start_vertex_id];
    while let Some(vertex_id) = to_be_tested.pop()
    {
        let sqr_distance = start_point.distance2(mesh.vertex_position(vertex_id));
        if sqr_distance < SQR_MAX_DISTANCE
        {
            // The weight is computed as the smoothstep function to the square euclidean distance
            // to the start point on the surface multiplied by the vertex normal.
            weights.insert(vertex_id, smoothstep_function(sqr_distance) * mesh.vertex_normal(vertex_id));
            // Add neighbouring vertices to be tested if they have not been visited yet
            for halfedge_id in mesh.vertex_halfedge_iter(vertex_id)
            {
                let neighbour_vertex_id = mesh.walker_from_halfedge(halfedge_id).vertex_id().unwrap();
                if !weights.contains_key(&neighbour_vertex_id) {
                    to_be_tested.push(neighbour_vertex_id);
                }
            }
        }
    }
    weights
}
fn compute_weights ( mesh : & Mesh , start_vertex_id : VertexID , start_point : & Vec3 ) -> HashMap < VertexID , Vec3 > { static SQR_MAX_DISTANCE : f64 = 1.0 ; // Use the smoothstep function to get a smooth morphing let smoothstep_function = | sqr_distance | { let x = sqr_distance / SQR_MAX_DISTANCE ; 1.0 - x * x * ( 3.0 - 2.0 * x ) } ; // Visit all the vertices close to the start vertex. let mut weights = HashMap :: new ( ) ; let mut to_be_tested = vec ! [ start_vertex_id ] ; while let Some ( vertex_id ) = to_be_tested . pop ( ) { let sqr_distance = start_point . distance2 ( mesh . vertex_position ( vertex_id ) ) ; if sqr_distance < SQR_MAX_DISTANCE { // The weight is computed as the smoothstep function to the square euclidean distance // to the start point on the surface multiplied by the vertex normal. weights . insert ( vertex_id , smoothstep_function ( sqr_distance ) * mesh . vertex_normal ( vertex_id ) ) ; // Add neighbouring vertices to be tested if they have not been visited yet for halfedge_id in mesh . vertex_halfedge_iter ( vertex_id ) { let neighbour_vertex_id = mesh . walker_from_halfedge ( halfedge_id ) . vertex_id ( ) . unwrap ( ) ; if ! weights . contains_key ( & neighbour_vertex_id ) { to_be_tested . push ( neighbour_vertex_id ) ; } } } } weights }
Compute a directional weight for each vertex to be used for the morph operation.
Compute a directional weight for each vertex to be used for the morph operation .
mesh
&Mesh
start_vertex_id
VertexID
start_point
&Vec3