示例#1
0
void Mesh::enable_debug(bool value) {
    if(value) {
        if(normal_debug_mesh_) return;

        //This maintains a lock on the material
        MaterialID mid = resource_manager().new_material();

        resource_manager().window->loader_for(
            "material_loader",
            Material::BuiltIns::DIFFUSE_ONLY
        )->into(resource_manager().material(mid));

        normal_debug_mesh_ = new_submesh_with_material("__debug__", mid, MESH_ARRANGEMENT_LINES, VERTEX_SHARING_MODE_INDEPENDENT);

        //Go through the submeshes, and for each index draw a normal line
        each([=](const std::string& name, SubMesh* mesh) {
            for(uint16_t idx: mesh->index_data->all()) {
                Vec3 pos1 = mesh->vertex_data->position_at<Vec3>(idx);

                Vec3 n;
                mesh->vertex_data->normal_at(idx, n);
                kmVec3Scale(&n, &n, 10.0);

                kmVec3 pos2;
                kmVec3Add(&pos2, &pos1, &n);

                normal_debug_mesh_->vertex_data->position(pos1);
                normal_debug_mesh_->vertex_data->diffuse(smlt::Colour::RED);
                int16_t next_index = normal_debug_mesh_->vertex_data->move_next();
                normal_debug_mesh_->index_data->index(next_index - 1);

                normal_debug_mesh_->vertex_data->position(pos2);
                normal_debug_mesh_->vertex_data->diffuse(smlt::Colour::RED);
                next_index = normal_debug_mesh_->vertex_data->move_next();
                normal_debug_mesh_->index_data->index(next_index - 1);
            }
        });

        normal_debug_mesh_->vertex_data->done();
        normal_debug_mesh_->index_data->done();
    } else {
        if(normal_debug_mesh_) {
            delete_submesh(normal_debug_mesh_->name());
            normal_debug_mesh_ = nullptr;
        }
    }
}
示例#2
0
void Debug::update() {
    double dt = stage_.window().delta_time();

    std::vector<DebugElement> to_keep;

    for(auto elem: elements_) {
        elem.time_since_created += dt;
        if(elem.time_since_created >= elem.duration) {
            auto mesh = stage_.mesh(mesh_);
            mesh->delete_submesh(elem.submesh);
        } else {
            to_keep.push_back(elem);
        }
    }

    elements_ = to_keep;
}