| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include "Record.h" |
|---|
| 21 | #include "Registry.h" |
|---|
| 22 | #include "Document.h" |
|---|
| 23 | #include "RecordInputStream.h" |
|---|
| 24 | |
|---|
| 25 | namespace flt { |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | osg::Vec4 getColorFromPool(int index, const ColorPool* colorPool) |
|---|
| 29 | { |
|---|
| 30 | osg::Vec4 color(1,1,1,1); |
|---|
| 31 | if (colorPool) |
|---|
| 32 | color = colorPool->getColor(index); |
|---|
| 33 | return color; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | enum Flags |
|---|
| 39 | { |
|---|
| 40 | START_HARD_EDGE = (0x8000 >> 0), |
|---|
| 41 | NORMAL_FROZEN = (0x8000 >> 1), |
|---|
| 42 | NO_COLOR = (0x8000 >> 2), |
|---|
| 43 | PACKED_COLOR = (0x8000 >> 3) |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | class VertexC : public Record |
|---|
| 48 | { |
|---|
| 49 | public: |
|---|
| 50 | |
|---|
| 51 | VertexC() {} |
|---|
| 52 | |
|---|
| 53 | META_Record(VertexC) |
|---|
| 54 | |
|---|
| 55 | virtual ~VertexC() {} |
|---|
| 56 | |
|---|
| 57 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 58 | { |
|---|
| 59 | in.readInt16(); |
|---|
| 60 | uint16 flags = in.readUInt16(); |
|---|
| 61 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 62 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 63 | int colorIndex = in.readInt32(-1); |
|---|
| 64 | |
|---|
| 65 | Vertex vertex; |
|---|
| 66 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | if (flags & PACKED_COLOR) |
|---|
| 70 | vertex.setColor(packedColor); |
|---|
| 71 | else if (colorIndex >= 0) |
|---|
| 72 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 73 | |
|---|
| 74 | if (_parent.valid()) |
|---|
| 75 | _parent->addVertex(vertex); |
|---|
| 76 | } |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | RegisterRecordProxy<VertexC> g_VertexC(VERTEX_C_OP); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | class VertexCN : public Record |
|---|
| 83 | { |
|---|
| 84 | public: |
|---|
| 85 | |
|---|
| 86 | VertexCN() {} |
|---|
| 87 | |
|---|
| 88 | META_Record(VertexCN) |
|---|
| 89 | |
|---|
| 90 | protected: |
|---|
| 91 | |
|---|
| 92 | virtual ~VertexCN() {} |
|---|
| 93 | |
|---|
| 94 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 95 | { |
|---|
| 96 | in.readInt16(); |
|---|
| 97 | uint16 flags = in.readUInt16(); |
|---|
| 98 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 99 | osg::Vec3f normal = in.readVec3f(); |
|---|
| 100 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 101 | int colorIndex = in.readInt32(-1); |
|---|
| 102 | |
|---|
| 103 | Vertex vertex; |
|---|
| 104 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 105 | vertex.setNormal(normal); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | if (flags & PACKED_COLOR) |
|---|
| 109 | vertex.setColor(packedColor); |
|---|
| 110 | else if (colorIndex >= 0) |
|---|
| 111 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 112 | |
|---|
| 113 | if (_parent.valid()) |
|---|
| 114 | _parent->addVertex(vertex); |
|---|
| 115 | } |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | RegisterRecordProxy<VertexCN> g_VertexCN(VERTEX_CN_OP); |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | class VertexCT : public Record |
|---|
| 122 | { |
|---|
| 123 | public: |
|---|
| 124 | |
|---|
| 125 | VertexCT() {} |
|---|
| 126 | |
|---|
| 127 | META_Record(VertexCT) |
|---|
| 128 | |
|---|
| 129 | protected: |
|---|
| 130 | |
|---|
| 131 | virtual ~VertexCT() {} |
|---|
| 132 | |
|---|
| 133 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 134 | { |
|---|
| 135 | in.readInt16(); |
|---|
| 136 | uint16 flags = in.readUInt16(); |
|---|
| 137 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 138 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 139 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 140 | int colorIndex = in.readInt32(-1); |
|---|
| 141 | |
|---|
| 142 | Vertex vertex; |
|---|
| 143 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 144 | vertex.setUV(0,uv); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | if (flags & PACKED_COLOR) |
|---|
| 148 | vertex.setColor(packedColor); |
|---|
| 149 | else if (colorIndex >= 0) |
|---|
| 150 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 151 | |
|---|
| 152 | if (_parent.valid()) |
|---|
| 153 | _parent->addVertex(vertex); |
|---|
| 154 | } |
|---|
| 155 | }; |
|---|
| 156 | |
|---|
| 157 | RegisterRecordProxy<VertexCT> g_VertexCT(VERTEX_CT_OP); |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | class VertexCNT : public Record |
|---|
| 161 | { |
|---|
| 162 | public: |
|---|
| 163 | |
|---|
| 164 | VertexCNT() {} |
|---|
| 165 | |
|---|
| 166 | META_Record(VertexCNT) |
|---|
| 167 | |
|---|
| 168 | protected: |
|---|
| 169 | |
|---|
| 170 | virtual ~VertexCNT() {} |
|---|
| 171 | |
|---|
| 172 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 173 | { |
|---|
| 174 | in.readInt16(); |
|---|
| 175 | uint16 flags = in.readUInt16(); |
|---|
| 176 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 177 | osg::Vec3f normal = in.readVec3f(); |
|---|
| 178 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 179 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 180 | int colorIndex = in.readInt32(-1); |
|---|
| 181 | |
|---|
| 182 | Vertex vertex; |
|---|
| 183 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 184 | vertex.setNormal(normal); |
|---|
| 185 | vertex.setUV(0,uv); |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | if (!coord.valid()) |
|---|
| 189 | { |
|---|
| 190 | osg::notify(osg::NOTICE)<<"Warning: data error detected in VertexCNT::readRecord coord="<<coord.x()<<" "<<coord.y()<<" "<<coord.z()<<std::endl; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if (!normal.valid()) |
|---|
| 194 | { |
|---|
| 195 | osg::notify(osg::NOTICE)<<"Warning: data error detected in VertexCNT::readRecord normal="<<normal.x()<<" "<<normal.y()<<" "<<normal.z()<<std::endl; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | if (!uv.valid()) |
|---|
| 199 | { |
|---|
| 200 | osg::notify(osg::NOTICE)<<"Warning: data error detected in VertexCNT::readRecord uv="<<uv.x()<<" "<<uv.y()<<std::endl; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | if (flags & PACKED_COLOR) |
|---|
| 205 | vertex.setColor(packedColor); |
|---|
| 206 | else if (colorIndex >= 0) |
|---|
| 207 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 208 | |
|---|
| 209 | if (_parent.valid()) |
|---|
| 210 | _parent->addVertex(vertex); |
|---|
| 211 | } |
|---|
| 212 | }; |
|---|
| 213 | |
|---|
| 214 | RegisterRecordProxy<VertexCNT> g_VertexCNT(VERTEX_CNT_OP); |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | class AbsoluteVertex : public Record |
|---|
| 221 | { |
|---|
| 222 | public: |
|---|
| 223 | |
|---|
| 224 | AbsoluteVertex() {} |
|---|
| 225 | |
|---|
| 226 | META_Record(AbsoluteVertex) |
|---|
| 227 | |
|---|
| 228 | protected: |
|---|
| 229 | |
|---|
| 230 | virtual ~AbsoluteVertex() {} |
|---|
| 231 | |
|---|
| 232 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 233 | { |
|---|
| 234 | int32 x = in.readInt32(); |
|---|
| 235 | int32 y = in.readInt32(); |
|---|
| 236 | int32 z = in.readInt32(); |
|---|
| 237 | |
|---|
| 238 | Vertex vertex; |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | if (in.getRecordBodySize() > (4+4+4)) |
|---|
| 245 | { |
|---|
| 246 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 247 | vertex.setUV(0,uv); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | if (_parent.valid()) |
|---|
| 251 | _parent->addVertex(vertex); |
|---|
| 252 | } |
|---|
| 253 | }; |
|---|
| 254 | |
|---|
| 255 | RegisterRecordProxy<AbsoluteVertex> g_AbsoluteVertex(OLD_ABSOLUTE_VERTEX_OP); |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | class ShadedVertex : public Record |
|---|
| 262 | { |
|---|
| 263 | public: |
|---|
| 264 | |
|---|
| 265 | ShadedVertex() {} |
|---|
| 266 | |
|---|
| 267 | META_Record(ShadedVertex) |
|---|
| 268 | |
|---|
| 269 | protected: |
|---|
| 270 | |
|---|
| 271 | virtual ~ShadedVertex() {} |
|---|
| 272 | |
|---|
| 273 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 274 | { |
|---|
| 275 | int32 x = in.readInt32(); |
|---|
| 276 | int32 y = in.readInt32(); |
|---|
| 277 | int32 z = in.readInt32(); |
|---|
| 278 | in.readUInt8(); |
|---|
| 279 | in.readUInt8(); |
|---|
| 280 | int colorIndex = (int)in.readInt16(); |
|---|
| 281 | |
|---|
| 282 | Vertex vertex; |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | if (colorIndex >= 0) |
|---|
| 289 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | if (in.getRecordBodySize() > (4+4+4+1+1+2)) |
|---|
| 293 | { |
|---|
| 294 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 295 | vertex.setUV(0,uv); |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | if (_parent.valid()) |
|---|
| 299 | _parent->addVertex(vertex); |
|---|
| 300 | } |
|---|
| 301 | }; |
|---|
| 302 | |
|---|
| 303 | RegisterRecordProxy<ShadedVertex> g_ShadedVertex(OLD_SHADED_VERTEX_OP); |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | class NormalVertex : public Record |
|---|
| 310 | { |
|---|
| 311 | public: |
|---|
| 312 | |
|---|
| 313 | NormalVertex() {} |
|---|
| 314 | |
|---|
| 315 | META_Record(NormalVertex) |
|---|
| 316 | |
|---|
| 317 | protected: |
|---|
| 318 | |
|---|
| 319 | virtual ~NormalVertex() {} |
|---|
| 320 | |
|---|
| 321 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 322 | { |
|---|
| 323 | int32 x = in.readInt32(); |
|---|
| 324 | int32 y = in.readInt32(); |
|---|
| 325 | int32 z = in.readInt32(); |
|---|
| 326 | in.readUInt8(); |
|---|
| 327 | in.readUInt8(); |
|---|
| 328 | int colorIndex = (int)in.readInt16(); |
|---|
| 329 | osg::Vec3f normal = in.readVec3d(); |
|---|
| 330 | |
|---|
| 331 | Vertex vertex; |
|---|
| 332 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 333 | vertex.setNormal(normal / (float)(1L<<30)); |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | if (colorIndex >= 0) |
|---|
| 337 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | if (in.getRecordBodySize() > (4+4+4+1+1+2+3*8)) |
|---|
| 341 | { |
|---|
| 342 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 343 | vertex.setUV(0,uv); |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | if (_parent.valid()) |
|---|
| 347 | _parent->addVertex(vertex); |
|---|
| 348 | } |
|---|
| 349 | }; |
|---|
| 350 | |
|---|
| 351 | RegisterRecordProxy<NormalVertex> g_NormalVertex(OLD_NORMAL_VERTEX_OP); |
|---|
| 352 | |
|---|
| 353 | } |
|---|