Skip to content

Rendering functions does not accept custom Vec3 #6

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

Closed
NicEastvillage opened this issue Oct 8, 2024 · 5 comments
Closed

Rendering functions does not accept custom Vec3 #6

NicEastvillage opened this issue Oct 8, 2024 · 5 comments

Comments

@NicEastvillage
Copy link
Contributor

A QoL feature of v4 is that it is very robust. In v4, all the rendering functions accepts custom vector objects. It just requires that the passed object had x, y, z attributes or was a 3-element list/sequence of numbers. It would be nice if this robustness returns for v5, especially for custom vector types, so you don't have to convert into flat.Vector3 each time.

@VirxEC
Copy link
Collaborator

VirxEC commented Oct 8, 2024

It should work if the type extends the flat.Vector3 class. As for just accepting any vector type with a defined x, y, & z field, I'm not sure how to annotate that in the type system (as imo the proper way to do that would be to extend flat.Vector3).

I do have this example of extending the flat.Vector3 class to add support for the + & * operators: https://github.com/VirxEC/python-interface/blob/140e30a2fb78305733cc2da5cf7786e1e56117cf/tests/render_fun/render_mesh.py#L10-L15

@NicEastvillage
Copy link
Contributor Author

Okay. I will try that. If there is no performance penalty of the flat struct then that is a fine solution.

@NicEastvillage
Copy link
Contributor Author

Looks like I can't have a custom constructor. But works otherwise!

@VirxEC
Copy link
Collaborator

VirxEC commented Oct 10, 2024

PyO3/pyo3#1644

@VirxEC
Copy link
Collaborator

VirxEC commented Oct 10, 2024

Basically, this should work:

class SubclassWithExtraInitArguments(SubclassableWithParameter):
    def __new__(cls, bar):
        print("before super new")
        return super().__new__(cls, foo=bool(bar))

    def __init__(self, bar):
        print("before super init")
        super().__init__()

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