| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #include "FltExportVisitor.h" |
|---|
| 18 | #include "ExportOptions.h" |
|---|
| 19 | #include "VertexPaletteManager.h" |
|---|
| 20 | #include "LightSourcePaletteManager.h" |
|---|
| 21 | #include "DataOutputStream.h" |
|---|
| 22 | #include "Opcodes.h" |
|---|
| 23 | #include <osg/Group> |
|---|
| 24 | #include <osg/Sequence> |
|---|
| 25 | #include <osg/LightSource> |
|---|
| 26 | #include <osg/LOD> |
|---|
| 27 | #include <osg/ProxyNode> |
|---|
| 28 | #include <osg/Switch> |
|---|
| 29 | #include <osgSim/MultiSwitch> |
|---|
| 30 | #include <osgSim/DOFTransform> |
|---|
| 31 | #include <osgSim/LightPointNode> |
|---|
| 32 | #include <osgSim/ObjectRecordData> |
|---|
| 33 | |
|---|
| 34 | #include <stdlib.h> |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #include "Pools.h" |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | namespace flt |
|---|
| 44 | { |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | void |
|---|
| 48 | FltExportVisitor::writeHeader( const std::string& headerName ) |
|---|
| 49 | { |
|---|
| 50 | int16 length; |
|---|
| 51 | int32 version; |
|---|
| 52 | const int ver = _fltOpt->getFlightFileVersionNumber(); |
|---|
| 53 | if (ver == ExportOptions::VERSION_15_7) |
|---|
| 54 | { |
|---|
| 55 | length = 304; |
|---|
| 56 | version = 1570; |
|---|
| 57 | } |
|---|
| 58 | else if (ver == ExportOptions::VERSION_15_8) |
|---|
| 59 | { |
|---|
| 60 | length = 324; |
|---|
| 61 | version = 1580; |
|---|
| 62 | } |
|---|
| 63 | else |
|---|
| 64 | { |
|---|
| 65 | length = 324; |
|---|
| 66 | version = 1610; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | int8 units; |
|---|
| 70 | switch( _fltOpt->getFlightUnits() ) |
|---|
| 71 | { |
|---|
| 72 | case ExportOptions::KILOMETERS: |
|---|
| 73 | units = 1; |
|---|
| 74 | break; |
|---|
| 75 | case ExportOptions::FEET: |
|---|
| 76 | units = 4; |
|---|
| 77 | break; |
|---|
| 78 | case ExportOptions::INCHES: |
|---|
| 79 | units = 5; |
|---|
| 80 | break; |
|---|
| 81 | case ExportOptions::NAUTICAL_MILES: |
|---|
| 82 | units = 8; |
|---|
| 83 | break; |
|---|
| 84 | default: |
|---|
| 85 | case ExportOptions::METERS: |
|---|
| 86 | units = 0; |
|---|
| 87 | break; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | static const unsigned int SAVE_VERTEX_NORMALS_BIT = 0x80000000u >> 0; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | uint32 flags( SAVE_VERTEX_NORMALS_BIT ); |
|---|
| 94 | |
|---|
| 95 | IdHelper id(*this, headerName); |
|---|
| 96 | id.dos_ = &_dos; |
|---|
| 97 | |
|---|
| 98 | _dos.writeInt16( (int16) HEADER_OP ); |
|---|
| 99 | _dos.writeInt16( length ); |
|---|
| 100 | _dos.writeID( id ); |
|---|
| 101 | _dos.writeInt32( version ); |
|---|
| 102 | _dos.writeInt32( 0 ); |
|---|
| 103 | |
|---|
| 104 | _dos.writeString( std::string(" "), 32 ); |
|---|
| 105 | _dos.writeInt16( 0 ); |
|---|
| 106 | _dos.writeInt16( 0 ); |
|---|
| 107 | _dos.writeInt16( 0 ); |
|---|
| 108 | _dos.writeInt16( 0 ); |
|---|
| 109 | _dos.writeInt16( 1 ); |
|---|
| 110 | _dos.writeInt8( units ); |
|---|
| 111 | _dos.writeInt8( 0 ); |
|---|
| 112 | _dos.writeUInt32( flags ); |
|---|
| 113 | _dos.writeFill( sizeof( int32 ) * 6 ); |
|---|
| 114 | _dos.writeInt32( 0 ); |
|---|
| 115 | _dos.writeFill( sizeof( int32 ) * 7 ); |
|---|
| 116 | _dos.writeInt16( 0 ); |
|---|
| 117 | _dos.writeInt16( 1 ); |
|---|
| 118 | _dos.writeInt32( 100 ); |
|---|
| 119 | _dos.writeFloat64( 0. ); |
|---|
| 120 | _dos.writeFloat64( 0. ); |
|---|
| 121 | _dos.writeFloat64( 0. ); |
|---|
| 122 | _dos.writeFloat64( 0. ); |
|---|
| 123 | _dos.writeInt16( 0 ); |
|---|
| 124 | _dos.writeInt16( 0 ); |
|---|
| 125 | _dos.writeFill( sizeof( int32 ) * 2 ); |
|---|
| 126 | _dos.writeInt16( 0 ); |
|---|
| 127 | _dos.writeInt16( 0 ); |
|---|
| 128 | _dos.writeInt16( 0 ); |
|---|
| 129 | _dos.writeInt16( 0 ); |
|---|
| 130 | _dos.writeInt32( 0 ); |
|---|
| 131 | _dos.writeFloat64( 0. ); |
|---|
| 132 | _dos.writeFloat64( 0. ); |
|---|
| 133 | _dos.writeFloat64( 0. ); |
|---|
| 134 | _dos.writeFloat64( 0. ); |
|---|
| 135 | _dos.writeFloat64( 0. ); |
|---|
| 136 | _dos.writeFloat64( 0. ); |
|---|
| 137 | _dos.writeFloat64( 0. ); |
|---|
| 138 | _dos.writeFloat64( 0. ); |
|---|
| 139 | _dos.writeInt16( 0 ); |
|---|
| 140 | _dos.writeInt16( 0 ); |
|---|
| 141 | _dos.writeInt16( 0 ); |
|---|
| 142 | _dos.writeInt16( 0 ); |
|---|
| 143 | _dos.writeFill( sizeof( int16 ) * 4 ); |
|---|
| 144 | _dos.writeInt32( 0 ); |
|---|
| 145 | _dos.writeInt16( 0 ); |
|---|
| 146 | _dos.writeInt16( 0 ); |
|---|
| 147 | _dos.writeInt16( 0 ); |
|---|
| 148 | _dos.writeFill( 6 ); |
|---|
| 149 | _dos.writeFloat64( 0. ); |
|---|
| 150 | _dos.writeFloat64( 0. ); |
|---|
| 151 | _dos.writeInt16( 0 ); |
|---|
| 152 | _dos.writeInt16( 0 ); |
|---|
| 153 | |
|---|
| 154 | if (version >= 1580) |
|---|
| 155 | { |
|---|
| 156 | _dos.writeInt32( 0 ); |
|---|
| 157 | _dos.writeFloat64( 0. ); |
|---|
| 158 | _dos.writeFloat64( 0. ); |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | static const unsigned int FORWARD_ANIM = 0x80000000u >> 1; |
|---|
| 165 | static const unsigned int SWING_ANIM = 0x80000000u >> 2; |
|---|
| 166 | static const unsigned int BOUND_BOX_FOLLOW = 0x80000000u >> 3; |
|---|
| 167 | static const unsigned int FREEZE_BOUND_BOX = 0x80000000u >> 4; |
|---|
| 168 | static const unsigned int DEFAULT_PARENT = 0x80000000u >> 5; |
|---|
| 169 | static const unsigned int BACKWARD_ANIM = 0x80000000u >> 6; |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | void |
|---|
| 176 | FltExportVisitor::writeGroup( const osg::Group& group ) |
|---|
| 177 | { |
|---|
| 178 | int32 flags = 0, loopCount = 0; |
|---|
| 179 | float32 loopDuration = 0.0f, lastFrameDuration = 0.0f; |
|---|
| 180 | |
|---|
| 181 | writeGroup(group, flags, loopCount, loopDuration, lastFrameDuration); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | void |
|---|
| 187 | FltExportVisitor::writeGroup( const osg::Group& group, |
|---|
| 188 | int32 flags, |
|---|
| 189 | int32 loopCount, |
|---|
| 190 | float32 loopDuration, |
|---|
| 191 | float32 lastFrameDuration) |
|---|
| 192 | { |
|---|
| 193 | int16 length( 44 ); |
|---|
| 194 | IdHelper id(*this, group.getName() ); |
|---|
| 195 | |
|---|
| 196 | _records->writeInt16( (int16) GROUP_OP ); |
|---|
| 197 | _records->writeInt16( length ); |
|---|
| 198 | _records->writeID( id ); |
|---|
| 199 | _records->writeInt16( 0 ); |
|---|
| 200 | _records->writeInt16( 0 ); |
|---|
| 201 | _records->writeUInt32( flags ); |
|---|
| 202 | _records->writeInt16( 0 ); |
|---|
| 203 | _records->writeInt16( 0 ); |
|---|
| 204 | _records->writeInt16( 0 ); |
|---|
| 205 | _records->writeInt8( 0 ); |
|---|
| 206 | _records->writeInt8( 0 ); |
|---|
| 207 | _records->writeInt32( 0 ); |
|---|
| 208 | _records->writeInt32( loopCount ); |
|---|
| 209 | _records->writeFloat32( loopDuration ); |
|---|
| 210 | _records->writeFloat32( lastFrameDuration ); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | void |
|---|
| 220 | FltExportVisitor::writeSequence( const osg::Sequence& sequence ) |
|---|
| 221 | { |
|---|
| 222 | |
|---|
| 223 | int32 flags = 0, loopCount = 0; |
|---|
| 224 | float32 loopDuration = 0.0f, lastFrameDuration = 0.0f; |
|---|
| 225 | |
|---|
| 226 | osg::Sequence::LoopMode mode; |
|---|
| 227 | int firstChildDisplayed, lastChildDisplayed; |
|---|
| 228 | sequence.getInterval(mode, firstChildDisplayed, lastChildDisplayed); |
|---|
| 229 | |
|---|
| 230 | if (firstChildDisplayed == 0) |
|---|
| 231 | { |
|---|
| 232 | flags |= FORWARD_ANIM; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | else |
|---|
| 236 | { |
|---|
| 237 | flags &= ~FORWARD_ANIM; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | if (mode == osg::Sequence::SWING) |
|---|
| 241 | { |
|---|
| 242 | flags |= SWING_ANIM; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | else |
|---|
| 246 | { |
|---|
| 247 | flags &= ~SWING_ANIM; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | float speedUp; |
|---|
| 252 | int numReps; |
|---|
| 253 | sequence.getDuration(speedUp, numReps); |
|---|
| 254 | |
|---|
| 255 | if (numReps != -1) |
|---|
| 256 | { |
|---|
| 257 | loopCount = numReps; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | else |
|---|
| 261 | { |
|---|
| 262 | loopCount = 0; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | for (unsigned int i = 0; i < sequence.getNumChildren(); ++i) |
|---|
| 267 | { |
|---|
| 268 | loopDuration += sequence.getTime(i); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | lastFrameDuration = sequence.getLastFrameTime(); |
|---|
| 272 | |
|---|
| 273 | writeGroup(sequence, flags, loopCount, loopDuration, lastFrameDuration); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | void |
|---|
| 278 | FltExportVisitor::writeObject( const osg::Group& group, osgSim::ObjectRecordData* ord ) |
|---|
| 279 | { |
|---|
| 280 | uint16 length( 28 ); |
|---|
| 281 | IdHelper id(*this, group.getName() ); |
|---|
| 282 | |
|---|
| 283 | if (!ord) |
|---|
| 284 | { |
|---|
| 285 | std::string warning( "fltexp: writeObject has invalid ObjectRecordData." ); |
|---|
| 286 | OSG_WARN << warning << std::endl; |
|---|
| 287 | _fltOpt->getWriteResult().warn( warning ); |
|---|
| 288 | return; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | _records->writeInt16( (int16) OBJECT_OP ); |
|---|
| 292 | _records->writeInt16( length ); |
|---|
| 293 | _records->writeID( id ); |
|---|
| 294 | _records->writeInt32( ord->_flags ); |
|---|
| 295 | _records->writeInt16( ord->_relativePriority ); |
|---|
| 296 | _records->writeUInt16( ord->_transparency ); |
|---|
| 297 | _records->writeUInt16( ord->_effectID1 ); |
|---|
| 298 | _records->writeUInt16( ord->_effectID2 ); |
|---|
| 299 | _records->writeUInt16( ord->_significance ); |
|---|
| 300 | _records->writeUInt16( 0 ); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | void |
|---|
| 304 | FltExportVisitor::writeDegreeOfFreedom( const osgSim::DOFTransform* dof ) |
|---|
| 305 | { |
|---|
| 306 | const osg::Matrix& invPut = dof->getInversePutMatrix(); |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | osg::Vec3d origin( invPut.getTrans() ); |
|---|
| 310 | |
|---|
| 311 | osg::Vec3 xAxis( invPut(0,0), invPut(0,1), invPut(0,2) ); |
|---|
| 312 | osg::Vec3 yAxis( invPut(1,0), invPut(1,1), invPut(1,2) ); |
|---|
| 313 | |
|---|
| 314 | osg::Vec3d pointOnXAxis = origin + xAxis; |
|---|
| 315 | |
|---|
| 316 | osg::Vec3d pointInXYPlane = origin + yAxis; |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | osg::Vec3d minTranslate( dof->getMinTranslate() ); |
|---|
| 320 | osg::Vec3d maxTranslate( dof->getMaxTranslate() ); |
|---|
| 321 | osg::Vec3d currTranslate( dof->getCurrentTranslate() ); |
|---|
| 322 | osg::Vec3d incrTranslate( dof->getIncrementTranslate() ); |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | osg::Vec3d minHPR( dof->getMinHPR() ); |
|---|
| 326 | osg::Vec3d maxHPR( dof->getMaxHPR() ); |
|---|
| 327 | osg::Vec3d currHPR( dof->getCurrentHPR() ); |
|---|
| 328 | osg::Vec3d incrHPR( dof->getIncrementHPR() ); |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | osg::Vec3d minScale( dof->getMinScale() ); |
|---|
| 332 | osg::Vec3d maxScale( dof->getMaxScale() ); |
|---|
| 333 | osg::Vec3d currScale( dof->getCurrentScale() ); |
|---|
| 334 | osg::Vec3d incrScale( dof->getIncrementScale() ); |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | uint16 length( 384 ); |
|---|
| 338 | IdHelper id(*this, dof->getName() ); |
|---|
| 339 | |
|---|
| 340 | _records->writeInt16( (int16) DOF_OP ); |
|---|
| 341 | _records->writeInt16( length ); |
|---|
| 342 | _records->writeID( id ); |
|---|
| 343 | _records->writeInt32( 0 ); |
|---|
| 344 | _records->writeVec3d( origin ); |
|---|
| 345 | _records->writeVec3d( pointOnXAxis ); |
|---|
| 346 | _records->writeVec3d( pointInXYPlane ); |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | _records->writeFloat64( minTranslate.z() ); |
|---|
| 350 | _records->writeFloat64( maxTranslate.z() ); |
|---|
| 351 | _records->writeFloat64( currTranslate.z() ); |
|---|
| 352 | _records->writeFloat64( incrTranslate.z() ); |
|---|
| 353 | |
|---|
| 354 | _records->writeFloat64( minTranslate.y() ); |
|---|
| 355 | _records->writeFloat64( maxTranslate.y() ); |
|---|
| 356 | _records->writeFloat64( currTranslate.y() ); |
|---|
| 357 | _records->writeFloat64( incrTranslate.y() ); |
|---|
| 358 | |
|---|
| 359 | _records->writeFloat64( minTranslate.x() ); |
|---|
| 360 | _records->writeFloat64( maxTranslate.x() ); |
|---|
| 361 | _records->writeFloat64( currTranslate.x() ); |
|---|
| 362 | _records->writeFloat64( incrTranslate.x() ); |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | _records->writeFloat64( osg::RadiansToDegrees(minHPR[1]) ); |
|---|
| 366 | _records->writeFloat64( osg::RadiansToDegrees(maxHPR[1]) ); |
|---|
| 367 | _records->writeFloat64( osg::RadiansToDegrees(currHPR[1]) ); |
|---|
| 368 | _records->writeFloat64( osg::RadiansToDegrees(incrHPR[1]) ); |
|---|
| 369 | |
|---|
| 370 | _records->writeFloat64( osg::RadiansToDegrees(minHPR[2]) ); |
|---|
| 371 | _records->writeFloat64( osg::RadiansToDegrees(maxHPR[2]) ); |
|---|
| 372 | _records->writeFloat64( osg::RadiansToDegrees(currHPR[2]) ); |
|---|
| 373 | _records->writeFloat64( osg::RadiansToDegrees(incrHPR[2]) ); |
|---|
| 374 | |
|---|
| 375 | _records->writeFloat64( osg::RadiansToDegrees(minHPR[0]) ); |
|---|
| 376 | _records->writeFloat64( osg::RadiansToDegrees(maxHPR[0]) ); |
|---|
| 377 | _records->writeFloat64( osg::RadiansToDegrees(currHPR[0]) ); |
|---|
| 378 | _records->writeFloat64( osg::RadiansToDegrees(incrHPR[0]) ); |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | _records->writeFloat64( minScale.z() ); |
|---|
| 382 | _records->writeFloat64( maxScale.z() ); |
|---|
| 383 | _records->writeFloat64( currScale.z() ); |
|---|
| 384 | _records->writeFloat64( incrScale.z() ); |
|---|
| 385 | |
|---|
| 386 | _records->writeFloat64( minScale.y() ); |
|---|
| 387 | _records->writeFloat64( maxScale.y() ); |
|---|
| 388 | _records->writeFloat64( currScale.y() ); |
|---|
| 389 | _records->writeFloat64( incrScale.y() ); |
|---|
| 390 | |
|---|
| 391 | _records->writeFloat64( minScale.x() ); |
|---|
| 392 | _records->writeFloat64( maxScale.x() ); |
|---|
| 393 | _records->writeFloat64( currScale.x() ); |
|---|
| 394 | _records->writeFloat64( incrScale.y() ); |
|---|
| 395 | |
|---|
| 396 | _records->writeInt32( dof->getLimitationFlags() ); |
|---|
| 397 | _records->writeInt32( 0 ); |
|---|
| 398 | |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | static const unsigned long COLOR_PALETTE_OVERRIDE = 0x80000000u >> 0; |
|---|
| 403 | static const unsigned long MATERIAL_PALETTE_OVERRIDE = 0x80000000u >> 1; |
|---|
| 404 | static const unsigned long TEXTURE_PALETTE_OVERRIDE = 0x80000000u >> 2; |
|---|
| 405 | static const unsigned long LINE_STYLE_PALETTE_OVERRIDE = 0x80000000u >> 3; |
|---|
| 406 | static const unsigned long SOUND_PALETTE_OVERRIDE = 0x80000000u >> 4; |
|---|
| 407 | static const unsigned long LIGHT_SOURCE_PALETTE_OVERRIDE = 0x80000000u >> 5; |
|---|
| 408 | static const unsigned long LIGHT_POINT_PALETTE_OVERRIDE = 0x80000000u >> 6; |
|---|
| 409 | static const unsigned long SHADER_PALETTE_OVERRIDE = 0x80000000u >> 7; |
|---|
| 410 | |
|---|
| 411 | void |
|---|
| 412 | FltExportVisitor::writeExternalReference( const osg::ProxyNode& proxy ) |
|---|
| 413 | { |
|---|
| 414 | uint16 length( 216 ); |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | unsigned long flags = COLOR_PALETTE_OVERRIDE | |
|---|
| 418 | MATERIAL_PALETTE_OVERRIDE | |
|---|
| 419 | TEXTURE_PALETTE_OVERRIDE | |
|---|
| 420 | LIGHT_POINT_PALETTE_OVERRIDE | |
|---|
| 421 | SHADER_PALETTE_OVERRIDE ; |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | const ParentPools* pp = dynamic_cast<const ParentPools*>(proxy.getUserData() ); |
|---|
| 425 | |
|---|
| 426 | if (pp && pp->getColorPool() ) |
|---|
| 427 | flags &= ~COLOR_PALETTE_OVERRIDE; |
|---|
| 428 | |
|---|
| 429 | if (pp && pp->getMaterialPool() ) |
|---|
| 430 | flags &= ~MATERIAL_PALETTE_OVERRIDE; |
|---|
| 431 | |
|---|
| 432 | if (pp && pp->getTexturePool() ) |
|---|
| 433 | flags &= ~TEXTURE_PALETTE_OVERRIDE; |
|---|
| 434 | |
|---|
| 435 | if (pp && pp->getLightSourcePool() ) |
|---|
| 436 | flags &= ~LIGHT_SOURCE_PALETTE_OVERRIDE; |
|---|
| 437 | |
|---|
| 438 | if (pp && pp->getLPAppearancePool() ) |
|---|
| 439 | flags &= ~LIGHT_POINT_PALETTE_OVERRIDE; |
|---|
| 440 | |
|---|
| 441 | if (pp && pp->getShaderPool() ) |
|---|
| 442 | flags &= ~SHADER_PALETTE_OVERRIDE; |
|---|
| 443 | |
|---|
| 444 | _records->writeInt16( (int16) EXTERNAL_REFERENCE_OP ); |
|---|
| 445 | _records->writeInt16( length ); |
|---|
| 446 | _records->writeString(proxy.getFileName(0), 200); |
|---|
| 447 | _records->writeInt32(0); |
|---|
| 448 | _records->writeInt32(flags); |
|---|
| 449 | _records->writeInt16(0); |
|---|
| 450 | _records->writeInt16(0); |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | void |
|---|
| 454 | FltExportVisitor::writeLevelOfDetail( const osg::LOD& lod, |
|---|
| 455 | osg::Vec3d const& center, |
|---|
| 456 | double switchInDist, |
|---|
| 457 | double switchOutDist) |
|---|
| 458 | { |
|---|
| 459 | uint16 length( 80 ); |
|---|
| 460 | IdHelper id(*this, lod.getName() ); |
|---|
| 461 | |
|---|
| 462 | _records->writeInt16( (int16) LOD_OP ); |
|---|
| 463 | _records->writeInt16( length ); |
|---|
| 464 | _records->writeID( id ); |
|---|
| 465 | _records->writeInt32( 0 ); |
|---|
| 466 | _records->writeFloat64( switchInDist ); |
|---|
| 467 | _records->writeFloat64( switchOutDist ); |
|---|
| 468 | _records->writeInt16( 0 ); |
|---|
| 469 | _records->writeInt16( 0 ); |
|---|
| 470 | _records->writeInt32( 0 ); |
|---|
| 471 | _records->writeFloat64( center.x() ); |
|---|
| 472 | _records->writeFloat64( center.y() ); |
|---|
| 473 | _records->writeFloat64( center.z() ); |
|---|
| 474 | _records->writeFloat64( 0 ); |
|---|
| 475 | _records->writeFloat64( 0 ); |
|---|
| 476 | |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | void |
|---|
| 480 | FltExportVisitor::writeLightSource( const osg::LightSource& node ) |
|---|
| 481 | { |
|---|
| 482 | |
|---|
| 483 | static const unsigned int ENABLED = 0x80000000u >> 0; |
|---|
| 484 | static const unsigned int GLOBAL = 0x80000000u >> 1; |
|---|
| 485 | |
|---|
| 486 | osg::Light const* light = node.getLight(); |
|---|
| 487 | int index = _lightSourcePalette->add(light); |
|---|
| 488 | |
|---|
| 489 | osg::Vec4d const& lightPos = light->getPosition(); |
|---|
| 490 | osg::Vec3f const& lightDir = light->getDirection(); |
|---|
| 491 | |
|---|
| 492 | uint32 flags = 0; |
|---|
| 493 | osg::StateSet const* ss = getCurrentStateSet(); |
|---|
| 494 | if (ss->getMode(GL_LIGHT0 + light->getLightNum() ) & osg::StateAttribute::ON) |
|---|
| 495 | { |
|---|
| 496 | flags |= ENABLED; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | ss = _stateSetStack.front().get(); |
|---|
| 502 | if (ss->getMode(GL_LIGHT0 + light->getLightNum() ) & osg::StateAttribute::ON) |
|---|
| 503 | { |
|---|
| 504 | flags |= GLOBAL; |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | uint16 length( 64 ); |
|---|
| 508 | IdHelper id(*this, node.getName() ); |
|---|
| 509 | |
|---|
| 510 | _records->writeInt16( (int16) LIGHT_SOURCE_OP ); |
|---|
| 511 | _records->writeInt16( length ); |
|---|
| 512 | _records->writeID( id ); |
|---|
| 513 | _records->writeInt32( 0 ); |
|---|
| 514 | _records->writeInt32( index ); |
|---|
| 515 | _records->writeInt32( 0 ); |
|---|
| 516 | _records->writeUInt32( flags ); |
|---|
| 517 | _records->writeInt32( 0 ); |
|---|
| 518 | _records->writeVec3d( osg::Vec3d( |
|---|
| 519 | lightPos.x() , lightPos.y() , lightPos.z() ) ); |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | _records->writeFloat32( lightDir[0] ); |
|---|
| 523 | _records->writeFloat32( lightDir[1] ); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | void |
|---|
| 529 | FltExportVisitor::writeSwitch( const osgSim::MultiSwitch* ms ) |
|---|
| 530 | { |
|---|
| 531 | int32 currMask = ms->getActiveSwitchSet(); |
|---|
| 532 | int32 numMasks = ms->getSwitchSetList().size(); |
|---|
| 533 | int32 numWordsPerMask = ms->getNumChildren() / 32; |
|---|
| 534 | if (ms->getNumChildren() % 32 != 0) ++numWordsPerMask; |
|---|
| 535 | |
|---|
| 536 | uint16 length( 28 + numMasks * numWordsPerMask * sizeof(int32) ); |
|---|
| 537 | IdHelper id(*this, ms->getName() ); |
|---|
| 538 | |
|---|
| 539 | _records->writeInt16( (int16) SWITCH_OP ); |
|---|
| 540 | _records->writeInt16( length ); |
|---|
| 541 | _records->writeID( id ); |
|---|
| 542 | _records->writeInt32( 0 ); |
|---|
| 543 | _records->writeInt32( currMask ); |
|---|
| 544 | _records->writeInt32( numMasks ); |
|---|
| 545 | _records->writeInt32( numWordsPerMask ); |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | for (int i = 0; i < numMasks; ++i) |
|---|
| 549 | { |
|---|
| 550 | |
|---|
| 551 | uint32 maskWord = 0; |
|---|
| 552 | const osgSim::MultiSwitch::ValueList& maskBits = ms->getValueList(i); |
|---|
| 553 | |
|---|
| 554 | for (size_t j = 0; j < maskBits.size(); ++j) |
|---|
| 555 | { |
|---|
| 556 | |
|---|
| 557 | if (maskBits[j]) maskWord |= 1 << (j % 32); |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | if ( (j + 1) % 32 == 0 ) |
|---|
| 562 | { |
|---|
| 563 | _records->writeUInt32(maskWord); |
|---|
| 564 | maskWord = 0; |
|---|
| 565 | } |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | if (maskBits.size() % 32 != 0) |
|---|
| 571 | { |
|---|
| 572 | _records->writeUInt32(maskWord); |
|---|
| 573 | } |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | void |
|---|
| 580 | FltExportVisitor::writeSwitch( const osg::Switch* sw ) |
|---|
| 581 | { |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | int32 currMask = 0; |
|---|
| 585 | int32 numMasks = 1; |
|---|
| 586 | int32 numWordsPerMask = sw->getNumChildren() / 32; |
|---|
| 587 | if (sw->getNumChildren() % 32 != 0) ++numWordsPerMask; |
|---|
| 588 | |
|---|
| 589 | uint16 length( 28 + numMasks * numWordsPerMask * sizeof(int32) ); |
|---|
| 590 | IdHelper id(*this, sw->getName() ); |
|---|
| 591 | |
|---|
| 592 | _records->writeInt16( (int16) SWITCH_OP ); |
|---|
| 593 | _records->writeInt16( length ); |
|---|
| 594 | _records->writeID( id ); |
|---|
| 595 | _records->writeInt32( 0 ); |
|---|
| 596 | _records->writeInt32( currMask ); |
|---|
| 597 | _records->writeInt32( numMasks ); |
|---|
| 598 | _records->writeInt32( numWordsPerMask ); |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | uint32 maskWord = 0; |
|---|
| 602 | const osg::Switch::ValueList& maskBits = sw->getValueList(); |
|---|
| 603 | |
|---|
| 604 | for (size_t i = 0; i < maskBits.size(); ++i) |
|---|
| 605 | { |
|---|
| 606 | |
|---|
| 607 | if (maskBits[i]) maskWord |= 1 << (i % 32); |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | if ( (i + 1) % 32 == 0 ) |
|---|
| 612 | { |
|---|
| 613 | _records->writeUInt32(maskWord); |
|---|
| 614 | maskWord = 0; |
|---|
| 615 | } |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | if (maskBits.size() % 32 != 0) |
|---|
| 621 | { |
|---|
| 622 | _records->writeUInt32(maskWord); |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | void |
|---|
| 628 | FltExportVisitor::writeLightPoint( const osgSim::LightPointNode* lpn ) |
|---|
| 629 | { |
|---|
| 630 | enum Directionality |
|---|
| 631 | { |
|---|
| 632 | OMNIDIRECTIONAL = 0, |
|---|
| 633 | UNIDIRECTIONAL = 1, |
|---|
| 634 | BIDIRECTIONAL = 2 |
|---|
| 635 | }; |
|---|
| 636 | enum DisplayMode |
|---|
| 637 | { |
|---|
| 638 | RASTER = 0, |
|---|
| 639 | CALLIG = 1, |
|---|
| 640 | EITHER = 2 |
|---|
| 641 | }; |
|---|
| 642 | enum Modes |
|---|
| 643 | { |
|---|
| 644 | ENABLE = 0, |
|---|
| 645 | DISABLE = 1 |
|---|
| 646 | }; |
|---|
| 647 | enum Flags |
|---|
| 648 | { |
|---|
| 649 | NO_BACK_COLOR = 0x80000000u >> 1, |
|---|
| 650 | CALLIGRAPHIC = 0x80000000u >> 3, |
|---|
| 651 | REFLECTIVE = 0x80000000u >> 4, |
|---|
| 652 | PERSPECTIVE = 0x80000000u >> 8, |
|---|
| 653 | FLASHING = 0x80000000u >> 9, |
|---|
| 654 | ROTATING = 0x80000000u >> 10, |
|---|
| 655 | ROTATE_CC = 0x80000000u >> 11, |
|---|
| 656 | VISIBLE_DAY = 0x80000000u >> 15, |
|---|
| 657 | VISIBLE_DUSK = 0x80000000u >> 16, |
|---|
| 658 | VISIBLE_NIGHT = 0x80000000u >> 17 |
|---|
| 659 | }; |
|---|
| 660 | int32 flags( NO_BACK_COLOR ); |
|---|
| 661 | |
|---|
| 662 | if (lpn->getNumLightPoints() == 0) |
|---|
| 663 | return; |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | const osgSim::LightPoint& lp0 = lpn->getLightPoint( 0 ); |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | float32 animPeriod( 0.f ); |
|---|
| 675 | float32 animEnabled( 0.f ); |
|---|
| 676 | float32 animPhaseDelay( 0.f ); |
|---|
| 677 | if (lp0._blinkSequence != NULL) |
|---|
| 678 | { |
|---|
| 679 | flags |= FLASHING; |
|---|
| 680 | animPeriod = 4.f; |
|---|
| 681 | animEnabled = 2.f; |
|---|
| 682 | animPhaseDelay = lp0._blinkSequence->getPhaseShift(); |
|---|
| 683 | } |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | int32 directionality( OMNIDIRECTIONAL ); |
|---|
| 688 | float32 horizLobe( 360.f ); |
|---|
| 689 | float32 vertLobe( 360.f ); |
|---|
| 690 | float32 lobeRoll( 0.f ); |
|---|
| 691 | const osgSim::DirectionalSector* ds = dynamic_cast< osgSim::DirectionalSector* >( lp0._sector.get() ); |
|---|
| 692 | if (ds) |
|---|
| 693 | { |
|---|
| 694 | directionality = UNIDIRECTIONAL; |
|---|
| 695 | horizLobe = osg::RadiansToDegrees( ds->getHorizLobeAngle() ); |
|---|
| 696 | vertLobe = osg::RadiansToDegrees( ds->getVertLobeAngle() ); |
|---|
| 697 | lobeRoll = osg::RadiansToDegrees( ds->getLobeRollAngle() ); |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | { |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | const uint16 length( 156 ); |
|---|
| 705 | IdHelper id( *this, lpn->getName() ); |
|---|
| 706 | |
|---|
| 707 | _records->writeInt16( (int16) LIGHT_POINT_OP ); |
|---|
| 708 | _records->writeInt16( length ); |
|---|
| 709 | _records->writeID( id ); |
|---|
| 710 | _records->writeInt16( 0 ); |
|---|
| 711 | _records->writeInt16( 0 ); |
|---|
| 712 | _records->writeUInt32( ~0u ); |
|---|
| 713 | _records->writeInt32( EITHER ); |
|---|
| 714 | _records->writeFloat32( lp0._intensity ); |
|---|
| 715 | _records->writeFloat32( 0.f ); |
|---|
| 716 | _records->writeFloat32( 0.f ); |
|---|
| 717 | _records->writeFloat32( 0.f ); |
|---|
| 718 | _records->writeInt32( DISABLE ); |
|---|
| 719 | _records->writeInt32( DISABLE ); |
|---|
| 720 | _records->writeInt32( DISABLE ); |
|---|
| 721 | _records->writeInt32( 0 ); |
|---|
| 722 | _records->writeFloat32( lpn->getMinPixelSize() ); |
|---|
| 723 | _records->writeFloat32( lpn->getMaxPixelSize() ); |
|---|
| 724 | _records->writeFloat32( lp0._radius * 2.f ); |
|---|
| 725 | _records->writeFloat32( 1.f ); |
|---|
| 726 | _records->writeFloat32( 1.f ); |
|---|
| 727 | _records->writeFloat32( 1.f ); |
|---|
| 728 | _records->writeFloat32( 0.f ); |
|---|
| 729 | _records->writeFloat32( 1.f ); |
|---|
| 730 | _records->writeFloat32( 0.f ); |
|---|
| 731 | _records->writeFloat32( 0.f ); |
|---|
| 732 | _records->writeInt32( directionality ); |
|---|
| 733 | _records->writeFloat32( horizLobe ); |
|---|
| 734 | _records->writeFloat32( vertLobe ); |
|---|
| 735 | _records->writeFloat32( lobeRoll ); |
|---|
| 736 | _records->writeFloat32( 0.f ); |
|---|
| 737 | _records->writeFloat32( 0.f ); |
|---|
| 738 | _records->writeFloat32( animPeriod ); |
|---|
| 739 | _records->writeFloat32( animPhaseDelay ); |
|---|
| 740 | _records->writeFloat32( animEnabled ); |
|---|
| 741 | _records->writeFloat32( 1.f ); |
|---|
| 742 | _records->writeInt32( 0 ); |
|---|
| 743 | _records->writeInt32( flags ); |
|---|
| 744 | _records->writeVec3f( osg::Vec3f( 0.f, 0.f, 0.f ) ); |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | { |
|---|
| 748 | osg::ref_ptr< osg::Vec3dArray > v = new osg::Vec3dArray( lpn->getNumLightPoints() ); |
|---|
| 749 | osg::ref_ptr< osg::Vec4Array > c = new osg::Vec4Array( lpn->getNumLightPoints() ); |
|---|
| 750 | osg::ref_ptr< osg::Vec3Array > n = new osg::Vec3Array( lpn->getNumLightPoints() ); |
|---|
| 751 | osg::Vec3f normal( 0.f, 0.f, 1.f ); |
|---|
| 752 | |
|---|
| 753 | unsigned int idx; |
|---|
| 754 | for( idx=0; idx<lpn->getNumLightPoints(); idx++) |
|---|
| 755 | { |
|---|
| 756 | const osgSim::LightPoint& lp = lpn->getLightPoint( idx ); |
|---|
| 757 | (*v)[ idx ] = lp._position; |
|---|
| 758 | (*c)[ idx ] = lp._color; |
|---|
| 759 | |
|---|
| 760 | const osgSim::DirectionalSector* ds = dynamic_cast< osgSim::DirectionalSector* >( lp._sector.get() ); |
|---|
| 761 | if (ds) |
|---|
| 762 | normal = ds->getDirection(); |
|---|
| 763 | (*n)[ idx ] = normal; |
|---|
| 764 | } |
|---|
| 765 | _vertexPalette->add( (const osg::Array*)NULL, v.get(), c.get(), n.get(), NULL, true, true, false ); |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | writeMatrix( lpn->getUserData() ); |
|---|
| 769 | writeComment( *lpn ); |
|---|
| 770 | writePush(); |
|---|
| 771 | writeVertexList( 0, lpn->getNumLightPoints() ); |
|---|
| 772 | writePop(); |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | void |
|---|
| 777 | FltExportVisitor::writeColorPalette() |
|---|
| 778 | { |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | uint16 length( 4228 ); |
|---|
| 782 | |
|---|
| 783 | _dos.writeInt16( (int16) COLOR_PALETTE_OP ); |
|---|
| 784 | _dos.writeInt16( length ); |
|---|
| 785 | _dos.writeFill( 128 ); |
|---|
| 786 | int idx; |
|---|
| 787 | for( idx=0; idx<1024; idx++) |
|---|
| 788 | _dos.writeUInt32( 0xffffffff ); |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | } |
|---|