4.0.0 • Published 10 days ago

@gltf-transform/view v4.0.0

Weekly downloads
-
License
BlueOak-1.0.0
Repository
github
Last release
10 days ago

@gltf-transform/view

Latest NPM release Minzipped size License

⚠️ EXPERIMENTAL - The @gltf-transform/view module is currently experimental, and does not follow semantic versioning, unlike other packages in the project. Consider pinning the dependency to a specific version of the package.

Creates three.js objects from a glTF Transform Document, then keeps the three.js scene graph updated — in realtime ⚡️ — as changes are made to the Document. Combined with import/export using WebIO, @gltf-transform/view provides a lossless workflow to load, view, edit, and export glTF assets. It's meant for editor-like applications on the web. Unlike using THREE.GLTFExporter, any glTF features that three.js doesn't support won't be lost, they just aren't rendered in the preview.

Quickstart

Installation:

npm install --save @gltf-transform/view

API

import { Scene, WebGLRenderer, PerspectiveCamera } from 'three';
import { WebIO } from '@gltf-transform/core';
import { KHRONOS_EXTENSIONS } from '@gltf-transform/extensions';
import { DocumentView } from '@gltf-transform/view';

// Set up three.js scene.

const scene = new Scene();
// ...

// Load glTF Document.
const io = new WebIO().registerExtensions(KHRONOS_EXTENSIONS);
const document = await io.read('path/to/input.glb');
const documentView = new DocumentView(document);

// Add glTF content to the scene (just once).
const sceneDef = document.getRoot().getDefaultScene(); // glTF Transform Scene
const group = documentView.view(sceneDef); // THREE.Group
scene.add(group);

// Render.
function animate () {
	requestAnimationFrame(animate);
	renderer.render(scene, camera);
}

// When glTF Document is edited, scene updates automatically.
const materialDef = document.getRoot().listMaterials()
	.find((mat) => mat.getName() === 'MyMaterial');
buttonEl.addEventListener('click', () => {
	materialDef.setBaseColorHex(0xFF0000);
});

Each DocumentView instance maintains reference counts and disposes of three.js WebGL resources (textures, geometry, materials) when the underlying glTF Transform properties are disposed. Unused resources are not disposed immediately, in case they might be used again later. To manually dispose of unused resources — e.g. to free up GPU memory — call documentView.gc(). Resources will be re-allocated automatically if they are used again.

Feature support

  •   Renders and updates
  • 🚧  Static render, no updates
  •   Not rendered
bindingstatus
Scene
Node
Mesh
Primitive
Accessor
Material
Texture
Light
Skin
TextureInfo🚧
Morph Targets
Animation
Camera

For supported extensions, see glTF-Transform-View#7.

Contributing

See CONTRIBUTING.md.

License

Published under Blue Oak Model License 1.0.0.

4.0.0-alpha.17

11 days ago

4.0.0-alpha.19

10 days ago

4.0.0-alpha.18

11 days ago

4.0.0

10 days ago

0.15.0

3 months ago

0.14.1

3 months ago

0.14.0

3 months ago

0.12.0

11 months ago

0.10.0

12 months ago

0.11.0

12 months ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.4.8

2 years ago

0.6.3

1 year ago

0.6.2

2 years ago

0.5.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.4.7

2 years ago

0.4.5

2 years ago

0.4.6

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.1

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago