SOCALLBACKACTION(3iv)

πŸ’– SoCallbackAction β€” the SoCallbackAction(3IV) era πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about the action that just... walks the whole scene graph and lets you vibe-check every node on the way. no cap. πŸ¦‹


✨ NAME ✨

SoCallbackAction β€” performs a generic traversal of the scene graph. literally that's her whole job and she ATE. πŸ’…


🌸 INHERITS FROM 🌸

SoAction > SoCallbackAction

so she's an SoAction girlie at heart, she just has extra tricks. iykyk. ✨


πŸŽ€ SYNOPSIS πŸŽ€

first things first, the include, because obviously:

#include <Inventor/actions/SoCallbackAction.h>

now the callback typedefs β€” these are the lil function shapes you gotta match when you register your own callbacks. copy them EXACTLY, do not freestyle, i'm begging:

typedef void        SoTriangleCB(void *userData,
                          SoCallbackAction *action,
                          const SoPrimitiveVertex *v1,
                          const SoPrimitiveVertex *v2,
                          const SoPrimitiveVertex *v3)
typedef void        SoLineSegmentCB(void *userData,
                          SoCallbackAction *action,
                          const SoPrimitiveVertex *v1,
                          const SoPrimitiveVertex *v2)
typedef void        SoPointCB(void *userData,
                          SoCallbackAction *action,
                          const SoPrimitiveVertex *v)
typedef SoCallbackAction::Response
                    SoCallbackActionCB(void *userData,
                          SoCallbackAction *action,
                          const SoNode *node)

and here's the Response enum β€” this is what you return to tell the traversal what to do next. choose wisely bestie, this is main character energy right here:

enum Response {
     SoCallbackAction::CONTINUE  Continue traversal as if nothing happened
     SoCallbackAction::ABORT     Abort traversal
     SoCallbackAction::PRUNE     Do not traverse node's children, but
                                      continue traversal
}

so like β€” CONTINUE is "keep going girl", ABORT is "we're DONE here", and PRUNE is "skip the kids but keep the party moving". iconic trio honestly. 🌈


🫢 Methods from class SoCallbackAction:

every single one of them, in order, no skipping, because we do not gatekeep:

                            SoCallbackAction()
void                        addPreCallback(SoType type, SoCallbackActionCB
                                 *cb, void *data)
void                        addPostCallback(SoType type,
                                 SoCallbackActionCB *cb, void *data)
void                        addPreTailCallback(SoCallbackActionCB *cb,
                                 void *data)
void                        addPostTailCallback(SoCallbackActionCB *cb,
                                 void *data)
void                        addTriangleCallback(SoType type, SoTriangleCB
                                 *cb, void *data)
void                        addLineSegmentCallback(SoType type,
                                 SoLineSegmentCB *cb, void *data)
void                        addPointCallback(SoType type, SoPointCB *cb,
                                 void *data)
float                       getComplexity() const
SoComplexity::Type          getComplexityType() const
int32_t                     getNumCoordinates() const
const SbVec3f &             getCoordinate3(int index) const
const SbVec4f &             getCoordinate4(int index) const
SoDrawStyle::Style          getDrawStyle() const
unsigned short              getLinePattern() const
float                       getLineWidth() const
float                       getPointSize() const
const SbName &              getFontName() const
float                       getFontSize() const
SoLightModel::Model         getLightModel() const
const SbVec3f &             getLightAttenuation() const
void                        getMaterial(SbColor &ambient, SbColor
                                 &diffuse, SbColor &specular, SbColor
                                 &emission, float &shininess, float
                                 &transparency, int mtlIndex = 0) const
SoMaterialBinding::Binding  getMaterialBinding() const
long                        getNumNormals() const
const SbVec3f &             getNormal(int index) const
SoNormalBinding::Binding    getNormalBinding() const
int32_t                     getNumProfileCoordinates() const
const SbVec2f &             getProfileCoordinate2(int index) const
const SbVec3f &             getProfileCoordinate3(int index) const
const SoNodeList &          getProfile() const
SoShapeHints::VertexOrdering
                            getVertexOrdering() const
SoShapeHints::ShapeType     getShapeType() const
SoShapeHints::FaceType      getFaceType() const
float                       getCreaseAngle() const
int32_t                     getNumTextureCoordinates() const
const SbVec2f &             getTextureCoordinate2(int index) const
const SbVec4f &             getTextureCoordinate4(int index) const
SoTextureCoordinateBinding::Binding
                            getTextureCoordinateBinding() const
const SbColor &             getTextureBlendColor() const
const unsigned char *       getTextureImage(SbVec2s &size, int &numComps)
                                 const
const SbMatrix &            getTextureMatrix() const
SoTexture2::Model           getTextureModel() const
SoTexture2::Wrap            getTextureWrapS() const
SoTexture2::Wrap            getTextureWrapT() const
const SbMatrix &            getModelMatrix() const
SoUnits::Units              getUnits() const
float                       getFocalDistance() const
const SbMatrix &            getProjectionMatrix() const
const SbMatrix &            getViewingMatrix() const
const SbViewVolume &        getViewVolume() const
SoPickStyle::Style          getPickStyle() const
int32_t                     getSwitch() const

look at all those getters, she's got range fr fr πŸ’œ


🧚 Methods from class SoAction:

the inherited ones, still here, still slaying:

virtual void        apply(SoNode *node)
virtual void        apply(SoPath *path)
virtual void        apply(const SoPathList &pathList, SbBool obeysRules =
                         FALSE)
static SoType       getClassTypeId()
virtual SoType      getTypeId()
virtual SbBool      isOfType(SoType type)
virtual void        invalidateState()

🌟 DESCRIPTION 🌟

okay so here's the whole tea. β˜•

this action defines a generic traversal of the scene graph. the user can specify callback functions for node types or paths β€” and when those node types or paths get encountered during the traversal, your callback function gets called. that's it, that's the mechanic. it's giving personal tour guide for your scene graph. 🫢

on top of that, you can also register callback functions for primitives generated by shapes in the scene graph. most shape types can generate primitives that represent or approximate their geometries:

  • triangle primitives are used for all surfaces β€” think cubes, face sets, or 3D text. πŸ”Ί
  • line segment primitives are used for line shapes. πŸ“
  • point primitives are used for point shapes. ⚬
note bestie: the type of primitives generated for a shape is the same, regardless of drawing style or other properties. don't come for me, that's just how she works. πŸ’€

and then β€” the important part, the part that'll save you a debugging meltdown β€”

most of the methods on this class access information from the traversal state. so they should be called only by callback functions that are invoked during traversal, so there's a valid state to work with.

🚨 like, seriously. call a get* method outside of a callback mid-traversal and you're working with a state that isn't valid. no state, no data, no slay. she will simply not have it. 😭

okay that's part one bestie β€” there's more coming, don't go anywhere πŸ’–

✨ METHODS ✨

okay bestie, deep breath πŸ’– this is the part where you actually do stuff with your SoCallbackAction. It's giving "toolkit era" and I'm obsessed. Every method, every signature, every little default β€” all here, no skips, periodt. πŸ‘‘

  • SoCallbackAction() β€” the constructor. That's the origin story, the main character entrance, the "hello world" but make it iconic. ✨
  • void addPreCallback(SoType type, SoCallbackActionCB *cb, void *data) and void addPostCallback(SoType type, SoCallbackActionCB *cb, void *data) β€” these add a callback function to call when a node of the given type is encountered during traversal. The PreCallback is called just before the node is traversed, and the PostCallback is called just after. The value returned by a callback function indicates whether the action should continue with the traversal. 🫢
  • void addPreTailCallback(SoCallbackActionCB *cb, void *data) and void addPostTailCallback(SoCallbackActionCB *cb, void *data) β€” these can be used to set up callback functions to call when the action is applied to a path. The functions are called just before or after the node at the tail of the path is traversed. πŸ¦‹
  • void addTriangleCallback(SoType type, SoTriangleCB *cb, void *data), void addLineSegmentCallback(SoType type, SoLineSegmentCB *cb, void *data), and void addPointCallback(SoType type, SoPointCB *cb, void *data) β€” routines to add callbacks for generated primitives (triangles, line segments, and points) for all shapes of the given type. The callback function will be called for each primitive generated for all shapes of or derived from that type. πŸ”₯
  • float getComplexity() const and SoComplexity::Type getComplexityType() const β€” returns complexity information from the state. Lowkey the vibe check of your scene. πŸ’…
  • int32_t getNumCoordinates() const, const SbVec3f & getCoordinate3(int index) const, and const SbVec4f & getCoordinate4(int index) const β€” returns the current coordinates from the state.
  • SoDrawStyle::Style getDrawStyle() const, unsigned short getLinePattern() const, float getLineWidth() const, and float getPointSize() const β€” returns the current drawing style information from the state.
  • const SbName & getFontName() const and float getFontSize() const β€” returns the current font information from the state. Aesthetic matters, bestie. πŸŽ€
  • SoLightModel::Model getLightModel() const and const SbVec3f & getLightAttenuation() const β€” returns the current lighting model information from the state.
  • void getMaterial(SbColor &ambient, SbColor &diffuse, SbColor &specular, SbColor &emission, float &shininess, float &transparency, int mtlIndex = 0) const and SoMaterialBinding::Binding getMaterialBinding() const β€” returns the current material information from the state. Providing a mtlIndex will return the material defined for that index. πŸ‘‘
  • long getNumNormals() const, const SbVec3f & getNormal(int index) const, and SoNormalBinding::Binding getNormalBinding() const β€” returns the current normal information from the state.
  • int32_t getNumProfileCoordinates() const, const SbVec2f & getProfileCoordinate2(int index) const, const SbVec3f & getProfileCoordinate3(int index) const, and const SoNodeList & getProfile() const β€” returns the current profiles and their coordinates from the state.
  • SoShapeHints::VertexOrdering getVertexOrdering() const, SoShapeHints::ShapeType getShapeType() const, SoShapeHints::FaceType getFaceType() const, and float getCreaseAngle() const β€” returns the current shape hints from the state.
  • int32_t getNumTextureCoordinates() const, const SbVec2f & getTextureCoordinate2(int index) const, const SbVec4f & getTextureCoordinate4(int index) const, SoTextureCoordinateBinding::Binding getTextureCoordinateBinding() const, const SbColor & getTextureBlendColor() const, and const unsigned char * getTextureImage(SbVec2s &size, int &numComps) const β€” returns texture information from the state. getNumTextureCoordinates() returns 0 if texture coordinates are generated by a function. getTextureImage() returns NULL if no texture is enabled. 🌸
  • const SbMatrix & getTextureMatrix() const, SoTexture2::Model getTextureModel() const, SoTexture2::Wrap getTextureWrapS() const, and SoTexture2::Wrap getTextureWrapT() const β€” returns the current texture mapping information from the state.
  • const SbMatrix & getModelMatrix() const and SoUnits::Units getUnits() const β€” returns the current modeling transformation and the current units from the state.
  • float getFocalDistance() const, const SbMatrix & getProjectionMatrix() const, const SbMatrix & getViewingMatrix() const, and const SbViewVolume & getViewVolume() const β€” returns the current camera and viewing information from the state. πŸ“Έ
  • SoPickStyle::Style getPickStyle() const β€” returns the current picking style.
  • int32_t getSwitch() const β€” returns the current switch value.

πŸ‘€ SEE ALSO πŸ‘€

go touch some other manpages, bestie, they're all linked in the group chat:

  • SoCallback
  • SoEventCallback
  • SoShape

and that's the whole page, no cap. this iconic little doc is stamped SoCallbackAction(3IV)() β€” that's the source/version/date footer energy, and yes it ate. periodt. πŸ’–βœ¨