Commit 42e3360a authored by Lázár Bence Kis's avatar Lázár Bence Kis
Browse files

Skinned box buffer generator refactored into separate method

parent 08ec1bee
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ struct BufferGenerators final : public com::Library

    Buffer* insert_procedural_box_solid(vec3 const& half_sizes_along_axes, std::string const& name, com::ContextPath const& sub_folders);
    Buffer* insert_procedural_box_wireframe(vec3 const& half_sizes_along_axes, std::string const& name, com::ContextPath const& sub_folders);
    Buffer* insert_procedural_box_skinned(vec3 const& half_sizes_along_axes, std::string const& name, com::ContextPath const& sub_folders);

    Buffer* insert_procedural_sphere_solid(
        scalar const radius,
+28 −18
Original line number Diff line number Diff line
@@ -626,24 +626,6 @@ Buffer* BufferGenerators::insert_procedural_box_solid(
        // face yz, x-max
        20U, 21U, 22U,  20U, 22U, 23U,
    });

    std::vector<vec4u> bone_ids(24, { 0U, 1U, 0U, 0U });
    buffer->insert_bones(bone_ids);

    std::unordered_set<unsigned> bottom_side_indices{0, 1, 2, 3, 8, 9, 12, 13, 16, 17, 20, 21};
    
    std::vector<vec4> bone_weights;
    bone_weights.reserve(24);

    constexpr vec4 bottom_weight{1.f, 0.f, 0.f, 0.f};
    constexpr vec4 top_weight{0.f, 1.f, 0.f, 0.f};

    for (unsigned i = 0; i < 24U; ++i)
    {
        bone_weights.push_back(bottom_side_indices.contains(i) ? bottom_weight : top_weight);
    }
    buffer->insert_weights(bone_weights);

    return buffer;
}

@@ -673,6 +655,34 @@ Buffer* BufferGenerators::insert_procedural_box_wireframe(
    return buffer;
}

Buffer* BufferGenerators::insert_procedural_box_skinned(
    vec3 const& half_sizes_along_axes,
    std::string const& name,
    com::ContextPath const& sub_folders
    )
{
    Buffer* const buffer = insert_procedural_box_solid(half_sizes_along_axes, name, sub_folders);

    std::vector<vec4u> bone_ids(24, { 0U, 1U, 0U, 0U });
    buffer->insert_bones(bone_ids);

    std::unordered_set<unsigned> bottom_side_indices{0, 1, 2, 3, 8, 9, 12, 13, 16, 17, 20, 21};
    
    std::vector<vec4> bone_weights;
    bone_weights.reserve(24);

    constexpr vec4 bottom_weight{1.f, 0.f, 0.f, 0.f};
    constexpr vec4 top_weight{0.f, 1.f, 0.f, 0.f};

    for (unsigned i = 0; i < 24U; ++i)
    {
        bone_weights.push_back(bottom_side_indices.contains(i) ? bottom_weight : top_weight);
    }
    buffer->insert_weights(bone_weights);

    return buffer;
}

Buffer* BufferGenerators::insert_procedural_sphere_solid(
    scalar const radius,
    std::uint8_t const num_lines_per_quarter_of_circle,