The new HUD system - Guide
-
This is a brief outline of what you can do with the new HUD system, included in SP 3.2.
The commands:
#drawing in 2d, to the screen @simulation.draw2D(type, points, color, size, stipple) #drawing in 3d model space @simulation.draw3D(type, points, color, size, stipple)
The different values you can use for 'type' are:
- "line": Draws a sequence of connected lines at the points specified (n-1 lines are drawn)
- "loop": Draws a sequence of connected lines at the points specified, looping back to the starting point automatically (n lines are drawn)
- "point": Draws points at the points specified (n points are drawn)
- "triangle": Draws filled triangles, one with each triplet of points specified (n/3 triangles are drawn)
- "quad": Draws filled quadrilaterals, one with each four points specified (n/4 quads are drawn)
- "polygon": Draws a single filled, convex polygon, using all points specified
'points' must be an array of points, which can be Geom::Point3d objects for both 3D and 2D operations (Z axis is ignored for 2D), or, in the case of 2D, an array of two values.
E.g:p3d = Geom;;Point3d.new(0,100,50) #3D p2d = Geom;;Point3d.new(0,100,0) #2D, last value (Z) is not used in drawing p2d2 = [0,100] #2D
'color' can be any valid SketchUp color value (see http://code.google.com/apis/sketchup/docs/ourdoc/color.html#introduction), and controls the color used for drawing with that particular draw call. Default value is "Black"
'size' must be an integer value, and controls the width of lines (when drawing lines), and the size of points (in 3D). Default value is 1
'stipple' controls the drawing style of lines. Valid strings are: ".", "-", "_", "-.-" and "", which produces a solid line. Default value is ""
Hope that helps If you want to see this in use (with lines), see: http://sketchup.google.com/3dwarehouse/details?mid=fa89a18ff1258124d595b43ed271a30e&prevstart=0
If you're familiar with the SketchUp draw methods, you'll know there's plenty of functionality that hasn't been exposed yet (stuff like styling points, and a couple more drawing methods), but all the basic elements are there for you to use. One thing of note is that drawing filled shapes in 3D comes out very wierd, but as far as I know, there's nothing I can do about it
-
Ja - it's an annoying long standing bug that polygons in 3d are drawn as black.
Text is drawn in the same colour as the current edge style. No font options.
draw_points blocks the next drawing operation (expects other draw_points) and should be the last in the draw stack -
@thomthom said:
Text is drawn in the same colour as the current edge style. No font options.
draw_points blocks the next drawing operation (expects other draw_points) and should be the last in the draw stackI could never even get text to work
I had no idea about that points problem, thanks for the heads-up. Points don't seem to be that useful anyway, in 3D they aren't even covered by model geometry. -
@wacov said:
Points don't seem to be that useful anyway, in 3D they aren't even covered by model geometry.
I know, very annoying when I wrote vertex tools. I ended up making a wrapper that drew a line segment simulating a point.
draw(GL_POINTS,pts) only draws single pixels... sigh
and no transparency - much to be desired when it comes to the drawing commands.
-
@thomthom said:
I ended up making a wrapper that drew a line segment simulating a point.
Nice idea, mind if I steal it?
Yup, I'd used draw_points for the 3D side of it, but forgot to change the 2D code, so that can only draw single pixels. I was assuming the line_width setting would affect points too, but apparently not. Transparency would be really helpful, especially for this system (no-one wants a mini map that blocks the screen...), and I'd personally like the ability to load images to the screen - or even just be able to manipulate watermarks. I guess that doesn't fit in with SU's primary role though, right?
-
@wacov said:
Nice idea, mind if I steal it?
Go ahead - by all means.
Here is my method from Vertex Tools:
<span class="syntaxdefault"><br /></span><span class="syntaxcomment"># Because the SU API doesn't let one set the Point size and style when drawing 3D points<br /># the vertices are simulated by using GL_LINES instead. There is a slight overhead by <br /># generating the new points like this, but it's the only solution at the moment.<br /></span><span class="syntaxdefault">def draw_points</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">points</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">color</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br /> return if </span><span class="syntaxdefault">points</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(Array) && </span><span class="syntaxdefault">points</span><span class="syntaxkeyword">.empty?<br /> </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">drawing_color </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">color<br /> points </span><span class="syntaxkeyword">= [</span><span class="syntaxdefault">points</span><span class="syntaxkeyword">] if </span><span class="syntaxdefault">points</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Vertex</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">half_size </span><span class="syntaxkeyword">= @</span><span class="syntaxdefault">settings</span><span class="syntaxkeyword">[;</span><span class="syntaxdefault">vertex_size</span><span class="syntaxkeyword">] / </span><span class="syntaxdefault">2.0<br /> </span><span class="syntaxcomment"># line_width appear to be limited to 10px<br /> </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">line_width </span><span class="syntaxkeyword">= @</span><span class="syntaxdefault">settings</span><span class="syntaxkeyword">[;</span><span class="syntaxdefault">vertex_size</span><span class="syntaxkeyword">]<br /> </span><span class="syntaxdefault">hack_points </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">v1 </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">xaxis<br /> v2 </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">v1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse<br /> </span><span class="syntaxkeyword">for </span><span class="syntaxdefault">v in points<br /> p </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">v</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position<br /> offset_length </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">pixels_to_model</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">half_size</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">p</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">hack_points </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">p</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">v1</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">offset_length</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">hack_points </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">p</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">v2</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">offset_length</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">end<br /> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">draw</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GL_LINES</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">hack_points</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /></span>
Another observation in regard to drawing in SketchUp, on (either ATI or nVidia - can't remember atm) if you draw 2d lines with odd number thickness they will appear fuzzy.
Say you draw a line from 50.0,50.0 to 100.0,50.0 in line width 3 it will not be a sharp and crisp line if the user has AA on. However, with even line width, like 2, it will look sharp.
To ensure crisp lines with off line width one has to offset the lines by .5 - so as in the previous example one would have to draw 50.5,50.5 to 100.5,50.5 .
Advertisement