I’m trying to create a texture from a canvas image and I’m getting some odd results.
I have a plane entity in a scene with this code attached. The canvas element is created in another function and looks correct. Once it’s drawn the following code is called. Currently the plane turns black. There’s several steps I’m not sure about specifically how what to pass to the pc.Texture() command. Below I’m pass the canvas element itself.
var canvas= document.getElementById('textureCanvas');
var texture = new pc.Texture(canvas, {
width: 192,
height: 192,
format: pc.PIXELFORMAT_R8_G8_B8
});
//add it to the registry and assign
var dynamicAsset = new pc.Asset("portraitSheet", "texture", {
url: "", // not sure exactly what you want to put in here, empty string might be fine
});
dynamicAsset.resource = texture;
dynamicAsset.loaded = true;
dynamicAsset.on("error", (message) =>{
console.log(message);
});
this.app.assets.add(dynamicAsset);
console.log("putting this bad boy on the plane");
var material = this.entity.model.material;
material.diffuseMap = dynamicAsset.resource;
material.update();
dynamicAsset.on("load", (asset)=> {
//load isn't called
});