We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Detect if object has a texture applied

Home Forums Programming Detect if object has a texture applied

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27825
    web
    Customer

    I’m applying some textures on runtime to a list of objects:
    object.material = new v3d.MeshBasicMaterial({map: texture});

    This works without any problems. But when this function is called again with the texture already applied, then there is a fast “blink” when the texture is getting reapplied.

    Therefor I thought to extend the function to check if there is already a texture on the object. At first I thought I could just use someting like:

    if(object.material.map.image)
    //do stuff

    But because the objects I’m working with, sometimes are hidden. The function throws an error because it cant read the property.

    I’m therefor wondering what would be the proper way to detect if an object has a texture applied?

    #27836

    Hi,

    I guess, that for those objects the object.material.map property is undefined. You can try something like this to fix it:

    
    var map = object.material.map;
    if (map && map.image) {
        // do stuff
    }
    

    Co-founder and lead developer at Soft8Soft.

    #27887
    web
    Customer

    Great thx, will try it.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.