It is easy to get lost in code for a newbie like me, in which line should I add error handler if there are any errors while parsing the file (err) ?
console.log('Model failed to load')
Thanks in advice
entity = new pc.Entity('Model');
pc.app.root.addChild(entity);
pc.app.assets.loadFromUrlAndFilename(modelurl, null, "container", function (err, asset) {
// Add the loaded scene to the hierarchy
entity.addComponent('model', {
asset: asset.resource.model
});
entity.addComponent('collision', {
type: 'mesh',
asset: asset.resource.model
});
entity.addComponent('rigidbody', {
type: pc.BODYTYPE_KINEMATIC
});
if (asset.resource.animations.length > 0) {
entity.addComponent('animation', {
assets: asset.resource.animations
});
}
entity.aabb = new pc.BoundingBox();
var meshes = entity.model.model.meshInstances;
if (meshes.length) {
entity.aabb.copy(meshes[0].aabb);
for(var i = 1; i < meshes.length; i++)
entity.aabb.add(meshes[i].aabb);
console.log(meshes);
x = entity.aabb.halfExtents.x * 2;
console.log(x);
y = entity.aabb.halfExtents.y * 2;
console.log(y);
z = entity.aabb.halfExtents.z * 2;
console.log(z);
var meshInstances = entity.model.meshInstances;
var mat;
var total = 0;
for (var i2 = 0; i2 < meshInstances.length; i2++) {
// mat = meshInstances[i].mesh.vertexBuffer.numVertices;
mat = parseFloat(meshInstances[i2].mesh.indexBuffer[0].numIndices / 3);
total += mat;
}
console.log(total);
}
});
The goal is to prevent crashing/executing the whole piece of code if error occurs