### Navigation

- index
- modules |
- previous |
- 3D Graphics »

# Texture Support

This module provides texture/material support for 3D Graphics objects and plotting. This is a very rough common interface for Tachyon, x3d, and obj (mtl). See `Texture` and `Texture_class` for full details about options and use.

Initially, we have no textures set:

    sage: sage.plot.plot3d.base.Graphics3d().texture_set()
    set()

However, one can access these textures in the following manner:

    sage: G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=0.5)
    sage: [t for t in G.texture_set() if t.color == colors.red] # we should have two red textures
    [Texture(texture..., red, ff0000), Texture(texture..., red, ff0000)]
    sage: [t for t in G.texture_set() if t.color == colors.yellow] # ...and one yellow
    [Texture(texture..., yellow, ffff00)]

And the Texture objects keep track of all their data:

    sage: T = tetrahedron(color='red', opacity=0.5)
    sage: t = T.get_texture()
    sage: t.opacity
    0.500000000000000
    sage: T # should be translucent
    Graphics3d Object

AUTHOR:

- Robert Bradshaw (2007-07-07) Initial version.

`sage.plot.plot3d.texture.``Texture`(id=None, **kwds)

  Return a texture.

  INPUT:

  - `id` - a texture (optional, default: None), a dict, a color, a str, a tuple, None or any other type acting as an ID. If `id` is None, then it returns a unique texture object.
  - `texture` - a texture
  - `color` - tuple or str, (optional, default: (.4, .4, 1))
  - `opacity` - number between 0 and 1 (optional, default: 1)
  - `ambient` - number (optional, default: 0.5)
  - `diffuse` - number (optional, default: 1)
  - `specular` - number (optional, default: 0)
  - `shininess` - number (optional, default: 1)
  - `name` - str (optional, default: None)
  - `**kwds` - other valid keywords

  OUTPUT:

  A texture object.

  EXAMPLES:

  Texture from integer `id`:

      sage: from sage.plot.plot3d.texture import Texture
      sage: Texture(17)
      Texture(17, 6666ff)

  Texture from rational `id`:

      sage: Texture(3/4)
      Texture(3/4, 6666ff)

  Texture from a dict:

      sage: Texture({'color':'orange','opacity':0.5})
      Texture(texture..., orange, ffa500)

  Texture from a color:

      sage: c = Color('red')
      sage: Texture(c)
      Texture(texture..., ff0000)

  Texture from a valid string color:

      sage: Texture('red')
      Texture(texture..., red, ff0000)

  Texture from a non valid string color:

      sage: Texture('redd')
      Texture(redd, 6666ff)

  Texture from a tuple:

      sage: Texture((.2,.3,.4))
      Texture(texture..., 334c66)

  Textures using other keywords:

      sage: Texture(specular=0.4)
      Texture(texture..., 6666ff)
      sage: Texture(diffuse=0.4)
      Texture(texture..., 6666ff)
      sage: Texture(shininess=0.3)
      Texture(texture..., 6666ff)
      sage: Texture(ambiant=0.7)
      Texture(texture..., 6666ff)

