| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "Node.h" |
|---|
| 16 | #include "MatrixTransform.h" |
|---|
| 17 | #include "Group.h" |
|---|
| 18 | #include "Object.h" |
|---|
| 19 | #include "StateSet.h" |
|---|
| 20 | #include "AnimationPathCallback.h" |
|---|
| 21 | #include "ClusterCullingCallback.h" |
|---|
| 22 | #include "VolumePropertyAdjustmentCallback.h" |
|---|
| 23 | |
|---|
| 24 | using namespace ive; |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | void Node::write(DataOutputStream* out){ |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | out->writeInt(IVENODE); |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 34 | if(obj){ |
|---|
| 35 | ((ive::Object*)(obj))->write(out); |
|---|
| 36 | } |
|---|
| 37 | else |
|---|
| 38 | out_THROW_EXCEPTION("Node::write(): Could not cast this osg::Node to an osg::Object."); |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | if ( out->getVersion() < VERSION_0012 ) |
|---|
| 43 | { |
|---|
| 44 | |
|---|
| 45 | out->writeString(getName()); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | out->writeBool( getCullingActive()); |
|---|
| 49 | |
|---|
| 50 | int nDesc = getDescriptions().size(); |
|---|
| 51 | out->writeInt(nDesc); |
|---|
| 52 | if(nDesc!=0){ |
|---|
| 53 | std::vector<std::string> desc = getDescriptions(); |
|---|
| 54 | for(int i=0;i<nDesc;i++) |
|---|
| 55 | out->writeString(desc[i]); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | out->writeBool( getStateSet()!=0); |
|---|
| 59 | if(getStateSet()) |
|---|
| 60 | out->writeStateSet(getStateSet()); |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | osg::AnimationPathCallback* nc = dynamic_cast<osg::AnimationPathCallback*>(getUpdateCallback()); |
|---|
| 64 | out->writeBool(nc!=0); |
|---|
| 65 | if(nc) |
|---|
| 66 | { |
|---|
| 67 | ((ive::AnimationPathCallback*)(nc))->write(out); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | if (out->getVersion() >= VERSION_0006) |
|---|
| 71 | { |
|---|
| 72 | osg::ClusterCullingCallback* ccc = dynamic_cast<osg::ClusterCullingCallback*>(getCullCallback()); |
|---|
| 73 | out->writeBool(ccc!=0); |
|---|
| 74 | if(ccc) |
|---|
| 75 | { |
|---|
| 76 | ((ive::ClusterCullingCallback*)(ccc))->write(out); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | if (out->getVersion() >= VERSION_0039) |
|---|
| 82 | { |
|---|
| 83 | osgVolume::PropertyAdjustmentCallback* pac = dynamic_cast<osgVolume::PropertyAdjustmentCallback*>(getEventCallback()); |
|---|
| 84 | out->writeBool(pac!=0); |
|---|
| 85 | if(pac) |
|---|
| 86 | { |
|---|
| 87 | ((ive::VolumePropertyAdjustmentCallback*)pac)->write(out); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if (out->getVersion() >= VERSION_0010) |
|---|
| 92 | { |
|---|
| 93 | const osg::BoundingSphere& bs = getInitialBound(); |
|---|
| 94 | out->writeBool(bs.valid()); |
|---|
| 95 | if (bs.valid()) |
|---|
| 96 | { |
|---|
| 97 | out->writeVec3(bs.center()); |
|---|
| 98 | out->writeFloat(bs.radius()); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | out->writeUInt(getNodeMask()); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void Node::read(DataInputStream* in){ |
|---|
| 108 | |
|---|
| 109 | int id = in->peekInt(); |
|---|
| 110 | |
|---|
| 111 | if(id == IVENODE){ |
|---|
| 112 | id = in->readInt(); |
|---|
| 113 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 114 | if(obj){ |
|---|
| 115 | ((ive::Object*)(obj))->read(in); |
|---|
| 116 | } |
|---|
| 117 | else |
|---|
| 118 | in_THROW_EXCEPTION("Node::read(): Could not cast this osg::Node to an osg::Object."); |
|---|
| 119 | |
|---|
| 120 | if ( in->getVersion() < VERSION_0012 ) |
|---|
| 121 | { |
|---|
| 122 | |
|---|
| 123 | setName(in->readString()); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | setCullingActive(in->readBool()); |
|---|
| 127 | |
|---|
| 128 | int nDesc = in->readInt(); |
|---|
| 129 | if(nDesc!=0){ |
|---|
| 130 | for(int i=0;i<nDesc;i++) |
|---|
| 131 | addDescription(in->readString()); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | if(in->readBool()) |
|---|
| 135 | { |
|---|
| 136 | setStateSet(in->readStateSet()); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | if(in->readBool()) |
|---|
| 141 | { |
|---|
| 142 | osg::AnimationPathCallback* nc = new osg::AnimationPathCallback(); |
|---|
| 143 | ((ive::AnimationPathCallback*)(nc))->read(in); |
|---|
| 144 | setUpdateCallback(nc); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | if (in->getVersion() >= VERSION_0006) |
|---|
| 148 | { |
|---|
| 149 | if(in->readBool()) |
|---|
| 150 | { |
|---|
| 151 | osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback(); |
|---|
| 152 | ((ive::ClusterCullingCallback*)(ccc))->read(in); |
|---|
| 153 | setCullCallback(ccc); |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | if (in->getVersion() >= VERSION_0039) |
|---|
| 158 | { |
|---|
| 159 | if(in->readBool()) |
|---|
| 160 | { |
|---|
| 161 | int pacID = in->peekInt(); |
|---|
| 162 | if (pacID==IVEVOLUMEPROPERTYADJUSTMENTCALLBACK) |
|---|
| 163 | { |
|---|
| 164 | osgVolume::PropertyAdjustmentCallback* pac = new osgVolume::PropertyAdjustmentCallback(); |
|---|
| 165 | ((ive::VolumePropertyAdjustmentCallback*)(pac))->read(in); |
|---|
| 166 | setEventCallback(pac); |
|---|
| 167 | } |
|---|
| 168 | else |
|---|
| 169 | { |
|---|
| 170 | in_THROW_EXCEPTION("Unknown event callback identification in Node::read()"); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | if (in->getVersion() >= VERSION_0010) |
|---|
| 177 | { |
|---|
| 178 | if (in->readBool()) |
|---|
| 179 | { |
|---|
| 180 | osg::BoundingSphere bs; |
|---|
| 181 | bs.center() = in->readVec3(); |
|---|
| 182 | bs.radius() = in->readFloat(); |
|---|
| 183 | setInitialBound(bs); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | setNodeMask(in->readUInt()); |
|---|
| 189 | } |
|---|
| 190 | else{ |
|---|
| 191 | in_THROW_EXCEPTION("Node::read(): Expected Node identification"); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|