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