ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::View

Inherits:
Object
  • Object
show all

Overview

Current viewport. Obtain it from ModraUp::Model#active_view.

draw / draw2d draw to the viewport during ModraUp::Tool#draw and when enabled ModraUp::Overlay#draw is active. #load_texture loads an image into the host, returning 0 on failure. #animation= advances the animation by one frame (next or nextFrame).

Examples:

view = ModraUp.active_model.active_view
view.invalidate
origin, dir = view.pickray(10, 10)

Constants # collapse

ModraUp::View::CORNER_TOP_LEFT

ModraUp::View::CORNER_TOP_LEFT = 0

ModraUp::View#corner top-left.

Returns:

  • (Integer)

Examples:

ModraUp::View::CORNER_TOP_LEFT  #=> 0
ModraUp::View::CORNER_TOP_RIGHT

ModraUp::View::CORNER_TOP_RIGHT = 1

ModraUp::View#corner top right.

Returns:

  • (Integer)

Examples:

ModraUp::View::CORNER_TOP_RIGHT  #=> 1
ModraUp::View::CORNER_BOTTOM_LEFT

ModraUp::View::CORNER_BOTTOM_LEFT = 2

ModraUp::View#corner bottom left.

Returns:

  • (Integer)

Examples:

ModraUp::View::CORNER_BOTTOM_LEFT  #=> 2
ModraUp::View::CORNER_BOTTOM_RIGHT

ModraUp::View::CORNER_BOTTOM_RIGHT = 3

ModraUp::View#corner bottom right.

Returns:

  • (Integer)

Examples:

ModraUp::View::CORNER_BOTTOM_RIGHT  #=> 3

Instance Method Summary # collapse

Instance Method Details

view.pick_helper ⇒ ModraUp::PickHelperview.pick_helper(x, y) ⇒ ModraUp::PickHelperview.pick_helper(x, y, aperture) ⇒ ModraUp::PickHelper

The pick helper bound to this viewport. Calls ModraUp::PickHelper#do_pick with coordinates immediately.

Parameters:

  • x (Numeric)
  • y (Numeric)

Returns:

  • (ModraUp::PickHelper)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)

view.camera ⇒ ModraUp::Camera

Current viewport camera. Calling ModraUp::Camera#set on the returned object will change the viewport.

Returns:

  • (ModraUp::Camera)

Examples:

ModraUp.active_model.active_view.camera.eye

view.camera = camera ⇒ ModraUp::Cameraview.camera = [camera, seconds] ⇒ Array

Change the viewport camera to camera. The array's second item is the transition seconds, which is currently ignored and will switch immediately.

Parameters:

  • camera (ModraUp::Camera, Array)

Returns:

  • (ModraUp::Camera, Array)

Examples:

view = ModraUp.active_model.active_view
view.camera = ModraUp::Camera.new([10, 0, 5], [0, 0, 0], [0, 0, 1])

view.model ⇒ ModraUp::Model

The model to which this viewport belongs.

Returns:

  • (ModraUp::Model)

Examples:

ModraUp.active_model.active_view.model == ModraUp.active_model

view.pickray(x, y) ⇒ Arrayview.pickray(screen_point) ⇒ Array

Screen point corresponding world ray: [Geom::Point3d start point, Geom::Vector3d direction].

Parameters:

  • x (Numeric, Geom::Point3d, Array<Numeric>) Screen X, or screen point
  • y (Numeric)

Returns:

  • (Array(Geom::Point3d, Geom::Vector3d))

Examples:

origin, dir = ModraUp.active_model.active_view.pickray(100, 80)

view.screen_coords(point) ⇒ Geom::Point3d

Projects a world point onto the screen. Returns the point's x/y coordinates as logical pixels; returns nil on projection failure.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Geom::Point3d, nil)

Examples:

ModraUp.active_model.active_view.screen_coords([0, 0, 0])

view.tooltip ⇒ String

Viewport tooltip text displayed next to the cursor.

Returns:

  • (String)

Examples:

ModraUp.active_model.active_view.tooltip

view.tooltip = string ⇒ String

Set the viewport tooltip next to the cursor. An empty string will hide it.

Parameters:

  • string (String)

Returns:

  • (String)

Examples:

ModraUp.active_model.active_view.tooltip = "Click to activate."

view.invalidate ⇒ view

Request the viewport to be redrawn (Tools + Draw+ / Animation).

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.invalidate

view.vpwidth ⇒ Integer

Viewport width (pixels).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.active_view.vpwidth

view.vpheight ⇒ Integer

Viewport height (pixels).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.active_view.vpheight

view.zoom(zoom) ⇒ viewview.zoom(entity) ⇒ viewview.zoom(entities) ⇒ view

Zooms by a factor or frames entities or a selection. A factor greater than 1 zooms in.

Parameters:

  • zoom (Numeric, ModraUp::Entity, ModraUp::Selection, Array<ModraUp::Entity>)

Returns:

  • (ModraUp::View)

Examples:

view = ModraUp.active_model.active_view
view.zoom 2
view.zoom ModraUp.active_model.selection

view.zoom_extents ⇒ view

Zoom to extents of the entire model, equivalent to filling the viewport.

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.zoom_extents

view.add_observer(observer) ⇒ Boolean

Register a ModraUp::ViewObserver. Adding the same object a second time returns false. After the camera is closed or the viewport size changes, the onViewChanged method is called; when the DPI changes, the onScaleFactorChange method is called.

Parameters:

  • observer (ModraUp::ViewObserver)

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.add_observer(ModraUp::ViewObserver.new)

view.remove_observer(observer) ⇒ Boolean

Removes the observer. Returns false if it was absent.

Parameters:

  • observer (ModraUp::ViewObserver)

Returns:

  • (Boolean)

Examples:

obs = ModraUp::ViewObserver.new
view = ModraUp.active_model.active_view
view.add_observer(obs)
view.remove_observer(obs)

view.refresh ⇒ view

Request an immediate redraw. Currently, this is equivalent to #invalidate and does not guarantee synchronous completion.

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.refresh

view.center ⇒ Geom::Point3d

The screen coordinates (logical pixels) of the viewport center.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.active_view.center

view.corner(index) ⇒ Geom::Point3d

The screen coordinates of the Viewport corner. index can be CORNER_TOP_LEFT, etc.

Parameters:

  • index (Integer)

Returns:

  • (Geom::Point3d)

Raises:

  • [ArgumentError] not in 0..3

Examples:

view = ModraUp.active_model.active_view
view.corner(ModraUp::View::CORNER_TOP_LEFT)

view.device_width ⇒ Integer

Viewport physical pixel width (logical width × UI.scale_factor(view)).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.active_view.device_width

view.device_height ⇒ Integer

Viewport physical pixel height (logical height × UI.scale_factor(view)).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.active_view.device_height

view.field_of_view ⇒ Numeric

Vertical field of view in degrees, same as ModraUp::Camera#fov.

Returns:

  • (Numeric)

Examples:

ModraUp.active_model.active_view.field_of_view

view.field_of_view = degrees ⇒ Numeric

Sets the vertical field of view.

Parameters:

  • degrees (Numeric)

Returns:

  • (Numeric)

Examples:

ModraUp.active_model.active_view.field_of_view = 35

view.graphics_engine ⇒ Symbol

Graphics backend. ModraUp fixed :graphics_engine_classic (OpenGL 3.3 + QPainter overlay).

Returns:

  • (Symbol)
Note: ModraUp extension. SketchUp may return :graphics_engine_2024.

Examples:

ModraUp.active_model.active_view.graphics_engine

view.pixels_to_model(pixels, point) ⇒ Numeric

Convert logical pixel dimensions to the model length at the point location.

Parameters:

  • pixels (Numeric)
  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Numeric)

Examples:

view = ModraUp.active_model.active_view
view.pixels_to_model(10, ORIGIN)

view.guess_target ⇒ Geom::Point3dview.guess_target(screen_point) ⇒ Geom::Point3d

Guess the user's target point in the model. Use the camera's target if no screen point is provided; otherwise, cast a ray from the screen point, or fall back to z=0 or the camera's target.

Parameters:

  • screen_point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.active_view.guess_target

view.dynamic = value ⇒ Object

Deprecated, ignore.

Parameters:

  • value (Object)

Returns:

  • (Object)

Examples:

ModraUp.active_model.active_view.dynamic = true

view.average_refresh_time ⇒ Float

Average refresh duration in milliseconds. Returns 0.0 before any measurements are available.

Returns:

  • (Float)

Examples:

ModraUp.active_model.active_view.average_refresh_time

view.last_refresh_time ⇒ Floatview.last_refresh_time(full) ⇒ Float

Duration of the last complete refresh in milliseconds. In SketchUp, passing true for full includes the entire frame. ModraUp currently returns 0.0.

Parameters:

  • full (Boolean)

Returns:

  • (Float)

Examples:

ModraUp.active_model.active_view.last_refresh_time

view.animation = animation ⇒ Object

Set the animation object and start the clock. The host ticks with next(view); if there is no next, it ticks with nextFrame(view).

In the callback, call #show_frame or return true to continue playing. nil stops.

Parameters:

  • animation (Object, nil)

Returns:

  • (Object, nil)

Examples:

ModraUp.active_model.active_view.animation = nil

view.show_frame ⇒ viewview.show_frame(delay) ⇒ view

Request the next frame in the animation callback. If delay is given in seconds (default is none, meaning as soon as possible), it will wait for that duration before the next tick.

Parameters:

  • delay (Numeric)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.show_frame

view.drawing_color = color ⇒ Object

Sets the color used by #draw. Accepts a ModraUp::Color, [r, g, b] / [r, g, b, a] array, or an English color name. The fourth item in the array corresponds to ModraUp::Color#alpha= and can be 0–255 or 0.0–1.0.

Parameters:

  • color (ModraUp::Color, Array<Numeric>, String)

Returns:

  • (Object)

Examples:

ModraUp.active_model.active_view.drawing_color = "DarkGray"
ModraUp.active_model.active_view.drawing_color = [255, 0, 0]

view.line_width = width ⇒ Numeric

Sets the line width for #draw in logical pixels.

Parameters:

  • width (Numeric)

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] width is negative

Examples:

ModraUp.active_model.active_view.line_width = 2

view.line_stipple ⇒ String

Current #draw line stipple. An empty string represents solid lines.

Returns:

  • (String)

Examples:

ModraUp.active_model.active_view.line_stipple = "-"
ModraUp.active_model.active_view.line_stipple  #=> "-"

view.line_stipple = pattern ⇒ String

Sets the #draw line pattern. Valid values are the same as in SketchUp: "" for dot-dash, ""- for short dash, "+"_ for long dash, "-.-" for dot-dot-dash, and an empty string for solid.

Parameters:

  • pattern (String)

Returns:

  • (String)

Examples:

Short dash

view = ModraUp.active_model.active_view
view.line_stipple = "-"

Dash-dot pattern

view.line_stipple = "-.-"

view.set_color_from_line(point1, point2) ⇒ view

Set the draw color to the red/green/blue axis color based on the direction defined by two points.

Parameters:

  • point1 (Geom::Point3d, Array<Numeric>)
  • point2 (Geom::Point3d, Array<Numeric>)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.set_color_from_line(ORIGIN, [1, 0, 0])

view.draw(opengl_const, *points) ⇒ viewview.draw(opengl_const, *points, texture: id, uvs: uvs) ⇒ view

Draw 3D geometry. Valid in ModraUp::Tool#draw or an active ModraUp::Overlay#draw. Share depth buffer with the model: hidden parts will not be drawn. Use #draw2d for screen pixels. :texture is a handle from #load_texture, and :uvs corresponds one-to-one with vertices (x=u, y=v). :normals are accepted but currently drawn as flat surfaces without lighting. Points can be Geom::Point3d, Geom::Vector3d, Geom::Point2d, [x, y, z], or objects with x/y; nil skips the point.

