loadFromUrl doesn't get called a second time after it loads a specific url once

app.assets.loadFromUrl(url, "model", function (err, asset) {            
            entity.model.model = asset.resource;

I have an event handler that triggers loadFromUrl when a user chooses a model from a drop down. But the loadFromUrl api doesn’t seem to call the success function after it’s loaded once. Is there an alternative to reload the same mode(from url) again?

Right now I’m having to do a hack and save the model in a dictionary once it’s loaded so that I don’t have to reload. But I fear this can easily eat away memory once too many models are loaded.


When, probably you have to call loadFromUrl only when you ensure that you haven’t load this asset before?..

Yes, sure that’s better for a subset of cases but not all.

  1. It saves on extra network calls
  2. It makes asset load faster.

But there are cases where I don’t want to store all the assets (imagine 1000s of furniture 3d models) I have loaded in memory. Since this is likely to use up my user’s memory.

In such a case this is highly inconvenient that I can’t reload the same asset from the same url.

Well, it’s still clear.
Instead of resolving asset just delete it every time, if it exists.

and how do you delete the asset ? I’m using the removeComponent on Entity but that doesn’t solve the above problem

var LoadFloorPlan = pc.createScript('loadFloorPlan');

LoadFloorPlan.prototype.initialize = function() {
    var entity = new pc.Entity();
    var app = this.app;
    var floorPlans = {};
    window.addEventListener("message", function (event) {        
//     // if (event.origin === "http://localhost:3000") {
        var url = event.data.home_model_url;
            entity.model.model = floorPlans[url];
        app.assets.loadFromUrl(url, "model", function (err, asset) {            
            entity.model.model = asset.resource;
            floorPlans[url] = asset.resource;
    // }
    }, false);

According to API this method called “unload”.

Ahh, cool thanks. I’ll try that.