Add texture to a box

I am new to coding in Playcanvas and would like to simply add an image to a box in runtime:

var asset_testImage ="testImages.png");
var asset_testImage_url = asset_testImage.getFileUrl();
// option 1
var asphaltTexture = new pc.Asset("asphaltTexture", "texture", {
        url: asset_testImage.getFileUrl()

// option 2
var asphaltTexture2 = new pc.Texture(;

box.addComponent("model", {
        type: "box"

var materialista = new pc.StandardMaterial();
    materialista.diffuseMap = asphaltTexture; // or asphaltTexture2??

box.model.material.diffuseMap = asphaltTexture2;

Is this the right way? I tried to solve it like the steps in the editor. What am I doing wrong?

Close, if the image is already the the assets, then it it is already a texture. Example:

1 Like

Thank you so much! I dont know how many hours I spent for this little thing