From Nick, Improved support for 3D labels.

This commit is contained in:
Robert Osfield
2004-02-05 11:39:12 +00:00
parent 22b2e7343e
commit 37ec69a397
6 changed files with 332 additions and 33 deletions

View File

@@ -22,6 +22,8 @@
#include <osgSim/LightPointNode>
#include <osgSim/BlinkSequence>
#include <iostream>
#include <fstream>
#include "TXPArchive.h"
#include "TXPParser.h"
@@ -518,26 +520,88 @@ bool TXPArchive::loadLightAttributes()
return true;
}
void trim(std::string& str)
{
while (!str.empty() && isspace(str[str.length()-1]))
str.erase(str.length()-1);
while (!str.empty() && isspace(str[0]))
str.erase(0,1);
}
bool TXPArchive::loadTextStyles()
{
const trpgTextStyleTable *textStyleTable = GetTextStyleTable();
if (!textStyleTable) return false;
const trpgTextStyleTable *textStyleTable = GetTextStyleTable();
if (!textStyleTable) return false;
if (textStyleTable->GetNumStyle() < 1) return true;
_fonts.resize(textStyleTable->GetNumStyle());
for (int i = 0; i < textStyleTable->GetNumStyle(); i++)
{
const trpgTextStyle *textStyle = textStyleTable->GetStyleRef(i);
if (!textStyle) continue;
// try fontmap.txt
std::map< std::string, std::string > fontmap;
const std::string *fontName = textStyle->GetFont();
if (!fontName) continue;
std::string fmapfname = std::string(getDir())+"\\fontmap.txt";
std::ifstream fmapfile;
fmapfile.open(fmapfname.c_str(),std::ios::in);
osg::ref_ptr< osgText::Font > font = osgText::readFontFile(*fontName + ".ttf");
if (fmapfile.is_open())
{
osg::notify(osg::NOTICE) << "txp:: Font map file found: " << fmapfname << std::endl;
std::string line;
while (getline(fmapfile,line))
{
int ix = line.find_first_of('=');
if (ix != std::string::npos)
{
std::string fontname = line.substr(0,ix);
std::string fontfilename = line.substr(ix+1,line.length()-ix+1);
_fonts[i] = font;
}
trim(fontname);
trim(fontfilename);
return true;
fontmap[fontname] = fontfilename;
}
}
fmapfile.close();
}
else
{
osg::notify(osg::NOTICE) << "txp:: No font map file found: " << fmapfname << std::endl;
osg::notify(osg::NOTICE) << "txp:: All fonts defaulted to ARIAL.TTF" << std::endl;
}
_fonts.resize(textStyleTable->GetNumStyle());
_fcolors.resize(textStyleTable->GetNumStyle());
for (int i = 0; i < textStyleTable->GetNumStyle(); i++)
{
const trpgTextStyle *textStyle = textStyleTable->GetStyleRef(i);
if (!textStyle) continue;
const std::string *fontName = textStyle->GetFont();
if (!fontName) continue;
std::string fontfilename = fontmap[*fontName];
if (!fontfilename.length()) fontfilename = "ARIAL.TTF";
osg::ref_ptr< osgText::Font > font = osgText::readFontFile(fontfilename);
_fonts[i] = font;
const trpgMatTable* matTable = GetMaterialTable();
if (matTable)
{
int matId = textStyle->GetMaterial();
const trpgMaterial* mat = matTable->GetMaterialRef(0,matId);
if (mat)
{
trpgColor faceColor;
mat->GetColor(faceColor);
float64 alpha;
mat->GetAlpha(alpha);
_fcolors[i] = osg::Vec4(faceColor.red, faceColor.green, faceColor.blue, alpha );
}
}
}
return true;
}
void TXPArchive::addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback, const osg::Vec3& att)