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

pxr.Gf.Vec3f can be convinced to return a pointer to its float array as a (clearly bogus) string #1290

Closed
marktucker opened this issue Aug 12, 2020 · 3 comments

Comments

@marktucker
Copy link
Contributor

Description of Issue

Trying to cast a Gf.Vec3f to a float in python causes the Gf.Vec3f's floating point data to be interpreted as a string. I'm sure this applies to lots of other types of data casting, and lots of other pxr classes (at least within Gf). I don't really understand the mechanism here, since calling str() on a Gf.Vec3f generates a reasonable string representation of the data.

Steps to Reproduce

  1. Run the following python code:
    rom pxr import Gf
    vec = Gf.Vec3f(34.56, 78.91, 23.45)
    f = float(vec)
    print f
  2. This produces the following output:
    Traceback (most recent call last):
    File "converttofloat.py", line 4, in
    f = float(vec)
    ValueError: could not convert string to float: q=
    B�ѝB���A

System Information (OS, Hardware)

Tested on Linux and Windows

Package Versions

USD 20.08

@jtran56
Copy link

jtran56 commented Aug 13, 2020

Filed as internal issue #USD-6284

@gitamohr
Copy link
Contributor

gitamohr commented Sep 4, 2020

I have mixed news on this one. I checked in a fix for how we implemented Python's buffer protocol for Python 2 for these types. It makes these examples raise TypeError, which seems good.

However, some Python 3 builtins like int() will just blindly attempt to treat bytes from objects that support the buffer protocol as string characters, ignoring what the actual data format is. I filed a Python bug for this, https://bugs.python.org/issue41707

When (if?) that Python bug gets fixed, that should resolve this for Python 3.

@monajalal
Copy link

I have an array of corner pairs (min and max from 3D BB). How can I get the minimum and maximum corners from this array? each corner is in gf vec3d format.

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

5 participants