| 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( ( (flags & NO_COLOR) == 0 ) && |
|---|
| 72 | ( colorIndex >= 0 ) ) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | if (_parent.valid()) |
|---|
| 80 | _parent->addVertex(vertex); |
|---|
| 81 | } |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | REGISTER_FLTRECORD(VertexC, VERTEX_C_OP) |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | class VertexCN : public Record |
|---|
| 89 | { |
|---|
| 90 | public: |
|---|
| 91 | |
|---|
| 92 | VertexCN() {} |
|---|
| 93 | |
|---|
| 94 | META_Record(VertexCN) |
|---|
| 95 | |
|---|
| 96 | protected: |
|---|
| 97 | |
|---|
| 98 | virtual ~VertexCN() {} |
|---|
| 99 | |
|---|
| 100 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 101 | { |
|---|
| 102 | in.readInt16(); |
|---|
| 103 | uint16 flags = in.readUInt16(); |
|---|
| 104 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 105 | osg::Vec3f normal = in.readVec3f(); |
|---|
| 106 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 107 | int colorIndex = in.readInt32(-1); |
|---|
| 108 | |
|---|
| 109 | Vertex vertex; |
|---|
| 110 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 111 | vertex.setNormal(normal); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | if (flags & PACKED_COLOR) |
|---|
| 115 | vertex.setColor(packedColor); |
|---|
| 116 | else if( ( (flags & NO_COLOR) == 0 ) && |
|---|
| 117 | ( colorIndex >= 0 ) ) |
|---|
| 118 | { |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | if (_parent.valid()) |
|---|
| 125 | _parent->addVertex(vertex); |
|---|
| 126 | } |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | REGISTER_FLTRECORD(VertexCN, VERTEX_CN_OP) |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | class VertexCT : public Record |
|---|
| 134 | { |
|---|
| 135 | public: |
|---|
| 136 | |
|---|
| 137 | VertexCT() {} |
|---|
| 138 | |
|---|
| 139 | META_Record(VertexCT) |
|---|
| 140 | |
|---|
| 141 | protected: |
|---|
| 142 | |
|---|
| 143 | virtual ~VertexCT() {} |
|---|
| 144 | |
|---|
| 145 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 146 | { |
|---|
| 147 | in.readInt16(); |
|---|
| 148 | uint16 flags = in.readUInt16(); |
|---|
| 149 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 150 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 151 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 152 | int colorIndex = in.readInt32(-1); |
|---|
| 153 | |
|---|
| 154 | Vertex vertex; |
|---|
| 155 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 156 | vertex.setUV(0,uv); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | if (flags & PACKED_COLOR) |
|---|
| 160 | vertex.setColor(packedColor); |
|---|
| 161 | else if( ( (flags & NO_COLOR) == 0 ) && |
|---|
| 162 | ( colorIndex >= 0 ) ) |
|---|
| 163 | { |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | if (_parent.valid()) |
|---|
| 170 | _parent->addVertex(vertex); |
|---|
| 171 | } |
|---|
| 172 | }; |
|---|
| 173 | |
|---|
| 174 | REGISTER_FLTRECORD(VertexCT, VERTEX_CT_OP) |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | class VertexCNT : public Record |
|---|
| 179 | { |
|---|
| 180 | public: |
|---|
| 181 | |
|---|
| 182 | VertexCNT() {} |
|---|
| 183 | |
|---|
| 184 | META_Record(VertexCNT) |
|---|
| 185 | |
|---|
| 186 | protected: |
|---|
| 187 | |
|---|
| 188 | virtual ~VertexCNT() {} |
|---|
| 189 | |
|---|
| 190 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 191 | { |
|---|
| 192 | in.readInt16(); |
|---|
| 193 | uint16 flags = in.readUInt16(); |
|---|
| 194 | osg::Vec3d coord = in.readVec3d(); |
|---|
| 195 | osg::Vec3f normal = in.readVec3f(); |
|---|
| 196 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 197 | osg::Vec4f packedColor = in.readColor32(); |
|---|
| 198 | int colorIndex = in.readInt32(-1); |
|---|
| 199 | |
|---|
| 200 | Vertex vertex; |
|---|
| 201 | vertex.setCoord(coord*document.unitScale()); |
|---|
| 202 | vertex.setNormal(normal); |
|---|
| 203 | vertex.setUV(0,uv); |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | if (!coord.valid()) |
|---|
| 207 | { |
|---|
| 208 | OSG_NOTICE<<"Warning: data error detected in VertexCNT::readRecord coord="<<coord.x()<<" "<<coord.y()<<" "<<coord.z()<<std::endl; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | if (!normal.valid()) |
|---|
| 212 | { |
|---|
| 213 | OSG_NOTICE<<"Warning: data error detected in VertexCNT::readRecord normal="<<normal.x()<<" "<<normal.y()<<" "<<normal.z()<<std::endl; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (!uv.valid()) |
|---|
| 217 | { |
|---|
| 218 | OSG_NOTICE<<"Warning: data error detected in VertexCNT::readRecord uv="<<uv.x()<<" "<<uv.y()<<std::endl; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | if (flags & PACKED_COLOR) |
|---|
| 223 | vertex.setColor(packedColor); |
|---|
| 224 | else if( ( (flags & NO_COLOR) == 0 ) && |
|---|
| 225 | ( colorIndex >= 0 ) ) |
|---|
| 226 | { |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | if (_parent.valid()) |
|---|
| 233 | _parent->addVertex(vertex); |
|---|
| 234 | } |
|---|
| 235 | }; |
|---|
| 236 | |
|---|
| 237 | REGISTER_FLTRECORD(VertexCNT, VERTEX_CNT_OP) |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | class AbsoluteVertex : public Record |
|---|
| 245 | { |
|---|
| 246 | public: |
|---|
| 247 | |
|---|
| 248 | AbsoluteVertex() {} |
|---|
| 249 | |
|---|
| 250 | META_Record(AbsoluteVertex) |
|---|
| 251 | |
|---|
| 252 | protected: |
|---|
| 253 | |
|---|
| 254 | virtual ~AbsoluteVertex() {} |
|---|
| 255 | |
|---|
| 256 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 257 | { |
|---|
| 258 | int32 x = in.readInt32(); |
|---|
| 259 | int32 y = in.readInt32(); |
|---|
| 260 | int32 z = in.readInt32(); |
|---|
| 261 | |
|---|
| 262 | Vertex vertex; |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | if (in.getRecordBodySize() > (4+4+4)) |
|---|
| 269 | { |
|---|
| 270 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 271 | vertex.setUV(0,uv); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | if (_parent.valid()) |
|---|
| 275 | _parent->addVertex(vertex); |
|---|
| 276 | } |
|---|
| 277 | }; |
|---|
| 278 | |
|---|
| 279 | REGISTER_FLTRECORD(AbsoluteVertex, OLD_ABSOLUTE_VERTEX_OP) |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | class ShadedVertex : public Record |
|---|
| 287 | { |
|---|
| 288 | public: |
|---|
| 289 | |
|---|
| 290 | ShadedVertex() {} |
|---|
| 291 | |
|---|
| 292 | META_Record(ShadedVertex) |
|---|
| 293 | |
|---|
| 294 | protected: |
|---|
| 295 | |
|---|
| 296 | virtual ~ShadedVertex() {} |
|---|
| 297 | |
|---|
| 298 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 299 | { |
|---|
| 300 | int32 x = in.readInt32(); |
|---|
| 301 | int32 y = in.readInt32(); |
|---|
| 302 | int32 z = in.readInt32(); |
|---|
| 303 | in.readUInt8(); |
|---|
| 304 | in.readUInt8(); |
|---|
| 305 | int colorIndex = (int)in.readInt16(); |
|---|
| 306 | |
|---|
| 307 | Vertex vertex; |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | if (colorIndex >= 0) |
|---|
| 314 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | if (in.getRecordBodySize() > (4+4+4+1+1+2)) |
|---|
| 318 | { |
|---|
| 319 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 320 | vertex.setUV(0,uv); |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | if (_parent.valid()) |
|---|
| 324 | _parent->addVertex(vertex); |
|---|
| 325 | } |
|---|
| 326 | }; |
|---|
| 327 | |
|---|
| 328 | REGISTER_FLTRECORD(ShadedVertex, OLD_SHADED_VERTEX_OP) |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | class NormalVertex : public Record |
|---|
| 336 | { |
|---|
| 337 | public: |
|---|
| 338 | |
|---|
| 339 | NormalVertex() {} |
|---|
| 340 | |
|---|
| 341 | META_Record(NormalVertex) |
|---|
| 342 | |
|---|
| 343 | protected: |
|---|
| 344 | |
|---|
| 345 | virtual ~NormalVertex() {} |
|---|
| 346 | |
|---|
| 347 | virtual void readRecord(RecordInputStream& in, Document& document) |
|---|
| 348 | { |
|---|
| 349 | int32 x = in.readInt32(); |
|---|
| 350 | int32 y = in.readInt32(); |
|---|
| 351 | int32 z = in.readInt32(); |
|---|
| 352 | in.readUInt8(); |
|---|
| 353 | in.readUInt8(); |
|---|
| 354 | int colorIndex = (int)in.readInt16(); |
|---|
| 355 | osg::Vec3f normal = in.readVec3d(); |
|---|
| 356 | |
|---|
| 357 | Vertex vertex; |
|---|
| 358 | vertex.setCoord(osg::Vec3(x,y,z) * document.unitScale()); |
|---|
| 359 | vertex.setNormal(normal / (float)(1L<<30)); |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | if (colorIndex >= 0) |
|---|
| 363 | vertex.setColor(getColorFromPool(colorIndex, document.getColorPool())); |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | if (in.getRecordBodySize() > (4+4+4+1+1+2+3*8)) |
|---|
| 367 | { |
|---|
| 368 | osg::Vec2f uv = in.readVec2f(); |
|---|
| 369 | vertex.setUV(0,uv); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | if (_parent.valid()) |
|---|
| 373 | _parent->addVertex(vertex); |
|---|
| 374 | } |
|---|
| 375 | }; |
|---|
| 376 | |
|---|
| 377 | REGISTER_FLTRECORD(NormalVertex, OLD_NORMAL_VERTEX_OP) |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | } |
|---|