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

Build 'Convex' shape in memory from vertices #22386

Open
Akshay5312 opened this issue Jan 3, 2025 · 3 comments
Open

Build 'Convex' shape in memory from vertices #22386

Akshay5312 opened this issue Jan 3, 2025 · 3 comments
Assignees
Labels
component: geometry general Geometry infrastructure or topics that defy categorization into other geometry components type: feature request

Comments

@Akshay5312
Copy link
Contributor

Is your feature request related to a problem? Please describe.
There is no straightforward way to create a general 'Convex' shape given vertices.This means that to visualize shapes generated during runtime, one needs to generate a mesh file in memory (MemoryFile(formatted_string_containing_vertices, ".OBJ", filename_hint)) then parse that file into a Convex object. This is inconvenient.

Describe the solution you'd like
As suggested by @jwnimmer-tri, a Convex::Convex(const Matrix3d& vertices, const std::string& filename_hint, double scale = 1.0) constructor would be great. This would also help implement a method to convert VPolytopes to Convex shapes to register VPolytopes as geometries.

@jwnimmer-tri jwnimmer-tri added the component: geometry general Geometry infrastructure or topics that defy categorization into other geometry components label Jan 3, 2025
@jwnimmer-tri
Copy link
Collaborator

jwnimmer-tri commented Jan 3, 2025

I imagine the best signature will be:

/** Creates a Convex shape from the convex hull of the given vertices,
 using an InMemoryMesh. */
explicit Convex(const Matrix3X<double>& vertices, std::string filename_hint = {}, const Vector3d& scale = Vector3d::Ones());

I think it's okay to default the hint to empty -- I don't think most users will need pass anything in since in most cases the Convex will be wrapped into a GeometryInstance with its own name.

For the scale we're moving towards non-isotropic scaling so I suggest Vector3d instead of double.

@Akshay5312
Copy link
Contributor Author

Akshay5312 commented Jan 3, 2025

For the scale we're moving towards non-isotropic scaling so I suggest Vector3d instead of double.

Currently, the Convex shape has a scalar 'scale' member (it is accessed and used otherwise as well). Changing this to a Vector3d would likely break a few things.

I could implement non-isotropic scaling by directly scaling the vertices before parsing them into a string?

@jwnimmer-tri
Copy link
Collaborator

Right. I imagined that for now, we would multiply the scale with vertices before making the wavefront string, and store scale_ = 1.0 internally. Then later once the member field is changed we could undo that. But maybe that's over-complicating things and we should just stick with scale double = 1.0 for now, and we can overload with a Vector3d constructor in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: geometry general Geometry infrastructure or topics that defy categorization into other geometry components type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants