Difference between revisions of "Item orb"
Line 311: | Line 311: | ||
LXtTableauBox bbox) | LXtTableauBox bbox) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 324: | Line 318: | ||
LXtID4 type) | LXtID4 type) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 333: | Line 327: | ||
const char **name) | const char **name) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 360: | Line 334: | ||
ILxUnknownID vdesc) | ILxUnknownID vdesc) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 382: | Line 343: | ||
ILxUnknownID trisoup) | ILxUnknownID trisoup) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 485: | Line 353: | ||
ILxUnknownID super) | ILxUnknownID super) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 496: | Line 359: | ||
COrbInstance::pins_Cleanup (void) | COrbInstance::pins_Cleanup (void) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 504: | Line 367: | ||
unsigned len) | unsigned len) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 517: | Line 373: | ||
COrbInstance::pins_DupType (void) | COrbInstance::pins_DupType (void) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 524: | Line 380: | ||
ILxUnknownID item) | ILxUnknownID item) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 530: | Line 386: | ||
COrbInstance::pins_Newborn (ILxUnknownID original) | COrbInstance::pins_Newborn (ILxUnknownID original) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 536: | Line 392: | ||
COrbInstance::pins_Loading (void) | COrbInstance::pins_Loading (void) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 542: | Line 398: | ||
COrbInstance::pins_AfterLoad (void) | COrbInstance::pins_AfterLoad (void) | ||
{ | { | ||
− | + | ... | |
} | } | ||
Line 557: | Line 413: | ||
const char **tag) | const char **tag) | ||
{ | { | ||
− | + | ... | |
− | + | ||
} | } | ||
Line 567: | Line 422: | ||
ILxUnknownID tblx) | ILxUnknownID tblx) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 631: | Line 430: | ||
int *update) | int *update) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 651: | Line 442: | ||
LXtVector itemColor) | LXtVector itemColor) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 753: | Line 449: | ||
int *count) | int *count) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
} | } | ||
Line 767: | Line 461: | ||
LXtVector offset) | LXtVector offset) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 791: | Line 469: | ||
int *chanIndex) | int *chanIndex) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 807: | Line 478: | ||
LXtVector position) | LXtVector position) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 825: | Line 487: | ||
double *chanValue) | double *chanValue) | ||
{ | { | ||
− | + | ... | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } |
Revision as of 23:41, 11 September 2013
Item_orb.cpp is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.
Item_orb.cpp is a plugin that adds the orb item to modo's toolkit.
Orb Item pictured above
Contents
Code Walkthrough
Class Declarations
We want this class to be able to write out to the log, so we inherit from CLxLuxologyLogMessage.
class COrbLog : public CLxLuxologyLogMessage { public: COrbLog () : CLxLuxologyLogMessage ("orb-item") { } const char * GetFormat () { return "Orb Object"; } };
This is a gear part that will be used in rendering.
class COrbPart { public: /* * Tableau Surface implementation. */ LxResult Bound (LXtTableauBox bbox); unsigned FeatureCount (LXtID4 type); LxResult FeatureByIndex ( LXtID4 type, unsigned int index, const char **name); LxResult SetVertex (ILxUnknownID vdesc); LxResult Sample ( const LXtTableauBox bbox, float scale, ILxUnknownID trisoup); /* * Part configuration. */ void SetPart (unsigned part); /* * Part. See the GearPart enum. */ unsigned m_part; unsigned hasUVs; CLxUser_TableauVertex vrt_desc; /* * Indices for vertex feature subscripts. */ enum { FEATURE_POSITION, FEATURE_OBJECT_POSITION, FEATURE_NORMAL, FEATURE_VELOCITY, BASE_FEATURE_COUNT }; enum { FEATURE_UV = BASE_FEATURE_COUNT, FEATURE_DPDU, TOTAL_FEATURE_COUNT }; int f_pos[TOTAL_FEATURE_COUNT]; LxResult InitializePart ( CLxUser_Item &m_item, CLxUser_ChannelRead &chanRead); LxResult InitializePart ( double coverage, double radius); /* * Construction channels. */ double latitude_coverage; double longitude_coverage; float m_radius; private: LxResult SampleOrbPartShell ( CLxUser_TriangleSoup &soup, unsigned &segmentID); LxResult SampleOrbPartCore ( CLxUser_TriangleSoup &soup, unsigned &segmentID); };
In order to display the part in the viewport, we inherit from CLxImpl_TableauSurface and CLxTableauInstance. We also need to inherit from COrbPart, as that is where the actual gear part is created.
class COrbElement : public CLxImpl_TableauSurface, public CLxImpl_TableauInstance, public COrbPart { COrbLog orb_log; public: CLxUser_TableauVertex vrt_desc; float m_radius; int m_resolution; int f_pos[4]; LXtVector m_offset; LXtMatrix m_xfrm; LxResult tsrf_Bound (LXtTableauBox bbox) LXx_OVERRIDE; unsigned tsrf_FeatureCount (LXtID4 type) LXx_OVERRIDE; LxResult tsrf_FeatureByIndex ( LXtID4 type, unsigned int index, const char **name) LXx_OVERRIDE; LxResult tsrf_SetVertex (ILxUnknownID vdesc) LXx_OVERRIDE; LxResult tsrf_Sample ( const LXtTableauBox bbox, float scale, ILxUnknownID trisoup) LXx_OVERRIDE; LxResult tins_Properties ( ILxUnknownID vecstack) LXx_OVERRIDE; LxResult tins_GetTransform ( unsigned endPoint, LXtVector offset, LXtMatrix xfrm) LXx_OVERRIDE; };
In order to create the item's surface, we need to inherit from CLxImpl_Surface. Among other things, this will perform binning, or the grouping of the primitives that make up the item's surface.
class COrbItemSurface : public CLxImpl_Surface { /* * The parts of the gear (side and endcaps) */ COrbPackage *src_pkg; public: LxResult surf_GetBBox (LXtBBox *bbox) LXx_OVERRIDE; LxResult surf_FrontBBox ( const LXtVector pos, const LXtVector dir, LXtBBox *bbox) LXx_OVERRIDE; LxResult surf_RayCast ( const LXtRayInfo *ray, LXtRayHit *hit) LXx_OVERRIDE; LxResult surf_BinCount (unsigned int *count) LXx_OVERRIDE; LxResult surf_BinByIndex ( unsigned int index, void **ppvObj) LXx_OVERRIDE; LxResult surf_TagCount ( LXtID4 type, unsigned int *count) LXx_OVERRIDE; LxResult surf_TagByIndex ( LXtID4 type, unsigned int index, const char **stag) LXx_OVERRIDE; LxResult Initialize ( COrbPackage *pkg, CLxUser_Item &m_item, CLxUser_ChannelRead &chanRead); LxResult Initialize ( COrbPackage *pkg, double radius); };
We want this class to create an instance of the orb. In order to do that, we will need to implement the related package, so we inherit from CLxImpl_PackageInstance. Additionally, we will want to set the tags of the instance, so we inherit from CLxImpl_PackageInstance. Finally, we want to display the object in the viewport, so we inherit from CLxImpl_ViewItem3D, which has basic 3D display methods, and CLxImpl_TableauSource, which makes it so that channels update the preview.
class COrbInstance : public CLxImpl_PackageInstance, public CLxImpl_StringTag, public CLxImpl_TableauSource, public CLxImpl_ViewItem3D { COrbLog orb_log; public: COrbPackage *src_pkg; CLxUser_Item m_item; ILxUnknownID inst_ifc; LxResult pins_Initialize ( ILxUnknownID item, ILxUnknownID super) LXx_OVERRIDE; void pins_Cleanup (void) LXx_OVERRIDE; LxResult pins_SynthName (char *buf, unsigned len) LXx_OVERRIDE; unsigned pins_DupType (void) LXx_OVERRIDE; LxResult pins_TestParent (ILxUnknownID item) LXx_OVERRIDE; LxResult pins_Newborn (ILxUnknownID original) LXx_OVERRIDE; LxResult pins_Loading (void) LXx_OVERRIDE; LxResult pins_AfterLoad (void) LXx_OVERRIDE; void pins_Doomed (void) LXx_OVERRIDE; LxResult stag_Get (LXtID4 type, const char **tag) LXx_OVERRIDE; LxResult tsrc_Elements (ILxUnknownID tblx) LXx_OVERRIDE; LxResult tsrc_PreviewUpdate ( int chanIndex, int *update) LXx_OVERRIDE; LxResult vitm_Draw ( ILxUnknownID itemChanRead, ILxUnknownID viewStrokeDraw, int selectionFlags, LXtVector itemColor) LXx_OVERRIDE; LxResult vitm_HandleCount ( int *count) LXx_OVERRIDE; LxResult vitm_HandleMotion ( int handleIndex, int *motionType, double *min, double *max, LXtVector plane, LXtVector offset) LXx_OVERRIDE; LxResult vitm_HandleChannel ( int handleIndex, int *chanIndex) LXx_OVERRIDE; LxResult vitm_HandleValueToPosition ( int handleIndex, double *chanValue, LXtVector position) LXx_OVERRIDE; LxResult vitm_HandlePositionToValue ( int handleIndex, LXtVector position, double *chanValue) LXx_OVERRIDE; };
We want to create a package for the orb item, so we have our class inherit from ClxImplPackage. Additionally, we want to have this class listen for global selection events, so we inherit from CLxImpl_SelectionListener.
class COrbPackage : public CLxImpl_Package, public CLxImpl_SelectionListener { public: static LXtTagInfoDesc descInfo[]; CLxPolymorph<COrbInstance> orb_factory; CLxPolymorph<COrbElement> elt_factory; COrbPackage (); LxResult pkg_SetupChannels ( ILxUnknownID addChan) LXx_OVERRIDE; LxResult pkg_TestInterface (const LXtGUID *guid) LXx_OVERRIDE; LxResult pkg_Attach (void **ppvObj) LXx_OVERRIDE; void selevent_Add ( LXtID4 type, unsigned int subtType) LXx_OVERRIDE; void selevent_Current (LXtID4 type) LXx_OVERRIDE; };
Server Tags
These tags indicate that the class COrbPackage is a subtype of the super type locator and has the internal name of test-orb.
LXtTagInfoDesc COrbPackage::descInfo[] = { { LXsPKG_SUPERTYPE, "locator" }, { LXsPKG_IS_MASK, "." }, { LXsSRV_LOGSUBSYSTEM, "test-orb" }, { 0 } };
Initialize
This method indicates that we will be exporting one server that will be dependent on the COrbPackage class. All of the interfaces of the classes that it inherited will also be added and the server will have the name of test.orb.
void initialize () { CLxGenericPolymorph *srv; srv = new CLxPolymorph<COrbPackage>; srv->AddInterface (new CLxIfc_Package <COrbPackage>); srv->AddInterface (new CLxIfc_StaticDesc <COrbPackage>); srv->AddInterface (new CLxIfc_SelectionListener<COrbPackage>); thisModule.AddServer ("test.orb", srv); }
Implementations
These functions create a tableau surface element that lives in the tableau and generates geometry for the renderer. It has a bounding box, vertex features, and a sample method.
LxResult COrbElement::tsrf_Bound ( LXtTableauBox bbox) { ... } unsigned COrbElement::tsrf_FeatureCount ( LXtID4 type) { ... } LxResult COrbElement::tsrf_FeatureByIndex ( LXtID4 type, unsigned index, const char **name) { ... } LxResult COrbElement::tsrf_SetVertex ( ILxUnknownID vdesc) { ... } LxResult COrbElement::tsrf_Sample ( const LXtTableauBox bbox, float scale, ILxUnknownID trisoup) { ... }
The instance is the implementation of the item, and there will be one allocated for each item in the scene. The functions here all perform a function(generally made evident by their name) for the instance.
LxResult COrbInstance::pins_Initialize ( ILxUnknownID item, ILxUnknownID super) { ... } void COrbInstance::pins_Cleanup (void) { ... } LxResult COrbInstance::pins_SynthName ( char *buf, unsigned len) { ... } unsigned COrbInstance::pins_DupType (void) { ... } LxResult COrbInstance::pins_TestParent ( ILxUnknownID item) { ... } LxResult COrbInstance::pins_Newborn (ILxUnknownID original) { ... } LxResult COrbInstance::pins_Loading (void) { ... } LxResult COrbInstance::pins_AfterLoad (void) { ... } void COrbInstance::pins_Doomed (void) { }
The instance also presents a StringTag interface so it can pretend to have part and material tags for finding a shader.
LxResult COrbInstance::stag_Get ( LXtID4 type, const char **tag) { ... }
The instance's TableauSource interface allows it to place elements into the tableau, in this case our orb element.
LxResult COrbInstance::tsrc_Elements ( ILxUnknownID tblx) { ... } LxResult COrbInstance::tsrc_PreviewUpdate ( int chanIndex, int *update) { ... }
Based on the channel values, draw the abstract item representation using the stroke drawing interface.
LxResult COrbInstance::vitm_Draw ( ILxUnknownID itemChanRead, ILxUnknownID viewStrokeDraw, int selectionFlags, LXtVector itemColor) { ... } LxResult COrbInstance::vitm_HandleCount ( int *count) { ... } LxResult COrbInstance::vitm_HandleMotion ( int handleIndex, int *motionType, double *min, double *max, LXtVector plane, LXtVector offset) { ... } LxResult COrbInstance::vitm_HandleChannel ( int handleIndex, int *chanIndex) { ... } LxResult COrbInstance::vitm_HandleValueToPosition ( int handleIndex, double *chanValue, LXtVector position) { ... } LxResult COrbInstance::vitm_HandlePositionToValue ( int handleIndex, LXtVector position, double *chanValue) { ... }