c4d.BaseView
¶
BaseView represents an editor view. It cannot be instantiated. 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.
c4d.
BaseView
¶
BaseView.GetFrame()
BaseView.GetSafeFrame()
BaseView.GetViewParameter()
BaseView.GetMg()
BaseView.GetMi()
BaseView.GetBaseMatrix()
BaseView.SetBaseMatrix()
BaseView.GetPlanarRotation()
BaseView.SetPlanarRotation()
BaseView.GetProjection()
BaseView.TestPoint()
BaseView.TestPointZ()
BaseView.TestClipping3D()
BaseView.WS()
BaseView.SW()
BaseView.WC()
BaseView.CW()
BaseView.SC()
BaseView.CS()
BaseView.WC_V()
BaseView.CW_V()
BaseView.ZSensitiveNear()
BaseView.ZSensitiveNearClipping()
BaseView.ZSensitiveFar()
BaseView.ZSensitiveFarClipping()
c4d.BaseList2D
BaseView.
GetFrame
(
)
¶
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.):
dimension = bv.GetFrame() print dimension["cl"], dimension["ct"], dimension["cr"], dimension["cb"] #(left, top, right, bottom)
Key cl: | The first visible left pixel position. |
---|---|
Key ct: | The first visible top pixel position. |
Key cr: | The first visible right pixel position. |
Key cb: | The first visible bottom pixel position. |
Return type: | dict{ cl : int, ct : int, cr : int, cb : int} |
BaseView.
GetSafeFrame
(
)
¶
The dimension in pixels of the render lines. The render lines show what part of the view is included in the rendered picture:
position = bv.GetSafeFrame() print position["cl"], position["ct"], position["cr"], position["cb"] #(left, top, right, bottom)
Key cl: | The first visible left pixel position. |
---|---|
Key ct: | The first visible top pixel position. |
Key cr: | The first visible right pixel position. |
Key cb: | The first visible bottom pixel position. |
Return type: | dict{ cl : int, cl : int, cr : int, cb : int} |
BaseView.
GetViewParameter
(
)
¶
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*(~inverse_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<=00 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==c4d.Pmilitary or projection==c4d.Pfrog or projection==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==c4d.Pmilitary or projection==c4d.Pfrog or projection==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.GetInt(CAMERA_PROJECTION, Pperspective) if projection!=Pperspective and projection!=Pparallel: opm.v1 = Vector(1.0,0.0,0.0) opm.v2 = Vector(0.0,1.0,0.0) opm.v3 = Vector(0.0,0.0,1.0) off.x = xres*0.5 off.y = yres*0.5 if b_ab == Pperspective: ap = data.GetFloat(CAMERAOBJECT_APERTURE, 36.0) scale.x = data.GetFloat(CAMERA_FOCUS, 36.0) / ap * xres else: scale.x = xres/1024.0*data.GetFloat(CAMERA_ZOOM,1.0) scale.y = -scale.x*pix_x/pix_y # ... calculated here #example how to use GetViewParameter params = bv.GetViewParameter() #params["offset"], params["scale"], params["scale_z"]
Key params: | The center of the view in screen space. |
---|---|
Key scale: | For perspective mode: the size of the view plane in pixels. For axonometric modes: the number of pixels per meter. |
Key scale_z: | The different Z scale for the X and Y axes in axonometric projections. |
Return type: |
dict{
offset
:
Vector
,
scale
:
Vector
,
scale_z
:
Vector
}
|
---|---|
Returns: | The dimension, is never None . |
BaseView.
GetMg
(
)
¶
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
(
)
¶
Returns the inverse of the camera matrix. Equivalent to
GetMg()
, but faster.
Return type: | c4d.Matrix |
---|---|
Returns: | The inverted camera matrix. |
BaseView.
GetBaseMatrix
(
)
¶
New in version R14.014.
Gets the base matrix.
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
(
mg
)
¶
New in version R14.014.
Sets the base matrix.
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
(
)
¶
New in version R14.014.
Gets the rotation of the planar views.
Return type: | float |
---|---|
Returns: | The planar rotation. |
BaseView.
SetPlanarRotation
(
r
)
¶
New in version R14.014.
Sets the rotation of the planar views.
Parameters: | mg ( float ) – The new planar rotation. |
---|
BaseView.
GetProjection
(
)
¶
Returns the projection used by the view. See
Ocamera.h
for values.
Return type: | int |
---|---|
Returns: | The projection type. |
BaseView.
TestPoint
(
x
,
y
)
¶
Returns
True
if the point is within the boundary returned by
GetFrame()
. The point coordinates must be in screen space.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the point is inside, otherwise False . |
BaseView.
TestPointZ
(
z
)
¶
Returns True if the point is visible in the view according to the current projection. The point must be in camera space.
Parameters: | y ( c4d.Vector ) – Y coordinate |
---|---|
Return type: | bool |
Returns: | True if the point is visible, otherwise False . |
BaseView.
TestClipping3D
(
mp
,
rad
,
mg
)
¶
Tests if a bounding box is visible in the view according to the current projection. The box is defined by these eight corner coordinates:
p = ( ) p.append(c4d.Vector(mp.x + rad.x, mp.y + rad.y, mp.z + rad.z) * mg) p.append(c4d.Vector(mp.x + rad.x, mp.y + rad.y, mp.z - rad.z) * mg) p.append(c4d.Vector(mp.x + rad.x, mp.y - rad.y, mp.z + rad.z) * mg) p.append(c4d.Vector(mp.x + rad.x, mp.y - rad.y, mp.z - rad.z) * mg) p.append(c4d.Vector(mp.x - rad.x, mp.y + rad.y, mp.z + rad.z) * mg) p.append(c4d.Vector(mp.x - rad.x, mp.y + rad.y, mp.z - rad.z) * mg) p.append(c4d.Vector(mp.x - rad.x, mp.y - rad.y, mp.z + rad.z) * mg) p.append(c4d.Vector(mp.x - rad.x, mp.y - rad.y, mp.z - rad.z) * mg) #example result = bv.TestClipping3D(mp, rad, mg) #result["visible"], result["clip2d"], result["clipz"]
Key visible: | True if the box is visible at all, otherwise False . |
---|---|
Key clip2d: | Is True if the box needs 2D clipping, i.e. if any part of it is outside of the view boundaries. Otherwise False . |
Key clipz: | Is assigned True if the box needs Z clipping, i.e. if any part of it is too close to or behind the camera. Otherwise False . |
Return type: | dict of bool: |
Returns: | The result |
BaseView.
WS
(
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
(
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
(
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
(
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
(
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
(
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: |
|
---|---|
Return type: | |
Returns: |
A point in screen space. |
BaseView.
WC_V
(
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
(
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
(
z
,
horizontal
)
¶
Returns the size in world units for a single pixel at the given Z-depth z .
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
The size in world units. |
BaseView.
WP_S
(
z
,
horizontal
)
¶
Returns the size in pixels for a single world unit at the given Z-depth z .
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
The size in pixels. |
BaseView.
PW_W
(
p
,
horizontal
)
¶
Returns the size in world units for a single pixel at screen space vector p .
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
Size in world units. |
BaseView.
WP_W
(
p
,
horizontal
)
¶
Returns the size in screen space pixels for a single world unit at world position p .
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
Size in screen space pixels. |
BaseView.
BackfaceCulling
(
n
,
p
)
¶
Tests the face with center p and normal n for backface culling.
Parameters: |
|
---|---|
Return type: | |
Returns: |
True if the face should be visible, otherwise False . |
BaseView.
ZSensitiveNear
(
)
¶
Indicates if the view has Z near clipping.
Return type: | bool |
---|---|
Returns: | True if the view has Z clipping near, otherwise False . |
BaseView.
ZSensitiveNearClipping
(
n
,
p
)
¶
Returns the near clipping of Z sensitive view.
Return type: | float |
---|---|
Returns: | Near clipping distance. |
BaseView.
ZSensitiveFar
(
)
¶
Indicates if the view has Z far clipping.
Return type: | bool |
---|---|
Returns: | True if the view has Z clipping far, otherwise False . |
BaseView.
ZSensitiveFarClipping
(
)
¶
Returns the far clipping of Z sensitive view.
Return type: | float |
---|---|
Returns: | Far clipping distance. |
BaseView.
ProjectPointOnLine
(
p
,
v
,
mouse_x
,
mouse_y
)
¶
Calculates the nearest point on the line defined by p and v for a given mouse coordinate.
Parameters: |
|
---|---|
Return type: |
tuple(
|
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 :
|
BaseView.
ProjectPointOnPlane
(
p
,
v
,
mouse_x
,
mouse_y
)
¶
Calculates the nearest point on the plane defined by p and v for a given mouse coordinate.
Parameters: |
|
---|---|
Return type: |
tuple(
|
Returns: |
The nearest point on the plane and an error code :
|