To All Sketch Users: Aymptote

336 views
Skip to first unread message

Gene

unread,
Jun 8, 2010, 4:45:13 PM6/8/10
to Sketch Users
All Sketch Users,

I have been looking at Asymptote: http://asymptote.sourceforge.net/

It seems to have many of the capabilities in my list of desired
features for Sketch 2 gathered from user feedback.

Note also the capability to embed Asymptote code in Latex files, a
nice one.

I'm interested in your comments. What could Sketch 2 do to meet your
requirements that is not already available in Asymptote?

Frankly, if I don't get some good answers, I can't see the benefit in
continuing with Sketch 2 design and construction.

Gene Ressler

Alex

unread,
Jun 9, 2010, 3:14:54 AM6/9/10
to Sketch Users
Yes, Asymptote is very powerful, but a bit more difficult to use imo,
and it only works with PSTricks, not TikZ.

I was thinking that it would be nice to integrate the Sketch
capabilities in TikZ.
TikZ works very well with pdflatex, without the need to call external
programs.

Also, I would like to have CSG features, like in openscad. I've used
CSG in my drawings;
they were made in openscad, then exported to STL, and then I've
written a script which converts
triangle meshes to Sketch code. If you like, I can attach some
examples.

Before, I used Alibre Design Xpress. It is pretty good for hobby CAD
and generates 3D drafts
(only contours, without shading, and also with annotations and
dimensions,
but of course, without LaTeX typesetting).

In order to get the drawing into LaTeX as vectorial graphic (not as
low-resolution screenshot),
I had to print the draft in PDF, then export the PDF to OpenOffice via
inkscape and then edit / annotate the drawing
in OO Draw. With openscad + sketch + tikz it was easier :)

So, another feature could be importing arbitrary meshes from 3D
software. Kjell has a blender to sketch exporter.
I have a script (not yet public) for exporting scad/stl/ply/3ds/etc.
to sketch.

I can also contribute a GUI with live preview (you write in a text
pane, and the 3D drawings appears as you type,
somewhat like Gummi does for .tex files). It's a plugin for gedit, but
it's not stable yet for a public release.

Alex

Kjell Magne Fauske

unread,
Jun 9, 2010, 3:53:38 PM6/9/10
to sketch...@googlegroups.com

I understand why you can't see an immediate benefit of creating Sketch
2. I have barely tried Asymptote, but it looks like it has most of the
missing features of Sketch. However, my initial impression of
Asymptote is that it is a bit slow and I don't like the style of the
default arrow heads;-) What I like about Sketch is:

- its simplicity
- designed primarily for 3D
- it outputs tikz/pstricks code that is easy to modify and postprocess
- I like the look and feel of the generated graphics

I have to admit that for my latest Sketch drawings I have used my
Blender2Sketch exporter because it is faster to set up a scene this
way. I therefore don't use much of Sketch's advanced language
features. What I miss is curved paths and surfaces, and some sort of
shading.

My comments are probably not very useful. I will experiment some more
with Asymptote and see how it compares to Sketch. Hopefully I can give
some better feedback then. I will probably also modify my Blender
exporter so that it can output Asymptote code as well.

- Kjell Magne Fauske

David Bremner

unread,
Jun 11, 2010, 6:21:21 PM6/11/10
to Kjell Magne Fauske, sketch...@googlegroups.com
On Wed, 9 Jun 2010 21:53:38 +0200, Kjell Magne Fauske <kje...@gmail.com> wrote:
> My comments are probably not very useful. I will experiment some more
> with Asymptote and see how it compares to Sketch. Hopefully I can give
> some better feedback then. I will probably also modify my Blender
> exporter so that it can output Asymptote code as well.
>
> - Kjell Magne Fauske

I'm glad to see you weigh in (and investigate) because one of the things
I wonder about asymptote is how easy it is to nake examples like

http://www.fauskes.net/nb/introduction-to-sketch/

I realize we are talking about sketch2, but this somehow affects the
long term plans for sketch1 as well.

All the best.

David

Gene

unread,
Jun 10, 2010, 9:11:14 PM6/10/10
to Sketch Users
On Jun 9, 3:53 pm, Kjell Magne Fauske <kjel...@gmail.com> wrote:
Actually they are. Sketch was always meant to be a polygon and edges
rendered. The "advanced" features were mostly meant to create
examples for a textbook. I agree that shading would be useful. But I
does TikZ have a simple Gouraud polygon renderer? This is what we
need to get shaded outputs.

Of course to make the shading usable, you need the option to make
individual edges of polygons visible or invisible. Then it would be
good to allow limb (silhouette) curve drawing. Then you need a
surface (vice simple polygon) model. So you might as well throw in
splines to allow compact representations. Pretty soon you have
Asymptote...

Alex

unread,
Jun 16, 2010, 5:08:21 PM6/16/10
to Sketch Users
I did a quick and dirty comparison with Asymptote, by trying to
reproduce the drawing from
http://www.piprime.fr/763/asymptote-using-solids_asy-fig0120/

The sources and output PDFs are here:
http://groups.google.com/group/sketch-users/web/asy-sketch.zip

Sketch version: 0.2 (build 161d) on Ubuntu Karmic.
Asy version: 1.80 (the one packaged in Ubuntu Karmic). I wasn't able
to install
the latest version due to some shared library errors.

Some observations:
- Asy output is... bitmap! Try zooming in the PDF. Did I compile it
wrong?!
- Asy draws nice cylinders. I used some ugly hacks to draw the same in
Sketch.
- Compilation times (on Core 2 Duo 2.4 GHz):
* sketch + pdflatex + pdfcrop: 0.8 seconds (compiling script was
sk2pdf from sketch-lib)
* asy (asy cyl.asy && epstopdf cyl.eps && pdfcrop cyl.pdf cyl.pdf):
5 seconds
(asy cyl.asy -f pdf didn't work... some internal error from
package movie15.
For simple 2D drawings it worked, though. Maybe this is fixed in
the latest release.)
- Sketch cannot define points as intersections of lines.
- Asy didn't seem to hide any elements behind the gray plane. Maybe
this option has to be activated somehow.
- Suggestion for Sketch: make points and vectors compatible
(preferably a single data type).
With this, one could simply write: def E ((A) + (B)) / 2

I did not try to print the PDFs to see if there is a difference in
output quality.

Alex

Gene

unread,
Jun 17, 2010, 5:31:49 PM6/17/10
to Sketch Users
On Jun 16, 5:08 pm, Alex <broscutama...@gmail.com> wrote:
> I did a quick and dirty comparison with Asymptote, by trying to
> reproduce the drawing fromhttp://www.piprime.fr/763/asymptote-using-solids_asy-fig0120/
>
> The sources and output PDFs are here:http://groups.google.com/group/sketch-users/web/asy-sketch.zip

Thanks for doing this.

>
> Sketch version: 0.2 (build 161d) on Ubuntu Karmic.
> Asy version: 1.80 (the one packaged in Ubuntu Karmic). I wasn't able
> to install
> the latest version due to some shared library errors.
>
> Some observations:
> - Asy output is... bitmap! Try zooming in the PDF. Did I compile it
> wrong?!
> - Asy draws nice cylinders. I used some ugly hacks to draw the same in
> Sketch.
> - Compilation times (on Core 2 Duo 2.4 GHz):
>   * sketch + pdflatex + pdfcrop: 0.8 seconds (compiling script was
> sk2pdf from sketch-lib)
>   * asy (asy cyl.asy && epstopdf cyl.eps && pdfcrop cyl.pdf cyl.pdf):
> 5 seconds
>     (asy cyl.asy -f pdf didn't work... some internal error from
> package movie15.
>      For simple 2D drawings it worked, though. Maybe this is fixed in
> the latest release.)
> - Sketch cannot define points as intersections of lines.

Right. Another good Sketch 2 capability. I have some ideas about how
to symbolically reference geometric features even after an object has
been instantiated more than once with e.g. different transformations.
The inspiration is the perspective projection of the house in the
manual. You want to be able to define the house in a convenient
coordinate space, transform it, and _then_ get at the transformed
vertices to draw the lines of projection. A generalization of this
will be very handy in lots of contexts.

> - Asy didn't seem to hide any elements behind the gray plane. Maybe
> this option has to be activated somehow.
> - Suggestion for Sketch: make points and vectors compatible
> (preferably a single data type).
>   With this, one could simply write: def E ((A) + (B)) / 2

I thought about his a lot. There seemed to be more benefit in
enforcing affine algebra "strong typing." This means you must write
instead

def E (A) + ((B) - (A)) / 2

which I admit is a bit painful. So I also thought about a primitive
interpolator because this is such a common operation.

def E lerp(A, B, 1/2)

Maybe I'll add this one in the next maintenance release.

>
> I did not try to print the PDFs to see if there is a difference in
> output quality.
>
> Alex
>

Thanks for this work!

Hey, how valuable would general Constructive Solid Geometry primitives
be in SketchII ? It's amazing to me that I can't seem to find any
open source implementations of CSG other than ray tracing systems that
don't apply here the GTS (GNU Triangulated Surface Library), which
only works on triangular meshes, and which is also not a good fit for
SketchII IMO. I'm talking about the "Intersect with Model" capability
in SketchUp, which reconfigures all polygons so there is an expicit
edge wherever two polygons intersect. Since SketchII will have to
support general polygonal surfaces and solids--including holes--the
topology of these would be updated as well.

Alex

