Code Monkey home page Code Monkey logo

three-gltf-extensions's Introduction

three-gltf-extensions

npm version

Three.js glTF loader and exporter have plugin system to provide extensibility mechanism to users. glTF extensions can be handled with the plugin system.

Some plugins for major and stable extensions are built-in in the loader and exporter. But other extensions are not supported as built-in by them (yet) because for example the specification is not great fit to Three.js API or structure, or the specification is not finalized.

If you want to use such extensions you need to write plugins by yourself but it requires the knowledge of glTF specification, extensions specification, Three.js core API, or Three.js glTF loader/exporter API. It can be difficult for some users.

This project provides you Three.js glTF loader/extension plugins even for such extensions. You no longer need to write the plugin on your own.

Goals

  • Provide reusablity and easiness to use even for the the extensions the spec of which isn't great fit to Three.js API or structure
  • Allow early trial of glTF extensions the spec of which is not finalized yet
  • Send feedback to Three.js glTF loader/exporter plugin system APIs

Online demo

Supported glTF extensions

Compatible Three.js revision

Depends on the plguins. Refer to each plugin's readme.

How to use

GLTFLoader plugins

// Import Three.js
<script type="importmap">
{
  "imports": {
    "three": "path_to_three.module.js"
  }
}
</script>
<script type="module">
import * as THREE from 'three';
import {GLTFLoader} from 'path_to_GLTFLoader.js';

// Import three-gltf-extensions loader plugins
import GLTFFooExtension from 'path_to_three-gltf-extensions/loaders/Foo_extension/Foo_extension.js';

// Register the plugin to the loader and then load glTF
const loader = new GLTFLoader();
loader.register(parser => new GLTFFooExtension(parser));
loader.load(path_to_gltf_asset, gltf => {
  ...
});
</script>

GLTFExporter plugins

// Import Three.js
<script type="importmap">
{
  "imports": {
    "three": "path_to_three.module.js"
  }
}
</script>
<script type="module">
import * as THREE from 'three';
import {GLTFExporter} from 'path_to_GLTFExporter.js';

// Import three-gltf-extensions exporter plugins
import GLTFExporterFooExtension from 'path_to_three-gltf-extensions/exporters/Foo_extension/Foo_extension_exporter.js';

// Register the plugin to the exporter and then export Three.js objects
const exporter = new GLTFExporter();
exporter.register(writer => new GLTFExporterFooExtension(writer));
exporter.parse(scene, result => {
  ...
});
</script>

Refer to each plugin's README for more detail.

Locally run examples

$ npm install
$ npm start
# Access http://localhost:8080/examples/index.html

Unit Test

Unit Test on Web browser

$ npm install
$ npm run test-install
$ npm run test-build
$ npm start
# Access http://localhost:8080/test/index.html

Unit Test on Node.js

$ npm run test-install
$ npm run test

Note that the unit tests which rely on Web don't run. I recommend to run the unit tests on Web browser.

Customize the plugins in your side

As written above, some extensions are not great fit to Three.js API or structure. So the plugins for them may have some limitations. If they don't cover your use case, please fork the repository and customize on your end.

three-gltf-extensions's People

Contributors

hybridherbst avatar mrdoob avatar takahirox 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  avatar  avatar

three-gltf-extensions's Issues

Missing optional extension, "EXT_mesh_gpu_instancing". with using draco compression by gltf-transform

Hi.
I met this warning message Missing optional extension, "EXT_mesh_gpu_instancing".

I think because I use the draco compression exporter, it cause this warning and It dosen't work also.

this is my exporter code.

this.exporter = new GLTFExporter();
this.exporter.register((writer) => new GLTFExporterMeshGPUInstancingExtension(writer));
...
...
this.exporter.parse(
                model,
                async (gltf) => {
                    console.log(gltf);
                    this.afterExport();

                    const document = await this.io.readJSON({
                        json: gltf,
                        resources: {},
                    });
              ;
                    document.createExtension(DracoMeshCompression).setRequired(true).setEncoderOptions({
                        method: DracoMeshCompression.EncoderMethod.EDGEBREAKER,
                        encodeSpeed: 5,
                    });
                    const arrayBuffer = await this.io.writeBinary(document); // ArrayBuffer
                    const blob = this.saveArrayBuffer(arrayBuffer);

                    if (forDownLoad) this.saveFile(blob);
                    else {
                        const file = new File([blob], 'model.glb', { type: 'model/gltf-binary' });

                        let formData = new FormData();
                        formData.append('3d-file', file);
                        onUpload({ id: this.projectId, data: formData });
                    }
                },
                (e) => {
                    console.error(e);
                },
                this.options,
            );

