ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Camera

Inherits:
Object
  • Object
show all

Overview

Viewport Camera: eye, target, up, field of view, and projection. Obtain the current camera from ModraUp::View#camera, or create one with ModraUp::Camera.new. to_s returns "Sketchup::Camera".

Examples:

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

Class Method Summary # collapse

  • .new ⇒ ModraUp::Camera
    Construct the camera. With three parameters, it defaults to a perspective view with a field of view of 30 degrees.

Instance Method Summary # collapse

Class Method Details

Camera.new ⇒ cameraCamera.new(eye, target, up) ⇒ cameraCamera.new(eye, target, up, perspective, fov) ⇒ camera

Construct the camera. With three parameters, it defaults to a perspective view with a field of view of 30 degrees.

Parameters:

  • eye (Geom::Point3d, Array<Numeric>)
  • target (Geom::Point3d, Array<Numeric>)
  • up (Geom::Vector3d, Array<Numeric>)
  • perspective (Boolean)
  • fov (Numeric)

Returns:

  • (ModraUp::Camera)

Examples:

ModraUp::Camera.new([10, 0, 5], [0, 0, 0], [0, 0, 1]).eye

Instance Method Details

camera.set(eye, target, up) ⇒ camera

Sets the eye, target, and up direction simultaneously.

Parameters:

  • eye (Geom::Point3d, Array<Numeric>)
  • target (Geom::Point3d, Array<Numeric>)
  • up (Geom::Vector3d, Array<Numeric>)

Returns:

  • (ModraUp::Camera)

Examples:

ModraUp.active_model.active_view.camera.set([0, 10, 5], [0, 0, 0], [0, 0, 1])

camera.eye ⇒ Geom::Point3d

Camera position.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.active_view.camera.eye

camera.target ⇒ Geom::Point3d

Target. The point where the camera is aimed.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.active_view.camera.target

camera.up ⇒ Geom::Vector3d

Up direction. The track camera is derived from the Z-axis, with custom roll not saved.

Returns:

  • (Geom::Vector3d)

Examples:

ModraUp.active_model.active_view.camera.up

camera.perspective? ⇒ Boolean

Returns whether the projection is perspective.

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.camera.perspective?

camera.perspective ⇒ Boolean

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.camera.perspective

camera.perspective = value ⇒ value

Perspective is true, orthographic is false.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.active_view.camera.perspective = true

camera.fov ⇒ Numeric

Vertical field of view in degrees.

Returns:

  • (Numeric)

Examples:

ModraUp.active_model.active_view.camera.fov

camera.fov = degrees ⇒ Numeric

Sets the vertical field of view.

Parameters:

  • degrees (Numeric)

Returns:

  • (Numeric)

Examples:

ModraUp.active_model.active_view.camera.fov = 35

camera.aspect_ratio ⇒ Float

Aspect ratio of the view. +0.0 indicates that it matches the viewport.

Returns:

  • (Float)

Examples:

ModraUp::Camera.new.aspect_ratio  #=> 0.0

camera.aspect_ratio = ratio ⇒ Numeric

Set the aspect ratio of the view. 0 indicates that it will match the viewport's aspect ratio.

Parameters:

  • ratio (Numeric)

Returns:

  • (Numeric)
Note: The value is saved currently; the viewport has not yet drawn the gray strip.

Examples:

cam = ModraUp::Camera.new
cam.aspect_ratio = 1.85

camera.center_2d ⇒ Geom::Point3d

Translation: The translation offset for two-point perspective or photo matching (in normalized device coordinates). The z value is always 0.

Returns:

  • (Geom::Point3d)
Note: Currently, it always returns the origin; the two-point perspective translation is applied afterward.

Examples:

ModraUp::Camera.new.center_2d  #=> [0, 0, 0]

camera.description ⇒ String

Camera description text.

Returns:

  • (String)

Examples:

ModraUp::Camera.new.description  #=> ""

camera.description = description ⇒ String

Set the camera description text.

Parameters:

  • description (String)

Returns:

  • (String)

Examples:

cam = ModraUp::Camera.new
cam.description = "35 mm Camera"

camera.direction ⇒ Geom::Vector3d

The direction of the view, which is the same as the #zaxis.

Returns:

  • (Geom::Vector3d)

Examples:

ModraUp::Camera.new([0, 10, 0], [0, 0, 0], [0, 0, 1]).direction

