I’m using playcanvas engine only to build and maintain our application.
The problem is the engine use url string to decide type of resource.
It would be great the type is decided with its content type shipped with http response header.
In my case, all the assets are loaded from the backend server and their url format is ended up with *.do (after excluded query strings)
So I had to change ModelHandler constructor as below.
constructor(device, defaultMaterial) {
this._device = device;
this._parsers = [];
this._defaultMaterial = defaultMaterial;
this.maxRetries = 0;
this.addParser(new JsonModelParser(this._device), function (url, data) {
return (path.getExtension(url) === '.json');
});
this.addParser(new GlbModelParser(this._device), function (url, data) {
return (path.getExtension(url) === '.glb' || path.getBasename(url) === 'glb.do');
});
}
Also, I need to modify AnimationHandler.load function as below.
load(url, callback) {
if (typeof url === 'string') {
url = {
load: url,
original: url
};
}
// we need to specify JSON for blob URLs
const options = {
retry: this.maxRetries > 0,
maxRetries: this.maxRetries
};
console.log("Animation Handler > url : ",url);
if (url.load.split('?')[0].endsWith('glb.do') || url.load.startsWith('blob:') || url.load.startsWith('data:')) {
if (path.getExtension(url.original).toLowerCase() === '.glb') {
console.log('response type is set to array buffer.');
options.responseType = Http.ResponseType.ARRAY_BUFFER;
} else {
options.responseType = Http.ResponseType.JSON;
}
}
http.get(url.load, options, function (err, response) {
if (err) {
callback("Error loading animation resource: " + url.original + " [" + err + "]");
} else {
callback(null, response);
}
});
}
There are comple more parts I’ve modified to load textures and materials.
So, I just wonder why playcanvas engine doesn’t use content-type from response header instead of paring url.
Hope this can be considered for the next update.