TranslationMaps Class Reference

#include <lib_modeling.h>

Detailed Description

With previous versions of Cinema 4D it was a hard to update plugin tags after modeling operations. They all had to be done manually per tool (at least in theory, not many plugins bothered!).

A solution to this problem are the tag translation messages. During Modeling::Commit() there are two points at which translations of tags can be done:

  • PRETRANSLATE: This is done before any changes to the object happen. It can be useful to use the old tag/polygon data to translate or to store this info for the translate;
    e.g. edge selections and UVs both need to store old tag data and polygon data ready for the translation after the object is changed.
  • TRANSLATE: This is done after the object is changed.
Note
If Modeling::Commit() fails then TRANSLATE is called with nullptr so that any data stored from PRETRANSLATE can be released.

The TranslationMaps pointer is passed for the translation message data.
A simple example is the vertex map tag. Points are the easiest to translate. Polygons are pretty much the same too. Edges are much harder since they do not have any representation.
In the modeling library they are handled by storing (in PRETRANSLATE) information about the points/polygons that form the edges and use this in TRANSLATE to match up any edge changes.

{
switch (type)
{
...
RemapVertexMap((Float*)t_data,(TranslationMaps*)data);
break;
}
return SUPER::Message(type,data);
}
static void RemapVertexMap(Float *vmap, TranslationMaps *map)
{
if (map && map->m_pPointMap && map->m_nPointCount && vmap)
{
// Processed any interpolated points
for (i=0;i<map->m_mPointCount;i++)
{
if (!(map->m_pPointMap[i].lFlags & TRANSMAP_PNTFLAG_INTER)) continue;
vmap[map->m_pPointMap[i].nIndex]=Mix(vmap[ipnt->p1],vmap[ipnt->p2],ipnt->t);
}
// Merge any welds
for (i=0;i<map->m_mWeldCount;)
{
l=map->m_pWeldMap[i].nIndex; s=0;
Float sum=0.0;
while (i<map->m_mWeldCount && map->m_pWeldMap[i].nIndex==l)
{
if (map->m_pWeldMap[i].oIndex>=0)
{
sum+=vmap[map->m_pWeldMap[i].oIndex];
s++;
}
i++;
}
if (s>0) sum=sum/Float(s);
vmap[l]=sum;
}
// Remap any changes
for (i=0;i<map->m_mPointCount;i++)
{
vmap[map->m_pPointMap[i].nIndex]=0.0;
else if (map->m_pPointMap[i].nIndex!=map->m_pPointMap[i].oIndex)
vmap[map->m_pPointMap[i].nIndex]=vmap[map->m_pPointMap[i].oIndex];
}
}
}
Py_ssize_t i
Definition: abstract.h:645
PyObject PyObject const char const char char ** s
Definition: bytesobject.h:60
Bool Message(Int32 type, void *data=nullptr)
Definition: c4d_baselist.h:1457
Definition: lib_modeling.h:214
Int32 m_mPointCount
Map point count.
Definition: lib_modeling.h:304
TransIndexMapData * m_pWeldMap
Weld index translation map.
Definition: lib_modeling.h:317
TransMapData * m_pPointMap
Point translation map.
Definition: lib_modeling.h:312
Int32 m_mWeldCount
Map weld count.
Definition: lib_modeling.h:309
TransPointInterData * m_pInterpolatedPoints
Interpolation map.
Definition: lib_modeling.h:325
Int32 m_nPointCount
New point count.
Definition: lib_modeling.h:299
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int32 Int32
Definition: ge_sys_math.h:60
maxon::Float Float
Definition: ge_sys_math.h:66
#define MSG_TRANSLATE_POINTS
Sent by the modeling core to let tags etc. update after point changes. The corresponding data is Tran...
Definition: c4d_baselist.h:550
#define TRANSMAP_FLAG_NEW
New.
Definition: lib_modeling.h:45
#define TRANSMAP_FLAG_DELETED
Deleted.
Definition: lib_modeling.h:48
#define TRANSMAP_PNTFLAG_INTER
Interpolated.
Definition: lib_modeling.h:55
PyObject ** type
Definition: pycore_pyerrors.h:34
PyObject PyObject int PyObject PyObject * l
Definition: pythonrun.h:156
Int32 oIndex
Old index.
Definition: lib_modeling.h:82
Int32 nIndex
New index.
Definition: lib_modeling.h:83
Int32 lFlags
Definition: lib_modeling.h:101
Int32 mIndex
Mapped index.
Definition: lib_modeling.h:104
Definition: lib_modeling.h:120
Int32 p1
First point.
Definition: lib_modeling.h:121
Float t
Interpolation parameter.
Definition: lib_modeling.h:123
Int32 p2
Second point.
Definition: lib_modeling.h:122

Public Member Functions

 TranslationMaps ()
 
Int32 FindOriginalPoint (Int32 index)
 
Int32 FindOriginalPolygon (Int32 index)
 
Int32 FindOriginalPgon (Int32 index)
 
Int32 FindOriginalSegment (Int32 index)
 
Int32 FindNewPoint (Int32 index)
 
Int32 FindNewPolygon (Int32 index)
 
