c4d.utils.ViewportSelect

This class is used to extract information from a viewport about which objects and object elements are visible at which pixels. It is used internally for stuff like highlighting and modeling.

Inheritance

  • c4d.utils.ViewportSelect

Members

ViewportSelect.__init__()
Return type: ViewportSelect
Returns: A new viewport select object.
ViewportSelect.Init(w, h, bd, ops, mode, onlyvisible, flags)

Initializes the viewport information for multiple objects. This has to be done before the pixel information can be retrieved. You have to retrieve the width and height of the viewport manually:

frame = bd.GetFrame()
left = frame["cl"]
right = frame["cr"]
top = frame["ct"]
bottom = frame["cb"]

width = right - left + 1
height = bottom - top +1
Parameters:
  • w (int) – Width of the viewport in pixels.
  • h (int) – Height of the viewport in pixels.
  • bd (BaseDraw) – The viewport base draw.
  • ops (list of BaseObject) – A list with objects to get the information for.
  • mode (int) –

    Editor mode:

    Mpoints Point edit mode.
    Medges Edge edit mode.
    Mpolygons Polygon edit mode.
    Mpolyedgepoint Combined poly/edge/point mode. Must only be used in ViewportSelect.
  • onlyvisible (bool) – If this is True only visible elements are included.
  • flags (int) –

    Flags:

    VIEWPORT_USE_HN Use HyperNURBS.
    VIEWPORT_USE_DEFORMERS Use deformers.
    VIEWPORT_IGNORE_HIDDEN_SEL Ignore hidden selection.
ViewportSelect.GetPixelInfoPoint(x, y)

