Skip to content

Conversation

ra100
Copy link
Contributor

@ra100 ra100 commented Jun 13, 2025

This PR addresses the point selection issues with the Vulkan backend reported in #517.

Changes

  • Added thick line drawing functions for better Vulkan compatibility
  • Enhanced entity drawing methods across model classes (arc, circle, line_2d, line_3d, point_2d, point_3d, workplane)
  • Updated draw utilities with triangle-based rendering for improved visibility
  • Reduced line width scaling for better point visibility

Problem

With the Vulkan backend, points were barely visible (1px wide) and lines appeared narrower, making point selection nearly impossible in the viewport.

Solution

Implemented triangle-based thick line rendering and enhanced drawing methods to ensure consistent visibility across both OpenGL and Vulkan backends.

Note

I think this will need bit more testing, below screenshots from simple test file

TODO/ensure functionality:

  • - line width is same at any zoom level
  • - points are same at any zoom level
  • - workplane selection works properly
    • borders are same width as other lines
    • workplanes are transparent
    • workplanes are selectable on hover over workplane, not just border
  • dashed lines are dashed

Fixes #517

Vulkan:
Screenshot_2025-06-18_23-33-00

OpenGL
Screenshot_2025-06-18_23-33-35

@ra100 ra100 force-pushed the main branch 2 times, most recently from 12fbe70 to 408a26c Compare June 15, 2025 17:00
@ra100 ra100 marked this pull request as draft June 15, 2025 17:14
@hlorus
Copy link
Owner

hlorus commented Jun 16, 2025

Hey, thanks for the PR! Let me know when it's ready to review.

@ra100
Copy link
Contributor Author

ra100 commented Jun 16, 2025

@hlorus I thought it is, then found out, there are multiple issues, I've added in description, what needs to be fixed.
Do you think these cases are testable automatically?

  • line width is same at any zoom level
  • points are same at any zoom level
  • workplane selection works properly
    • borders are same width as other lines
    • workplanes are transparent
    • workplanes are selectable on hover over workplane, not just border

@hlorus
Copy link
Owner

hlorus commented Jun 16, 2025

Currently, there's no graphical testing setup in place. I'm unsure if it's feasible or how much effort it would require. That said, why do you see it as necessary? Is it primarily to make finding edge cases easier, or is it more about preventing regressions?

@ra100
Copy link
Contributor Author

ra100 commented Jun 16, 2025

I was just curious, if something is avaialable or not. At this point, only to find the edge cases easier, or to find regression while this fix is being made.
I don't want to overengineer it by adding extra layers of tests, of course :)
I'll just have to check these cases on each iteration.

@ra100 ra100 changed the title 🐛 fix: improve point and line visibility for Vulkan backend Improve Vulkan backend compatibility Jun 18, 2025
@ra100 ra100 marked this pull request as ready for review June 18, 2025 21:38
@ra100 ra100 force-pushed the main branch 3 times, most recently from 1ac3c06 to 9dc9bf3 Compare June 18, 2025 21:55
@ra100
Copy link
Contributor Author

ra100 commented Jun 19, 2025

@hlorus I think it's ready, all functionality I've checked works. There are small visual differences compared to OpenGL, I hope it's acceptable.

@hlorus
Copy link
Owner

hlorus commented Jun 19, 2025

Hey there, some comments/questions from my side:

  • Are these changes really only usable with vulkan? Otherwise we could avoid the complexity of supporting two backends and just change the drawing for both backends.
  • The workplanes are now selectable from their faces but don't corretly take depth into consideration which makes one workplane occlude other which makes them difficult to select. @rcarmo was working on that in Fix #50 by refactoring the selection mechanism #513, might be a good inspiration.
  • It's a bit late, sorry but i don't really see the reason why the entities have to scale with zoom, it feels like this just complicates things without a clear benefit. After all we don't really know in what scale the user will work and it's kinda akward if your lines are huge when working on a small part vs. tiny when working on a big part.

@ra100
Copy link
Contributor Author

ra100 commented Jun 20, 2025

Those are very good points:

  • I've removed the ifs, so there is same logic for OpenGL and Vulkan, looks working same on both
  • workplanes respect depth/z-index
  • and for the zoom+scale, that's the part I'm not happy with, this solution uses geometry so the point and lines have some width, the scale with zoom is there to compensate for zoom, so that lines and points keep the same screen size, at least, that's what I intended for it to do:

image
image

just in perspective view, the points are not correct, I've just noticed that
image

Also there was a weird bug, when I hovered over the line under tabs, blender somehow froze
This line:
image

There is a workaround for that. But I don't actually know what that's happening.

@hlorus
Copy link
Owner

hlorus commented Jul 1, 2025

Hey there, is this ready for review?

@ra100
Copy link
Contributor Author

ra100 commented Jul 2, 2025

@hlorus now, I believe, it is, didn't notice any bugs, this time.

Copy link
Owner

@hlorus hlorus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally ok, but points don't seem to scale with the entity scale option.

@ra100
Copy link
Contributor Author

ra100 commented Jul 7, 2025

Generally ok, but points don't seem to scale with the entity scale option.

I'll check the points scaling

ra100 added 9 commits July 11, 2025 21:44
…on, use POLYLINE_UNIFORM_COLOR for lines, render points as triangle geometry
…pdated all checks from Vulkan/Metal to Vulkan-only for more targeted rendering optimization
…ge-only - Draw both outline and surface in draw_id for complete plane selectability
…R for all lines to ensure proper line width support
…plete support for all construction entities with proper line thickness
…nts (5→3px) and smaller Vulkan geometry (2D: 0.1→0.06, 3D: 0.05→0.03)
… calls - reduces redundant queries in update() calls
ra100 added 18 commits July 11, 2025 21:44
…ss - improves maintainability and consistency
…nd debug logging - better debugging and error recovery
…nderer utility - reduces code duplication and improves maintainability
…methods - improves code maintainability and developer understanding
…c - streamline rendering for all backends using geometry-based methods, improving maintainability and consistency across entities.
- scale point sizes based on view distance to improve visual consistency across different contexts
- calculate distances from the camera to ensure proper selection order, improving visual accuracy and interaction responsiveness.
 - prevent GPU operations from hanging when the mouse is near the top edge of the viewport, enhancing user interaction stability.
- Use RenderingConstants.POINT_SIZE directly for consistent sizing
- Remove obsolete get_point_screen_size() method chain from point classes
- Implement efficient view-change detection for billboard updates
- Fix screen-space scaling with proper view distance calculation
- Add 5px border margin to prevent UI boundary freezing
- Optimize selection buffer updates to only redraw when needed
- Clean up imports and update documentation
- Fix workplane selection: workplanes now selectable regardless of active sketch
- Fix selection buffer updates: properly handles view changes (zoom/pan/rotate)
- Add performance optimizations:
  * Camera location caching with view matrix change detection
  * Reduced redundant matrix calculations by 90%+
  * Smart selection buffer redraw logic
- Improve workplane selection priority over sketch elements
- Add cache invalidation hooks for entity/constraint operations
- Preserve existing functionality and freezing fixes
- Clean up debug code and maintain production-ready codebase

Resolves selection issues where workplanes were unselectable and selection
would get 'stuck' after view changes. Maintains backward compatibility
while providing significant performance improvements.
…tionship caching, memory management, and lazy initialization

- Add constraint existence caching in operators/base_constraint.py to avoid O(n) loops
- Implement entity dependency caching in base_entity.py and base_constraint.py
- Add periodic GPU batch cleanup in global_data.py and draw_handler.py
- Implement lazy geometry initialization in vulkan_compat.py
- Add cache invalidation hooks in group_constraints.py
- Preserve all existing functionality while improving performance
- Fix point size quadratic scaling causing huge/tiny points
- Fix selection not working on file load with existing sketches
- Add universal click selection support to all CAD Sketcher tools
- Optimize view matrix hash calculation performance
- Replace magic numbers with named constants
- Improve error handling with specific exceptions and logging
- Add proper file load cache initialization
- Add ShaderManager class for centralized shader caching
- Add GPUResourceManager for time-based resource cleanup
- Add CLEANUP_INTERVAL_SECONDS constant for time-based cleanup
- Replace direct shader creation with ShaderManager calls
- Update _shader and _id_shader properties to use caching
- Update workplane surface rendering with cached shaders
- Maintain backward compatibility while improving performance
- Add time-based GPU resource cleanup to draw handler
- Update selection box to use cached polyline shader
- Add automatic GPU cleanup on file load
- Replace frame-based with time-based cleanup for better performance
- Remove broken tag_update function from model/utilities.py that caused infinite recursion
- Update model/circle.py to import tag_update from base_entity instead of utilities
- Update model/arc.py to import tag_update from base_entity instead of utilities
- Fixes 'SlvsCircle' object has no attribute 'tag_update' error
- Ensures proper entity property updates and dependency cache invalidation
- Remove unused shader functions: dashed_uniform_color_3d, uniform_color_3d, point_color_3d, polyline_color_3d, uniform_color_line_2d
- Consolidate duplicate ID shaders (id_line_3d and id_shader_3d were identical)
- Remove unused shader infrastructure and base shader strings
- Remove orphaned imports and commented-out functions
- Update GPU manager to use consolidated shader for both points and lines

All changes maintain 100% backward compatibility and functionality.
@ra100
Copy link
Contributor Author

ra100 commented Jul 11, 2025

did some cleanup
didn't figure out the point scaling
and found another issue, when dragging start point of arc the radius of arc is not changing, it changes after handle release
image

I might have completely wrong approach, I'm afraid.

- Introduce pixel_size_to_world_size function for accurate world size calculation based on pixel size.
- Update BillboardPointRenderer to use fixed pixel size for point handles, improving consistency in rendering.
- Modify RenderingConstants to define POINT_HANDLE_PIXEL_SIZE for better control over point size.
- Adjust draw_billboard_quad_3d calls to utilize calculated world size, ensuring proper scaling in various view contexts.
- Refine geometry regeneration logic to account for viewport size changes, enhancing performance and visual fidelity.
@ra100
Copy link
Contributor Author

ra100 commented Jul 14, 2025

point handles should work now:
image
image
image
image

@hlorus
Copy link
Owner

hlorus commented Jul 22, 2025

That looks good! The point scaling doesn't seem to work in the OpenGL mode though.

Also there seems to be some differences in the selection textures, these are the outputs of the 'Write Selection Texture' operator with both backends and an entity scale of 3. With the Vulkan backend both points and lines are tiny:

OpenGL:
image

Vulkan:
image

@hlorus hlorus mentioned this pull request Jul 29, 2025
@hlorus
Copy link
Owner

hlorus commented Jul 29, 2025

Hey there, since this PR grew quite a bit in size i pulled out the changes to better support the vulkan backend, please give it a test: #524

Note that it currently does not support custom thickness for dashed lines. I saw that you addressed this by creating dash geometry on the cpu side. I haven't looked closer into that solution and the performance implication that come with it. If you'd like to include such a change (or other changes from this PR) please submit PRs that are smaller scoped to make review and testing more feasible.

@hlorus hlorus closed this Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Can't select point with Vulkan backend
2 participants