Geopipe / gltf2glb

GLTF to Binary GLTF (GLB) converter, supporting Cesium Batch and Instance files (b3dm and i3dm) as well.
BSD 3-Clause "New" or "Revised" License
93 stars 27 forks source link

gltf to b3dm #4

Open qdnguyen opened 7 years ago

qdnguyen commented 7 years ago

HI,

Thank for your tools!

I have converted a gltf to b3dm file with success but when i use threejs GLTF loader to parse the b3dm file, i got this error:

GLTFLoader.js:980 Uncaught (in promise) TypeError: Cannot read property 'binary_glTF' of undefined at GLTFLoader.js:980 at _each (GLTFLoader.js:592) at GLTFLoader.js:978 at

Do you have any idea what is problem?

p/s : I can visualize my gltf file with this online demo without problem (please see attached file) LYON_1ER_00033.zip

https://gltf-viewer.donmccurdy.com/

My gltf file has 21.4KB but the converted b3dm file takes 187KB, is it possible?

Thank for your reply!

qdnguyen commented 7 years ago

i think it embed the texture by default, i tried to desactivate it without success.

KermMartian commented 7 years ago

2ff30d6 should fix this; please test at your convenience.

qdnguyen commented 7 years ago

Thank you very much for you quick reply, it seem that patch fix the embeded texture problem but i still can not visualize the converted file (both glb and b3dm) with gltf-viewer.

For online viewer (gltf-viewer), i got this error:

Uncaught Error: GLTF2Loader: Legacy binary file detected. Use GLTFLoader instead. at new GLTFBinaryExtension (bundle.js:863) at GLTF2Loader.parse (bundle.js:558) at bundle.js:531 at XMLHttpRequest. (bundle.js:34154)

and for my viewer, i had this error:

GLTFLoader.js:980 Uncaught (in promise) TypeError: Cannot read property 'binary_glTF' of undefined at GLTFLoader.js:980 at _each (GLTFLoader.js:592) at GLTFLoader.js:978 at

Do you have any idea?

qdnguyen commented 7 years ago

ok, the problem is that this tool is not compatible with gltf 2.0, if i use older gltfLoader, it work, have you plan to upgrade this tool?

thank anyway

KermMartian commented 7 years ago

I'd certainly like to make it compatible with GLTF 2.0. Do you have any idea about what specifically is incompatible between this tool and GLTF 2.0?

qdnguyen commented 7 years ago

i take a look at GLTFLoader, and i saw that it arrive to parse header, json but not accessor and i do not know why?

i have this error in the function loadAccessors

GLTFLoader.js:1023 Uncaught (in promise) RangeError: Invalid typed array length at new Float32Array (native)

GLTFParser.prototype.loadAccessors = function () {

        var json = this.json;

        return this._withDependencies( [

            "bufferViews"

        ] ).then( function ( dependencies ) {

            return _each( json.accessors, function ( accessor ) {

                var arraybuffer = dependencies.bufferViews[ accessor.bufferView ];
                var itemSize = WEBGL_TYPE_SIZES[ accessor.type ];
                var TypedArray = WEBGL_COMPONENT_TYPES[ accessor.componentType ];

                // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
                var elementBytes = TypedArray.BYTES_PER_ELEMENT;
                var itemBytes = elementBytes * itemSize;

                // The buffer is not interleaved if the stride is the item size in bytes.
                if ( accessor.byteStride && accessor.byteStride !== itemBytes ) {

                    // Use the full buffer if it's interleaved.
                    var array = new TypedArray( arraybuffer );

                    // Integer parameters to IB/IBA are in array elements, not bytes.
                    var ib = new THREE.InterleavedBuffer( array, accessor.byteStride / elementBytes );

                    return new THREE.InterleavedBufferAttribute( ib, itemSize, accessor.byteOffset / elementBytes );

                } else {

                    **array = new TypedArray( arraybuffer, accessor.byteOffset, accessor.count * itemSize );**

                    return new THREE.BufferAttribute( array, itemSize );

                }

            } );

        } );

    };
KermMartian commented 7 years ago

Can you please provide the input GLTF 2.0 file and the command line you're trying to use to convert it for my debugging?

qdnguyen commented 7 years ago

i attache the file here TilesetBuilding.zip

i have tried with many command line such as gltf2glb.py -b "" -o LYON_1ER_00042.b3dm LYON_1ER_00042.gltf

gltf2glb.py -c -b "" -o LYON_1ER_00042.b3dm LYON_1ER_00042.gltf

gltf2glb.py LYON_1ER_00042.gltf

the last one generate a glb file then you can test it with threejs gltfLoader

https://threejs.org/examples/#webgl_loader_gltf http://localhost/Github/threejs/examples/#webgl_loader_gltf2

Thank for your debug!

p/s : I was wrong in my comment a day ago. The glb file, which is generated with your tools, does not work with threejs gltfLoader, but the glb file generated by https://github.com/Qantas94Heavy/binary-gltf-utils/, works well!

KermMartian commented 7 years ago

I was able to use the latest commit to successfully convert your file into a GLB that the three.js example viewer can load. Please verify, and if you replicate my success, I'll close this.

qdnguyen commented 7 years ago

Thank you, but it does not work for me, please see attached photo to have more information!

image

iyush1993 commented 4 years ago

Hi @qdnguyen, May I know how you converted gltf to b3dm?

leopessanha74 commented 3 years ago

I'd like to know how to convert gltf files to b3dm too!