🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@gltf-transform/view

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/view

Syncs a glTF-Transform Document with a three.js scene graph

npmnpm
Version
0.3.0
Version published
Weekly downloads
267
-46.39%
Maintainers
1
Weekly downloads
 
Created
Source

@gltf-transform/view

Latest NPM release Minzipped size License Build Status

IN DEVELOPMENT: This project is currently in development, and missing some functionality.

Syncs a glTF-Transform Document with a three.js scene graph, keeping three.js updated over time as changes are made to the Document. After changes are complete, export the exact glTF document — losslessly — with the glTF-Transform NodeIO / WebIO tools.

Motivation

While three.js can render glTF 2.0 files out of the box with THREE.GLTFLoader, and export them with THREE.GLTFLoader, this approach has an important limitation: the GLTFExporter → GLTFLoader trip is lossy, and doesn't support all features of glTF. For a small set of closely-controlled assets, this might be a good workflow. But in general, it is error-prone.

@gltf-transform/view provides a tighter integration between a glTF Document and a three.js scene, so that changes within the Document (e.g. to a Material) are shown instantly in the rendered result. In addition, any features that three.js doesn't support won't be lost — they just aren't rendered in the preview.

NOTE: The fast edit/refresh loop requires some additional memory overhead, so this project is not meant to replace THREE.GLTFLoader for one-time loading.

Quickstart

Install:

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();
const camera = new PerspectiveCamera(50, window.innerWidth / window.innerHeight, .1, 100);
const renderer = new WebGLRenderer();
// ...

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

// Add glTF content to the scene (just once).
const sceneDef = document.getRoot().listScenes()[0];
scene.add(documentView.view(sceneDef));

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

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

Bindings

bindingstatuscomments
SceneDynamic
NodeDynamic
MeshDynamic
PrimitiveDynamic
AccessorDynamic
MaterialDynamic
TextureDynamic
TextureInfo🚧Static
AnimationNo bindings
CameraNo bindings
LightNo bindings

Legend:

  • ✅  Renders and updates
  • 🚧  Static render, no updates
  • ❌  Not rendered

Bugs / Limitations / To Do

See https://github.com/donmccurdy/glTF-Transform-View/issues/8.

Extensions Supported

See https://github.com/donmccurdy/glTF-Transform-View/issues/7.

Contributing

# Install dependencies.
yarn

# Build source, watch for changes.
yarn watch

# Build source, watch for changes, and run examples.
yarn dev

# Run tests.
yarn test

FAQs

Package last updated on 29 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts