IPainterInterface.h

Go to the documentation of this file.
00001 
00002 
00003 #pragma once
00004 
00005 #include "object.h"
00006 
00007 /********************************************************************************
00008 
00009   IPainterInterface contains all the interfaces to let a plugin interact with
00010   Maxs Paint system
00011 
00012   Basically the system consists of 2 components the IPainterInterface and IPainterCanvasInterface
00013 
00014   For a plugin to use the paint system it must sub class of IPainterCanvasInterface_V5 or greater 
00015   and implement the virtual methods and be a sub class of ReferenceTarget.  A canvas is what the 
00016   painterInterface paints on. Basically  IPainterCanvasInterface_V5 consists of functions to 
00017   identify the canvas version and functions that are called a as the system paints, basically a 
00018   start stroke, stroke and endstroke.
00019 
00020   The IPainterInterface is what does all the hit testing against the mesh using a quad tree.  
00021   Basically it tells the canvas what the stroke looks like.  In addition the canvas can use it
00022   do additional hit testing not associated with a stroke.
00023 
00024   In its simplest from all that needs to be done is
00025   
00026     1.  Subclass your plugin from IPainterCanvasInterface_V5 and ReferenceTarget
00027     2.  Fill out these virtual methods
00028 
00029         StartStroke() - called when a stroke is started
00030         PaintStroke()/PaintStroke(<..>) - called as a stroke is going on
00031         EndStroke() - called when the stroke ends and accepted.
00032         EndStroke(<...>) - called when the system is set to non interactive mode.
00033         CancelStroke() - called if a stroke is canceled.
00034         SystemEndPaintSession() - is called when the painter wants to end a paint session for some reason
00035         See the header for me description of the parameters
00036 
00037         You also need to add the painter interface to the GetInterface method from ReferenceTarget.  
00038         Something along the lines below.  This lets the painter set what interfaces the canvas supports.
00039             
00040               void* PainterTester::GetInterface(ULONG id)
00041                 {
00042                 switch(id)
00043                     {
00044                     case PAINTERCANVASINTERFACE_V5 : return (IPainterCanvasInterface_V5 *) this;
00045                         break;
00046                     default: return ReferenceTarget::GetInterface(id);
00047                     break;
00048                     }
00049                 }
00050 
00051 
00052 
00053     3.  In addition to implementing these methods, The plugin needs to hook up to 
00054         the painterInterface.  Using these functions.  The pointer to the painter 
00055         can be gotten by using the CreateInstance(REF_TARGET_CLASS_ID,PAINTERINTERFACE_CLASS_ID). 
00056         Once that pointer is gotten you need to grab a specific version of the painterInterface
00057         using GetPaintInterface.   See sample below
00058 
00059     
00060             ReferenceTarget *painterRef = (ReferenceTarge *) GetCOREInterface()->CreateInstance(REF_TARGET_CLASS_ID,PAINTERINTERFACE_CLASS_ID); 
00061 //set it to the correct verion
00062             if (painterRef)         
00063                 IPainterInterface_V5 *painter = (IPainterInterface_V5 *) painterRef->GetInterface(PAINTERINTERFACE_V5);
00064 
00065         Once you have a valid pointer you need to hook your self up to the Painter using the
00066         InitializeCallback method.  This is should be done just before you want to start a paint seesion.
00067         All you are doing is passing a pointer of yourself to the painter system so it knows where 
00068         to send the messages.  Note yourself to IPainterCanvasInterface since the Painter will 
00069         interogate you to find out which version of the canvas you are.
00070 
00071             painter->InitializeCallback((ReferenceTarget *) this);
00072 
00073         Once you have called InitializedCallback and are ready to start a paint session you need load up which 
00074         Nodes you want to paint on.  This is done with InitializeNodes(int flags, Tab<INode*> &nodeList).
00075 
00076                 painter->InitializeNodes(0, nodes);
00077 
00078         Then StartPaintSession() is called.  Once this is called everytime the the users drag paints across
00079         the nodes the Canvas's StartStroke/PaintStroke/EndStroke will get called.
00080         
00081                 painter->StartPaintSession();
00082 
00083         If the canvas changes the topology or geometry of the painted nodes UpdateMeshes() needs to be called
00084         so the quad tree gets updated.
00085 
00086                 painter->UpdateMeshes(BOOL updatePoitnCache);
00087 
00088         
00089         Once the canvas is done with the painter it needs to call EndPaintSession() so that all the data can
00090         be freed and it can be unhooked.  Otherwise the StartStroke/PaintStroke/EndStroke will still be called.
00091 
00092                 painter->EndPaintSession();
00093 
00094         You can also bring up the Painters Option dialog using the BringUpOptions().
00095 
00096                 painter->BringUpOptions() ;
00097 
00098         In addition there will be some helper functions for gathering points within a stroke and their weigths; and 
00099         tools for intersecting rays against the quad tree.  See the header for more descriptions.
00100 
00101 
00102         See the PaintTester project for a simple implementation of a canvas and interaction with the painter.
00103 
00104 
00105 
00106 *********************************************************************************/
00107 
00108 
00109 #include "maxheap.h"
00110 #include "iFnPub.h"
00111 #include "icurvctl.h"
00112 
00113 
00114 #define PAINTERINTERFACE_V5 0x78ffe181
00115 #define PAINTERINTERFACE_V7 0x78ffe182
00116 #define PAINTERINTERFACE_V14 0x78ffe183
00117 #define PAINTERCANVASINTERFACE_V5 0x29ff7ac9
00118 #define PAINTERCANVASINTERFACE_V5_1 0x29ff7ad0
00119 #define PAINTERCANVASINTERFACE_V7 0x1e962374
00120 
00121 #define PAINTERINTERFACE_CLASS_ID   Class_ID(0x2f2ef7e9, 0x78ffe181)
00122 #define PAINTERINTERFACE_SUPERCLASS_ID  REF_TARGET_CLASS_ID
00123 
00124 #define PAINTERINTERFACEV5_INTERFACE Interface_ID(0x53b4520c, 0x29ff7ac9)
00125 
00126 //These are defines used to when mirroring is enabled with point gathering
00127 //a point can be hit by the original brush, the mirror brushed, or both
00128 #define NO_MIRRROR      0
00129 #define MIRRRORED       1
00130 #define MIRRROR_SHARED  2
00131 
00132 
00137 #define         RINGCOLOR           0x445408e0
00138 #define         NORMALCOLOR         0x445408e1
00139 #define         RINGPRESSEDCOLOR    0x445408e2
00140 #define         NORMALPRESSEDCOLOR  0x445408e3
00141 #define         TRACECOLOR          0x445408e4
00142 #define         GIZMOCOLOR          0x445408e5
00143 
00144 
00149 #define PRESSURE_AFFECTS_NONE   0
00150 #define PRESSURE_AFFECTS_STR    1
00151 #define PRESSURE_AFFECTS_SIZE   2
00152 #define PRESSURE_AFFECTS_BOTH   3
00153 
00154 
00155 
00161 class IPainterInterface_V5: public MaxHeapOperators
00162     {
00163     public:
00164     
00165 //these are the esswential tools to get you started     
00166 //they cover the basics to get you started
00167 
00168 
00170 
00172         virtual BOOL  InitializeCallback(ReferenceTarget *canvas) = 0;//tested
00173 
00175 
00179         virtual BOOL  InitializeNodes(int flags, Tab<INode*> &nodeList) = 0;//tested
00180 
00182 
00191         virtual BOOL  UpdateMeshes(BOOL updatePointGather) = 0;
00192 
00194         virtual BOOL  StartPaintSession() = 0;//tested
00195 
00197         virtual BOOL  EndPaintSession() = 0;//tested
00198 
00199 
00201         virtual BOOL  InPaintMode()=0;//tested
00202 
00204         virtual BOOL  BringUpOptions() = 0;//tested
00205 
00207 
00209         virtual int *RetrieveTimeList(int &ct) = 0;
00210 
00211 //These functions are additional tools to further hit testing and point gathering
00212 //to help with finding points on a mesh that are within the stroke and theoir weights
00213 
00215 
00229         virtual BOOL TestHit(
00230                           IPoint2 mousePos,
00231                           Point3 &worldPoint, Point3 &worldNormal,
00232                           Point3 &localPoint, Point3 &localNormal,
00233                           Point3 &bary,  int &index,
00234                           INode *node,
00235                           BOOL &mirrorOn,
00236                           Point3 &worldMirrorPoint, Point3 &worldMirrorNormal,
00237                           Point3 &localMirrorPoint, Point3 &localMirrorNormal
00238                           ) = 0;
00239 
00241 
00257         virtual BOOL RandomHit(Point3 &worldPoint, Point3 &worldNormal,
00258                           Point3 &localPoint, Point3 &localNormal,
00259                           Point3 &bary,  int &index,
00260                           float &strFromFalloff, INode *node,
00261                           BOOL &mirrorOn,
00262                           Point3 &worldMirrorPoint, Point3 &worldMirrorNormal,
00263                           Point3 &localMirrorPoint, Point3 &localMirrorNormal,
00264                           int tabIndex) = 0;
00265 
00267 
00282         virtual BOOL RandomHitAlongStroke(Point3 &worldPoint, Point3 &worldNormal,
00283                           Point3 &localPoint, Point3 &localNormal,
00284                           Point3 &bary,  int &index,
00285                           float &strFromFalloff, INode *node,
00286                           BOOL &mirrorOn,
00287                           Point3 &worldMirrorPoint, Point3 &worldMirrorNormal,
00288                           Point3 &localMirrorPoint, Point3 &localMirrorNormal,
00289                           int tabIndex) = 0;
00290 
00291 
00293 
00297         virtual BOOL ClearStroke()=0;
00298 
00300 
00309         virtual BOOL AddToStroke(IPoint2 mousePos, BOOL rebuildPointGatherData, BOOL updateViewport)=0;
00310 
00311     //These are direct to stroke data lists if you are doing your own point gather
00312     //Each stroke contains an arrays of data that are used to describe it such as
00313     //position, str, radius etc.
00314 
00316         virtual int GetStrokeCount() = 0;
00318         virtual float *GetStrokeStr() = 0;
00320         virtual float *GetStrokeRadius() = 0;
00322         virtual Point3 *GetStrokePointWorld() = 0;
00324         virtual Point3 *GetStrokeNormalWorld() = 0;
00326         virtual Point3 *GetStrokePointWorldMirror() = 0;
00328         virtual Point3 *GetStrokeNormalWorldMirror() = 0;
00331         virtual float *GetStrokePressure() = 0;
00332 
00334         virtual Point3 *GetStrokePointLocal() = 0;
00336         virtual Point3 *GetStrokeNormalLocal() = 0;
00338         virtual Point3 *GetStrokePointLocalMirror() = 0;
00340         virtual Point3 *GetStrokeNormalLocalMirror() = 0;
00341 
00343         virtual IPoint2 *GetStrokeMousePos() = 0;
00345 
00347         virtual BOOL *GetStrokeHitList() = 0;
00348 
00350         virtual Point3 *GetStrokeBary() = 0;
00352         virtual int *GetStrokeIndex() = 0;
00353 
00355         virtual BOOL *GetStrokeShift() = 0;
00357         virtual BOOL *GetStrokeCtrl() = 0;
00359         virtual BOOL *GetStrokeAlt() = 0;
00360 
00362         virtual INode **GetStrokeNode() = 0;
00364         virtual int *GetStrokeTime() = 0;
00365 
00366 
00368         virtual float GetStrFromPoint(Point3 point) = 0;
00369 
00370 //These functions let you interogate and set the state of the options dialog
00371 
00373 
00381         //these return array of floats one entry for each point on the stroke
00382          virtual float *GetPredefineStrStrokeData(int &ct)=0;
00383 
00385 
00393          virtual float *GetPredefineSizeStrokeData(int &ct)=0;
00394 
00395 
00396          //put in access to all the dialog properties
00397 
00399 
00403         virtual BOOL  GetBuildNormalData() = 0;
00405 
00409         virtual void  SetBuildNormalData(BOOL enable) = 0;
00410 
00411 //These functions deal with the point gather.  The painter can automatically determines the weights
00412 //of points by using the  PointGather
00413 
00415 
00417         virtual BOOL  GetEnablePointGather() = 0;
00419 
00421         virtual void  SetEnablePointGather(BOOL enable) = 0;//tested
00422 
00424 
00429         virtual BOOL LoadCustomPointGather(int ct, Point3 *points, INode *node) = 0;//tested
00430 
00431         //Once a stroke has started you can retrieve data about you point list such
00432         //as weigths, str etc.
00434 
00437         virtual float *RetrievePointGatherWeights(INode *node, int &ct) = 0;
00439 
00442         virtual float *RetrievePointGatherStr(INode *node, int &ct) = 0;//tested
00444 
00447         virtual BOOL *RetrievePointGatherIsMirror(INode *node, int &ct) = 0;//tested
00449 
00452         virtual Point3 *RetrievePointGatherPoints(INode *node, int &ct) = 0;//tested
00453         
00455 
00459         virtual Point3 *RetrievePointGatherNormals(INode *node, int &ct) = 0;
00460 
00462 
00465         virtual float *RetrievePointGatherU(INode *node, int &ct) = 0;
00466 
00467         
00468 
00469 //functions to get the mirror plane data
00470 //NOTE all mirror function work in world space
00472         virtual BOOL  GetMirrorEnable() = 0 ;//tested
00474         virtual void  SetMirrorEnable(BOOL enable) = 0;
00476 
00478         virtual Point3 GetMirrorPlaneCenter() = 0;//tested
00480 
00484         virtual int GetMirrorAxis() = 0;//tested
00486 
00490         virtual void SetMirrorAxis(int dir) = 0;
00492         virtual float GetMirrorOffset() = 0;//tested
00494         virtual void  SetMirrorOffset(float offset) = 0;//tested
00495 
00496 
00498 
00501         virtual int GetTreeDepth() = 0;//tested
00503 
00506         virtual void SetTreeDepth(int depth) = 0;//tested
00507 
00509 
00512         virtual BOOL GetUpdateOnMouseUp() = 0;
00514 
00517         virtual void SetUpdateOnMouseUp(BOOL update) = 0;
00518 
00520 
00523         virtual int GetLagRate() = 0;
00525 
00528         virtual void SetLagRate(int lagRate) = 0;
00529 
00530 //These functions control how the brush behaves
00531 
00533 
00535         virtual float GetMinStr() = 0;//tested
00537 
00539         virtual void  SetMinStr(float str) = 0;//tested
00541 
00543         virtual float GetMaxStr() = 0;//tested
00545 
00547         virtual void  SetMaxStr(float str) = 0;//tested
00548 
00550 
00552         virtual float GetMinSize() = 0;//tested
00554 
00556         virtual void  SetMinSize(float str) = 0;//tested
00558 
00560         virtual float GetMaxSize() = 0;//tested
00562 
00564         virtual void  SetMaxSize(float str) = 0;//tested
00565 
00567 
00571         virtual BOOL  GetAdditiveMode()=0;//tested
00573 
00577         virtual void  SetAdditiveMode(BOOL enable)=0;//tested
00580         virtual ICurve *GetFalloffGraph()=0;
00581 
00582 
00583 //These functions allow you to control the display of a stroke
00584 //Colors are stored in the color manager. See the color ID defines at the top
00585 
00587 
00588         virtual BOOL  GetDrawRing()=0;//tested
00590 
00591         virtual void  SetDrawRing(BOOL draw)=0;//tested
00592 
00594 
00595         virtual BOOL  GetDrawNormal()=0;//tested
00597 
00598         virtual void  SetDrawNormal(BOOL draw)=0;//tested
00599 
00601 
00602         virtual BOOL  GetDrawTrace()=0;//tested
00604 
00605         virtual void  SetDrawTrace(BOOL draw)=0;//tested
00606 
00607 
00608 //These functions deal with the pressure sensitive devices and mimicing pressure sensitivity
00609 
00611 
00614         virtual BOOL  GetPressureEnable()=0;//tested
00616 
00619         virtual void  SetPressureEnable(BOOL enable)=0;//tested
00620 
00622 
00624         virtual BOOL  GetPressureAffects()=0;//tested
00626 
00628         virtual void  SetPressureAffects(int affect)=0;//tested
00629 
00631 
00632         virtual BOOL  GetPredefinedStrEnable()=0;//tested
00634 
00635         virtual void  SetPredefinedStrEnable(BOOL enable)=0;//tested
00636 
00638 
00639         virtual BOOL  GetPredefinedSizeEnable()=0;//tested
00641 
00642         virtual void  SetPredefinedSizeEnable(BOOL enable)=0;//tested
00644 
00645         virtual ICurve *GetPredefineSizeStrokeGraph()=0;
00647 
00648         virtual ICurve *GetPredefineStrStrokeGraph()=0;
00649 
00650         virtual float GetNormalScale() = 0;
00651         virtual void SetNormalScale(float scale) = 0;
00652 
00653         virtual BOOL GetMarkerEnable() = 0;
00654         virtual void SetMarkerEnable(BOOL on) = 0;
00655         virtual float GetMarker() = 0;
00656         virtual void SetMarker(float pos) = 0;
00657 
00659 
00663         virtual int GetOffMeshHitType() = 0;
00664 
00666 
00670         virtual void SetOffMeshHitType(int type) = 0;
00671 
00672         virtual float GetOffMeshHitZDepth() = 0;
00673         virtual void SetOffMeshHitZDepth(float depth) = 0;
00674 
00675         virtual Point3 GetOffMeshHitPos() = 0;
00676         virtual void SetOffMeshHitPos(Point3 pos) = 0;
00677 
00678 
00679     };
00680 
00687     class FaceDataFromPatch: public MaxHeapOperators
00688     {
00689     public:
00690         int owningPatch;  
00691         Point2 st[3];    
00692     };
00693 
00699     class IPainterRightClickHandler: public MaxHeapOperators
00700     {
00701     public:
00703         virtual void RightClick ()=0;
00704     };
00705 
00711     class IPainterInterface_V7 : public IPainterInterface_V5
00712     {
00713     public:
00715 
00722         virtual BOOL  InitializeNodesByObjState(int flags, Tab<INode*> &nodeList, Tab<ObjectState> &objList) = 0;//tested
00723 
00725 
00736         virtual BOOL  UpdateMeshesByObjState(BOOL updatePointGather, Tab<ObjectState> &objList) = 0;
00737 
00740         virtual void  GetPatchFaceData(PatchMesh &patch, Tab<FaceDataFromPatch> &faceData) = 0;
00741 
00744 
00748         virtual BOOL  StartPaintSession (IPainterRightClickHandler *rightClicker) = 0;
00749     // I have to add this one over again, otherwise it doesn't show up in the V7 interface:
00751         virtual BOOL  StartPaintSession() = 0;//tested
00752 
00754         virtual float GetStrDragLimitMin() = 0;
00756         virtual void SetStrDragLimitMin(float l) = 0;
00757 
00759         virtual float GetStrDragLimitMax() = 0;
00761         virtual void SetStrDragLimitMax(float l) = 0;
00762 
00763 
00764     };
00765 
00770     class IPainterInterface_V14 : public IPainterInterface_V7
00771     {
00772     public:
00774         virtual BOOL GetUseSplineConstraint() = 0;
00776         virtual void SetUseSplineConstraint(BOOL onoff) = 0;
00779         virtual BOOL SetSplineConstraintNode(INode* snode) = 0;
00781         virtual BOOL IsSplineConstraintNodeValid() = 0;
00782     };
00783 
00784 
00790 class IPainterCanvasInterface_V5: public MaxHeapOperators 
00791     {
00792     public:
00793     
00795         virtual BOOL  StartStroke() = 0;
00796 
00797 
00799 
00824         virtual BOOL  PaintStroke(
00825                           BOOL hit,
00826                           IPoint2 mousePos, 
00827                           Point3 worldPoint, Point3 worldNormal,
00828                           Point3 localPoint, Point3 localNormal,
00829                           Point3 bary,  int index,
00830                           BOOL shift, BOOL ctrl, BOOL alt, 
00831                           float radius, float str,
00832                           float pressure, INode *node,
00833                           BOOL mirrorOn,
00834                           Point3 worldMirrorPoint, Point3 worldMirrorNormal,
00835                           Point3 localMirrorPoint, Point3 localMirrorNormal
00836                           ) = 0;
00837 
00839         virtual BOOL  EndStroke() = 0;
00840 
00842 
00845         virtual BOOL  EndStroke(int ct, BOOL *hit, IPoint2 *mousePos, 
00846                           Point3 *worldPoint, Point3 *worldNormal,
00847                           Point3 *localPoint, Point3 *localNormal,
00848                           Point3 *bary,  int *index,
00849                           BOOL *shift, BOOL *ctrl, BOOL *alt, 
00850                           float *radius, float *str,
00851                           float *pressure, INode **node,
00852                           BOOL mirrorOn,
00853                           Point3 *worldMirrorPoint, Point3 *worldMirrorNormal,
00854                           Point3 *localMirrorPoint, Point3 *localMirrorNormal   ) = 0;
00855 
00857         virtual BOOL  CancelStroke() = 0;   
00858 
00860         virtual BOOL  SystemEndPaintSession() = 0;
00861 
00864         virtual void PainterDisplay(TimeValue t, ViewExp *vpt, int flags) = 0;
00865 
00866 
00867     };
00868 
00869 
00876 class IPainterCanvasInterface_V5_1: public MaxHeapOperators
00877     {
00878     public:
00879 
00881 
00887         virtual void CanvasStartPaint()=0;
00889 
00895         virtual void CanvasEndPaint()=0;
00896     
00897 
00898     };
00899 
00901 class IPainterCanvasInterface_V7: public MaxHeapOperators
00902 {
00903     public:
00905 
00906         virtual void OnPaintBrushChanged() = 0;
00907 };
00908