Search code examples
pythonvpython

How to add texture in Vpython?


i Wonder How to put texture on my boxes in my Vpython script?


Solution

  • from visual import *
    
    box(pos=(-1,-1,-2), length=2, height=2, width=4, material=materials.wood)
    

    enter image description here

    For more details, see http://vpython.org/contents/docs/visual/materials.html

    Edit: at the link above, look for the section titled "Making a texture from a photo"

    Edit2: not sure what's causing your error; this works for me:

    from visual import *
    import Image
    
    im = Image.open('flower.jpg')  # size must be power of 2, ie 128 x 128
    tex = materials.texture(data=im, mapping='rectangular')
    
    box(material=tex)
    

    enter image description here

    Edit3: I figured out what caused your error:

    box(material=materials.loadTGA(filename))
    

    fails;

    tex = materials.texture(data=loadTGA(filename), mapping='rectangular')
    box(material=tex)
    

    works properly.