unread,
Jun 18, 2010, 2:58:33 AM6/18/10
to Sketch Users
1) lerp is OK. You may also consider linear interpolation for
transforms (lerp in X, Y, Z and scaling; slerp on rotation component).
I don't know how to interpolate perspective terms, maybe lerp would
work for them, too.)

2) Also, a nice idea would be specifying rotations as Euler angles,
e.g.:
rotateZYZ(yaw,pitch,roll) = rz(yaw) * ry(pitch) * rz(roll)

What about shortcuts (like rx(ang), ry(ang) and rz(ang), or rotx/roty/
rotz(ang)) for elementary rotations?

3) Another suggestion for Sketch 2: use Python-like indentation and
allow less braces:

put:
translate(1,2,3) then rotz(45):
sweep(5, rotx(10)): % this belongs to "translate"
(1,-1,0) % this belongs to "sweep" due to
indentation
{box} % this belongs to "translate"

global:
language tikz

Or, on a single line:

put: translate(1,2,3): {object}

Now, I have to do: put{translate([1,2,3])}{object} and there are a lot
of braces and brackets.



4) For CSG, a nice implementation is OpenSCAD, with a description
language very similar to Sketch.
It seems to use CGAL as the backend.

http://openscad.org/

Here is an example of how I've used openscad + sketch:
http://groups.google.com/group/sketch-users/web/sketch%20csg%20example.zip

The files in the archive are:

- i.scad: OpenSCAD source for an I-shaped part with 5 holes
- i.stl: OpenSCAD output (you can open it in MeshLab)
- i.sk: obtained from i.stl with a script similar to Kjell's
blender2sketch
- tool-transform.sk: a figure using the I-shaped part
- spiral.sk: a figure with many I-shaped parts (it takes a long time
to compile)
- tool-transform.pdf, spiral.pd: output files
- *-traced.pdf: postprocessed versions of the outputs (with potrace).
They load much faster in Acrobat.
- lib/ subfolder: my shapes library, required to compile the sketches.

I will also release the processing scripts as open source after
documenting them.

5) The last suggestion: make a public repository so we can send
patches. An overview of how the code works will also be useful.

Alex

Alex

unread,
Jun 18, 2010, 3:10:50 AM6/18/10
to Sketch Users
It seems that Google Groups has some problems with the zip files, so I
have attached .tar.gz versions:

http://sketch-users.googlegroups.com/web/sketch+csg+example.tar.gz
http://sketch-users.googlegroups.com/web/asy-sketch.tar.gz

Windows users: open them with WinRar.

Alex
> Here is an example of how I've used openscad + sketch:http://groups.google.com/group/sketch-users/web/sketch%20csg%20exampl...

Gene

unread,
Jun 18, 2010, 11:50:18 PM6/18/10
to Sketch Users
Thanks. Lots of good thoughts. I had not looked at CGAL for a long
time. Cool to see boolean ops there. And OpenSCAD is interesting.
Your drawings are very pretty.

To lerp full homogeneous transformations, it make sense to factor the
upper left 3x3 into rotation, scale, and shear, the upper right 3x1
(post-translation), and the bottom 1x4 (perspective dividend).
Interpolate all these separately (the rotations with quaternions) and
then recombine. It would be fun even if not all that useful.
> Here is an example of how I've used openscad + sketch:http://groups.google.com/group/sketch-users/web/sketch%20csg%20exampl...

Olumide

unread,
Jul 13, 2010, 2:26:37 PM7/13/10
to Sketch Users
On Jun 16, 10:08 pm, Alex <broscutama...@gmail.com> wrote:
> I did a quick and dirty comparison with Asymptote, by trying to
> reproduce the drawing fromhttp://www.piprime.fr/763/asymptote-using-solids_asy-fig0120/
>
> The sources and output PDFs are here:http://groups.google.com/group/sketch-users/web/asy-sketch.zip
>
> Sketch version: 0.2 (build 161d) on Ubuntu Karmic.
> Asy version: 1.80 (the one packaged in Ubuntu Karmic). I wasn't able
> to install
> the latest version due to some shared library errors.
>
> Some observations:
> - Asy output is... bitmap! Try zooming in the PDF. Did I compile it
> wrong?!

I've noticed this too! ... I have pointed this out to the Asymptote's
developers but they don't seem to understand -- that just because a
document is a PDF does not mean its content is a vector.

Also, perhaps the biggest problem with Asymptote is that it *cannot*
handle more than several hundred polygons, and crashes when give "too
many" polygons. I've posted on the Asymptote forum about this:
http://sourceforge.net/projects/asymptote/forums/forum/409349/topic/3687914

Sketch on the other hand can take up to 20mins if given a very large
polygon count but does the job beautifully. The following eps file was
generated by me using Sketch.
http://uploading.com/files/bf386981/Head.eps

Gene, please (Please) don't stop the development of the next
generation of Sketch. There is nothing quite like it out there.
Asymptote has Gouraud shading which I wish Sketch had, but the bitmap
render/output and low poly count make it useless for all but really
simple stuff.

BTW, when will Sketch2 be available? ;-) . I was hoping to use it('s
advanced features) to produce high-quality images for my thesis.

Alex

unread,
Jul 15, 2010, 3:11:46 PM7/15/10
to Sketch Users
20 minutes to render a figure? I'd like to see the result, but your
link does not work. Can you upload it again?

On my figures with imported meshes, sketch processes the input in
around 1 second, and then pdflatex can take from 10 seconds to 1
minute. However, this is very time consuming if you do a lot of trial-
and-error adjustments (like label placement, for example).

For speeding up the compilation, you may try MeshLab, which does a
good job in simplifying triangle meshes.

For bitmap rendering, you can always use Print Screen with any 3D
graphics program you like. But, while shaded rederings look good on
screen, on paper it is the opposite.
Printing shaded 3D graphics on a black and white printer often results
in poor contrast. On paper, Sketch output with black contours and some
light shading (like blue!15) looks best, and the figure is easy to
read.


On Jul 13, 9:26 pm, Olumide <50...@web.de> wrote:
> On Jun 16, 10:08 pm, Alex <broscutama...@gmail.com> wrote:
>
> > I did a quick and dirty comparison with Asymptote, by trying to
> > reproduce the drawing fromhttp://www.piprime.fr/763/asymptote-using-solids_asy-fig0120/
>
> > The sources and output PDFs are here:http://groups.google.com/group/sketch-users/web/asy-sketch.zip
>
> > Sketch version: 0.2 (build 161d) on Ubuntu Karmic.
> > Asy version: 1.80 (the one packaged in Ubuntu Karmic). I wasn't able
> > to install
> > the latest version due to some shared library errors.
>
> > Some observations:
> > - Asy output is... bitmap! Try zooming in the PDF. Did I compile it
> > wrong?!
>
> I've noticed this too! ... I have pointed this out to the Asymptote's
> developers but they don't seem to understand -- that just because a
> document is a PDF does not mean its content is a vector.
>
> Also, perhaps the biggest problem with Asymptote is that it *cannot*
> handle more than several hundred polygons, and crashes when give "too
> many" polygons. I've posted on the Asymptote forum about this:http://sourceforge.net/projects/asymptote/forums/forum/409349/topic/3...
>
> Sketch on the other hand can take up to 20mins if given a very large
> polygon count but does the job beautifully. The following eps file was
> generated by me using Sketch.http://uploading.com/files/bf386981/Head.eps

Gene

unread,
Jul 15, 2010, 7:12:40 PM7/15/10
to Sketch Users
Thanks. I agree 20 minute processing must mean quite a large image.
The rabbit mesh I use for testing has ~20,000 triangles and takes a
couple of seconds at most for Sketch. I'd love to see this monster.

Good do know that Sketch is best in at least some niches. So I'll keep
thinking about v2. But I still can't give a schedule. Life is too
full.

My goal for shading would be a reflectance model that yields good
printed (esp. B&W) diagram quality like the beautiful hand-rendered
surfaces in old calculus and physics textbooks. More common models are
meant to depict photo-realism on a monitor, which is different. By
adding a "surface" primitive (collection of polygons), I'd be able to
detect limb curves automatically, so you'd get classic ruled
surfaces. There should be a way to depict lines on surfaces without
the current kludge of "floating" them slightly in front so the hidden
surface algorithm can't get them.

Thanks again, guys.

Alex

unread,
Jul 16, 2010, 11:47:54 AM7/16/10
to Sketch Users
The rabbit mesh renders in exactly one second on my system (and this
includes sketch, pdflatex and pdfcrop).

Can you post some titles of physics / calculus textbooks with such
surfaces, or even some scanned pages? I would like to experiment a bit
by reproducing them.

Limb curves are a must-have not only for ruled surfaces, but for any
kind of smooth surfaces.

Any idea of how to draw limb curves in the current version of Sketch
for ? For cylinders I've used a trick: draw two opposed generatrices
and rotate the cylinder until both of them are visible (i.e. until the
plane described by them becomes parallel to the camera plane).

Here is an example of an imported mesh, without limb lines:
http://groups.google.com/group/sketch-users/web/without-limb-lines.pdf
. In order to emulate those lines, I've added a gray shading, and the
contrast between gray and white "creates" the missing lines.

For those who don't know: Limb curves are also called rims, virtual
edges or viewpoint dependent edges.

A few interesting resources:
Line Drawings from 3D Models (SIGGRAPH course):
http://www.cs.princeton.edu/gfx/proj/sg05lines/
Suggestive contours: http://www.cs.rutgers.edu/~decarlo/contour.html
jot (a program for non photorealisting rendering): http://jot.cs.princeton.edu/

Gene

unread,
Jul 16, 2010, 7:08:16 PM7/16/10
to Sketch Users
I'll have to scan some. Don't have a scanner here. Give me a week or
so.

By "ruled surface" I meant a smooth-shaded surface with the outlines
(limbs) ruled with lines. So we're talking about the same thing.

I can't imagine a way to do limb curves in current sketch (other than
the cool trick you used; those images are impressive) because you need
the two adjacent polygons to decide which edges are on the limb.
You're looking for edges where the z-components of adjacent normals
have opposing signs. There is no polygon connectivity information in
a sketch input file, so we're out of beer.

Alex

unread,
Jul 17, 2010, 6:09:55 AM7/17/10
to Sketch Users
OK, it's true that there is no conectivity info in a sketch input
file, but it can be reconstructed. You just have to match vertices
which have the same coordinates (within a small tolerance).

MeshLab does this when it asks you to "Unify Duplicated
Vertices" (e.g. when opening STL files), and it's fast even for large
meshes. I've also implemented this in my script for converting meshes
into sketch files, with a brute force approach Python. It is slower,
but at least it works :)

Here is my implementation, which uses an array of vertices and another
array of face indices:

def unique(verts, faces):
print "finding unique vertices..."
v = []
for p in verts:
x,y,z = p
x = round(x, 4)
y = round(y, 4)
z = round(z, 4)
v.append((x,y,z))
vs = set(v)
vu = list(vs)

print "updating face indices..."
fu = []
degen = 0
for f in faces:
a,b,c = f
pa, pb, pc = v[a], v[b], v[c]
a,b,c = vu.index(pa), vu.index(pb), vu.index(pc)
if a==b or b==c or a==c:
degen += 1
else:
fu.append((a,b,c))
print "degenerated faces:", degen
return vu, fu

After that, I take every edge and find all the triangles which contain
it, and this is the connectivity information. In most cases there are
two triangles for every edge. In order to apply the sign test for the
adjacent normals, the camera transform is also needed.

Gene

unread,
Jul 17, 2010, 11:39:31 PM7/17/10
to Sketch Users
Yes I know this much. Have already figured this will be needed in V2
to stitch swept objects at the closures so that normal vertices will
be correct, etc. I meant with current Sketch there is no general way.

Gene

Olumide

unread,
Jul 19, 2010, 7:32:01 PM7/19/10
to Sketch Users
On Jul 16, 12:12 am, Gene <gene.ress...@gmail.com> wrote:
> Thanks. I agree 20 minute processing must mean quite a large image.
> The rabbit mesh I use for testing has ~20,000 triangles and takes a
> couple of seconds at most for Sketch.  I'd love to see this monster.

Here:
http://groups.google.com/group/sketch-users/web/Head_A.rar

The file contains the *.sk file and an output *.eps file. If I
remember correctly, the *.sk file can takes several minutes to compile
into PSTricks code. I exported these files from a 3d application
(Maya) over a year ago.

> My goal for shading would be a reflectance model that yields good
> printed (esp. B&W) diagram quality like the beautiful hand-rendered
> surfaces in old calculus and physics textbooks. More common models are
> meant to depict photo-realism on a monitor, which is different.

Can I suggest a simple per-triangle Gouraud triangle shading option,
such that objects are not recursively subdivided in order to generate
specular highlights.

As I am exporting objects from Maya, my geometry is at a satisfactory
level of detail. Maya uses this level of detail to perform Gouraud
shading with a pleasant specular highlights.

Gene

unread,
Jul 19, 2010, 8:26:02 PM7/19/10
to Sketch Users
The current problem is that TikZ does not have a Gouraud shaded output
primitive at all. PSTricks only has a Gouraud triangle primitive, and
the arithmetic it uses does not seem to be very robust. It rotates
the triangle to line up the gradient. I expect there will be edge
mismatches among triangles in degenerate cases. Anyway, even if there
were usable primitives, since Sketch allows general convex polygons,
we would have to add delaunay triangulation to handle 4 and more sided
faces. Not that this couldn't be done. It's just beyond the initial
version's scope. Or I could average intensities per face, but then
we'd have Mach banding problems.

All this is on the list to research and solve for Sketch 2. But any
insights you guys have are appreciated. For example, I have not yet
read about how Postscript handles interpolated shading. If there are
any wizards out there who can design good 2d output primitives for
TikZ and/or PSTricks, I'd be ahead in getting Herbert Voss and the
TikZ maintainers to adopt them.

Gene

Alex

unread,
Jul 20, 2010, 12:04:24 PM7/20/10
to Sketch Users
You are talking about \psGTriangle, right?

TikZ has the functional shading primitive; here is an example:
http://files.lol-aids.de/rgb.txt
However, it takes a lot of time to render the PDF in the viewer, even
for that simple cube. Besides, functional shading is not available on
all backends.

PDF has gouraud shading (/ShadingType 4). A primitive for this has to
be implemented in the PGF system layer, on the same level as
\pgfsys@radialshading, for example (file pgfsys-pdftex.def). This
would be the best solution imo, since the other TikZ shadings
(horizontal, vertical and radial) are rendered very fast and without
artifacts in most PDF viewers.

VRender ( http://artis.imag.fr/Software/VRender/index.html ) also
implements a gouraud shading primitive as PS code (see the teapot
example and take a look at EPSExporter.cpp). I was able to isolate
the PS code and call the gouraud shading triangle primitive with
something like this:

% [x1 x2 x3 y1 y2 y3] [r1 g1 b1] [r2 g2 b2] [r3 g3 b3]
[100 100 500 500 100 200] [0 0 0] [0 0 1] [1 1 1] gdt


If I remember well, you may insert arbitrary PS code in PSTricks (but
I never did that). However, only Adobe Reader displays these shadings
properly. Evince and xpdf have some artifacts, and the rendering is
not very fast.

Another solution (an ugly hack, though) would be to generate bitmap
gradients to be used for shading, and include them with
includegraphics.

Gene

unread,
Jul 20, 2010, 2:22:56 PM7/20/10
to Sketch Users
Yes. Herbert Voss added psGTriangle because I asked him for it for
Sketch 2. He's very responsive.

Yes there is a \pstverb command that provides for direct Postscript
output in PSTricks.

Thanks. I didn't know about the functional shading in TikZ. This is
good to have in the toolbox.

I have generally resisted adding features that require strange and/or
arcane output primitives. One of the Sketch secondary goals is
readable output code.

For Sketch 2, my approach would be to emit a preamble of defs that
supplement what's not provided in the output language and then argue
to have this stuff added to future PSTricks/TikZ versions. Postscript
wizards (I am not one) who can help with Gouraud shading preamble code
are welcome to contribute.

Gene

On Jul 20, 12:04 pm, Alex <broscutama...@gmail.com> wrote:
> You are talking about \psGTriangle, right?
>
> TikZ has the functional shading primitive; here is an example:http://files.lol-aids.de/rgb.txt
> However, it takes a lot of time to render the PDF in the viewer, even
> for that simple cube. Besides, functional shading is not available on
> all backends.
>
> PDF has gouraud shading (/ShadingType 4). A primitive for this has to
> be implemented in the PGF system layer, on the same level as
> \pgfsys@radialshading, for example (file pgfsys-pdftex.def). This
> would be the best solution imo, since the other TikZ shadings
> (horizontal, vertical and radial) are rendered very fast and without
> artifacts in most PDF viewers.
>
> VRender (http://artis.imag.fr/Software/VRender/index.html) also
> > > shading with a pleasant specular highlights.- Hide quoted text -
>
> - Show quoted text -

Gene

unread,
Jul 20, 2010, 2:36:02 PM7/20/10
to Sketch Users
Sorry it took me a while to get rar working. Mac Safari was
downloading as text. Argh...

This is a beautiful image. Not what Sketch was intended for, but I'm
happy it works nonetheless.

I assume you want to use Sketch in order to attach the blue-dotted
indicator lines? Otherwise Maya can create a find bitmap for you...

Will keep thinking about Gouraud options.

Gene

On Jul 19, 7:32 pm, Olumide <50...@web.de> wrote:

Olumide

unread,
Jul 21, 2010, 1:48:26 AM7/21/10
to Sketch Users
On Jul 20, 7:36 pm, Gene <gene.ress...@gmail.com> wrote:
> This is a beautiful image.  Not what Sketch was intended for, but I'm
> happy it works nonetheless.

You're welcome and thanks for producing such a handy piece of
software ;)

> I assume you want to use Sketch in order to attach the blue-dotted
> indicator lines?  Otherwise Maya can create a find bitmap for you...

I don't understand the last part of what you've just wrote. The blue
lines are/identify landmarks, and I'm happy with them. What I'm
interested in is Gouraud shading the head model; for example by
assigning an intensity (color) value to each vertex based on the
relationship between its (vertex) normal and the camera view vector --
such that a vertices that face the camera get a specular highlight.
Maya uses the same technique in its viewport.

A quick word about VRender. (I've tried almost every export program
out there.) VRender produces annoying tesselation artifacts artifacts
(for example, http://artis.imag.fr/Software/VRender/examples/teapot.pdf
). However, according to the FAQ (http://artis.imag.fr/Software/
VRender/userManual.html#FAQ), these artifacts do not show on the
printer. This I've got to see for myself ...

Olumide

unread,
Jul 21, 2010, 10:24:21 AM7/21/10
to Sketch Users
On the subject of Postscript. I've read bits of Bill Casselman's
"Mathematical Illustrations".

Chapter 14 - Drawing surfaces in 3D (http://www.math.ubc.ca/~cass/
graphics/manual/pdf/ch14.pdf ) shows how to use postscript to draw
Gouraud shaded 3d meshes. Unfortunately, the code used in the text is
no longer maintained and the author now favors a newer python library
that is not as feature-rich as the old postscript library.

Olumide

unread,
Jul 21, 2010, 10:25:33 AM7/21/10
to Sketch Users
On Jul 21, 3:24 pm, Olumide <50...@web.de> wrote:
> On the subject of Postscript. I've read bits of Bill Casselman's
> "Mathematical Illustrations".

The entire book can be found at: http://www.math.ubc.ca/~cass/graphics/manual/index.html#main

Alex

unread,
Jul 21, 2010, 3:26:05 PM7/21/10
to Sketch Users
Thank you for the book, it's not bad at all :)

> PSTricks only has a Gouraud triangle primitive, and
> the arithmetic it uses does not seem to be very robust.

I've managed to create a quick and dirty example of gouraud-shaded
triangle in Sketch/PSTtricks, without using any arithmetic and
triangle rotations. Here it is:

http://groups.google.com/group/sketch-users/web/shading.sk

The PS code was copied from here: https://geuz.org/svn/gl2ps/trunk/gl2ps.c
(the license is GPL). It just extracts the coordinates from the stack
and passes them to a Shading object in PS, with ShadingType 4, so all
the math is done by the PDF viewer. I would like to ask Gene to find
its behaviour in degenerate cases.

This primitive can also be extended to triangle meshes, but a PS
wizard may be needed for this, like Gene said :)

PDF has a similar syntax for shadings, and this code should be ported
easily to TikZ... by a TeX / PDF wizard, of course.

A suggestion for Gene, regarding [lay=under] specials. Please make
sure that two consecutive [lay=under] objects will appear in the
output in the exact same order. With the latest version, they don't.

About the tesselation artifacts, here they only show in Evince. In
Adobe Reader they are rendered properly. What's curious is that
pdftoppm (which is also based on Poppler, like Evince) renders the
shadings OK (not as well as Acrobat, but without any artifacts). This
happens on all Gouraud / functional shading methods I've tried,
including this one.

Olumide

unread,
Jul 23, 2010, 12:24:39 AM7/23/10
to Sketch Users
On Jul 21, 8:26 pm, Alex <broscutama...@gmail.com> wrote:
> Thank you for the book, it's not bad at all :)
>
> > PSTricks only has a Gouraud triangle primitive, and
> > the arithmetic it uses does not seem to be very robust.
>
> I've managed to create a quick and dirty example of gouraud-shaded
> triangle in Sketch/PSTtricks, without using any arithmetic and
> triangle rotations. Here it is:
>
> http://groups.google.com/group/sketch-users/web/shading.sk
>

Brilliant! ...

Unfortunately, as the demo is based on 2d objects, I'll have to do
some project the triangles of my 3d mesh to the camera plane and draw
them back to front a la painters algorithm. Barring degenerate
triangles, it just might work ;-)

