Ticket #14428: tachyon.patch

File tachyon.patch, 4.5 KB (added by anton_t, 9 years ago)

patch to tachyon.py to enable general 3d objects to be inserted into tachyon scenes.

  • sage/plot/plot3d/base.pyx

    # HG changeset patch
    # User Anton Todorov <anton.t.aus@gmail.com>
    # Date 1365476409 -36000
    # Node ID a6a06c0d64fe7d7d9f6d31d8a010ed96acb0b0f7
    # Parent  4381a8e9f0c8d5d481433f3e670c8de9ddeadc4f
    Edited in a general object type for tachyon to get arbitrary graphics from sage.
    * * *
    A patch that allows general sage 3d objects to be placed inside tachyon rendered scenes.
    
    diff --git a/sage/plot/plot3d/base.pyx b/sage/plot/plot3d/base.pyx
    a b  
    522522    %s
    523523
    524524end_scene""" % (render_params.antialiasing,
    525                "\n".join(sorted([t.tachyon_str() for t in self.texture_set()])),
    526                "\n".join(flatten_list(self.tachyon_repr(render_params))))
     525                "\n".join(sorted([t.tachyon_str() for t in self.texture_set()])),
     526                "\n".join(flatten_list(self.tachyon_repr(render_params))))
    527527
    528528    def obj(self):
    529529        """
  • sage/plot/plot3d/tachyon.py

    diff --git a/sage/plot/plot3d/tachyon.py b/sage/plot/plot3d/tachyon.py
    a b  
    5656
    5757from sage.misc.misc import SAGE_TMP
    5858from sage.misc.temporary_file import tmp_filename, graphics_filename
    59 
     59from sage.plot.plot3d.base import flatten_list
    6060#from sage.ext import fast_tachyon_routines
    6161
    6262import os
     
    219219            sage: t = Tachyon()
    220220            sage: t._xres
    221221            350
     222            sage: t._look_at
     223            (0, 0, 0)
    222224        """
    223225        self._xres = xres
    224226        self._yres = yres
     
    227229        self._antialiasing = antialiasing
    228230        self._raydepth = raydepth
    229231        self._camera_center = camera_center
     232        self._look_at = look_at
    230233        self._updir = updir
    231234        self._projection = projection
    232235        self._objects = []
     
    311314            sage: q.sphere((0,0,0),1,'s')
    312315            sage: q.show(verbose = False)
    313316        """
     317        self._viewdir = [self._look_at[i] - self._camera_center[i] for i in range(3)]
    314318        import sage.plot.plot
    315319        if sage.plot.plot.DOCTEST_MODE:
    316320            filename = graphics_filename()
     
    524528            names.append(n)
    525529
    526530        return names
     531    def general_object(self, sage_3d_object):
     532        r"""
     533        Creates the information needed for a general object to be rendered in the scene.
     534        EXAMPLES::
     535            sage: t = Tachyon()
     536            sage: var('x y')
     537            (x, y)
     538            sage: a = plot3d(sin(x+y), (x, -4, 4), (y, -4, 4))
     539            sage: t.general_object(a)
     540            sage: t._objects[0].str()[-100:]
     541            '4 0.989358\ntexture21\nTRI V0 3.79487 3.79487 0.965292 V1 4 4 0.989358 V2 4 3.79487 0.998254\ntexture21'
     542        """
     543        self._objects.append(GeneralObject(sage_3d_object))
    527544
    528545    def sphere(self, center, radius, texture):
    529546        r"""
     
    907924             tostr(self._color),
    908925             self._texfunc)
    909926
     927
     928class GeneralObject:
     929    r"""
     930    A class for complex pre-plotted sage objects
     931    """
     932    def __init__(self, sage_3d_object):
     933        r"""
     934        Stores the texture and triangle mesh of general plot objects of sage.
     935        EXAMPLES::
     936
     937            sage: var('x y')
     938            (x, y)
     939            sage: a = plot3d(sin(x+y), (x, -4, 4), (y, -4, 4))
     940            sage: from sage.plot.plot3d.tachyon import GeneralObject
     941            sage: ob = GeneralObject(a)
     942            sage: ob._texture[0]
     943            Texture(texture22, 6666ff)
     944            sage: ob._data[0]
     945            'TRI V0 -4 -4 -0.989358 V1 -4 -3.79487 -0.998254 V2 -3.79487 -3.79487 -0.965292'
     946        """
     947        self._texture = list(sage_3d_object.texture_set())
     948        self._data = sage_3d_object.tachyon_repr(sage_3d_object.default_render_params())
     949
     950    def str(self):
     951        r"""
     952        Returns the scene string for a general 3d sage object along, both its texture and shape.
     953        EXAMPLES::
     954
     955            sage: var('x y')
     956            (x, y)
     957            sage: a = plot3d(sin(x+y), (x, -4, 4), (y, -4, 4))
     958            sage: from sage.plot.plot3d.tachyon import GeneralObject
     959            sage: ob = GeneralObject(a)
     960            sage: ob.str()[:100]
     961            '\n               Texdef texture23\n  Ambient 0.333333333333 Diffuse 0.666666666667 Specular 0.0 Opacit'
     962        """
     963        return r"""
     964               %s
     965               %s"""%( "\n".join(t.tachyon_str() for t in flatten_list(self._texture)),
     966                       "\n".join(flatten_list(self._data)))
     967
    910968class Sphere:
    911969    r"""
    912970    A class for creating spheres in tachyon.