Good afternoon guys,
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.
My project is:
And the script is:
gltf-load.js
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));
}
Any idea of what is going on?