BTW, I've just completed an A0 conference poster, and I've had to use
laptop and desktop screenshots that don't do justice to the level of
detail :( . 'Such a let down not to be able to properly show results
of years of research and development :( .

Alex

unread,
Jul 23, 2010, 2:09:28 AM7/23/10
to Sketch Users
Sorry for your poster :( Can we see it?

You can just type 3D coordinates in the demo, e.g.:

def A (0,0,1)
def B (1,0.5,2)
def C (0,1,3)
...
global { camera view((2,2,2), (0,0,0), [0,0,1]) * scale(10) }

I've just updated the demo with those values. But you will have to
compute vertex colors by hand. And if you paint more triangles, you
should draw first the shading and then the contours; otherwise, you
may have artifacts at the edges. Please try to use it with more
triangles and post the result, if possible.

I've also noticed that Evince renders the resulting PDF with wrong
colors (it seems to consider the shading as 50% transparent), while
Acrobat and pdftoppm render it very well. Also, my Sketch previewer (a
gedit plugin which uses poppler/cairo) renders it like Evince. Could
it be a Cairo bug?

Olumide

unread,
Jul 23, 2010, 5:43:30 AM7/23/10
to Sketch Users
> Sorry for your poster :( Can we see it?

Sure. I'll upload it to a private address and send it to you a link to
it by email.

> You can just type 3D coordinates in the demo, e.g.:
>
> def A (0,0,1)
> def B (1,0.5,2)
> def C (0,1,3)
> ...
> global { camera view((2,2,2), (0,0,0), [0,0,1]) * scale(10) }
>
> I've just updated the demo with those values. But you will have to
> compute vertex colors by hand.

Cool. That I can do.

Can you confirm that Sketch's BSP (hidden surface removal and polygon
splitting) algorithm will ignore my special objects i.e. will simply
draw them over or under the objects it can handle.

> I've also noticed that Evince renders the resulting PDF with wrong
> colors (it seems to consider the shading as 50% transparent), while
> Acrobat and pdftoppm render it very well. Also, my Sketch previewer (a
> gedit plugin which uses poppler/cairo) renders it like Evince. Could
> it be a Cairo bug?

As I haven't done much with shading, I'm yet to run into render bugs
yet, but as I noted earlier the output of VRender does have artifacts.
I hope to print a sample today in order convince myself that the
artifact is indeed caused by the viewer and will not show up on the
printer.

Alex

unread,
Jul 23, 2010, 6:31:50 AM7/23/10
to Sketch Users
Sketch BSP can be disabled for any object (including special objects)
with [lay=over] and [lay=under] options. See the sketch manual for a
detailed explanation.

However, there's no guarantee that they will appear in the .tex output
in the same order as in the .sk input. Hopefully Gene will fix this :)

What program do you use to view the PDFs? Adobe Reader or something
else?

Olumide

unread,
Jul 23, 2010, 8:37:43 AM7/23/10
to Sketch Users
On Jul 23, 11:31 am, Alex <broscutama...@gmail.com> wrote:
> Sketch BSP can be disabled for any object (including special objects)
> with [lay=over] and [lay=under] options. See the sketch manual for a
> detailed explanation.

Does this mean that Sketch's BSP will handle them if neither option
supplied? It would be really nice if it does.

> However, there's no guarantee that they will appear in the .tex output
> in the same order as in the .sk input. Hopefully Gene will fix this :)
>
> What program do you use to view the PDFs? Adobe Reader or something
> else?

I use Adobe's reader.

Gene

unread,
Jul 23, 2010, 12:38:34 PM7/23/10
to Sketch Users
On Jul 23, 8:37 am, Olumide <50...@web.de> wrote:
> On Jul 23, 11:31 am, Alex <broscutama...@gmail.com> wrote:
>
> > Sketch BSP can be disabled for any object (including special objects)
> > with [lay=over] and [lay=under] options. See the sketch manual for a
> > detailed explanation.
>
> Does this mean that Sketch's BSP will handle them if neither option
> supplied? It would be really nice if it does.

If you say [lay=in], specials will be depth sorted based on the first
point in the argument list, though never split. This sometimes gives a
useful hiding effect. If you're careful about which vertex of the
triangle you give first (e.g. always the nearest to the obeserver),
you might get a reasonable result with convex smooth-shaded solids
having triangle mesh boundaries.

>
> > However, there's no guarantee that they will appear in the .tex output
> > in the same order as in the .sk input. Hopefully Gene will fix this :)
>

