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

RFP: How should shape-specific APIs be exposed? #35

Open
codynova opened this issue Mar 17, 2020 · 6 comments
Open

RFP: How should shape-specific APIs be exposed? #35

codynova opened this issue Mar 17, 2020 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@codynova
Copy link
Member

codynova commented Mar 17, 2020

Some functions are specific to a shape class - for example, Cannon's ConvexPolyhedron shape has a transformAllPoints function which can be used to adjust the alignment axes for the shape. This function is useful for orienting physics bodies and meshes into the same axes.

I'm requesting proposals on how use-cannon should expose these shape-specific APIs? We can continue to add all available APIs to the object returned from useBody, but some (many?) of those will not actually be valid depending on which hook you are using.

Maybe we could have a generic API object with methods which are valid for all physics bodies, and spread spread that into a second API object that's generated based on the type of the shape (and maybe a third based on the body type if necessary)?

@codynova codynova added the question Further information is requested label Mar 17, 2020
@stockhuman
Copy link
Member

This is a great question - is the invalidity of various API for particular shapes a faux-pas, even if that invalidity makes perfect sense?

In the future I'd like to integrate V-HACD in a way that matches #6, which is probably better suited to the generated, shape-specific approach.

@codynova
Copy link
Member Author

codynova commented Mar 17, 2020

I would say it is a faux-pas. We would need to guard against users attempting to call functions which don't exist on certain classes to provide a remotely sane dev experience, and even then you'd get misleading intellisense. I think the generated approach makes more sense from a TypeScript perspective as well.

And now I'm off topic but wow, V-HACD looks incredible.

@codynova codynova self-assigned this Mar 17, 2020
@codynova
Copy link
Member Author

Related to #28

@drcmda
Copy link
Member

drcmda commented Mar 28, 2020

each hook could bring its own types, and makeapi could maybe take some kind of injection callback so that hooks can add their specific apis?

@drcmda
Copy link
Member

drcmda commented Mar 28, 2020

function useBody(
  type: BodyShapeType, 
  fn: BodyFn, 
  inject: (...) => any
  argFn: ArgFn, deps: any[] = []): Api {
    ...
    function makeApi(index?: number): WorkerApi {
      return {
        // Specific api
        ...inject(index, post, getUUID, makeVec),

@codynova
Copy link
Member Author

That sounds pretty ideal to me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants