c4d.BaseView

class c4d.BaseView
BaseView represents an editor view.
In most cases the sub-class BaseDraw is used. It adds functions for drawing into the view.

See the dbasedraw.h description file for container IDs.

Warning

This type cannot be instantiated.

Methods Signatures

BaseView.GetFrame(self)

The dimension in pixels of the view window.

BaseView.GetSafeFrame(self)

The dimension in pixels of the render lines.

BaseView.GetViewParameter(self)

Retrieves the parameters for the current projection. See Ocamera.h for projection types.

BaseView.GetMg(self)

Returns the camera matrix, i.e. the global object matrix of the current camera object.

BaseView.GetMi(self)

Returns the inverse of the camera matrix.

BaseView.GetBaseMatrix(self)

Gets the base matrix.

BaseView.SetBaseMatrix(self, mg)

Sets the base matrix.

BaseView.GetPlanarRotation(self)

Gets the rotation of the planar views.

BaseView.SetPlanarRotation(self, r)

Sets the rotation of the planar views.

BaseView.GetProjection(self)

Returns the projection used by the view. See Ocamera.h for values.

BaseView.TestPoint(self, x, y)

Returns True if the point is within the boundary returned by GetFrame().

BaseView.TestPointZ(self, p)

Tests if the point is visible in the view according to the current projection.

BaseView.TestClipping3D(self, mp, rad, mg)

Tests if a bounding box is visible in the view according to the current projection.

BaseView.WS(self, p)

World to screen conversion.

BaseView.SW(self, p)

Screen to world conversion.

BaseView.WC(self, p)

World to camera conversion.

BaseView.CW(self, p)

Camera to world conversion.

BaseView.SC(self, p)

Screen to camera conversion.

BaseView.CS(self, p, z_inverse)

Camera to screen conversion.

BaseView.WC_V(self, v)

World to camera vector conversion.

BaseView.CW_V(self, v)

Camera to world vector conversion.

BaseView.PW_S(self, z, horizontal)

Returns the size in world units for a single pixel at the given Z-depth z.

BaseView.WP_S(self, z, horizontal)

Returns the size in pixels for a single world unit at the given Z-depth z.

BaseView.PW_W(self, p, horizontal)

Returns the size in world units for a single pixel at screen space vector p.

BaseView.WP_W(self, p, horizontal)

Returns the size in screen space pixels for a single world unit at world position p.

BaseView.BackfaceCulling(self, n, p)

Tests the face with center p and normal n for backface culling.

BaseView.ZSensitiveNear(self)

Indicates if the view has Z near clipping.

BaseView.ZSensitiveNearClipping(self)

Returns the near clipping of Z sensitive view.

BaseView.ZSensitiveFar(self)

Indicates if the view has Z far clipping.

BaseView.ZSensitiveFarClipping(self)

Returns the far clipping of Z sensitive view.

BaseView.ProjectPointOnLine(self, p, v, mouse_x, ...)

Calculates the nearest point on the line defined by p and v for a given mouse coordinate.

BaseView.ProjectPointOnPlane(self, p, v, mouse_x, ...)

Calculates the nearest point on the plane defined by p and v for a given mouse coordinate.

Inheritance

Parent Class:

Child Class:

Methods Documentation

BaseView.GetFrame(self)
The dimension in pixels of the view window.
The coordinates are relative to the upper left corner of the view, and specify visible pixels. (I.e. the border is not included.).
>>> bd = doc.GetActiveBaseDraw()
>>> bd
<c4d.BaseDraw object called Perspective with ID 110305 at 1694970435200>
>>> bd.GetFrame()
{'cl': 0, 'ct': 0, 'cr': 696, 'cb': 441}
Return type

Dict[int, int, int, int]

BaseView.GetSafeFrame(self)
The dimension in pixels of the render lines.
The render lines show what part of the view is included in the rendered picture.
>>> bd = doc.GetActiveBaseDraw()
>>> bd
<c4d.BaseDraw object called Perspective with ID 110305 at 1694970435200>
>>> bd.GetSafeFrame()
{'cl': 0, 'ct': 25, 'cr': 696, 'cb': 417}
Return type

Dict[int, int, int, int]

BaseView.GetViewParameter(self)
Retrieves the parameters for the current projection. See Ocamera.h for projection types.
The following is the code used internally to project points.
CAMDIST = 0.05