class `sage.plot.plot3d.texture.``Texture_class`(id, color=(0.4, 0.4, 1), opacity=1, ambient=0.5, diffuse=1, specular=0, shininess=1, name=None, **kwds)

  Bases: `sage.structure.sage_object.SageObject`

  Construction of a texture.

  See documentation of `Texture` for more details and examples.

  EXAMPLES:

  We create a translucent texture:

      sage: from sage.plot.plot3d.texture import Texture
      sage: t = Texture(opacity=0.6)
      sage: t
      Texture(texture..., 6666ff)
      sage: t.opacity
      0.600000000000000
      sage: t.jmol_str('obj')
      'color obj translucent 0.4 [102,102,255]'
      sage: t.mtl_str()
      'newmtl texture...\nKa 0.2 0.2 0.5\nKd 0.4 0.4 1.0\nKs 0.0 0.0 0.0\nillum 1\nNs 1\nd 0.600000000000000'
      sage: t.x3d_str()
      "<Appearance><Material diffuseColor='0.4 0.4 1.0' shininess='1' specularColor='0.0 0.0 0.0'/></Appearance>"

  `hex_rgb`()

    EXAMPLES:

        sage: from sage.plot.plot3d.texture import Texture
        sage: Texture('red').hex_rgb()
        'ff0000'
        sage: Texture((1, .5, 0)).hex_rgb()
        'ff7f00'

  `jmol_str`(obj)

    Converts Texture object to string suitable for Jmol applet.

    INPUT:

    - `obj` - str

    EXAMPLES:

        sage: from sage.plot.plot3d.texture import Texture
        sage: t = Texture(opacity=0.6)
        sage: t.jmol_str('obj')
        'color obj translucent 0.4 [102,102,255]'

        sage: sum([dodecahedron(center=[2.5*x, 0, 0], color=(1, 0, 0, x/10)) for x in range(11)]).show(aspect_ratio=[1,1,1], frame=False, zoom=2)

  `mtl_str`()

    Converts Texture object to string suitable for mtl output.

    EXAMPLES:

        sage: from sage.plot.plot3d.texture import Texture
        sage: t = Texture(opacity=0.6)
        sage: t.mtl_str()
        'newmtl texture...\nKa 0.2 0.2 0.5\nKd 0.4 0.4 1.0\nKs 0.0 0.0 0.0\nillum 1\nNs 1\nd 0.600000000000000'

  `tachyon_str`()

    Converts Texture object to string suitable for Tachyon ray tracer.

    EXAMPLES:

        sage: from sage.plot.plot3d.texture import Texture
        sage: t = Texture(opacity=0.6)
        sage: t.tachyon_str()
        'Texdef texture...\n  Ambient 0.333333333333 Diffuse 0.666666666667 Specular 0.0 Opacity 0.600000000000000\n   Color 0.4 0.4 1.0\n   TexFunc 0'

  `x3d_str`()

    Converts Texture object to string suitable for x3d.

    EXAMPLES:

        sage: from sage.plot.plot3d.texture import Texture
        sage: t = Texture(opacity=0.6)
        sage: t.x3d_str()
        "<Appearance><Material diffuseColor='0.4 0.4 1.0' shininess='1' specularColor='0.0 0.0 0.0'/></Appearance>"

`sage.plot.plot3d.texture.``is_Texture`(x)

  Return whether `x` is an instance of `Texture_class`.

  EXAMPLES:

      sage: from sage.plot.plot3d.texture import is_Texture, Texture
      sage: t = Texture(0.5)
      sage: is_Texture(t)
      True

      sage: is_Texture(4)
      False

`sage.plot.plot3d.texture.``parse_color`(info, base=None)

  Parses the color.

  It transforms a valid color string into a color object and a color object into an RBG tuple of length 3. Otherwise, it multiplies the info by the base color.

  INPUT:

  - `info` - color, valid color str or number
  - `base` - tuple of length 3 (optional, default: None)

  OUTPUT:

  A tuple or color.

  EXAMPLES:

  From a color:

      sage: from sage.plot.plot3d.texture import parse_color
      sage: c = Color('red')
      sage: parse_color(c)
      (1.0, 0.0, 0.0)

  From a valid color str:

      sage: parse_color('red')
      RGB color (1.0, 0.0, 0.0)
      sage: parse_color('#ff0000')
      RGB color (1.0, 0.0, 0.0)

  From a non valid color str:

      sage: parse_color('redd')
      Traceback (most recent call last):
      ...
      ValueError: unknown color 'redd'

  From an info and a base:

      sage: opacity = 10
      sage: parse_color(opacity, base=(.2,.3,.4))
      (2.0, 3.0, 4.0)

### Navigation

- index
- modules |
- previous |
- 3D Graphics »