| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #include "FltExportVisitor.h" |
|---|
| 18 | #include "DataOutputStream.h" |
|---|
| 19 | #include "Opcodes.h" |
|---|
| 20 | #include <osg/MatrixTransform> |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | namespace flt |
|---|
| 25 | { |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | void |
|---|
| 32 | FltExportVisitor::writeComment( const osg::Node& node, DataOutputStream* dos ) |
|---|
| 33 | { |
|---|
| 34 | if (dos==NULL) |
|---|
| 35 | dos = _records; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | unsigned int nd = node.getNumDescriptions(); |
|---|
| 39 | unsigned int idx=0; |
|---|
| 40 | while( idx < nd ) |
|---|
| 41 | { |
|---|
| 42 | const std::string& com = node.getDescription( idx ); |
|---|
| 43 | unsigned int iLen = com.length() + 5; |
|---|
| 44 | if (iLen > 0xffff) |
|---|
| 45 | { |
|---|
| 46 | |
|---|
| 47 | std::string warning( "fltexp: writeComment: Descriptions too long, resorts in short overrun. Skipping." ); |
|---|
| 48 | _fltOpt->getWriteResult().warn( warning ); |
|---|
| 49 | OSG_WARN << warning << std::endl; |
|---|
| 50 | continue; |
|---|
| 51 | } |
|---|
| 52 | uint16 length( (uint16)iLen ); |
|---|
| 53 | |
|---|
| 54 | dos->writeInt16( (int16) COMMENT_OP ); |
|---|
| 55 | dos->writeInt16( length ); |
|---|
| 56 | dos->writeString( com ); |
|---|
| 57 | |
|---|
| 58 | idx++; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | void |
|---|
| 66 | FltExportVisitor::writeLongID( const std::string& id, DataOutputStream* dos ) |
|---|
| 67 | { |
|---|
| 68 | if (dos==NULL) |
|---|
| 69 | dos = _records; |
|---|
| 70 | |
|---|
| 71 | uint16 length( 2 + 2 + id.length() + 1 ); |
|---|
| 72 | |
|---|
| 73 | dos->writeInt16( (int16) LONG_ID_OP ); |
|---|
| 74 | dos->writeUInt16( length ); |
|---|
| 75 | dos->writeString( id ); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void |
|---|
| 79 | FltExportVisitor::writeMatrix( const osg::Referenced* ref ) |
|---|
| 80 | { |
|---|
| 81 | const osg::RefMatrix* rm = dynamic_cast<const osg::RefMatrix*>( ref ); |
|---|
| 82 | if (!rm) |
|---|
| 83 | return; |
|---|
| 84 | |
|---|
| 85 | uint16 length( 4 + (16 * sizeof(float32)) ); |
|---|
| 86 | |
|---|
| 87 | _records->writeInt16( (int16) MATRIX_OP ); |
|---|
| 88 | _records->writeUInt16( length ); |
|---|
| 89 | |
|---|
| 90 | int idx, jdx; |
|---|
| 91 | for (idx=0; idx<4; idx++) |
|---|
| 92 | { |
|---|
| 93 | for (jdx=0; jdx<4; jdx++) |
|---|
| 94 | { |
|---|
| 95 | _records->writeFloat32( (*rm)( idx, jdx ) ); |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void |
|---|
| 101 | FltExportVisitor::writeContinuationRecord( const unsigned short length ) |
|---|
| 102 | { |
|---|
| 103 | OSG_DEBUG << "fltexp: Continuation record length: " << length+4 << std::endl; |
|---|
| 104 | _records->writeInt16( (int16) CONTINUATION_OP ); |
|---|
| 105 | _records->writeUInt16( length+4 ); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | } |
|---|