def WorldToCamera(p, camera_matrix):
    return p * (~camera_matrix)


def CameraToWorld(p, camera_matrix):
    return p * camera_matrix


def CameraToScreen(pp):
    p = c4d.Vector(pp)
    if projection == c4d.Pperspective:
        nz = 1.0 / CAMDIST if p.z <= 0 else 1.0 / (p.z + CAMDIST)
        p.x = p.x * scale.x * nz+off.x
        p.y = p.y * scale.y * nz+off.y
        return p

    p.x = (p.x * scale.x) + off.x
    p.y = (p.y * scale.y) + off.y

    if projection in (c4d.Pmilitary, c4d.Pfrog, c4d.Pgentleman):
        p.x += p.z * scale.x * sclaez.x
        p.y -= p.z * scale.y * scalez.y
    return p


def ScreenToCamera(pp):
    p = c4d.Vector(pp)
    if projection in (c4d.Pmilitary, c4d.Pfrog, c4d.Pgentleman):
        p.x -= p.z * scale.x * scalez.x
        p.y += p.z * scale.y * scalez.y

    p.x = (p.x - off.x) / scale.x
    p.y = (p.y - off.y) / scale.y

    if projection == c4d.Pperspective:
        nz = p.z + CAMDIST
        p.x *= nz
        p.y *= nz
    return p

For non-axometric projection here’s the code how to calculate off/scale.

def InitView(camera, xres, yres, pix_x, pix_y):

    opm = camera.GetMg()
    data = camera.GetDataInstance()
    project = data.GetInt32(c4d.CAMERA_PROJECTION, c4d.Pperspective)

    if projection not in (c4d.Pperspective, c4d.Pparallel):
        opm.v1 = c4d.Vector(1.0, 0.0, 0.0)
        opm.v2 = c4d.Vector(0.0, 1.0, 0.0)
        opm.v3 = c4d.Vector(0.0, 0.0, 1.0)

    off.x = xres * 0.5
    off.y = yres * 0.5

    if b_ab == c4d.Pperspective:
        ap = data.GetFloat(c4d.CAMERAOBJECT_APERTURE, 36.0)
        scale.x = data.GetFloat(c4d.CAMERA_FOCUS, 36.0) / ap * xres
    else:
        scale.x = xres / 1024.0 * data.GetFloat(c4d.CAMERA_ZOOM, 1.0)

    scale.y = -scale.x * pix_x / pix_y
    # ... calculated here

Example for how to use BaseView.GetViewParameter():

>>> bd = doc.GetActiveBaseDraw()
>>> bd
<c4d.BaseDraw object called Perspective with ID 110305 at 1694970435200>
>>> bd.GetViewParameter()
{'offset': Vector(348.5, 221, 0), 'scale': Vector(697, -697, 0), 'scale_z': Vector(0, 0, 0)}
Return type

Dict[c4d.Vector, c4d.Vector, c4d.Vector]

Returns

The dimension, is never None.

BaseView.GetMg(self)

Returns the camera matrix, i.e. the global object matrix of the current camera object.

Return type

c4d.Matrix

Returns

The camera matrix.

BaseView.GetMi(self)

Returns the inverse of the camera matrix.

Equivalent to GetMg(), but faster.

Return type

c4d.Matrix

Returns

The inverted camera matrix.

BaseView.GetBaseMatrix(self)

Gets the base matrix.

New in version R14.014.

Note

The base matrix is multiplied with the camera matrix so that it is possible to have e.g. a frontal view into another direction than +Z.

Return type

c4d.Matrix

Returns

The base matrix.

BaseView.SetBaseMatrix(self, mg)

Sets the base matrix.

New in version R14.014.

Note

The base matrix is multiplied with the camera matrix so that it is possible to have e.g. a frontal view into another direction than +Z.

Parameters

mg (c4d.Matrix) – The new base matrix.

BaseView.GetPlanarRotation(self)

Gets the rotation of the planar views.

New in version R14.014.

Return type

float

Returns

The planar rotation.

BaseView.SetPlanarRotation(self, r)

Sets the rotation of the planar views.

New in version R14.014.

Parameters

mg (float) – The new planar rotation.

BaseView.GetProjection(self)