I checked gltf variable I can see

image

The warning cause in line

const document = await this.io.readJSON({
                        json: gltf,
                        resources: {},
                    });

In side of readJSON code this part call warn

		if (json.extensionsUsed) {
			for (const extensionName of json.extensionsUsed) {
				if (!options.extensions.find((extension) => extension.EXTENSION_NAME === extensionName)) {
					options.logger.warn(`Missing optional extension, "${extensionName}".`);
				}
			}
		}

EXT_mesh_gpu_instancing - Support multiple primitives mesh

Hello !
Using a glb and transforming it with gltf-transform (https://github.com/donmccurdy/glTF-Transform) in 2 steps :

  • dedup (after we used gltf-transfor inspect and we do see several meshes that have many instances - max 102)
  • instance (the one that enable EXT_mesh_gpu_instancing)

We are able to see correct result in babylon.js (in the sandbox) and unity (using GLTFast : https://github.com/atteneder/glTFast).
image
unity_glb_instancing

We we're not able to see the correct results in threejs using your code :
image

Here is the glb that uses EXT_mesh_gpu_instancing:
01_batiment_instance.glb.zip

And thanks for developing this extension for threejs users :)

KHR_materials_variants: Needs a way to select original materials

The KHR_materials_variants plugin needs a way to select original materials. The first argument of .selectVariant() takes variant name and the function selects variant materials. selectVariant() needs a capability to select original materials or a new function would be necessary.

lod.addLevel bug

MSFT_lod.js:

lod.addLevel(mesh, this._calculateDistance(nodeLevel, rootNodeDef))

Causes mesh removed from meshes

MSFT_LOD onUpdate values inconsistent

When loading the torus asset (https://github.com/takahirox/three-gltf-extensions/tree/main/examples/assets/gltf/Torus/glTF-lod),
the update does not return the good mesh :

Using this function as OnUpdate : (e,f) =>{console.log(e,f)}

return

11:50:36.923 
MSFT_LOD_Loader.js:64 LOD {uuid: '19A64444-FB39-4DDD-8C74-B1FFE2AC9253', name: '', type: 'LOD', parent: null, children: Array(1), …} 
Mesh {uuid: 'F2B479C3-3FA3-47D4-9EAD-96B88856A828', name: 'Torus_Low_LOD', type: 'Mesh', parent: LOD, children: Array(0), …}

11:50:36.924 
MSFT_LOD_Loader.js:64 LOD {uuid: '19A64444-FB39-4DDD-8C74-B1FFE2AC9253', name: '', type: 'LOD', parent: null, children: Array(2), …} 
Mesh {uuid: '520EB3BF-00F1-4F39-9157-D76FB020EC0E', name: 'Torus_Middle_LOD', type: 'Mesh', parent: LOD, children: Array(0), …}

11:50:36.924 
MSFT_LOD_Loader.js:64 LOD {uuid: '19A64444-FB39-4DDD-8C74-B1FFE2AC9253', name: '', type: 'LOD', parent: null, children: Array(3), …} 
Mesh {uuid: '1BDD1ED5-AB57-4CE1-8A4F-7591813F2FB0', name: 'Torus', type: 'Mesh', parent: LOD, children: Array(0), …}

11:50:36.924 
MSFT_LOD_Loader.js:64 LOD {uuid: 'FBFC4D70-915F-47F6-8068-4AC6B92ED06D', name: '', type: 'LOD', parent: null, children: Array(1), …} 
Mesh {uuid: '6AE523EF-F985-4B3B-BD3A-74CBBC2EC5AE', name: 'Torus_High_LOD', type: 'Mesh', parent: LOD, children: Array(0), …}

11:50:36.924 
MSFT_LOD_Loader.js:64 LOD {uuid: 'FBFC4D70-915F-47F6-8068-4AC6B92ED06D', name: '', type: 'LOD', parent: null, children: Array(2), …}
Mesh {uuid: 'C6767CBC-08CA-4170-AA51-0939FE8D33B6', name: 'Torus_High_LOD', type: 'Mesh', parent: LOD, children: Array(0), …}

11:50:36.925 
MSFT_LOD_Loader.js:64 LOD {uuid: 'FBFC4D70-915F-47F6-8068-4AC6B92ED06D', name: '', type: 'LOD', parent: null, children: Array(3), …} Mesh {uuid: '1DD73E77-3CFD-428E-A912-448D3BE1CF9D', name: 'Torus_High_LOD', type: 'Mesh', parent: LOD, children: Array(0), …}

which translate to:

  • Donut 1 Low
  • Donut 1 Middle
  • Donut 1 High
  • Donut 2 High
  • Donut 2 High
  • Donut 2 High

Expected behavior :

  • Donut 1 Low
  • Donut 1 Middle
  • Donut 1 High
  • Donut 2 Low
  • Donut 2 Middle
  • Donut 2 High
    or similar (one each, no specific order)...

Is this a naming mistake in the 3D model or a bug ? cannot tell :/

Mozilla Lightmaps?

How much of a hassle would it be to add support for Mozilla-Hubs' own Lightmap implementation?

Cheers and have a nice day!

Move the repository to https://github.com/threejs

As @mrdoob suggested.

Probably I would break up the repository to two, one for the practical plugins (Materials Variants and Texture DDS) and move them there, and another one for the experimental ones (Text and upcoming ones) and keep them under my repository.

[EXT_mesh_gpu_instancing ] Not adjusting the position,scale,rotation for parent geometry

Hi, thanks for the gpu instancing extension, I think it is very comfortable with blender. :)

Any way I think the transform values are not adjusted well for parent geometry.

instTest.glb.zip

This is my test file to check the EXT mesh loader.
As you can see the instanced monkey are look backward and positioned slightly left.
image

but when I load with my own loader and three js editor, I think the parent geometry trasnform are not correct.
image

I console logged the instansed mesh. But I think the matrix(position,scale,rotation) are correct but not adjusted in scene.
스크린샷 2022-11-15 오후 8 48 37

MSFT_LOD LOD scales and render is inconsistent

Hello,
I noticed a strange behavior with a 3D model that contain a lot of LOD in Aframe (threejs 0.137.0).
The model is made internally using gltf-transform and a custom extension and is compliant to MSFT_LOD spec afaik.

The issue is that levels (color coded) are not presented with the same size, and are not hidden correctly. See for example that the threejs representation show both red and green models at the same distance, while both represent a different level.

I suspect that this is correlated with the nesting of the 3D model

Blender representation of the model :
image

Threejs representation of the model :
image

Blender scene representation of the model :
image
The red arrow point to the node hosting MSFT_screencoverage and the extension.

GLTF model
arbre_output.zip

How can I fix this ?

[Feature Request] KHR_techniques_webgl

While the KHR_techniques_webgl extension has been archived, it seems to be quite interesting to use for custom shaders embedded in gltf.
Having this as another extension here to experiment and hack with would be awesome!
Things that would probably need to be controlled by the loader:

  • are the shaders assumed to be WebGL1 or WebGL2
  • are they assumed ShaderMaterial or RawShaderMaterial (should the shader code be prefixed with threejs-specifics or not)

Cesium kinda "supports" this but adds a ton of custom code to the shader, probably its written for one specific exporter (https://github.com/CesiumGS/cesium/blob/94e5646e6c970a83b604652cd908064033ef9870/Source/Scene/processModelMaterialsCommon.js#L400).

If you want to tackle this I'm happy to provide sample files (either WebGL1 or WebGL2). I understand the extension hasn't been ratified because of too many unclarities (as shown by the Cesium implementation), so please close this if you feel it doesn't make sense :)

Use import map for Three.js core

Some plugins have dependency with Three.js core. Currently I ask uses to pass dependent Three.js core objects to plugin constructors.

I don't think it's a good design. If we use import map, it would be simpler.

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.