Skip to content

Commit

Permalink
Fix reloading model primitive materials
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalpias committed Aug 31, 2015
1 parent a695e42 commit 49436c1
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/framework/components/model/model_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,6 @@ pc.extend(pc, function () {
_onMaterialAsset: function(asset) {
var assets = this.system.app.assets;

// unsubscribe
if (this.data.materialAsset !== asset.id) {
if (this.data.materialAsset)
this._onMaterialAssetRemove(this.data.materialAsset);

assets.on('load:' + asset.id, this._onMaterialAsset, this);
assets.once('remove:' + asset.id, this._onMaterialAssetRemove, this);
}

if (asset.resource) {
this.material = asset.resource;
} else {
Expand All @@ -290,19 +281,27 @@ pc.extend(pc, function () {
var assets = this.system.app.assets;
var self = this;

// unsubscribe
if (this.data.materialAsset !== id) {
if (this.data.materialAsset)
this._onMaterialAssetRemove(this.data.materialAsset);

if (id) {
assets.on('load:' + id, this._onMaterialAsset, this);
assets.once('remove:' + id, this._onMaterialAssetRemove, this);
}
}

// try to load the material asset
if (id !== undefined && id !== null) {
var asset = assets.get(id);
if (asset)
this._onMaterialAsset(asset);

// subscribe for adds
assets.on('add:' + id, this._onMaterialAsset, this);
assets.once('add:' + id, this._onMaterialAsset, this);
} else if (id === null) {
self.material = pc.ModelHandler.DEFAULT_MATERIAL;

if (this.data.materialAsset)
this._onMaterialAssetRemove(this.data.materialAsset);
}

var valueOld = this.data.materialAsset;
Expand Down

0 comments on commit 49436c1

Please sign in to comment.