-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Serialization format for transforms #1391
Comments
Hi @javagl! I've thought a little bit about the idea of a JSON representation of the public API and its documentation. For example it would be nice to be able to get help text and validation into the CLI without as much boilerplate as Maybe the closest thing in the project now, the documentation system encodes {
"kind": "Function",
"name": "textureCompress",
"source": {
"text": "packages/functions/src/texture-compress.ts",
"url": "https://github.com/donmccurdy/glTF-Transform/tree/main/packages/functions/src/texture-compress.ts"
},
"tags": {
"category": "Transforms"
},
"params": [
{
"name": "_options",
"type": {
"path": "/modules/functions/interfaces/TextureCompressOptions",
"name": "TextureCompressOptions",
"kind": "Interface"
}
}
],
"returns": "Transform",
"comment": "<p>Optimizes images, optionally resizing<...>"
} ... with a similar structure representing |
Just to emphasize: There is no problem that needs to be solved right now. It's just a gut feeling that something like this could be cool and useful for certain tasks. But the point that you brought up is one where one could think about leveraging such an infrastructure inside of glTF-Transform. The idea (that is also ... 'drafted' but not really fully 'implemented' in other things that I've been working on) is roughly speaking: The CLI is parsing the command line arguments, and building a JSON structure. That JSON structure can (if desired) be trivially validated against the schema, using some generic JSON schema validator. Then, there only is a thin layer on top of the API, that translates this (validated) JSON into the proper API calls (and this can then be really be thin and generic). Yeah. Sounds cool. But it's easier said than done, and raises questions like this:
I don't know the processes/tools/libraries that are currently used for generating the CLI- and API documentation (although, from just looking at the result, it seems to be sophisticated and powerful). And whether or not it is possible (with which effort) to avoid duplication is indeed an open question. I'd say that the TSDoc API docs have to exist anyhow, because they are independent of that serialization format after all. About the example for the This looks like something that already could be stored as a JSON schema. And this includes things like a Related to the question about duplication: Right now, the (Remotely related: I once hacked |
This is not a real "feature request", but rather some brainstorming.
The scripting API is nice and powerful. The CLI is nice and powerful. But I could imagine a layer hidden between both of them - namely, that of a serialization format for transforms.
As an experiment, I created a stupidly-simple function that just takes JSON like this....
and translates this into an array of
Transform[]
objects. This allows something likeIn general, the possibility to read/write certain configurations of transform sequences could be pretty useful. (And more structured and versatile than a
.BAT
/.sh
file that contains the proper CLI calls...)I know how complicated this can become. I know many of the caveats of such an approach. If this was supposed to be done 'right', it would involve some work. (I defined a bunch of JSON schemas for
dedup/center/...
transforms, and these could be trivially translated into TypeScript structures, allowing to safely assemble them programmatically and so on - but doing that thoroughly is not something that can casually be jotted down on a boring afternoon). But I think that there might still be a few relatively low-hanging fruits with that approach.The text was updated successfully, but these errors were encountered: