From Brede Johansen, "I have added an optimization to the OpenFlight plugin. By default it
ignores the Object records if it's safe to do so. The reader option preserveObject prevents this optimization. I have also removed the flat shading attribute set by the Object record. This flag is only intended for the "Calculate Shading" operation in Creator."
This commit is contained in:
@@ -11,6 +11,7 @@ using namespace flt;
|
||||
|
||||
Document::Document() :
|
||||
_preserveFace(false),
|
||||
_preserveObject(false),
|
||||
_defaultDOFAnimationState(false),
|
||||
_useTextureAlphaForTransparancyBinning(true),
|
||||
_doUnitsConversion(true),
|
||||
|
||||
@@ -144,6 +144,8 @@ class Document
|
||||
// Options
|
||||
void setPreserveFace(bool flag) { _preserveFace = flag; }
|
||||
bool getPreserveFace() const { return _preserveFace; }
|
||||
void setPreserveObject(bool flag) { _preserveObject = flag; }
|
||||
bool getPreserveObject() const { return _preserveObject; }
|
||||
void setDefaultDOFAnimationState(bool state) { _defaultDOFAnimationState = state; }
|
||||
bool getDefaultDOFAnimationState() const { return _defaultDOFAnimationState; }
|
||||
void setUseTextureAlphaForTransparancyBinning(bool flag) { _useTextureAlphaForTransparancyBinning=flag; }
|
||||
@@ -161,6 +163,7 @@ class Document
|
||||
// Options
|
||||
osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
|
||||
bool _preserveFace;
|
||||
bool _preserveObject;
|
||||
bool _defaultDOFAnimationState;
|
||||
bool _useTextureAlphaForTransparancyBinning;
|
||||
bool _doUnitsConversion;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
// Copyright (C) 2005-2006 Brede Johansen
|
||||
//
|
||||
|
||||
#include <assert.h>
|
||||
#include <typeinfo>
|
||||
#include <osg/Notify>
|
||||
#include <osg/ShadeModel>
|
||||
#include <osg/ProxyNode>
|
||||
@@ -17,7 +19,6 @@
|
||||
#include "Registry.h"
|
||||
#include "Document.h"
|
||||
#include "RecordInputStream.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace flt {
|
||||
|
||||
@@ -122,63 +123,6 @@ protected:
|
||||
RegisterRecordProxy<Header> g_Header(HEADER_OP);
|
||||
|
||||
|
||||
/** Object
|
||||
*/
|
||||
class Object : public PrimaryRecord
|
||||
{
|
||||
static const unsigned int HIDE_IN_DAYLIGHT = 0x80000000u >> 0;
|
||||
static const unsigned int HIDE_AT_DUSK = 0x80000000u >> 1;
|
||||
static const unsigned int HIDE_AT_NIGHT = 0x80000000u >> 2;
|
||||
static const unsigned int NO_ILLUMINATION = 0x80000000u >> 3;
|
||||
static const unsigned int FLAT_SHADED = 0x80000000u >> 4;
|
||||
static const unsigned int SHADOW_OBJECT = 0x80000000u >> 5;
|
||||
|
||||
osg::ref_ptr<osg::Group> _object;
|
||||
|
||||
public:
|
||||
|
||||
Object() {}
|
||||
|
||||
META_Record(Object)
|
||||
|
||||
META_setID(_object)
|
||||
META_setComment(_object)
|
||||
META_setMatrix(_object)
|
||||
META_setMultitexture(_object)
|
||||
META_addChild(_object)
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Object() {}
|
||||
|
||||
virtual void readRecord(RecordInputStream& in, Document& /*document*/)
|
||||
{
|
||||
std::string id = in.readString(8);
|
||||
uint32 flags = in.readUInt32();
|
||||
|
||||
_object = new osg::Group;
|
||||
_object->setName(id);
|
||||
|
||||
// Flat shaded?
|
||||
if (flags & FLAT_SHADED)
|
||||
{
|
||||
static osg::ref_ptr<osg::ShadeModel> shademodel;
|
||||
if (!shademodel.valid())
|
||||
{
|
||||
shademodel = new osg::ShadeModel;
|
||||
shademodel->setMode(osg::ShadeModel::FLAT);
|
||||
}
|
||||
_object->getOrCreateStateSet()->setAttribute(shademodel.get());
|
||||
}
|
||||
|
||||
if (_parent.valid())
|
||||
_parent->addChild(*_object);
|
||||
}
|
||||
};
|
||||
|
||||
RegisterRecordProxy<Object> g_Object(OBJECT_OP);
|
||||
|
||||
|
||||
/** Group
|
||||
*/
|
||||
class Group : public PrimaryRecord
|
||||
@@ -191,10 +135,15 @@ class Group : public PrimaryRecord
|
||||
static const unsigned int BACKWARD_ANIM = 0x80000000u >> 6;
|
||||
|
||||
osg::ref_ptr<osg::Group> _group;
|
||||
bool _forwardAnim;
|
||||
bool _backwardAnim;
|
||||
|
||||
public:
|
||||
|
||||
Group() {}
|
||||
Group():
|
||||
_forwardAnim(false),
|
||||
_backwardAnim(false)
|
||||
{}
|
||||
|
||||
META_Record(Group)
|
||||
|
||||
@@ -204,6 +153,8 @@ public:
|
||||
META_setMultitexture(_group)
|
||||
META_addChild(_group)
|
||||
|
||||
bool hasAnimation() const { return _forwardAnim || _backwardAnim; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Group() {}
|
||||
@@ -226,18 +177,18 @@ protected:
|
||||
/*float32 lastFrameDuration =*/ in.readFloat32();
|
||||
|
||||
// Check for forward animation (sequence)
|
||||
bool forwardAnim = (flags & FORWARD_ANIM) != 0;
|
||||
_forwardAnim = (flags & FORWARD_ANIM) != 0;
|
||||
|
||||
// For versions prior to 15.8, the swing bit can be set independently
|
||||
// of the animation bit. This implies forward animation (with swing)
|
||||
if ((document.version() < VERSION_15_8) && (flags & SWING_ANIM))
|
||||
forwardAnim = true;
|
||||
_forwardAnim = true;
|
||||
|
||||
// OpenFlight 15.8 adds backwards animations
|
||||
const bool backwardAnim = ( (document.version() >= VERSION_15_8) &&
|
||||
_backwardAnim = ( (document.version() >= VERSION_15_8) &&
|
||||
((flags & BACKWARD_ANIM) != 0) );
|
||||
|
||||
if (forwardAnim || backwardAnim)
|
||||
if (_forwardAnim || _backwardAnim)
|
||||
{
|
||||
osg::ref_ptr<osg::Sequence> sequence = new osg::Sequence;
|
||||
|
||||
@@ -245,7 +196,7 @@ protected:
|
||||
const osg::Sequence::LoopMode loopMode = ((flags & SWING_ANIM) == 0) ?
|
||||
osg::Sequence::LOOP : osg::Sequence::SWING;
|
||||
|
||||
if (forwardAnim)
|
||||
if (_forwardAnim)
|
||||
sequence->setInterval(loopMode, 0, -1);
|
||||
else
|
||||
sequence->setInterval(loopMode, -1, 0);
|
||||
@@ -812,6 +763,98 @@ protected:
|
||||
RegisterRecordProxy<Extension> g_Extension(EXTENSION_OP);
|
||||
|
||||
|
||||
/** Object
|
||||
*/
|
||||
class Object : public PrimaryRecord
|
||||
{
|
||||
static const unsigned int HIDE_IN_DAYLIGHT = 0x80000000u >> 0;
|
||||
static const unsigned int HIDE_AT_DUSK = 0x80000000u >> 1;
|
||||
static const unsigned int HIDE_AT_NIGHT = 0x80000000u >> 2;
|
||||
static const unsigned int NO_ILLUMINATION = 0x80000000u >> 3;
|
||||
static const unsigned int FLAT_SHADED = 0x80000000u >> 4;
|
||||
static const unsigned int SHADOW_OBJECT = 0x80000000u >> 5;
|
||||
|
||||
osg::ref_ptr<osg::Group> _object;
|
||||
|
||||
public:
|
||||
|
||||
Object() {}
|
||||
|
||||
META_Record(Object)
|
||||
|
||||
META_setID(_object)
|
||||
META_setComment(_object)
|
||||
META_setMatrix(_object)
|
||||
META_setMultitexture(_object)
|
||||
|
||||
virtual void addChild(osg::Node& child)
|
||||
{
|
||||
// If object excists it means it is preserved.
|
||||
if (_object.valid())
|
||||
_object->addChild(&child);
|
||||
// If no object add child to parent.
|
||||
else if (_parent.valid())
|
||||
_parent->addChild(child);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Object() {}
|
||||
|
||||
virtual void readRecord(RecordInputStream& in, Document& document)
|
||||
{
|
||||
// Is it safe to remove the object?
|
||||
if (!document.getPreserveObject())
|
||||
{
|
||||
// The following tests need a valid parent.
|
||||
if (!_parent.valid())
|
||||
return;
|
||||
|
||||
// LODs adds an empty child group so it is safe to remove this object record.
|
||||
if (typeid(*_parent)==typeid(flt::LevelOfDetail))
|
||||
return;
|
||||
|
||||
if (typeid(*_parent)==typeid(flt::OldLevelOfDetail))
|
||||
return;
|
||||
|
||||
// If parent is a Group record we have to check for animation.
|
||||
Group* parentGroup = dynamic_cast<flt::Group*>(_parent.get());
|
||||
if (parentGroup && !parentGroup->hasAnimation())
|
||||
return;
|
||||
}
|
||||
|
||||
std::string id = in.readString(8);
|
||||
_object = new osg::Group;
|
||||
_object->setName(id);
|
||||
|
||||
|
||||
#if 1
|
||||
/*uint32 flags =*/ in.readUInt32();
|
||||
#else
|
||||
|
||||
// The Object "Flat Shaded" checkbox in Creator is used by the "Calculate Shading" operation,
|
||||
// it is not a flat shaded state attribute.
|
||||
|
||||
uint32 flags = in.readUInt32();
|
||||
// Flat shaded?
|
||||
if (flags & FLAT_SHADED)
|
||||
{
|
||||
static osg::ref_ptr<osg::ShadeModel> shademodel;
|
||||
if (!shademodel.valid())
|
||||
{
|
||||
shademodel = new osg::ShadeModel;
|
||||
shademodel->setMode(osg::ShadeModel::FLAT);
|
||||
}
|
||||
_object->getOrCreateStateSet()->setAttribute(shademodel.get());
|
||||
}
|
||||
#endif
|
||||
if (_parent.valid())
|
||||
_parent->addChild(*_object);
|
||||
}
|
||||
};
|
||||
|
||||
RegisterRecordProxy<Object> g_Object(OBJECT_OP);
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
|
||||
@@ -165,6 +165,9 @@ class FLTReaderWriter : public ReaderWriter
|
||||
document.setPreserveFace((options->getOptionString().find("preserveFace")!=std::string::npos));
|
||||
osg::notify(osg::DEBUG_INFO) << readerMsg << "preserveFace=" << document.getPreserveFace() << std::endl;
|
||||
|
||||
document.setPreserveObject((options->getOptionString().find("preserveObject")!=std::string::npos));
|
||||
osg::notify(osg::DEBUG_INFO) << readerMsg << "preserveObject=" << document.getPreserveObject() << std::endl;
|
||||
|
||||
document.setDefaultDOFAnimationState((options->getOptionString().find("dofAnimation")!=std::string::npos));
|
||||
osg::notify(osg::DEBUG_INFO) << readerMsg << "dofAnimation=" << document.getDefaultDOFAnimationState() << std::endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user