| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include "Document.h" |
|---|
| 21 | |
|---|
| 22 | using namespace flt; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | Document::Document() : |
|---|
| 26 | _replaceClampWithClampToEdge(false), |
|---|
| 27 | _preserveFace(false), |
|---|
| 28 | _preserveObject(false), |
|---|
| 29 | _defaultDOFAnimationState(false), |
|---|
| 30 | _useTextureAlphaForTransparancyBinning(true), |
|---|
| 31 | _useBillboardCenter(false), |
|---|
| 32 | _doUnitsConversion(true), |
|---|
| 33 | _readObjectRecordData(false), |
|---|
| 34 | _desiredUnits(METERS), |
|---|
| 35 | _done(false), |
|---|
| 36 | _level(0), |
|---|
| 37 | _subfaceLevel(0), |
|---|
| 38 | _unitScale(1.0), |
|---|
| 39 | _version(0), |
|---|
| 40 | _colorPoolParent(false), |
|---|
| 41 | _texturePoolParent(false), |
|---|
| 42 | _materialPoolParent(false), |
|---|
| 43 | _lightSourcePoolParent(false), |
|---|
| 44 | _lightPointAppearancePoolParent(false), |
|---|
| 45 | _lightPointAnimationPoolParent(false), |
|---|
| 46 | _shaderPoolParent(false) |
|---|
| 47 | { |
|---|
| 48 | _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | Document::~Document() |
|---|
| 52 | { |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void Document::pushLevel() |
|---|
| 56 | { |
|---|
| 57 | _levelStack.push_back(_currentPrimaryRecord.get()); |
|---|
| 58 | _level++; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void Document::popLevel() |
|---|
| 62 | { |
|---|
| 63 | _levelStack.pop_back(); |
|---|
| 64 | |
|---|
| 65 | if (!_levelStack.empty()) |
|---|
| 66 | _currentPrimaryRecord = _levelStack.back(); |
|---|
| 67 | |
|---|
| 68 | if (--_level<=0) |
|---|
| 69 | _done = true; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void Document::pushSubface() |
|---|
| 73 | { |
|---|
| 74 | _subfaceLevel++; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void Document::popSubface() |
|---|
| 78 | { |
|---|
| 79 | _subfaceLevel--; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void Document::pushExtension() |
|---|
| 83 | { |
|---|
| 84 | if (!_currentPrimaryRecord.valid()) |
|---|
| 85 | { |
|---|
| 86 | osg::notify(osg::WARN) << "No current primary in Document::pushExtension()." << std::endl; |
|---|
| 87 | return; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | _extensionStack.push_back(_currentPrimaryRecord.get()); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | void Document::popExtension() |
|---|
| 94 | { |
|---|
| 95 | _currentPrimaryRecord=_extensionStack.back().get(); |
|---|
| 96 | if (!_currentPrimaryRecord.valid()) |
|---|
| 97 | { |
|---|
| 98 | osg::notify(osg::WARN) << "Can't decide primary in Document::popExtension()." << std::endl; |
|---|
| 99 | return; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | _extensionStack.pop_back(); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | osg::Node* Document::getInstanceDefinition(int no) |
|---|
| 106 | { |
|---|
| 107 | InstanceDefinitionMap::iterator itr = _instanceDefinitionMap.find(no); |
|---|
| 108 | if (itr != _instanceDefinitionMap.end()) |
|---|
| 109 | return (*itr).second.get(); |
|---|
| 110 | |
|---|
| 111 | return NULL; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | void Document::setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po) |
|---|
| 115 | { |
|---|
| 116 | _subsurfacePolygonOffsets[level] = po; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | osg::PolygonOffset* Document::getSubSurfacePolygonOffset(int level) |
|---|
| 120 | { |
|---|
| 121 | osg::notify(osg::DEBUG_INFO)<<"Document::getSubSurfacePolygonOffset("<<level<<")"<<std::endl; |
|---|
| 122 | osg::ref_ptr<osg::PolygonOffset>& po = _subsurfacePolygonOffsets[level]; |
|---|
| 123 | if (!po) |
|---|
| 124 | { |
|---|
| 125 | po = new osg::PolygonOffset(-1.0f*float(level), -1.0f); |
|---|
| 126 | } |
|---|
| 127 | return po.get(); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | double flt::unitsToMeters(CoordUnits unit) |
|---|
| 131 | { |
|---|
| 132 | switch (unit) |
|---|
| 133 | { |
|---|
| 134 | case METERS: |
|---|
| 135 | return 1.0; |
|---|
| 136 | case KILOMETERS: |
|---|
| 137 | return 1000.0; |
|---|
| 138 | case FEET: |
|---|
| 139 | return 0.3048; |
|---|
| 140 | case INCHES: |
|---|
| 141 | return 0.02540; |
|---|
| 142 | case NAUTICAL_MILES: |
|---|
| 143 | return 1852.0; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | return 1.0; |
|---|
| 147 | } |
|---|