All Projects → wnayes → glTF-js-utils

wnayes / glTF-js-utils

Licence: MIT license
Helper library for creating glTF 2.0 models with JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to glTF-js-utils

Stl Thumb
Thumbnail generator for STL files
Stars: ✭ 226 (+370.83%)
Mutual labels:  3d-models
maya-glTF
glTF 2.0 exporter for Autodesk Maya
Stars: ✭ 121 (+152.08%)
Mutual labels:  gltf2
glTF-Rhino
Support for glTF 2.0 files in Rhino
Stars: ✭ 37 (-22.92%)
Mutual labels:  gltf2
Model Viewer
Easily display interactive 3D models on the web and in AR!
Stars: ✭ 3,751 (+7714.58%)
Mutual labels:  3d-models
HxSTLParser
Basic STL loader for SceneKit
Stars: ✭ 23 (-52.08%)
Mutual labels:  3d-models
stl2gltf
Convert STL to glb
Stars: ✭ 67 (+39.58%)
Mutual labels:  gltf2
Sdfx
A simple CAD package using signed distance functions
Stars: ✭ 213 (+343.75%)
Mutual labels:  3d-models
docker-gltf-to-udsz
Docker container for converting gltf files into apple usdz quicklook files
Stars: ✭ 42 (-12.5%)
Mutual labels:  gltf2
3D-GuidedGradCAM-for-Medical-Imaging
This Repo containes the implemnetation of generating Guided-GradCAM for 3D medical Imaging using Nifti file in tensorflow 2.0. Different input files can be used in that case need to edit the input to the Guided-gradCAM model.
Stars: ✭ 60 (+25%)
Mutual labels:  3d-models
libgltf
glTF 2.0 parser/loader for C++11, supports many extensions likes `KHR_draco_mesh_compression`, `KHR_lights_punctual`, `KHR_materials_clearcoat`, and more.
Stars: ✭ 55 (+14.58%)
Mutual labels:  gltf2
Blacksmith
Blacksmith is a tool for viewing, extracting, and converting textures, 3D models, and sounds from Assassin's Creed: Odyssey/Origins/Valhalla and Steep.
Stars: ✭ 104 (+116.67%)
Mutual labels:  3d-models
SPHARM-PDM
Shape analysis has become of increasing interest to the medical community due to its potential to precisely locate morphological changes between healthy and pathological structures. SPHARM-PDM is a tool that computes point-based models using a parametric boundary description for the computing of Shape analysis.
Stars: ✭ 32 (-33.33%)
Mutual labels:  3d-models
NeuroMorph
The NeuroMorph analysis and visualization toolkit
Stars: ✭ 57 (+18.75%)
Mutual labels:  3d-models
Cherry Mx Keycaps
3D models of Chery MX keycaps
Stars: ✭ 250 (+420.83%)
Mutual labels:  3d-models
gdx-gltf
GLTF 2.0 3D format support and PBR shader implementation for LibGDX
Stars: ✭ 156 (+225%)
Mutual labels:  gltf2
Pulse
A pendant to warn you when you touch your face
Stars: ✭ 229 (+377.08%)
Mutual labels:  3d-models
pcad2kicad
Convert Altium Designer and PCAD library to KiCad
Stars: ✭ 94 (+95.83%)
Mutual labels:  3d-models
Procedural-Terrain-Generator-OpenGL
Procedural terrain generator with tessellation | C++ OpenGL 4.1
Stars: ✭ 98 (+104.17%)
Mutual labels:  3d-models
JOpenCTM
Java implementation of the openCTM Mesh compression file format
Stars: ✭ 13 (-72.92%)
Mutual labels:  3d-models
ObjToSchematic
A tool to convert .obj files into Minecraft Schematics
Stars: ✭ 156 (+225%)
Mutual labels:  3d-models

gltf-js-utils

Helper library for creating glTF 2.0 models with JavaScript.

Usage

Creating glTF from scratch

Create a GLTFAsset structure using the provided types.

import {
  GLTFAsset, Scene, Node, Material, Texture, Mesh, Vertex, WrappingMode
} from "gltf-js-utils";

const asset = new GLTFAsset();
const scene = new Scene();
asset.addScene(scene);

const node = new Node();
node.setTranslation(x, y, z);
node.setRotationRadians(x, y, z);
node.setScale(x, y, z);
scene.addNode(node);

const material = new Material();
// Supported texture types: HTMLImageElement | HTMLCanvasElement | ArrayBuffer (PNG) | Data URL (PNG)
const texture = new Texture(image);
texture.wrapS = WrappingMode.CLAMP_TO_EDGE;
texture.wrapT = WrappingMode.REPEAT;
material.pbrMetallicRoughness.baseColorTexture = texture;

const mesh = new Mesh();
mesh.material = [material];
node.mesh = mesh;

const v1 = new Vertex();
v1.x = 1;
v1.y = 1;
v1.z = 1;
v1.u = 0;
v1.v = 0;
const v2 = new Vertex();
// ...

const faceColor = undefined;
const faceMaterialIndex = 0;
mesh.addFace(v1, v2, v3, faceColor, faceMaterialIndex);
mesh.addFace(v4, v5, v6, faceColor, faceMaterialIndex);
// ...
Create Animation
import { Node, Animation, InterpolationMode, Transformation } from "gltf-js-utils";

const node = new Node();
scene.addNode(node);
const nodeAnim = new Animation(Transformation.TRANSLATION);
nodeAnim.keyframes = [
    {
        time: 0,
        value: [1, 2, 3],
        interpType: InterpolationMode.LINEAR
    },
    {
        time: 0.3,
        value: [4, 5, 6],
        interpType: InterpolationMode.LINEAR
    }
];
// or add keyframes via addKeyframe function
nodeAnim1.addKeyframe(0.8, [7, 8, 9], InterpolationMode.STEP);
node.animations = [nodeAnim];
Export to a collection of individual files/data

With the default options, you'll receive an object keyed with the glTF JSON and binary buffers.

import { exportGLTF } from "gltf-js-utils";

const gltfFiles = await exportGLTF(asset);
// {
//   "model.gltf": string /* JSON glTF string */
//   "data1.bin": ArrayBuffer /* ArrayBuffer of buffer data */
//   "data2.bin": ArrayBuffer,
//   "data3.bin": ArrayBuffer,
//   ...
//   "img1.png": ArrayBuffer /* Texture image */
//   "img2.png": ArrayBuffer
//   ...
// }
Export using data URIs

Buffers and/or images can be embedded within the JSON as data URIs.

import { exportGLTF, BufferOutputType } from "gltf-js-utils";

const gltfFiles = await exportGLTF(asset, {
  bufferOutputType: BufferOutputType.DataURI,
  imageOutputType: BufferOutputType.DataURI,
});
// {
//   "model.gltf": string /* JSON glTF string, all data embedded */
// }
Export to a ZIP file

Requires a JSZip reference. The result will be a ZIP blob.

import * as JSZip from "jszip";
import { exportGLTFZip } from "gltf-js-utils";

exportGLTFZip(asset, JSZip).then(blob => {
  // Use FileSaver as an example.
  saveAs(blob, "model.zip");
});

Create glTF from Three.js object

Use the separate gtlf-js-utils-three package to create glTF models from Three.js models. See the gtlf-js-utils-three documentation for more details.

import { exportGLTF } from "gltf-js-utils";
import { glTFAssetFromTHREE } from "gltf-js-utils-three";

// Create a Three.js Scene or Object3D structure...
const scene = new THREE.Scene();
...

const gltfFiles = await exportGLTF(glTFAssetFromTHREE(scene));

Create a GLB container

Calling exportGLB will produce a single GLB model in an ArrayBuffer.

import { exportGLB } from "gltf-js-utils";

const glbArrayBuffer = await exportGLB(asset);

You can also use exportGLTF with the GLB output type to selectively keep some assets external.

import { exportGLTF, BufferOutputType } from "gltf-js-utils";

const gltfFiles = await exportGLTF(asset, {
  bufferOutputType: BufferOutputType.GLB,
  imageOutputType: BufferOutputType.External,
});
// {
//   "model.glb": ArrayBuffer
//   ...
//   // Only images follow, data bins are in the GLB file
//   "img1.png": ArrayBuffer /* Texture image */
//   "img2.png": ArrayBuffer
// }

Limitations

  • No support for camera yet.

Development

To build:

npm install
npm run build

To test:

npm run test

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].