Replies: 5 comments
-
Hi. Thanks for the report and thanks for the detailed description 🙏 I think it makes sense, therefore I didn't debug it, but I'll do that if you don't buy my explanation 🙂 So So that's what I think happens, to verify, you can print the pixel positions and see if they go crazy when you have issues. You can see the math here if you're interested, the problem arrises when you try to project the point onto the image plane. To fix it, I think you need to ensure that your 3D end points are relatively inside the viewport of the camera before using the |
Beta Was this translation helpful? Give feedback.
-
Yeah, that makes sense. I did see some pixel position values going crazy while debugging, like you mention. We were trying to use relatively long lines in 3D space to make a grid covering the 'ground' over a large space. But that means that the endpoints of any given line are usually far outside of the viewport. Maybe I can flip things around a bit and use the methods you have to first get the extents of the 3d locations currently in the viewport, and then just draw the relevant lines based on those extents, so they don't extend too far past what's visible |
Beta Was this translation helpful? Give feedback.
-
I think that sounds like a good plan 👍 Do you have any luck so far? |
Beta Was this translation helpful? Give feedback.
-
This wasn't quite as straightforward as I had thought. I think I would need to clip the 3d lines to the extents of the view frustum, but not sure offhand how to do that. I see there is an in_frustum method in the three_d camera, but that's just a true/false on whether a bounding box is in the frustum. I would need something that gets the 3d intersection point(s) of a line and any of the frustum planes. And then would need to update those and re-draw the lines every frame when the camera moves. At that point I'm not sure we're in a better place than drawing 3d cylinders and updating the width every frame based on camera distance to approximate fixed-width. I see from: asny/three-d#310 that there is an option in OpenGL for doing these kinds of fixed-width lines. Any possibility of adding that as an option to three-d? |
Beta Was this translation helpful? Give feedback.
-
Yeah, graphics can be hard 🙂
It's just line/plane intersection and you don't need to do it for all 6 sides of the frustum, the only plane that matters is the near plane. So just stop your line where the line intersects the near plane and you should be good 🙂
That's also an option, but I don't think it will perform better if that's what you think and getting the screen space width of the line correct is not easy.
Oh I get that question a lot 😆 But it's still no. Drawing lines with OpenGL is legacy functionality so it's not necessarily supported by all hardware and even if it is, it might be poorly implemented. |
Beta Was this translation helpful? Give feedback.
-
Related to this discussion: asny/three-d#310
We've been using the new
pixel_at_position
method to convert 3D world coordinate lines into 2D screen coordinates updated every frame, and then drawing them with a 2D camera. For example, to draw a reference grid on the ground, and keep line width the same regardless of distance from camera. This works fine when the camera is relatively far away from the lines, but when the camera gets closer, the projection starts to get wacky. Some example snapshots below. Not sure if we're just not using the feature correctly, or if something else is going on.Examples that look ok, with the camera further back:
Examples that get weird, with the camera closer in:
I made some minimal changes to the shapes example that show the issue. Here's the diff. Basically just creating some 3d lines (start and end points in 3d, where I want them) that form a uniform grid at Z=0. And then in each frame of the render loop converting that into a set of 2d Lines, calling the pixel_at_position method on each to get the screenspace 2D start and end coordinates, and then rendering those.
Beta Was this translation helpful? Give feedback.
All reactions