From Alberto Farre, fixes to ProxyNode.
This commit is contained in:
@@ -76,7 +76,7 @@ bool ProxyNode::addChild( Node *child )
|
||||
{
|
||||
if (Group::addChild(child))
|
||||
{
|
||||
expandFileNameListTo(_children.size());
|
||||
expandFileNameListTo(_children.size()-1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -2437,7 +2437,7 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
|
||||
{
|
||||
osg::Group *tempParent = visitAncillary(osgParent, *external, rec);
|
||||
tempParent->addChild(external);
|
||||
return 0;
|
||||
return external;
|
||||
}
|
||||
#endif
|
||||
pFile->setDesiredUnits( rec->getFltFile()->getDesiredUnits() );
|
||||
@@ -2467,7 +2467,7 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
|
||||
proxynode->setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
|
||||
proxynode->addChild(external, rec->getFilename());
|
||||
tempParent->addChild(proxynode);
|
||||
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), external);
|
||||
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
|
||||
#else
|
||||
tempParent->addChild(external);
|
||||
#endif
|
||||
@@ -2486,7 +2486,7 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
|
||||
proxynode->setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
|
||||
proxynode->addChild(model, rec->getFilename());
|
||||
tempParent->addChild(proxynode);
|
||||
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), model);
|
||||
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
|
||||
#else
|
||||
//tempParent->addChild(model);
|
||||
#endif
|
||||
@@ -2504,7 +2504,6 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
|
||||
return external;
|
||||
}
|
||||
|
||||
|
||||
void ConvertFromFLT::visitLightPoint(GeoSetBuilder* pBuilder,osg::Group& osgParent, LightPointRecord* rec)
|
||||
{
|
||||
DynGeoSet* dgset = pBuilder->getDynGeoSet();
|
||||
|
||||
@@ -14,14 +14,35 @@
|
||||
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/FileNameUtils>
|
||||
|
||||
#include "Exception.h"
|
||||
#include "ProxyNode.h"
|
||||
#include "Group.h"
|
||||
#include "Node.h"
|
||||
|
||||
using namespace ive;
|
||||
/*
|
||||
for(osgDB::FilePathList::iterator itr=osgDB::getDataFilePathList().begin(); itr!=osgDB::getDataFilePathList().end(); ++itr)
|
||||
printf("#1######%s\n", itr->c_str());
|
||||
for(osgDB::FilePathList::const_iterator itrO=in->getOptions()->getDatabasePathList().begin(); itrO!=in->getOptions()->getDatabasePathList().end(); ++itrO)
|
||||
printf("#2######%s\n", itrO->c_str());
|
||||
namespace osgDB {
|
||||
class PushAndPopDataPath
|
||||
{
|
||||
public:
|
||||
PushAndPopDataPath(const std::string& path)
|
||||
{
|
||||
getDataFilePathList().push_front(path);
|
||||
}
|
||||
|
||||
~PushAndPopDataPath()
|
||||
{
|
||||
getDataFilePathList().pop_front();
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
void ProxyNode::write(DataOutputStream* out)
|
||||
{
|
||||
@@ -29,59 +50,29 @@ void ProxyNode::write(DataOutputStream* out)
|
||||
out->writeInt(IVEPROXYNODE);
|
||||
|
||||
// If the osg class is inherited by any other class we should also write this to file.
|
||||
osg::Group* node = dynamic_cast<osg::Group*>(this);
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(this);
|
||||
if(node)
|
||||
{
|
||||
static_cast<ive::Group*>(node)->write(out);
|
||||
}
|
||||
else throw Exception("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::LOD.");
|
||||
|
||||
if ( out->getVersion() > VERSION_0006 )
|
||||
{
|
||||
out->writeString(getDatabasePath());
|
||||
static_cast<ive::Node*>(node)->write(out);
|
||||
}
|
||||
else
|
||||
throw Exception("ProxyNode::write(): Could not cast this osg::ProxyNode to an osg::Node.");
|
||||
|
||||
out->writeFloat(getRadius());
|
||||
out->writeInt(getCenterMode());
|
||||
out->writeVec3(getCenter());
|
||||
|
||||
if(out->getIncludeExternalReferences()) // inlined mode
|
||||
out->writeUInt(getNumFileNames());
|
||||
unsigned int numChildrenToWriteOut = 0;
|
||||
unsigned int i;
|
||||
for(i=0; i<getNumFileNames(); i++)
|
||||
{
|
||||
out->writeUInt(getNumChildren());
|
||||
unsigned int i;
|
||||
for(i=0; i<getNumChildren(); i++)
|
||||
if (getFileName(i).empty())
|
||||
{
|
||||
out->writeNode(getChild(i));
|
||||
out->writeString("");
|
||||
++numChildrenToWriteOut;
|
||||
}
|
||||
out->writeUInt(getNumFileNames());
|
||||
for(i=0; i<getNumFileNames(); i++)
|
||||
{
|
||||
out->writeString(getFileName(i));
|
||||
}
|
||||
}
|
||||
else //no inlined mode
|
||||
{
|
||||
unsigned int numChildrenToWriteOut = 0;
|
||||
unsigned int i;
|
||||
for(i=0; i<getNumFileNames();++i)
|
||||
{
|
||||
if (getFileName(i).empty())
|
||||
{
|
||||
++numChildrenToWriteOut;
|
||||
}
|
||||
}
|
||||
|
||||
out->writeUInt(numChildrenToWriteOut);
|
||||
for(i=0; i<getNumChildren(); i++)
|
||||
{
|
||||
if (getFileName(i).empty())
|
||||
{
|
||||
out->writeNode(getChild(i));
|
||||
}
|
||||
}
|
||||
|
||||
out->writeUInt(getNumFileNames());
|
||||
for(i=0; i<getNumFileNames(); i++)
|
||||
else
|
||||
{
|
||||
if(out->getUseOriginalExternalReferences())
|
||||
{
|
||||
@@ -91,14 +82,37 @@ void ProxyNode::write(DataOutputStream* out)
|
||||
{
|
||||
std::string ivename = osgDB::getFilePath(getFileName(i)) +"/"+ osgDB::getStrippedName(getFileName(i)) +".ive";
|
||||
out->writeString(ivename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(out->getWriteExternalReferenceFiles())
|
||||
if(out->getIncludeExternalReferences()) //--------- inlined mode
|
||||
{
|
||||
out->writeUInt(getNumChildren());
|
||||
for(i=0; i<getNumChildren(); i++)
|
||||
{
|
||||
out->writeNode(getChild(i));
|
||||
}
|
||||
}
|
||||
else //----------------------------------------- no inlined mode
|
||||
{
|
||||
out->writeUInt(numChildrenToWriteOut);
|
||||
|
||||
for(i=0; i<getNumFileNames(); i++)
|
||||
{
|
||||
if (getFileName(i).empty())
|
||||
{
|
||||
out->writeNode(getChild(i));
|
||||
}
|
||||
else if(out->getWriteExternalReferenceFiles())
|
||||
{
|
||||
if(out->getUseOriginalExternalReferences())
|
||||
{
|
||||
std::string path = getDatabasePath();
|
||||
if (path.empty() && out->getOptions() && !out->getOptions()->getDatabasePathList().empty())
|
||||
path = out->getOptions()->getDatabasePathList().front();
|
||||
if(!path.empty()) path += "/";
|
||||
ivename = path + ivename;
|
||||
osgDB::writeNodeFile(*getChild(i), getFileName(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string ivename = osgDB::getFilePath(getFileName(i)) +"/"+ osgDB::getStrippedName(getFileName(i)) +".ive";
|
||||
osgDB::writeNodeFile(*getChild(i), ivename);
|
||||
}
|
||||
}
|
||||
@@ -115,21 +129,15 @@ void ProxyNode::read(DataInputStream* in)
|
||||
// Read ProxyNode's identification.
|
||||
id = in->readInt();
|
||||
// If the osg class is inherited by any other class we should also read this from file.
|
||||
osg::Group* node = dynamic_cast<osg::Group*>(this);
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(this);
|
||||
if(node)
|
||||
{
|
||||
((ive::Group*)(node))->read(in);
|
||||
((ive::Node*)(node))->read(in);
|
||||
}
|
||||
else
|
||||
throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node.");
|
||||
throw Exception("ProxyNode::read(): Could not cast this osg::ProxyNode to an osg::Node.");
|
||||
|
||||
|
||||
if ( in->getVersion() > VERSION_0006 )
|
||||
{
|
||||
setDatabasePath(in->readString());
|
||||
}
|
||||
|
||||
if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty())
|
||||
if (in->getOptions() && !in->getOptions()->getDatabasePathList().empty())
|
||||
{
|
||||
const std::string& path = in->getOptions()->getDatabasePathList().front();
|
||||
if (!path.empty())
|
||||
@@ -142,28 +150,39 @@ void ProxyNode::read(DataInputStream* in)
|
||||
setCenterMode((osg::ProxyNode::CenterMode)in->readInt());
|
||||
setCenter(in->readVec3());
|
||||
|
||||
// Read groups properties.
|
||||
// Read number of children.
|
||||
unsigned int size = in->readUInt();
|
||||
// Read children.
|
||||
unsigned int numFileNames = in->readUInt();
|
||||
unsigned int i;
|
||||
for(i=0; i<size; i++)
|
||||
for(i=0; i<numFileNames; i++)
|
||||
{
|
||||
addChild(in->readNode());
|
||||
setFileName(i, in->readString());
|
||||
}
|
||||
|
||||
size = in->readUInt();
|
||||
for(i=0;i<size;i++)
|
||||
unsigned int numChildren = in->readUInt();
|
||||
for(i=0; i<numChildren; i++)
|
||||
{
|
||||
//setFileName(i, in->readString());
|
||||
std::string filename = in->readString();
|
||||
osg::Node *node = osgDB::readNodeFile(getDatabasePath() + filename); // If filename is flt, will need getDatabasePath()
|
||||
if(node)
|
||||
addChild(node, filename);
|
||||
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)in->getOptions())->getDatabasePathList();
|
||||
fpl.push_front( fpl.empty() ? osgDB::getFilePath(getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(getFileName(i)));
|
||||
addChild(in->readNode());
|
||||
fpl.pop_front();
|
||||
}
|
||||
|
||||
for(i=0; i<numFileNames; i++)
|
||||
{
|
||||
if(i>=numChildren && !getFileName(i).empty())
|
||||
{
|
||||
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)in->getOptions())->getDatabasePathList();
|
||||
fpl.push_front( fpl.empty() ? osgDB::getFilePath(getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(getFileName(i)));
|
||||
osg::Node *node = osgDB::readNodeFile(getFileName(i), in->getOptions());
|
||||
fpl.pop_front();
|
||||
if(node)
|
||||
{
|
||||
insertChild(i, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("ProxyNode::read(): Expected ProxyNode identification.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "osgDB/Input"
|
||||
#include "osgDB/Output"
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/FileNameUtils>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
@@ -40,8 +43,8 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
fr+=4;
|
||||
}
|
||||
else
|
||||
proxyNode.setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
|
||||
else
|
||||
proxyNode.setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
|
||||
|
||||
float radius;
|
||||
if (fr[0].matchWord("Radius") && fr[1].getFloat(radius))
|
||||
@@ -51,7 +54,7 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (proxyNode.getDatabasePath().empty() && fr.getOptions() && !fr.getOptions()->getDatabasePathList().empty())
|
||||
if (fr.getOptions() && !fr.getOptions()->getDatabasePathList().empty())
|
||||
{
|
||||
const std::string& path = fr.getOptions()->getDatabasePathList().front();
|
||||
if (!path.empty())
|
||||
@@ -80,16 +83,7 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
if (fr[0].isString() || fr[0].isQuotedString())
|
||||
{
|
||||
if (fr[0].getStr())
|
||||
{
|
||||
osg::Node *node = osgDB::readNodeFile(proxyNode.getDatabasePath() + fr[0].getStr()); // If filename is flt, will need getDatabasePath()
|
||||
if(node)
|
||||
{
|
||||
printf("cargando: %s\n", fr[0].getStr());
|
||||
proxyNode.addChild(node, fr[0].getStr());
|
||||
}
|
||||
}
|
||||
//if (fr[0].getStr()) proxyNode.setFileName(i,fr[0].getStr());
|
||||
if (fr[0].getStr()) proxyNode.setFileName(i,fr[0].getStr());
|
||||
else proxyNode.setFileName(i,"");
|
||||
|
||||
++fr;
|
||||
@@ -115,11 +109,32 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
Node* node = NULL;
|
||||
while((node=fr.readNode())!=NULL)
|
||||
for(int i=0; i<num_children; i++)
|
||||
{
|
||||
proxyNode.addChild(node);
|
||||
iteratorAdvanced = true;
|
||||
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)fr.getOptions())->getDatabasePathList();
|
||||
fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i)));
|
||||
Node* node = NULL;
|
||||
if((node=fr.readNode())!=NULL)
|
||||
{
|
||||
proxyNode.addChild(node);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
fpl.pop_front();
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<proxyNode.getNumFileNames(); i++)
|
||||
{
|
||||
if(i>=proxyNode.getNumChildren() && !proxyNode.getFileName(i).empty())
|
||||
{
|
||||
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)fr.getOptions())->getDatabasePathList();
|
||||
fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i)));
|
||||
osg::Node *node = osgDB::readNodeFile(proxyNode.getFileName(i), fr.getOptions());
|
||||
fpl.pop_front();
|
||||
if(node)
|
||||
{
|
||||
proxyNode.insertChild(i, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
@@ -128,13 +143,17 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
bool ProxyNode_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
bool includeExternalReferences = false;
|
||||
bool useOriginalExternalReferences = false;
|
||||
bool writeExternalReferenceFiles = true;
|
||||
|
||||
const ProxyNode& proxyNode = static_cast<const ProxyNode&>(obj);
|
||||
|
||||
if (proxyNode.getCenterMode()==osg::ProxyNode::USER_DEFINED_CENTER) fw.indent() << "Center "<< proxyNode.getCenter() << std::endl;
|
||||
|
||||
fw.indent() << "Radius "<<proxyNode.getRadius()<<std::endl;
|
||||
|
||||
fw.indent() << "FileNameList "<<proxyNode.getNumFileNames()<<" {"<< std::endl;
|
||||
fw.indent() << "FileNameList "<<proxyNode.getNumFileNames()<<" {"<< std::endl;
|
||||
fw.moveIn();
|
||||
|
||||
unsigned int numChildrenToWriteOut = 0;
|
||||
@@ -148,21 +167,52 @@ bool ProxyNode_writeLocalData(const Object& obj, Output& fw)
|
||||
}
|
||||
else
|
||||
{
|
||||
fw.indent() << proxyNode.getFileName(i) << std::endl;
|
||||
if(useOriginalExternalReferences)
|
||||
{
|
||||
fw.indent() << proxyNode.getFileName(i) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string osgname = osgDB::getFilePath(proxyNode.getFileName(i)) +"/"+ osgDB::getStrippedName(proxyNode.getFileName(i)) +".osg";
|
||||
fw.indent() << osgname << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
fw.moveOut();
|
||||
fw.indent() << "}"<< std::endl;
|
||||
|
||||
fw.indent() << "num_children " << numChildrenToWriteOut << std::endl;
|
||||
for(unsigned int j=0;j<proxyNode.getNumChildren();++j)
|
||||
|
||||
if(includeExternalReferences) //out->getIncludeExternalReferences()) // inlined mode
|
||||
{
|
||||
if (proxyNode.getFileName(j).empty())
|
||||
fw.indent() << "num_children " << proxyNode.getNumChildren() << std::endl;
|
||||
for(unsigned int i=0; i<proxyNode.getNumChildren(); i++)
|
||||
{
|
||||
fw.writeObject(*proxyNode.getChild(j));
|
||||
fw.writeObject(*proxyNode.getChild(i));
|
||||
}
|
||||
}
|
||||
else //----------------------------------------- no inlined mode
|
||||
{
|
||||
fw.indent() << "num_children " << numChildrenToWriteOut << std::endl;
|
||||
for(unsigned int i=0; i<proxyNode.getNumChildren(); ++i)
|
||||
{
|
||||
if (proxyNode.getFileName(i).empty())
|
||||
{
|
||||
fw.writeObject(*proxyNode.getChild(i));
|
||||
}
|
||||
else if(writeExternalReferenceFiles) //out->getWriteExternalReferenceFiles())
|
||||
{
|
||||
if(useOriginalExternalReferences) //out->getUseOriginalExternalReferences())
|
||||
{
|
||||
osgDB::writeNodeFile(*proxyNode.getChild(i), proxyNode.getFileName(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string osgname = osgDB::getFilePath(proxyNode.getFileName(i)) +"/"+ osgDB::getStrippedName(proxyNode.getFileName(i)) +".osg";
|
||||
osgDB::writeNodeFile(*proxyNode.getChild(i), osgname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user