donmccurdy / gltf-transform Goto Github PK
View Code? Open in Web Editor NEWglTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.
Home Page: https://gltf-transform.dev
License: MIT License
glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.
Home Page: https://gltf-transform.dev
License: MIT License
There's a basic "inspect()" function checked into the CLI package, but I'd like to put that into its own npm package so it's available both in web and node.js. The current script prints a number of tables describing the content of the file, and is intended to be useful for understanding performance behavior, and whether the model follows basic best practice1. For example:
The goal for a @gltf-transform/inspect
package would be to abstract that into something that returns JSON. Users can read the JSON on Web/Node.js, and the CLI tool can use it to print the same tables it does today. Example usage:
import { WebIO } from '@gltf-transform/core';
import { inspect } from '@gltf-transform/inspect';
const doc = await new WebIO().read('path/to/model.glb');
const report = inspect(doc);
console.log(report);
1 Best practice, as opposed to whether it's a technically valid glTF file. The glTF-Validator already covers the latter case very well.
Hi; I know this is in development, so feel free to close if this isn't expected to be working yet. I came here because of the de-duplication idea (based on Matt Deslaurier's gist).
I cloned the repo, did npm install
, lerna bootstrap
, and npm run dist
, then ran node_modules/.bin/gltf-transform analyze DamagedHelmet.glb
and got this error:
/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:600
if (bufferView.byteLength > 0) {
^
TypeError: Cannot read property 'byteLength' of undefined
at Function.removeBufferView (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:600:24)
at forEach (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:236:22)
at Array.forEach (<anonymous>)
at PackedGLTFContainer.unpack (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:231:29)
at Function.fromGLB (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:338:54)
at NodeIO.readGLB (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:766:25)
at NodeIO.read (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:761:29)
at Command.program.command.argument.action [as _action] (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/src/cli.js:26:30)
at Command._run (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/command.js:413:40)
at Program._run (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/program.js:170:16)
at Program.parse (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/program.js:276:17)
at Object.<anonymous> (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/src/cli.js:99:6)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
If I load my own model, I get a slightly different error:
/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:91
throw new Error(`Empty top-level array, "${this.json[key]}".`);
^
Error: Empty top-level array, "".
at GLTFContainer.validate (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:91:23)
at PackedGLTFContainer.unpack (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:241:19)
at Function.fromGLB (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:338:54)
at NodeIO.readGLB (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:766:25)
at NodeIO.read (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/node_modules/@gltf-transform/core/dist/gltf-transform-core.js:761:29)
at Command.program.command.argument.action [as _action] (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/src/cli.js:26:30)
at Command._run (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/command.js:413:40)
at Program._run (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/program.js:170:16)
at Program.parse (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/node_modules/caporal/lib/program.js:276:17)
at Object.<anonymous> (/c/DSS/Product/Horizon/WebProjects/horizon-project/horizon-data-converters/glTF-Transform/packages/cli/src/cli.js:99:6)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
(I tried modifying packages/core/src/packed-container.ts to see if I could print the "key" it's looking for, and re-running npm run dist
but it didn't pick up my changes -- I'm not a lerna person so I assume I missed a step.)
I think I originally used JS here for easier debugging or something? Practically the unit tests seem to be working well for that, I'd rather have the CLI use TS and ts-node at this point.
Looks like Caporal now supports sections in its --help
output, which could be nice:
general
modify
clean
compress
Split mesh.ts, animation.ts, and texture.ts into a file for each class.
Methods to get world transforms without manually traversing the scene graph. Using gl-matrix.
After cloning the repository, run: yarn install
This produce error:" [Errno 2] No such file or directory: 'install'"
Could you help with newbie how to proceed with installation?
files: [
"*",
"!test/"
]
Consider:
@gltf-transform/cli
@gltf-transform/util
@gltf-transform/occlusion-vertex
@gltf-transform/prune
@gltf-transform/split
@gltf-transform/atlas
...
Preferably automatically in a lint sweep.
Similar to three.js, just traverse a node's descendants. Probably add to Scene, too?
Ideally it would print the first table with basic information it can get from a NativeDocument, before trying to parse and showing the error. The other tables could be omitted.
I think this requires editing the i/o classes a bit, so that they have methods to create a NativeDocument from a URI, and convert that to a Document as a second step.
Related links:
Usage:
gltf-transform screenshot model.glb --options ...
import { screenshot } from '@gltf-transform/screenshot';
import { NodeIO } from '@gltf-transform/core';
const doc = new NodeIO().read('model.glb');
const screenshotBuffer = screenshot(doc);
fs.writeFileSync('screenshot.png', screenshotBuffer);
When it lands in Microbundle 0.12.0, this should hopefully reduce bundle size a bit.
Keeping a package for each transform (ao, colorspace, prune, split, ...) is messy, I often find myself wanting to rename things, or add something quickly, and because NPM packages can't be deleted there's an aspect of "cluttering" the namespace as that goes on. I think all of these could be consolidated into a single package (perhaps "lib"?) that provides functions built on top of the core and extension APIs. In dependency order:
cli > lib > extensions > core
Test coveraged slipped with new features in v0.5, let's try to get this back above 80%.
Remove legacy module and umd output. Should resolve the warnings of the form No name was provided for external module
, and make building faster.
Basic snippet:
// Warn for unknown extensions.
const extensionsRecognized = new Set();
doc.getRoot().listExtensionsUsed().forEach((ext) => extensionsRecognized.add(ext.extensionName));
extensionsUsed.forEach((extensionName) => {
if (!extensionsRecognized.has(extensionName)) {
logger.warn(`Extension "${extensionName}" not recognized by this tool.`);
}
});
Not sure if this belongs in CLI or core I/O.
Pending GoogleChromeLabs/squoosh#280.
Encoding basis seems to be done via toktx
tool that could be downloaded from here https://github.com/KhronosGroup/KTX-Software/releases/tag/v4.0.0-beta3
CLI preview is already out of date and will probably keep becoming so unless I automate it. The "transforms" should probably go into a "library page". Maybe that leaves "installation" and "scripting"?
Plan —
transformPrimitive(prim, matrix)
, transformMesh(mesh, matrix)
clearNodeParent(node)
, clearNodeTransform(node)
. Requires (1).
node.mesh
document.transform(flatten())
. Requires (1) and (2).
joinPrimitives(prim: Primitive[])
.
document.transform(join())
. Requires (1), (2), (3), (4).
Other considerations —
clearNodeTransform
must warn on attached camera or lightDetails in KhronosGroup/glTF#1719 (comment). May need get-pixels to rewrite glossiness->roughness.
Usage:
gltf-transform metalrough input.glb output.glb
import {metalRough} from '@gltf-transform/lib';
import {NodeIO} from '@gltf-transform/core';
const io = new NodeIO(fs, path);
const doc = io.read('input.glb');
metalRough(doc);
io.write('output.glb', doc);
Similar API to existing unlit
function.
Missing dependencies for canvas
and @gltf-transform/atlas
.
Should probably also add a test to catch this in the future...
gltf-transform \
[ prune ] \
[ atlas --size 1024 ] \
[ ao --samples 500 ]
The new version is a breaking change, but has an improved API, and supports sections in the help output that look useful to me.
Not ideal for an SDK, which is what the core lib seems to be headed toward. Perhaps something like:
Accept (sRGB) hex value and convert to linear vec3.
When reading the attatched lamp.gltf file and then writing it, some accessors' min and max arrays will have null values. (This prevents the next tool in our pipeline to convert it to usdz). We know that the original .gltf file has some issues, but we would expect that upon successful reading of the file that it would also write a correct file.
const io = new NodeIO(fs, path); var doc = io.read("lamp/lamp.gltf"); io.write("lamp/lampOut.gltf", doc);
gltf-transform/core version: 0.3.2
Add draco package
--unlit
to bake occlusion to vertex colors?
New installation of CLI:
Error: Cannot find module '@gltf-transform/colorspace'
See KhronosGroup/glTF#1681, similar to https://github.com/facebookincubator/glTFVariantMeld. Would be added to the lib
package and available through the CLI. Not sure whether the existing meld API is the right one, maybe this should take a config file pointing to external textures, and a single glTF, instead?
Given a model in which a particular mesh is repeated many times in the scene, with different transforms, output a model using EXT_gpu_mesh_compression to instance the mesh. Ideally with options for tiling the instances for better culling. Some ideas for sample models:
Hey, I know support for extensions is in development in the v0.4
branch but according to the comment, the only thing missing is documentation.
Can I start using this branch? Is there anything else I can do to help with it?
I'm using glTF-Transform to extract the 3D models from a proprietary format and I'd like to use the KHR_materials_unlit
extension.
Intended to look for common validity issues in the Document that would prevent its being exported, before the Document is written to a file (after which glTF-Validator is the better thing to use). Things like:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.