I have a GLTF model that i want to load by playcanvas-gltf.js. I did what the documentation of this script show, but nothing happens and no error is displayed.
GltfLoad.prototype.initialize = function() {
var gltfAsset = this.app.assets.find('BoxTextured.gltf');
var binAsset = this.app.assets.find('BoxTextured.bin');
var self = this;
var json = ab2str(gltfAsset.resource);
var gltf = JSON.parse(json);
loadGltf(gltf, this.app.graphicsDevice, gltfCallback, {buffers: binAsset.resource, processUri: texturePath});
function texturePath(url, callback){
callback(self.app.assets.find('BoxTextured.png').getFileUrl());
}
function gltfCallback (model, textures, animationClips) {
// Wrap the model as an asset and add to the asset registry
var asset = new pc.Asset('gltf', 'model', {
url: ''
});
asset.resource = model;
asset.loaded = true;
self.app.assets.add(asset);
// Add the loaded scene to the hierarchy
var gltf = new pc.Entity('gltf');
gltf.addComponent('model', {
asset: asset
});
console.log(asset);
console.log(gltf);
gltf.model.meshInstances[0].material = new pc.StandardMaterial();
gltf.model.meshInstances[0].material.update();
self.app.root.children[0].addChild(gltf);
}
};
// source: http://stackoverflow.com/a/11058858
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
It’s because the glTF loader only works with GLB or embedded (single file) glTF files if you are using the Editor. You have are trying to load an unbundled glTF file.
If you were using just the Engine stand-along, you could also load unbundled glTF.
Only if you place the unbundled glTF files on your own server somewhere. This is because the loader code tries to load unbundled files from paths relative to the gltf file itself. But when you upload all the files to the Editor, they’re moved to unrelated folders. It’s conceivable that the glTF loader code could be updated to use the PlayCanvas server file locations, but I personally don’t have time to do that right now. Ideally, you should be using GLB anyway, because it’s a more efficient serialization format for GLTF (fewer HTTP requests, smaller binary format).