I will look at this.

alfC

unread,
Oct 6, 2010, 5:30:59 AM10/6/10
to Gene, sketch...@googlegroups.com
On Jun 8, 1:45 pm, Gene <gene.ress...@gmail.com> wrote:
> All Sketch Users,
>
> I have been looking at Asymptote:http://asymptote.sourceforge.net/
>
> It seems to have many of the capabilities in my list of desired
> features for Sketch 2 gathered from user feedback.
>
> Note also the capability to embed Asymptote code in Latex files, a
> nice one.

I like Sketch because it is simple and small, although I have been
using Asymptote lately because of the capability of including 3D PRC
objects in PDF.

Having said that, I find Asymptote quite slow and big and it does not
a good job at rendering 3D scenes to vector 2D format. Raster 2D
projection has it problems too, depends on display rendering, openGL.

I am not sure how difficult could be to implement 3D PRC output in
Sketch but it would be the coolest thing. If Sketch can generate a 3D
PRC *and* the 2D vector preview I will be very happy.

Second, (I requested this to the Asymptote developer also), if you can
provide a "Sketch C++ library" to generate drawings from a C++
program, that will be game changer. You may say "but I have to give up
this nice Sketch programming language"; ie. Sketch defines its own
language with some language specification (in YACCs or Bison, I don't
remember ).

Did you hear about Boost.Proto and Boost.Spirit? you can define a
minilanguage in C++ that approaches your original language. That is
you can write C++ code that because of operator overloading, etc can
resemble sketch code and generate directly the output for the C++
program compiled with the "Sketch library".

for example, the following is valid C++ syntax that can be tricked (by
Boost.Proto) into performing the semantic actions of the sketch
program but without the sketch executable:

int main(){
sketch::scene s("tikzoutput");
using namespace sketch;
s << polygon[ map("fillcolor", lightgray)("linewidth", 3*pt)](0,0,1)
(1,0,0)(0,1,0)
<< line[map("linestyle",dotted)](-1,-1,-1)(2,2,2);
s.save("hello.tikz"); // or s.save("hello.ps");
}

Note that the previous is valid C++ with semantic actions that will be
defined with the help of Boost.Proto.
The code can be a simple translation of your YACC grammars. More info
at http://cpp-next.com/

Just ideas,
Alfredo

Reply all
Reply to author
Forward
0 new messages