示例#1
0
ItemBase* ScenePickingHandler::pick(const QPoint& point)
{
    if (!m_project.has_trace_context())
    {
        RENDERER_LOG_INFO("the scene must be rendering or must have been rendered at least once for picking to be available.");
        return 0;
    }

    const Vector2i pix = m_mouse_tracker.widget_to_pixel(point);
    const Vector2d ndc = m_mouse_tracker.widget_to_ndc(point);

    const ScenePicker scene_picker(m_project);
    const ScenePicker::PickingResult result = scene_picker.pick(ndc);

    stringstream sstr;

    sstr << "picking details:" << endl;
    sstr << "  pixel coords     " << pix.x << ", " << pix.y << endl;
    sstr << "  ndc coords       " << ndc.x << ", " << ndc.y << endl;
    sstr << "  world coords     " << result.m_point.x << ", " << result.m_point.y << ", " << result.m_point.z << endl;
    sstr << "  depth            " << result.m_distance << endl;
    sstr << "  primitive type   " << get_primitive_type_name(result.m_primitive_type) << endl;

    sstr << print_entity("  camera           ", result.m_camera) << endl;
    sstr << print_entity("  assembly inst.   ", result.m_assembly_instance) << endl;
    sstr << print_entity("  assembly         ", result.m_assembly) << endl;
    sstr << print_entity("  object inst.     ", result.m_object_instance) << endl;
    sstr << print_entity("  object           ", result.m_object) << endl;
    sstr << print_entity("  material         ", result.m_material) << endl;
    sstr << print_entity("  surface shader   ", result.m_surface_shader) << endl;
    sstr << print_entity("  bsdf             ", result.m_bsdf) << endl;
    sstr << print_entity("  bssrdf           ", result.m_bssrdf) << endl;
    sstr << print_entity("  edf              ", result.m_edf);

    RENDERER_LOG_INFO("%s", sstr.str().c_str());

    emit signal_entity_picked(result);

    const QString picking_mode =
        m_picking_mode_combo->itemData(m_picking_mode_combo->currentIndex()).value<QString>();
    const Entity* picked_entity = get_picked_entity(result, picking_mode);

    ItemBase* item;

    if (picked_entity)
    {
        item = m_project_explorer.select_entity(picked_entity->get_uid());
    }
    else
    {
        m_project_explorer.clear_selection();
        item = 0;
    }

    m_widget->setFocus();

    return item;
}
ItemBase* ScenePickingHandler::pick(const QPoint& point)
{
    if (!m_project.has_trace_context())
    {
        RENDERER_LOG_INFO("the scene must be rendering or must have been rendered at least once for picking to be available.");
        return nullptr;
    }

    const Vector2i pix = m_mouse_tracker.widget_to_pixel(point);
    const Vector2d ndc = m_mouse_tracker.widget_to_ndc(point);

    const ScenePicker scene_picker(m_project);
    const ScenePicker::PickingResult result = scene_picker.pick(ndc);

    stringstream sstr;

    sstr << "picking details:" << endl;

    sstr << "  pixel coordinates             " << pix << endl;
    sstr << "  ndc coordinates               " << ndc << endl;
    sstr << "  primitive type                " << get_primitive_type_name(result.m_primitive_type) << endl;
    sstr << "  distance                      " << result.m_distance << endl;

    sstr << "  barycentric coordinates       " << filter_neg_zero(result.m_bary) << endl;
    sstr << "  uv coordinates                " << filter_neg_zero(result.m_uv) << endl;
    sstr << "  duvdx                         " << filter_neg_zero(result.m_duvdx) << endl;
    sstr << "  duvdy                         " << filter_neg_zero(result.m_duvdy) << endl;
    sstr << "  point                         " << filter_neg_zero(result.m_point) << endl;
    sstr << "  dpdu                          " << filter_neg_zero(result.m_dpdu) << endl;
    sstr << "  dpdv                          " << filter_neg_zero(result.m_dpdv) << endl;
    sstr << "  dndu                          " << filter_neg_zero(result.m_dndu) << endl;
    sstr << "  dndv                          " << filter_neg_zero(result.m_dndv) << endl;
    sstr << "  dpdx                          " << filter_neg_zero(result.m_dpdx) << endl;
    sstr << "  dpdy                          " << filter_neg_zero(result.m_dpdy) << endl;
    sstr << "  geometric normal              " << filter_neg_zero(result.m_geometric_normal) << endl;
    sstr << "  shading normal                " << filter_neg_zero(result.m_original_shading_normal) << endl;
    sstr << "  side                          " << get_side_name(result.m_side) << endl;

    sstr << print_entity("  camera                        ", result.m_camera) << endl;
    sstr << print_entity("  assembly instance             ", result.m_assembly_instance) << endl;
    sstr << print_entity("  assembly                      ", result.m_assembly) << endl;
    sstr << print_entity("  object instance               ", result.m_object_instance) << endl;
    sstr << print_entity("  object                        ", result.m_object) << endl;
    sstr << print_entity("  material                      ", result.m_material) << endl;
    sstr << print_entity("  surface shader                ", result.m_surface_shader) << endl;
    sstr << print_entity("  bsdf                          ", result.m_bsdf) << endl;
    sstr << print_entity("  bssrdf                        ", result.m_bssrdf) << endl;
    sstr << print_entity("  edf                           ", result.m_edf);

    RENDERER_LOG_INFO("%s", sstr.str().c_str());

    emit signal_entity_picked(result);

    const QString picking_mode =
        m_picking_mode_combo->itemData(m_picking_mode_combo->currentIndex()).value<QString>();
    const Entity* picked_entity = get_picked_entity(result, picking_mode);

    ItemBase* item;

    if (picked_entity)
    {
        item = m_project_explorer.select_entity(picked_entity->get_uid());
    }
    else
    {
        m_project_explorer.clear_selection();
        item = nullptr;
    }

    m_widget->setFocus();

    return item;
}