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
for full details about options and use.
Initially, we have no textures set:
sage: sage.plot.plot3d.base.Graphics3d().texture_set()
set()
>>> from sage.all import *
>>> sage.plot.plot3d.base.Graphics3d().texture_set()
set()
sage.plot.plot3d.base.Graphics3d().texture_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)]
>>> from sage.all import *
>>> G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=RealNumber('0.5'))
>>> [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)]
>>> [t for t in G.texture_set() if t.color == colors.yellow] # ...and one yellow
[Texture(texture..., yellow, ffff00)]
G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=0.5) [t for t in G.texture_set() if t.color == colors.red] # we should have two red textures [t for t in G.texture_set() if t.color == colors.yellow] # ...and one yellow
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.5
sage: T # should be translucent
Graphics3d Object
>>> from sage.all import *
>>> T = tetrahedron(color='red', opacity=RealNumber('0.5'))
>>> t = T.get_texture()
>>> t.opacity
0.5
>>> T # should be translucent
Graphics3d Object
T = tetrahedron(color='red', opacity=0.5) t = T.get_texture() t.opacity T # should be translucent
AUTHOR:
Robert Bradshaw (2007-07-07) Initial version.
- class sage.plot.plot3d.texture.Texture(id, color=(0.4, 0.4, 1), opacity=1, ambient=0.5, diffuse=1, specular=0, shininess=1, name=None, **kwds)[source]¶
Bases:
WithEqualityById
,SageObject
Class representing a texture.
See documentation of
Texture.__classcall__
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.6 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.0\nd 0.6' sage: t.x3d_str() "<Appearance><Material diffuseColor='0.4 0.4 1.0' shininess='1.0' specularColor='0.0 0.0 0.0'/></Appearance>"
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> t = Texture(opacity=RealNumber('0.6')) >>> t Texture(texture..., 6666ff) >>> t.opacity 0.6 >>> t.jmol_str('obj') 'color obj translucent 0.4 [102,102,255]' >>> 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.0\nd 0.6' >>> t.x3d_str() "<Appearance><Material diffuseColor='0.4 0.4 1.0' shininess='1.0' specularColor='0.0 0.0 0.0'/></Appearance>"
from sage.plot.plot3d.texture import Texture t = Texture(opacity=0.6) t t.opacity t.jmol_str('obj') t.mtl_str() t.x3d_str()
- hex_rgb()[source]¶
EXAMPLES:
sage: from sage.plot.plot3d.texture import Texture sage: Texture('red').hex_rgb() 'ff0000' sage: Texture((1, .5, 0)).hex_rgb() 'ff7f00'
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> Texture('red').hex_rgb() 'ff0000' >>> Texture((Integer(1), RealNumber('.5'), Integer(0))).hex_rgb() 'ff7f00'
from sage.plot.plot3d.texture import Texture Texture('red').hex_rgb() Texture((1, .5, 0)).hex_rgb()
- jmol_str(obj)[source]¶
Convert 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]'
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> t = Texture(opacity=RealNumber('0.6')) >>> t.jmol_str('obj') 'color obj translucent 0.4 [102,102,255]'
from sage.plot.plot3d.texture import Texture t = Texture(opacity=0.6) t.jmol_str('obj')
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)
>>> from sage.all import * >>> sum([dodecahedron(center=[RealNumber('2.5')*x, Integer(0), Integer(0)], color=(Integer(1), Integer(0), Integer(0), x/Integer(10))) for x in range(Integer(11))]).show(aspect_ratio=[Integer(1),Integer(1),Integer(1)], frame=False, zoom=Integer(2))
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)
>>> from sage.all import * >>> sum([dodecahedron(center=[RealNumber('2.5')*x, Integer(0), Integer(0)], color=(Integer(1), Integer(0), Integer(0), x/Integer(10))) for x in range(Integer(11))]).show(aspect_ratio=[Integer(1),Integer(1),Integer(1)], frame=False, zoom=Integer(2))
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()[source]¶
Convert 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.0\nd 0.6'
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> t = Texture(opacity=RealNumber('0.6')) >>> 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.0\nd 0.6'
from sage.plot.plot3d.texture import Texture t = Texture(opacity=0.6) t.mtl_str()
- tachyon_str()[source]¶
Convert 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.3333333333333333 Diffuse 0.6666666666666666 Specular 0.0 Opacity 0.6\n Color 0.4 0.4 1.0\n TexFunc 0'
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> t = Texture(opacity=RealNumber('0.6')) >>> t.tachyon_str() 'Texdef texture...\n Ambient 0.3333333333333333 Diffuse 0.6666666666666666 Specular 0.0 Opacity 0.6\n Color 0.4 0.4 1.0\n TexFunc 0'
from sage.plot.plot3d.texture import Texture t = Texture(opacity=0.6) t.tachyon_str()
- x3d_str()[source]¶
Convert 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.0' specularColor='0.0 0.0 0.0'/></Appearance>"
>>> from sage.all import * >>> from sage.plot.plot3d.texture import Texture >>> t = Texture(opacity=RealNumber('0.6')) >>> t.x3d_str() "<Appearance><Material diffuseColor='0.4 0.4 1.0' shininess='1.0' specularColor='0.0 0.0 0.0'/></Appearance>"
from sage.plot.plot3d.texture import Texture t = Texture(opacity=0.6) t.x3d_str()
- sage.plot.plot3d.texture.is_Texture(x)[source]¶
Deprecated. Use
isinstance(x, Texture)
instead.EXAMPLES:
sage: from sage.plot.plot3d.texture import is_Texture, Texture sage: t = Texture(0.5) sage: is_Texture(t) doctest:...: DeprecationWarning: Please use isinstance(x, Texture) See https://github.com/sagemath/sage/issues/27593 for details. True
>>> from sage.all import * >>> from sage.plot.plot3d.texture import is_Texture, Texture >>> t = Texture(RealNumber('0.5')) >>> is_Texture(t) doctest:...: DeprecationWarning: Please use isinstance(x, Texture) See https://github.com/sagemath/sage/issues/27593 for details. True
from sage.plot.plot3d.texture import is_Texture, Texture t = Texture(0.5) is_Texture(t)
- sage.plot.plot3d.texture.parse_color(info, base=None)[source]¶
Parse 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 numberbase
– tuple of length 3 (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 sage.all import * >>> from sage.plot.plot3d.texture import parse_color >>> c = Color('red') >>> parse_color(c) (1.0, 0.0, 0.0)
from sage.plot.plot3d.texture import parse_color c = Color('red') parse_color(c)
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 sage.all import * >>> parse_color('red') RGB color (1.0, 0.0, 0.0) >>> parse_color('#ff0000') RGB color (1.0, 0.0, 0.0)
parse_color('red') parse_color('#ff0000')
From a non valid color str:
sage: parse_color('redd') Traceback (most recent call last): ... ValueError: unknown color 'redd'
>>> from sage.all import * >>> parse_color('redd') Traceback (most recent call last): ... ValueError: unknown color 'redd'
parse_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)
>>> from sage.all import * >>> opacity = Integer(10) >>> parse_color(opacity, base=(RealNumber('.2'),RealNumber('.3'),RealNumber('.4'))) (2.0, 3.0, 4.0)
opacity = 10 parse_color(opacity, base=(.2,.3,.4))