camera.focal_length ⇒ Float

The focal length (in millimeters) calculated from #fov and #image_width. If #image_width is 0, it defaults to 36 mm.

Returns:

  • (Float)

Examples:

ModraUp::Camera.new([10, 0, 5], [0, 0, 0], [0, 0, 1]).focal_length

camera.focal_length = focal_length ⇒ Numeric

Sets the field of view using the focal length in millimeters. Valid range is 1..3000.

Parameters:

  • focal_length (Numeric)

Returns:

  • (Numeric)

Examples:

cam = ModraUp::Camera.new([10, 0, 5], [0, 0, 0], [0, 0, 1])
cam.focal_length = 120

camera.fov_is_height? ⇒ Boolean

Returns whether the field of view is measured in the vertical direction.

Returns:

  • (Boolean)
Note: The field of view is measured in the vertical direction.

Examples:

ModraUp::Camera.new.fov_is_height?  #=> true

camera.height ⇒ Float

Parallel projection visible height (in inches). Perspective camera also returns an equivalent height.

Returns:

  • (Float)

Examples:

cam = ModraUp::Camera.new
cam.perspective = false
cam.height

camera.height = value ⇒ Numeric

Sets the visible height for parallel projection in inches.

Parameters:

  • value (Numeric)

Returns:

  • (Numeric)

Examples:

cam = ModraUp::Camera.new
cam.perspective = false
cam.height = 20

camera.image_width ⇒ Float

Frame width in millimeters used to calculate #focal_length. A value of 0 means 36 mm.

Returns:

  • (Float)

Examples:

ModraUp::Camera.new.image_width  #=> 0.0

camera.image_width = image_width ⇒ Numeric

Set the image width in millimeters. 0 indicates that the focal length is calculated based on 36 mm. This does not affect the viewport display.

Parameters:

  • image_width (Numeric)

Returns:

  • (Numeric)

Examples:

cam = ModraUp::Camera.new
cam.image_width = 1.0

camera.is_2d? ⇒ Boolean

Returns true if the camera is in two-point perspective (or matches a photograph).

Returns:

  • (Boolean)

Examples:

ModraUp::Camera.new.is_2d?  #=> false

camera.scale_2d ⇒ Float

The scale factor for two-point perspective. Not scaled to 1.0.

Returns:

  • (Float)
Note: Currently fixed to return +1.0; two-point perspective scaling will be incorporated and written later.

Examples:

ModraUp::Camera.new.scale_2d  #=> 1.0

camera.xaxis ⇒ Geom::Vector3d

The camera coordinate system X-axis (right) is obtained by the cross product of the view direction and the up direction.

Returns:

  • (Geom::Vector3d)

Examples:

ModraUp::Camera.new([0, 10, 0], [0, 0, 0], [0, 0, 1]).xaxis

camera.yaxis ⇒ Geom::Vector3d

Camera coordinate system y-axis (up), perpendicular to the line of sight.

Returns:

  • (Geom::Vector3d)

Examples:

ModraUp::Camera.new([0, 10, 0], [0, 0, 0], [0, 0, 1]).yaxis

camera.zaxis ⇒ Geom::Vector3d

The camera coordinate system Z-axis, which is the same as #direction.

Returns:

  • (Geom::Vector3d)

Examples:

cam = ModraUp::Camera.new([0, 10, 0], [0, 0, 0], [0, 0, 1])
cam.zaxis == cam.direction

camera.focus_at(point) ⇒ camera

Focus the camera on the depth of point point, without translating or scaling the current view. Preserve the perspective eye position, and maintain the field of view height for parallel projection.

Parameters:

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

Returns:

  • (ModraUp::Camera)
Note: ModraUp extension. SketchUp does not have this method; the equivalent is Camera::focus_at.

Examples:

cam = ModraUp.active_model.active_view.camera
cam.focus_at(cam.target)

camera.zoom_at(point, factor) ⇒ camera

Zoom around a world point while maintaining that point's screen position. A factor greater than 1 moves the view farther away, while a factor less than 1 moves the view closer.

Parameters:

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

Returns:

  • (ModraUp::Camera)
Note: ModraUp extension. SketchUp does not have this method; the equivalent is Camera::zoom_at.

Examples:

cam = ModraUp.active_model.active_view.camera
cam.zoom_at(cam.target, 0.5)