Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 3D projection onto canvas #396

Open
very-meanly opened this issue Aug 13, 2023 · 4 comments
Open

Support 3D projection onto canvas #396

very-meanly opened this issue Aug 13, 2023 · 4 comments

Comments

@very-meanly
Copy link

very-meanly commented Aug 13, 2023

I often initially create designs in Processing, and then rewrite the code in Python using vsketch if I want to plot it with fills. One of the convenient aspects of Processing is that it supports a 3D renderer that can do both orthographic and perspective projections. When I try to adapt the digital design for a plot in vsketch (fills are not supported in Processing's SVG renderer), it is difficult to achieve the same appearance since vsketch does not support 3 dimensions.

While it is trivial to do orthographic projection from 3D points in vsketch, perspective projection is a bit trickier unless you're already familiar with how to do this. Having a method that accepts x/y/z coordinates and a field of view and then returns the point's projection onto the 2D surface formed by the canvas would open up interesting possibilities for plots without having to support full 3D rendering across vsketch's entire suite of methods.

@very-meanly
Copy link
Author

I have a working implementation of this in code but it is really dirty because I customized it to my needs. :) I should be able to write a more generalized version of this using vsketch's conventions though. Here's an example of the plot in both orthographic and perspective projections:

Orthographic
Screen Shot 2023-08-13 at 11 00 41 PM

Perspective
Screen Shot 2023-08-13 at 10 59 52 PM

@abey79
Copy link
Owner

abey79 commented Aug 14, 2023

Cool! 🤩

A good was to go about this would be to discuss the APIs before spending too much time fine-tuning the implementation. That can be done here or in a draft PR.

@very-meanly
Copy link
Author

very-meanly commented Aug 14, 2023

@abey79 Yep, I definitely will do a draft PR and then can adjust from there based on any feedback! One thought - this is something that could feasibly be implemented in vpype. Is there any precedent for doing an implementation in both projects? Like, have you ever implemented something in vpype and then added wrappers in vsketch as a convenience method so that the end user doesn’t have to call the vpype method directly? I gotta learn to stop commenting on issues before I’ve had coffee. Realized that wouldn’t work since vpype wouldn’t have access to z-index data.

@abey79
Copy link
Owner

abey79 commented Aug 14, 2023

Well, vsketch is based on and uses vpype, so yes, anything that's in vpype can be used in vsketch. This can happen in two ways:

  • Functionality is implemented in the vpype package (the core library) with a proper public API => can be used by any client code, vsketch included. Typically, a vsketch wrapper API is needed to make the feature more vsketch-esque.
  • Functionality is implemented as vpype command in the vpype_cli package, then it is automatically available in vsketch through vsk.vpype() (though this typically isn't the most ergonomic).

BTW, if you haven't yet, you might take a look at https://github.com/abey79/vpype-perspective and https://github.com/abey79/lines.

There is an alternative avenue that you might consider that would arguably be more practical. You could work on a standalone python package, publish it, and use it in vsketch sketches. If your package produces a bunch of numpy arrays of complexes, then it's a matter of calling vsk.polygon() on them. Your package could certainly depend on vpype if some of the stuff there is useful to you (e.g. cropping, etc.). Also, this wouldn't preclude some form of tighter integration with vsketch down the line if/when things are more mature.

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

No branches or pull requests

2 participants