meshselection.h

Go to the documentation of this file.
00001 /*  
00002  *      MeshSub.h - edit mesh sub-object classes & functions
00003  *                  also includes MeshDelta and MNMesh scripter classes
00004  *
00005  *  exposes the new-with-R3 MeshDelta, MapDelta & MeshSel tools for
00006  *  working with meshes.  Also provides access to MNMesh tools and 
00007  *  mesh sub-objects as direct properties on nodes.
00008  *
00009  *          Copyright (c) Autodesk, Inc., 1998
00010  *              John Wainwright
00011  */
00012 
00013 #pragma once
00014 
00015 #include "..\kernel\value.h"
00016 #include "mxsobjects.h"
00017 #include "..\..\mnmesh.h"
00018 #include "..\..\patch.h"
00019 
00020 // forward declarations
00021 class MeshDelta;
00022 class GenericNamedSelSetList;
00023 
00024 // mesh selection types
00025 #define MSEL_ALL        1       // whole mesh selected 
00026 #define MSEL_CUR        2       // current selection 
00027 #define MSEL_EXP        3       // explicit selection (in vsel) 
00028 #define MSEL_SINGLE     4       // explicit single index  
00029 #define MSEL_NAMED      5       // named selection set - name in nss_name
00030 
00031 /* -------------- base class for mesh sub-object selections ------------------- */
00032 
00033 class MeshSelection : public Value
00034 {
00035 public:
00036     MAXWrapper* owner;          // owner node or modifier if any
00037     BYTE        sel_type;       // selection type
00038     BitArray    vsel;           // stand-alone selection if any
00039     int         index;          // single vert index            
00040     MSTR        nss_name;       // name of named selection set
00041 
00042     void        gc_trace();
00043 #   define is_meshselection(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(VertSelectionValue) || (v)->tag == class_tag(FaceSelectionValue) || \
00044                                 (v)->tag == class_tag(EdgeSelectionValue) )
00045 
00046     virtual MeshSelection* new_sel(MAXWrapper* own, BYTE stype, int indx = 0) = 0;
00047 
00048     // utility functions to be specialized
00049     virtual BitArray get_sel() = 0; // my element selection
00050     virtual BitArray get_owner_sel() = 0;   // get owner's element selection
00051     virtual void     set_owner_sel(BitArray &sel) = 0;  // set owner's element selection
00052     virtual BitArray get_sel_vertices(Mesh* m) = 0; // vertexes involved in my element selection
00053     virtual BitArray get_sel_vertices(MNMesh* m) = 0;   // vertexes involved in my element selection
00054     virtual BitArray get_sel_vertices(PatchMesh* m) = 0;    // vertexes involved in my element selection
00055     virtual GenericNamedSelSetList& get_named_sel_set_list() = 0;
00056     virtual int     num_elements(Mesh* m) = 0;
00057     virtual int     num_elements(MNMesh* m) = 0;
00058     virtual int     num_elements(PatchMesh* m) = 0;
00059     virtual BOOL    is_same_selection(Value* s) = 0;
00060     virtual void    delete_sel(Mesh& m, MeshDelta& md, BitArray &sel) = 0;
00061     virtual void    delete_sel(MNMesh* m, ReferenceTarget* owner, BitArray &sel) = 0; 
00062 
00063     // utility functions
00064             int     get_sel_index(BitArray &vs, int n);  // index for n'th item vertex in BitArray
00065             void    update_sel();
00066             void    set_sel(BitArray &vs);
00067             void    sprin1(MCHAR* type, CharStream* s);
00068 
00069     // operations
00070 #include "..\macros\define_implementations.h"
00071 #   include "..\protocols\arrays.inl"
00072     def_generic ( move,         "move");
00073     def_generic ( scale,        "scale");
00074     def_generic ( rotate,       "rotate");
00075     def_generic ( delete,       "delete");
00076     def_generic ( select,       "select");
00077     def_generic ( deselect,     "deselect");
00078     def_generic ( selectmore,   "selectMore");
00079     use_generic  ( coerce,      "coerce");
00080 
00081     ScripterExport Value* map(node_map& m);
00082 
00083     void        to_fpvalue(FPValue& v); 
00084     ScripterExport Value*   to_bitarrayValue(); 
00085 
00086     // built-in property accessors
00087     def_property ( count );
00088     def_property ( index );
00089     def_property ( selSetNames );
00090 };
00091 
00092 /* ---------------- mesh vertex selection --------------------- */
00093 
00094 visible_class (VertSelectionValue)
00095 
00096 class VertSelectionValue : public MeshSelection
00097 {
00098 public:
00099     ScripterExport VertSelectionValue(MAXWrapper* own, BYTE stype, int indx = 0);
00100     
00101     MeshSelection* new_sel(MAXWrapper* own, BYTE stype, int indx = 0);
00102 
00103                 classof_methods (VertSelectionValue, Value);
00104 #   define      is_vertselection(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(VertSelectionValue))
00105     void        collect() { delete this; }
00106     ScripterExport void sprin1(CharStream* s);
00107 
00108     // specialized utility functions
00109     BitArray    get_sel();
00110     BitArray    get_owner_sel() { return (owner == NULL) ? BitArray() : owner->get_vertsel(); }
00111     void        set_owner_sel(BitArray &sel) {if (owner != NULL) owner->set_vertsel(sel); }
00112     BitArray    get_sel_vertices(Mesh* m);
00113     BitArray    get_sel_vertices(MNMesh* m);
00114     BitArray    get_sel_vertices(PatchMesh* m);
00115     GenericNamedSelSetList& get_named_sel_set_list() { return owner->get_named_vertsel_set(); }
00116     int         num_elements(Mesh* m) { return m->getNumVerts(); } 
00117     int         num_elements(MNMesh* m) { return m->VNum(); } 
00118     int         num_elements(PatchMesh* m) { return m->getNumVerts(); } 
00119     BOOL        is_same_selection(Value* s) { return is_vertselection(s); }
00120     void        delete_sel(Mesh& m, MeshDelta& md, BitArray &sel);
00121     void        delete_sel(MNMesh* m, ReferenceTarget* owner, BitArray &sel); 
00122 
00123     // operations
00124     def_generic ( put,          "put");
00125 
00126     // built-in property accessors
00127     def_property ( pos );
00128 };
00129 
00130 /* ---------------- mesh face selection --------------------- */
00131 
00132 visible_class (FaceSelectionValue)
00133 
00134 class FaceSelectionValue : public MeshSelection
00135 {
00136 public:
00137     ScripterExport FaceSelectionValue(MAXWrapper* own, BYTE stype, int indx = 0);
00138     
00139     MeshSelection* new_sel(MAXWrapper* own, BYTE stype, int indx = 0);
00140 
00141                 classof_methods (FaceSelectionValue, Value);
00142 #   define      is_faceselection(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FaceSelectionValue))
00143     void        collect() { delete this; }
00144     ScripterExport void sprin1(CharStream* s);
00145 
00146     // specialized utility functions
00147     BitArray    get_sel();
00148     BitArray    get_owner_sel() { return (owner == NULL) ? BitArray() : owner->get_facesel(); }
00149     void        set_owner_sel(BitArray &sel) {if (owner != NULL) owner->set_facesel(sel); }
00150     BitArray    get_sel_vertices(Mesh* m);
00151     BitArray    get_sel_vertices(MNMesh* m);
00152     BitArray    get_sel_vertices(PatchMesh* m);
00153     GenericNamedSelSetList& get_named_sel_set_list() { return owner->get_named_facesel_set(); }
00154     int         num_elements(Mesh* m) { return m->getNumFaces(); } 
00155     int         num_elements(MNMesh* m) { return m->FNum(); } 
00156     int         num_elements(PatchMesh* m) { return m->getNumPatches(); } 
00157     BOOL        is_same_selection(Value* s) { return is_faceselection(s); }
00158     void        delete_sel(Mesh& m, MeshDelta& md, BitArray &sel);
00159     void        delete_sel(MNMesh* m, ReferenceTarget* owner, BitArray &sel); 
00160 
00161     // operations
00162     def_generic ( put,          "put");
00163 
00164     // built-in property accessors
00165 };
00166 
00167 /* ---------------- edge face selection --------------------- */
00168 
00169 visible_class (EdgeSelectionValue)
00170 
00171 class EdgeSelectionValue : public MeshSelection
00172 {
00173 public:
00174     ScripterExport EdgeSelectionValue(MAXWrapper* own, BYTE stype, int indx = 0);
00175     
00176     MeshSelection* new_sel(MAXWrapper* own, BYTE stype, int indx = 0);
00177 
00178                 classof_methods (EdgeSelectionValue, Value);
00179 #   define      is_edgeselection(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(EdgeSelectionValue))
00180     void        collect() { delete this; }
00181     ScripterExport void sprin1(CharStream* s);
00182 
00183     // specialized utility functions
00184     BitArray    get_sel();
00185     BitArray    get_owner_sel() { return (owner == NULL) ? BitArray() : owner->get_edgesel(); }
00186     void        set_owner_sel(BitArray &sel) {if (owner != NULL) owner->set_edgesel(sel); }
00187     BitArray    get_sel_vertices(Mesh* m);
00188     BitArray    get_sel_vertices(MNMesh* m);
00189     BitArray    get_sel_vertices(PatchMesh* m);
00190     GenericNamedSelSetList& get_named_sel_set_list() { return owner->get_named_edgesel_set(); }
00191     int         num_elements(Mesh* m) { return m->getNumFaces() * 3; } 
00192     int         num_elements(MNMesh* m) { return m->ENum(); } 
00193     int         num_elements(PatchMesh* m) { return m->getNumEdges(); } 
00194     BOOL        is_same_selection(Value* s) { return is_edgeselection(s); }
00195     void        delete_sel(Mesh& m, MeshDelta& md, BitArray &sel);
00196     void        delete_sel(MNMesh* m, ReferenceTarget* owner, BitArray &sel); 
00197 
00198     // operations
00199 
00200     // built-in property accessors
00201 };
00202