Class: TT::GL_Image

Inherits:
Object
  • Object
show all
Defined in:
TT_Lib2/gl_image.rb

Overview

Note:

Alpha stage. Very likely to be subject to change!

Read .gli file into an array of drawing instructions. The instructions is an array of method name and arguments.

POLYGON [10,0],[14,4],[6,4]

becomes

[ :draw2d, [ Point3d(10,0,0), Point3d(14,4,0), Point3d(6,4,0) ] ]

This translate to arguments that is sent to the View object by using the .send method.

GL Image Format

Data Types

<color>

  • red <int>

  • green <int>

  • blue <int>

  • alpha <int> (Default = 255)

<point>

  • x <float>

  • y <float>

Instructions

COLOR

  • color <color>

WIDTH

  • width <int>

STIPPLE

  • width <string>

POINTS

  • type <string>

    TRIANGLE_OPEN
    TRIANGLE_FILLED
    SQUARE_OPEN
    SQUARE_FILLED
    CIRCLE, O
    DISC, *
    PLUS, +
    CROSS, X
  • size <int>

  • points <point>+

LINES

  • points <point>+

POLYLINE

  • points <point>+

BEZIER

  • points <point>+

LOOP

  • points <point>+

ARC

  • center <point>

  • radius <float>

  • degrees <float>

  • segments <int>

  • start_angle <float> (Default = 0.0)

CIRCLE

  • center <point>

  • radius <float>

  • segments <int>

RECT

  • left <float>

  • top <float>

  • width <float>

  • height <float>

  • corner_radius <float> (Default = 0.0)

POLYGON

  • points <point>+

PIE

  • center <point>

  • radius <float>

  • degrees <float>

  • segments <int>

  • start_angle <float> (Default = 0.0)

DISC

  • center <point>

  • radius <float>

  • segments <int>

GRADIENT

  • left <float>

  • top <float>

  • width <float>

  • height <float>

  • steps <int>

  • horizontal <bool>

  • start_color <color>

  • end_color <color>

Since:

  • 2.7.0

Defined Under Namespace

Classes: ParseError

Instance Method Summary collapse

Constructor Details

#initialize(gl_image_file) ⇒ GL_Image

Returns a new instance of GL_Image

Parameters:

  • gl_image_file (String)

Since:

  • 2.7.0



134
135
136
137
138
139
140
# File 'TT_Lib2/gl_image.rb', line 134

def initialize( gl_image_file )
  unless File.exist?( gl_image_file )
    raise( ArgumentError, "GL Image '#{gl_image_file}' not found." )
  end
  @file = gl_image_file
  @instructions = read_file( gl_image_file )
end

Instance Method Details

#draw(view, x, y) ⇒ Object

Parameters:

  • view (Sketchup::View)
  • x (Integer)
  • y (Integer)

Since:

  • 2.7.0



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'TT_Lib2/gl_image.rb', line 147

def draw( view, x, y )
  # Reset viewport
  view.line_width = 1
  view.line_stipple = ''
  view.drawing_color = [0,0,0]
  # Process drawing instructions. Offset drawing by given coordinates.
  offset = Geom::Vector3d.new( x, y, 0 )
  for instruction in @instructions
    command, arguments = instruction
    positioned_arguments = arguments.map { |argument|
      if argument.is_a?( Geom::Point3d )
        argument.transform( offset )
      else
        argument
      end
    }
    begin
      view.send( command, *positioned_arguments )
    rescue => e
      p instruction
      raise( e )
    end
  end
end

#inspectString

Returns:

  • (String)

Since:

  • 2.7.0



174
175
176
177
# File 'TT_Lib2/gl_image.rb', line 174

def inspect
  hex_id = TT.object_id_hex( self )
  "#<#{self.class.name}:#{hex_id}>"
end