00001
00002
00003
00004
00005
00006
00007 #ifndef __AMPLE_H__
00008 #define __AMPLE_H__
00009
00010 #include <algorithm>
00011 #include <string>
00012 #include <vector>
00013 #include <stack>
00014 #include <list>
00015 #include <map>
00016
00017 #include <AmpleUtil.h>
00018
00019 namespace verse
00020 {
00021 namespace ample
00022 {
00023
00024
00025
00026 const uint32 INVALID_VERTEX_ID = ((uint32) ~0);
00027 const uint32 INVALID_POLYGON_ID = ((uint32) ~0);
00028
00029 const VLayerID BASE_VERTEX_LAYER_ID = 0;
00030 const VLayerID BASE_POLYGON_LAYER_ID = 1;
00031
00032
00033
00034 class BaseVertex;
00035 class BasePolygon;
00036 class BaseMesh;
00037
00038 class Quaternion64;
00039
00040 template <typename T>
00041 class Observer;
00042 template <typename T>
00043 class Observable;
00044
00045 class Versioned;
00046
00047 class Tag;
00048 class TagObserver;
00049 class TagGroup;
00050 class TagGroupObserver;
00051
00052 class Node;
00053 class NodeObserver;
00054
00055 class TextBuffer;
00056 class TextBufferObserver;
00057 class TextNode;
00058 class TextNodeObserver;
00059
00060 class GeometryLayer;
00061 class GeometryLayerObserver;
00062 class Bone;
00063 class BoneObserver;
00064 class GeometryNode;
00065 class GeometryNodeObserver;
00066
00067 class Method;
00068 class MethodObserver;
00069 class MethodGroup;
00070 class MethodGroupObserver;
00071 class Link;
00072 class LinkObserver;
00073 class ObjectNode;
00074 class ObjectNodeObserver;
00075
00076 class BitmapLayer;
00077 class BitmapLayerObserver;
00078 class BitmapNode;
00079 class BitmapNodeObserver;
00080
00081 class Fragment;
00082 class FragmentObserver;
00083 class MaterialNode;
00084 class MaterialNodeObserver;
00085
00086 class Session;
00087 class SessionObserver;
00088
00089
00090
00091 class BaseVertex
00092 {
00093 public:
00094 BaseVertex(void);
00095 BaseVertex(real64 sx, real64 sy, real64 sz);
00096 bool isValid(void) const;
00097 void set(real64 sx, real64 sy, real64 sz);
00098 void setInvalid(void);
00099 real64 x;
00100 real64 y;
00101 real64 z;
00102 };
00103
00104
00105
00106 class BasePolygon
00107 {
00108 public:
00109 BasePolygon(void);
00110 BasePolygon(uint32 v0, uint32 v1, uint32 v2, uint32 v3);
00111 bool isValid(void) const;
00112 void set(uint32 v0, uint32 v1, uint32 v2, uint32 v3);
00113 void setInvalid(void);
00114 uint32 mIndices[4];
00115 };
00116
00117
00118
00119 class BaseMesh
00120 {
00121 public:
00122 typedef std::vector<BaseVertex> VertexList;
00123 typedef std::vector<BasePolygon> PolygonList;
00124 VertexList mVertices;
00125 PolygonList mPolygons;
00126 };
00127
00128
00129
00130 class Quaternion64 : public VNQuat64
00131 {
00132 public:
00133 Quaternion64(void);
00134 Quaternion64(real64 sx, real64 sy, real64 sz, real64 sw);
00135 void invert(void);
00136 void normalize(void);
00137 template <typename T>
00138 void rotateVector(Vector3<T>& vector) const;
00139 real64 dotProduct(const Quaternion64& other) const;
00140 Quaternion64 interpolateTo(real64 t, const Quaternion64& other) const;
00141 Quaternion64 operator * (real64 value) const;
00142 Quaternion64 operator / (real64 value) const;
00143 Quaternion64 operator + (const Quaternion64& quat) const;
00144 Quaternion64 operator * (const Quaternion64& quat) const;
00145 Quaternion64& operator += (const Quaternion64& quat);
00146 Quaternion64& operator *= (const Quaternion64& quat);
00147 Quaternion64& operator = (const VNQuat32& source);
00148 Quaternion64& operator = (const VNQuat64& source);
00149 bool operator == (const Quaternion64& quaternion) const;
00150 bool operator != (const Quaternion64& quaternion) const;
00151 void set(real64 sx, real64 sy, real64 sz, real64 sw);
00152 void setDefaults(void);
00153 template <typename T>
00154 void setVectorRotation(const Vector3<T>& vector, T angle);
00155 template <typename T>
00156 void getAxisRotation(Vector3<T>& axis, T& angle) const;
00157 template <typename T>
00158 void setAxisRotation(const Vector3<T>& axis, T angle);
00159 };
00160
00161
00162
00163 class Translation
00164 {
00165 public:
00166 Vector3d mPosition;
00167 Vector3d mSpeed;
00168 Vector3d mAccel;
00169 Vector3d mDragNormal;
00170 uint32 mSeconds;
00171 uint32 mFraction;
00172 real64 mDrag;
00173 };
00174
00175
00176
00177 class Rotation
00178 {
00179 public:
00180 Quaternion64 mRotation;
00181 Quaternion64 mSpeed;
00182 Quaternion64 mAccel;
00183 Quaternion64 mDragNormal;
00184 uint32 mSeconds;
00185 uint32 mFraction;
00186 real64 mDrag;
00187 };
00188
00189
00190
00191 class Block
00192 {
00193 public:
00194 Block(void);
00195 Block(const Block& source);
00196 ~Block(void);
00197 void resize(size_t count);
00198 void reserve(size_t count);
00199 void release(void);
00200 operator void* (void);
00201 operator const void* (void) const;
00202 Block& operator = (const Block& source);
00203 void* getItem(size_t index);
00204 const void* getItem(size_t index) const;
00205 void* getItems(void);
00206 const void* getitems(void) const;
00207 void setItem(void* item, size_t index);
00208 size_t getItemSize(void) const;
00209 void setItemSize(size_t size);
00210 size_t getItemCount(void) const;
00211 size_t getGranularity(void) const;
00212 void setGranularity(size_t grain);
00213 private:
00214 size_t mItemCount;
00215 size_t mItemSize;
00216 size_t mGrain;
00217 uint8* mData;
00218 };
00219
00220
00221
00224 template <typename T>
00225 class Observer
00226 {
00227 public:
00228 typedef Observable<T> ObservableType;
00229 friend class Observable<T>;
00232 inline virtual ~Observer(void);
00235 inline void detachObservables(void);
00236 private:
00237 typedef std::vector<ObservableType*> ObservableList;
00238 ObservableList mObservables;
00239 };
00240
00241
00242
00243 template <typename T>
00244 inline Observer<T>::~Observer(void)
00245 {
00246 detachObservables();
00247 }
00248
00249 template <typename T>
00250 inline void Observer<T>::detachObservables(void)
00251 {
00252 while (mObservables.size())
00253 mObservables.front()->removeObserver(*this);
00254 }
00255
00256
00257
00260 template <typename T>
00261 class Observable
00262 {
00263 public:
00264 typedef Observer<T> ObserverType;
00265 typedef std::vector<T*> ObserverList;
00268 inline virtual ~Observable(void);
00273 inline void addObserver(T& observer);
00277 inline void removeObserver(T& observer);
00281 inline void removeObserver(Observer<T>& observer);
00284 inline const ObserverList& getObservers(void) const;
00285 private:
00286 ObserverList mObservers;
00287 };
00288
00289
00290
00291 template <typename T>
00292 inline Observable<T>::~Observable(void)
00293 {
00294 while (mObservers.size())
00295 removeObserver(*mObservers.front());
00296 }
00297
00298 template <typename T>
00299 inline void Observable<T>::addObserver(T& observer)
00300 {
00301 if (std::find(mObservers.begin(), mObservers.end(), &observer) != mObservers.end())
00302 return;
00303
00304 mObservers.push_back(&observer);
00305 static_cast<ObserverType&>(observer).mObservables.push_back(this);
00306 }
00307
00308 template <typename T>
00309 inline void Observable<T>::removeObserver(T& observer)
00310 {
00311 typename ObserverList::iterator i = std::find(mObservers.begin(), mObservers.end(), &observer);
00312 if (i != mObservers.end())
00313 {
00314 typename ObserverType::ObservableList& observables = static_cast<ObserverType&>(observer).mObservables;
00315 observables.erase(std::find(observables.begin(), observables.end(), this));
00316 mObservers.erase(i);
00317 }
00318 }
00319
00320 template <typename T>
00321 inline void Observable<T>::removeObserver(Observer<T>& observer)
00322 {
00323 typename ObserverList::iterator i = std::find(mObservers.begin(), mObservers.end(), &observer);
00324 if (i != mObservers.end())
00325 {
00326 typename ObserverType::ObservableList& observables = observer.mObservables;
00327 observables.erase(std::find(observables.begin(), observables.end(), this));
00328 mObservers.erase(i);
00329 }
00330 }
00331
00332 template <typename T>
00333 inline const typename Observable<T>::ObserverList& Observable<T>::getObservers(void) const
00334 {
00335 return mObservers;
00336 }
00337
00338
00339
00342 class Versioned
00343 {
00344 friend class TagGroup;
00345 friend class Node;
00346 friend class TextBuffer;
00347 friend class TextNode;
00348 friend class GeometryLayer;
00349 friend class GeometryNode;
00350 friend class MethodGroup;
00351 friend class Link;
00352 friend class ObjectNode;
00353 friend class MaterialNode;
00354 friend class BitmapNode;
00355 friend class Session;
00356 public:
00359 Versioned(void);
00363 unsigned int getDataVersion(void) const;
00367 unsigned int getStructureVersion(void) const;
00368 private:
00369 void updateDataVersion(void);
00370 void updateStructureVersion(void);
00371 unsigned int mDataVersion;
00372 unsigned int mStructVersion;
00373 };
00374
00375
00376
00379 class Tag : public Versioned, public Observable<TagObserver>
00380 {
00381 friend class TagGroup;
00382 public:
00388 void destroy(void);
00391 uint16 getID(void) const;
00394 const std::string& getName(void) const;
00401 void setName(const std::string& name);
00403
00405 VNTagType getType(void) const;
00413 void setType(VNTagType type, const VNTag& value);
00416 const VNTag& getValue(void) const;
00423 void setValue(const VNTag& value);
00426 TagGroup& getGroup(void) const;
00427 private:
00428 Tag(uint16 ID, const std::string& name, VNTagType type, const VNTag& value, TagGroup& group);
00429 uint16 mID;
00430 std::string mName;
00431 VNTagType mType;
00432 VNTag mValue;
00433 TagGroup& mGroup;
00434 };
00435
00436
00437
00440 class TagObserver : public Observer<TagObserver>
00441 {
00442 public:
00443 virtual void onSetType(Tag& tag, VNTagType type, const VNTag& value);
00444 virtual void onSetValue(Tag& tag, const VNTag& value);
00449 virtual void onSetName(Tag& tag, const std::string name);
00453 virtual void onDestroy(Tag& tag);
00454 };
00455
00456
00457
00460 class TagGroup : public Versioned, public Observable<TagGroupObserver>
00461 {
00462 friend class Node;
00463 public:
00469 void destroy(void);
00478 void createTag(const std::string& name, VNTagType type, const VNTag& value);
00481 uint16 getID(void) const;
00484 const std::string& getName(void) const;
00491 void setName(const std::string& name);
00495 Tag* getTagByID(uint16 ID);
00499 const Tag* getTagByID(uint16 ID) const;
00503 Tag* getTagByIndex(unsigned int index);
00507 const Tag* getTagByIndex(unsigned int index) const;
00511 Tag* getTagByName(const std::string& name);
00515 const Tag* getTagByName(const std::string& name) const;
00518 unsigned int getTagCount(void) const;
00521 Node& getNode(void) const;
00522 private:
00523 TagGroup(uint16 ID, const std::string& name, Node& node);
00524 ~TagGroup(void);
00525 static void initialize(void);
00526 static void receiveTagCreate(void* user, VNodeID ID, uint16 groupID, uint16 tagID, const char* name, VNTagType type, const VNTag* value);
00527 static void receiveTagDestroy(void* user, VNodeID ID, uint16 groupID, uint16 tagID);
00528 typedef std::vector<Tag*> TagList;
00529 TagList mTags;
00530 std::string mName;
00531 uint16 mID;
00532 Node& mNode;
00533 };
00534
00535
00536
00539 class TagGroupObserver : public Observer<TagGroupObserver>
00540 {
00541 public:
00546 virtual void onCreateTag(TagGroup& group, Tag& tag);
00551 virtual void onDestroyTag(TagGroup& group, Tag& tag);
00556 virtual void onSetName(TagGroup& group, const std::string& name);
00560 virtual void onDestroy(TagGroup& group);
00561 };
00562
00563
00564
00567 class Node : public Versioned, public Observable<NodeObserver>
00568 {
00569 friend class Session;
00570 public:
00576 void destroy(void);
00583 void createTagGroup(const std::string& name);
00587 TagGroup* getTagGroupByID(uint16 ID);
00591 const TagGroup* getTagGroupByID(uint16 ID) const;
00595 TagGroup* getTagGroupByIndex(unsigned int index);
00599 const TagGroup* getTagGroupByIndex(unsigned int index) const;
00603 TagGroup* getTagGroupByName(const std::string& name);
00607 const TagGroup* getTagGroupByName(const std::string& name) const;
00610 unsigned int getTagGroupCount(void) const;
00615 Tag* getTagByNames(const std::string& groupName, const std::string& tagName);
00620 const Tag* getTagByNames(const std::string& groupName, const std::string& tagName) const;
00623 bool isMine(void) const;
00626 VNodeID getID(void) const;
00629 VNodeType getType(void) const;
00632 const std::string& getName(void) const;
00639 void setName(const std::string& name);
00642 Session& getSession(void) const;
00643 protected:
00650 Node(VNodeID ID, VNodeType type, VNodeOwner owner, Session& session);
00653 virtual ~Node(void);
00654 private:
00655 static void initialize(void);
00656 static void receiveNodeNameSet(void* user, VNodeID ID, const char *name);
00657 static void receiveTagGroupCreate(void* user, VNodeID ID, uint16 groupID, const char* name);
00658 static void receiveTagGroupDestroy(void* user, VNodeID ID, uint16 groupID);
00659 typedef std::vector<TagGroup*> TagGroupList;
00660 VNodeID mID;
00661 VNodeType mType;
00662 VNodeOwner mOwner;
00663 std::string mName;
00664 TagGroupList mGroups;
00665 Session& mSession;
00666 };
00667
00668
00669
00672 class NodeObserver : public Observer<NodeObserver>
00673 {
00674 public:
00679 virtual void onCreateTagGroup(Node& node, TagGroup& group);
00684 virtual void onDestroyTagGroup(Node& node, TagGroup& group);
00689 virtual void onSetName(Node& node, const std::string& name);
00693 virtual void onDestroy(Node& node);
00694 };
00695
00696
00697
00698 class NodeNameObserver : public Observer<NodeNameObserver>
00699 {
00700 public:
00701 virtual void onNewNode(Node& node);
00702 virtual void onDestroyNode(Node& node);
00703 };
00704
00705
00706
00709 class TextBuffer : public Versioned, public Observable<TextBufferObserver>
00710 {
00711 friend class Session;
00712 friend class TextNode;
00713 public:
00722 void replaceRange(uint32 position,
00723 uint32 length,
00724 const std::string& text);
00730 void destroy(void);
00733 VBufferID getID(void) const;
00736 const std::string& getName(void) const;
00743 void setName(const std::string& name);
00746 const std::string& getText(void) const;
00753 void setText(const std::string& text);
00756 TextNode& getNode(void) const;
00757 private:
00758 TextBuffer(VBufferID ID, const std::string& name, TextNode& node);
00759 static void initialize(void);
00760 static void receiveTextBufferSet(void* user, VNodeID ID, VBufferID bufferID, uint32 position, uint32 length, const char* text);
00761 VBufferID mID;
00762 std::string mName;
00763 std::string mText;
00764 TextNode& mNode;
00765 };
00766
00767
00768
00771 class TextBufferObserver : public Observer<TextBufferObserver>
00772 {
00773 public:
00780 virtual void onReplaceRange(TextBuffer& buffer, uint32 position, uint32 length, const std::string& text);
00785 virtual void onSetName(TextBuffer& buffer, const std::string& name);
00789 virtual void onDestroy(TextBuffer& buffer);
00790 };
00791
00792
00793
00796 class TextNode : public Node
00797 {
00798 friend class Session;
00799 public:
00806 void createBuffer(const std::string& name);
00810 TextBuffer* getBufferByID(VBufferID ID);
00814 const TextBuffer* getBufferByID(VBufferID ID) const;
00818 TextBuffer* getBufferByIndex(unsigned int index);
00822 const TextBuffer* getBufferByIndex(unsigned int index) const;
00826 TextBuffer* getBufferByName(const std::string& name);
00830 const TextBuffer* getBufferByName(const std::string& name) const;
00833 unsigned int getBufferCount(void) const;
00836 const std::string& getLanguage(void) const;
00843 void setLanguage(const std::string& language);
00844 private:
00845 TextNode(VNodeID ID, VNodeOwner owner, Session& session);
00846 ~TextNode(void);
00847 static void initialize(void);
00848 static void receiveNodeLanguageSet(void* user, VNodeID ID, const char* language);
00849 static void receiveTextBufferCreate(void* user, VNodeID ID, VBufferID bufferID, const char* name);
00850 static void receiveTextBufferDestroy(void* user, VNodeID ID, VBufferID bufferID);
00851 typedef std::vector<TextBuffer*> BufferList;
00852 BufferList mBuffers;
00853 std::string mLanguage;
00854 };
00855
00856
00857
00860 class TextNodeObserver : public NodeObserver
00861 {
00862 public:
00867 virtual void onCreateBuffer(TextNode& node, TextBuffer& buffer);
00872 virtual void onDestroyBuffer(TextNode& node, TextBuffer& buffer);
00877 virtual void onSetLanguage(TextNode& node, const std::string& language);
00878 };
00879
00880
00881
00884 class GeometryLayer : public Versioned, public Observable<GeometryLayerObserver>
00885 {
00886 friend class GeometryNode;
00887 public:
00890 enum Stack
00891 {
00894 VERTEX,
00897 POLYGON,
00898 };
00904 void destroy(void);
00907 VLayerID getID(void) const;
00910 Stack getStack(void) const;
00913 VNRealFormat getRealFormat(void) const;
00916 const std::string& getName(void) const;
00923 void setName(const std::string& name);
00926 unsigned int getSlotSize(void) const;
00929 VNGLayerType getType(void) const;
00935 bool getSlot(uint32 slotID, void* data) const;
00943 void setSlot(uint32 slotID, const void* data);
00946 uint32 getDefaultInt(void) const;
00949 real64 getDefaultReal(void) const;
00952 GeometryNode& getNode(void) const;
00953 private:
00954 GeometryLayer(VLayerID ID, const std::string& name, VNGLayerType type,
00955 GeometryNode& node, uint32 defaultInt, real64 defaultReal);
00956 void reserve(size_t slotCount);
00957 static void initialize(void);
00958 static void receiveVertexSetXyzReal32(void* user, VNodeID nodeID, VLayerID layerID, uint32 vertexID, real32 x, real32 y, real32 z);
00959 static void receiveVertexDeleteReal32(void* user, VNodeID nodeID, uint32 vertexID);
00960 static void receiveVertexSetXyzReal64(void* user, VNodeID nodeID, VLayerID layerID, uint32 vertexID, real64 x, real64 y, real64 z);
00961 static void receiveVertexDeleteReal64(void* user, VNodeID nodeID, uint32 vertexID);
00962 static void receiveVertexSetUint32(void* user, VNodeID nodeID, VLayerID layerID, uint32 vertexID, uint32 value);
00963 static void receiveVertexSetReal64(void* user, VNodeID nodeID, VLayerID layerID, uint32 vertexID, real64 value);
00964 static void receiveVertexSetReal32(void* user, VNodeID nodeID, VLayerID layerID, uint32 vertexID, real32 value);
00965 static void receivePolygonSetCornerUint32(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, uint32 v0, uint32 v1, uint32 v2, uint32 v3);
00966 static void receivePolygonDelete(void* user, VNodeID nodeID, uint32 polygonID);
00967 static void receivePolygonSetCornerReal64(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, real64 v0, real64 v1, real64 v2, real64 v3);
00968 static void receivePolygonSetCornerReal32(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, real32 v0, real32 v1, real32 v2, real32 v3);
00969 static void receivePolygonSetFaceUint8(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, uint8 value);
00970 static void receivePolygonSetFaceUint32(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, uint32 value);
00971 static void receivePolygonSetFaceReal64(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, real64 value);
00972 static void receivePolygonSetFaceReal32(void* user, VNodeID nodeID, VLayerID layerID, uint32 polygonID, real32 value);
00973 static unsigned int getTypeSize(VNGLayerType type);
00974 static unsigned int getTypeElementCount(VNGLayerType type);
00975 Block mData;
00976 VLayerID mID;
00977 std::string mName;
00978 Stack mStack;
00979 VNGLayerType mType;
00980 VNRealFormat mFormat;
00981 GeometryNode& mNode;
00982 uint32 mDefaultInt;
00983 real64 mDefaultReal;
00984 };
00985
00986
00987
00990 class GeometryLayerObserver : public Observer<GeometryLayerObserver>
00991 {
00992 public:
00998 virtual void onSetSlot(GeometryLayer& layer, uint32 slotID, const void* data);
01003 virtual void onSetName(GeometryLayer& layer, const std::string& name);
01007 virtual void onDestroy(GeometryLayer& layer);
01008 };
01009
01010
01011
01012 class Bone : public Observable<BoneObserver>
01013 {
01014 public:
01015 void destroy(void);
01016 const Vector3d getPosition(void) const;
01017 void setPosition(const Vector3d& position);
01018 const Quaternion64 getRotation(void) const;
01019 void setRotation(const Quaternion64& rotation);
01020 const std::string& getCurveLabel(void) const;
01021 void setCurveLabel(const std::string& label);
01022 uint16 getID(void) const;
01023 private:
01024 Bone(uint16 ID,
01025 const std::string& weight,
01026 const std::string& reference,
01027 const Vector3d& position,
01028 const Quaternion64& rotation,
01029 const std::string& curveLabel);
01030 uint16 mID;
01031 std::string mWeight;
01032 std::string mReference;
01033 Vector3d mPosition;
01034 Quaternion64 mRotation;
01035 std::string mCurveLabel;
01036 };
01037
01038
01039
01040 class BoneObserver : public Observer<BoneObserver>
01041 {
01042 public:
01043 virtual void onDestroy(Bone& bone);
01044 };
01045
01046
01047
01050 class GeometryNode : public Node
01051 {
01052 friend class GeometryLayer;
01053 friend class Session;
01054 public:
01064 void createLayer(const std::string& name,
01065 VNGLayerType type,
01066 uint32 defaultInt = 0,
01067 real64 defaultReal = 0.0);
01073 bool getBaseMesh(BaseMesh& mesh);
01077 GeometryLayer* getLayerByID(VLayerID ID);
01081 const GeometryLayer* getLayerByID(VLayerID ID) const;
01085 GeometryLayer* getLayerByIndex(unsigned int index);
01089 const GeometryLayer* getLayerByIndex(unsigned int index) const;
01093 GeometryLayer* getLayerByName(const std::string& name);
01097 const GeometryLayer* getLayerByName(const std::string& name) const;
01100 bool isVertex(uint32 vertexID) const;
01103 bool isPolygon(uint32 polygonID) const;
01109 bool getBaseVertex(uint32 vertexID, BaseVertex& vertex) const;
01115 bool getBasePolygon(uint32 polygonID, BasePolygon& polygon) const;
01123 void setBaseVertex(uint32 vertexID, const BaseVertex& vertex);
01131 void setBasePolygon(uint32 polygonID, const BasePolygon& polygon);
01138 void deleteVertex(uint32 vertexID);
01145 void deletePolygon(uint32 polygonID);
01148 size_t getVertexSize(void) const;
01151 size_t getPolygonSize(void) const;
01155 GeometryLayer* getVertexCreaseLayer(void);
01159 const std::string& getVertexCreaseLayerName(void) const;
01162 uint32 getVertexDefaultCrease(void) const;
01166 void setVertexDefaultCrease(uint32 crease);
01170 GeometryLayer* getEdgeCreaseLayer(void);
01174 const std::string& getEdgeCreaseLayerName(void) const;
01177 uint32 getEdgeDefaultCrease(void) const;
01181 void setEdgeDefaultCrease(uint32 crease);
01184 uint32 getHighestVertexID(void) const;
01188 uint32 getFirstFreeVertexID(void) const;
01191 uint32 getHighestPolygonID(void) const;
01195 uint32 getFirstFreePolygonID(void) const;
01198 uint32 getVertexCount(void) const;
01201 uint32 getPolygonCount(void) const;
01202 private:
01203 GeometryNode(VNodeID ID, VNodeOwner owner, Session& session);
01204 ~GeometryNode(void);
01205 static void initialize(void);
01206 static void receiveGeometryLayerCreate(void* data, VNodeID ID, VLayerID layerID, const char* name, VNGLayerType type, uint32 defaultInt, real64 defaultReal);
01207 static void receiveGeometryLayerDestroy(void* data, VNodeID ID, VLayerID layerID);
01208 static void receiveCreaseSetVertex(void* user, VNodeID nodeID, const char *layer, uint32 def_crease);
01209 static void receiveCreaseSetEdge(void* user, VNodeID nodeID, const char *layer, uint32 def_crease);
01210 static void receiveBoneCreate(void* user, VNodeID nodeID, uint16 bone_id, const char *weight, const char *reference, uint32 parent, real64 pos_x, real64 pos_y, real64 pos_z, real64 rot_x, real64 rot_y, real64 rot_z, real64 rot_w);
01211 static void receiveBoneDestroy(void* user, VNodeID nodeID, uint16 bone_id);
01212 static void receiveVertexDeleteReal32(void* user, VNodeID nodeID, uint32 vertexID);
01213 static void receiveVertexDeleteReal64(void* user, VNodeID nodeID, uint32 vertexID);
01214 typedef std::vector<bool> ValidityMap;
01215 typedef std::vector<GeometryLayer*> LayerList;
01216 typedef std::map<uint32,uint32> VertexIndexMap;
01217 LayerList mLayers;
01218 GeometryLayer* mBaseVertexLayer;
01219 GeometryLayer* mBasePolygonLayer;
01220 ValidityMap mValidVertices;
01221 ValidityMap mValidPolygons;
01222 std::string mVertexCreases;
01223 uint32 mVertexDefaultCrease;
01224 std::string mEdgeCreases;
01225 uint32 mEdgeDefaultCrease;
01226 uint32 mHighestVertexID;
01227 uint32 mHighestPolygonID;
01228 uint32 mFirstFreeVertexID;
01229 uint32 mFirstFreePolygonID;
01230 uint32 mVertexCount;
01231 uint32 mPolygonCount;
01232 };
01233
01234
01235
01238 class GeometryNodeObserver : public NodeObserver
01239 {
01240 public:
01246 virtual void onCreateVertex(GeometryNode& node, uint32 vertexID, const BaseVertex& vertex);
01252 virtual void onChangeBaseVertex(GeometryNode& node, uint32 vertexID, const BaseVertex& vertex);
01257 virtual void onDeleteVertex(GeometryNode& node, uint32 vertexID);
01263 virtual void onCreatePolygon(GeometryNode& node, uint32 polygonID, const BasePolygon& polygon);
01269 virtual void onChangeBasePolygon(GeometryNode& node, uint32 polygonID, const BasePolygon& polygon);
01274 virtual void onDeletePolygon(GeometryNode& node, uint32 polygonID);
01279 virtual void onCreateLayer(GeometryNode& node, GeometryLayer& layer);
01284 virtual void onDestroyLayer(GeometryNode& node, GeometryLayer& layer);
01285 };
01286
01287
01288
01289 struct MethodParam
01290 {
01291 MethodParam(const std::string& name, VNOParamType type);
01292 size_t getSize(void) const;
01293 std::string mName;
01294 VNOParamType mType;
01295 };
01296
01297
01298
01299 typedef std::vector<MethodParam> MethodParamList;
01300
01301
01302
01303 typedef std::vector<VNOParam> MethodArgumentList;
01304
01305
01306
01309 class Method : public Versioned, public Observable<MethodObserver>
01310 {
01311 friend class MethodGroup;
01312 public:
01318 void destroy(void);
01324 bool call(const MethodArgumentList& arguments, VNodeID senderID = (VNodeID) ~0);
01327 uint16 getID(void) const;
01330 const std::string& getName(void) const;
01331 void setName(const std::string& name);
01334 uint8 getParamCount(void) const;
01338 const MethodParam& getParam(uint8 index);
01341 MethodGroup& getGroup(void) const;
01342 private:
01343 Method(uint16 ID, const std::string& name, MethodGroup& group);
01344 static void initialize(void);
01345 static void receiveMethodCall(void* user, VNodeID nodeID, uint16 groupID, uint16 methodID, VNodeID senderID, const VNOPackedParams* arguments);
01346 typedef std::vector<VNOParamType> ParamTypeList;
01347 MethodParamList mParams;
01348 ParamTypeList mTypes;
01349 uint16 mID;
01350 std::string mName;
01351 MethodGroup& mGroup;
01352 };
01353
01354
01355
01358 class MethodObserver : public Observer<MethodObserver>
01359 {
01360 public:
01365 virtual void onCall(Method& method, const MethodArgumentList& arguments);
01366 virtual void onSetName(Method& method, const std::string& name);
01370 virtual void onDestroy(Method& method);
01371 };
01372
01373
01374
01377 class MethodGroup : public Versioned, public Observable<MethodGroupObserver>
01378 {
01379 friend class ObjectNode;
01380 public:
01386 void destroy(void);
01394 void createMethod(const std::string& name, const MethodParamList& parameters);
01398 Method* getMethodByID(uint16 methodID);
01402 const Method* getMethodByID(uint16 methodID) const;
01406 Method* getMethodByIndex(unsigned int index);
01410 const Method* getMethodByIndex(unsigned int index) const;
01414 Method* getMethodByName(const std::string& name);
01418 const Method* getMethodByName(const std::string& name) const;
01421 unsigned int getMethodCount(void) const;
01424 const uint16 getID(void) const;
01427 const std::string& getName(void) const;
01430 ObjectNode& getNode(void) const;
01431 private:
01432 MethodGroup(uint16 ID, const std::string& name, ObjectNode& node);
01433 ~MethodGroup(void);
01434 static void initialize(void);
01435 static void receiveMethodCreate(void* user, VNodeID nodeID, uint16 groupID, uint16 methodID, const char* name, uint8 paramCount, const VNOParamType* paramTypes, const char** paramNames);
01436 static void receiveMethodDestroy(void* user, VNodeID nodeID, uint16 groupID, uint16 methodID);
01437 typedef std::vector<Method*> MethodList;
01438 MethodList mMethods;
01439 uint16 mID;
01440 std::string mName;
01441 ObjectNode& mNode;
01442 };
01443
01444
01445
01448 class MethodGroupObserver : public Observer<MethodGroupObserver>
01449 {
01450 public:
01455 virtual void onCreateMethod(MethodGroup& group, Method& method);
01460 virtual void onDestroyMethod(MethodGroup& group, Method& method);
01465 virtual void onSetName(MethodGroup& group, const std::string& name);
01469 virtual void onDestroy(MethodGroup& group);
01470 };
01471
01472
01473
01474
01475
01476 class Link : public Versioned, public Observable<LinkObserver>
01477 {
01478 friend class ObjectNode;
01479 public:
01485 void destroy(void);
01488 uint16 getID(void) const;
01491 VNodeID getLinkedNodeID(void) const;
01495 Node* getLinkedNode(void) const;
01496 void setLinkedNode(VNodeID nodeID);
01499 VNodeID getTargetNodeID(void) const;
01503 Node* getTargetNode(void) const;
01504 void setTargetNode(VNodeID nodeID);
01507 const std::string& getName(void) const;
01508 void setName(const std::string& name);
01511 ObjectNode& getNode(void) const;
01512 private:
01513 Link(uint16 ID, const std::string& name, VNodeID nodeID, VNodeID targetID, ObjectNode& node);
01514 void sendData(void);
01515 void receiveLinkSet(void* user, VNodeID nodeID, uint16 linkID, VNodeID linkedNodeID, const char* name, uint32 targetNodeID);
01516 class Data
01517 {
01518 public:
01519 VNodeID mNodeID;
01520 VNodeID mTargetID;
01521 std::string mName;
01522 };
01523 Data mState;
01524 Data mCache;
01525 uint16 mID;
01526 ObjectNode& mNode;
01527 };
01528
01529
01530
01531 class LinkObserver : public Observer<LinkObserver>
01532 {
01533 public:
01534 virtual void onSetLinkedNode(Link& link, VNodeID nodeID);
01535 virtual void onSetTargetNode(Link& link, VNodeID targetID);
01536 virtual void onSetName(Link& link, const std::string name);
01537 virtual void onDestroy(Link& link);
01538 };
01539
01540
01541
01544 class ObjectNode : public Node
01545 {
01546 friend class Session;
01547 public:
01554 void createMethodGroup(const std::string& name);
01563 void createLink(const std::string& name, VNodeID nodeID, VNodeID targetID = (VNodeID) ~0);
01567 bool isLight(void) const;
01571 void setLightIntensity(const ColorRGB& intensity);
01574 const ColorRGB& getLightIntensity(void) const;
01578 MethodGroup* getMethodGroupByID(uint16 groupID);
01582 const MethodGroup* getMethodGroupByID(uint16 groupID) const;
01586 MethodGroup* getMethodGroupByIndex(unsigned int index);
01590 const MethodGroup* getMethodGroupByIndex(unsigned int index) const;
01594 MethodGroup* getMethodGroupByName(const std::string& name);
01598 const MethodGroup* getMethodGroupByName(const std::string& name) const;
01601 unsigned int getMethodGroupCount(void) const;
01605 Link* getLinkByID(uint16 groupID);
01609 const Link* getLinkByID(uint16 groupID) const;
01613 Link* getLinkByIndex(unsigned int index);
01617 const Link* getLinkByIndex(unsigned int index) const;
01621 Link* getLinkByName(const std::string& name);
01625 const Link* getLinkByName(const std::string& name) const;
01628 unsigned int getLinkCount(void) const;
01632 Node* getNodeByLinkName(const std::string& name) const;
01633 void setTranslation(const Translation& translation);
01634 void setRotation(const Rotation& rotation);
01637 const Vector3d& getPosition(void) const;
01644 void setPosition(const Vector3d& position);
01647 const Vector3d& getSpeed(void) const;
01654 void setSpeed(const Vector3d& speed);
01657 const Vector3d& getAccel(void) const;
01664 void setAccel(const Vector3d& accel);
01667 const Quaternion64& getRotation(void) const;
01674 void setRotation(const Quaternion64& rotation);
01675 const Quaternion64& getRotationSpeed(void) const;
01676 void setRotationSpeed(const Quaternion64& speed);
01677 const Quaternion64& getRotationAccel(void) const;
01678 void setRotationAccel(const Quaternion64& accel);
01681 const Vector3d& getScale(void) const;
01685 void setScale(const Vector3d& scale);
01686 private:
01687 ObjectNode(VNodeID ID, VNodeOwner owner, Session& session);
01688 ~ObjectNode(void);
01689 void sendTranslation(void);
01690 void sendRotation(void);
01691 static void initialize(void);
01692 static void receiveTransformPosReal32(void* user, VNodeID nodeID, uint32 seconds, uint32 fraction, const real32* pos, const real32* speed, const real32* accelerate, const real32* dragNormal, real32 drag);
01693 static void receiveTransformRotReal32(void* user, VNodeID nodeID, uint32 seconds, uint32 fraction, const VNQuat32* rot, const VNQuat32* speed, const VNQuat32* accelerate, const VNQuat32* dragNormal, real32 drag);
01694 static void receiveTransformScaleReal32(void* user, VNodeID nodeID, real32 scaleX, real32 scaleY, real32 scaleZ);
01695 static void receiveTransformPosReal64(void* user, VNodeID nodeID, uint32 seconds, uint32 fraction, const real64* pos, const real64* speed, const real64* accelerate, const real64* dragNormal, real64 drag);
01696 static void receiveTransformRotReal64(void* user, VNodeID nodeID, uint32 seconds, uint32 fraction, const VNQuat64* rot, const VNQuat64* speed, const VNQuat64* accelerate, const VNQuat64* dragNormal, real64 drag);
01697 static void receiveTransformScaleReal64(void* user, VNodeID nodeID, real64 scaleX, real64 scaleY, real64 scaleZ);
01698 static void receiveLightSet(void* user, VNodeID nodeID, real64 lightR, real64 lightG, real64 lightB);
01699 static void receiveLinkSet(void* user, VNodeID nodeID, uint16 linkID, VNodeID linkedNodeID, const char* name, uint32 targetNodeID);
01700 static void receiveLinkDestroy(void* user, VNodeID nodeID, uint16 linkID);
01701 static void receiveMethodGroupCreate(void* user, VNodeID nodeID, uint16 groupID, const char* name);
01702 static void receiveMethodGroupDestroy(void* user, VNodeID nodeID, uint16 groupID);
01703 static void receiveAnimRun(void* user, VNodeID nodeID, uint16 linkID, uint32 seconds, uint32 fraction, real64 pos, real64 speed, real64 accel, real64 scale, real64 scaleSpeed);
01704 typedef std::vector<MethodGroup*> MethodGroupList;
01705 typedef std::vector<Link*> LinkList;
01706 MethodGroupList mGroups;
01707 LinkList mLinks;
01708 Translation mTranslation;
01709 Translation mTranslationCache;
01710 Rotation mRotation;
01711 Rotation mRotationCache;
01712 Vector3d mScale;
01713 ColorRGB mIntensity;
01714 };
01715
01716
01717
01720 class ObjectNodeObserver : public NodeObserver
01721 {
01722 public:
01727 virtual void onCreateMethodGroup(ObjectNode& node, MethodGroup& group);
01732 virtual void onDestroyMethodGroup(ObjectNode& node, MethodGroup& group);
01737 virtual void onCreateLink(ObjectNode& node, Link& link);
01742 virtual void onDestroyLink(ObjectNode& node, Link& link);
01743 virtual void onSetPosition(ObjectNode& node, Vector3d& position);
01744 virtual void onSetRotation(ObjectNode& node, Quaternion64& rotation);
01745 virtual void onSetScale(ObjectNode& node, Vector3d& scale);
01746 virtual void onSetLightIntensity(ObjectNode& node, const ColorRGB& color);
01747 };
01748
01749
01750
01753 class BitmapLayer : public Versioned, public Observable<BitmapLayerObserver>
01754 {
01755 friend class BitmapNode;
01756 public:
01757 void destroy(void);
01758 void getTile(uint16 tileX, uint16 tileY, uint16 z, VNBTile& tile);
01759 void setTile(uint16 tileX, uint16 tileY, uint16 z, const VNBTile& tile);
01760 VLayerID getID(void) const;
01761 const std::string& getName(void) const;
01762 VNBLayerType getType(void) const;
01763 BitmapNode& getNode(void) const;
01764 private:
01765 BitmapLayer(VLayerID ID, const std::string& name, BitmapNode& node, VNBLayerType type);
01766 static void initialize(void);
01767 static void receiveTileSet(void* user, VNodeID nodeID, VLayerID layerID, uint16 tileX, uint16 tileY, uint16 z, VNBLayerType type, const VNBTile* data);
01768 VLayerID mID;
01769 std::string mName;
01770 BitmapNode& mNode;
01771 VNBLayerType mType;
01772 };
01773
01774
01775
01778 class BitmapLayerObserver : public Observer<BitmapLayerObserver>
01779 {
01780 public:
01781 virtual void setTile(BitmapLayer& layer, uint16 tileX, uint16 tileY, uint16 z, const VNBTile& tile);
01782 virtual void onSetType(BitmapLayer& layer, VNBLayerType type);
01783 virtual void onSetName(BitmapLayer& layer, const std::string name);
01784 virtual void onDestroy(BitmapLayer& layer);
01785 };
01786
01787
01788
01791 class BitmapNode : public Node
01792 {
01793 friend class Session;
01794 public:
01795 void createLayer(const std::string& name, VNBLayerType type);
01799 BitmapLayer* getLayerByID(VLayerID ID);
01803 const BitmapLayer* getLayerByID(VLayerID ID) const;
01807 BitmapLayer* getLayerByIndex(unsigned int index);
01811 const BitmapLayer* getLayerByIndex(unsigned int index) const;
01815 BitmapLayer* getLayerByName(const std::string& name);
01819 const BitmapLayer* getLayerByName(const std::string& name) const;
01820 uint16 getLayerCount(void) const;
01821 void setDimensions(uint16 width, uint16 height, uint16 depth = 1);
01822 uint16 getWidth(void) const;
01823 uint16 getHeight(void) const;
01824 uint16 getDepth(void) const;
01825 unsigned int getDimensionCount(void) const;
01826 private:
01827 BitmapNode(VNodeID ID, VNodeOwner owner, Session& session);
01828 ~BitmapNode(void);
01829 static void initialize(void);
01830 static void receiveDimensionsSet(void* user, VNodeID nodeID, uint16 width, uint16 height, uint16 depth);
01831 static void receiveLayerCreate(void* user, VNodeID nodeID, VLayerID layerID, const char* name, VNBLayerType type);
01832 static void receiveLayerDestroy(void* user, VNodeID nodeID, VLayerID layerID);
01833 typedef std::vector<BitmapLayer*> LayerList;
01834 LayerList mLayers;
01835 uint16 mWidth;
01836 uint16 mHeight;
01837 uint16 mDepth;
01838 };
01839
01840
01841
01844 class BitmapNodeObserver : public NodeObserver
01845 {
01846 public:
01847 virtual void onSetDimensions(BitmapNode& node, uint16 width, uint16 height, uint16 depth);
01848 virtual void onCreateLayer(BitmapNode& node, BitmapLayer& layer);
01849 virtual void onDestroyLayer(BitmapNode& node, BitmapLayer& layer);
01850 };
01851
01852
01853
01856 class Fragment : public Versioned, public Observable<FragmentObserver>
01857 {
01858 friend class MaterialNode;
01859 public:
01860 void destroy(void);
01861 VNMFragmentID getID(void) const;
01862 VNMFragmentType getType(void) const;
01863 const VMatFrag& getValue(void) const;
01864 MaterialNode& getNode(void) const;
01865 private:
01866 Fragment(VNMFragmentID ID, MaterialNode& node, VNMFragmentType type, const VMatFrag& value);
01867 VNMFragmentID mID;
01868 VNMFragmentType mType;
01869 VMatFrag mValue;
01870 MaterialNode& mNode;
01871 };
01872
01873
01874
01877 class FragmentObserver : public Observer<FragmentObserver>
01878 {
01879 public:
01880 virtual void onSetType(Fragment& fragment, VNMFragmentType type);
01881 virtual void onSetValue(Fragment& fragment, const VMatFrag& value);
01882 virtual void onDestroy(Fragment& fragment);
01883 };
01884
01885
01886
01889 class MaterialNode : public Node
01890 {
01891 friend class Session;
01892 public:
01893 void createFragment(VNMFragmentID ID, VNMFragmentType type, const VMatFrag& value);
01898 Fragment* getFragmentByID(VNMFragmentID ID);
01903 const Fragment* getFragmentByID(VNMFragmentID ID) const;
01908 Fragment* getFragmentByIndex(unsigned int index);
01913 const Fragment* getFragmentByIndex(unsigned int index) const;
01918 Fragment* getFragmentByName(const std::string& name);
01923 const Fragment* getFragmentByName(const std::string& name) const;
01926 uint16 getFragmentCount(void) const;
01927 private:
01928 MaterialNode(VNodeID ID, VNodeOwner owner, Session& session);
01929 ~MaterialNode(void);
01930 static void initialize(void);
01931 static void receiveFragmentCreate(void* user, VNodeID nodeID, VNMFragmentID fragmentID, VNMFragmentType type, const VMatFrag* value);
01932 static void receiveFragmentDestroy(void* user, VNodeID nodeID, VNMFragmentID fragmentID);
01933 typedef std::vector<Fragment*> FragmentList;
01934 FragmentList mFragments;
01935 };
01936
01937
01938
01941 class MaterialNodeObserver : public NodeObserver
01942 {
01943 public:
01944 virtual void onCreateFragment(MaterialNode& node, Fragment& fragment);
01945 virtual void onDestroyFragment(MaterialNode& node, Fragment& fragment);
01946 };
01947
01948
01949
01952 class Session : public Versioned, public Observable<SessionObserver>
01953 {
01954 public:
01957 enum State
01958 {
01961 CONNECTING,
01964 CONNECTED,
01968 TERMINATED,
01972 RELEASED,
01973 };
01976 void push(void);
01979 void pop(void);
01986 void terminate(const std::string& byebye);
01991 void release(void);
02001 void createNode(const std::string& name, VNodeType type);
02004 State getState(void) const;
02008 Node* getNodeByID(VNodeID ID);
02012 const Node* getNodeByID(VNodeID ID) const;
02016 Node* getNodeByIndex(unsigned int index);
02020 const Node* getNodeByIndex(unsigned int index) const;
02024 Node* getNodeByName(const std::string& name);
02028 const Node* getNodeByName(const std::string& name) const;
02031 unsigned int getNodeCount(void) const;
02034 Node* getAvatarNode(void);
02037 const Node* getAvatarNode(void) const;
02040 const std::string& getAddress(void) const;
02047 static Session* create(const std::string& address,
02048 const std::string& username,
02049 const std::string& password,
02050 unsigned int typeMask = 0);
02055 static Session* find(const std::string& address);
02062 static void update(uint32 microseconds);
02066 static void terminateAll(const std::string& byebye);
02069 static Session* getCurrent(void);
02074 static Session* getByIndex(unsigned int index);
02077 static unsigned int getCount(void);
02078 private:
02079 Session(const std::string& address,
02080 const std::string& username,
02081 VSession internal);
02082 ~Session(void);
02083 static void receiveAccept(void* user, VNodeID avatarID, const char* address, uint8* hostID);
02084 static void receiveTerminate(void* user, const char* address, const char* byebye);
02085 static void receiveNodeCreate(void* user, VNodeID ID, VNodeType type, VNodeOwner owner);
02086 static void receiveNodeDestroy(void* user, VNodeID ID);
02087 class PendingNode
02088 {
02089 public:
02090 PendingNode(const std::string& name, VNodeType type);
02091 std::string mName;
02092 VNodeType mType;
02093 };
02094 typedef std::list<Session*> SessionList;
02095 typedef std::stack<Session*> SessionStack;
02096 typedef std::list<PendingNode> PendingList;
02097 typedef std::vector<Node*> NodeList;
02098 NodeList mNodes;
02099 PendingList mPending;
02100 std::string mAddress;
02101 std::string mUserName;
02102 VSession mInternal;
02103 VNodeID mAvatarID;
02104 State mState;
02105 uint32 mTypeMask;
02106 static SessionList msSessions;
02107 static SessionStack msStack;
02108 static Session* msCurrent;
02109 static bool msInitialized;
02110 };
02111
02112
02113
02114 class SessionObserver : public Observer<SessionObserver>
02115 {
02116 public:
02120 virtual void onAccept(Session& session);
02125 virtual void onTerminate(Session& session, const std::string& byebye);
02129 virtual void onDestroy(Session& session);
02134 virtual void onCreateNode(Session& session, Node& node);
02139 virtual void onDestroyNode(Session& session, Node& node);
02140 };
02141
02142
02143
02144 }
02145 }
02146
02147 #endif
02148