UPDATED: See the example project here: https://playcanvas.com/editor/scene/1084051
UPDATE #2: Here is the working code, for anyone else having this issue:
…
/* jshint esversion: 6 */
var DynamicAssetLoader = pc.createScript(‘dynamicAssetLoader’);
DynamicAssetLoader.prototype.initialize = function() {
this.testAssetLoading();
};
DynamicAssetLoader.prototype.testAssetLoading = function() {
const cube01 = this.app.root.findByName("Cube_Example-01");
this.loadAssetResourceCallback("example_preload-off.png", (loadedAsset) => {
cube02.model.meshInstances[0].material.diffuseMap = loadedAsset.resource;
cube02.model.meshInstances[0].material.update(); // THE FIX !!!
});
};
DynamicAssetLoader.prototype.loadAssetResourceCallback = function(assetName, callback) {
var loadedAsset = this.app.assets.find(assetName);
var onAssetLoaded = function() {
callback(loadedAsset);
};
if (loadedAsset.resource) {
return onAssetLoaded();
} else {
loadedAsset.ready(onAssetLoaded);
this.app.assets.load(loadedAsset);
}
};
…
I am trying to create a generic function that will load and return an asset which I can apply to an entity.
Since I have about 60+ textures but will only use 4 per level, I only want to load those required for my level.
The correct asset are being loaded and passed back, but they don’t have any texture data and display as white.
I’m using code straight from https://developer.playcanvas.com/en/tutorials/using-assets/
and searched the forums, but haven’t found anyone experiencing this exact issue
I’m using code straight from https://developer.playcanvas.com/en/tutorials/using-assets/
and searched the forums, but haven’t found anyone experiencing this exact issue
I’m trying to avoid providing a callback, but is that my only workable option here?
Apologies for the epic post, trying to provide enough data to be helpful. Thanks all!
Any thoughts @yaustar?