Class: ModraUp::View
- Inherits:
-
Object
- Object
- ModraUp::View
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).
Constants # collapse
- ModraUp::View::CORNER_TOP_LEFT
ModraUp::View::CORNER_TOP_LEFT = 0
ModraUp::View#corner top-left.
- ModraUp::View::CORNER_TOP_RIGHT
ModraUp::View::CORNER_TOP_RIGHT = 1
ModraUp::View#corner top right.
- ModraUp::View::CORNER_BOTTOM_LEFT
ModraUp::View::CORNER_BOTTOM_LEFT = 2
ModraUp::View#corner bottom left.
- ModraUp::View::CORNER_BOTTOM_RIGHT
ModraUp::View::CORNER_BOTTOM_RIGHT = 3
ModraUp::View#corner bottom right.
Instance Method Summary # collapse
-
#pick_helper ⇒ ModraUp::PickHelper
The pick helper bound to this viewport. Calls ModraUp::PickHelper#do_pick with coordinates immediately.
-
#camera ⇒ ModraUp::Camera
Current viewport camera. Calling ModraUp::Camera#set on the returned object will change the viewport.
-
#camera= ⇒ ModraUp::Camera, Array
Change the viewport camera to camera. The array's second item is the transition seconds, which is currently ignored and will switch immediately.
-
#model ⇒ ModraUp::Model
The model to which this viewport belongs.
-
#pickray(x, y) ⇒ Array(Geom::Point3d, Geom::Vector3d)
Screen point corresponding world ray: [Geom::Point3d start point, Geom::Vector3d direction].
-
#screen_coords(point) ⇒ Geom::Point3d, nil
Projects a world point onto the screen. Returns the point's x/y coordinates as logical pixels; returns nil on projection failure.
-
#tooltip ⇒ String
Viewport tooltip text displayed next to the cursor.
-
#tooltip= ⇒ String
Set the viewport tooltip next to the cursor. An empty string will hide it.
-
#invalidate ⇒ ModraUp::View
Request the viewport to be redrawn (Tools + Draw+ / Animation).
-
#vpwidth ⇒ Integer
Viewport width (pixels).
-
#vpheight ⇒ Integer
Viewport height (pixels).
-
#zoom(zoom) ⇒ ModraUp::View
Zooms by a factor or frames entities or a selection. A factor greater than 1 zooms in.
-
#zoom_extents ⇒ ModraUp::View
Zoom to extents of the entire model, equivalent to filling the viewport.
-
#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.
-
#remove_observer(observer) ⇒ Boolean
Removes the observer. Returns false if it was absent.
-
#refresh ⇒ ModraUp::View
Request an immediate redraw. Currently, this is equivalent to #invalidate and does not guarantee synchronous completion.
-
#center ⇒ Geom::Point3d
The screen coordinates (logical pixels) of the viewport center.
-
#corner(index) ⇒ Geom::Point3d
The screen coordinates of the Viewport corner. index can be CORNER_TOP_LEFT, etc.
-
#device_width ⇒ Integer
Viewport physical pixel width (logical width × UI.scale_factor(view)).
-
#device_height ⇒ Integer
Viewport physical pixel height (logical height × UI.scale_factor(view)).
-
#field_of_view ⇒ Numeric
Vertical field of view in degrees, same as ModraUp::Camera#fov.
-
#field_of_view= ⇒ Numeric
Sets the vertical field of view.
-
#graphics_engine ⇒ Symbol
Graphics backend. ModraUp fixed :graphics_engine_classic (OpenGL 3.3 + QPainter overlay).
-
#pixels_to_model(pixels, point) ⇒ Numeric
Convert logical pixel dimensions to the model length at the point location.
-
#guess_target ⇒ 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.
-
#dynamic= ⇒ Object
Deprecated, ignore.
-
#average_refresh_time ⇒ Float
Average refresh duration in milliseconds. Returns 0.0 before any measurements are available.
-
#last_refresh_time ⇒ Float
Duration of the last complete refresh in milliseconds. In SketchUp, passing true for full includes the entire frame. ModraUp currently returns 0.0.
-
#animation= ⇒ Object, nil
Set the animation object and start the clock. The host ticks with next(view); if there is no next, it ticks with nextFrame(view).
-
#show_frame ⇒ ModraUp::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.
-
#drawing_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.
-
#line_width= ⇒ Numeric
Sets the line width for #draw in logical pixels.
-
#line_stipple ⇒ String
Current #draw line stipple. An empty string represents solid lines.
-
#line_stipple= ⇒ String
Sets the #draw line pattern. Valid values are the same as in SketchUp:
-
#set_color_from_line(point1, point2) ⇒ ModraUp::View
Set the draw color to the red/green/blue axis color based on the direction defined by two points.
-
#draw(opengl_const, *points) ⇒ ModraUp::View
Draw 3D geometry. Valid in ModraUp::Tool#draw or an active ModraUp::Overlay#draw.
-
#draw2d(opengl_const, *points) ⇒ ModraUp::View
Draw primitives on screen coordinates. Valid in ModraUp::Tool#draw or an enabled ModraUp::Overlay#draw.
-
#draw_line(*points) ⇒ ModraUp::View
Draw a polyline. Point types are the same as for #draw; nil skips the point.
-
#draw_polyline(*points) ⇒ ModraUp::View
Same as #draw_line.
-
#draw_lines(*points) ⇒ ModraUp::View
Draw line segments by points. The point types are the same as for #draw; nil skips the point.
-
#draw_points(points, size = 6, style = 3, color = "black") ⇒ ModraUp::View
Draw screen points. style: 1 empty square, 2 solid square, 3 cross, 4 plus, 5 star, 6 empty triangle, 7 solid triangle.
-
#draw_text(point, text) ⇒ ModraUp::View
Draw text on the screen coordinates. The options can contain :font, :size, :pixel_size, :point_size, :bold, :align, :vertical_align, and :color.
-
#text_bounds(point, text) ⇒ Geom::Bounds2d
Calculate the text box in screen coordinates for #draw_text. The point is in viewport pixels (Z ignored).
-
#load_texture(filename, *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.
-
#release_texture(texture_id) ⇒ Boolean
Release the #load_texture handle. Return false if the unknown ID or host is invalid.
-
#write_image(filename, width = vpwidth, height = vpheight, antialias = false, compression = 1.0) ⇒ Boolean
Write the current 3D frame buffer as an image. Returns false if host fails or capture fails.
-
#inputpoint ⇒ ModraUp::InputPoint
Creates a ModraUp::InputPoint. Supplying coordinates immediately calls ModraUp::InputPoint#pick.
-
#inference_locked? ⇒ Boolean
Returns whether inference is locked by #lock_inference.
-
#lock_inference ⇒ ModraUp::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.
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.
view.camera ⇒ ModraUp::Camera
Current viewport camera. Calling ModraUp::Camera#set on the returned object will change the viewport.
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.
view.model ⇒ ModraUp::Model
The model to which this viewport belongs.
view.pickray(x, y) ⇒ Arrayview.pickray(screen_point) ⇒ Array
Screen point corresponding world ray: [Geom::Point3d start point, Geom::Vector3d direction].
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.
view.tooltip ⇒ String
Viewport tooltip text displayed next to the cursor.
view.tooltip = string ⇒ String
Set the viewport tooltip next to the cursor. An empty string will hide it.
view.invalidate ⇒ view
Request the viewport to be redrawn (Tools + Draw+ / Animation).
view.vpwidth ⇒ Integer
Viewport width (pixels).
view.vpheight ⇒ Integer
Viewport height (pixels).
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.
view.zoom_extents ⇒ view
Zoom to extents of the entire model, equivalent to filling the viewport.
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.
view.remove_observer(observer) ⇒ Boolean
Removes the observer. Returns false if it was absent.
view.refresh ⇒ view
Request an immediate redraw. Currently, this is equivalent to #invalidate and does not guarantee synchronous completion.
view.center ⇒ Geom::Point3d
The screen coordinates (logical pixels) of the viewport center.
view.corner(index) ⇒ Geom::Point3d
The screen coordinates of the Viewport corner. index can be CORNER_TOP_LEFT, etc.
view.device_width ⇒ Integer
Viewport physical pixel width (logical width × UI.scale_factor(view)).
view.device_height ⇒ Integer
Viewport physical pixel height (logical height × UI.scale_factor(view)).
view.field_of_view ⇒ Numeric
Vertical field of view in degrees, same as ModraUp::Camera#fov.
view.field_of_view = degrees ⇒ Numeric
Sets the vertical field of view.
view.graphics_engine ⇒ Symbol
Graphics backend. ModraUp fixed :graphics_engine_classic (OpenGL 3.3 + QPainter overlay).
view.pixels_to_model(pixels, point) ⇒ Numeric
Convert logical pixel dimensions to the model length at the point location.
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.
view.dynamic = value ⇒ Object
Deprecated, ignore.
view.average_refresh_time ⇒ Float
Average refresh duration in milliseconds. Returns 0.0 before any measurements are available.
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.
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.
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.
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.
view.line_width = width ⇒ Numeric
Sets the line width for #draw in logical pixels.
view.line_stipple ⇒ String
Current #draw line stipple. An empty string represents solid lines.
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.
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.
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.
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.
view.draw_line(*points) ⇒ view
Draw a polyline. Point types are the same as for #draw; nil skips the point.
view.draw_polyline(*points) ⇒ view
Same as #draw_line.
view.draw_lines(*points) ⇒ view
Draw line segments by points. The point types are the same as for #draw; nil skips the point.
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.
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").
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.
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.
view.release_texture(texture_id) ⇒ Boolean
Release the #load_texture handle. Return false if the unknown ID or host is invalid.
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.
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.
view.inference_locked? ⇒ Boolean
Returns whether inference is locked by #lock_inference.
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.