Returns the projection used by the view. See Ocamera.h for values.

Return type

int

Returns

The projection type.

BaseView.TestPoint(self, x, y)
Returns True if the point is within the boundary returned by GetFrame().
The point coordinates must be in screen space.
Parameters
  • x (int) – X coordinate

  • y (int) – Y coordinate

Return type

bool

Returns

True if the point is inside, otherwise False.

BaseView.TestPointZ(self, p)
Tests if the point is visible in the view according to the current projection.
The point must be in camera space.
Parameters

p (c4d.Vector) – The point to check.

Return type

bool

Returns

True if the point is visible in the view, otherwise False.

BaseView.TestClipping3D(self, mp, rad, mg)

Tests if a bounding box is visible in the view according to the current projection.

The box is defined with passed mp, rad and mg by these eight corner coordinates

p0 = c4d.Vector(mp.x + rad.x, mp.y + rad.y, mp.z + rad.z) * mg
p1 = c4d.Vector(mp.x + rad.x, mp.y + rad.y, mp.z - rad.z) * mg
p2 = c4d.Vector(mp.x + rad.x, mp.y - rad.y, mp.z + rad.z) * mg
p3 = c4d.Vector(mp.x + rad.x, mp.y - rad.y, mp.z - rad.z) * mg
p4 = c4d.Vector(mp.x - rad.x, mp.y + rad.y, mp.z + rad.z) * mg
p5 = c4d.Vector(mp.x - rad.x, mp.y + rad.y, mp.z - rad.z) * mg
p6 = c4d.Vector(mp.x - rad.x, mp.y - rad.y, mp.z + rad.z) * mg
p7 = c4d.Vector(mp.x - rad.x, mp.y - rad.y, mp.z - rad.z) * mg
Parameters
  • mp (c4d.Vector) – The center of the box.

  • rad (c4d.Vector) – The radius of the box.

  • mg (c4d.Matrix) – The transformation to world space from mp/rad space.

Return type

Dict[bool, bool, bool]

Returns

A dictionary with the following information:

’visible’: True if the box is visible, otherwise False.
’clip2d’: True if the box needs 2D clipping, i.e. if any part of it is outside of the view boundaries. Otherwise False.
’clipz’: True if the box needs Z clipping, i.e. if any part of it is too close to or behind the camera. Otherwise False.

BaseView.WS(self, p)
World to screen conversion.
Converts p from world space to screen space (pixels relative to the view), and returns the conversion.
The orthogonal distance to the world point is stored in world units in the Z axis of the result.
Parameters

p (c4d.Vector) – A point in world space.

Return type

c4d.Vector

Returns

The point in screen space.

BaseView.SW(self, p)
Screen to world conversion.
Converts p from screen space (pixels relative to the view) to world space.

The X and Y coordinates of the point are given in screen space; the Z coordinate is the orthogonal distance in world units to the point from the view plane. The result of the conversion is returned.
Parameters

p (c4d.Vector) – A point in screenspace.

Return type

c4d.Vector

Returns

The point in worldspace.

BaseView.WC(self, p)
World to camera conversion.
Converts p from world space to camera space and returns the result.
Parameters

p (c4d.Vector) – A point in world space.

Return type

c4d.Vector

Returns

The point in camera space.

BaseView.CW(self, p)
Camera to world conversion.
Converts p from camera space to world space and returns the result.
Parameters

p (c4d.Vector) – A point in camera space.

Return type

c4d.Vector

Returns

The point in world space.

BaseView.SC(self, p)
Screen to camera conversion.
Converts p from screen space (pixels relative to the view) to camera space and returns the result.

The X and Y coordinates of the point are given in screen space; the Z coordinate is the orthogonal distance in world units to the point from the view plane.
Parameters

p (c4d.Vector) – A point in screen space.

Return type

c4d.Vector

Returns

The point in camera space.

BaseView.CS(self, p, z_inverse)
Camera to screen conversion.
Converts p from camera space to screen space (pixels relative to the view) and returns the result.
Parameters
  • p (c4d.Vector) – A point in camera space.

  • z_inverse (bool) –

    If True the Z coordinate of the converted point is inverted.
    This is used by the Z-buffer.

Return type

c4d.Vector

Returns

A point in screen space.