Retrieves point information at the pixel position (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
op = infopoint["op"] #c4dBaseObject
z = infopoint["z"] #float
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Return type:

dict{i: int, op: BaseObject, z: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetPixelInfoPolygon(x, y)

Retrieves polygon information at the pixel position (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
op = infopoint["op"] #c4dBaseObject
z = infopoint["z"] #float
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Return type:

dict{i: int, op: BaseObject, z: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetPixelInfoEdge(x, y)

Retrieves edge information at the pixel positio (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
op = infopoint["op"] #c4dBaseObject
z = infopoint["z"] #float
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Return type:

dict{i: int, op: BaseObject, z: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetNearestPoint(op, x, y[, maxrad=MAXLONG][, onlyselected=False][, ignorelist=None][, ignorecnt=0])

New in version R13.029.

Retrieves nearest point information at the pixel position (x,y).

Parameters:
  • op (BaseObject) – The object to search for the closest element.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init(). If an element was found the reference is updated to reflect the X coordinate of the nearest point.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init(). If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
  • maxrad (int) – A maximal radius for the search in pixels.
  • onlyselected (ignorelist) – If this is True only selected elements are included in the search.
  • onlyselected – List of points to ignore.
  • ignorecnt (int) – Ignore list count.
Return type:

dict{i: int, op: BaseObject, z: float, x: float, y: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

x

float

X pixel position.

 

y

float

Y pixel position.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetNearestPolygon(op, x, y[, maxrad=MAXLONG][, onlyselected=False][, ignorelist=None][, ignorecnt=0])

New in version R13.029.

Retrieves nearest polygon information at the pixel position (x,y).

Parameters:
  • op (BaseObject) – The object to search for the closest element.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init(). If an element was found the reference is updated to reflect the X coordinate of the nearest point.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init(). If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
  • maxrad (int) – A maximal radius for the search in pixels.
  • onlyselected (ignorelist) – If this is True only selected elements are included in the search.
  • onlyselected – List of polygons to ignore.
  • ignorecnt (int) – Ignore list count.
Return type:

dict{i: int, op: BaseObject, z: float, x: float, y: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

x

float

X pixel position.

 

y

float

Y pixel position.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetNearestEdge(op, x, y[, maxrad=MAXLONG][, onlyselected=False][, ignorelist=None][, ignorecnt=0])

New in version R13.029.

Retrieves nearest edge information at the pixel position (x,y).

Parameters:
  • op (BaseObject) – The object to search for the closest element.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init(). If an element was found the reference is updated to reflect the X coordinate of the nearest point.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where y is the width given to Init(). If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
  • maxrad (int) – A maximal radius for the search in pixels.
  • onlyselected (ignorelist) – If this is True only selected elements are included in the search.
  • onlyselected – List of edges to ignore.
  • ignorecnt (int) – Ignore list count.
Return type:

dict{i: int, op: BaseObject, z: float, x: float, y: float}

i

int

Element index. The index depends on the element type:

 
   

point

point index

   

polygon

polygon index

   

edge

4*polygon + edge index

   

spline

point segment offset + point index

op

BaseObject

Object.

 

z

float

Z coordinate of the current element.

 

x

float

X pixel position.

 

y

float

Y pixel position.

 

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.DrawPolygon(p, i, op[, onlyvisible=False])

Draws a polygon into the internal pixel structure, so that pixels inside the polygon will be associated with i and op in the viewport pixel retrieved.

Parameters:
  • p (array (Vector)) –

    An array of points that make up the polygon.

    Note

    All coordinates are in screen space.

  • i (int) – The polygon index to associate with this polygon.
  • op (BaseObject) – The object to associate with this polygon.
  • onlyvisible (bool) – If this is True, only visible parts of the polygon are drawn.
Return type:

bool

Returns:

True if successfull, otherwise False.

ViewportSelect.DrawHandle(p, i, op[, onlyvisible=False])

Draws a handle into the internal pixel structure, so that pixels inside the handle will be associated with i and op in the viewport pixel retrieved.

Parameters:
  • p (Vector) –

    The position of the handle.

    Note

    All coordinates are in screen space.

  • i (int) – The polygon index to associate with this polygon.
  • op (BaseObject) – The object to associate with this polygon.
  • onlyvisible (bool) – If this is True, only visible parts of the handle are drawn.
Return type:

bool

Returns:

True if successfull, otherwise False.

ViewportSelect.ShowHotspot(bw, x, y)

Draws an XOR circle to the view bw at the pixel position (x, y). The radius is set by SetBrushRadius().

Parameters:
  • bw (EditorWindow) – The editor window to draw to.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
ViewportSelect.SetBrushRadius(r)

Sets the radius for ShowHotspot().

Parameters: r (float) – The new radius in pixels.
ViewportSelect.ClearPixelInfo(x, y, mask)

Deletes the pixel information at (x ,*y*) according to mask.

This is used for example in the live edge selection with “tolerant” deactivated to find out how many pixels of a certain edge was selected. If an edge is determined under the cursor, the pixel counter is decremented and the edge information is deleted afterwards.

Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
  • mask (int) –

    A bitfield of what to clear:

    VIEWPORT_CLEAR_POINT Clear points.
    VIEWPORT_CLEAR_POLYGON Clear polygons.
    VIEWPORT_CLEAR_EDGE Clear edges.
ViewportSelect.GetCameraCoordinates(x, y, z)

Converts the pixel position ( x , y , z ) to camera coordinates.

Parameters:
  • x (float) – An X coordinate within the viewport.
  • y (float) – An Y coordinate within the viewport.
  • z (float) – A Z coordinate.
Return type:

Vector

Returns:

The calculated camera coordinate.

ViewportSelect.PickObject(bd, doc, x, y, rad, allowOpenGL)

Deletes the pixel information at (x ,*y*) according to mask.

This is used for example in the live edge selection with “tolerant” deactivated to find out how many pixels of a certain edge was selected. If an edge is determined under the cursor, the pixel counter is decremented and the edge information is deleted afterwards.

Parameters:
  • bd (BaseDraw) – The viewport base draw.
  • doc (BaseDocument) – Document.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
  • rad (int) – A radius for the search in pixels.
  • allowOpenGL (bool) – Allow OpenGL.
Return type:

list[BaseObject]

Returns:

Object list or None on failure.

Table Of Contents