Parameters:

  • opengl_const (Integer) GL_LINES and
  • points (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (ModraUp::View)

Examples:

view = ModraUp.active_model.active_view
view.draw(GL_LINES, ORIGIN, [1, 0, 0])

view.draw2d(opengl_const, *points) ⇒ viewview.draw2d(opengl_const, *points, texture: id, uvs: uvs) ⇒ view

Draw primitives on screen coordinates. Valid in ModraUp::Tool#draw or an enabled ModraUp::Overlay#draw. Draws on top of the model and 3D #draw without depth testing. Point types are the same as in #draw; nil skips the draw.

Parameters:

  • opengl_const (Integer) GL_LINE_STRIP and
  • points (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (ModraUp::View)

Examples:

view = ModraUp.active_model.active_view
view.draw2d(GL_LINE_STRIP, [0, 0, 0], [40, 40, 0])

view.draw_line(*points) ⇒ view

Draw a polyline. Point types are the same as for #draw; nil skips the point.

Parameters:

  • points (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.draw_line(ORIGIN, [1, 0, 0])

view.draw_polyline(*points) ⇒ view

Same as #draw_line.

Parameters:

  • points (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.draw_polyline(ORIGIN, [1, 0, 0], [1, 1, 0])

view.draw_lines(*points) ⇒ view

Draw line segments by points. The point types are the same as for #draw; nil skips the point.

Parameters:

  • points (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.draw_lines(ORIGIN, [1, 0, 0], [0, 1, 0], [1, 1, 0])

view.draw_points(points, size = 6, style = 3, color = "black") ⇒ view

Draw screen points. style: 1 empty square, 2 solid square, 3 cross, 4 plus, 5 star, 6 empty triangle, 7 solid triangle.

Parameters:

  • points (Geom::Point3d, Array<Geom::Point3d>)
  • size (Integer)
  • style (Integer)
  • color (ModraUp::Color, Array<Integer>, String)

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.draw_points(ORIGIN, 10, 1, "red")

view.draw_text(point, text) ⇒ viewview.draw_text(point, text, options) ⇒ view

Draw text on the screen coordinates. The options can contain :font, :size, :pixel_size, :point_size, :bold, :align, :vertical_align, and :color.

The :color can be a ModraUp::Color, [r, g, b], a color name, or a CSS hexadecimal value (e.g., "#1A1A1A").

Parameters:

  • point (Geom::Point3d, Array<Numeric>)
  • text (String)
  • options (Hash)

Returns:

  • (ModraUp::View)

Examples:

view = ModraUp.active_model.active_view
view.draw_text([10, 10, 0], "Hi", size: 12, color: "#1A1A1A")

view.text_bounds(point, text) ⇒ Geom::Bounds2dview.text_bounds(point, text, options) ⇒ Geom::Bounds2d

Calculate the text box in screen coordinates for #draw_text. The point is in viewport pixels (Z ignored). The options can include :font, :size, :pixel_size, :point_size, :bold, :align, :vertical_align.

Without a Qt host, use fixed-width font estimation to ensure non-empty strings have positive width and height.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)
  • text (String)
  • options (Hash)

Returns:

  • (Geom::Bounds2d)

Examples:

view = ModraUp.active_model.active_view
b = view.text_bounds([0, 0, 0], "Hi")
b.is_a?(Geom::Bounds2d)  #=> true
b.width > 0 && b.height > 0  #=> true

view.load_texture(filename, *rest) ⇒ Integerview.load_texture(image_rep, *rest) ⇒ Integer

Load an image as a texture into the viewport, returning a handle. Returns 0 if the file does not exist, cannot be decoded, is an empty ModraUp::ImageRep, or has no host. #draw / #draw2d can apply the :texture and :uvs to polygons.

Parameters:

  • filename (String, ModraUp::ImageRep)
  • rest (Numeric) UV scaling and offset: u_scale, v_scale, u_offset, v_offset

Returns:

  • (Integer)

Examples:

ModraUp.active_model.active_view.load_texture("missing.png")  #=> 0

view.release_texture(texture_id) ⇒ Boolean

Release the #load_texture handle. Return false if the unknown ID or host is invalid.

Parameters:

  • texture_id (Integer)

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.release_texture(1)

view.write_image(filename, width = vpwidth, height = vpheight, antialias = false, compression = 1.0) ⇒ Booleanview.write_image(options) ⇒ Boolean

Write the current 3D frame buffer as an image. Returns false if host fails or capture fails.

options key :filename / :width / :height / :antialias / :compression; :transparent is ignored.

Parameters:

  • filename (String, Hash)

Returns:

  • (Boolean)
Note: ModraUp extension. Does not include a QPainter overlay; anti-aliasing only takes effect during zoom.

Examples:

view = ModraUp.active_model.active_view
view.write_image({})  #=> false

view.inputpoint ⇒ ModraUp::InputPointview.inputpoint(x, y) ⇒ ModraUp::InputPointview.inputpoint(x, y, inputpoint) ⇒ ModraUp::InputPoint

Creates a ModraUp::InputPoint. Supplying coordinates immediately calls ModraUp::InputPoint#pick.

Parameters:

  • x (Numeric)
  • y (Numeric)
  • inputpoint (ModraUp::InputPoint) Previous point, used for axial/parallel inference.

Returns:

  • (ModraUp::InputPoint)

Examples:

view = ModraUp.active_model.active_view
ip = view.inputpoint(10, 10)

view.inference_locked? ⇒ Boolean

Returns whether inference is locked by #lock_inference.

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.inference_locked?

view.lock_inference ⇒ viewview.lock_inference(inputpoint) ⇒ viewview.lock_inference(inputpoint, inputpoint2) ⇒ view

Unlocks with no parameters. Releases adsorption types on the RGB axes with a single click; locks on the axes if two points are close. Diagonal edges and faces are held until they are fully defined.

Parameters:

  • inputpoint (ModraUp::InputPoint)
  • inputpoint2 (ModraUp::InputPoint)

Returns:

  • (ModraUp::View)

Examples:

view = ModraUp.active_model.active_view
view.lock_inference