BaseView.WC_V(self, v)
World to camera vector conversion.
Converts the world vector v to camera space and returns the result.
Parameters

v (c4d.Vector) – A vector in world space.

Return type

c4d.Vector

Returns

The vector in camera space.

BaseView.CW_V(self, v)
Camera to world vector conversion.
Converts the camera vector v to world space and returns the result.
Parameters

v (c4d.Vector) – A vector in camera space.

Return type

c4d.Vector

Returns

The vector in world space.

BaseView.PW_S(self, z, horizontal)

Returns the size in world units for a single pixel at the given Z-depth z.

Parameters
  • z (float) – The Z-depth.

  • horizontal (bool) –

    True if the size is measured horizontally, False for vertical measurement.
    This is useful for non-square pixel aspect ratios.

Return type

float

Returns

The size in world units.

BaseView.WP_S(self, z, horizontal)

Returns the size in pixels for a single world unit at the given Z-depth z.

Parameters
  • z (float) – The Z-depth.

  • horizontal (bool) –

    True if the size is measured horizontally, False for vertical measurement.
    This is useful for non-square pixel aspect ratios.

Return type

float

Returns

The size in pixels.

BaseView.PW_W(self, p, horizontal)

Returns the size in world units for a single pixel at screen space vector p.

Parameters
  • p (c4d.Vector) – The pixel in screen space.

  • horizontal (bool) –

    True if the size is measured horizontally, False for vertical measurement.
    This is useful for non-square pixel aspect ratios.

Return type

float

Returns

Size in world units.

BaseView.WP_W(self, p, horizontal)

Returns the size in screen space pixels for a single world unit at world position p.

Parameters
  • p (c4d.Vector) – The world unit in world space.

  • horizontal (bool) –

    True if the size is measured horizontally, False for vertical measurement.
    This is useful for non-square pixel aspect ratios.

Return type

float

Returns

Size in screen space pixels.

BaseView.BackfaceCulling(self, n, p)

Tests the face with center p and normal n for backface culling.

Note

Both vector must be defined in the same space coordinate.

Parameters
Return type

c4d.Vector

Returns

True if the face should be visible, otherwise False.

BaseView.ZSensitiveNear(self)

Indicates if the view has Z near clipping.

Return type

bool

Returns

True if the view has Z clipping near, otherwise False.

BaseView.ZSensitiveNearClipping(self)

Returns the near clipping of Z sensitive view.

BaseView.ZSensitiveFar(self)

Indicates if the view has Z far clipping.

Return type

bool

Returns

True if the view has Z clipping far, otherwise False.

BaseView.ZSensitiveFarClipping(self)

Returns the far clipping of Z sensitive view.

Return type

float

Returns

Far clipping distance.

BaseView.ProjectPointOnLine(self, p, v, mouse_x, mouse_y)

Calculates the nearest point on the line defined by p and v for a given mouse coordinate.

Parameters
  • p (c4d.Vector) – Start position of the line in world space.

  • v (c4d.Vector) – Direction of the line. The length of this vector determines the scaling of the returned offset.

  • mouse_x (float) – Mouse X-coordinate.

  • mouse_y (float) – Mouse Y-coordinate.

Return type

tuple(Vector, float, int)

Returns

The nearest point on the line, the distance from p scaled by the length of v (offset = distance to p / length of v) and an error code:

  • 1 = Failed to find nearest point correctly, lines may be beyond horizon, behind camera, or ray line and line may be parallel.

  • 2 = Point is either beyond the start or end of the described segment (but a point will still be returned for the line/ray).

BaseView.ProjectPointOnPlane(self, p, v, mouse_x, mouse_y)

Calculates the nearest point on the plane defined by p and v for a given mouse coordinate.

Parameters
  • p (c4d.Vector) – The plane’s position in world space.

  • v (c4d.Vector) – The plane’s normal in world space.

  • mouse_x (float) – Mouse X-coordinate.

  • mouse_y (float) – Mouse Y-coordinate.

Return type

tuple(Vector, int)

Returns

The nearest point on the plane and an error code:

  • 1 = Failed to find nearest point correctly, lines may be beyond horizon, behind camera, or ray line and line may be parallel.

  • 2 = Point is either beyond the start or end of the described segment (but a point will still be returned for the line/ray).