Satimage Previous | Next
The GLobject
Home Documentation SmileLab Scripting Graphic objects Graphic view View3D The GLobject  
Introduction
A GLobject is an elementary 3D object which may be either a line, a triangle, a quad or a polygon.
Providing the GLobject with data
kind, contained data
You define a GLobject by specifying its kind and by supplying (as its contained data property) the list of points that it requires. The list of points is formatted as the list of the coordinates {x1, y1, z1,... ,xn, yn, zn} of the points. You can provide any number of points, so the list should have 3n items.
Graphic options for the GLobject
drawmode
You can have a GLobject drawn filled or wired or both filled and wired by setting its drawmode property to 1, 2 or 3.
pen width
The pen width property is only effective for GLobjects drawn wired (it is always the case for GLobjects of the curve3D kind). The pen width depends also of the view3D's resolution.
ambiant color, diffused color, specular color, emission color, ambiant pen color, diffused pen color, specular pen color, emission pen color and shininess
You can change the material color properties of the GLobjects by settings its following properties: ambiant color, diffused color, specular color, emission color, ambiant pen color, diffused pen color, specular pen color, emission pen color and shininess.
fill color and pen color are shortcuts to define both ambiant and diffused colors for filled and wired display.
colordata, color palette and limits
Instead of using unique material colors for displaying a GLobject, you can provide a list of n real numbers (where n is the number of points in contained data) to the colordata property. Those values will define a color for each point, using the color palette and limits property to convert the values as colors (use color palettes like bitmaps do).
set w to make new graphic window with properties {name:"Colored polygon", never save:true}
set v to make new view3D at w with properties {name:"Polygon", resolution:144, limits:{-2, -1, -2, 2, 0, 3}}
set g to make new GLobject at v with properties {kind:polygon, contained data:{-1.5, 0, 1, -1.5, 2, 1, -1.5, 2, 3, -1.5, 0, 3, -1.5, -1, 2, -1.5, 0, 1}, colordata:createarray 6}
Use of the triangulate command to display a GLobject of kind triangle set
The triangulate command makes a list of x,y coordinates into a list of triangles. Use this command to display a 3D surface where the color (or, z) was defined in some x,y locations. Here is an example:
--create data: x,y are random
set n to 200
set x to randomarray n range {0, 1}
set y to randomarray n range {0, 1}
set z to evalformula "0.5-0.25*cos(2*pi*x)*(x*x+y*y)" with {x:x, y:y}
set c to evalformula "(x*y)" with {x:x, y:y}

--compute triangulation
set {xx, yy, zz, cc} to triangulate {x, y} syncing {z, c}
--create a list of 3D coordinates: the values are x1, y1, z1, x2, y2, z2, etc.
set pts to array of real of ({xx, yy, zz} as matrix)

--display the triangle set
set w to make new graphic window
set never save of w to true
set v to make new view3D at w
set c to make new GLObject at v with properties {kind:triangle set, contained data:pts, colordata:cc, pen color:{0, 0, 0, 1}}


Import script
Copyright ©2008 Paris, Satimage