Int32 FindNewPgon (Int32 index)
 
Int32 FindNewSegment (Int32 index)
 
Int32 FindWeldPoint (Int32 index)
 
Int32 FindMeltPolygon (Int32 index)
 

Public Attributes

Int32 m_oPointCount
 
Int32 m_oPolygonCount
 
Int32 m_oPgonCount
 
Int32 m_oSegmentCount
 
Int32 m_nPointCount
 
Int32 m_nPolygonCount
 
Int32 m_nPgonCount
 
Int32 m_nSegmentCount
 
Int32 m_mPointCount
 
Int32 m_mPolygonCount
 
Int32 m_mPgonCount
 
Int32 m_mSegmentCount
 
Int32 m_mWeldCount
 
Int32 m_mMeltCount
 
TransMapDatam_pPointMap
 
TransMapDatam_pPolygonMap
 
TransMapDatam_pPgonMap
 
TransMapDatam_pSegmentMap
 
TransIndexMapDatam_pWeldMap
 
TransIndexMapDatam_pMeltMap
 
TransMapNewDatam_pNewPointMap
 
TransMapNewDatam_pNewPolygonMap
 
TransMapNewDatam_pNewPgonMap
 
TransMapNewDatam_pNewSegmentMap
 
TransPointInterDatam_pInterpolatedPoints
 
TransPointDeltaDatam_pDeltaPoints
 

Constructor & Destructor Documentation

◆ TranslationMaps()

Constructor.

Member Function Documentation

◆ FindOriginalPoint()

Int32 FindOriginalPoint ( Int32  index)

Searches for the original (i.e old) index based on the new index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe new index.
Returns
The old index.

◆ FindOriginalPolygon()

Int32 FindOriginalPolygon ( Int32  index)

Searches for the original (i.e old) index based on the new index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe new index.
Returns
The old index.

◆ FindOriginalPgon()

Int32 FindOriginalPgon ( Int32  index)

Searches for the original (i.e old) index based on the new index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe new index.
Returns
The old index.

◆ FindOriginalSegment()

Int32 FindOriginalSegment ( Int32  index)

Searches for the original (i.e old) index based on the new index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe new index.
Returns
The old index.

◆ FindNewPoint()

Int32 FindNewPoint ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

◆ FindNewPolygon()

Int32 FindNewPolygon ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

◆ FindNewPgon()

Int32 FindNewPgon ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

◆ FindNewSegment()

Int32 FindNewSegment ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

◆ FindWeldPoint()

Int32 FindWeldPoint ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

◆ FindMeltPolygon()

Int32 FindMeltPolygon ( Int32  index)

Searches for the new index based on the original index. (A pure helper. The source for this function is available in lib_modeling.cpp.)

Parameters
[in]indexThe old index.
Returns
The new index.

Member Data Documentation

◆ m_oPointCount

Int32 m_oPointCount

Original point count.

◆ m_oPolygonCount

Int32 m_oPolygonCount

Original polygon count.

◆ m_oPgonCount

Int32 m_oPgonCount

Original Pgon count.

◆ m_oSegmentCount

Int32 m_oSegmentCount

Original segment count.

◆ m_nPointCount

Int32 m_nPointCount

New point count.

◆ m_nPolygonCount

Int32 m_nPolygonCount

New polygon count.

◆ m_nPgonCount

Int32 m_nPgonCount

New Pgon count.

◆ m_nSegmentCount

Int32 m_nSegmentCount

New segment count.

◆ m_mPointCount

Int32 m_mPointCount

Map point count.

◆ m_mPolygonCount

Int32 m_mPolygonCount

Map polygon count.

◆ m_mPgonCount

Int32 m_mPgonCount

Map Pgon count.

◆ m_mSegmentCount

Int32 m_mSegmentCount

Map segment count.

◆ m_mWeldCount

Int32 m_mWeldCount

Map weld count.

◆ m_mMeltCount

Int32 m_mMeltCount

Map melt count.

◆ m_pPointMap

TransMapData* m_pPointMap

Point translation map.

◆ m_pPolygonMap

TransMapData* m_pPolygonMap

Polygon translation map.

◆ m_pPgonMap

TransMapData* m_pPgonMap

Pgon translation map.

◆ m_pSegmentMap

TransMapData* m_pSegmentMap

Segment translation map.

◆ m_pWeldMap

TransIndexMapData* m_pWeldMap

Weld index translation map.

◆ m_pMeltMap

TransIndexMapData* m_pMeltMap

Melt index translation map.

◆ m_pNewPointMap

TransMapNewData* m_pNewPointMap

New point translation map.

◆ m_pNewPolygonMap

TransMapNewData* m_pNewPolygonMap

New polygon translation map.

◆ m_pNewPgonMap

TransMapNewData* m_pNewPgonMap

New Pgon translation map.

◆ m_pNewSegmentMap

TransMapNewData* m_pNewSegmentMap

New segment translation map.

◆ m_pInterpolatedPoints

TransPointInterData* m_pInterpolatedPoints

Interpolation map.

◆ m_pDeltaPoints

TransPointDeltaData* m_pDeltaPoints

Delta map.