[SOLVED] Detect if glb or gltf is valid?

Hi, I have a question, I’m loading lots of models using loadFromUrlAndFilename, I was wondering is it possible to detect for a valid model prior loading, let’s say I’d try to load a empty model.glb file, the engine throws RangeError: Offset is outside the bounds of the DataView thus failing to load other valid models aswell

PlayCanvas engine only supports loading GLBs. You can validate GLBs here glTF Validator

Theres no way for the engine to know if the GLB is valid before loading hence its important to check for errors in the callback of loadFromUrl.

Playcanvas can load gltf + bin as well, not only glb - you can drag & drop those into our viewer as well.

Hi @Newbie_Coder,

Can you give us a repro of this? One GLB failing to load should not stop others from loading.

If these were preload assets, then scene might never finish loading because one failed. But that shouldn’t be an issue if you’re loadFromUrlAndFilename yourself.

Thanks!

Hi, Yes I’m using loadFromUrlAndFilename, I loop trough entities, every entity has a property of model url, and the loadFromUrlAndFilename works in another loop aswell, probably that’s the case

That’s a great find, unfortunately, couldn’t find any examples as I need it to work with URLS rather than picking file, the dart conversion to js in unreadable to my eyes yet, however, I’ve got some luck with Node.js, but again, not sure how to achieve this:
Player sends request to Node server with model url to be checked and gets appropriate response

const fs = require('fs');
const validator = require('gltf-validator');



const http = require('http');
const https = require("https");

const file = fs.createWriteStream("Ant.glb");

https.get("https://example.com/models/Ant.glb", response => {
  var stream = response.pipe(file);

  stream.on("finish", function() {
const asset = fs.readFileSync("Ant.glb");
validator.validateBytes(new Uint8Array(asset))
    .then((report) => console.info('Validation succeeded: ', report))
    .catch((error) => console.error('Validation failed: ', error));
  });
});


Whats the context of this issue? Isnt the engine telling you that the GLB is invalid when you try to load it enough?

The whole loop of model loading fails due to this, players are able to load models into the PlayCanvas engine/world, only if asset loads corecctly it gets added to global loading loop, in theory, player’s can’t submit non working assets unless…The request would be spoofed

If we load a blank file model we get these errors

RangeError: Offset is outside the bounds of the DataView
Uncaught TypeError: Cannot read properties of undefined (reading 'model')

As far as I understand, I’d still need to load model in order to catch errors etc so there’s no way to handle these prior loading,or am I wrong?

Update:
I can fix Uncaught TypeError: Cannot read properties of undefined (reading 'model') by
if (asset._resources[0]){

Still, no ideas how to solve this without validation RangeError: Offset is outside the bounds of the DataView

We can mark this as solved, turns out the loop wasn’t working not due to error, but some of my variables were blocking it, have to reset them on error/failed model load.

This is sort of a workaround instead of validation, but hey, it works

Great, thanks for letting us know.