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

Adding function to export scenes as glTF #630

Merged
merged 17 commits into from Aug 18, 2022

Conversation

xtanion
Copy link
Member

@xtanion xtanion commented Jul 17, 2022

This PR adds the ability to convert a scene as gltf file and can be loaded back using glTF loader (added in #600 ).

@pep8speaks
Copy link

pep8speaks commented Jul 17, 2022

Hello @xtanion! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-07-23 08:01:18 UTC

Copy link
Contributor

@m-agour m-agour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @xtanion ,
Great job. It's working well.
I had some issues trying to export actors with no indices such as dot and line actors. It's causing the following error: ValueError: zero-size array to reduction operation maximum which has no identity which is triggered by this section of code:

  if indices is not None:
      indices = indices.reshape((-1, ))
      amax = [np.max(indices)]
      amin = [np.min(indices)]

Also, there are some typos in the gltf.py file. It's not related to this PR:

Copy link
Contributor

@ganimtron-10 ganimtron-10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @xtanion ,
I had a few suggestions regarding the docs which I have mentioned below.
Also, we should discuss the name of the parameters as some of them don't clearly explain what they contain.

I haven't reviewed and tested the code yet, I will do it as soon as possible and let you know if I found anything.
Thanks!

fury/gltf.py Outdated
----------
scene : Scene
FURY scene object.
name : str, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename instead

fury/gltf.py Outdated
gltf2glb(f'{name}.gltf', destination=filename)


def _connect_primitives(gltf, actor, buff_file, boffset, count, name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing docs for boffset

fury/gltf.py Outdated
count += 1
material = None if tcoords is None else 0
prim = get_prim(vertex, index, color, tcoord, normal, material)
return prim, boffset, count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should change boffset to byteoffset as per mention in the docs

fury/gltf.py Outdated
Pygltflib GLTF2 object
mesh : int, optional
Mesh index
camera : int, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think camera_index would be a more explanatory name

fury/gltf.py Outdated
gltf.cameras.append(cam)


def get_prim(verts, indices, cols, tcoords, normals, mat):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should try using full terms for eg. vertex, color, material, or something similar depending on the value they have. I am also a bit confused because you have written verts (plural) but as per the docs they store int (single value).

fury/gltf.py Outdated
return prim


def write_material(gltf, bct: int, uri: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

@xtanion xtanion Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing the entire parameter name for these functions can make the lines very long, also these parameters are explained in the docstring too.

fury/gltf.py Outdated
gltf.images.append(image)


def write_accessor(gltf, bv, bo, ct, cnt, atype, max=None, min=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason as above

fury/gltf.py Outdated
gltf.accessors.append(accessor)


def write_bufferview(gltf, buffer, bo, bl, bs=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@xtanion
Copy link
Member Author

xtanion commented Jul 19, 2022

Thanks for the review @ganimtron-10 and @m-agour.

Also, thanks @m-agour for finding the method to differentiate between lines and points, using

Polydata.GetNumberOfPolys()
Polydata.GetNumberOfLines()
Polydata.GetNumberOfPolys()

is easier than comparing the ratio of Number Of Points vs. Number Of Cells of the polydata.

I figured out the mode attribute in primitives decides if the rendered mesh should be a line or point or a triangle, there aren't any sample model that uses POINTS or LINES mode tho, Also the current glTF importer doesn't support rendering lines or points. I'll create a new PR with lines and points support.

@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #630 (19071aa) into master (26318ec) will increase coverage by 0.36%.
The diff coverage is 0.00%.

❗ Current head 19071aa differs from pull request most recent head 9ee3a45. Consider uploading reports for the commit 9ee3a45 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #630      +/-   ##
==========================================
+ Coverage   51.63%   52.00%   +0.36%     
==========================================
  Files         105      108       +3     
  Lines       22829    24066    +1237     
  Branches     2531     2643     +112     
==========================================
+ Hits        11788    12515     +727     
- Misses      10657    11145     +488     
- Partials      384      406      +22     
Impacted Files Coverage Δ
fury/gltf.py 0.00% <0.00%> (ø)
fury/io.py 0.00% <0.00%> (ø)
fury/lib.py 0.00% <0.00%> (ø)
fury/transform.py 0.00% <0.00%> (ø)
fury/utils.py 0.00% <0.00%> (ø)
fury/actor.py 0.00% <0.00%> (ø)
fury/window.py 0.00% <0.00%> (ø)
fury/fury/lib.py 100.00% <0.00%> (ø)
... and 18 more

Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this work @xtanion, merging

==============================
Exporting scene as a glTF file
==============================
In this tutorial, we will show how to create a glTF file for a scene.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from instead of for

@skoudoro skoudoro merged commit ffa1191 into fury-gl:master Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants