IpCommunicationThread Class Reference

#include <c4d_renderconnection.h>

Inheritance diagram for IpCommunicationThread:

Open/Close

Bool Open (const Char *ip_address, Int32 application_id, Int32 initial_timeout, Int32 connection_timeout, Int32 retries=50)
 
Bool Close (Bool shutdown=true)
 

Send File

Bool SendScenefile (const Filename &filepath)
 
Bool SendScenefile (const Filename &filepath, BaseDocument *doc)
 
Bool FrameScene (OVERVIEW mode, Vector &newPos, Vector &newRot)
 
Bool SetActiveObject (Int32 appid, const void *mem, Int32 size, Int32 mode=0)
 

Update

Bool UpdateScenefile (Int32 unique_id_type, BaseDocument *doc)
 
Bool UpdateView (const Vector &pos, const Vector &rot, Float focal_length, Float aperture, Float zoom, Int32 projection, Bool bNewCamera=false)
 
Bool UpdateCamera (BaseObject *op, Bool bNewCamera=false)
 
Bool UpdateSetActiveCamera (Int32 applicationUID, GeMarker cameraUID)
 
Bool UpdateDisplaySettings (BaseDraw *draw)
 
Bool UpdateRenderSettings (RenderData *rdat, Bool bKeepVP=false)
 
Bool UpdateTime (BaseTime time)
 

Texture

Bool UseTextureCache (Bool bKeepTextures)
 
Bool SendTexture (const Filename &filepath, void *mem, Int64 len, Bool memoryOnly)
 
Bool SendTextureRaw (const Filename &filepath, void *data, const COLORMODE &mode, const Int64 &width, const Int64 &height, const Int64 &rowBytes)
 
Bool FlushTexture (const Filename &filepath)
 

Start/Stop Render

Bool StartRender (Int32 xres, Int32 yres, ColorResolution colorresolution, Bool allow_saving, Bool high_priority)
 
Bool StopRender ()
 

Image Callback

Bool GetImageUpdate (UpdateImage imgupdate, void *userdata, Bool *is_running)
 
Bool GetImageUpdateMP (Int32 vpbuffid, Int32 vpbuffsubid, UpdateImage imgupdate, void *userdata, Bool *is_running)
 
Bool GetFullImage (UpdateImage imgupdate, void *userdata, Bool *is_running)
 
Bool GetFullImageMP (Int32 vpbuffid, Int32 vpbuffsubid, UpdateImage imgupdate, void *userdata, Bool *is_running)
 

Textures/Assets

Bool GetAllTextures (BaseContainer *bc)
 
Bool GetAllAssets (BaseContainer *bc)
 

Miscellaneous

Bool ExportScene (const Filename &filepath, FILEFORMAT format)
 
Bool FreeSession ()
 
Bool ResetRenderServer ()
 
Bool GetC4dVersion (Int32 *version)
 
Bool GetC4dVersionType (VERSIONTYPE *type)
 
Bool GetPreferencePath (String &prefsPath)
 
Bool GetRenderStatus (Bool *is_running, Int32 *rendererror, Float *progress_percent, Int32 *progress_type)
 
Bool GetRenderErrorString (String &errorText)
 
Bool IsSceneAlive (Bool *is_alive)
 
BaseList2DConvertParameters (BaseList2D *node, CINEMA4D_VERSION version)
 
Bool BuildDescription (Int32 pluginId, BaseContainer &bc)
 
BaseDocumentRenderMaterials (BaseDocument *doc)
 

Private. For AFX only.

Bool UpdateLayer (BaseArray< GeMarker > &layerMarkers, Bool enableDefaultLayer)
 
Bool UpdateLayerEx (Int32 *array, Int32 count, Bool enableDefaultLayer)
 
Bool SetCurrentTake (const GeMarker &takeMarker)
 
Bool GetInfo (Int32 pluginID, Int32 *info)
 

Additional Inherited Members

- Public Types inherited from BaseThread
enum  {
  UnknownThreadId,
  MainThreadId,
  FirstThreadId
}
 
enum  {
  UnknownThreadId,
  MainThreadId,
  FirstThreadId
}
 
enum  {
  UnknownThreadId,
  MainThreadId,
  FirstThreadId
}
 
- Public Member Functions inherited from BaseCommunicationThread
 BaseCommunicationThread ()
 
IpConnectionGetIpc ()
 
- Public Member Functions inherited from BaseThread
 BaseThread ()
 
virtual ~BaseThread ()
 
void SetUserData (void *data)
 
