-
Notifications
You must be signed in to change notification settings - Fork 222
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
3d tiles writer #306
Conversation
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. |
52cd0d4
to
997bd47
Compare
997bd47
to
b63e67b
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened CesiumGS/3d-tiles#476.
|
||
std::optional<Variant0> v0; | ||
std::optional<std::vector<double>> v1; | ||
std::optional<double> v2; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 optional
sapproach also covers the semantics of both
oneOfand
anyOf`, granted that's not relevant for glTF/3DTiles
There was a problem hiding this comment.
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.
@baothientran @kring the schema has been changed so the |
Upstream changed GlobalPropertyScalar to GlobalPropertyInteger and GlobalPropertyNumber.
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 |
I'll refer back to this PR as I work on GltfWriter and Cesium3DTilesWriter but I think it can be closed. |
Adding a writer for 3D Tiles.
ExtensionWriterContext
(similar to Extract extension handling #299) and tests for it underCesiumJsonWriter
Cesium3DTilesWriter