Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generate code from json schema? #19

Closed
bwasty opened this issue May 14, 2017 · 14 comments
Closed

Generate code from json schema? #19

bwasty opened this issue May 14, 2017 · 14 comments

Comments

@bwasty
Copy link
Member

bwasty commented May 14, 2017

Hi,
Have you considered generating the Rust code from the official json schema?
I did a quick experiment with schemafiy, but immediately ran into Marwes/schemafy#3 (panic on external references).

I got the idea initially from https://github.com/slack-rs/slack-rs-api/tree/master/codegen. They use a custom generator to generate bindings to the Slack API. It works pretty well there (I've worked with the generated code).

Side question: How far along is the 2.0 branch?

@alteous
Copy link
Member

alteous commented May 14, 2017

Have you considered generating the Rust code

Yes. The idea of generating code like gl or slack-rs as you mentioned is tempting. I decided against it originally because there seemed to be too many special cases. For example when items require 'non-standard' defaults, when extensions are introduced into the mix, and what to do with extras.

I think it is more reasonable for gl to generate code rather than gltf because the former is generating function prototypes which are much simpler than hierarchical data structures. Having said this though, I'm not against the idea. It would just requires a lot more thought.

The glTF 2.0 implementation is in the incoming branch and is 'almost complete'. I'm waiting for the specification to be finalised before the code is merged into master and uploaded to crates.io.

@bwasty
Copy link
Member Author

bwasty commented May 14, 2017

Thanks for the answer. I also had the feeling it might be a little more complex than slack-rs.
I'm thinking of writing a glTF viewer with ​gfx-rs/gfx (as a 'small' exercise to get back into graphics programming). I think I'll base it on the incoming branch if I get there before it's merged.

@alteous
Copy link
Member

alteous commented May 14, 2017

as a 'small' exercise to get back into graphics programming

To save you time I encourage you to read this and take my mistakes into consideration (TL;DR: don't use gfx). Recently I've been experimenting with a new graphics API, namely rugl which is much reasonable for this use case.

@bwasty
Copy link
Member Author

bwasty commented May 14, 2017

Hmm, difficult choice. What I like about gfx is that it supports Vulkan and OpenGL ES (-> can possibly be compiled to WebAssembly(gfx-rs/gfx#641)).

@alteous
Copy link
Member

alteous commented May 14, 2017

I should add what I said above only applies to glTF 1.0. It would be very reasonable to use gfx for glTF 2.0.

@alteous
Copy link
Member

alteous commented May 15, 2017

Random thought: It might be worth using the schema to validate the correctness of the hand written 'raw' data structures.

@bwasty
Copy link
Member Author

bwasty commented May 16, 2017

How would you do that?

Btw, the glTF-Sample-Models repo now contains a few more models updated to 2.0 and e.g. Box can't be loaded with the v2 loader. Also failing is the minimal example here: https://github.com/javagl/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_003_MinimalGltfFile.md
Both work with https://gltf-viewer.donmccurdy.com/

@alteous
Copy link
Member

alteous commented May 16, 2017

Thanks for reporting. I've updated the sample models in incoming. Hopefully a fix will be released soon.

@alteous
Copy link
Member

alteous commented Jun 3, 2017

Recently I've been experimenting with generating Rust code from the current 2.0 schema.

I think writing a code generator would be too troublesome at this stage due to the complexity of the schema. Even if there exists a smart person that could write a correct generator tonight, whatever code is generated is unlikely to be correct tomorrow, and worse still would probably fail silently.

@bwasty
Copy link
Member Author

bwasty commented Jun 9, 2017

The glTF 2.0 implementation is in the incoming branch and is 'almost complete'. I'm waiting for the specification to be finalised before the code is merged into master and uploaded to crates.io.

https://www.khronos.org/news/press/khronos-releases-gltf-2.0-specification 😃

@bwasty
Copy link
Member Author

bwasty commented Jun 9, 2017

Another thing: I noticed one relevant recent spec change under Scenes:

When scene is undefined, runtime is not required to render anything at load time.

Implementation Note: This allows applications to use glTF assets as libraries of individual entities such as materials or meshes.

So this could be removed I guess.

@alteous
Copy link
Member

alteous commented Jun 10, 2017

So this could be removed I guess.

I think it's important to provide all the data from the glTF. Whether the user decides to make use of the default scene index is up to them.

@bwasty
Copy link
Member Author

bwasty commented Jun 10, 2017

Well, the part of the spec saying that the default scene (if not specified) is 0 was removed, so the default here should now be None I think.

EDIT: For reference: https://github.com/KhronosGroup/glTF/pull/958/files

@alteous
Copy link
Member

alteous commented Jun 10, 2017

Thanks, I've made the change.

Whatever 2.0-specific code is in the incoming branch should be ready for a 0.5.0 release. I'll check it over again and publish in a few hours.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants