[osg-users] BTG to blender with textures?
Josh Branning
lovell.joshyyy at gmail.com
Fri Jul 31 19:34:16 PDT 2015
Hi,
I'm trying to convert flightgear BTG files to a format which I can open in the most recent blender. The most success I've had is with 3ds format, but there are no textures shown.
Here is the code (most of it shamelessly 'robbed' from flightgear's fgviewer):
Code:
//
// Copyright (C) 2009 - 2012 Mathias Froehlich
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <osg/ArgumentParser>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/tgdb/userdata.hxx>
#include <simgear/scene/model/ModelRegistry.hxx>
#include <simgear/misc/ResourceManager.hxx>
int
main(int argc, char** argv)
{
/// Read arguments and environment variables.
// use an ArgumentParser object to manage the program arguments.
// FIXME implement a flightgear similar argument parser into simgear and use this one
osg::ArgumentParser arguments(&argc, argv);
sglog().set_log_classes(SG_ALL);
sglog().set_log_priority(SG_ALERT);
std::string fg_root;
if (arguments.read("--fg-root", fg_root)) {
} else if (const char *fg_root_env = std::getenv("FG_ROOT")) {
fg_root = fg_root_env;
} else {
SG_LOG(SG_GENERAL, SG_ALERT, "No --fg-root option set.");
return -1;
}
std::string fg_scenery;
if (arguments.read("--fg-scenery", fg_scenery)) {
} else if (const char *fg_scenery_env = std::getenv("FG_SCENERY")) {
fg_scenery = fg_scenery_env;
} else {
SG_LOG(SG_GENERAL, SG_ALERT, "No --fg-scenery option set.");
return -1;
}
SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
try {
SGPath preferencesFile = fg_root;
preferencesFile.append("preferences.xml");
readProperties(preferencesFile.str(), props);
} catch (...) {
// In case of an error, at least make summer :)
props->getNode("sim/startup/season", true)->setStringValue("summer");
SG_LOG(SG_GENERAL, SG_ALERT, "Problems loading FlightGear preferences.\n"
<< "Probably FG_ROOT is not properly set.");
}
std::string config;
while (arguments.read("--config", config)) {
try {
readProperties(config, props);
} catch (...) {
SG_LOG(SG_GENERAL, SG_ALERT, "Problems loading config file \"" << config
<< "\" given on the command line.");
}
}
std::string prop, value;
while (arguments.read("--prop", prop, value)) {
props->setStringValue(prop, value);
}
std::string renderer;
while (arguments.read("--renderer", renderer));
std::string federation;
if (arguments.read("--federation", federation)) {
props->setStringValue("hla/federate/federation", federation);
}
/// now set up the simgears required model stuff
simgear::ResourceManager::instance()->addBasePath(fg_root, simgear::ResourceManager::PRIORITY_DEFAULT);
// Just reference simgears reader writer stuff so that the globals get
// pulled in by the linker ...
// FIXME: make that more explicit clear and call an initialization function
simgear::ModelRegistry::instance();
// FIXME Ok, replace this by querying the root of the property tree
sgUserDataInit(props.get());
SGSceneFeatures::instance()->setTextureCompression(SGSceneFeatures::DoNotUseCompression);
SGMaterialLibPtr ml = new SGMaterialLib;
SGPath mpath(fg_root);
mpath.append("Materials/default/materials.xml");
try {
ml->load(fg_root, mpath.str(), props);
} catch (...) {
SG_LOG(SG_GENERAL, SG_ALERT, "Problems loading FlightGear materials.\n"
<< "Probably FG_ROOT is not properly set.");
}
simgear::SGModelLib::init(fg_root, props);
// Set up the reader/writer options
osg::ref_ptr<simgear::SGReaderWriterOptions> options;
if (osgDB::Options* ropt = osgDB::Registry::instance()->getOptions())
options = new simgear::SGReaderWriterOptions(*ropt);
else
options = new simgear::SGReaderWriterOptions;
osgDB::convertStringPathIntoFilePathList(fg_scenery,
options->getDatabasePathList());
options->setMaterialLib(ml);
options->setPropertyNode(props);
options->setPluginStringData("SimGear::FG_ROOT", fg_root);
// Omit building bounding volume trees, as the viewer will not run a simulation
options->setPluginStringData("SimGear::BOUNDINGVOLUMES", "OFF");
options->setOptionString("OutputTextureFiles");
//viewer.setReaderWriterOptions(options.get());
// Here, all arguments are processed
arguments.reportRemainingOptionsAsUnrecognized();
arguments.writeErrorMessages(std::cerr);
/// Read the model files that are configured.
osg::ref_ptr<osg::Node> loadedModel;
if (1 < arguments.argc()) {
// read the scene from the list of file specified command line args.
loadedModel = osgDB::readNodeFiles(arguments, options.get());
} else {
// if no arguments given resort to the whole world scenery
options->setPluginStringData("SimGear::FG_EARTH", "ON");
loadedModel = osgDB::readNodeFile("w180s90-360x180.spt", options.get());
}
// if no model has been successfully loaded report failure.
if (!loadedModel.valid()) {
SG_LOG(SG_GENERAL, SG_ALERT, arguments.getApplicationName()
<< ": No data loaded");
return EXIT_FAILURE;
}
osgDB::writeNodeFile(*loadedModel, "saved.3ds", options.get());
}
I compile with:
Code:
g++ -g $1.cxx -o $1 -lSimGearCore -lSimGearScene -losg -losgDB -lOpenThreads -losgViewer
After installing dependencies:
Code:
sudo apt-get install libboost-dev libsimgear-dev libsimgearcore3.0.0 libsimgearscene3.0.0 libopenscenegraph-dev libopenthreads-dev libopenthreads14
I've tried with other formats without success, others don't tend to show anything at all.
Thank you!
Cheers,
Josh[/quote]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64556#64556
More information about the osg-users
mailing list