void * GetUserData ()
 
virtual Int32 TestBreak ()
 
virtual Int32 Start (Bool back, Int32 Priority=THREADPRIORITY_NORMAL)
 
virtual void End (Bool wait=true)
 
virtual void Wait ()
 
virtual Bool IsRunning ()
 
virtual Bool ItsMe ()
 
virtual Int32 ChangeThreadPriority ()
 
void Action ()
 
void * GetCrashInfo ()
 
UInt32 GetThreadId ()
 
 BaseThread ()
 
virtual ~BaseThread ()
 
void SetUserData (void *data)
 
void * GetUserData ()
 
virtual Int32 TestBreak ()
 
virtual Bool IsRunning ()
 
virtual void Wait ()
 
virtual void End (Bool wait=true)
 
virtual Bool ItsMe ()
 
virtual Int32 Start (Bool back, Int32 priority=THREADPRIORITY_NORMAL)
 
virtual Int32 ChangeThreadPriority ()
 
 BaseThread ()
 
virtual ~BaseThread ()
 
void SetUserData (void *data)
 
void * GetUserData ()
 
virtual Int32 TestBreak ()
 
virtual Int32 Start (Bool back, Int32 Priority=THREADPRIORITY_NORMAL)
 
virtual void End (Bool wait=true)
 
virtual void Wait ()
 
virtual Bool IsRunning ()
 
virtual Bool ItsMe ()
 
virtual Int32 ChangeThreadPriority ()
 
void Action ()
 
void * GetCrashInfo ()
 
UInt32 GetThreadId ()
 
 BaseThread ()
 
 ~BaseThread ()
 
void SetUserData (void *data)
 
void * GetUserData ()
 
virtual Int32 TestBreak ()
 
virtual Int32 Start (Bool back, Int32 Priority=THREADPRIORITY_NORMAL)
 
virtual void End (Bool wait=true)
 
virtual void Wait ()
 
virtual Bool IsRunning ()
 
virtual Bool ItsMe ()
 
virtual Int32 ChangeThreadPriority ()
 
void Action ()
 
void * GetCrashInfo ()
 
UInt32 GetThreadId ()
 
- Static Public Member Functions inherited from BaseThread
static BaseThreadGetCurrentThread ()
 
static UInt32 GetCurrentThreadId ()
 
static Bool StopAllThreads ()
 
static BaseThreadGetCurrentThread ()
 
static UInt32 GetCurrentThreadId ()
 
static Bool StopAllThreads ()
 
static BaseThreadGetCurrentThread ()
 
static UInt32 GetCurrentThreadId ()
 
static Bool StopAllThreads ()
 
- Public Attributes inherited from BaseThread
Bool keepthreadrunning
 
- Protected Member Functions inherited from BaseCommunicationThread
Bool ReadBytes (void *adr, Int cnt)
 
Bool WriteBytes (void *adr, Int cnt)
 
Bool ReadString (String *v)
 
Bool WriteString (const String &v)
 
Bool ReadContainer (BaseContainer &bc)
 
Bool WriteContainer (const BaseContainer &bc)
 
Bool WriteChar (Char num)
 
Bool WriteUChar (UChar num)
 
Bool WriteInt32 (Int32 num)
 
Bool WriteInt64 (Int64 num)
 
Bool WriteFloat32 (Float32 num)
 
Bool ReadUChar (UChar &num)
 
Bool ReadInt16 (Int16 &num)
 
Bool ReadChar (Char &num)
 
Bool ReadInt32 (Int32 &num)
 
Bool ReadInt64 (Int64 &num)
 
Bool ReadFloat32 (Float32 &num)
 
IPCOMMANDRESULT SendCommand (Int32 command, Bool closeConnectionOnError=true)
 
Bool Acknowledged ()
 
virtual const CharGetThreadName ()
 
Bool SetError ()
 
- Protected Member Functions inherited from BaseThread
virtual void Main ()=0
 
void Init ()
 
void StopAsync ()
 
virtual void Main ()=0
 
virtual void Main ()=0
 
void Init ()
 
void StopAsync ()
 
virtual void Main ()=0
 
void Init ()
 
void StopAsync ()
 
- Protected Attributes inherited from BaseCommunicationThread
IpConnectionipc
 

Detailed Description

Communication thread to establish a connection to a render server and to control the rendering process.

Member Function Documentation

◆ Open()

Bool Open ( const Char ip_address,
Int32  application_id,
Int32  initial_timeout,
Int32  connection_timeout,
Int32  retries = 50 
)

Opens a connection to the render server at ip_address.

Parameters
[in]ip_addressIP address of the render server. The default IP (127.0.0.1:1234) is used if nullptr is passed.
[in]application_idA unique ID provided by the external application. Provide different (unique) IDs to maintain multiple sessions at the same time.
[in]initial_timeoutTimeout in seconds after which the connection attempts shall be stopped (default 10 seconds).
[in]connection_timeoutTimeout in seconds after which the connection will be closed if no data has been sent since then (default 60 seconds).
[in]retriesDefine how many times the function tries to connect.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ Close()

Bool Close ( Bool  shutdown = true)

Closes the connection to the render server.

Parameters
[in]shutdownThe connection is closed if set to false but the session is still valid, so it is possible to open a new connection.
In that case rendering will start then immediately, without the need to transfer the scene data again.
The render server terminates if set to true. All open sessions will be freed.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ SendScenefile() [1/2]

Bool SendScenefile ( const Filename filepath)

Transfers a file on disc to the render server/session.

Parameters
[in]filepathThe path to the file to transfer.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ SendScenefile() [2/2]

Bool SendScenefile ( const Filename filepath,
BaseDocument doc 
)

Transfers a document from memory to the render server/session.

Parameters
[in]filepathFilename for the scene.
[in]docDocument to transfer. The caller owns the pointed document.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ FrameScene()

Bool FrameScene ( OVERVIEW  mode,
Vector newPos,
Vector newRot 
)

Frames the active camera to the selected objects or elements, geometry only or whole scene.

Since
R19
Parameters
[in]modeDefines what should be zoomed to: OVERVIEW
[out]newPosNew local position of the active camera.
[out]newRotNew local rotation of the active camera.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ SetActiveObject()

Bool SetActiveObject ( Int32  appid,
const void *  mem,
Int32  size,
Int32  mode = 0 
)

Modifies the current object multi-selection on server side depending on mode.

Since
R19
Parameters
[in]appidThe unique application ID under which the UID of the object should be searched for.
[in]memPoints to a block of memory containing the UID data. Scene including the object must been sent already.
[in]sizeThe length of mem block.
[in]modeThe selection mode: SELECTION
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateScenefile()

Bool UpdateScenefile ( Int32  unique_id_type,
BaseDocument doc 
)

Updates an existing scene file on the render server.

Parameters
[in]unique_id_typeUnique ID, should usually be set to MAXON_CREATOR_ID unless an own system for unique IDs is used.
[in]docDocument to update. The caller owns the pointed document.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateView()

Bool UpdateView ( const Vector pos,
const Vector rot,
Float  focal_length,
Float  aperture,
Float  zoom,
Int32  projection,
Bool  bNewCamera = false 
)

Updates the scene or editor camera.

Parameters
[in]posNew camera position.
[in]rotNew camera rotation.
[in]focal_lengthNew focal length.
[in]apertureNew camera aperture.
[in]zoomNew camera zoom.
[in]projectionNew camera projection type, for instance Pleft or Pperspective.
[in]bNewCameraIf true if true, otherwise false., creates a new camera object.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateCamera()

Bool UpdateCamera ( BaseObject op,
Bool  bNewCamera = false 
)

Updates an existing scene camera with op.

Parameters
[in]opNew camera object. The caller owns the pointed camera object.
[in]bNewCameraIf true if true, otherwise false., creates a new camera object.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateSetActiveCamera()

Bool UpdateSetActiveCamera ( Int32  applicationUID,
GeMarker  cameraUID 
)

Sets an existing camera as active scene camera.

Parameters
[in]applicationUIDApplication UID under which the cameras UIDs should be searched for.
[in]cameraUIDUID of the camera object that should be set as active.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateDisplaySettings()

Bool UpdateDisplaySettings ( BaseDraw draw)

Updates the display settings of the given draw view.

Parameters
[in]drawView to update. The caller owns the pointed view.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateRenderSettings()

Bool UpdateRenderSettings ( RenderData rdat,
Bool  bKeepVP = false 
)

Updates the render settings with rdat.

Parameters
[in]rdatNew render settings. The caller owns the pointed render data.
[in]bKeepVPPass true to keep Video Post.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UpdateTime()

Bool UpdateTime ( BaseTime  time)

Updates the document to the given time.

Parameters
[in]timeNew time.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ UseTextureCache()

Bool UseTextureCache ( Bool  bKeepTextures)

Controls if the texture cache should be kept in memory or freed after rendering.

