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

3d tiles writer #306

Closed
wants to merge 15 commits into from
Closed

3d tiles writer #306

wants to merge 15 commits into from

Conversation

krupkad
Copy link
Contributor

@krupkad krupkad commented Aug 11, 2021

Adding a writer for 3D Tiles.

@krupkad krupkad requested review from kring and baothientran August 11, 2021 12:24
@kring
Copy link
Member

kring commented Aug 11, 2021

Thanks @krupkad! What's doing the code generation? The comments say it's generate-gltf-classes, but I don't see any changes to that in this PR.

@krupkad
Copy link
Contributor Author

krupkad commented Aug 11, 2021

@kring Just updated the description, there's a branch/PR in #307 with that which I separated because it's extensive.

@krupkad krupkad mentioned this pull request Aug 11, 2021
Copy link
Contributor

@baothientran baothientran left a comment

Choose a reason for hiding this comment

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

Code generation looks really nice! I just have a couple of comments below.


std::optional<std::vector<double>> region;

std::optional<std::vector<double>> sphere;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick from me, it would be nice if this one can be a variant type. Maybe save a little bit of memory. Also it would be nice if we have a Box type that defines the center and half-axis, rather than vector<double>. Similar to Region and Sphere. If it's not possible for the generator, I wouldn't worry about it

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use a hybrid approach here? For example, we can manually define Box, Sphere, and Region C++ type and all the utility functions. Then, we tell the generator to use those defined type, rather than create it's own. I haven't tried it, so I'm not sure it's worth the effort

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be possible, but I do think the generated code should be as schema-faithful as possible with minimum "customization", with any custom logic done through other means e.g. inheritance, non-member non-friend utility functions. So maybe in this case we provide e.g. a non-member non-friend BoundingVolume createBox(const glm::dvec3& center, const glm::dvec3& halfSize); in include/Utils.h and src/Utils.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Related discussion in #362

struct CODEGEN_API Properties : public CesiumUtility::ExtensibleObject {
static inline constexpr const char* TypeName = "Properties";

std::unordered_map<std::string, TilesetProperties> additionalProperties;
Copy link
Contributor

Choose a reason for hiding this comment

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

using unordered_map maybe slower than map when there are very few item

struct CODEGEN_API GlobalPropertyScalar {
static inline constexpr const char* TypeName = "GlobalPropertyScalar";

struct CODEGEN_API Variant0 : public CesiumUtility::ExtensibleObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda know why we use Variant0 naming here since schema doesn't define the name for it. But it still not a good word for API alone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed but unsure how best to address this - looks like it would be fairly not-easy to override this in generator config

std::optional<std::vector<double>> v1;
std::optional<double> v2;
};
struct CODEGEN_API GlobalPropertyCartesian3 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick from me, but we should have space between structs

Copy link
Contributor

@baothientran baothientran left a comment

Choose a reason for hiding this comment

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

That's all I have for the generated code in this round. The only comment I have is that some of the construct in the 3D tiles spec requires one of the several properties to appear at most once (e.g Bounding Volume requires to be a bounding sphere or Box, etc), should we use std::variant in those cases?

DOUBLE
};

double byteOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

CesiumGltf has int64 for byteOffset. Can the generator do the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue is that the 3D Tiles schema has number for this, which does properly correspond to a double. Options are

  • change the schema to integer like glTF, which is technically a non-standard type (but the generator does handle)
  • add logic for handling this special case, which feels "incorrect"

Copy link
Member

Choose a reason for hiding this comment

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

We should change the spec. integer is standard in the version of JSON Schema 3D Tiles and glTF use: https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-04

Copy link
Contributor Author

Choose a reason for hiding this comment

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


std::optional<Variant0> v0;
std::optional<std::vector<double>> v1;
std::optional<double> v2;
Copy link
Contributor

Choose a reason for hiding this comment

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

This may have the same problem with the bounding volume above. The schema specifies GlobalPropertyScalar can only accept one of the properties above. Should using std::variant be a better choice in this case? cc @kring for more opinions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did consider this, my concern was that the reader becomes much more complicated since it has to "read every alternative at the same time", so

  • some template/STL gymnastics is required to get each type instantiated as a read destination
  • there's no obvious choice when multiple alternatives are valid other than "first in the specified order", which also requires some STL mess to accomplish

Not opposed to doing it that way, just will take a little more work and be a little STL-heavy.

The "multiple optionalsapproach also covers the semantics of bothoneOfandanyOf`, granted that's not relevant for glTF/3DTiles

Copy link
Member

Choose a reason for hiding this comment

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

Without necessarily understanding the full implications, std::variant sounds right to me. It more closely matches the schema semantics and will be more memory efficient as well.

@krupkad krupkad requested a review from baothientran August 25, 2021 15:15
@krupkad
Copy link
Contributor Author

krupkad commented Aug 25, 2021

@baothientran @kring the schema has been changed so the byteOffsets are ints, and the writer now uses std::variant.

@cesium-concierge
Copy link

Thanks again for your contribution @krupkad!

No one has commented on this pull request in 30 days. Maintainers, can you review, merge or close to keep things tidy?

I'm going to re-bump this in 30 days. If you'd like me to stop, just comment with @cesium-concierge stop. If you want me to start again, just delete the comment.

@lilleyse
Copy link
Contributor

I'll refer back to this PR as I work on GltfWriter and Cesium3DTilesWriter but I think it can be closed.

@lilleyse lilleyse closed this Oct 12, 2021
@lilleyse lilleyse mentioned this pull request Dec 7, 2021
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

Successfully merging this pull request may close these issues.

6 participants