Text material for custom assets

I’ve been trying to apply a variable text as a material to my custom asset.
I succeded it to a sphere model but when I tried the same thing to the custom asset, it didn’t work.
What should I do to do this?

https://playcanvas.com/editor/scene/893990

Hi @Hee and welcome!

For assigning materials in code you have to iterate through their mesh instances array and do the assignment. And also if you would like to have a different texture per model then clone the material instead of making the changes to the same instance each time:

    // ####################################################
    // Material
    // ####################################################
    
    this.entity.model.meshInstances.forEach( function(meshInstance){
        
        meshInstance.material = meshInstance.material.clone();
        
        meshInstance.material.diffuse = this.fontColor;//new pc.Color(1, 0, 0, 1);
        meshInstance.material.blendType = pc.BLEND_NORMAL;
        meshInstance.material.emissive = this.fontColor;//.set(0, 0, 1);
        meshInstance.material.emissiveMap = this.texture;
        meshInstance.material.emissiveMapTint = true;
        meshInstance.material.opacityMap = this.texture;
        meshInstance.material.blendType = pc.BLEND_NORMAL;
        meshInstance.material.opacity = 1;
        meshInstance.material.alphaTest = 0;
        meshInstance.material.noFog = true;
        meshInstance.material.update();
        
    }.bind(this));

Though this still won’t solve your issue, it seems your model is missing texture coordinates:

image

I’ve loaded another model that is UVW unwrapped and it works correctly. If you fix that on your model it’s going to work.

Ofcourse to have the text texture positioned and aligned properly, you must UVW unwrap your model in your modelling app accordingly.

Hi Leonidas!

I understand the mesh instances array. Thank you for explanation.

But still stuck haha. I found Auto-unwrap at model>pipeline>padding.
Is this the same function as UVW unwrap in modelling app like you said?
OR should I do unwrap the model in an external app?

1 Like

Hey @Hee, no that is to create a second set of texture coordinates (channel UV1) to be used for lightmapping.

To properly unwrap your model you will have to do it in an external app.