Parameters
[in]bKeepTexturesPass true to keep textures in memory after render is finished, false to free them.
Returns
true if successful, otherwise false.

◆ SendTexture()

Bool SendTexture ( const Filename filepath,
void *  mem,
Int64  len,
Bool  memoryOnly 
)

Transfers a texture from memory to the render server/session.

Parameters
[in]filepathTexture path (if only the name is passed the texture will be saved in the preferences folder under tex/).
[in]memPointer to the memory block containing the texture bitmap. Can contain any Cinema 4D readable image format.
[in]lenSize of the memory block.
[in]memoryOnlyIf true the texture will be saved to memory and not written to disk (requires Cinema 4D version >= 15.059).
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ SendTextureRaw()

Bool SendTextureRaw ( const Filename filepath,
void *  data,
const COLORMODE mode,
const Int64 width,
const Int64 height,
const Int64 rowBytes 
)

Transfers a texture from memory to the render server/session.

Parameters
[in]filepathTexture name - must be unique to this render session.
[in]dataPointer to the memory block containing the data.
[in]modeThe format of the data, must adhere to known C4D orders.
[in]widthThe width in pixels of the texture.
[in]heightThe height in pixels of the texture.
[in]rowBytesThe number of bytes per scanline
Note: It is not always the same as width*sizeof(PIXEL) in some applications.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ FlushTexture()

Bool FlushTexture ( const Filename filepath)

Frees a specific texture on render server/session and deletes the file on disk (requires Cinema 4D build >= #119398).

Parameters
[in]filepathTexture path (if only the name is passed the texture file will be searched in the preferences folder under tex/).
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ StartRender()

Bool StartRender ( Int32  xres,
Int32  yres,
ColorResolution  colorresolution,
Bool  allow_saving,
Bool  high_priority 
)

Starts rendering the open session.

Note
The call returns immediately. It does not wait until rendering is finished.
Parameters
[in]xresThe width of the rendered image in pixels.
[in]yresThe height of the rendered image in pixels.
[in]colorresolutionDetermine the color depth the image that will be streamed
Note: It is not enough for an image to be streamed as float data if the render settings are not adjusted to float resolution.
[in]allow_savingPass false to set RDATA_GLOBALSAVE to false before rendering.
[in]high_priorityPass true to start rendering with different priorities (low/high priority).
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ StopRender()

Bool StopRender ( )

Stops rendering of the open session.

Note
Does not free the session.
See also
FreeSession()
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetImageUpdate()

Bool GetImageUpdate ( UpdateImage  imgupdate,
void *  userdata,
Bool is_running 
)

Gets image updates.

Parameters
[in]imgupdateCallback for image updates.
[in]userdataUser data for imgupdate callback. Can be nullptr.
[out]is_runningAssigned the render running status. Can be nullptr if not needed.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetImageUpdateMP()

Bool GetImageUpdateMP ( Int32  vpbuffid,
Int32  vpbuffsubid,
UpdateImage  imgupdate,
void *  userdata,
Bool is_running 
)

Gets multipass image updates.

Parameters
[in]vpbuffidSelects the multipass image channel ID.
[in]vpbuffsubidSelects the multipass image channel sub ID.
[in]imgupdateCallback for image updates.
[in]userdataUser data for imgupdate callback. Can be nullptr.
[out]is_runningAssigned the render running status. Can be nullptr if not needed.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetFullImage()

Bool GetFullImage ( UpdateImage  imgupdate,
void *  userdata,
Bool is_running 
)

Gets full image updates.

Parameters
[in]imgupdateCallback to get the full image.
[in]userdataUser data for imgupdate callback. Can be nullptr.
[out]is_runningAssigned the render running status. Can be nullptr if not needed.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetFullImageMP()

Bool GetFullImageMP ( Int32  vpbuffid,
Int32  vpbuffsubid,
UpdateImage  imgupdate,
void *  userdata,
Bool is_running 
)

Gets full multipass image updates.

Parameters
[in]vpbuffidSelects the multipass image channel ID.
[in]vpbuffsubidSelects the multipass image channel sub ID.
[in]imgupdateCallback to get the full image.
[in]userdataUser data for imgupdate callback. Can be nullptr.
[out]is_runningAssigned the render running status. Can be nullptr if not needed.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetAllTextures()

Bool GetAllTextures ( BaseContainer bc)

Gets all the textures used in render.

Parameters
[out]bcFilled with all textures filenames. The caller owns the pointed container.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetAllAssets()

Bool GetAllAssets ( BaseContainer bc)

Gets all the assets used in render.

Parameters
[in]bcFilled with all assets. The caller owns the pointed container.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ ExportScene()

Bool ExportScene ( const Filename filepath,
FILEFORMAT  format 
)

Exports the scene into filepath in the given format.

Parameters
[in]filepathThe path to the file to export.
[in]formatThe file format.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ FreeSession()

Bool FreeSession ( )

Frees the session (scene, image etc.).

Note
The session is still open afterwards.
As old scenes are automatically freed when new ones are uploaded this is mostly used to quit the external application, but keep the render server open.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ ResetRenderServer()

Bool ResetRenderServer ( )

Frees all sessions (all scenes, images, textures in memory etc., requires Cinema4D version >= 15.059).

Note
All sessions are still open afterwards.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetC4dVersion()

Bool GetC4dVersion ( Int32 version)

Gets the running Cinema 4D version of the render server.

Parameters
[in]versionAssigned the running Cinema 4D version of the render server (for older servers where the command isn't supported this will be set to 1).
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetC4dVersionType()

Bool GetC4dVersionType ( VERSIONTYPE type)

Gets the running Cinema 4D version type of the render server.

Parameters
[in]typeAssigned the running Cinema 4D version type of the render server (for older servers where the command isn't supported this will be set to VERSIONTYPE_UNKNOWN).
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetPreferencePath()

Bool GetPreferencePath ( String prefsPath)

Gets the path to the preference folder of the render server.

Parameters
[out]prefsPathAssigned the preference path as String.
Note: The string will be empty if the server version is too old and doesn't support the call.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetRenderStatus()

Bool GetRenderStatus ( Bool is_running,
Int32 rendererror,
Float progress_percent,
Int32 progress_type 
)

Checks if the renderer is running.

Note
Any of the passed parameter can be set to nullptr if its information is not needed.
Parameters
[out]is_runningAssigned the render running status.
[out]rendererrorAssigned a render error code: RENDERERROR.
[out]progress_percentAssigned the render progress in percentage.
[out]progress_typeAssigned the render progress type: PROGRESSTYPE.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ GetRenderErrorString()

Bool GetRenderErrorString ( String errorText)

Gets additional error information after an error has occurred.

Note
The returned String might be empty if no additional data is available, if connected to a legacy server which doesn't support the call or if there was no error at all.
Parameters
[out]errorTextAssigned the render error text as String. Depends on the error which has occurred before.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ IsSceneAlive()

Bool IsSceneAlive ( Bool is_alive)

Checks if a scene file was already sent to the render server.

Parameters
[in]is_aliveAssigned true only if a scene was already transfered.
Returns
true if successful, otherwise false.
If false, connection to the server will be closed automatically.

◆ ConvertParameters()

BaseList2D* ConvertParameters ( BaseList2D node,
CINEMA4D_VERSION  version 
)

Converts legacy parameters of a node into actual parameters of the running Cinema 4D version.

Parameters
[in]nodeThe node containing the legacy parameter. Types of BaseObject, BaseMaterial, BaseTag and RenderData are supported.
[in]versionThe C4D version the parameter data was valid for.
Returns
A new node with converted parameters. If an error occurs nullptr is returned, connection to the server will NOT be closed automatically.

◆ BuildDescription()

Bool BuildDescription ( Int32  pluginId,
BaseContainer bc 
)

Returns the description data of the node related to the running Cinema 4D version.

Parameters
[in]pluginIdThe plugin ID of the node.
[out]bcThe existing BaseContainer which will be filled with the parameter of the description.
Returns
true if successful, otherwise false.
If false, connection to the server will NOT be closed automatically.

◆ RenderMaterials()

BaseDocument* RenderMaterials ( BaseDocument doc)

Renders the materials previews of all included materials.

Since
R20
Parameters
[in]docThe document containing the materials.
Returns
A new document including the materials with updated previews. The document must be freed by the caller.

◆ UpdateLayer()

Bool UpdateLayer ( BaseArray< GeMarker > &  layerMarkers,
Bool  enableDefaultLayer 
)

Private.

◆ UpdateLayerEx()

Bool UpdateLayerEx ( Int32 array,
Int32  count,
Bool  enableDefaultLayer 
)

Private.

◆ SetCurrentTake()

Bool SetCurrentTake ( const GeMarker takeMarker)

Private.

◆ GetInfo()

Bool GetInfo ( Int32  pluginID,
Int32 info 
)

Private.