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

How to access material:binding relation from GeomSubset object? #50

Closed
xahon opened this issue Dec 7, 2022 · 8 comments
Closed

How to access material:binding relation from GeomSubset object? #50

xahon opened this issue Dec 7, 2022 · 8 comments

Comments

@xahon
Copy link

xahon commented Dec 7, 2022

I didn't find an API to get material binding relation like from GeomMesh object with materialBinding field

@syoyo syoyo closed this as completed Dec 7, 2022
@syoyo
Copy link
Collaborator

syoyo commented Dec 7, 2022

If you are looking for materialBind info from GeomSubset, not GeomMesh, currently handy API is not provided. You may find it through generic Property field GeomSubset::props https://github.com/syoyo/tinyusdz/blob/41970d1aa8dd94e754c95e78ac159afe93c74337/src/usdGeom.hh#L388

@xahon
Copy link
Author

xahon commented Dec 7, 2022

@syoyo props field is empty in my case. Looks like a bug then

@syoyo
Copy link
Collaborator

syoyo commented Dec 7, 2022

@xahon
Copy link
Author

xahon commented Dec 7, 2022

I'd like to contribute but I still can't understand how GeomSubset was intended to work. Pixar's API reference for that type is kind of vague and I found no clear description of Mesh and GeomSubset. I have an ascii model definition with that structure:

-  type Mesh
   points, normals, indices
   -  type GeomSubset
      indices
   -  type GeomSubset
      indices

And some indices from both GeomSubsets are out of bounds if they are used as indices in Mesh's points array. I think GeomSubset is for defining a submesh but then why Mesh contains indices at all.

@syoyo syoyo reopened this Dec 7, 2022
@syoyo
Copy link
Collaborator

syoyo commented Dec 7, 2022

I'd like to contribute

👍

I still can't understand how GeomSubset was intended to work

Yeah! Even me :-)

It'd be first look at this:

PixarAnimationStudios/OpenUSD#542
https://github.com/PixarAnimationStudios/USD/tree/release/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLGeomSubsets

In basic GeomSuset configuration, GeomSubset::indices are indices of face id in its parent's GeomMesh::faceVertexIndices, not array index of GeomMesh::points, since GeomSubset is usually for representing per-face materials of GeomMesh.

@xahon
Copy link
Author

xahon commented Dec 12, 2022

I found out that indices in GeomSubset are not indices at all. It's a face offset in main Mesh indices array. I mean that if you have (Pseudo USD)

Mesh:
    faceVertexCounts = [4, 4, 4, 4]
    faceVertexIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
   
    GeomSubset:
        indices = [3]

Then you want to access indices at faceVertexIndices[sum(faceVertexCounts[0], faceVertexCounts[3])] with subarray length of faceVertexCounts[3]

In other words to access Nth GeomSubset's face you want to calculate:

size_t offset = 0;
for (size_t i = 0; i < N; i++) offset += faceVertexIndices[i];
uint32_t *faceIndices = faceVertexIndices[offset];
size_t faceIndicesCount = faceVertexCounts[N];

I made a helper structure that firstly builds an array of polygon data in O(N) in my user code, then I can easily triangulate them into my custom mesh format

If you first build a faces array then GeomSubset indices will be indices into that array

@syoyo
Copy link
Collaborator

syoyo commented May 10, 2024

MaterialBinding API is finally supported in dev branch.

You can look into https://github.com/syoyo/tinyusdz/blob/dev/src/tydra/render-data.cc for how to use it.
It also contains how to process indices in GeomSubset(e.g. rebuild indices in GeomSubset in trinangulation)

@syoyo syoyo closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants