Code Monkey home page Code Monkey logo

minimal-gltf-loader's Introduction

minimal-gltf-loader

Build Status License

A minimal, engine-agnostic JavaScript glTF Loader, with a raw WebGL 2 simple renderer example using the loader.

Viewer Screenshot

Live Demo

click here for live demo

Usage

import {vec3, vec4, quat, mat4} from 'gl-matrix';
var MinimalGLTFLoader = require('build/minimal-gltf-loader.js');

var glTFLoader = new MinimalGLTFLoader.glTFLoader();
glTFLoader.loadGLTF(url, function(glTF){
    //...
});

Loading Features

  • Accessors
    • Progressive loading / rendering
  • Buffers
  • BufferViews
  • Images
  • Meshes
  • Nodes
  • Primitives
  • Samplers
  • Textures
  • Shader Loader (not part of the core of glTF 2.0)
  • Animations
  • Cameras
  • Materials
  • Skins

Formats

  • glTF (.gltf) with separate resources: .bin (geometry, animation, skins), .glsl (shaders), and image files
  • glTF (.gltf) with embedded resources
  • Binary glTF (.glb) using the KHR_binary_glTF extension

Examples

  • WebGL 2 simple renderer
    • baseColorFactor
    • baseColorTexture
    • normalTexture
    • Skybox
    • PBR
    • Animation
    • Interpolations
      • LINEAR
      • STEP
      • CATMULLROMSPLINE
      • CUBICSPLINE
    • Skin
    • Camera (from glTF)
    • Progressive rendering (No plan for this)
    • Occlusion Culling experiment
      • Bounding Box
        • AABB (Axis Aligned Bounding Box, *static)
        • OBB (Object/Oriented Bounding Box)
      • Scene Bounding Box (fast iterated) And auto centered and scaled
      • Build octree
      • Occlusion Query with hierarchy

Credits


minimal-gltf-loader-typescript

A minimal, engine-agnostic TypeScript glTF Loader.

What's new in gltf-loader-typescript

This loader is a new instance of the minimal-gltf-loader.

In this branch, the author updated the loading file fuction from XMLHttpRequest to fetch API and used Promise and async/await to make loading procedure much more clearer.

In glTF 2.0 standard, the target attribute on bufferView is optional. Different 3D softwares have different interpretation of glTF exporter. For instance, the glTF files exported by Cinema4D have filled target attribute, but those exported by Blender 2.80+ will NOT have the target attribute filled. (Can see the issue in the following link: KhronosGroup/glTF-Blender-IO#142) Therefore, before binding buffer, the loader should infer the target attribute is whether ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER accoring to the usage of bufferview.

Usage

import {vec3, vec4, quat, mat4} from 'gl-matrix';
import {GLTFLoader, GLTF} from './src/glTFLoader.ts'

let gl : WebGLRenderingContext | WebGL2RenderingContext;

new GLTFLoader(gl).loadGLTF('YourURL').then((glTF: GLTF) => {
    // Create with glTF object, and proceed rendering process...
}).catch (() => {
    // Error control...
});

minimal-gltf-loader's People

Contributors

shrekshao avatar simongh0striley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minimal-gltf-loader's Issues

FlightHelmet.gltf goggles are opacity

I tried to display a new sample model FlightHelmet.gltf with the library of the latest version of minimal-glTF-Loader.
However, in minimal-glTF-Loader, the appearance of goggles seems to be different from other libraries.

Three.js Babylon.js minimal-glTF-Loader
image image image

Error loading when loading models other than BrainStem

I updated gltf-test Minimal glTF library and tested some models.

https://cdn.rawgit.com/cx20/gltf-test/b12768e1aad9853a53f583d5a9c568b02a3aae33/index.html

Models such as Box, RiggedFigure, BrainStem can be displayed.
However, I get an error when trying to display Avocado or Duck.
Duck.gltf result

index.js:460
Uncaught TypeError: Failed to execute 'uniform4fv' on 'WebGL2RenderingContext': No function was found that matched the signature provided.
    at drawPrimitive (index.js:460)
    at drawNode (index.js:518)
    at drawNode (index.js:534)
    at drawScene (index.js:542)
    at render (index.js:660)
    at MinimalGLTFLoader.glTFLoader.onload (index.js:675)
    at MinimalGLTFLoader.glTFLoader.glTFLoader._checkComplete (minimal-gltf-loader.js:697)
    at loadArrayBufferCallback (minimal-gltf-loader.js:941)
    at XMLHttpRequest.xobj.onreadystatechange (minimal-gltf-loader.js:1319)

I think that a model without vertex color probably has become an error.

请教关于 skins 的疑问

狄学长,你好

我看到了你在这里提的问题,你现在有答案了么?我可能有一些想法。

我想看看你对glTF的skinning的实现,但是没找到相关代码,README.md中说明已经实现了skin
所以我想问一下可否告诉我代码在哪?

谢谢。

Triangle.gltf is not displayed

I tried to display Triangle.gltf. However, there seems to be an error in the console.

Triangle.gltf result

index.js:256 
Uncaught TypeError: Cannot read property 'boundingBox' of undefined
    at MinimalGLTFLoader.glTFLoader.onload (index.js:256)
    at MinimalGLTFLoader.glTFLoader.glTFLoader._checkComplete (minimal-gltf-loader.js:697)
    at loadArrayBufferCallback (minimal-gltf-loader.js:935)
    at XMLHttpRequest.xobj.onreadystatechange (minimal-gltf-loader.js:1313)

Probably because there is no default scene in this model.
If default scene is not specified, it is a good idea to display the first scene.

[Request] Synchronous version of loading

Hello, I am working a project the need to preload some glTF models.
However, the vanilla method (asynchronous way) seem to a little bit not suitable for preloading.
Maybe it's because I'm not so skillful at "async", but I still want to see the synchronous version of the loading method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.