Replaced tabs with spaces.

This commit is contained in:
Robert Osfield
2005-11-17 15:03:51 +00:00
parent 0e16b64665
commit d3541b96ed
116 changed files with 6866 additions and 6855 deletions

View File

@@ -3,7 +3,7 @@
using namespace ac3d;
Exception::Exception(std::string error){
_error = error;
_error = error;
}
Exception::~Exception(){}

File diff suppressed because it is too large Load Diff

View File

@@ -147,7 +147,7 @@ struct DDSURFACEDESC2
};
UI32 dwAlphaBitDepth;
UI32 dwReserved;
UI32 lpSurface; //Fred Marmond: removed from pointer type to UI32 for 64bits compatibility. it is unused data
UI32 lpSurface; //Fred Marmond: removed from pointer type to UI32 for 64bits compatibility. it is unused data
DDCOLORKEY ddckCKDestOverlay;
DDCOLORKEY ddckCKDestBlt;
DDCOLORKEY ddckCKSrcOverlay;

View File

@@ -204,7 +204,7 @@ public:
opening[nop-1].addvtx(nvtot);
}
}
void setNBegin(int n1) {nVertStart=n1;}
void setNBegin(int n1) {nVertStart=n1;}
void norm(Vec3 &n, const Vec3 side, const Vec3 s2) const {
n=s2^side; // perpendicular
n.normalize(); // unit norm
@@ -344,7 +344,7 @@ private:
class _face *opening; // openings in this face. number of verts, vertex list for opening
int nv; // number of vertices in the face
int nset; // number read so far
int nVertStart; // start index of vertices in the grand Geometry
int nVertStart; // start index of vertices in the grand Geometry
Vec3 nrm; // surface normal
int *idx; // indices into the vertex list for the object
};
@@ -357,22 +357,22 @@ public:
prims() { nbegin=0; // primlengs=NULL; gsidx=NULL;nrmidx=NULL;
// txidx=NULL;nrms=NULL;txcoords=NULL;
// nload=0; nff=0; curmode=0;
vertices = new osg::Vec3Array;
normals = new osg::Vec3Array;
txc = new osg::Vec3Array;
vertices = new osg::Vec3Array;
normals = new osg::Vec3Array;
txc = new osg::Vec3Array;
txcoords=new osg::Vec3Array; // new Vec2[6*nfnvf]; // one texture coord per vertex
tmat=NULL;
tmat=NULL;
}
~prims() { /*delete [] primlengs; delete [] nrms;
delete [] gsidx; delete [] nrmidx; delete [] txcoords;*/
}
void addv(avertex *pos) { // tesselation callback
vertices->push_back(osg::Vec3(pos->pos[0],pos->pos[1],pos->pos[2]));
normals->push_back(pos->nrmv);
vertices->push_back(osg::Vec3(pos->pos[0],pos->pos[1],pos->pos[2]));
normals->push_back(pos->nrmv);
txcoords->push_back(osg::Vec3(pos->uv[0],pos->uv[1],0.0f));
}
void End() { // tesselation is done
int nverts=vertices->size()-nbegin;
int nverts=vertices->size()-nbegin;
osg::DrawArrays *drw=NULL;
switch (primType) {
case GL_TRIANGLES: //gset->setPrimType( osg::GeoSet::TRIANGLES );
@@ -406,15 +406,15 @@ public:
}
}
void begin(GLenum op) { // part of a tesselator callback - starts a new primitive of type op
primType=op;
nbegin=vertices->size();
primType=op;
nbegin=vertices->size();
}
void combine( GLdouble coords[3], avertex *d[4],
GLfloat w[4], avertex **dataOut , _dwobj *dwob);
void linkholes(const std::vector<Vec3> verts, const dwmaterial *themat,
const _face *f1, const _face *f2,
const int ipr[2], const int nv) {
int gsidx[4];
int gsidx[4];
gsidx[0]=f1->getidx(ipr[1]); // vertex position index
gsidx[1]=f1->getidx(ipr[0]); // vertex position index
gsidx[2]=f2->getidx(nv-ipr[0]-1); // vertex position index
@@ -427,14 +427,14 @@ public:
s2=verts[gsidx[2]]-verts[gsidx[1]];
f1->norm(nrm, s2, s1);
f1->settrans(mx, nrm, verts,themat);
int n1=vertices->size();
int n1=vertices->size();
for (int j=0; j<4; j++) {
Vec3 uv;
Vec3 coord=(verts[gsidx[j]]);
vertices->push_back( coord );
Vec3 coord=(verts[gsidx[j]]);
vertices->push_back( coord );
uv=mx*verts[gsidx[j]];
txcoords->push_back(uv);
normals->push_back(nrm);
txcoords->push_back(uv);
normals->push_back(nrm);
}
osg::DrawArrays *drw=NULL;
drw=new osg::DrawArrays(osg::PrimitiveSet::QUADS,n1,4);
@@ -442,29 +442,29 @@ public:
}
void tesselate(_face &fc, const std::vector<Vec3> verts, const dwmaterial *themat,GLUtesselator* ts, _dwobj *dwob)
{ // generates a set of primitives all of one type (eg tris, qstrip trifan...)
fc.setNBegin(vertices->size());
fc.setNBegin(vertices->size());
fc.tesselate(verts, themat, ts, dwob, tmat);
}
void buildGeometry() { // at end of all faces, add collection of vertices to geometry
gset->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); //BIND_PERPRIM); //
gset->setNormalArray(normals);
gset->setTexCoordArray(0,txcoords);
gset->setNormalArray(normals);
gset->setTexCoordArray(0,txcoords);
gset->setVertexArray(vertices); // setCoords( vts, nusidx );
}
void setGeometry(osg::Geometry *gs) {
gset=gs;
gset=gs;
}
void settmat(const Matrix *mx) {
tmat= mx;
}
private:
osg::Geometry *gset;
osg::Vec3Array* vertices;
osg::Vec3Array* normals;
osg::Vec3Array* txc;
osg::Vec3Array* txcoords;
GLenum primType;
int nbegin; // vertex indices for current primitive
osg::Geometry *gset;
osg::Vec3Array* vertices;
osg::Vec3Array* normals;
osg::Vec3Array* txc;
osg::Vec3Array* txcoords;
GLenum primType;
int nbegin; // vertex indices for current primitive
const Matrix *tmat; // local texture matrix, or may be NULL for default mapping
};
@@ -709,24 +709,24 @@ void _face::tesselate(const std::vector<Vec3> verts, const dwmaterial *themat,
}
void prims::combine( GLdouble coords[3], avertex *d[4],
GLfloat w[4], avertex **dataOut , _dwobj *dwob) {
avertex *newv = new avertex(); // (avertex *)calloc(1, sizeof(avertex));
newv->pos[0] = coords[0];
newv->pos[1] = coords[1];
newv->pos[2] = coords[2];
newv->uv[0] = newv->uv[1] =0;
newv->nrmv[0] = newv->nrmv[1] = newv->nrmv[2] =0;
for (int i=0; i<4; i++) {
if (d[i]) {
newv->uv[0] = w[i]*d[i]->uv[0];
newv->uv[1] = w[i]*d[i]->uv[1];
newv->nrmv[0] = w[i]*d[i]->nrmv[0];
newv->nrmv[1] = w[i]*d[i]->nrmv[1];
newv->nrmv[2] = w[i]*d[i]->nrmv[2];
}
}
dwob->makeuv(newv->uv, newv->pos);
newv->idx=dwob->addvtx(coords[0], coords[1], coords[2]);
*dataOut = newv;
avertex *newv = new avertex(); // (avertex *)calloc(1, sizeof(avertex));
newv->pos[0] = coords[0];
newv->pos[1] = coords[1];
newv->pos[2] = coords[2];
newv->uv[0] = newv->uv[1] =0;
newv->nrmv[0] = newv->nrmv[1] = newv->nrmv[2] =0;
for (int i=0; i<4; i++) {
if (d[i]) {
newv->uv[0] = w[i]*d[i]->uv[0];
newv->uv[1] = w[i]*d[i]->uv[1];
newv->nrmv[0] = w[i]*d[i]->nrmv[0];
newv->nrmv[1] = w[i]*d[i]->nrmv[1];
newv->nrmv[2] = w[i]*d[i]->nrmv[2];
}
}
dwob->makeuv(newv->uv, newv->pos);
newv->idx=dwob->addvtx(coords[0], coords[1], coords[2]);
*dataOut = newv;
}
void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *options)
{ // current DWobject complete; make a drawable, and add it to a osg::Group
@@ -744,45 +744,45 @@ void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *optio
LightSource *ls=themat->makeLight(pos);
grp->addChild(ls);
} else {
Geode *geode = new Geode;
int nfnvf=0; // number of vertices for faces plus holes
int i; // a general counter
for (i=0; i<nfaces; i++) { // for each face
faces[i].setnorm(verts); // set its normal and any hole normals
nfnvf+=faces[i].getallverts(); // get total vertices in object, defines dimensions of NEW arrays
}
GLUtesselator* ts=gluNewTess();
gluTessCallback(ts, GLU_TESS_BEGIN, (GLU_TESS_CALLBACK) myFaceBegin);
gluTessCallback(ts, GLU_TESS_VERTEX, (GLU_TESS_CALLBACK) myVertex);
gluTessCallback(ts, GLU_TESS_END, (GLU_TESS_CALLBACK) myFaceEnd);
gluTessCallback(ts, GLU_TESS_ERROR, (GLU_TESS_CALLBACK) error);
gluTessCallback(ts, GLU_TESS_COMBINE_DATA, (GLU_TESS_CALLBACK) combineCallback);
// for (int nvf=0; nvf<6; nvf++) { // for each length of face
// for Geometry we dont need to collect prim types individually
// prd.setmode(nvf , nfnvf); // filter out only this type of tesselated face
prd=new prims;
prd->settmat(tmat);
osg::Geometry *gset = new osg::Geometry;
prd->setGeometry(gset);
StateSet *dstate=themat->make(options);
gset->setStateSet( dstate );
grp->addChild( geode ); // add to the world outside
geode->addDrawable(gset);
Geode *geode = new Geode;
int nfnvf=0; // number of vertices for faces plus holes
int i; // a general counter
for (i=0; i<nfaces; i++) { // for each face
faces[i].setnorm(verts); // set its normal and any hole normals
nfnvf+=faces[i].getallverts(); // get total vertices in object, defines dimensions of NEW arrays
}
// each face adds a primitive to the geometry, after it is tesselated
GLUtesselator* ts=gluNewTess();
gluTessCallback(ts, GLU_TESS_BEGIN, (GLU_TESS_CALLBACK) myFaceBegin);
gluTessCallback(ts, GLU_TESS_VERTEX, (GLU_TESS_CALLBACK) myVertex);
gluTessCallback(ts, GLU_TESS_END, (GLU_TESS_CALLBACK) myFaceEnd);
gluTessCallback(ts, GLU_TESS_ERROR, (GLU_TESS_CALLBACK) error);
gluTessCallback(ts, GLU_TESS_COMBINE_DATA, (GLU_TESS_CALLBACK) combineCallback);
// for (int nvf=0; nvf<6; nvf++) { // for each length of face
// for Geometry we dont need to collect prim types individually
// prd.setmode(nvf , nfnvf); // filter out only this type of tesselated face
prd=new prims;
prd->settmat(tmat);
osg::Geometry *gset = new osg::Geometry;
prd->setGeometry(gset);
StateSet *dstate=themat->make(options);
gset->setStateSet( dstate );
grp->addChild( geode ); // add to the world outside
geode->addDrawable(gset);
// each face adds a primitive to the geometry, after it is tesselated
for (i=0; i<nfaces; i++) { // for each face, collect up
prd->tesselate(faces[i],verts, themat, ts, this);
}
for (i=0; i<nopens; i++) { // for each hole, join up front & back with Quads
if (fc1 && fc2) {
faces[fc1[i]].link(openings[i*2], &faces[fc2[i]],openings[i*2+1],verts, themat);
}
} // for each opening
if (fc1 && fc2) {
faces[fc1[i]].link(openings[i*2], &faces[fc2[i]],openings[i*2+1],verts, themat);
}
} // for each opening
prd->buildGeometry();
gluDeleteTess(ts);
delete prd;
delete prd;
}
} // nfaces>0
verts.clear();

View File

@@ -50,12 +50,12 @@ ReaderWriterdxf::readNode(const std::string& filename, const osgDB::ReaderWriter
std::string ext = osgDB::getFileExtension(filename);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
// Open
dxfFile df(filename);
if (df.parseFile()) {
// convert to OSG
osg::Group* osg_top = df.dxf2osg();
return (osg_top);
}
return ReadResult::FILE_NOT_HANDLED;
dxfFile df(filename);
if (df.parseFile()) {
// convert to OSG
osg::Group* osg_top = df.dxf2osg();
return (osg_top);
}
return ReadResult::FILE_NOT_HANDLED;
}

View File

@@ -21,38 +21,38 @@ using namespace std;
void
dxfBlock::assign(dxfFile* dxf, codeValue& cv)
{
string s = cv._string;
if (cv._groupCode == 0) {
if (_currentEntity && _currentEntity->done()) {
_currentEntity = new dxfEntity(s);
_entityList.push_back(_currentEntity);
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else {
_currentEntity = new dxfEntity(s);
_entityList.push_back(_currentEntity);
}
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else if (cv._groupCode != 0) {
double d = cv._double;
switch (cv._groupCode) {
case 2:
_name = s;
case 10:
_position.x() = d;
break;
case 20:
_position.y() = d;
break;
case 30:
_position.z() = d;
break;
default:
// dxf garble
break;
}
}
string s = cv._string;
if (cv._groupCode == 0) {
if (_currentEntity && _currentEntity->done()) {
_currentEntity = new dxfEntity(s);
_entityList.push_back(_currentEntity);
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else {
_currentEntity = new dxfEntity(s);
_entityList.push_back(_currentEntity);
}
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else if (cv._groupCode != 0) {
double d = cv._double;
switch (cv._groupCode) {
case 2:
_name = s;
case 10:
_position.x() = d;
break;
case 20:
_position.y() = d;
break;
case 30:
_position.z() = d;
break;
default:
// dxf garble
break;
}
}
}
const osg::Vec3d& dxfBlock::getPosition() const { return _position; }

File diff suppressed because it is too large Load Diff

View File

@@ -22,52 +22,52 @@
using namespace std;
bool
bool
dxfFile::parseFile()
{
if (_fileName == "") return false;
_reader = new dxfReader;
if (_reader->openFile(_fileName)) {
codeValue cv;
while(_reader->nextGroupCode(cv)) {
short result = assign(cv);
if (result < 0)
return false;
else if (result == 0) {
return true;
}
}
// we did not reach 0 EOF
return false;
} else {
return false;
}
if (_fileName == "") return false;
_reader = new dxfReader;
if (_reader->openFile(_fileName)) {
codeValue cv;
while(_reader->nextGroupCode(cv)) {
short result = assign(cv);
if (result < 0)
return false;
else if (result == 0) {
return true;
}
}
// we did not reach 0 EOF
return false;
} else {
return false;
}
}
osg::Group*
dxfFile::dxf2osg()
{
if (!_entities) return NULL;
if (!_tables) { // a dxfTable is needed to create undefined layers
_tables = new dxfTables;
}
osg::ref_ptr<dxfLayerTable> layerTable = _tables->getOrCreateLayerTable();
// to do: should be more general and pass a pointer to ourselves
// which in turn should be able to feed any information
// the scene might need
_scene = new scene(layerTable.get());
_entities->drawScene(_scene.get());
osg::Group* g = _scene->scene2osg();
return g;
if (!_entities) return NULL;
if (!_tables) { // a dxfTable is needed to create undefined layers
_tables = new dxfTables;
}
osg::ref_ptr<dxfLayerTable> layerTable = _tables->getOrCreateLayerTable();
// to do: should be more general and pass a pointer to ourselves
// which in turn should be able to feed any information
// the scene might need
_scene = new scene(layerTable.get());
_entities->drawScene(_scene.get());
osg::Group* g = _scene->scene2osg();
return g;
}
dxfBlock*
dxfBlock*
dxfFile::findBlock(std::string name)
{
if (_blocks.get())
return _blocks->findBlock(name);
return NULL;
if (_blocks.get())
return _blocks->findBlock(name);
return NULL;
}
/// not used. if you want to know what a header variable
@@ -76,45 +76,45 @@ dxfFile::findBlock(std::string name)
VariableList
dxfFile::getVariable(std::string var)
{
return _header->getVariable(var);
return _header->getVariable(var);
}
/// parse the dxf sections
short
dxfFile::assign(codeValue& cv)
{
std::string s = cv._string;
if (cv._groupCode == 0 && s == std::string("ENDSEC")) {
_isNewSection = false;
_current = _unknown.get();
} else if (cv._groupCode == 0 && s == std::string("SECTION")) {
_isNewSection = true;
} else if (cv._groupCode == 0 && s == std::string("EOF")) {
return 0;
} else if (cv._groupCode == 2 && _isNewSection) {
_isNewSection = false;
// std::cout << "Reading section " << s << std::endl;
if (s =="HEADER") {
_header = new dxfHeader;
_current = _header.get();
} else if (s =="TABLES") {
_tables = new dxfTables;
_current = _tables.get();
} else if (s =="BLOCKS") {
_blocks = new dxfBlocks;
_current = _blocks.get();
} else if (s =="ENTITIES") {
_entities = new dxfEntities;
_current = _entities.get();
} else {
_current = _unknown.get();
}
} else if (_isNewSection) {
// problem. a 0/SECTION should be followed by a 2/SECTION_NAME
std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl;
return -1;
} else if (_current.get()) {
_current->assign(this, cv);
}
return 1;
std::string s = cv._string;
if (cv._groupCode == 0 && s == std::string("ENDSEC")) {
_isNewSection = false;
_current = _unknown.get();
} else if (cv._groupCode == 0 && s == std::string("SECTION")) {
_isNewSection = true;
} else if (cv._groupCode == 0 && s == std::string("EOF")) {
return 0;
} else if (cv._groupCode == 2 && _isNewSection) {
_isNewSection = false;
// std::cout << "Reading section " << s << std::endl;
if (s =="HEADER") {
_header = new dxfHeader;
_current = _header.get();
} else if (s =="TABLES") {
_tables = new dxfTables;
_current = _tables.get();
} else if (s =="BLOCKS") {
_blocks = new dxfBlocks;
_current = _blocks.get();
} else if (s =="ENTITIES") {
_entities = new dxfEntities;
_current = _entities.get();
} else {
_current = _unknown.get();
}
} else if (_isNewSection) {
// problem. a 0/SECTION should be followed by a 2/SECTION_NAME
std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl;
return -1;
} else if (_current.get()) {
_current->assign(this, cv);
}
return 1;
}

View File

@@ -27,10 +27,10 @@ static
std::string
trim(const string& str)
{
if (!str.size()) return str;
string::size_type first = str.find_first_not_of(" \t");
string::size_type last = str.find_last_not_of(" \t\r\n");
return str.substr(first, last-first+1);
if (!str.size()) return str;
string::size_type first = str.find_first_not_of(" \t");
string::size_type last = str.find_last_not_of(" \t\r\n");
return str.substr(first, last-first+1);
}
/*
@@ -38,38 +38,38 @@ trim(const string& str)
*/
bool readerBase::readGroup(std::ifstream& f, codeValue& cv)
{
cv.reset();
if (readGroupCode(f, cv._groupCode)) {
cv._type = dxfDataType::typeForCode(cv._groupCode);
switch (cv._type) {
case dxfDataType::BOOL:
return readValue(f, cv._bool);
break;
case dxfDataType::SHORT:
return readValue(f, cv._short);
break;
case dxfDataType::INT:
return readValue(f, cv._int);
break;
case dxfDataType::LONG:
return readValue(f, cv._long);
break;
case dxfDataType::DOUBLE:
return readValue(f, cv._double);
break;
case dxfDataType::UNKNOWN:
case dxfDataType::STRING:
case dxfDataType::HEX:
default: // to do: default case an error
return readValue(f, cv._string);
break;
cv.reset();
if (readGroupCode(f, cv._groupCode)) {
cv._type = dxfDataType::typeForCode(cv._groupCode);
switch (cv._type) {
case dxfDataType::BOOL:
return readValue(f, cv._bool);
break;
case dxfDataType::SHORT:
return readValue(f, cv._short);
break;
case dxfDataType::INT:
return readValue(f, cv._int);
break;
case dxfDataType::LONG:
return readValue(f, cv._long);
break;
case dxfDataType::DOUBLE:
return readValue(f, cv._double);
break;
case dxfDataType::UNKNOWN:
case dxfDataType::STRING:
case dxfDataType::HEX:
default: // to do: default case an error
return readValue(f, cv._string);
break;
}
} else {
cv._type = dxfDataType::UNKNOWN;
cv._groupCode = -1;
}
return false;
}
} else {
cv._type = dxfDataType::UNKNOWN;
cv._groupCode = -1;
}
return false;
}
/*
@@ -78,88 +78,88 @@ bool readerBase::readGroup(std::ifstream& f, codeValue& cv)
bool readerText::success(bool inSuccess, string type)
{
if (!inSuccess)
cout << "Error converting line " << _lineCount << " to type " << type << endl;
return inSuccess;
if (!inSuccess)
cout << "Error converting line " << _lineCount << " to type " << type << endl;
return inSuccess;
}
bool readerText::getTrimmedLine(std::ifstream& f)
{
static string line = "";
if (getline(f, line, _delim)) {
++_lineCount;
_str.clear();
_str.str(trim(line));
return true;
}
return false;
static string line = "";
if (getline(f, line, _delim)) {
++_lineCount;
_str.clear();
_str.str(trim(line));
return true;
}
return false;
}
bool readerText::readGroupCode(std::ifstream& f, int &groupcode)
{
if (getTrimmedLine(f)) {
_str >> groupcode;
return success(!_str.fail(), "int");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> groupcode;
return success(!_str.fail(), "int");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, string &s)
{
if (getTrimmedLine(f)) {
getline(_str, s);
// empty string is valid
return success((!_str.fail() || s == ""), "string");
} else {
return false;
}
if (getTrimmedLine(f)) {
getline(_str, s);
// empty string is valid
return success((!_str.fail() || s == ""), "string");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, bool &b)
{
if (getTrimmedLine(f)) {
_str >> b;
return success(!_str.fail(), "bool");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> b;
return success(!_str.fail(), "bool");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, unsigned short &s)
{
if (getTrimmedLine(f)) {
_str >> s;
return success(!_str.fail(), "unsigned short");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> s;
return success(!_str.fail(), "unsigned short");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, int &i)
{
if (getTrimmedLine(f)) {
_str >> i;
return success(!_str.fail(), "int");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> i;
return success(!_str.fail(), "int");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, long &l)
{
if (getTrimmedLine(f)) {
_str >> l;
return success(!_str.fail(), "long");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> l;
return success(!_str.fail(), "long");
} else {
return false;
}
}
bool readerText::readValue(std::ifstream& f, double &d)
{
if (getTrimmedLine(f)) {
_str >> d;
return success(!_str.fail(), "double");
} else {
return false;
}
if (getTrimmedLine(f)) {
_str >> d;
return success(!_str.fail(), "double");
} else {
return false;
}
}
/*
@@ -167,38 +167,38 @@ bool readerText::readValue(std::ifstream& f, double &d)
*/
bool
bool
dxfReader::openFile(std::string fileName)
{
if (fileName.size() == 0) return false;
_ifs.open(fileName.c_str(), ios::binary); // found mac autocad with \r delimiters
if (!_ifs) {
cout << " Can't open " << fileName << endl;
return false;
}
// A binary file starts with "AutoCAD Binary DXF<CR><LF><SUB><NULL>"
if (fileName.size() == 0) return false;
_ifs.open(fileName.c_str(), ios::binary); // found mac autocad with \r delimiters
if (!_ifs) {
cout << " Can't open " << fileName << endl;
return false;
}
// A binary file starts with "AutoCAD Binary DXF<CR><LF><SUB><NULL>"
char buf[255];
_ifs.get(buf, 255);
string sentinel(buf);
if (trim(sentinel) == "AutoCAD Binary DXF") {
cout << " Binary DXF not supported. For now. Come back soon." << endl;
return false;
}
//string::size_type lf = sentinel.find('\n');
//string::size_type cr = sentinel.find('\r');
// gossage. un mac peut mettre juste CR. ca fonctionne pas:
// if (cr > 0 && (!lf || lf > cr + 1))
// _reader = new readerText('\r');
// else
_reader = new readerText;
_ifs.seekg(0, ios::beg);
return true;
char buf[255];
_ifs.get(buf, 255);
string sentinel(buf);
if (trim(sentinel) == "AutoCAD Binary DXF") {
cout << " Binary DXF not supported. For now. Come back soon." << endl;
return false;
}
//string::size_type lf = sentinel.find('\n');
//string::size_type cr = sentinel.find('\r');
// gossage. un mac peut mettre juste CR. ca fonctionne pas:
// if (cr > 0 && (!lf || lf > cr + 1))
// _reader = new readerText('\r');
// else
_reader = new readerText;
_ifs.seekg(0, ios::beg);
return true;
}
bool
dxfReader::nextGroupCode(codeValue& cv)
{
return (_reader->readGroup(_ifs, cv));
return (_reader->readGroup(_ifs, cv));
}

View File

@@ -16,71 +16,71 @@
void dxfHeader::assign(dxfFile*, codeValue& cv)
{
if (cv._groupCode == 9) {
_inVariable = true;
VariableList var;
_variables[cv._string] = var;
_currentVariable = cv._string;
} else if (_inVariable) {
VariableList& var = getVariable(_currentVariable);
var.push_back(cv);
}
if (cv._groupCode == 9) {
_inVariable = true;
VariableList var;
_variables[cv._string] = var;
_currentVariable = cv._string;
} else if (_inVariable) {
VariableList& var = getVariable(_currentVariable);
var.push_back(cv);
}
}
void dxfTables::assign(dxfFile* dxf, codeValue& cv)
{
if (cv._groupCode == 0 && cv._string == "TABLE") {
_currentTable = NULL;
} else if (cv._groupCode == 2 && !_currentTable.get()) {
// treat layer table as a special case
if (cv._string == "LAYER") {
_layerTable = new dxfLayerTable;
_currentTable = _layerTable.get();
} else {
_currentTable = new dxfTable;
_others.push_back(_currentTable.get());
}
} else if (_currentTable.get()) {
_currentTable->assign(dxf, cv);
}
if (cv._groupCode == 0 && cv._string == "TABLE") {
_currentTable = NULL;
} else if (cv._groupCode == 2 && !_currentTable.get()) {
// treat layer table as a special case
if (cv._string == "LAYER") {
_layerTable = new dxfLayerTable;
_currentTable = _layerTable.get();
} else {
_currentTable = new dxfTable;
_others.push_back(_currentTable.get());
}
} else if (_currentTable.get()) {
_currentTable->assign(dxf, cv);
}
}
void dxfBlocks::assign(dxfFile* dxf, codeValue& cv)
{
if (cv._groupCode == 0 && cv._string == std::string("BLOCK")) {
_currentBlock = new dxfBlock;
_blockList.push_back(_currentBlock);
} else if (cv._groupCode == 0 && cv._string == std::string("ENDBLK") && _currentBlock) {
std::string bn = _currentBlock->getName();
_blockNameList[bn] = _currentBlock;
} else if (_currentBlock) {
_currentBlock->assign(dxf, cv);
}
if (cv._groupCode == 0 && cv._string == std::string("BLOCK")) {
_currentBlock = new dxfBlock;
_blockList.push_back(_currentBlock);
} else if (cv._groupCode == 0 && cv._string == std::string("ENDBLK") && _currentBlock) {
std::string bn = _currentBlock->getName();
_blockNameList[bn] = _currentBlock;
} else if (_currentBlock) {
_currentBlock->assign(dxf, cv);
}
}
void dxfEntities::assign(dxfFile* dxf, codeValue& cv)
{
if (cv._groupCode == 0) {
if (_currentEntity && _currentEntity->done()) {
_currentEntity = new dxfEntity(cv._string);
_entityList.push_back(_currentEntity);
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else {
_currentEntity = new dxfEntity(cv._string);
_entityList.push_back(_currentEntity);
}
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
}
if (cv._groupCode == 0) {
if (_currentEntity && _currentEntity->done()) {
_currentEntity = new dxfEntity(cv._string);
_entityList.push_back(_currentEntity);
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
} else {
_currentEntity = new dxfEntity(cv._string);
_entityList.push_back(_currentEntity);
}
} else if (_currentEntity) {
_currentEntity->assign(dxf, cv);
}
}
void
dxfEntities::drawScene(scene* sc)
{
for (std::vector<dxfEntity*>::iterator itr = _entityList.begin();
itr != _entityList.end(); ++itr)
(*itr)->drawScene(sc);
for (std::vector<dxfEntity*>::iterator itr = _entityList.begin();
itr != _entityList.end(); ++itr)
(*itr)->drawScene(sc);
}
dxfBlock*
dxfBlocks::findBlock(std::string s) { return _blockNameList[s]; }

View File

@@ -16,31 +16,31 @@
void dxfLayer::assign(dxfFile*, codeValue& cv)
{
switch (cv._groupCode) {
case 2:
_name = cv._string;
break;
case 62:
_color = cv._short;
if ((short)_color < 0) _frozen = true;
break;
case 70:
_frozen = (bool)(cv._short & 1);
break;
}
switch (cv._groupCode) {
case 2:
_name = cv._string;
break;
case 62:
_color = cv._short;
if ((short)_color < 0) _frozen = true;
break;
case 70:
_frozen = (bool)(cv._short & 1);
break;
}
}
void dxfLayerTable::assign(dxfFile* dxf, codeValue& cv)
{
std::string s = cv._string;
if (cv._groupCode == 0 ) {
if (_currentLayer.get()) {
_layers[_currentLayer->getName()] = _currentLayer.get();
}
if (s == "LAYER") {
_currentLayer = new dxfLayer;
} // otherwise it's the close call from ENDTAB
} else if (_currentLayer.get()) {
_currentLayer->assign(dxf, cv);
}
std::string s = cv._string;
if (cv._groupCode == 0 ) {
if (_currentLayer.get()) {
_layers[_currentLayer->getName()] = _currentLayer.get();
}
if (s == "LAYER") {
_currentLayer = new dxfLayer;
} // otherwise it's the close call from ENDTAB
} else if (_currentLayer.get()) {
_currentLayer->assign(dxf, cv);
}
}

View File

@@ -10,180 +10,180 @@ using namespace osg;
using namespace std;
osg::Vec4
osg::Vec4
sceneLayer::getColor(unsigned short color)
{
// you're supposed to have a correct color in hand
unsigned short r = color * 3;
unsigned short g = color * 3 + 1;
unsigned short b = color * 3 + 2;
Vec4 c(aci::table[r], aci::table[g], aci::table[b], 1.0f);
return c;
// you're supposed to have a correct color in hand
unsigned short r = color * 3;
unsigned short g = color * 3 + 1;
unsigned short b = color * 3 + 2;
Vec4 c(aci::table[r], aci::table[g], aci::table[b], 1.0f);
return c;
}
scene::scene(dxfLayerTable* lt) : _layerTable(lt)
{
_m.makeIdentity();
_r.makeIdentity();
_m.makeIdentity();
_r.makeIdentity();
}
void
scene::setLayerTable(dxfLayerTable* lt)
{
_layerTable = lt;
_layerTable = lt;
}
Vec3d scene::addVertex(Vec3d v)
{
v += _t;
v = preMultd(_r, v);
osg::Matrixd m = osg::Matrixd::translate(v.x(), v.y(), v.z());
m = m * _m;
Vec3d a = preMultd(m, Vec3d(0,0,0));
_b.expandBy(a);
return a;
v += _t;
v = preMultd(_r, v);
osg::Matrixd m = osg::Matrixd::translate(v.x(), v.y(), v.z());
m = m * _m;
Vec3d a = preMultd(m, Vec3d(0,0,0));
_b.expandBy(a);
return a;
}
Vec3d scene::addNormal(Vec3d v)
{
// to do: vertices are not always listed in order. find why.
return v;
// to do: vertices are not always listed in order. find why.
return v;
}
void
scene::addLine(std::string l, unsigned short color, Vec3d s, Vec3d e)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
Vec3d a(addVertex(s)), b(addVertex(e));
ly->_lines[correctedColorIndex(l, color)].push_back(a);
ly->_lines[correctedColorIndex(l, color)].push_back(b);
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
Vec3d a(addVertex(s)), b(addVertex(e));
ly->_lines[correctedColorIndex(l, color)].push_back(a);
ly->_lines[correctedColorIndex(l, color)].push_back(b);
}
void scene::addLineStrip(std::string l, unsigned short color, std::vector<Vec3d> vertices)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
std::vector<Vec3d> converted;
for (std::vector<Vec3d>::iterator itr = vertices.begin();
itr != vertices.end(); ++itr) {
converted.push_back(addVertex(*itr));
}
ly->_linestrips[correctedColorIndex(l, color)].push_back(converted);
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
std::vector<Vec3d> converted;
for (std::vector<Vec3d>::iterator itr = vertices.begin();
itr != vertices.end(); ++itr) {
converted.push_back(addVertex(*itr));
}
ly->_linestrips[correctedColorIndex(l, color)].push_back(converted);
}
void scene::addLineLoop(std::string l, unsigned short color, std::vector<Vec3d> vertices)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
std::vector<Vec3d> converted;
for (std::vector<Vec3d>::iterator itr = vertices.begin();
itr != vertices.end(); ++itr) {
converted.push_back(addVertex(*itr));
}
converted.push_back(addVertex(vertices.front()));
ly->_linestrips[correctedColorIndex(l, color)].push_back(converted);
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
std::vector<Vec3d> converted;
for (std::vector<Vec3d>::iterator itr = vertices.begin();
itr != vertices.end(); ++itr) {
converted.push_back(addVertex(*itr));
}
converted.push_back(addVertex(vertices.front()));
ly->_linestrips[correctedColorIndex(l, color)].push_back(converted);
}
void scene::addTriangles(std::string l, unsigned short color, std::vector<Vec3d> vertices, bool inverted)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
for (VList::iterator itr = vertices.begin();
itr != vertices.end(); ) {
VList::iterator a;
VList::iterator b;
VList::iterator c;
if (inverted) {
c = itr++;
b = itr++;
a = itr++;
} else {
a = itr++;
b = itr++;
c = itr++;
}
if (a != vertices.end() &&
b != vertices.end() &&
c != vertices.end()) {
Vec3d n = ((*b - *a) ^ (*c - *a));
n.normalize();
ly->_trinorms[correctedColorIndex(l, color)].push_back( n );
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*a));
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*b));
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*c));
}
}
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
for (VList::iterator itr = vertices.begin();
itr != vertices.end(); ) {
VList::iterator a;
VList::iterator b;
VList::iterator c;
if (inverted) {
c = itr++;
b = itr++;
a = itr++;
} else {
a = itr++;
b = itr++;
c = itr++;
}
if (a != vertices.end() &&
b != vertices.end() &&
c != vertices.end()) {
Vec3d n = ((*b - *a) ^ (*c - *a));
n.normalize();
ly->_trinorms[correctedColorIndex(l, color)].push_back( n );
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*a));
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*b));
ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*c));
}
}
}
void scene::addQuads(std::string l, unsigned short color, std::vector<Vec3d> vertices, bool inverted)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
for (VList::iterator itr = vertices.begin();
itr != vertices.end(); ) {
VList::iterator a = vertices.end();
VList::iterator b = vertices.end();
VList::iterator c = vertices.end();
VList::iterator d = vertices.end();
if (inverted) {
d = itr++;
if (itr != vertices.end())
c = itr++;
if (itr != vertices.end())
b = itr++;
if (itr != vertices.end())
a = itr++;
} else {
a = itr++;
if (itr != vertices.end())
b = itr++;
if (itr != vertices.end())
c = itr++;
if (itr != vertices.end())
d = itr++;
}
if (a != vertices.end() &&
b != vertices.end() &&
c != vertices.end()&&
d != vertices.end()) {
Vec3d n = ((*b - *a) ^ (*c - *a));
n.normalize();
short cindex = correctedColorIndex(l, color);
ly->_quadnorms[cindex].push_back( n );
MapVList mvl = ly->_quads;
VList vl = mvl[cindex];
vl.push_back(addVertex(*a));
vl.push_back(addVertex(*b));
vl.push_back(addVertex(*c));
vl.push_back(addVertex(*d));
mvl[cindex] = vl;
ly->_quads = mvl;
}
}
}
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
for (VList::iterator itr = vertices.begin();
itr != vertices.end(); ) {
VList::iterator a = vertices.end();
VList::iterator b = vertices.end();
VList::iterator c = vertices.end();
VList::iterator d = vertices.end();
if (inverted) {
d = itr++;
if (itr != vertices.end())
c = itr++;
if (itr != vertices.end())
b = itr++;
if (itr != vertices.end())
a = itr++;
} else {
a = itr++;
if (itr != vertices.end())
b = itr++;
if (itr != vertices.end())
c = itr++;
if (itr != vertices.end())
d = itr++;
}
if (a != vertices.end() &&
b != vertices.end() &&
c != vertices.end()&&
d != vertices.end()) {
Vec3d n = ((*b - *a) ^ (*c - *a));
n.normalize();
short cindex = correctedColorIndex(l, color);
ly->_quadnorms[cindex].push_back( n );
MapVList mvl = ly->_quads;
VList vl = mvl[cindex];
vl.push_back(addVertex(*a));
vl.push_back(addVertex(*b));
vl.push_back(addVertex(*c));
vl.push_back(addVertex(*d));
mvl[cindex] = vl;
ly->_quads = mvl;
}
}
}
unsigned short
scene::correctedColorIndex(std::string l, unsigned short color)
{
if (color >= aci::MIN && color <= aci::MAX) {
return color;
} else if (!color || color == aci::BYLAYER) {
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
unsigned short lcolor = layer->getColor();
if (lcolor >= aci::MIN && lcolor <= aci::MAX) {
return lcolor;
} else {
return aci::WHITE;
}
} else {
return aci::WHITE;
}
if (color >= aci::MIN && color <= aci::MAX) {
return color;
} else if (!color || color == aci::BYLAYER) {
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
unsigned short lcolor = layer->getColor();
if (lcolor >= aci::MIN && lcolor <= aci::MAX) {
return lcolor;
} else {
return aci::WHITE;
}
} else {
return aci::WHITE;
}
}

View File

@@ -13,6 +13,6 @@ void FindExternalModelVisitor::apply( osg::Node &node )
if ( node.getName() == _modelName )
_model = &node; // Store the node. No need to process children.
else
traverse( node );
traverse( node );
}

View File

@@ -35,10 +35,10 @@ void GroupRecord::endian()
ENDIAN( pSGroup->iSpecialId_2 );
ENDIAN( pSGroup->iSignificance );
if (getFltFile()->getFlightVersion() >= 1580 )
{
ENDIAN( pSGroup->iLoopCount );
ENDIAN( pSGroup->fLoopDuration );
ENDIAN( pSGroup->fLastFrameDuration );
}
if (getFltFile()->getFlightVersion() >= 1580 )
{
ENDIAN( pSGroup->iLoopCount );
ENDIAN( pSGroup->fLoopDuration );
ENDIAN( pSGroup->fLastFrameDuration );
}
}

View File

@@ -99,8 +99,8 @@ void HeaderRecord::endian()
memcpy( &(pHeader->RecHeader), src, 4 ); src += 4;
memcpy( &(pHeader->szIdent), src, 8 ); src += 8;
// Be sure to swap revision level here, since we reference it to determine
// which other fields to memcpy.
// Be sure to swap revision level here, since we reference it to determine
// which other fields to memcpy.
memcpy( &(pHeader->diFormatRevLev), src, 4 ); src += 4;
ENDIAN( pHeader->diFormatRevLev );

View File

@@ -109,27 +109,27 @@ void LtPtAnimationPaletteRecord::endian()
ENDIAN( ltPtAnim->charRate );
ENDIAN( ltPtAnim->numSequences );
for (int idx=0; idx < ltPtAnim->numSequences; idx++)
{
SLightPointAnimationSequence* seq = sequence( idx );
assert( seq );
ENDIAN( seq->seqState );
ENDIAN( seq->duration );
ENDIAN( seq->seqColor );
}
for (int idx=0; idx < ltPtAnim->numSequences; idx++)
{
SLightPointAnimationSequence* seq = sequence( idx );
assert( seq );
ENDIAN( seq->seqState );
ENDIAN( seq->duration );
ENDIAN( seq->seqColor );
}
}
SLightPointAnimationSequence*
LtPtAnimationPaletteRecord::sequence( int idx )
{
SLightPointAnimationPalette* ltPtAnim = (SLightPointAnimationPalette*)getData();
if (idx >= ltPtAnim->numSequences)
return NULL;
if (idx >= ltPtAnim->numSequences)
return NULL;
SLightPointAnimationSequence* seq = (SLightPointAnimationSequence*)
( (char*)getData() + sizeof( SLightPointAnimationPalette ) );
seq += idx;
SLightPointAnimationSequence* seq = (SLightPointAnimationSequence*)
( (char*)getData() + sizeof( SLightPointAnimationPalette ) );
seq += idx;
return seq;
return seq;
}

View File

@@ -37,10 +37,10 @@ void LodRecord::endian()
pSLod->Center.endian();
ENDIAN( pSLod->dfTransitionRange );
if (getFltFile()->getFlightVersion() >= 1580 )
{
if (getFltFile()->getFlightVersion() >= 1580 )
{
ENDIAN( pSLod->dfSignificantSize );
}
}
}

View File

@@ -3,8 +3,8 @@
// may be replaced when clipRegion accepted into OSG proper.
// i) a clipregion is class derived from Group, with a Geode and any children of the group
// ii) a special draw is made that:
// sets stencil bits by drawing the clip Geode
// draws the children of group clipped by the stencil region.
// sets stencil bits by drawing the clip Geode
// draws the children of group clipped by the stencil region.
// partly derived fromt he stencil code in osgreflect example.
#include "ClipRegion.h"
@@ -19,7 +19,7 @@ using namespace osg;
//=====
GeoClipRegion::GeoClipRegion(int bin)
{
stencilbin=bin;
stencilbin=bin;
}
GeoClipRegion::~GeoClipRegion()
@@ -31,28 +31,28 @@ GeoClipRegion::GeoClipRegion(const GeoClipRegion& clr,const osg::CopyOp& copyop)
}
void GeoClipRegion::addClipNode(osg::Node *gd) {
osg::StateSet *state=gd->getOrCreateStateSet();
// add clip node(s) to set stencil bit marking the clip area.
// stencil op so that the stencil buffer get set at the clip pixels
osg::Stencil* stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::ALWAYS,1,~0);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE);
state->setAttributeAndModes(stencil,osg::StateAttribute::ON);
// switch off the writing to the color bit planes. (Dont show the clip area)
osg::ColorMask* colorMask = new osg::ColorMask;
colorMask->setMask(false,false,false,false);
state->setRenderBinDetails(stencilbin,"RenderBin");
state->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
state->setAttribute(colorMask);
osg::StateSet *state=gd->getOrCreateStateSet();
// add clip node(s) to set stencil bit marking the clip area.
// stencil op so that the stencil buffer get set at the clip pixels
osg::Stencil* stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::ALWAYS,1,~0);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE);
state->setAttributeAndModes(stencil,osg::StateAttribute::ON);
// switch off the writing to the color bit planes. (Dont show the clip area)
osg::ColorMask* colorMask = new osg::ColorMask;
colorMask->setMask(false,false,false,false);
state->setRenderBinDetails(stencilbin,"RenderBin");
state->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
state->setAttribute(colorMask);
// set up depth so all writing to depth goes to maximum depth. (dont want to z-clip the cull stencil)
osg::Depth* depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
depth->setRange(1.0,1.0);
state->setAttribute(depth);
Group::addChild(gd);
state->setAttribute(depth);
Group::addChild(gd);
}
bool GeoClipRegion::addChild( osg::Node *child )
@@ -65,14 +65,14 @@ bool GeoClipRegion::addChild( osg::Node *child )
stencil->setFunction(osg::Stencil::ALWAYS,0,~0);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE);
statesetBin2->setAttributeAndModes(stencil,osg::StateAttribute::ON);*/
return Group::addChild(child);
return Group::addChild(child);
}
bool GeoClipRegion::addClippedChild( osg::Node *child )
{
// these children of this clipregion are drawn in stencilBin+2, clipped at the edges of the clip region
osg::StateSet *state=child->getOrCreateStateSet();
// state tests pixels against the set stencil.
osg::StateSet *state=child->getOrCreateStateSet();
// state tests pixels against the set stencil.
osg::Stencil* stenciltest = new osg::Stencil;
stenciltest->setFunction(osg::Stencil::EQUAL,1,~0);
stenciltest->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
@@ -89,13 +89,13 @@ bool GeoClipRegion::addClippedChild( osg::Node *child )
rootDepth->setRange(0.0,1.0);
state->setAttribute(rootDepth);
return Group::addChild(child);
return Group::addChild(child);
}
bool GeoClipRegion::addObscuredChild( osg::Node *child )
{
// other children of this node are drawn in stencilBin+2 outside the clip, hidden by the clip region
osg::StateSet *state=child->getOrCreateStateSet();
// state tests pixels against the set stencil.
osg::StateSet *state=child->getOrCreateStateSet();
// state tests pixels against the set stencil.
osg::Stencil* stenciltest = new osg::Stencil;
stenciltest->setFunction(osg::Stencil::NOTEQUAL,1,~0);
stenciltest->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
@@ -111,13 +111,13 @@ bool GeoClipRegion::addObscuredChild( osg::Node *child )
rootDepth->setFunction(osg::Depth::LESS);
rootDepth->setRange(0.0,1.0);
state->setAttribute(rootDepth);
return Group::addChild(child);
return Group::addChild(child);
}
void GeoClipRegion::addDrawClipNode(osg::Node *ndclip)
{
osg::StateSet *state=ndclip->getOrCreateStateSet();
// last bin - draw clip area and blend it with the clipped, visible geometry.
osg::StateSet *state=ndclip->getOrCreateStateSet();
// last bin - draw clip area and blend it with the clipped, visible geometry.
// set up depth so all writing to depth goes to maximum depth.
osg::Depth* depth = new osg::Depth;
@@ -136,5 +136,5 @@ void GeoClipRegion::addDrawClipNode(osg::Node *ndclip)
state->setAttributeAndModes(stencil,osg::StateAttribute::ON);
state->setAttributeAndModes(trans,osg::StateAttribute::ON);
state->setAttribute(depth);
Group::addChild(ndclip);
Group::addChild(ndclip);
}

View File

@@ -200,8 +200,8 @@ public:
// gr is tha vertex; gface is the face containing the vertex
bool hbeh=false; // true if this vertex has a behaviour
if (gr->getType()==DB_DSK_VERTEX ||
gr->getType()==DB_DSK_FAT_VERTEX ||
gr->getType()==DB_DSK_SLIM_VERTEX) {
gr->getType()==DB_DSK_FAT_VERTEX ||
gr->getType()==DB_DSK_SLIM_VERTEX) {
const geoField *gfshade=gface->getField(GEO_DB_POLY_SHADEMODEL); // shaded gouraud, flat...
int shademodel=gfshade ? gfshade->getInt() : -1;
if (shademodel!=GEO_POLY_SHADEMODEL_LIT && shademodel!=GEO_POLY_SHADEMODEL_FLAT) {
@@ -894,8 +894,8 @@ class ReaderGEO
++itr)
{
if ((*itr)->getType()==DB_DSK_VERTEX ||
(*itr)->getType()==DB_DSK_FAT_VERTEX ||
(*itr)->getType()==DB_DSK_SLIM_VERTEX)
(*itr)->getType()==DB_DSK_FAT_VERTEX ||
(*itr)->getType()==DB_DSK_SLIM_VERTEX)
{ // light point vertices
const geoField *gfd=(*itr)->getField(GEO_DB_VRTX_COORD);
osg::Vec3 pos;

View File

@@ -124,7 +124,7 @@ void geoAr3Behaviour::doaction(osg::Node *) { // do math operation
bool geoAr3Behaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeader) {
bool ok=false;
const geoField *gfd=grec->getField(GEO_DB_EQUATION_ACTION_INPUT_VAR);
const unsigned int act=grec->getType();
const unsigned int act=grec->getType();
if (gfd) {
unsigned fid= gfd->getUInt(); // field identifier
in=theHeader->getVar(fid); // returns address of input var with fid
@@ -366,7 +366,7 @@ void geoMoveBehaviour::doaction(osg::Node *node) {
bool geoMoveBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader) {
bool ok=false;
const unsigned int act=grec->getType();
const unsigned int act=grec->getType();
setType(act);
if (act==DB_DSK_ROTATE_ACTION) {
const geoField *gfd=grec->getField(GEO_DB_ROTATE_ACTION_INPUT_VAR);
@@ -378,8 +378,8 @@ bool geoMoveBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *the
setVar(vcon);
const geoField *gfdir=grec->getField(GEO_DB_ROTATE_ACTION_DIR);
int flip=gfdir!=NULL; // ?(gfdir->getInt()):false;
// printf("Flip %d gfdir %x\n",flip, gfdir);
gfd=grec->getField(GEO_DB_ROTATE_ACTION_VECTOR);
// printf("Flip %d gfdir %x\n",flip, gfdir);
gfd=grec->getField(GEO_DB_ROTATE_ACTION_VECTOR);
if (gfd) {
float *ax= gfd->getVec3Arr(); // field identifier
if (flip) setAxis(-osg::Vec3(ax[0],ax[1],ax[2]));
@@ -439,7 +439,7 @@ void geoMoveVertexBehaviour::doaction(osg::Matrix *mtr) {
bool geoMoveVertexBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader)
{
const unsigned int act=grec->getType();
const unsigned int act=grec->getType();
bool ok=false;
setType(act);
if (act==DB_DSK_ROTATE_ACTION) {
@@ -529,7 +529,7 @@ bool geoColourBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *t
void geoColourBehaviour::doaction(osg::Drawable *dr)
{ // do visibility operation on Node
if (getVar()) {
double val=getValue();
double val=getValue();
unsigned int idx=(unsigned int)val;
osg::Geometry *gm=dynamic_cast<osg::Geometry *>(dr);
if (gm) {
@@ -605,13 +605,13 @@ void geoBehaviourCB::operator() (osg::Node *node, osg::NodeVisitor* nv)
{ // callback updates the transform, colour, string content...
MatrixTransform *mtr=dynamic_cast<MatrixTransform *> (node);
if (mtr) mtr->setMatrix(Matrix::identity()); // all actions are multiplied to this
// printf("setting matrix %x\n", mtr);
// printf("setting matrix %x\n", mtr);
// PositionAttitudeTransform *patr=dynamic_cast<PositionAttitudeTransform *> (node);
// if (patr) patr->setMatrix(Matrix::identity()); // all actions are multiplied to this
for (std::vector<geoBehaviour *>::const_iterator itr=gblist.begin();
itr<gblist.end();
itr++) { // motion behaviour
(*itr)->doaction(node);
(*itr)->doaction(node);
/* === the above is equivalent to my old code with lots of tests in: */
/* geoArithBehaviour *ab=dynamic_cast<geoArithBehaviour *>(*itr);
if (ab) ab->doaction(node);
@@ -644,8 +644,8 @@ void geoBehaviourDrawableCB::update(osg::NodeVisitor *,osg::Drawable *dr) {
itr<gblist.end();
itr++)
{ // color or string action behaviour, can also do maths...
// (*itr)->doaction(dr);
Node *nd=NULL;
// (*itr)->doaction(dr);
Node *nd=NULL;
geoArithBehaviour *ab=dynamic_cast<geoArithBehaviour *>(*itr);
if (ab) ab->doaction(nd);
geoAr3Behaviour *a3=dynamic_cast<geoAr3Behaviour *>(*itr);

View File

@@ -1,14 +1,14 @@
/**********************************************************************
*
* FILE: AlphaFunc.cpp
* FILE: AlphaFunc.cpp
*
* DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk.
* DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk.
*
* CREATED BY: Pavlo Moloshtan
* CREATED BY: Pavlo Moloshtan
*
* HISTORY: Created 30.11.2003
* HISTORY: Created 30.11.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: AnimationPath.cpp
* FILE: AnimationPath.cpp
*
* DESCRIPTION: Read/Write osg::AnimationPath in binary format to disk.
* DESCRIPTION: Read/Write osg::AnimationPath in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 25.3.2003
* HISTORY: Created 25.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,58 +19,58 @@
using namespace ive;
void AnimationPath::write(DataOutputStream* out){
// Write AnimationPath's identification.
out->writeInt(IVEANIMATIONPATH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("AnimationPath::write(): Could not cast this osg::AnimationPath to an osg::Object.");
// Write AnimationPath's properties.
// Write AnimationPath's identification.
out->writeInt(IVEANIMATIONPATH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("AnimationPath::write(): Could not cast this osg::AnimationPath to an osg::Object.");
// Write AnimationPath's properties.
// Write loopmode
out->writeInt(getLoopMode());
// Write control points
AnimationPath::TimeControlPointMap tcpm = getTimeControlPointMap();
out->writeInt(tcpm.size());
// Write loopmode
out->writeInt(getLoopMode());
// Write control points
AnimationPath::TimeControlPointMap tcpm = getTimeControlPointMap();
out->writeInt(tcpm.size());
for(AnimationPath::TimeControlPointMap::iterator itr=tcpm.begin(); itr!=tcpm.end(); ++itr){
out->writeFloat(itr->first);
out->writeVec3(itr->second.getPosition());
out->writeQuat(itr->second.getRotation());
out->writeVec3(itr->second.getScale());
out->writeFloat(itr->first);
out->writeVec3(itr->second.getPosition());
out->writeQuat(itr->second.getRotation());
out->writeVec3(itr->second.getScale());
}
}
void AnimationPath::read(DataInputStream* in){
// Peek on AnimationPath's identification.
int id = in->peekInt();
if(id == IVEANIMATIONPATH){
// Read AnimationPath's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("AnimationPath::read(): Could not cast this osg::AnimationPath to an osg::Object.");
// Read AnimationPath's properties
// Peek on AnimationPath's identification.
int id = in->peekInt();
if(id == IVEANIMATIONPATH){
// Read AnimationPath's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("AnimationPath::read(): Could not cast this osg::AnimationPath to an osg::Object.");
// Read AnimationPath's properties
// Read loopmode
setLoopMode((osg::AnimationPath::LoopMode)in->readInt());
// Read control points
int size = in->readInt();
for(int i=0;i<size;i++){
float time = in->readFloat();
osg::Vec3 pos = in->readVec3();
osg::Quat rot = in->readQuat();
osg::Vec3 scale = in->readVec3();
insert(time, osg::AnimationPath::ControlPoint(pos, rot, scale));
}
}
else{
throw Exception("AnimationPath::read(): Expected AnimationPath identification.");
}
// Read loopmode
setLoopMode((osg::AnimationPath::LoopMode)in->readInt());
// Read control points
int size = in->readInt();
for(int i=0;i<size;i++){
float time = in->readFloat();
osg::Vec3 pos = in->readVec3();
osg::Quat rot = in->readQuat();
osg::Vec3 scale = in->readVec3();
insert(time, osg::AnimationPath::ControlPoint(pos, rot, scale));
}
}
else{
throw Exception("AnimationPath::read(): Expected AnimationPath identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: AnimationPathCallback.cpp
* FILE: AnimationPathCallback.cpp
*
* DESCRIPTION: Read/Write osg::AnimationPathCallback in binary format to disk.
* DESCRIPTION: Read/Write osg::AnimationPathCallback in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 25.3.2003
* HISTORY: Created 25.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -20,62 +20,62 @@
using namespace ive;
void AnimationPathCallback::write(DataOutputStream* out){
// Write AnimationPathCallback's identification.
out->writeInt(IVEANIMATIONPATHCALLBACK);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("AnimationPathCallback::write(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
// Write AnimationPathCallback's properties.
// Write AnimationPathCallback's identification.
out->writeInt(IVEANIMATIONPATHCALLBACK);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("AnimationPathCallback::write(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
// Write AnimationPathCallback's properties.
out->writeVec3(_pivotPoint);
out->writeDouble(_timeOffset);
out->writeDouble(_timeMultiplier);
out->writeDouble(_firstTime);
out->writeDouble(_pauseTime);
// Write animationpath if any
if(getAnimationPath())
out->writeVec3(_pivotPoint);
out->writeDouble(_timeOffset);
out->writeDouble(_timeMultiplier);
out->writeDouble(_firstTime);
out->writeDouble(_pauseTime);
// Write animationpath if any
if(getAnimationPath())
{
out->writeInt(1); // true we have an animation path.
((ive::AnimationPath*)(getAnimationPath()))->write(out);
}
out->writeInt(1); // true we have an animation path.
((ive::AnimationPath*)(getAnimationPath()))->write(out);
}
else
{
out->writeInt(0); // false we don't have an animation path.
out->writeInt(0); // false we don't have an animation path.
}
}
void AnimationPathCallback::read(DataInputStream* in){
// Peek on AnimationPathCallback's identification.
int id = in->peekInt();
if(id == IVEANIMATIONPATHCALLBACK){
// Read AnimationPathCallback's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("AnimationPathCallback::read(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
// Read AnimationPathCallback's properties
_pivotPoint = in->readVec3();
_timeOffset = in->readDouble();
_timeMultiplier = in->readDouble();
_firstTime = in->readDouble();
_pauseTime = in->readDouble();
// Read animationpath if any
if(in->readInt())
// Peek on AnimationPathCallback's identification.
int id = in->peekInt();
if(id == IVEANIMATIONPATHCALLBACK){
// Read AnimationPathCallback's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("AnimationPathCallback::read(): Could not cast this osg::AnimationPathCallback to an osg::Object.");
// Read AnimationPathCallback's properties
_pivotPoint = in->readVec3();
_timeOffset = in->readDouble();
_timeMultiplier = in->readDouble();
_firstTime = in->readDouble();
_pauseTime = in->readDouble();
// Read animationpath if any
if(in->readInt())
{
osg::AnimationPath* path = new osg::AnimationPath();
((ive::AnimationPath*)(path))->read(in);
setAnimationPath(path);
}
}
else{
throw Exception("AnimationPathCallback::read(): Expected AnimationPathCallback identification.");
}
osg::AnimationPath* path = new osg::AnimationPath();
((ive::AnimationPath*)(path))->read(in);
setAnimationPath(path);
}
}
else{
throw Exception("AnimationPathCallback::read(): Expected AnimationPathCallback identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: AzimElevationSector.cpp
* FILE: AzimElevationSector.cpp
*
* DESCRIPTION: Read/Write osgSim::AzimElevationSector in binary format to disk.
* DESCRIPTION: Read/Write osgSim::AzimElevationSector in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.9.2003
* HISTORY: Created 9.9.2003
*
**********************************************************************/
@@ -17,38 +17,38 @@
using namespace ive;
void AzimElevationSector::write(DataOutputStream* out){
// Write AzimElevationSector's identification.
out->writeInt(IVEAZIMELEVATIONSECTOR);
// Write AzimElevationSector's properties.
out->writeFloat(getMinElevation());
// Write AzimElevationSector's identification.
out->writeInt(IVEAZIMELEVATIONSECTOR);
// Write AzimElevationSector's properties.
out->writeFloat(getMinElevation());
out->writeFloat(getMaxElevation());
out->writeFloat(getFadeAngle());
float minAzimuth, maxAzimuth, fadeAngle;
getAzimuthRange(minAzimuth, maxAzimuth, fadeAngle);
out->writeFloat(minAzimuth);
out->writeFloat(maxAzimuth);
out->writeFloat(fadeAngle);
out->writeFloat(minAzimuth);
out->writeFloat(maxAzimuth);
out->writeFloat(fadeAngle);
}
void AzimElevationSector::read(DataInputStream* in){
// Peek on AzimElevationSector's identification.
int id = in->peekInt();
if(id == IVEAZIMELEVATIONSECTOR){
// Read AzimElevationSector's identification.
id = in->readInt();
// Read AzimElevationSector's properties
float minElevation = in->readFloat();
// Peek on AzimElevationSector's identification.
int id = in->peekInt();
if(id == IVEAZIMELEVATIONSECTOR){
// Read AzimElevationSector's identification.
id = in->readInt();
// Read AzimElevationSector's properties
float minElevation = in->readFloat();
float maxElevation = in->readFloat();
float fadeAngle = in->readFloat();
setElevationRange(minElevation, maxElevation, fadeAngle);
setElevationRange(minElevation, maxElevation, fadeAngle);
float minAzimuth = in->readFloat();
float maxAzimuth = in->readFloat();
fadeAngle = in->readFloat();
float minAzimuth = in->readFloat();
float maxAzimuth = in->readFloat();
fadeAngle = in->readFloat();
setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle);
}
else{
throw Exception("AzimElevationSector::read(): Expected AzimElevationSector identification.");
}
}
else{
throw Exception("AzimElevationSector::read(): Expected AzimElevationSector identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: AzimSector.cpp
* FILE: AzimSector.cpp
*
* DESCRIPTION: Read/Write osgSim::AzimSector in binary format to disk.
* DESCRIPTION: Read/Write osgSim::AzimSector in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.9.2003
* HISTORY: Created 9.9.2003
*
**********************************************************************/
@@ -17,29 +17,29 @@
using namespace ive;
void AzimSector::write(DataOutputStream* out){
// Write AzimSector's identification.
out->writeInt(IVEAZIMSECTOR);
// Write AzimSector's properties.
// Write AzimSector's identification.
out->writeInt(IVEAZIMSECTOR);
// Write AzimSector's properties.
float minAzimuth, maxAzimuth, fadeAngle;
getAzimuthRange(minAzimuth, maxAzimuth, fadeAngle);
out->writeFloat(minAzimuth);
out->writeFloat(maxAzimuth);
out->writeFloat(fadeAngle);
out->writeFloat(minAzimuth);
out->writeFloat(maxAzimuth);
out->writeFloat(fadeAngle);
}
void AzimSector::read(DataInputStream* in){
// Peek on AzimSector's identification.
int id = in->peekInt();
if(id == IVEAZIMSECTOR){
// Read AzimSector's identification.
id = in->readInt();
// Read AzimSector's properties
float minAzimuth = in->readFloat();
float maxAzimuth = in->readFloat();
float fadeAngle = in->readFloat();
// Peek on AzimSector's identification.
int id = in->peekInt();
if(id == IVEAZIMSECTOR){
// Read AzimSector's identification.
id = in->readInt();
// Read AzimSector's properties
float minAzimuth = in->readFloat();
float maxAzimuth = in->readFloat();
float fadeAngle = in->readFloat();
setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle);
}
else{
throw Exception("AzimSector::read(): Expected AzimSector identification.");
}
}
else{
throw Exception("AzimSector::read(): Expected AzimSector identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Billboard.cpp
* FILE: Billboard.cpp
*
* DESCRIPTION: Read/Write osg::Billboard in binary format to disk.
* DESCRIPTION: Read/Write osg::Billboard in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 24.3.2003
* HISTORY: Created 24.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,60 +19,60 @@
using namespace ive;
void Billboard::write(DataOutputStream* out){
// Write Billboard's identification.
out->writeInt(IVEBILLBOARD);
// If the osg class is inherited by any other class we should also write this to file.
osg::Geode* geode = dynamic_cast<osg::Geode*>(this);
if(geode){
((ive::Geode*)(geode))->write(out);
}
else
throw Exception("Billboard::write(): Could not cast this osg::Billboard to an osg::Geode.");
// Write Billboard's properties.
// Write Billboard's identification.
out->writeInt(IVEBILLBOARD);
// If the osg class is inherited by any other class we should also write this to file.
osg::Geode* geode = dynamic_cast<osg::Geode*>(this);
if(geode){
((ive::Geode*)(geode))->write(out);
}
else
throw Exception("Billboard::write(): Could not cast this osg::Billboard to an osg::Geode.");
// Write Billboard's properties.
// Write mode
out->writeInt(getMode());
// Write axis
out->writeVec3(getAxis());
// Write normal
out->writeVec3(getNormal());
// Write positions
int size = _positionList.size();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeVec3(getPosition(i));
}
// Write mode
out->writeInt(getMode());
// Write axis
out->writeVec3(getAxis());
// Write normal
out->writeVec3(getNormal());
// Write positions
int size = _positionList.size();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeVec3(getPosition(i));
}
}
void Billboard::read(DataInputStream* in){
// Peek on Billboard's identification.
int id = in->peekInt();
if(id == IVEBILLBOARD){
// Read Billboard's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Geode* geode = dynamic_cast<osg::Geode*>(this);
if(geode){
((ive::Geode*)(geode))->read(in);
}
else
throw Exception("Billboard::read(): Could not cast this osg::Billboard to an osg::Geode.");
// Read Billboard's properties
// Peek on Billboard's identification.
int id = in->peekInt();
if(id == IVEBILLBOARD){
// Read Billboard's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Geode* geode = dynamic_cast<osg::Geode*>(this);
if(geode){
((ive::Geode*)(geode))->read(in);
}
else
throw Exception("Billboard::read(): Could not cast this osg::Billboard to an osg::Geode.");
// Read Billboard's properties
// Read mode
setMode((osg::Billboard::Mode)in->readInt());
// Read axis
setAxis(in->readVec3());
// Read normal
setNormal(in->readVec3());
// Read positions
int size = in->readInt();
for(int i=0;i<size;i++){
setPosition(i,in->readVec3());
}
// Read mode
setMode((osg::Billboard::Mode)in->readInt());
// Read axis
setAxis(in->readVec3());
// Read normal
setNormal(in->readVec3());
// Read positions
int size = in->readInt();
for(int i=0;i<size;i++){
setPosition(i,in->readVec3());
}
}
else{
throw Exception("Billboard::read(): Expected Billboard identification.");
}
}
else{
throw Exception("Billboard::read(): Expected Billboard identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: BlendFunc.cpp
* FILE: BlendFunc.cpp
*
* DESCRIPTION: Read/Write osg::BlendFunc in binary format to disk.
* DESCRIPTION: Read/Write osg::BlendFunc in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,45 +19,45 @@
using namespace ive;
void BlendFunc::write(DataOutputStream* out){
// Write BlendFunc's identification.
out->writeInt(IVEBLENDFUNC);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("BlendFunc::write(): Could not cast this osg::BlendFunc to an osg::Object.");
// Write BlendFunc's properties.
// Write BlendFunc's identification.
out->writeInt(IVEBLENDFUNC);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("BlendFunc::write(): Could not cast this osg::BlendFunc to an osg::Object.");
// Write BlendFunc's properties.
// Write source
out->writeInt(getSource());
// Write destination
out->writeInt(getDestination());
// Write source
out->writeInt(getSource());
// Write destination
out->writeInt(getDestination());
}
void BlendFunc::read(DataInputStream* in){
// Peek on BlendFunc's identification.
int id = in->peekInt();
if(id == IVEBLENDFUNC){
// Read BlendFunc's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("BlendFunc::read(): Could not cast this osg::BlendFunc to an osg::Object.");
// Read BlendFunc's properties
// Peek on BlendFunc's identification.
int id = in->peekInt();
if(id == IVEBLENDFUNC){
// Read BlendFunc's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("BlendFunc::read(): Could not cast this osg::BlendFunc to an osg::Object.");
// Read BlendFunc's properties
// Read source
setSource((GLenum)in->readInt());
// Read destination
setDestination((GLenum)in->readInt());
// Read source
setSource((GLenum)in->readInt());
// Read destination
setDestination((GLenum)in->readInt());
}
else{
throw Exception("BlendFunc::read(): Expected BlendFunc identification.");
}
}
else{
throw Exception("BlendFunc::read(): Expected BlendFunc identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: BlinkSequence.cpp
* FILE: BlinkSequence.cpp
*
* DESCRIPTION: Read/Write osgSim::BlinkSequence in binary format to disk.
* DESCRIPTION: Read/Write osgSim::BlinkSequence in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 5.9.2003
* HISTORY: Created 5.9.2003
*
**********************************************************************/
@@ -18,64 +18,64 @@
using namespace ive;
void BlinkSequence::write(DataOutputStream* out){
// Write BlinkSequence's identification.
out->writeInt(IVEBLINKSEQUENCE);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("BlinkSequence::write(): Could not cast this osgSim::BlinkSequence to an osg::Object.");
// Write BlinkSequence's identification.
out->writeInt(IVEBLINKSEQUENCE);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("BlinkSequence::write(): Could not cast this osgSim::BlinkSequence to an osg::Object.");
// Write BlinkSequence's properties.
// Write BlinkSequence's properties.
// Write out pulse data.
unsigned int size = getNumPulses();
out->writeInt(size);
for(unsigned int i=0; i<size; i++){
double length;
osg::Vec4 color;
getPulse(i, length, color);
out->writeDouble(length);
out->writeVec4(color);
}
// Write out phase shift.
out->writeDouble(getPhaseShift());
// Write out SequenceGroup.
out->writeDouble(getSequenceGroup()->_baseTime);
// Write out pulse data.
unsigned int size = getNumPulses();
out->writeInt(size);
for(unsigned int i=0; i<size; i++){
double length;
osg::Vec4 color;
getPulse(i, length, color);
out->writeDouble(length);
out->writeVec4(color);
}
// Write out phase shift.
out->writeDouble(getPhaseShift());
// Write out SequenceGroup.
out->writeDouble(getSequenceGroup()->_baseTime);
}
void BlinkSequence::read(DataInputStream* in){
// Peek on BlinkSequence's identification.
int id = in->peekInt();
if(id == IVEBLINKSEQUENCE){
// Read BlinkSequence's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("BlinkSequence::read(): Could not cast this osgSim::BlinkSequence to an osg::Object.");
// Read BlinkSequence's properties
// Peek on BlinkSequence's identification.
int id = in->peekInt();
if(id == IVEBLINKSEQUENCE){
// Read BlinkSequence's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("BlinkSequence::read(): Could not cast this osgSim::BlinkSequence to an osg::Object.");
// Read BlinkSequence's properties
// Read in pulse data.
unsigned int size = in->readInt();
for(unsigned int i=0; i<size; i++){
double length = in->readDouble();
osg::Vec4 color = in->readVec4();
addPulse(length,color);
}
// Read in phase shift.
setPhaseShift(in->readDouble());
// Read in SequenceGroup
setSequenceGroup(new osgSim::SequenceGroup(in->readDouble()));
// Read in pulse data.
unsigned int size = in->readInt();
for(unsigned int i=0; i<size; i++){
double length = in->readDouble();
osg::Vec4 color = in->readVec4();
addPulse(length,color);
}
// Read in phase shift.
setPhaseShift(in->readDouble());
// Read in SequenceGroup
setSequenceGroup(new osgSim::SequenceGroup(in->readDouble()));
}
else{
throw Exception("BlinkSequence::read(): Expected BlinkSequence identification.");
}
}
else{
throw Exception("BlinkSequence::read(): Expected BlinkSequence identification.");
}
}

View File

@@ -1,14 +1,14 @@
/**********************************************************************
*
* FILE: ClipPlane.cpp
* FILE: ClipPlane.cpp
*
* DESCRIPTION: Read/Write osg::ClipPlane (partially) in binary format to disk.
* DESCRIPTION: Read/Write osg::ClipPlane (partially) in binary format to disk.
*
* CREATED BY: Stanislav Blinov
* CREATED BY: Stanislav Blinov
*
* HISTORY: Created 7.09.2004
* HISTORY: Created 7.09.2004
*
* Copyright 2004 OtherSide
* Copyright 2004 OtherSide
**********************************************************************/
#include "Exception.h"

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: ConeSector.cpp
* FILE: ConeSector.cpp
*
* DESCRIPTION: Read/Write osgSim::ConeSector in binary format to disk.
* DESCRIPTION: Read/Write osgSim::ConeSector in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.9.2003
* HISTORY: Created 9.9.2003
*
**********************************************************************/
@@ -17,27 +17,27 @@
using namespace ive;
void ConeSector::write(DataOutputStream* out){
// Write ConeSector's identification.
out->writeInt(IVECONESECTOR);
// Write ConeSector's properties.
out->writeVec3(getAxis());
out->writeFloat(getAngle());
// Write ConeSector's identification.
out->writeInt(IVECONESECTOR);
// Write ConeSector's properties.
out->writeVec3(getAxis());
out->writeFloat(getAngle());
out->writeFloat(getFadeAngle());
}
void ConeSector::read(DataInputStream* in){
// Peek on ConeSector's identification.
int id = in->peekInt();
if(id == IVECONESECTOR){
// Read ConeSector's identification.
id = in->readInt();
// Read ConeSector's properties
setAxis(in->readVec3());
// Peek on ConeSector's identification.
int id = in->peekInt();
if(id == IVECONESECTOR){
// Read ConeSector's identification.
id = in->readInt();
// Read ConeSector's properties
setAxis(in->readVec3());
float angle = in->readFloat();
float fadeangle = in->readFloat();;
setAngle(angle, fadeangle);
}
else{
throw Exception("ConeSector::read(): Expected ConeSector identification.");
}
}
else{
throw Exception("ConeSector::read(): Expected ConeSector identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: ConvexPlanarPolygon.cpp
* FILE: ConvexPlanarPolygon.cpp
*
* DESCRIPTION: Read/Write osg::ConvexPlanarPolygon in binary format to disk.
* DESCRIPTION: Read/Write osg::ConvexPlanarPolygon in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 23.4.2003
* HISTORY: Created 23.4.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -18,50 +18,50 @@
using namespace ive;
void ConvexPlanarPolygon::write(DataOutputStream* out){
// Write ConvexPlanarPolygon's identification.
out->writeInt(IVECONVEXPLANARPOLYGON);
// If the osg class is inherited by any other class we should also write this to file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->write(out);
//}
//else
// throw Exception("ConvexPlanarPolygon::write(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Write ConvexPlanarPolygon's properties.
// Write ConvexPlanarPolygon's identification.
out->writeInt(IVECONVEXPLANARPOLYGON);
// If the osg class is inherited by any other class we should also write this to file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->write(out);
//}
//else
// throw Exception("ConvexPlanarPolygon::write(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Write ConvexPlanarPolygon's properties.
// Write Vertex list
VertexList vertexList = getVertexList();
int size = vertexList.size();
out->writeInt(size);
for(int i=0; i<size; i++){
out->writeVec3(vertexList[i]);
}
// Write Vertex list
VertexList vertexList = getVertexList();
int size = vertexList.size();
out->writeInt(size);
for(int i=0; i<size; i++){
out->writeVec3(vertexList[i]);
}
}
void ConvexPlanarPolygon::read(DataInputStream* in){
// Peek on ConvexPlanarPolygon's identification.
int id = in->peekInt();
if(id == IVECONVEXPLANARPOLYGON){
// Read ConvexPlanarPolygon's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->read(in);
//}
//else
// throw Exception("ConvexPlanarPolygon::read(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Read ConvexPlanarPolygon's properties
// Peek on ConvexPlanarPolygon's identification.
int id = in->peekInt();
if(id == IVECONVEXPLANARPOLYGON){
// Read ConvexPlanarPolygon's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->read(in);
//}
//else
// throw Exception("ConvexPlanarPolygon::read(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Read ConvexPlanarPolygon's properties
// Read Vertex list
int size = in->readInt();
for(int i=0; i<size; i++){
add(in->readVec3());
}
// Read Vertex list
int size = in->readInt();
for(int i=0; i<size; i++){
add(in->readVec3());
}
}
else{
throw Exception("ConvexPlanarPolygon::read(): Expected ConvexPlanarPolygon identification.");
}
}
else{
throw Exception("ConvexPlanarPolygon::read(): Expected ConvexPlanarPolygon identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: CullFace.cpp
* FILE: CullFace.cpp
*
* DESCRIPTION: Read/Write osg::CullFace in binary format to disk.
* DESCRIPTION: Read/Write osg::CullFace in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,36 +19,36 @@
using namespace ive;
void CullFace::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVECULLFACE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("CullFace::write(): Could not cast this osg::CullFace to an osg::Object.");
// Write CullFace's properties.
out->writeInt(getMode());
// Write CullFace's identification.
out->writeInt(IVECULLFACE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("CullFace::write(): Could not cast this osg::CullFace to an osg::Object.");
// Write CullFace's properties.
out->writeInt(getMode());
}
void CullFace::read(DataInputStream* in){
// Peek on CullFace's identification.
int id = in->peekInt();
if(id == IVECULLFACE){
// Read CullFace's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("CullFace::read(): Could not cast this osg::CullFace to an osg::Object.");
// Read CullFace's properties
setMode((osg::CullFace::Mode)in->readInt());
}
else{
throw Exception("CullFace::read(): Expected CullFace identification.");
}
// Peek on CullFace's identification.
int id = in->peekInt();
if(id == IVECULLFACE){
// Read CullFace's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("CullFace::read(): Could not cast this osg::CullFace to an osg::Object.");
// Read CullFace's properties
setMode((osg::CullFace::Mode)in->readInt());
}
else{
throw Exception("CullFace::read(): Expected CullFace identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: DirectionalSector.cpp
* FILE: DirectionalSector.cpp
*
* DESCRIPTION: Read/Write osgSim::DirectionalSector in binary format to disk.
* DESCRIPTION: Read/Write osgSim::DirectionalSector in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.9.2003
* HISTORY: Created 9.9.2003
*
**********************************************************************/
@@ -17,10 +17,10 @@
using namespace ive;
void DirectionalSector::write(DataOutputStream* out){
// Write DirectionalSector's identification.
out->writeInt(IVEDIRECTIONALSECTOR);
// Write DirectionalSector's properties.
out->writeVec3(getDirection());
// Write DirectionalSector's identification.
out->writeInt(IVEDIRECTIONALSECTOR);
// Write DirectionalSector's properties.
out->writeVec3(getDirection());
out->writeFloat(getHorizLobeAngle());
out->writeFloat(getVertLobeAngle());
out->writeFloat(getLobeRollAngle());
@@ -28,20 +28,20 @@ void DirectionalSector::write(DataOutputStream* out){
}
void DirectionalSector::read(DataInputStream* in){
// Peek on DirectionalSector's identification.
int id = in->peekInt();
if(id == IVEDIRECTIONALSECTOR){
// Read DirectionalSector's identification.
id = in->readInt();
// Read DirectionalSector's properties
setDirection(in->readVec3());
// Peek on DirectionalSector's identification.
int id = in->peekInt();
if(id == IVEDIRECTIONALSECTOR){
// Read DirectionalSector's identification.
id = in->readInt();
// Read DirectionalSector's properties
setDirection(in->readVec3());
setHorizLobeAngle(in->readFloat());
setVertLobeAngle(in->readFloat());
setLobeRollAngle(in->readFloat());
setFadeAngle(in->readFloat());
}
else{
throw Exception("DirectionalSector::read(): Expected DirectionalSector identification.");
}
}
else{
throw Exception("DirectionalSector::read(): Expected DirectionalSector identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: ElevationSector.cpp
* FILE: ElevationSector.cpp
*
* DESCRIPTION: Read/Write osgSim::ElevationSector in binary format to disk.
* DESCRIPTION: Read/Write osgSim::ElevationSector in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.9.2003
* HISTORY: Created 9.9.2003
*
**********************************************************************/
@@ -17,27 +17,27 @@
using namespace ive;
void ElevationSector::write(DataOutputStream* out){
// Write ElevationSector's identification.
out->writeInt(IVEELEVATIONSECTOR);
// Write ElevationSector's properties.
out->writeFloat(getMinElevation());
// Write ElevationSector's identification.
out->writeInt(IVEELEVATIONSECTOR);
// Write ElevationSector's properties.
out->writeFloat(getMinElevation());
out->writeFloat(getMaxElevation());
out->writeFloat(getFadeAngle());
}
void ElevationSector::read(DataInputStream* in){
// Peek on ElevationSector's identification.
int id = in->peekInt();
if(id == IVEELEVATIONSECTOR){
// Read ElevationSector's identification.
id = in->readInt();
// Read ElevationSector's properties
float minElevation = in->readFloat();
// Peek on ElevationSector's identification.
int id = in->peekInt();
if(id == IVEELEVATIONSECTOR){
// Read ElevationSector's identification.
id = in->readInt();
// Read ElevationSector's properties
float minElevation = in->readFloat();
float maxElevation = in->readFloat();
float fadeAngle = in->readFloat();
setElevationRange(minElevation, maxElevation, fadeAngle);
}
else{
throw Exception("ElevationSector::read(): Expected ElevationSector identification.");
}
setElevationRange(minElevation, maxElevation, fadeAngle);
}
else{
throw Exception("ElevationSector::read(): Expected ElevationSector identification.");
}
}

View File

@@ -1,14 +1,14 @@
/**********************************************************************
*
* FILE: Exception.cpp
* FILE: Exception.cpp
*
* DESCRIPTION: Exception throwed when error occur.
* DESCRIPTION: Exception throwed when error occur.
*
* CREATED BY: Rune Schmidt Jensen
* CREATED BY: Rune Schmidt Jensen
*
* HISTORY: Created 17.03.2003
* HISTORY: Created 17.03.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
@@ -17,7 +17,7 @@
using namespace ive;
Exception::Exception(std::string error){
_error = error;
_error = error;
}
Exception::~Exception(){}

View File

@@ -68,7 +68,7 @@ void FragmentProgram::read(DataInputStream* in){
// Read data
int i, size;
size = in->readInt();
for(i=0; i<size; i++)
for(i=0; i<size; i++)
{
int index = in->readInt();
osg::Vec4 v = in->readVec4();

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: FrontFace.cpp
* FILE: FrontFace.cpp
*
* DESCRIPTION: Read/Write osg::FrontFace in binary format to disk.
* DESCRIPTION: Read/Write osg::FrontFace in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,42 +19,42 @@
using namespace ive;
void FrontFace::write(DataOutputStream* out){
// Write FrontFace's identification.
out->writeInt(IVEFRONTFACE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("FrontFace::write(): Could not cast this osg::FrontFace to an osg::Object.");
// Write FrontFace's properties.
// Write FrontFace's identification.
out->writeInt(IVEFRONTFACE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("FrontFace::write(): Could not cast this osg::FrontFace to an osg::Object.");
// Write FrontFace's properties.
// Write mode
out->writeInt(getMode());
// Write mode
out->writeInt(getMode());
}
void FrontFace::read(DataInputStream* in){
// Peek on FrontFace's identification.
int id = in->peekInt();
if(id == IVEFRONTFACE){
// Read FrontFace's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("FrontFace::read(): Could not cast this osg::FrontFace to an osg::Object.");
// Read FrontFace's properties
// Peek on FrontFace's identification.
int id = in->peekInt();
if(id == IVEFRONTFACE){
// Read FrontFace's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("FrontFace::read(): Could not cast this osg::FrontFace to an osg::Object.");
// Read FrontFace's properties
// Read mode
setMode((osg::FrontFace::Mode)in->readInt());
// Read mode
setMode((osg::FrontFace::Mode)in->readInt());
}
else{
throw Exception("FrontFace::read(): Expected FrontFace identification.");
}
}
else{
throw Exception("FrontFace::read(): Expected FrontFace identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Impostor.cpp
* FILE: Impostor.cpp
*
* DESCRIPTION: Read/Write osg::Impostor in binary format to disk.
* DESCRIPTION: Read/Write osg::Impostor in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 16.4.2003
* HISTORY: Created 16.4.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,36 +19,36 @@
using namespace ive;
void Impostor::write(DataOutputStream* out){
// Write Impostor's identification.
out->writeInt(IVEIMPOSTOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->write(out);
}
else
throw Exception("Impostor::write(): Could not cast this osg::Impostor to an osg::LOD.");
// Write Impostor's properties.
out->writeFloat(getImpostorThreshold());
// Write Impostor's identification.
out->writeInt(IVEIMPOSTOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->write(out);
}
else
throw Exception("Impostor::write(): Could not cast this osg::Impostor to an osg::LOD.");
// Write Impostor's properties.
out->writeFloat(getImpostorThreshold());
}
void Impostor::read(DataInputStream* in){
// Peek on Impostor's identification.
int id = in->peekInt();
if(id == IVEIMPOSTOR){
// Read Impostor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->read(in);
}
else
throw Exception("Impostor::read(): Could not cast this osg::Impostor to an osg::LOD.");
// Read Impostor's properties
setImpostorThreshold(in->readFloat());
}
else{
throw Exception("Impostor::read(): Expected Impostor identification.");
}
// Peek on Impostor's identification.
int id = in->peekInt();
if(id == IVEIMPOSTOR){
// Read Impostor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->read(in);
}
else
throw Exception("Impostor::read(): Could not cast this osg::Impostor to an osg::LOD.");
// Read Impostor's properties
setImpostorThreshold(in->readFloat());
}
else{
throw Exception("Impostor::read(): Expected Impostor identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: LOD.cpp
* FILE: LOD.cpp
*
* DESCRIPTION: Read/Write osg::LOD in binary format to disk.
* DESCRIPTION: Read/Write osg::LOD in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 24.3.2003
* HISTORY: Created 24.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,69 +19,69 @@
using namespace ive;
void LOD::write(DataOutputStream* out){
// Write LOD's identification.
out->writeInt(IVELOD);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("LOD::write(): Could not cast this osg::LOD to an osg::Group.");
// Write LOD's properties.
// Write LOD's identification.
out->writeInt(IVELOD);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("LOD::write(): Could not cast this osg::LOD to an osg::Group.");
// Write LOD's properties.
out->writeFloat(getRadius());
// Write centermode
out->writeInt(getCenterMode());
out->writeVec3(getCenter());
// Write centermode
out->writeInt(getCenterMode());
out->writeVec3(getCenter());
out->writeInt(getRangeMode());
// Write rangelist
int size = getNumRanges();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeFloat(getMinRange(i));
out->writeFloat(getMaxRange(i));
}
int size = getNumRanges();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeFloat(getMinRange(i));
out->writeFloat(getMaxRange(i));
}
}
void LOD::read(DataInputStream* in){
// Peek on LOD's identification.
int id = in->peekInt();
if(id == IVELOD){
// Read LOD's identification.
id = in->readInt();
// Peek on LOD's identification.
int id = in->peekInt();
if(id == IVELOD){
// Read LOD's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("LOD::read(): Could not cast this osg::LOD to an osg::Group.");
// Read LOD's properties
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("LOD::read(): Could not cast this osg::LOD to an osg::Group.");
// Read LOD's properties
if ( in->getVersion() > VERSION_0002 )
setRadius(in->readFloat());
// Read centermode
setCenterMode((osg::LOD::CenterMode)in->readInt());
setCenter(in->readVec3());
// Read centermode
setCenterMode((osg::LOD::CenterMode)in->readInt());
setCenter(in->readVec3());
if ( in->getVersion() > VERSION_0002 )
setRangeMode((RangeMode)in->readInt());
// Read rangelist
int size = in->readInt();;
for(int i=0;i<size;i++){
float min = in->readFloat();
float max = in->readFloat();
setRange(i, min, max);
}
}
else{
throw Exception("LOD::read(): Expected LOD identification.");
}
// Read rangelist
int size = in->readInt();;
for(int i=0;i<size;i++){
float min = in->readFloat();
float max = in->readFloat();
setRange(i, min, max);
}
}
else{
throw Exception("LOD::read(): Expected LOD identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Light.cpp
* FILE: Light.cpp
*
* DESCRIPTION: Read/Write osg::Light in binary format to disk.
* DESCRIPTION: Read/Write osg::Light in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,57 +19,57 @@
using namespace ive;
void Light::write(DataOutputStream* out){
// Write Light's identification.
out->writeInt(IVELIGHT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Light::write(): Could not cast this osg::Light to an osg::Object.");
// Write Light's properties.
out->writeInt(getLightNum());
out->writeVec4(getAmbient());
out->writeVec4(getDiffuse());
out->writeVec4(getSpecular());
out->writeVec4(getPosition());
out->writeVec3(getDirection());
out->writeFloat(getConstantAttenuation());
out->writeFloat(getLinearAttenuation ());
out->writeFloat(getQuadraticAttenuation());
out->writeFloat(getSpotExponent());
out->writeFloat(getSpotCutoff());
// Write Light's identification.
out->writeInt(IVELIGHT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Light::write(): Could not cast this osg::Light to an osg::Object.");
// Write Light's properties.
out->writeInt(getLightNum());
out->writeVec4(getAmbient());
out->writeVec4(getDiffuse());
out->writeVec4(getSpecular());
out->writeVec4(getPosition());
out->writeVec3(getDirection());
out->writeFloat(getConstantAttenuation());
out->writeFloat(getLinearAttenuation ());
out->writeFloat(getQuadraticAttenuation());
out->writeFloat(getSpotExponent());
out->writeFloat(getSpotCutoff());
}
void Light::read(DataInputStream* in){
// Peek on Light's identification.
int id = in->peekInt();
if(id == IVELIGHT){
// Read Light's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Light::read(): Could not cast this osg::Light to an osg::Object.");
// Read Light's properties
setLightNum(in->readInt());
setAmbient(in->readVec4());
setDiffuse(in->readVec4());
setSpecular(in->readVec4());
setPosition(in->readVec4());
setDirection(in->readVec3());
setConstantAttenuation(in->readFloat());
setLinearAttenuation (in->readFloat());
setQuadraticAttenuation(in->readFloat());
setSpotExponent(in->readFloat());
setSpotCutoff(in->readFloat());
}
else{
throw Exception("Light::read(): Expected Light identification.");
}
// Peek on Light's identification.
int id = in->peekInt();
if(id == IVELIGHT){
// Read Light's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Light::read(): Could not cast this osg::Light to an osg::Object.");
// Read Light's properties
setLightNum(in->readInt());
setAmbient(in->readVec4());
setDiffuse(in->readVec4());
setSpecular(in->readVec4());
setPosition(in->readVec4());
setDirection(in->readVec3());
setConstantAttenuation(in->readFloat());
setLinearAttenuation (in->readFloat());
setQuadraticAttenuation(in->readFloat());
setSpotExponent(in->readFloat());
setSpotCutoff(in->readFloat());
}
else{
throw Exception("Light::read(): Expected Light identification.");
}
}

View File

@@ -1,14 +1,14 @@
/**********************************************************************
*
* FILE: LightModel.cpp
* FILE: LightModel.cpp
*
* DESCRIPTION: Read/Write osg::LightModel (partially) in binary format to disk.
* DESCRIPTION: Read/Write osg::LightModel (partially) in binary format to disk.
*
* CREATED BY: Stanislav Blinov
* CREATED BY: Stanislav Blinov
*
* HISTORY: Created 7.09.2004
* HISTORY: Created 7.09.2004
*
* Copyright 2004 OtherSide
* Copyright 2004 OtherSide
**********************************************************************/
#include "Exception.h"
@@ -54,9 +54,9 @@ void LightModel::read(DataInputStream* in){
// Read LightModel's properties
setTwoSided(in->readBool());
setLocalViewer(in->readBool());
setAmbientIntensity(in->readVec4());
setColorControl((ColorControl)in->readInt());
setLocalViewer(in->readBool());
setAmbientIntensity(in->readVec4());
setColorControl((ColorControl)in->readInt());
}
else{
throw Exception("LightModel::read(): Expected LightModel identification.");

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: LightPoint.cpp
* FILE: LightPoint.cpp
*
* DESCRIPTION: Read/Write osgSim::LightPoint in binary format to disk.
* DESCRIPTION: Read/Write osgSim::LightPoint in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 5.9.2003
* HISTORY: Created 5.9.2003
*
**********************************************************************/
@@ -23,106 +23,106 @@
using namespace ive;
void LightPoint::write(DataOutputStream* out){
// Write LightPoint's identification.
out->writeInt(IVELIGHTPOINT);
// Write LightPoint's identification.
out->writeInt(IVELIGHTPOINT);
// Write LightPoint's properties.
out->writeBool(_on);
out->writeVec3(_position);
out->writeVec4(_color);
out->writeFloat(_intensity);
out->writeFloat(_radius);
// Write LightPoint's properties.
out->writeBool(_on);
out->writeVec3(_position);
out->writeVec4(_color);
out->writeFloat(_intensity);
out->writeFloat(_radius);
// Write out osgSim::sector.
out->writeBool(_sector.valid());
if(_sector.valid()){
if(dynamic_cast<osgSim::AzimElevationSector*>(_sector.get())){
((ive::AzimElevationSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::ElevationSector*>(_sector.get())){
((ive::ElevationSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::AzimSector*>(_sector.get())){
((ive::AzimSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::ConeSector*>(_sector.get())){
((ive::ConeSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::DirectionalSector*>(_sector.get())){
((ive::DirectionalSector*)(_sector.get()))->write(out);
}
else
throw Exception("Unknown sector in LightPoint::write()");
}
// Write out osgSim::sector.
out->writeBool(_sector.valid());
if(_sector.valid()){
if(dynamic_cast<osgSim::AzimElevationSector*>(_sector.get())){
((ive::AzimElevationSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::ElevationSector*>(_sector.get())){
((ive::ElevationSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::AzimSector*>(_sector.get())){
((ive::AzimSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::ConeSector*>(_sector.get())){
((ive::ConeSector*)(_sector.get()))->write(out);
}
else if(dynamic_cast<osgSim::DirectionalSector*>(_sector.get())){
((ive::DirectionalSector*)(_sector.get()))->write(out);
}
else
throw Exception("Unknown sector in LightPoint::write()");
}
// Write out osgSim::BlinkSequence.
out->writeBool(_blinkSequence.valid());
if(_blinkSequence.valid()){
((ive::BlinkSequence*)(_blinkSequence.get()))->write(out);
}
// Write out blendingMode.
// Write out osgSim::BlinkSequence.
out->writeBool(_blinkSequence.valid());
if(_blinkSequence.valid()){
((ive::BlinkSequence*)(_blinkSequence.get()))->write(out);
}
// Write out blendingMode.
out->writeInt(_blendingMode);
}
void LightPoint::read(DataInputStream* in){
// Peek on LightPoint's identification.
int id = in->peekInt();
if(id == IVELIGHTPOINT){
// Read LightPoint's identification.
id = in->readInt();
// Peek on LightPoint's identification.
int id = in->peekInt();
if(id == IVELIGHTPOINT){
// Read LightPoint's identification.
id = in->readInt();
// Read LightPoint's properties
_on = in->readBool();
_position = in->readVec3();
_color = in->readVec4();
_intensity = in->readFloat();
_radius = in->readFloat();
// Read LightPoint's properties
_on = in->readBool();
_position = in->readVec3();
_color = in->readVec4();
_intensity = in->readFloat();
_radius = in->readFloat();
// read in osgSim::sector.
if(in->readBool()){
osgSim::Sector* sector;
int attributeID = in->peekInt();
if(attributeID == IVEAZIMELEVATIONSECTOR){
sector = new osgSim::AzimElevationSector();
((ive::AzimElevationSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEELEVATIONSECTOR){
sector = new osgSim::ElevationSector();
((ive::ElevationSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEAZIMSECTOR){
sector = new osgSim::AzimSector();
((ive::AzimSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVECONESECTOR){
sector = new osgSim::ConeSector();
((ive::ConeSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEDIRECTIONALSECTOR){
sector = new osgSim::DirectionalSector();
((ive::DirectionalSector*)(sector))->read(in);
_sector = sector;
}
else
throw Exception("Unknown sector in LightPoint::read()");
}
// read in osgSim::sector.
if(in->readBool()){
osgSim::Sector* sector;
int attributeID = in->peekInt();
if(attributeID == IVEAZIMELEVATIONSECTOR){
sector = new osgSim::AzimElevationSector();
((ive::AzimElevationSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEELEVATIONSECTOR){
sector = new osgSim::ElevationSector();
((ive::ElevationSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEAZIMSECTOR){
sector = new osgSim::AzimSector();
((ive::AzimSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVECONESECTOR){
sector = new osgSim::ConeSector();
((ive::ConeSector*)(sector))->read(in);
_sector = sector;
}
else if(attributeID == IVEDIRECTIONALSECTOR){
sector = new osgSim::DirectionalSector();
((ive::DirectionalSector*)(sector))->read(in);
_sector = sector;
}
else
throw Exception("Unknown sector in LightPoint::read()");
}
// Read in osgSim::BlinkSequence.
if(in->readBool()){
osgSim::BlinkSequence* blinkSequence = new osgSim::BlinkSequence();
((ive::BlinkSequence*)(blinkSequence))->read(in);
_blinkSequence = blinkSequence;
}
// Read in blendingMode.
_blendingMode = (osgSim::LightPoint::BlendingMode)in->readInt();
}
else{
throw Exception("LightPoint::read(): Expected LightPoint identification.");
}
// Read in osgSim::BlinkSequence.
if(in->readBool()){
osgSim::BlinkSequence* blinkSequence = new osgSim::BlinkSequence();
((ive::BlinkSequence*)(blinkSequence))->read(in);
_blinkSequence = blinkSequence;
}
// Read in blendingMode.
_blendingMode = (osgSim::LightPoint::BlendingMode)in->readInt();
}
else{
throw Exception("LightPoint::read(): Expected LightPoint identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: LightPointNode.cpp
* FILE: LightPointNode.cpp
*
* DESCRIPTION: Read/Write osgSim::LightPointNode in binary format to disk.
* DESCRIPTION: Read/Write osgSim::LightPointNode in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 14.9.2003
* HISTORY: Created 14.9.2003
*
**********************************************************************/
@@ -19,56 +19,56 @@
using namespace ive;
void LightPointNode::write(DataOutputStream* out){
// Write LightPointNode's identification.
out->writeInt(IVELIGHTPOINTNODE);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
((ive::Node*)(node))->write(out);
}
else
throw Exception("LightPointNode::write(): Could not cast this osgSim::LightPointNode to an osg::Node.");
// Write LightPointNode's identification.
out->writeInt(IVELIGHTPOINTNODE);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
((ive::Node*)(node))->write(out);
}
else
throw Exception("LightPointNode::write(): Could not cast this osgSim::LightPointNode to an osg::Node.");
// Write LightPointNode's properties.
out->writeFloat(getMinPixelSize());
out->writeFloat(getMaxPixelSize());
out->writeFloat(getMaxVisibleDistance2());
// Write LightPointNode's properties.
out->writeFloat(getMinPixelSize());
out->writeFloat(getMaxPixelSize());
out->writeFloat(getMaxVisibleDistance2());
// Write out LightPoints.
unsigned int size = getNumLightPoints();
out->writeUInt(size);
for(unsigned int i=0; i<size; i++){
((ive::LightPoint*)(&getLightPoint(i)))->write(out);
}
// Write out LightPoints.
unsigned int size = getNumLightPoints();
out->writeUInt(size);
for(unsigned int i=0; i<size; i++){
((ive::LightPoint*)(&getLightPoint(i)))->write(out);
}
}
void LightPointNode::read(DataInputStream* in){
// Peek on LightPointNode's identification.
int id = in->peekInt();
if(id == IVELIGHTPOINTNODE){
// Read LightPointNode's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
((ive::Node*)(node))->read(in);
}
else
throw Exception("LightPointNode::read(): Could not cast this osgSim::LightPointNode to an osg::Object.");
// Read LightPointNode's properties
setMinPixelSize(in->readFloat());
setMaxPixelSize(in->readFloat());
setMaxVisibleDistance2(in->readFloat());
// Peek on LightPointNode's identification.
int id = in->peekInt();
if(id == IVELIGHTPOINTNODE){
// Read LightPointNode's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
((ive::Node*)(node))->read(in);
}
else
throw Exception("LightPointNode::read(): Could not cast this osgSim::LightPointNode to an osg::Object.");
// Read LightPointNode's properties
setMinPixelSize(in->readFloat());
setMaxPixelSize(in->readFloat());
setMaxVisibleDistance2(in->readFloat());
// Read in lightpoints.
unsigned int size = in->readUInt();
for(unsigned int i=0; i<size; i++ ){
osgSim::LightPoint* lightPoint = new osgSim::LightPoint();
((ive::LightPoint*)(lightPoint))->read(in);
addLightPoint(*lightPoint);
}
}
else{
throw Exception("LightPointNode::read(): Expected LightPointNode identification.");
}
// Read in lightpoints.
unsigned int size = in->readUInt();
for(unsigned int i=0; i<size; i++ ){
osgSim::LightPoint* lightPoint = new osgSim::LightPoint();
((ive::LightPoint*)(lightPoint))->read(in);
addLightPoint(*lightPoint);
}
}
else{
throw Exception("LightPointNode::read(): Expected LightPointNode identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: LineWidth.cpp
* FILE: LineWidth.cpp
*
* DESCRIPTION: Read/Write osg::LineWidth in binary format to disk.
* DESCRIPTION: Read/Write osg::LineWidth in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,36 +19,36 @@
using namespace ive;
void LineWidth::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVELINEWIDTH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("LineWidth::write(): Could not cast this osg::LineWidth to an osg::Object.");
// Write LineWidth's properties.
out->writeFloat(getWidth());
// Write CullFace's identification.
out->writeInt(IVELINEWIDTH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("LineWidth::write(): Could not cast this osg::LineWidth to an osg::Object.");
// Write LineWidth's properties.
out->writeFloat(getWidth());
}
void LineWidth::read(DataInputStream* in){
// Peek on LineWidth's identification.
int id = in->peekInt();
if(id == IVELINEWIDTH){
// Read LineWidth's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("LineWidth::read(): Could not cast this osg::LineWidth to an osg::Object.");
// Read LineWidth's properties
setWidth(in->readFloat());
}
else{
throw Exception("LineWidth::read(): Expected LineWidth identification.");
}
// Peek on LineWidth's identification.
int id = in->peekInt();
if(id == IVELINEWIDTH){
// Read LineWidth's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("LineWidth::read(): Could not cast this osg::LineWidth to an osg::Object.");
// Read LineWidth's properties
setWidth(in->readFloat());
}
else{
throw Exception("LineWidth::read(): Expected LineWidth identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Material.cpp
* FILE: Material.cpp
*
* DESCRIPTION: Read/Write osg::Material in binary format to disk.
* DESCRIPTION: Read/Write osg::Material in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 20.3.2003
* HISTORY: Created 20.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,80 +19,80 @@
using namespace ive;
void Material::write(DataOutputStream* out){
// Write Material's identification.
out->writeInt(IVEMATERIAL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Material::write(): Could not cast this osg::Material to an osg::Object.");
// Write Material's properties.
// Write Material's identification.
out->writeInt(IVEMATERIAL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Material::write(): Could not cast this osg::Material to an osg::Object.");
// Write Material's properties.
// Write color mode
// Write color mode
out->writeInt(_colorMode);
// Write ambient
out->writeBool(_ambientFrontAndBack);
out->writeVec4(_ambientFront);
// Write ambient
out->writeBool(_ambientFrontAndBack);
out->writeVec4(_ambientFront);
out->writeVec4(_ambientBack);
// Write diffuse
// Write diffuse
out->writeBool(_diffuseFrontAndBack);
out->writeVec4(_diffuseFront);
out->writeVec4(_diffuseBack);
// Write specular
// Write specular
out->writeBool(_specularFrontAndBack);
out->writeVec4(_specularFront);
out->writeVec4(_specularBack);
// Write emmision
// Write emmision
out->writeBool(_emissionFrontAndBack);
out->writeVec4(_emissionFront);
out->writeVec4(_emissionBack);
// Write shininess
// Write shininess
out->writeBool(_shininessFrontAndBack);
out->writeFloat(_shininessFront);
out->writeFloat(_shininessBack);
out->writeFloat(_shininessFront);
out->writeFloat(_shininessBack);
}
void Material::read(DataInputStream* in){
// Read Material's identification.
int id = in->peekInt();
if(id == IVEMATERIAL){
// Code to read Material's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Material::read(): Could not cast this osg::Material to an osg::Object.");
// Read Material's identification.
int id = in->peekInt();
if(id == IVEMATERIAL){
// Code to read Material's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Material::read(): Could not cast this osg::Material to an osg::Object.");
// Read color mode.
_colorMode = (osg::Material::ColorMode)in->readInt();
// Read ambient
_ambientFrontAndBack = in->readBool();
// Read color mode.
_colorMode = (osg::Material::ColorMode)in->readInt();
// Read ambient
_ambientFrontAndBack = in->readBool();
_ambientFront = in->readVec4();
_ambientBack = in->readVec4();
// Read diffuse
// Read diffuse
_diffuseFrontAndBack = in->readBool();
_diffuseFront = in->readVec4();
_diffuseBack = in->readVec4();
// Read specular
// Read specular
_specularFrontAndBack = in->readBool();
_specularFront = in->readVec4();
_specularBack = in->readVec4();
// Read emission
// Read emission
_emissionFrontAndBack = in->readBool();
_emissionFront = in->readVec4();
_emissionBack = in->readVec4();
// Read shiniess
// Read shiniess
_shininessFrontAndBack = in->readBool();
_shininessFront = in->readFloat();
_shininessBack = in->readFloat();
}
else{
throw Exception("Material::read(): Expected Material identification.");
}
}
else{
throw Exception("Material::read(): Expected Material identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Switch.cpp
* FILE: Switch.cpp
*
* DESCRIPTION: Read/Write osg::Switch in binary format to disk.
* DESCRIPTION: Read/Write osg::Switch in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.4.2003
* HISTORY: Created 9.4.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,58 +19,60 @@
using namespace ive;
void MultiSwitch::write(DataOutputStream* out){
// Write Switch's identification.
out->writeInt(IVEMULTISWITCH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group.");
// Write Switch's properties.
// Write Switch's identification.
out->writeInt(IVEMULTISWITCH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group.");
// Write Switch's properties.
out->writeBool(getNewChildDefaultValue());
out->writeUInt(getActiveSwitchSet());
out->writeBool(getNewChildDefaultValue());
out->writeUInt(getActiveSwitchSet());
const osgSim::MultiSwitch::SwitchSetList& switchset = getSwitchSetList();
out->writeUInt(switchset.size());
for(unsigned int s=0;s<switchset.size();++s)
{
// Write childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
const osgSim::MultiSwitch::SwitchSetList& switchset = getSwitchSetList();
out->writeUInt(switchset.size());
for(unsigned int s=0;s<switchset.size();++s)
{
// Write childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
out->writeBool(getValue(s,i));
}
}
void MultiSwitch::read(DataInputStream* in)
{
// Peek on Switch's identification.
int id = in->peekInt();
if(id == IVEMULTISWITCH)
{
// Read Switch's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
}
void MultiSwitch::read(DataInputStream* in){
// Peek on Switch's identification.
int id = in->peekInt();
if(id == IVEMULTISWITCH){
// Read Switch's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group.");
// Read Switch's properties
setNewChildDefaultValue(in->readBool());
setActiveSwitchSet(in->readUInt());
unsigned int numSwitchSets = in->readUInt();
for(unsigned int s=0;s<numSwitchSets;++s)
{
// Read childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
setValue(s, i, in->readBool());
}
}
else{
throw Exception("Switch::read(): Expected Switch identification.");
}
else
throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group.");
// Read Switch's properties
setNewChildDefaultValue(in->readBool());
setActiveSwitchSet(in->readUInt());
unsigned int numSwitchSets = in->readUInt();
for(unsigned int s=0;s<numSwitchSets;++s)
{
// Read childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
setValue(s, i, in->readBool());
}
}
else{
throw Exception("Switch::read(): Expected Switch identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Object.cpp
* FILE: Object.cpp
*
* DESCRIPTION: Read/Write osg::Object in binary format to disk.
* DESCRIPTION: Read/Write osg::Object in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 17.3.2003
* HISTORY: Created 17.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -31,8 +31,8 @@ void Object::write(DataOutputStream* out)
// Write Object's properties.
switch(getDataVariance())
{
case(osg::Object::STATIC): out->writeChar((char)0); break;
case(osg::Object::DYNAMIC): out->writeChar((char)1); break;
case(osg::Object::STATIC): out->writeChar((char)0); break;
case(osg::Object::DYNAMIC): out->writeChar((char)1); break;
}
}
@@ -41,8 +41,8 @@ void Object::read(DataInputStream* in){
int id = in->peekInt();
if(id == IVEOBJECT)
{
// Code to read Object's properties.
id = in->readInt();
// Code to read Object's properties.
id = in->readInt();
if ( in->getVersion() >= VERSION_0012 )
{
@@ -50,13 +50,14 @@ void Object::read(DataInputStream* in){
setName(in->readString());
}
char c = in->readChar();
switch((int)c){
case 0: setDataVariance(osg::Object::STATIC);break;
case 1: setDataVariance(osg::Object::DYNAMIC);break;
}
char c = in->readChar();
switch((int)c)
{
case 0: setDataVariance(osg::Object::STATIC);break;
case 1: setDataVariance(osg::Object::DYNAMIC);break;
}
}
else{
throw Exception("Object::read(): Expected Object identification");
throw Exception("Object::read(): Expected Object identification");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: PagedLOD.cpp
* FILE: PagedLOD.cpp
*
* DESCRIPTION: Read/Write osg::PagedLOD in binary format to disk.
* DESCRIPTION: Read/Write osg::PagedLOD in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 24.3.2003
* HISTORY: Created 24.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -18,134 +18,138 @@
using namespace ive;
void PagedLOD::write(DataOutputStream* out){
// Write LOD's identification.
out->writeInt(IVEPAGEDLOD);
// If the osg class is inherited by any other class we should also write this to file.
void PagedLOD::write(DataOutputStream* out)
{
// Write LOD's identification.
out->writeInt(IVEPAGEDLOD);
// If the osg class is inherited by any other class we should also write this to file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
static_cast<ive::Node*>(node)->write(out);
}
else
throw Exception("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::LOD.");
out->writeString(getDatabasePath());
out->writeFloat(getRadius());
out->writeUInt(getNumChildrenThatCannotBeExpired());
unsigned int numChildrenToWriteOut = 0;
int i;
for(i=0; i<(int)getNumFileNames();++i)
{
if (getFileName(i).empty())
{
++numChildrenToWriteOut;
}
}
// Write Group's properties.
// Write number of children.
out->writeInt(numChildrenToWriteOut);
// Write children.
for(i=0; i<(int)getNumChildren(); i++){
if (getFileName(i).empty())
{
osg::Node* child = getChild(i);
out->writeNode(child);
}
}
// LOD properties
// Write centermode
out->writeInt(getCenterMode());
out->writeVec3(getCenter());
out->writeInt(getRangeMode());
// Write rangelist
int size = getNumRanges();
out->writeInt(size);
for(i=0;i<size;i++){
out->writeFloat(getMinRange(i));
out->writeFloat(getMaxRange(i));
}
// PagedLOD properties
size = getNumFileNames();
out->writeInt(size);
for(i=0;i<size;i++){
out->writeString(getFileName(i));
}
}
void PagedLOD::read(DataInputStream* in)
{
// Peek on LOD's identification.
int id = in->peekInt();
if(id == IVEPAGEDLOD)
{
// Read LOD's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
static_cast<ive::Node*>(node)->write(out);
((ive::Node*)(node))->read(in);
}
else
throw Exception("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::LOD.");
out->writeString(getDatabasePath());
out->writeFloat(getRadius());
out->writeUInt(getNumChildrenThatCannotBeExpired());
throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node.");
unsigned int numChildrenToWriteOut = 0;
int i;
for(i=0; i<(int)getNumFileNames();++i)
if ( in->getVersion() >= VERSION_0006 )
{
if (getFileName(i).empty())
{
++numChildrenToWriteOut;
}
setDatabasePath(in->readString());
}
// Write Group's properties.
// Write number of children.
out->writeInt(numChildrenToWriteOut);
// Write children.
for(i=0; i<(int)getNumChildren(); i++){
if (getFileName(i).empty())
if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty())
{
const std::string& path = in->getOptions()->getDatabasePathList().front();
if (!path.empty())
{
osg::Node* child = getChild(i);
out->writeNode(child);
setDatabasePath(path);
}
}
setRadius(in->readFloat());
setNumChildrenThatCannotBeExpired(in->readUInt());
// Read groups properties.
// Read number of children.
int size = in->readInt();
// Read children.
int i;
for(i=0; i<size; i++)
{
addChild(in->readNode());
}
// LOD properties
// Write centermode
out->writeInt(getCenterMode());
out->writeVec3(getCenter());
// Read centermode
setCenterMode((osg::LOD::CenterMode)in->readInt());
setCenter(in->readVec3());
out->writeInt(getRangeMode());
setRangeMode((RangeMode)in->readInt());
// Read rangelist
size = in->readInt();
for(i=0;i<size;i++){
float min = in->readFloat();
float max = in->readFloat();
setRange(i, min, max);
}
// Write rangelist
int size = getNumRanges();
out->writeInt(size);
for(i=0;i<size;i++){
out->writeFloat(getMinRange(i));
out->writeFloat(getMaxRange(i));
}
// PagedLOD properties
size = getNumFileNames();
out->writeInt(size);
for(i=0;i<size;i++){
out->writeString(getFileName(i));
}
}
void PagedLOD::read(DataInputStream* in){
// Peek on LOD's identification.
int id = in->peekInt();
if(id == IVEPAGEDLOD){
// Read LOD's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Node* node = dynamic_cast<osg::Node*>(this);
if(node){
((ive::Node*)(node))->read(in);
}
else
throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node.");
if ( in->getVersion() >= VERSION_0006 ) {
setDatabasePath(in->readString());
}
if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty())
{
const std::string& path = in->getOptions()->getDatabasePathList().front();
if (!path.empty())
{
setDatabasePath(path);
}
}
setRadius(in->readFloat());
setNumChildrenThatCannotBeExpired(in->readUInt());
// Read groups properties.
// Read number of children.
int size = in->readInt();
// Read children.
int i;
for(i=0; i<size; i++)
{
addChild(in->readNode());
}
// Read centermode
setCenterMode((osg::LOD::CenterMode)in->readInt());
setCenter(in->readVec3());
setRangeMode((RangeMode)in->readInt());
// Read rangelist
size = in->readInt();
for(i=0;i<size;i++){
float min = in->readFloat();
float max = in->readFloat();
setRange(i, min, max);
}
size = in->readInt();
for(i=0;i<size;i++){
setFileName(i, in->readString());
}
}
else{
throw Exception("LOD::read(): Expected LOD identification.");
}
size = in->readInt();
for(i=0;i<size;i++){
setFileName(i, in->readString());
}
}
else{
throw Exception("LOD::read(): Expected LOD identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Point.cpp
* FILE: Point.cpp
*
* DESCRIPTION: Read/Write osg::Point in binary format to disk.
* DESCRIPTION: Read/Write osg::Point in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,44 +19,44 @@
using namespace ive;
void Point::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVEPOINT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Point::write(): Could not cast this osg::Point to an osg::Object.");
// Write Point's properties.
out->writeFloat(getSize());
out->writeFloat(getFadeThresholdSize());
out->writeVec3(getDistanceAttenuation());
out->writeFloat(getMinSize());
out->writeFloat(getMaxSize());
// Write CullFace's identification.
out->writeInt(IVEPOINT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Point::write(): Could not cast this osg::Point to an osg::Object.");
// Write Point's properties.
out->writeFloat(getSize());
out->writeFloat(getFadeThresholdSize());
out->writeVec3(getDistanceAttenuation());
out->writeFloat(getMinSize());
out->writeFloat(getMaxSize());
}
void Point::read(DataInputStream* in){
// Peek on Point's identification.
int id = in->peekInt();
if(id == IVEPOINT){
// Read Point's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Point::read(): Could not cast this osg::Point to an osg::Object.");
// Read Point's properties
setSize(in->readFloat());
setFadeThresholdSize(in->readFloat());
setDistanceAttenuation(in->readVec3());
setMinSize(in->readFloat());
setMaxSize(in->readFloat());
}
else{
throw Exception("Point::read(): Expected Point identification.");
}
// Peek on Point's identification.
int id = in->peekInt();
if(id == IVEPOINT){
// Read Point's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Point::read(): Could not cast this osg::Point to an osg::Object.");
// Read Point's properties
setSize(in->readFloat());
setFadeThresholdSize(in->readFloat());
setDistanceAttenuation(in->readVec3());
setMinSize(in->readFloat());
setMaxSize(in->readFloat());
}
else{
throw Exception("Point::read(): Expected Point identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: PolygonOffset.cpp
* FILE: PolygonOffset.cpp
*
* DESCRIPTION: Read/Write osg::PolygonOffset in binary format to disk.
* DESCRIPTION: Read/Write osg::PolygonOffset in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,38 +19,38 @@
using namespace ive;
void PolygonOffset::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVEPOLYGONOFFSET);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("PolygonOffset::write(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Write PolygonOffset's properties.
out->writeFloat(getFactor());
out->writeFloat(getUnits());
// Write CullFace's identification.
out->writeInt(IVEPOLYGONOFFSET);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("PolygonOffset::write(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Write PolygonOffset's properties.
out->writeFloat(getFactor());
out->writeFloat(getUnits());
}
void PolygonOffset::read(DataInputStream* in){
// Peek on PolygonOffset's identification.
int id = in->peekInt();
if(id == IVEPOLYGONOFFSET){
// Read PolygonOffset's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("PolygonOffset::read(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Read PolygonOffset's properties
setFactor(in->readFloat());
setUnits(in->readFloat());
}
else{
throw Exception("PolygonOffset::read(): Expected PolygonOffset identification.");
}
// Peek on PolygonOffset's identification.
int id = in->peekInt();
if(id == IVEPOLYGONOFFSET){
// Read PolygonOffset's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("PolygonOffset::read(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Read PolygonOffset's properties
setFactor(in->readFloat());
setUnits(in->readFloat());
}
else{
throw Exception("PolygonOffset::read(): Expected PolygonOffset identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: PositionAttitudeTransform.cpp
* FILE: PositionAttitudeTransform.cpp
*
* DESCRIPTION: Read/Write osg::PositionAttitudeTransform in binary format to disk.
* DESCRIPTION: Read/Write osg::PositionAttitudeTransform in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 25.3.2003
* HISTORY: Created 25.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,44 +19,44 @@
using namespace ive;
void PositionAttitudeTransform::write(DataOutputStream* out){
// Write PositionAttitudeTransform's identification.
out->writeInt(IVEPOSITIONATTITUDETRANSFORM);
// If the osg class is inherited by any other class we should also write this to file.
osg::Transform* trans = dynamic_cast<osg::Transform*>(this);
if(trans){
((ive::Transform*)(trans))->write(out);
}
else
throw Exception("PositionAttitudeTransform::write(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform.");
// Write PositionAttitudeTransform's properties.
// Write PositionAttitudeTransform's identification.
out->writeInt(IVEPOSITIONATTITUDETRANSFORM);
// If the osg class is inherited by any other class we should also write this to file.
osg::Transform* trans = dynamic_cast<osg::Transform*>(this);
if(trans){
((ive::Transform*)(trans))->write(out);
}
else
throw Exception("PositionAttitudeTransform::write(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform.");
// Write PositionAttitudeTransform's properties.
out->writeVec3(getPosition());
out->writeQuat(getAttitude());
out->writeVec3(getScale());
out->writeVec3(getPivotPoint());
out->writeVec3(getPosition());
out->writeQuat(getAttitude());
out->writeVec3(getScale());
out->writeVec3(getPivotPoint());
}
void PositionAttitudeTransform::read(DataInputStream* in){
// Peek on PositionAttitudeTransform's identification.
int id = in->peekInt();
if(id == IVEPOSITIONATTITUDETRANSFORM){
// Read PositionAttitudeTransform's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Transform* trans = dynamic_cast<osg::Transform*>(this);
if(trans){
((ive::Transform*)(trans))->read(in);
}
else
throw Exception("PositionAttitudeTransform::read(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform.");
// Read PositionAttitudeTransform's properties
setPosition(in->readVec3());
setAttitude(in->readQuat());
setScale(in->readVec3());
setPivotPoint(in->readVec3());
// Peek on PositionAttitudeTransform's identification.
int id = in->peekInt();
if(id == IVEPOSITIONATTITUDETRANSFORM){
// Read PositionAttitudeTransform's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Transform* trans = dynamic_cast<osg::Transform*>(this);
if(trans){
((ive::Transform*)(trans))->read(in);
}
else
throw Exception("PositionAttitudeTransform::read(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform.");
// Read PositionAttitudeTransform's properties
setPosition(in->readVec3());
setAttitude(in->readQuat());
setScale(in->readVec3());
setPivotPoint(in->readVec3());
}
else{
throw Exception("PositionAttitudeTransform::read(): Expected PositionAttitudeTransform identification.");
}
}
else{
throw Exception("PositionAttitudeTransform::read(): Expected PositionAttitudeTransform identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: PrimitiveSet.cpp
* FILE: PrimitiveSet.cpp
*
* DESCRIPTION: Read/Write osg::PrimitiveSet in binary format to disk.
* DESCRIPTION: Read/Write osg::PrimitiveSet in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 18.3.2003
* HISTORY: Created 18.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,40 +19,40 @@
using namespace ive;
void PrimitiveSet::write(DataOutputStream* out){
// Write PrimitiveSet's identification.
out->writeInt(IVEPRIMITIVESET);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("PrimitiveSet::write(): Could not cast this osg::PrimitiveSet to an osg::Object.");
// Write PrimitiveSet's identification.
out->writeInt(IVEPRIMITIVESET);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("PrimitiveSet::write(): Could not cast this osg::PrimitiveSet to an osg::Object.");
// Write PrimitiveSet's properties.
out->writeInt(getMode());
// Write PrimitiveSet's properties.
out->writeInt(getMode());
}
void PrimitiveSet::read(DataInputStream* in){
// Read PrimitiveSet's identification.
int id = in->peekInt();
if(id == IVEPRIMITIVESET){
// Code to read PrimitiveSet's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("PrimitiveSet::read(): Could not cast this osg::PrimitiveSet to an osg::Object.");
// Read PrimitiveSet's identification.
int id = in->peekInt();
if(id == IVEPRIMITIVESET){
// Code to read PrimitiveSet's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("PrimitiveSet::read(): Could not cast this osg::PrimitiveSet to an osg::Object.");
// Read in primitiveset properties.
setMode(in->readInt());
}
else{
throw Exception("PrimitiveSet::read(): Expected PrimitiveSet identification.");
}
// Read in primitiveset properties.
setMode(in->readInt());
}
else{
throw Exception("PrimitiveSet::read(): Expected PrimitiveSet identification.");
}
}

View File

@@ -82,8 +82,8 @@ class IVEReaderWriter : public ReaderWriter
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
if (!fout) return WriteResult::ERROR_IN_WRITING_FILE;
if (!fout) return WriteResult::ERROR_IN_WRITING_FILE;
WriteResult result = writeNode(node, fout, local_opt.get());
fout.close();
return result;
@@ -106,13 +106,13 @@ class IVEReaderWriter : public ReaderWriter
out.writeNode(const_cast<osg::Node*>(&node));
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
return WriteResult::FILE_SAVED;
}
catch(ive::Exception e)
{
osg::notify(osg::WARN)<<"Error writing IVE file: "<< e.getError() << std::endl;
osg::notify(osg::WARN)<<"Error writing IVE file: "<< e.getError() << std::endl;
}
return WriteResult::FILE_NOT_HANDLED;

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Scissor.cpp
* FILE: Scissor.cpp
*
* DESCRIPTION: Read/Write osg::Scissor in binary format to disk.
* DESCRIPTION: Read/Write osg::Scissor in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,45 +19,45 @@
using namespace ive;
void Scissor::write(DataOutputStream* out){
// Write Scissor's identification.
out->writeInt(IVESCISSOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object.");
// Write Scissor's properties.
// Write Scissor's identification.
out->writeInt(IVESCISSOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object.");
// Write Scissor's properties.
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
}
void Scissor::read(DataInputStream* in){
// Peek on Scissor's identification.
int id = in->peekInt();
if(id == IVESCISSOR){
// Read Scissor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object.");
// Peek on Scissor's identification.
int id = in->peekInt();
if(id == IVESCISSOR){
// Read Scissor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object.");
// Read Scissor's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
// Read Scissor's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
}
else{
throw Exception("Scissor::read(): Expected Scissor identification.");
}
}
else{
throw Exception("Scissor::read(): Expected Scissor identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Sequence.cpp
* FILE: Sequence.cpp
*
* DESCRIPTION: Read/Write osg::Sequence in binary format to disk.
* DESCRIPTION: Read/Write osg::Sequence in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 24.3.2003
* HISTORY: Created 24.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,73 +19,73 @@
using namespace ive;
void Sequence::write(DataOutputStream* out){
// Write Sequence's identification.
out->writeInt(IVESEQUENCE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group.");
// Write Sequence's properties.
// Write Sequence's identification.
out->writeInt(IVESEQUENCE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group.");
// Write Sequence's properties.
// Write frame times.
int size = getNumChildren();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeFloat(getTime(i));
}
int size = getNumChildren();
out->writeInt(size);
for(int i=0;i<size;i++){
out->writeFloat(getTime(i));
}
// Write loop mode & interval
osg::Sequence::LoopMode mode;
osg::Sequence::LoopMode mode;
int begin, end;
getInterval(mode, begin, end);
out->writeInt(mode);
out->writeInt(begin);
out->writeInt(end);
// Write duration
out->writeInt(mode);
out->writeInt(begin);
out->writeInt(end);
// Write duration
float speed;
int nreps;
getDuration(speed, nreps);
out->writeFloat(speed);
out->writeInt(nreps);
out->writeFloat(speed);
out->writeInt(nreps);
// Write sequence mode
out->writeInt(getMode());
}
void Sequence::read(DataInputStream* in){
// Peek on Sequence's identification.
int id = in->peekInt();
if(id == IVESEQUENCE){
// Read Sequence's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group.");
// Read Sequence's properties
// Read frame times.
int size = in->readInt();
for(int i=0;i<size;i++){
setTime(i, in->readFloat());
}
// Read loop mode & interval
int mode = in->readInt();
int begin = in->readInt();
int end = in->readInt();
setInterval((osg::Sequence::LoopMode)mode, begin, end);
// Read duration
float speed = in->readFloat();
int nreps = in->readInt();
setDuration(speed, nreps);
// Read sequence mode
setMode((osg::Sequence::SequenceMode)in->readInt());
}
else{
throw Exception("Sequence::read(): Expected Sequence identification.");
}
// Peek on Sequence's identification.
int id = in->peekInt();
if(id == IVESEQUENCE){
// Read Sequence's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group.");
// Read Sequence's properties
// Read frame times.
int size = in->readInt();
for(int i=0;i<size;i++){
setTime(i, in->readFloat());
}
// Read loop mode & interval
int mode = in->readInt();
int begin = in->readInt();
int end = in->readInt();
setInterval((osg::Sequence::LoopMode)mode, begin, end);
// Read duration
float speed = in->readFloat();
int nreps = in->readInt();
setDuration(speed, nreps);
// Read sequence mode
setMode((osg::Sequence::SequenceMode)in->readInt());
}
else{
throw Exception("Sequence::read(): Expected Sequence identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: ShadeModel.cpp
* FILE: ShadeModel.cpp
*
* DESCRIPTION: Read/Write osg::ShadeModel in binary format to disk.
* DESCRIPTION: Read/Write osg::ShadeModel in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,36 +19,36 @@
using namespace ive;
void ShadeModel::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVESHADEMODEL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("ShadeModel::write(): Could not cast this osg::ShadeModel to an osg::Object.");
// Write ShadeModel's properties.
out->writeInt(getMode());
// Write CullFace's identification.
out->writeInt(IVESHADEMODEL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("ShadeModel::write(): Could not cast this osg::ShadeModel to an osg::Object.");
// Write ShadeModel's properties.
out->writeInt(getMode());
}
void ShadeModel::read(DataInputStream* in){
// Peek on ShadeModel's identification.
int id = in->peekInt();
if(id == IVESHADEMODEL){
// Read ShadeModel's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("ShadeModel::read(): Could not cast this osg::ShadeModel to an osg::Object.");
// Read ShadeModel's properties
setMode((Mode)in->readInt());
}
else{
throw Exception("ShadeModel::read(): Expected ShadeModel identification.");
}
// Peek on ShadeModel's identification.
int id = in->peekInt();
if(id == IVESHADEMODEL){
// Read ShadeModel's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("ShadeModel::read(): Could not cast this osg::ShadeModel to an osg::Object.");
// Read ShadeModel's properties
setMode((Mode)in->readInt());
}
else{
throw Exception("ShadeModel::read(): Expected ShadeModel identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Switch.cpp
* FILE: Switch.cpp
*
* DESCRIPTION: Read/Write osg::Switch in binary format to disk.
* DESCRIPTION: Read/Write osg::Switch in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.4.2003
* HISTORY: Created 9.4.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,44 +19,44 @@
using namespace ive;
void Switch::write(DataOutputStream* out){
// Write Switch's identification.
out->writeInt(IVESWITCH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group.");
// Write Switch's properties.
// Write Switch's identification.
out->writeInt(IVESWITCH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group.");
// Write Switch's properties.
// Write childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
// Write childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
out->writeBool(getValue(i));
}
void Switch::read(DataInputStream* in){
// Peek on Switch's identification.
int id = in->peekInt();
if(id == IVESWITCH){
// Read Switch's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group.");
// Read Switch's properties
// Peek on Switch's identification.
int id = in->peekInt();
if(id == IVESWITCH){
// Read Switch's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group.");
// Read Switch's properties
// Read childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
setValue(i, in->readBool());
// Read childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
setValue(i, in->readBool());
}
else{
throw Exception("Switch::read(): Expected Switch identification.");
}
}
else{
throw Exception("Switch::read(): Expected Switch identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: TexEnv.cpp
* FILE: TexEnv.cpp
*
* DESCRIPTION: Read/Write osg::TexEnv in binary format to disk.
* DESCRIPTION: Read/Write osg::TexEnv in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,44 +19,44 @@
using namespace ive;
void TexEnv::write(DataOutputStream* out){
// Write TexEnv's identification.
out->writeInt(IVETEXENV);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexEnv::write(): Could not cast this osg::TexEnv to an osg::Object.");
// Write TexEnv's properties.
// Write TexEnv's identification.
out->writeInt(IVETEXENV);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexEnv::write(): Could not cast this osg::TexEnv to an osg::Object.");
// Write TexEnv's properties.
// Write mode
out->writeInt(getMode());
// Write color
out->writeVec4(getColor());
// Write mode
out->writeInt(getMode());
// Write color
out->writeVec4(getColor());
}
void TexEnv::read(DataInputStream* in){
// Peek on TexEnv's identification.
int id = in->peekInt();
if(id == IVETEXENV){
// Read TexEnv's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexEnv::read(): Could not cast this osg::TexEnv to an osg::Object.");
// Read TexEnv's properties
// Peek on TexEnv's identification.
int id = in->peekInt();
if(id == IVETEXENV){
// Read TexEnv's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexEnv::read(): Could not cast this osg::TexEnv to an osg::Object.");
// Read TexEnv's properties
// Read mode
setMode((osg::TexEnv::Mode)in->readInt());
// Read color
setColor(in->readVec4());
}
else{
throw Exception("TexEnv::read(): Expected TexEnv identification.");
}
// Read mode
setMode((osg::TexEnv::Mode)in->readInt());
// Read color
setColor(in->readVec4());
}
else{
throw Exception("TexEnv::read(): Expected TexEnv identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: TexEnvCombine.cpp
* FILE: TexEnvCombine.cpp
*
* DESCRIPTION: Read/Write osg::TexEnvCombine in binary format to disk.
* DESCRIPTION: Read/Write osg::TexEnvCombine in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,80 +19,80 @@
using namespace ive;
void TexEnvCombine::write(DataOutputStream* out){
// Write TexEnvCombine's identification.
out->writeInt(IVETEXENVCOMBINE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexEnvCombine::write(): Could not cast this osg::TexEnvCombine to an osg::Object.");
// Write TexEnvCombine's properties.
// Write combine method
// Write TexEnvCombine's identification.
out->writeInt(IVETEXENVCOMBINE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexEnvCombine::write(): Could not cast this osg::TexEnvCombine to an osg::Object.");
// Write TexEnvCombine's properties.
// Write combine method
out->writeInt(getCombine_RGB());
out->writeInt(getCombine_Alpha());
// Write source params
out->writeInt(getSource0_RGB());
out->writeInt(getSource1_RGB());
out->writeInt(getSource2_RGB());
out->writeInt(getSource0_Alpha());
out->writeInt(getSource1_Alpha());
out->writeInt(getSource2_Alpha());
// Write operand params
out->writeInt(getOperand0_RGB());
out->writeInt(getOperand1_RGB());
out->writeInt(getOperand2_RGB());
out->writeInt(getOperand0_Alpha());
out->writeInt(getOperand1_Alpha());
out->writeInt(getOperand2_Alpha());
// Write scale and constant color
out->writeFloat(getScale_RGB());
out->writeFloat(getScale_Alpha());
out->writeVec4(getConstantColor());
// Write source params
out->writeInt(getSource0_RGB());
out->writeInt(getSource1_RGB());
out->writeInt(getSource2_RGB());
out->writeInt(getSource0_Alpha());
out->writeInt(getSource1_Alpha());
out->writeInt(getSource2_Alpha());
// Write operand params
out->writeInt(getOperand0_RGB());
out->writeInt(getOperand1_RGB());
out->writeInt(getOperand2_RGB());
out->writeInt(getOperand0_Alpha());
out->writeInt(getOperand1_Alpha());
out->writeInt(getOperand2_Alpha());
// Write scale and constant color
out->writeFloat(getScale_RGB());
out->writeFloat(getScale_Alpha());
out->writeVec4(getConstantColor());
}
void TexEnvCombine::read(DataInputStream* in){
// Peek on TexEnvCombine's identification.
int id = in->peekInt();
if(id == IVETEXENVCOMBINE){
// Read TexEnvCombine's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexEnvCombine::read(): Could not cast this osg::TexEnvCombine to an osg::Object.");
// Read TexEnvCombine's properties
// Peek on TexEnvCombine's identification.
int id = in->peekInt();
if(id == IVETEXENVCOMBINE){
// Read TexEnvCombine's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexEnvCombine::read(): Could not cast this osg::TexEnvCombine to an osg::Object.");
// Read TexEnvCombine's properties
// Read combine method
setCombine_RGB((GLint)in->readInt());
// Read combine method
setCombine_RGB((GLint)in->readInt());
setCombine_Alpha((GLint)in->readInt());
// Read combine source
setSource0_RGB((GLint)in->readInt());
// Read combine source
setSource0_RGB((GLint)in->readInt());
setSource1_RGB((GLint)in->readInt());
setSource2_RGB((GLint)in->readInt());
setSource0_Alpha((GLint)in->readInt());
setSource1_Alpha((GLint)in->readInt());
setSource2_Alpha((GLint)in->readInt());
// read combine params
// read combine params
setOperand0_RGB((GLint)in->readInt());
setOperand1_RGB((GLint)in->readInt());
setOperand2_RGB((GLint)in->readInt());
setOperand0_Alpha((GLint)in->readInt());
setOperand1_Alpha((GLint)in->readInt());
setOperand2_Alpha((GLint)in->readInt());
// Read scale and constant color
// Read scale and constant color
setScale_RGB(in->readFloat());
setScale_Alpha(in->readFloat());
setConstantColor(in->readVec4());
}
else{
throw Exception("TexEnvCombine::read(): Expected TexEnvCombine identification.");
}
}
else{
throw Exception("TexEnvCombine::read(): Expected TexEnvCombine identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: TexGen.cpp
* FILE: TexGen.cpp
*
* DESCRIPTION: Read/Write osg::TexGen in binary format to disk.
* DESCRIPTION: Read/Write osg::TexGen in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,55 +19,55 @@
using namespace ive;
void TexGen::write(DataOutputStream* out){
// Write TexGen's identification.
out->writeInt(IVETEXGEN);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexGen::write(): Could not cast this osg::TexGen to an osg::Object.");
// Write TexGen's properties.
// Write TexGen's identification.
out->writeInt(IVETEXGEN);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexGen::write(): Could not cast this osg::TexGen to an osg::Object.");
// Write TexGen's properties.
// Write mode
out->writeInt(getMode());
// Write mode
out->writeInt(getMode());
if ( out->getVersion() >= VERSION_0005 )
{
out->writePlane(getPlane(osg::TexGen::S));
out->writePlane(getPlane(osg::TexGen::T));
out->writePlane(getPlane(osg::TexGen::R));
out->writePlane(getPlane(osg::TexGen::Q));
}
if ( out->getVersion() >= VERSION_0005 )
{
out->writePlane(getPlane(osg::TexGen::S));
out->writePlane(getPlane(osg::TexGen::T));
out->writePlane(getPlane(osg::TexGen::R));
out->writePlane(getPlane(osg::TexGen::Q));
}
}
void TexGen::read(DataInputStream* in){
// Peek on TexGen's identification.
int id = in->peekInt();
if(id == IVETEXGEN){
// Read TexGen's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexGen::read(): Could not cast this osg::TexGen to an osg::Object.");
// Read TexGen's properties
setMode((osg::TexGen::Mode)in->readInt());
// Peek on TexGen's identification.
int id = in->peekInt();
if(id == IVETEXGEN){
// Read TexGen's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexGen::read(): Could not cast this osg::TexGen to an osg::Object.");
// Read TexGen's properties
setMode((osg::TexGen::Mode)in->readInt());
if ( in->getVersion() >= VERSION_0005 )
{
setPlane(osg::TexGen::S, in->readPlane());
setPlane(osg::TexGen::T, in->readPlane());
setPlane(osg::TexGen::R, in->readPlane());
setPlane(osg::TexGen::Q, in->readPlane());
}
if ( in->getVersion() >= VERSION_0005 )
{
setPlane(osg::TexGen::S, in->readPlane());
setPlane(osg::TexGen::T, in->readPlane());
setPlane(osg::TexGen::R, in->readPlane());
setPlane(osg::TexGen::Q, in->readPlane());
}
}
else{
throw Exception("TexGen::read(): Expected TexGen identification.");
}
}
else{
throw Exception("TexGen::read(): Expected TexGen identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: TexMat.cpp
* FILE: TexMat.cpp
*
* DESCRIPTION: Read/Write osg::TexMat in binary format to disk.
* DESCRIPTION: Read/Write osg::TexMat in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,41 +19,41 @@
using namespace ive;
void TexMat::write(DataOutputStream* out){
// Write TexMat's identification.
out->writeInt(IVETEXMAT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexMat::write(): Could not cast this osg::TexMat to an osg::Object.");
// Write TexMat's properties.
// Write TexMat's identification.
out->writeInt(IVETEXMAT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("TexMat::write(): Could not cast this osg::TexMat to an osg::Object.");
// Write TexMat's properties.
// Write mode
out->writeMatrixf(getMatrix());
// Write mode
out->writeMatrixf(getMatrix());
}
void TexMat::read(DataInputStream* in){
// Peek on TexMat's identification.
int id = in->peekInt();
if(id == IVETEXMAT){
// Read TexMat's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexMat::read(): Could not cast this osg::TexMat to an osg::Object.");
// Read TexMat's properties
// Peek on TexMat's identification.
int id = in->peekInt();
if(id == IVETEXMAT){
// Read TexMat's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("TexMat::read(): Could not cast this osg::TexMat to an osg::Object.");
// Read TexMat's properties
// Read matrix
setMatrix(in->readMatrixf());
// Read matrix
setMatrix(in->readMatrixf());
}
else{
throw Exception("TexMat::read(): Expected TexMat identification.");
}
}
else{
throw Exception("TexMat::read(): Expected TexMat identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Transform.cpp
* FILE: Transform.cpp
*
* DESCRIPTION: Read/Write osg::Transform in binary format to disk.
* DESCRIPTION: Read/Write osg::Transform in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerate
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 25.3.2003
* HISTORY: Created 25.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,36 +19,36 @@
using namespace ive;
void Transform::write(DataOutputStream* out){
// Write Transform's identification.
out->writeInt(IVETRANSFORM);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Transform::write(): Could not cast this osg::Transform to an osg::Group.");
// Write Transform's properties.
out->writeInt(getReferenceFrame());
// Write Transform's identification.
out->writeInt(IVETRANSFORM);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Transform::write(): Could not cast this osg::Transform to an osg::Group.");
// Write Transform's properties.
out->writeInt(getReferenceFrame());
}
void Transform::read(DataInputStream* in){
// Peek on Transform's identification.
int id = in->peekInt();
if(id == IVETRANSFORM){
// Read Transform's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Transform::read(): Could not cast this osg::Transform to an osg::Group.");
// Read Transform's properties
setReferenceFrame((osg::Transform::ReferenceFrame)in->readInt());
}
else{
throw Exception("Transform::read(): Expected Transform identification.");
}
// Peek on Transform's identification.
int id = in->peekInt();
if(id == IVETRANSFORM){
// Read Transform's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Transform::read(): Could not cast this osg::Transform to an osg::Group.");
// Read Transform's properties
setReferenceFrame((osg::Transform::ReferenceFrame)in->readInt());
}
else{
throw Exception("Transform::read(): Expected Transform identification.");
}
}

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: Viewport.cpp
* FILE: Viewport.cpp
*
* DESCRIPTION: Read/Write osg::Viewport in binary format to disk.
* DESCRIPTION: Read/Write osg::Viewport in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -19,45 +19,45 @@
using namespace ive;
void Viewport::write(DataOutputStream* out){
// Write Viewport's identification.
out->writeInt(IVEVIEWPORT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object.");
// Write Viewport's properties.
// Write Viewport's identification.
out->writeInt(IVEVIEWPORT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object.");
// Write Viewport's properties.
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
}
void Viewport::read(DataInputStream* in){
// Peek on Viewport's identification.
int id = in->peekInt();
if(id == IVEVIEWPORT){
// Read Viewport's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object.");
// Peek on Viewport's identification.
int id = in->peekInt();
if(id == IVEVIEWPORT){
// Read Viewport's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object.");
// Read Viewport's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
// Read Viewport's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
}
else{
throw Exception("Viewport::read(): Expected Viewport identification.");
}
}
else{
throw Exception("Viewport::read(): Expected Viewport identification.");
}
}

View File

@@ -1,13 +1,13 @@
/**********************************************************************
*
* FILE: VisibilityGroup.cpp
* FILE: VisibilityGroup.cpp
*
* DESCRIPTION: Read/Write osgSim::VisibilityGroup in binary format to disk.
* DESCRIPTION: Read/Write osgSim::VisibilityGroup in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerator.exe
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.11.2003
* HISTORY: Created 27.11.2003
*
**********************************************************************/
@@ -18,41 +18,41 @@
using namespace ive;
void VisibilityGroup::write(DataOutputStream* out){
// Write VisibilityGroup's identification.
out->writeInt(IVEVISIBILITYGROUP);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("VisibilityGroup::write(): Could not cast this osgSim::VisibilityGroup to an osg::Group.");
// Write VisibilityGroup's identification.
out->writeInt(IVEVISIBILITYGROUP);
// If the osgSim class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("VisibilityGroup::write(): Could not cast this osgSim::VisibilityGroup to an osg::Group.");
// Write VisibilityGroup's properties.
out->writeNode(getVisibilityVolume());
out->writeUInt(getVolumeIntersectionMask());
out->writeFloat(getSegmentLength());
// Write VisibilityGroup's properties.
out->writeNode(getVisibilityVolume());
out->writeUInt(getVolumeIntersectionMask());
out->writeFloat(getSegmentLength());
}
void VisibilityGroup::read(DataInputStream* in){
// Peek on VisibilityGroup's identification.
int id = in->peekInt();
if(id == IVEVISIBILITYGROUP){
// Read VisibilityGroup's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("VisibilityGroup::read(): Could not cast this osgSim::VisibilityGroup to an osg::Group.");
// Read VisibilityGroup's properties
setVisibilityVolume(in->readNode());
setVolumeIntersectionMask(in->readUInt());
// Peek on VisibilityGroup's identification.
int id = in->peekInt();
if(id == IVEVISIBILITYGROUP){
// Read VisibilityGroup's identification.
id = in->readInt();
// If the osgSim class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("VisibilityGroup::read(): Could not cast this osgSim::VisibilityGroup to an osg::Group.");
// Read VisibilityGroup's properties
setVisibilityVolume(in->readNode());
setVolumeIntersectionMask(in->readUInt());
setSegmentLength(in->readFloat());
}
else{
throw Exception("VisibilityGroup::read(): Expected VisibilityGroup identification.");
}
}
else{
throw Exception("VisibilityGroup::read(): Expected VisibilityGroup identification.");
}
}

View File

@@ -305,11 +305,11 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,L
for (p=node->childs; p!=0; p=p->next) {
if (!group) {
group =new osg::Group;
if (strcmp(node->name, "$$$DUMMY") == 0) {
group->setName(node->data.object.instance);
} else {
group->setName(node->name);
}
if (strcmp(node->name, "$$$DUMMY") == 0) {
group->setName(node->data.object.instance);
} else {
group->setName(node->name);
}
}
group->addChild(processNode(drawStateMap,f,p));
}

View File

@@ -13,135 +13,135 @@
using namespace lwosg;
Block::Block(const lwo2::FORM::SURF::BLOK *blok)
: enabled_(true),
opacity_type_(ADDITIVE),
opacity_amount_(1)
: enabled_(true),
opacity_type_(ADDITIVE),
opacity_amount_(1)
{
if (blok) {
compile(blok);
}
if (blok) {
compile(blok);
}
}
void Block::read_common_attributes(const iff::Chunk_list &subchunks)
{
for (iff::Chunk_list::const_iterator i=subchunks.begin(); i!=subchunks.end(); ++i) {
const lwo2::FORM::SURF::BLOK::CHAN *chan = dynamic_cast<const lwo2::FORM::SURF::BLOK::CHAN *>(*i);
if (chan) {
channel_ = std::string(chan->texture_channel.id, 4);
}
const lwo2::FORM::SURF::BLOK::ENAB *enab = dynamic_cast<const lwo2::FORM::SURF::BLOK::ENAB *>(*i);
if (enab) {
enabled_ = enab->enable != 0;
}
const lwo2::FORM::SURF::BLOK::OPAC *opac = dynamic_cast<const lwo2::FORM::SURF::BLOK::OPAC *>(*i);
if (opac) {
opacity_type_ = static_cast<Opacity_type>(opac->type);
opacity_amount_ = opac->opacity.fraction;
}
const lwo2::FORM::SURF::BLOK::AXIS *axis = dynamic_cast<const lwo2::FORM::SURF::BLOK::AXIS *>(*i);
if (axis) {
displacement_axis_ = static_cast<Axis_type>(axis->displacement_axis);
}
}
for (iff::Chunk_list::const_iterator i=subchunks.begin(); i!=subchunks.end(); ++i) {
const lwo2::FORM::SURF::BLOK::CHAN *chan = dynamic_cast<const lwo2::FORM::SURF::BLOK::CHAN *>(*i);
if (chan) {
channel_ = std::string(chan->texture_channel.id, 4);
}
const lwo2::FORM::SURF::BLOK::ENAB *enab = dynamic_cast<const lwo2::FORM::SURF::BLOK::ENAB *>(*i);
if (enab) {
enabled_ = enab->enable != 0;
}
const lwo2::FORM::SURF::BLOK::OPAC *opac = dynamic_cast<const lwo2::FORM::SURF::BLOK::OPAC *>(*i);
if (opac) {
opacity_type_ = static_cast<Opacity_type>(opac->type);
opacity_amount_ = opac->opacity.fraction;
}
const lwo2::FORM::SURF::BLOK::AXIS *axis = dynamic_cast<const lwo2::FORM::SURF::BLOK::AXIS *>(*i);
if (axis) {
displacement_axis_ = static_cast<Axis_type>(axis->displacement_axis);
}
}
}
void Block::compile(const lwo2::FORM::SURF::BLOK *blok)
{
const lwo2::FORM::SURF::BLOK::IMAP *imap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP *>(blok->header);
if (imap) {
type_ = "IMAP";
ordinal_ = imap->ordinal;
const lwo2::FORM::SURF::BLOK::IMAP *imap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP *>(blok->header);
if (imap) {
type_ = "IMAP";
ordinal_ = imap->ordinal;
// read common parameters
read_common_attributes(imap->block_attributes);
// read common parameters
read_common_attributes(imap->block_attributes);
// read imagemap-related attributes
for (iff::Chunk_list::const_iterator i=blok->attributes.begin(); i!=blok->attributes.end(); ++i) {
const lwo2::FORM::SURF::BLOK::IMAP::TMAP *tmap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP *>(*i);
if (tmap) {
Texture_mapping mapping;
for (iff::Chunk_list::const_iterator i=tmap->attributes.begin(); i!=tmap->attributes.end(); ++i) {
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *cntr = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *>(*i);
if (cntr) {
mapping.center_ = osg::Vec3(cntr->vector.X, cntr->vector.Y, cntr->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *size = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *>(*i);
if (size) {
mapping.size_ = osg::Vec3(size->vector.X, size->vector.Y, size->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *rota = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *>(*i);
if (rota) {
mapping.rotation_ = osg::Vec3(rota->vector.X, rota->vector.Y, rota->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *csys = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *>(*i);
if (csys) {
mapping.csys_ = static_cast<Texture_mapping::Coordinate_system_type>(csys->type);
}
}
imap_.mapping = mapping;
}
// read imagemap-related attributes
for (iff::Chunk_list::const_iterator i=blok->attributes.begin(); i!=blok->attributes.end(); ++i) {
const lwo2::FORM::SURF::BLOK::IMAP::TMAP *tmap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP *>(*i);
if (tmap) {
Texture_mapping mapping;
for (iff::Chunk_list::const_iterator i=tmap->attributes.begin(); i!=tmap->attributes.end(); ++i) {
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *cntr = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *>(*i);
if (cntr) {
mapping.center_ = osg::Vec3(cntr->vector.X, cntr->vector.Y, cntr->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *size = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *>(*i);
if (size) {
mapping.size_ = osg::Vec3(size->vector.X, size->vector.Y, size->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *rota = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *>(*i);
if (rota) {
mapping.rotation_ = osg::Vec3(rota->vector.X, rota->vector.Y, rota->vector.Z);
}
const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *csys = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *>(*i);
if (csys) {
mapping.csys_ = static_cast<Texture_mapping::Coordinate_system_type>(csys->type);
}
}
imap_.mapping = mapping;
}
const lwo2::FORM::SURF::BLOK::IMAP::PROJ *proj = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::PROJ *>(*i);
if (proj) {
imap_.projection = static_cast<Image_map::Projection_mode>(proj->projection_mode);
}
const lwo2::FORM::SURF::BLOK::IMAP::PROJ *proj = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::PROJ *>(*i);
if (proj) {
imap_.projection = static_cast<Image_map::Projection_mode>(proj->projection_mode);
}
const lwo2::FORM::SURF::BLOK::IMAP::AXIS *axis = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::AXIS *>(*i);
if (axis) {
imap_.axis = static_cast<Image_map::Axis_type>(axis->texture_axis);
}
const lwo2::FORM::SURF::BLOK::IMAP::AXIS *axis = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::AXIS *>(*i);
if (axis) {
imap_.axis = static_cast<Image_map::Axis_type>(axis->texture_axis);
}
const lwo2::FORM::SURF::BLOK::IMAP::IMAG *imag = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::IMAG *>(*i);
if (imag) {
imap_.image_map = imag->texture_image.index;
}
const lwo2::FORM::SURF::BLOK::IMAP::IMAG *imag = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::IMAG *>(*i);
if (imag) {
imap_.image_map = imag->texture_image.index;
}
const lwo2::FORM::SURF::BLOK::IMAP::WRAP *wrap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRAP *>(*i);
if (wrap) {
imap_.width_wrap = static_cast<Image_map::Wrap_type>(wrap->width_wrap);
imap_.height_wrap = static_cast<Image_map::Wrap_type>(wrap->height_wrap);
}
const lwo2::FORM::SURF::BLOK::IMAP::WRAP *wrap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRAP *>(*i);
if (wrap) {
imap_.width_wrap = static_cast<Image_map::Wrap_type>(wrap->width_wrap);
imap_.height_wrap = static_cast<Image_map::Wrap_type>(wrap->height_wrap);
}
const lwo2::FORM::SURF::BLOK::IMAP::WRPW *wrpw = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRPW *>(*i);
if (wrpw) {
imap_.wrap_amount_w = wrpw->cycles.fraction;
}
const lwo2::FORM::SURF::BLOK::IMAP::WRPW *wrpw = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRPW *>(*i);
if (wrpw) {
imap_.wrap_amount_w = wrpw->cycles.fraction;
}
const lwo2::FORM::SURF::BLOK::IMAP::WRPH *wrph = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRPH *>(*i);
if (wrph) {
imap_.wrap_amount_h = wrph->cycles.fraction;
}
const lwo2::FORM::SURF::BLOK::IMAP::WRPH *wrph = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::WRPH *>(*i);
if (wrph) {
imap_.wrap_amount_h = wrph->cycles.fraction;
}
const lwo2::FORM::SURF::BLOK::IMAP::VMAP *vmap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::VMAP *>(*i);
if (vmap) {
imap_.uv_map = vmap->txuv_map_name;
}
const lwo2::FORM::SURF::BLOK::IMAP::VMAP *vmap = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::VMAP *>(*i);
if (vmap) {
imap_.uv_map = vmap->txuv_map_name;
}
const lwo2::FORM::SURF::BLOK::IMAP::TAMP *tamp = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TAMP *>(*i);
if (tamp) {
imap_.texture_amplitude = tamp->amplitude.fraction;
}
}
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Block: only IMAP (image map) block types are supported, this block will be ignored" << std::endl;
}
const lwo2::FORM::SURF::BLOK::IMAP::TAMP *tamp = dynamic_cast<const lwo2::FORM::SURF::BLOK::IMAP::TAMP *>(*i);
if (tamp) {
imap_.texture_amplitude = tamp->amplitude.fraction;
}
}
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Block: only IMAP (image map) block types are supported, this block will be ignored" << std::endl;
}
}
osg::Vec3 Block::setup_texture_point(const osg::Vec3 &P) const
{
osg::Vec3 Q = P;
osg::Vec3 Q = P;
const osg::Vec3 &ypr = imap_.mapping.rotation_;
Q -= imap_.mapping.center_;
Q = Q * osg::Matrix::rotate(ypr.z(), osg::Vec3(0, 0, -1));
Q = Q * osg::Matrix::rotate(ypr.x(), osg::Vec3(0, 1, 0));
Q = Q * osg::Matrix::rotate(ypr.y(), osg::Vec3(-1, 0, 0));
if (imap_.projection != Image_map::SPHERICAL) {
Q.x() *= 1/imap_.mapping.size_.x();
Q.y() *= 1/imap_.mapping.size_.y();
Q.z() *= 1/imap_.mapping.size_.z();
}
const osg::Vec3 &ypr = imap_.mapping.rotation_;
Q -= imap_.mapping.center_;
Q = Q * osg::Matrix::rotate(ypr.z(), osg::Vec3(0, 0, -1));
Q = Q * osg::Matrix::rotate(ypr.x(), osg::Vec3(0, 1, 0));
Q = Q * osg::Matrix::rotate(ypr.y(), osg::Vec3(-1, 0, 0));
if (imap_.projection != Image_map::SPHERICAL) {
Q.x() *= 1/imap_.mapping.size_.x();
Q.y() *= 1/imap_.mapping.size_.y();
Q.z() *= 1/imap_.mapping.size_.z();
}
return Q;
return Q;
}

View File

@@ -11,15 +11,15 @@ using namespace lwosg;
Clip::Clip(const lwo2::FORM::CLIP *clip)
{
if (clip) {
compile(clip);
}
if (clip) {
compile(clip);
}
}
void Clip::compile(const lwo2::FORM::CLIP *clip)
{
for (iff::Chunk_list::const_iterator j=clip->attributes.begin(); j!=clip->attributes.end(); ++j) {
const lwo2::FORM::CLIP::STIL *stil = dynamic_cast<const lwo2::FORM::CLIP::STIL *>(*j);
if (stil) still_filename_ = stil->name.name;
}
for (iff::Chunk_list::const_iterator j=clip->attributes.begin(); j!=clip->attributes.end(); ++j) {
const lwo2::FORM::CLIP::STIL *stil = dynamic_cast<const lwo2::FORM::CLIP::STIL *>(*j);
if (stil) still_filename_ = stil->name.name;
}
}

View File

@@ -25,280 +25,280 @@ using namespace lwosg;
namespace
{
struct GeometryBin {
osg::ref_ptr<osg::DrawElementsUInt> deui_points;
osg::ref_ptr<osg::DrawElementsUInt> deui_lines;
osg::ref_ptr<osg::DrawElementsUInt> deui_triangles;
struct GeometryBin {
osg::ref_ptr<osg::DrawElementsUInt> deui_points;
osg::ref_ptr<osg::DrawElementsUInt> deui_lines;
osg::ref_ptr<osg::DrawElementsUInt> deui_triangles;
GeometryBin()
: deui_points(new osg::DrawElementsUInt(GL_POINTS)),
deui_lines(new osg::DrawElementsUInt(GL_LINES)),
deui_triangles(new osg::DrawElementsUInt(GL_TRIANGLES))
{}
};
GeometryBin()
: deui_points(new osg::DrawElementsUInt(GL_POINTS)),
deui_lines(new osg::DrawElementsUInt(GL_LINES)),
deui_triangles(new osg::DrawElementsUInt(GL_TRIANGLES))
{}
};
}
Converter::Converter()
: root_(new osg::Group)
: root_(new osg::Group)
{
}
Converter::Converter(const Options &options, const osgDB::ReaderWriter::Options* db_options)
: root_(new osg::Group),
options_(options),
db_options_(db_options)
: root_(new osg::Group),
options_(options),
db_options_(db_options)
{
}
osg::Group *Converter::convert(Object &obj)
{
if (root_->getNumChildren() > 0) {
root_->removeChild(0, root_->getNumChildren());
}
if (root_->getNumChildren() > 0) {
root_->removeChild(0, root_->getNumChildren());
}
osg::notify(osg::INFO) << "INFO: lwosg::Converter: flattening per-polygon vertex maps\n";
for (Object::Layer_map::iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) {
for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) {
j->flatten_maps();
}
}
osg::notify(osg::INFO) << "INFO: lwosg::Converter: flattening per-polygon vertex maps\n";
for (Object::Layer_map::iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) {
for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) {
j->flatten_maps();
}
}
osg::notify(osg::INFO) << "INFO: lwosg::Converter: creating scene graph\n";
build_scene_graph(obj);
osg::notify(osg::INFO) << "INFO: lwosg::Converter: creating scene graph\n";
build_scene_graph(obj);
return root_.get();
return root_.get();
}
void Converter::build_scene_graph(Object &obj)
{
// generate layer structure
typedef std::map<int, osg::ref_ptr<osg::Group> > Layer_group_map;
Layer_group_map lymap;
// generate layer structure
typedef std::map<int, osg::ref_ptr<osg::Group> > Layer_group_map;
Layer_group_map lymap;
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: creating layer structure\n";
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: creating layer structure\n";
// create a flat layer structure, no parenting since it's handled in scene files
for (Object::Layer_map::const_iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) {
const Layer &layer = i->second;
osg::ref_ptr<osg::Group> new_group = new osg::Group;
lymap[layer.number()] = new_group.get();
if (layer.get_layer_chunk()) {
new_group->setName(layer.get_layer_chunk()->name);
if (layer.get_layer_chunk()->flags & 1) {
new_group->setNodeMask(0);
}
} else {
new_group->setName("Default_layer");
}
root_->addChild(new_group.get());
}
// create a flat layer structure, no parenting since it's handled in scene files
for (Object::Layer_map::const_iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) {
const Layer &layer = i->second;
osg::ref_ptr<osg::Group> new_group = new osg::Group;
lymap[layer.number()] = new_group.get();
if (layer.get_layer_chunk()) {
new_group->setName(layer.get_layer_chunk()->name);
if (layer.get_layer_chunk()->flags & 1) {
new_group->setNodeMask(0);
}
} else {
new_group->setName("Default_layer");
}
root_->addChild(new_group.get());
}
for (Object::Layer_map::iterator li=obj.layers().begin(); li!=obj.layers().end(); ++li) {
Layer &layer = li->second;
for (Object::Layer_map::iterator li=obj.layers().begin(); li!=obj.layers().end(); ++li) {
Layer &layer = li->second;
osg::Group *layer_group = lymap[layer.number()].get();
osg::Group *layer_group = lymap[layer.number()].get();
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: processing layer '" << layer_group->getName() << "'\n";
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: processing layer '" << layer_group->getName() << "'\n";
for (Layer::Unit_list::iterator j=layer.units().begin(); j!=layer.units().end(); ++j) {
for (Layer::Unit_list::iterator j=layer.units().begin(); j!=layer.units().end(); ++j) {
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating primitives\n";
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating primitives\n";
int tess_success = 0;
int tess_fail = 0;
int tess_success = 0;
int tess_fail = 0;
typedef std::map<const Surface *, GeometryBin> GeometryBin_map;
GeometryBin_map bins;
typedef std::map<const Surface *, GeometryBin> GeometryBin_map;
GeometryBin_map bins;
typedef std::map<const Surface *, Unit::Index_list> Remapping_map;
Remapping_map remappings;
typedef std::map<const Surface *, Unit::Index_list> Remapping_map;
Remapping_map remappings;
// compute remapping map for default surface
j->compute_vertex_remapping(0, remappings[0]);
// compute remapping map for default surface
j->compute_vertex_remapping(0, remappings[0]);
// compute remapping maps for other surfaces
for (Object::Surface_map::const_iterator h=obj.surfaces().begin(); h!=obj.surfaces().end(); ++h) {
j->compute_vertex_remapping(&h->second, remappings[&h->second]);
}
// compute remapping maps for other surfaces
for (Object::Surface_map::const_iterator h=obj.surfaces().begin(); h!=obj.surfaces().end(); ++h) {
j->compute_vertex_remapping(&h->second, remappings[&h->second]);
}
// create primitive sets, taking into account remapping maps
for (unsigned k=0; k<j->polygons().size(); ++k) {
const Polygon &poly = j->polygons()[k];
GeometryBin &bin = bins[poly.get_surface()];
const Unit::Index_list &remapping = remappings[poly.get_surface()];
// create primitive sets, taking into account remapping maps
for (unsigned k=0; k<j->polygons().size(); ++k) {
const Polygon &poly = j->polygons()[k];
GeometryBin &bin = bins[poly.get_surface()];
const Unit::Index_list &remapping = remappings[poly.get_surface()];
if (poly.indices().size() == 1) {
bin.deui_points->push_back(remapping[poly.indices()[0]]);
}
if (poly.indices().size() == 2) {
bin.deui_lines->push_back(remapping[poly.indices()[0]]);
bin.deui_lines->push_back(remapping[poly.indices()[1]]);
}
if (poly.indices().size() == 3) {
bin.deui_triangles->push_back(remapping[poly.indices()[0]]);
bin.deui_triangles->push_back(remapping[poly.indices()[1]]);
bin.deui_triangles->push_back(remapping[poly.indices()[2]]);
}
if (poly.indices().size() >= 4) {
Tessellator tess;
if (tess.tessellate(poly, j->points(), bin.deui_triangles.get(), &remapping)) {
++tess_success;
} else {
++tess_fail;
}
}
}
if (poly.indices().size() == 1) {
bin.deui_points->push_back(remapping[poly.indices()[0]]);
}
if (poly.indices().size() == 2) {
bin.deui_lines->push_back(remapping[poly.indices()[0]]);
bin.deui_lines->push_back(remapping[poly.indices()[1]]);
}
if (poly.indices().size() == 3) {
bin.deui_triangles->push_back(remapping[poly.indices()[0]]);
bin.deui_triangles->push_back(remapping[poly.indices()[1]]);
bin.deui_triangles->push_back(remapping[poly.indices()[2]]);
}
if (poly.indices().size() >= 4) {
Tessellator tess;
if (tess.tessellate(poly, j->points(), bin.deui_triangles.get(), &remapping)) {
++tess_success;
} else {
++tess_fail;
}
}
}
if (tess_success > 0) {
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: " << tess_success << " polygons have been tessellated correctly\n";
}
if (tess_success > 0) {
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: " << tess_success << " polygons have been tessellated correctly\n";
}
if (tess_fail > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Converter: could not tessellate " << tess_fail << " polygons correctly. This is probably due to self-intersecting polygons being used, try to Triple them in Lightwave and restart the conversion" << std::endl;
}
if (tess_fail > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Converter: could not tessellate " << tess_fail << " polygons correctly. This is probably due to self-intersecting polygons being used, try to Triple them in Lightwave and restart the conversion" << std::endl;
}
// create normal array
osg::ref_ptr<osg::Vec3Array> normals = j->normals()->asVec3Array(j->points()->size());
// create normal array
osg::ref_ptr<osg::Vec3Array> normals = j->normals()->asVec3Array(j->points()->size());
// create first geode
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
// create first geode
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
for (GeometryBin_map::iterator i=bins.begin(); i!=bins.end(); ++i) {
const Surface *surface = i->first;
GeometryBin &bin = i->second;
for (GeometryBin_map::iterator i=bins.begin(); i!=bins.end(); ++i) {
const Surface *surface = i->first;
GeometryBin &bin = i->second;
const Unit::Index_list &remapping = remappings[surface];
const Unit::Index_list &remapping = remappings[surface];
// clean up points and normals according to remapping map
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcleaning up redundant vertices and vertex attributes for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n";
osg::ref_ptr<osg::Vec3Array> new_points = new osg::Vec3Array;
osg::ref_ptr<osg::Vec3Array> new_normals = new osg::Vec3Array;
for (unsigned pi=0; pi<j->points()->size(); ++pi) {
if (remapping[pi] != -1) {
new_points->push_back((*j->points())[pi]);
new_normals->push_back((*normals)[pi]);
}
}
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating geometry for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n";
// clean up points and normals according to remapping map
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcleaning up redundant vertices and vertex attributes for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n";
osg::ref_ptr<osg::Vec3Array> new_points = new osg::Vec3Array;
osg::ref_ptr<osg::Vec3Array> new_normals = new osg::Vec3Array;
for (unsigned pi=0; pi<j->points()->size(); ++pi) {
if (remapping[pi] != -1) {
new_points->push_back((*j->points())[pi]);
new_normals->push_back((*normals)[pi]);
}
}
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating geometry for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n";
osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
geo->setVertexArray(new_points.get());
geo->setNormalArray(new_normals.get());
geo->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
geo->setVertexArray(new_points.get());
geo->setNormalArray(new_normals.get());
geo->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
bool group_used = false;
bool group_used = false;
if (surface) {
if (!options_.combine_geodes)
{
geode->setName(surface->get_name());
}
if (surface) {
if (!options_.combine_geodes)
{
geode->setName(surface->get_name());
}
// apply surface parameters and texture/color maps according to remapping map
osg::ref_ptr<VertexMap_map> rm_texture_maps = j->texture_maps()->remap(remapping);
osg::ref_ptr<VertexMap_map> rm_rgb_maps = j->rgb_maps()->remap(remapping);
osg::ref_ptr<VertexMap_map> rm_rgba_maps = j->rgba_maps()->remap(remapping);
osg::Group *sgrp = surface->apply(geo.get(),
rm_texture_maps.get(),
rm_rgb_maps.get(),
rm_rgba_maps.get(),
options_.max_tex_units,
options_.use_osgfx,
options_.force_arb_compression,
db_options_.get());
if (sgrp)
{
group_used = true;
osg::ref_ptr<osg::Geode> grp_geode = new osg::Geode;
grp_geode->setName(surface->get_name());
grp_geode->addDrawable(geo.get());
sgrp->addChild(grp_geode.get());
layer_group->addChild(sgrp);
}
}
// apply surface parameters and texture/color maps according to remapping map
osg::ref_ptr<VertexMap_map> rm_texture_maps = j->texture_maps()->remap(remapping);
osg::ref_ptr<VertexMap_map> rm_rgb_maps = j->rgb_maps()->remap(remapping);
osg::ref_ptr<VertexMap_map> rm_rgba_maps = j->rgba_maps()->remap(remapping);
osg::Group *sgrp = surface->apply(geo.get(),
rm_texture_maps.get(),
rm_rgb_maps.get(),
rm_rgba_maps.get(),
options_.max_tex_units,
options_.use_osgfx,
options_.force_arb_compression,
db_options_.get());
if (sgrp)
{
group_used = true;
osg::ref_ptr<osg::Geode> grp_geode = new osg::Geode;
grp_geode->setName(surface->get_name());
grp_geode->addDrawable(geo.get());
sgrp->addChild(grp_geode.get());
layer_group->addChild(sgrp);
}
}
if (!group_used)
{
geode->addDrawable(geo.get());
if (geode->getNumParents() == 0)
{
layer_group->addChild(geode.get());
}
}
if (!group_used)
{
geode->addDrawable(geo.get());
if (geode->getNumParents() == 0)
{
layer_group->addChild(geode.get());
}
}
if (!options_.combine_geodes)
{
geode = new osg::Geode;
}
if (!options_.combine_geodes)
{
geode = new osg::Geode;
}
// add primitive sets to geometry
if (!bin.deui_points->empty()) geo->addPrimitiveSet(bin.deui_points.get());
if (!bin.deui_lines->empty()) geo->addPrimitiveSet(bin.deui_lines.get());
if (!bin.deui_triangles->empty()) geo->addPrimitiveSet(bin.deui_triangles.get());
}
}
// add primitive sets to geometry
if (!bin.deui_points->empty()) geo->addPrimitiveSet(bin.deui_points.get());
if (!bin.deui_lines->empty()) geo->addPrimitiveSet(bin.deui_lines.get());
if (!bin.deui_triangles->empty()) geo->addPrimitiveSet(bin.deui_triangles.get());
}
}
osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
cf->setMode(osg::CullFace::BACK);
root_->getOrCreateStateSet()->setAttributeAndModes(cf.get());
osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
cf->setMode(osg::CullFace::BACK);
root_->getOrCreateStateSet()->setAttributeAndModes(cf.get());
if (options_.apply_light_model) {
osg::ref_ptr<osg::LightModel> lm = new osg::LightModel;
lm->setTwoSided(true);
lm->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR);
lm->setAmbientIntensity(osg::Vec4(0, 0, 0, 0));
lm->setLocalViewer(true);
root_->getOrCreateStateSet()->setAttributeAndModes(lm.get());
}
}
if (options_.apply_light_model) {
osg::ref_ptr<osg::LightModel> lm = new osg::LightModel;
lm->setTwoSided(true);
lm->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR);
lm->setAmbientIntensity(osg::Vec4(0, 0, 0, 0));
lm->setLocalViewer(true);
root_->getOrCreateStateSet()->setAttributeAndModes(lm.get());
}
}
}
osg::Group *Converter::convert(const iff::Chunk_list &data)
{
Object obj(data);
obj.set_coordinate_system_fixer(options_.csf.get());
return convert(obj);
Object obj(data);
obj.set_coordinate_system_fixer(options_.csf.get());
return convert(obj);
}
osg::Group *Converter::convert(const std::string &filename)
{
std::string file = osgDB::findDataFile(filename, db_options_.get());
if (file.empty()) return 0;
std::string file = osgDB::findDataFile(filename, db_options_.get());
if (file.empty()) return 0;
std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary);
if (!ifs.is_open()) return 0;
std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary);
if (!ifs.is_open()) return 0;
std::vector<char> buffer;
char c;
while (ifs.get(c)) buffer.push_back(c);
std::vector<char> buffer;
char c;
while (ifs.get(c)) buffer.push_back(c);
lwo2::Parser<std::vector<char>::const_iterator > parser(osg::notify(osg::DEBUG_INFO));
lwo2::Parser<std::vector<char>::const_iterator > parser(osg::notify(osg::DEBUG_INFO));
try
{
parser.parse(buffer.begin(), buffer.end());
}
catch(lwo2::parser_error &e)
{
std::cerr << e.what() << std::endl;
return 0;
}
try
{
parser.parse(buffer.begin(), buffer.end());
}
catch(lwo2::parser_error &e)
{
std::cerr << e.what() << std::endl;
return 0;
}
for (iff::Chunk_list::const_iterator i=parser.chunks().begin(); i!=parser.chunks().end(); ++i) {
const lwo2::FORM *form = dynamic_cast<const lwo2::FORM *>(*i);
if (form) {
Object obj(form->data);
obj.set_coordinate_system_fixer(options_.csf.get());
if (!convert(obj)) {
return 0;
}
root_->setName(file);
return root_.get();
}
}
for (iff::Chunk_list::const_iterator i=parser.chunks().begin(); i!=parser.chunks().end(); ++i) {
const lwo2::FORM *form = dynamic_cast<const lwo2::FORM *>(*i);
if (form) {
Object obj(form->data);
obj.set_coordinate_system_fixer(options_.csf.get());
if (!convert(obj)) {
return 0;
}
root_->setName(file);
return root_.get();
}
}
return 0;
return 0;
}

View File

@@ -18,445 +18,445 @@ using namespace lwosg;
namespace
{
bool triangle_is_clockwise(const osg::Vec3Array *points, int a, int b, int c)
{
const osg::Vec3 &A = (*points)[a];
const osg::Vec3 &B = (*points)[b];
const osg::Vec3 &C = (*points)[c];
float area2 = 0;
area2 += A.x() * B.y() - B.x() * A.y();
area2 += B.x() * C.y() - C.x() * B.y();
area2 += C.x() * A.y() - A.x() * C.y();
return area2 < 0;
}
bool triangle_is_clockwise(const osg::Vec3Array *points, int a, int b, int c)
{
const osg::Vec3 &A = (*points)[a];
const osg::Vec3 &B = (*points)[b];
const osg::Vec3 &C = (*points)[c];
float area2 = 0;
area2 += A.x() * B.y() - B.x() * A.y();
area2 += B.x() * C.y() - C.x() * B.y();
area2 += C.x() * A.y() - A.x() * C.y();
return area2 < 0;
}
float cylindrical_angle(float x, float y)
{
float r = sqrtf(x*x+y*y);
if (r == 0) return 0;
x /= r;
float a;
if (x < 0 && y >= 0) a = osg::PI_2 - acosf(-x);
else if (x < 0 && y < 0) a = acosf(-x) + osg::PI_2;
else if (x >= 0 && y >= 0) a = acosf(x) + 3 * osg::PI_2;
else if (x >= 0 && y < 0) a = 3 * osg::PI_2 - acosf(x);
float cylindrical_angle(float x, float y)
{
float r = sqrtf(x*x+y*y);
if (r == 0) return 0;
x /= r;
float a;
if (x < 0 && y >= 0) a = osg::PI_2 - acosf(-x);
else if (x < 0 && y < 0) a = acosf(-x) + osg::PI_2;
else if (x >= 0 && y >= 0) a = acosf(x) + 3 * osg::PI_2;
else if (x >= 0 && y < 0) a = 3 * osg::PI_2 - acosf(x);
else a = 0.0f;
return a/osg::PI/2;
}
return a/osg::PI/2;
}
}
Object::Object()
: csf_(new LwoCoordFixer)
: csf_(new LwoCoordFixer)
{
}
Object::Object(const iff::Chunk_list &data)
: csf_(new LwoCoordFixer)
: csf_(new LwoCoordFixer)
{
build(data);
build(data);
}
void Object::build(const iff::Chunk_list &data)
{
clips_.clear();
surfaces_.clear();
layers_.clear();
comment_ = "";
description_ = "";
clips_.clear();
surfaces_.clear();
layers_.clear();
comment_ = "";
description_ = "";
osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning clips\n";
scan_clips(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning surfaces\n";
scan_surfaces(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: parsing LWO2 chunks and building object\n";
parse(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: generating normals\n";
generate_normals();
osg::notify(osg::INFO) << "INFO: lwosg::Object: generating automatic texture maps\n";
generate_auto_texture_maps();
osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning clips\n";
scan_clips(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning surfaces\n";
scan_surfaces(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: parsing LWO2 chunks and building object\n";
parse(data);
osg::notify(osg::INFO) << "INFO: lwosg::Object: generating normals\n";
generate_normals();
osg::notify(osg::INFO) << "INFO: lwosg::Object: generating automatic texture maps\n";
generate_auto_texture_maps();
}
void Object::scan_clips(const iff::Chunk_list &data)
{
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
const lwo2::FORM::CLIP *clip = dynamic_cast<const lwo2::FORM::CLIP *>(*i);
if (clip) {
clips_[clip->index] = Clip(clip);
}
}
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
const lwo2::FORM::CLIP *clip = dynamic_cast<const lwo2::FORM::CLIP *>(*i);
if (clip) {
clips_[clip->index] = Clip(clip);
}
}
}
void Object::scan_surfaces(const iff::Chunk_list &data)
{
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
const lwo2::FORM::SURF *surf = dynamic_cast<const lwo2::FORM::SURF *>(*i);
if (surf) {
surfaces_[surf->name] = Surface(surf, clips_);
}
}
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
const lwo2::FORM::SURF *surf = dynamic_cast<const lwo2::FORM::SURF *>(*i);
if (surf) {
surfaces_[surf->name] = Surface(surf, clips_);
}
}
}
void Object::parse(const iff::Chunk_list &data)
{
typedef std::vector<std::string> String_list;
String_list tag_strings;
typedef std::vector<std::string> String_list;
String_list tag_strings;
Layer current_layer;
Layer current_layer;
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) {
const lwo2::FORM::LAYR *layr = dynamic_cast<const lwo2::FORM::LAYR *>(*i);
if (layr) {
if (!current_layer.units().empty() || current_layer.get_layer_chunk()) {
layers_[current_layer.number()] = current_layer;
}
current_layer.set_layer_chunk(layr);
current_layer.units().clear();
}
const lwo2::FORM::LAYR *layr = dynamic_cast<const lwo2::FORM::LAYR *>(*i);
if (layr) {
if (!current_layer.units().empty() || current_layer.get_layer_chunk()) {
layers_[current_layer.number()] = current_layer;
}
current_layer.set_layer_chunk(layr);
current_layer.units().clear();
}
const lwo2::FORM::PNTS *pnts = dynamic_cast<const lwo2::FORM::PNTS *>(*i);
if (pnts) {
Unit new_unit;
for (lwo2::FORM::PNTS::Point_list::const_iterator i=pnts->point_location.begin(); i!=pnts->point_location.end(); ++i) {
new_unit.points()->push_back(csf_->fix_point(osg::Vec3(i->X, i->Y, i->Z) /*+ current_layer.pivot()*/));
}
new_unit.shares().assign(new_unit.points()->size(), Unit::Index_list());
current_layer.units().push_back(new_unit);
}
const lwo2::FORM::PNTS *pnts = dynamic_cast<const lwo2::FORM::PNTS *>(*i);
if (pnts) {
Unit new_unit;
for (lwo2::FORM::PNTS::Point_list::const_iterator i=pnts->point_location.begin(); i!=pnts->point_location.end(); ++i) {
new_unit.points()->push_back(csf_->fix_point(osg::Vec3(i->X, i->Y, i->Z) /*+ current_layer.pivot()*/));
}
new_unit.shares().assign(new_unit.points()->size(), Unit::Index_list());
current_layer.units().push_back(new_unit);
}
const lwo2::FORM::VMAP *vmap = dynamic_cast<const lwo2::FORM::VMAP *>(*i);
if (vmap && !current_layer.units().empty()) {
std::string type(vmap->type.id, 4);
if (type == "WGHT") {
if (vmap->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().weight_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "MNVW") {
if (vmap->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().subpatch_weight_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "TXUV") {
if (vmap->dimension != 2) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().texture_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0);
}
}
if (type == "RGB ") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().rgb_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1);
}
}
if (type == "RGBA") {
if (vmap->dimension != 4) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().rgba_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3));
}
}
if (type == "MORF") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().displacement_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 0);
}
}
if (type == "SPOT") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().spot_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(csf_->fix_point(osg::Vec3(i->value.at(0), i->value.at(1), i->value.at(2))), 0);
}
}
}
const lwo2::FORM::VMAP *vmap = dynamic_cast<const lwo2::FORM::VMAP *>(*i);
if (vmap && !current_layer.units().empty()) {
std::string type(vmap->type.id, 4);
if (type == "WGHT") {
if (vmap->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().weight_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "MNVW") {
if (vmap->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().subpatch_weight_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "TXUV") {
if (vmap->dimension != 2) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().texture_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0);
}
}
if (type == "RGB ") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().rgb_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1);
}
}
if (type == "RGBA") {
if (vmap->dimension != 4) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().rgba_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3));
}
}
if (type == "MORF") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().displacement_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 0);
}
}
if (type == "SPOT") {
if (vmap->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl;
continue;
}
VertexMap *new_map = current_layer.units().back().spot_maps()->getOrCreate(vmap->name);
for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) {
(*new_map)[i->vert.index] = osg::Vec4(csf_->fix_point(osg::Vec3(i->value.at(0), i->value.at(1), i->value.at(2))), 0);
}
}
}
const lwo2::FORM::POLS *pols = dynamic_cast<const lwo2::FORM::POLS *>(*i);
if (pols && !current_layer.units().empty()) {
std::string type(pols->type.id, 4);
if (type != "FACE") {
osg::notify(osg::INFO) << "INFO: Lwo2Object: polygon list of type " << type << " not supported, rendering may be inaccurate" << std::endl;
}
for (lwo2::FORM::POLS::Polygon_list::const_iterator i=pols->polygons.begin(); i!=pols->polygons.end(); ++i) {
Polygon polygon;
bool must_invert_winding = csf_->invert_winding();
const lwo2::FORM::POLS *pols = dynamic_cast<const lwo2::FORM::POLS *>(*i);
if (pols && !current_layer.units().empty()) {
std::string type(pols->type.id, 4);
if (type != "FACE") {
osg::notify(osg::INFO) << "INFO: Lwo2Object: polygon list of type " << type << " not supported, rendering may be inaccurate" << std::endl;
}
for (lwo2::FORM::POLS::Polygon_list::const_iterator i=pols->polygons.begin(); i!=pols->polygons.end(); ++i) {
Polygon polygon;
bool must_invert_winding = csf_->invert_winding();
// FIX FOR A LIGHTWAVE BUG? MAYBE IT IS A FEATURE, I DON'T KNOW...
// if the first vertex is at a concave corner, we must invert the winding of the polygon
// beacuse it appears as flipped in Lighwave. Also, we tell the polygon to invert its normal.
// (not implemented yet)
/*if (i->vert.size() >= 4) {
if (must_invert_winding == triangle_is_clockwise(current_layer.units().back().points(), i->vert.front().index, i->vert.back().index, i->vert[1].index)) {
must_invert_winding = !must_invert_winding;
polygon.set_invert_normal(true);
}
}*/
// FIX FOR A LIGHTWAVE BUG? MAYBE IT IS A FEATURE, I DON'T KNOW...
// if the first vertex is at a concave corner, we must invert the winding of the polygon
// beacuse it appears as flipped in Lighwave. Also, we tell the polygon to invert its normal.
// (not implemented yet)
/*if (i->vert.size() >= 4) {
if (must_invert_winding == triangle_is_clockwise(current_layer.units().back().points(), i->vert.front().index, i->vert.back().index, i->vert[1].index)) {
must_invert_winding = !must_invert_winding;
polygon.set_invert_normal(true);
}
}*/
if (must_invert_winding) {
for (unsigned j=0; j<i->numvert; ++j) {
int index = i->vert.at((i->numvert-j)%i->numvert).index;
polygon.indices().push_back(index);
current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size());
}
} else {
for (unsigned j=0; j<i->numvert; ++j) {
int index = i->vert.at(j).index;
polygon.indices().push_back(index);
current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size());
}
}
current_layer.units().back().polygons().push_back(polygon);
}
}
if (must_invert_winding) {
for (unsigned j=0; j<i->numvert; ++j) {
int index = i->vert.at((i->numvert-j)%i->numvert).index;
polygon.indices().push_back(index);
current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size());
}
} else {
for (unsigned j=0; j<i->numvert; ++j) {
int index = i->vert.at(j).index;
polygon.indices().push_back(index);
current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size());
}
}
current_layer.units().back().polygons().push_back(polygon);
}
}
const lwo2::FORM::TAGS *tags = dynamic_cast<const lwo2::FORM::TAGS *>(*i);
if (tags) {
tag_strings = tags->tag_string;
}
const lwo2::FORM::TAGS *tags = dynamic_cast<const lwo2::FORM::TAGS *>(*i);
if (tags) {
tag_strings = tags->tag_string;
}
const lwo2::FORM::PTAG *ptag = dynamic_cast<const lwo2::FORM::PTAG *>(*i);
if (ptag && !current_layer.units().empty()) {
std::string type(ptag->type.id, 4);
if (type == "SURF") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_surface(&surfaces_[tag_strings.at(i->tag)]);
}
}
if (type == "PART") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_part_name(tag_strings.at(i->tag));
}
}
if (type == "SMGP") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_smoothing_group(tag_strings.at(i->tag));
}
}
}
const lwo2::FORM::PTAG *ptag = dynamic_cast<const lwo2::FORM::PTAG *>(*i);
if (ptag && !current_layer.units().empty()) {
std::string type(ptag->type.id, 4);
if (type == "SURF") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_surface(&surfaces_[tag_strings.at(i->tag)]);
}
}
if (type == "PART") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_part_name(tag_strings.at(i->tag));
}
}
if (type == "SMGP") {
for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {
current_layer.units().back().polygons().at(i->poly.index).set_smoothing_group(tag_strings.at(i->tag));
}
}
}
const lwo2::FORM::VMAD *vmad = dynamic_cast<const lwo2::FORM::VMAD *>(*i);
if (vmad && !current_layer.units().empty()) {
std::string type(vmad->type.id, 4);
if (type == "WGHT") {
if (vmad->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).weight_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "TXUV") {
if (vmad->dimension != 2) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).texture_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0);
}
}
if (type == "RGB ") {
if (vmad->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgb_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1);
}
}
if (type == "RGBA") {
if (vmad->dimension != 4) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgba_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3));
}
}
}
const lwo2::FORM::VMAD *vmad = dynamic_cast<const lwo2::FORM::VMAD *>(*i);
if (vmad && !current_layer.units().empty()) {
std::string type(vmad->type.id, 4);
if (type == "WGHT") {
if (vmad->dimension != 1) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).weight_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);
}
}
if (type == "TXUV") {
if (vmad->dimension != 2) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).texture_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0);
}
}
if (type == "RGB ") {
if (vmad->dimension != 3) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgb_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1);
}
}
if (type == "RGBA") {
if (vmad->dimension != 4) {
osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;
continue;
}
for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {
VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgba_maps()->getOrCreate(vmad->name);
(*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3));
}
}
}
const lwo2::FORM::DESC *desc = dynamic_cast<const lwo2::FORM::DESC *>(*i);
if (desc) {
description_ = desc->description_line;
}
const lwo2::FORM::DESC *desc = dynamic_cast<const lwo2::FORM::DESC *>(*i);
if (desc) {
description_ = desc->description_line;
}
const lwo2::FORM::TEXT *text = dynamic_cast<const lwo2::FORM::TEXT *>(*i);
if (text) {
comment_ = text->comment;
}
const lwo2::FORM::TEXT *text = dynamic_cast<const lwo2::FORM::TEXT *>(*i);
if (text) {
comment_ = text->comment;
}
}
}
if (!current_layer.units().empty() || current_layer.get_layer_chunk()) {
layers_[current_layer.number()] = current_layer;
}
if (!current_layer.units().empty() || current_layer.get_layer_chunk()) {
layers_[current_layer.number()] = current_layer;
}
}
void Object::generate_normals()
{
for (Layer_map::iterator i=layers_.begin(); i!=layers_.end(); ++i) {
for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) {
j->generate_normals();
}
}
for (Layer_map::iterator i=layers_.begin(); i!=layers_.end(); ++i) {
for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) {
j->generate_normals();
}
}
}
void Object::generate_auto_texture_maps()
{
for (Surface_map::iterator i=surfaces_.begin(); i!=surfaces_.end(); ++i) {
for (Surface::Block_map::iterator j=i->second.blocks().begin(); j!=i->second.blocks().end(); ++j) {
Block &block = j->second;
if (block.get_type() == "IMAP") {
if (block.get_image_map().projection == Image_map::UV) continue;
for (Surface_map::iterator i=surfaces_.begin(); i!=surfaces_.end(); ++i) {
for (Surface::Block_map::iterator j=i->second.blocks().begin(); j!=i->second.blocks().end(); ++j) {
Block &block = j->second;
if (block.get_type() == "IMAP") {
if (block.get_image_map().projection == Image_map::UV) continue;
Image_map::Axis_type axis = block.get_image_map().axis;
Image_map::Axis_type axis = block.get_image_map().axis;
std::ostringstream oss;
oss << "Auto_map_" << &block;
std::string map_name = oss.str();
std::ostringstream oss;
oss << "Auto_map_" << &block;
std::string map_name = oss.str();
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Object: creating automatic texture map '" << map_name << "'\n";
osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Object: creating automatic texture map '" << map_name << "'\n";
for (Layer_map::iterator k=layers_.begin(); k!=layers_.end(); ++k) {
for (Layer::Unit_list::iterator h=k->second.units().begin(); h!=k->second.units().end(); ++h) {
for (Layer_map::iterator k=layers_.begin(); k!=layers_.end(); ++k) {
for (Layer::Unit_list::iterator h=k->second.units().begin(); h!=k->second.units().end(); ++h) {
osg::ref_ptr<VertexMap> new_map = new VertexMap;
(*h->texture_maps())[map_name] = new_map.get();
osg::ref_ptr<VertexMap> new_map = new VertexMap;
(*h->texture_maps())[map_name] = new_map.get();
if (block.get_image_map().projection == Image_map::FRONT_PROJECTION) {
osg::notify(osg::WARN) << "Warning: lwosg::Object: front projection is not supported" << std::endl;
}
if (block.get_image_map().projection == Image_map::FRONT_PROJECTION) {
osg::notify(osg::WARN) << "Warning: lwosg::Object: front projection is not supported" << std::endl;
}
if (block.get_image_map().projection == Image_map::CUBIC) {
if (block.get_image_map().projection == Image_map::CUBIC) {
for (Unit::Polygon_list::iterator p=h->polygons().begin(); p!=h->polygons().end(); ++p) {
for (Unit::Polygon_list::iterator p=h->polygons().begin(); p!=h->polygons().end(); ++p) {
Polygon &poly = *p;
osg::ref_ptr<VertexMap> local_uv_map = poly.texture_maps()->getOrCreate(map_name);
Polygon &poly = *p;
osg::ref_ptr<VertexMap> local_uv_map = poly.texture_maps()->getOrCreate(map_name);
osg::Vec3 N = csf_->fix_vector(poly.face_normal(h->points()));
osg::Vec3 N = csf_->fix_vector(poly.face_normal(h->points()));
Image_map::Axis_type axis = Image_map::X;
if (N.y() > N.x() && N.y() > N.z()) axis = Image_map::Y;
if (-N.y() > N.x() && -N.y() > N.z()) axis = Image_map::Y;
if (N.z() > N.x() && N.z() > N.y()) axis = Image_map::Z;
if (-N.z() > N.x() && -N.z() > N.y()) axis = Image_map::Z;
Image_map::Axis_type axis = Image_map::X;
if (N.y() > N.x() && N.y() > N.z()) axis = Image_map::Y;
if (-N.y() > N.x() && -N.y() > N.z()) axis = Image_map::Y;
if (N.z() > N.x() && N.z() > N.y()) axis = Image_map::Z;
if (-N.z() > N.x() && -N.z() > N.y()) axis = Image_map::Z;
for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i) {
for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i) {
// fetch vertex
osg::Vec3 P = csf_->fix_point((*h->points())[*i]);
// fetch vertex
osg::Vec3 P = csf_->fix_point((*h->points())[*i]);
// setup scale/translation/rotation
P = block.setup_texture_point(P);
// setup scale/translation/rotation
P = block.setup_texture_point(P);
osg::Vec2 uv;
switch (axis) {
case Image_map::X: uv.set(P.z(), P.y()); break;
case Image_map::Y: uv.set(P.x(), P.z()); break;
case Image_map::Z: uv.set(P.x(), P.y()); break;
default: ;
}
uv += osg::Vec2(0.5f, 0.5f);
osg::Vec2 uv;
switch (axis) {
case Image_map::X: uv.set(P.z(), P.y()); break;
case Image_map::Y: uv.set(P.x(), P.z()); break;
case Image_map::Z: uv.set(P.x(), P.y()); break;
default: ;
}
uv += osg::Vec2(0.5f, 0.5f);
osg::Vec4 map_value(uv.x(), uv.y(), 0, 0);
osg::Vec4 map_value(uv.x(), uv.y(), 0, 0);
if ((new_map->find(*i) != new_map->end()) && (map_value != (*new_map.get())[*i])) {
(*local_uv_map.get())[*i] = map_value;
} else {
(*new_map.get())[*i] = map_value;
}
}
}
} else {
if ((new_map->find(*i) != new_map->end()) && (map_value != (*new_map.get())[*i])) {
(*local_uv_map.get())[*i] = map_value;
} else {
(*new_map.get())[*i] = map_value;
}
}
}
} else {
for (unsigned p=0; p<h->points()->size(); ++p) {
for (unsigned p=0; p<h->points()->size(); ++p) {
// fetch vertex
osg::Vec3 P = csf_->fix_point((*h->points())[p]);
// fetch vertex
osg::Vec3 P = csf_->fix_point((*h->points())[p]);
// setup scale/translation/rotation
P = block.setup_texture_point(P);
// setup scale/translation/rotation
P = block.setup_texture_point(P);
osg::Vec2 uv;
osg::Vec2 uv;
if (block.get_image_map().projection == Image_map::PLANAR) {
switch (axis) {
case Image_map::X: uv.set(P.z(), P.y()); break;
case Image_map::Y: uv.set(P.x(), P.z()); break;
case Image_map::Z: uv.set(P.x(), P.y()); break;
default: ;
}
uv += osg::Vec2(0.5f, 0.5f);
}
if (block.get_image_map().projection == Image_map::PLANAR) {
switch (axis) {
case Image_map::X: uv.set(P.z(), P.y()); break;
case Image_map::Y: uv.set(P.x(), P.z()); break;
case Image_map::Z: uv.set(P.x(), P.y()); break;
default: ;
}
uv += osg::Vec2(0.5f, 0.5f);
}
if (block.get_image_map().projection == Image_map::CYLINDRICAL) {
switch (axis) {
case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), P.x()); break;
case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), P.y()); break;
case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), P.z()); break;
default: ;
}
uv.x() *= block.get_image_map().wrap_amount_w;
uv += osg::Vec2(0, 0.5f);
}
if (block.get_image_map().projection == Image_map::CYLINDRICAL) {
switch (axis) {
case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), P.x()); break;
case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), P.y()); break;
case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), P.z()); break;
default: ;
}
uv.x() *= block.get_image_map().wrap_amount_w;
uv += osg::Vec2(0, 0.5f);
}
if (block.get_image_map().projection == Image_map::SPHERICAL) {
float r = P.length();
if (r != 0) {
switch (axis) {
case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), (asinf(P.x()/r) + osg::PI_2) / osg::PI); break;
case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), (asinf(P.y()/r) + osg::PI_2) / osg::PI); break;
case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), (asinf(P.z()/r) + osg::PI_2) / osg::PI); break;
default: ;
}
}
uv.x() *= block.get_image_map().wrap_amount_w;
uv.y() *= block.get_image_map().wrap_amount_h;
}
if (block.get_image_map().projection == Image_map::SPHERICAL) {
float r = P.length();
if (r != 0) {
switch (axis) {
case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), (asinf(P.x()/r) + osg::PI_2) / osg::PI); break;
case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), (asinf(P.y()/r) + osg::PI_2) / osg::PI); break;
case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), (asinf(P.z()/r) + osg::PI_2) / osg::PI); break;
default: ;
}
}
uv.x() *= block.get_image_map().wrap_amount_w;
uv.y() *= block.get_image_map().wrap_amount_h;
}
(*new_map.get())[p] = osg::Vec4(uv.x(), uv.y(), 0, 0);
}
}
}
}
(*new_map.get())[p] = osg::Vec4(uv.x(), uv.y(), 0, 0);
}
}
}
}
block.get_image_map().uv_map = map_name;
block.get_image_map().projection = Image_map::UV;
}
}
}
block.get_image_map().uv_map = map_name;
block.get_image_map().projection = Image_map::UV;
}
}
}
}

View File

@@ -10,13 +10,13 @@
using namespace lwosg;
Polygon::Polygon()
: surf_(0),
local_normals_(new VertexMap),
weight_maps_(new VertexMap_map),
texture_maps_(new VertexMap_map),
rgb_maps_(new VertexMap_map),
rgba_maps_(new VertexMap_map),
invert_normal_(false),
last_used_points_(0)
: surf_(0),
local_normals_(new VertexMap),
weight_maps_(new VertexMap_map),
texture_maps_(new VertexMap_map),
rgb_maps_(new VertexMap_map),
rgba_maps_(new VertexMap_map),
invert_normal_(false),
last_used_points_(0)
{
}

View File

@@ -24,306 +24,306 @@ using namespace lwosg;
namespace
{
osg::Texture::WrapMode osg_wrap_mode(Image_map::Wrap_type w)
{
switch (w) {
case Image_map::RESET: return osg::Texture::CLAMP;
case Image_map::REPEAT: return osg::Texture::REPEAT;
case Image_map::MIRROR: return osg::Texture::MIRROR;
case Image_map::EDGE: return osg::Texture::CLAMP_TO_EDGE;
default: return osg::Texture::REPEAT;
};
}
osg::Texture::WrapMode osg_wrap_mode(Image_map::Wrap_type w)
{
switch (w) {
case Image_map::RESET: return osg::Texture::CLAMP;
case Image_map::REPEAT: return osg::Texture::REPEAT;
case Image_map::MIRROR: return osg::Texture::MIRROR;
case Image_map::EDGE: return osg::Texture::CLAMP_TO_EDGE;
default: return osg::Texture::REPEAT;
};
}
}
Surface::Surface()
: base_color_(0.784f, 0.784f, 0.784f),
diffuse_(1.0f),
luminosity_(0),
specularity_(0),
reflection_(0),
transparency_(0),
translucency_(0),
glossiness_(0.4f),
sidedness_(FRONT_ONLY),
max_smoothing_angle_(0)
: base_color_(0.784f, 0.784f, 0.784f),
diffuse_(1.0f),
luminosity_(0),
specularity_(0),
reflection_(0),
transparency_(0),
translucency_(0),
glossiness_(0.4f),
sidedness_(FRONT_ONLY),
max_smoothing_angle_(0)
{
}
Surface::Surface(const lwo2::FORM::SURF *surf, const Clip_map &clips)
: base_color_(0.784f, 0.784f, 0.784f),
diffuse_(1.0f),
luminosity_(0),
specularity_(0),
reflection_(0),
transparency_(0),
translucency_(0),
glossiness_(0.4f),
sidedness_(FRONT_ONLY),
max_smoothing_angle_(0)
: base_color_(0.784f, 0.784f, 0.784f),
diffuse_(1.0f),
luminosity_(0),
specularity_(0),
reflection_(0),
transparency_(0),
translucency_(0),
glossiness_(0.4f),
sidedness_(FRONT_ONLY),
max_smoothing_angle_(0)
{
compile(surf, clips);
compile(surf, clips);
}
void Surface::compile(const lwo2::FORM::SURF *surf, const Clip_map &clips)
{
// invalidate the stateset so it will be rebuilt
stateset_ = 0;
// invalidate the stateset so it will be rebuilt
stateset_ = 0;
name_ = surf->name;
name_ = surf->name;
for (iff::Chunk_list::const_iterator j=surf->attributes.begin(); j!=surf->attributes.end(); ++j) {
for (iff::Chunk_list::const_iterator j=surf->attributes.begin(); j!=surf->attributes.end(); ++j) {
const lwo2::FORM::SURF::COLR *colr = dynamic_cast<const lwo2::FORM::SURF::COLR *>(*j);
if (colr) base_color_ = osg::Vec3(colr->base_color.red, colr->base_color.green, colr->base_color.blue);
const lwo2::FORM::SURF::COLR *colr = dynamic_cast<const lwo2::FORM::SURF::COLR *>(*j);
if (colr) base_color_ = osg::Vec3(colr->base_color.red, colr->base_color.green, colr->base_color.blue);
const lwo2::FORM::SURF::DIFF *diff = dynamic_cast<const lwo2::FORM::SURF::DIFF *>(*j);
if (diff) diffuse_ = diff->intensity.fraction;
const lwo2::FORM::SURF::DIFF *diff = dynamic_cast<const lwo2::FORM::SURF::DIFF *>(*j);
if (diff) diffuse_ = diff->intensity.fraction;
const lwo2::FORM::SURF::LUMI *lumi = dynamic_cast<const lwo2::FORM::SURF::LUMI *>(*j);
if (lumi) luminosity_ = lumi->intensity.fraction;
const lwo2::FORM::SURF::LUMI *lumi = dynamic_cast<const lwo2::FORM::SURF::LUMI *>(*j);
if (lumi) luminosity_ = lumi->intensity.fraction;
const lwo2::FORM::SURF::SPEC *spec = dynamic_cast<const lwo2::FORM::SURF::SPEC *>(*j);
if (spec) specularity_ = spec->intensity.fraction;
const lwo2::FORM::SURF::SPEC *spec = dynamic_cast<const lwo2::FORM::SURF::SPEC *>(*j);
if (spec) specularity_ = spec->intensity.fraction;
const lwo2::FORM::SURF::REFL *refl = dynamic_cast<const lwo2::FORM::SURF::REFL *>(*j);
if (refl) reflection_ = refl->intensity.fraction;
const lwo2::FORM::SURF::REFL *refl = dynamic_cast<const lwo2::FORM::SURF::REFL *>(*j);
if (refl) reflection_ = refl->intensity.fraction;
const lwo2::FORM::SURF::TRAN *tran = dynamic_cast<const lwo2::FORM::SURF::TRAN *>(*j);
if (tran) transparency_ = tran->intensity.fraction;
const lwo2::FORM::SURF::TRAN *tran = dynamic_cast<const lwo2::FORM::SURF::TRAN *>(*j);
if (tran) transparency_ = tran->intensity.fraction;
const lwo2::FORM::SURF::TRNL *trnl = dynamic_cast<const lwo2::FORM::SURF::TRNL *>(*j);
if (trnl) translucency_ = trnl->intensity.fraction;
const lwo2::FORM::SURF::TRNL *trnl = dynamic_cast<const lwo2::FORM::SURF::TRNL *>(*j);
if (trnl) translucency_ = trnl->intensity.fraction;
const lwo2::FORM::SURF::GLOS *glos = dynamic_cast<const lwo2::FORM::SURF::GLOS *>(*j);
if (glos) glossiness_ = glos->glossiness.fraction;
const lwo2::FORM::SURF::GLOS *glos = dynamic_cast<const lwo2::FORM::SURF::GLOS *>(*j);
if (glos) glossiness_ = glos->glossiness.fraction;
const lwo2::FORM::SURF::SIDE *side = dynamic_cast<const lwo2::FORM::SURF::SIDE *>(*j);
if (side) sidedness_ = static_cast<Sidedness>(side->sidedness);
const lwo2::FORM::SURF::SIDE *side = dynamic_cast<const lwo2::FORM::SURF::SIDE *>(*j);
if (side) sidedness_ = static_cast<Sidedness>(side->sidedness);
const lwo2::FORM::SURF::SMAN *sman = dynamic_cast<const lwo2::FORM::SURF::SMAN *>(*j);
if (sman) max_smoothing_angle_ = sman->max_smoothing_angle.radians;
const lwo2::FORM::SURF::SMAN *sman = dynamic_cast<const lwo2::FORM::SURF::SMAN *>(*j);
if (sman) max_smoothing_angle_ = sman->max_smoothing_angle.radians;
const lwo2::FORM::SURF::VCOL *vcol = dynamic_cast<const lwo2::FORM::SURF::VCOL *>(*j);
if (vcol) {
color_map_intensity_ = vcol->intensity.fraction;
color_map_type_ = std::string(vcol->vmap_type.id, 4);
color_map_name_ = vcol->name;
}
const lwo2::FORM::SURF::VCOL *vcol = dynamic_cast<const lwo2::FORM::SURF::VCOL *>(*j);
if (vcol) {
color_map_intensity_ = vcol->intensity.fraction;
color_map_type_ = std::string(vcol->vmap_type.id, 4);
color_map_name_ = vcol->name;
}
const lwo2::FORM::SURF::BLOK *blok = dynamic_cast<const lwo2::FORM::SURF::BLOK *>(*j);
if (blok) {
Block new_block(blok);
if (new_block.get_type() == "IMAP") {
Clip_map::const_iterator i = clips.find(new_block.get_image_map().image_map);
if (i != clips.end()) {
new_block.get_image_map().clip = &i->second;
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: cannot find clip number " << new_block.get_image_map().image_map << std::endl;
}
}
blocks_.insert(Block_map::value_type(new_block.get_ordinal(), new_block));
}
}
const lwo2::FORM::SURF::BLOK *blok = dynamic_cast<const lwo2::FORM::SURF::BLOK *>(*j);
if (blok) {
Block new_block(blok);
if (new_block.get_type() == "IMAP") {
Clip_map::const_iterator i = clips.find(new_block.get_image_map().image_map);
if (i != clips.end()) {
new_block.get_image_map().clip = &i->second;
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: cannot find clip number " << new_block.get_image_map().image_map << std::endl;
}
}
blocks_.insert(Block_map::value_type(new_block.get_ordinal(), new_block));
}
}
}
void Surface::generate_stateset(int max_tex_units, bool force_arb_compression, const osgDB::ReaderWriter::Options* db_options) const
{
if (!stateset_.valid()) {
if (!stateset_.valid()) {
stateset_ = new osg::StateSet;
stateset_ = new osg::StateSet;
osg::ref_ptr<osg::Material> material = new osg::Material;
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * diffuse_, 1-transparency_));
material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(specularity_, specularity_, specularity_, 1));
material->setShininess(osg::Material::FRONT_AND_BACK, powf(2, 10 * glossiness_ + 2));
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * luminosity_, 1-transparency_));
stateset_->setAttributeAndModes(material.get());
osg::ref_ptr<osg::Material> material = new osg::Material;
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * diffuse_, 1-transparency_));
material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(specularity_, specularity_, specularity_, 1));
material->setShininess(osg::Material::FRONT_AND_BACK, powf(2, 10 * glossiness_ + 2));
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * luminosity_, 1-transparency_));
stateset_->setAttributeAndModes(material.get());
if (!color_map_name_.empty()) {
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
}
if (!color_map_name_.empty()) {
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
}
if (transparency_ > 0) {
osg::ref_ptr<osg::BlendFunc> bf = new osg::BlendFunc;
bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
stateset_->setAttributeAndModes(bf.get());
stateset_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
if (transparency_ > 0) {
osg::ref_ptr<osg::BlendFunc> bf = new osg::BlendFunc;
bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
stateset_->setAttributeAndModes(bf.get());
stateset_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
if (sidedness_ == FRONT_AND_BACK) {
stateset_->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
} else {
osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
switch (sidedness_) {
case NONE: cf->setMode(osg::CullFace::FRONT_AND_BACK); break;
case FRONT_ONLY: cf->setMode(osg::CullFace::BACK); break;
case BACK_ONLY: cf->setMode(osg::CullFace::FRONT); break;
default: ;
}
stateset_->setAttributeAndModes(cf.get());
}
if (sidedness_ == FRONT_AND_BACK) {
stateset_->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
} else {
osg::ref_ptr<osg::CullFace> cf = new osg::CullFace;
switch (sidedness_) {
case NONE: cf->setMode(osg::CullFace::FRONT_AND_BACK); break;
case FRONT_ONLY: cf->setMode(osg::CullFace::BACK); break;
case BACK_ONLY: cf->setMode(osg::CullFace::FRONT); break;
default: ;
}
stateset_->setAttributeAndModes(cf.get());
}
int unit = 0;
for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) {
int unit = 0;
for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) {
const Block &block = i->second;
if (!block.enabled()) {
continue;
}
const Block &block = i->second;
if (!block.enabled()) {
continue;
}
if (block.get_type() == "IMAP") {
if (block.get_channel() == "COLR") {
if (block.get_image_map().clip) {
std::string image_file = block.get_image_map().clip->get_still_filename();
if (!image_file.empty()) {
if (block.get_type() == "IMAP") {
if (block.get_channel() == "COLR") {
if (block.get_image_map().clip) {
std::string image_file = block.get_image_map().clip->get_still_filename();
if (!image_file.empty()) {
if (unit >= max_tex_units && max_tex_units > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: maximum number of texture units (" << max_tex_units << ") has been reached, skipping incoming blocks" << std::endl;
break;
}
if (unit >= max_tex_units && max_tex_units > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: maximum number of texture units (" << max_tex_units << ") has been reached, skipping incoming blocks" << std::endl;
break;
}
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
if (force_arb_compression)
texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
texture->setImage(osgDB::readImageFile(image_file, db_options));
texture->setWrap(osg::Texture::WRAP_S, osg_wrap_mode(block.get_image_map().width_wrap));
texture->setWrap(osg::Texture::WRAP_T, osg_wrap_mode(block.get_image_map().height_wrap));
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
stateset_->setTextureAttributeAndModes(unit, texture.get());
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
if (force_arb_compression)
texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
texture->setImage(osgDB::readImageFile(image_file, db_options));
texture->setWrap(osg::Texture::WRAP_S, osg_wrap_mode(block.get_image_map().width_wrap));
texture->setWrap(osg::Texture::WRAP_T, osg_wrap_mode(block.get_image_map().height_wrap));
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
stateset_->setTextureAttributeAndModes(unit, texture.get());
osg::ref_ptr<osg::TexEnvCombine> tec = new osg::TexEnvCombine;
switch (block.get_opacity_type()) {
case Block::NORMAL:
{
float s = block.get_opacity_amount();
if (unit == 0) {
tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);
osg::Vec3 color(diffuse_, diffuse_, diffuse_);
color = color * s + base_color_ * (1 - s);
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(color, 1-transparency_));
material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK));
material->setColorMode(osg::Material::OFF);
} else {
tec->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
tec->setConstantColor(osg::Vec4(s, s, s, s));
}
}
break;
osg::ref_ptr<osg::TexEnvCombine> tec = new osg::TexEnvCombine;
switch (block.get_opacity_type()) {
case Block::NORMAL:
{
float s = block.get_opacity_amount();
if (unit == 0) {
tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);
osg::Vec3 color(diffuse_, diffuse_, diffuse_);
color = color * s + base_color_ * (1 - s);
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(color, 1-transparency_));
material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK));
material->setColorMode(osg::Material::OFF);
} else {
tec->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
tec->setConstantColor(osg::Vec4(s, s, s, s));
}
}
break;
case Block::ADDITIVE:
tec->setCombine_RGB(osg::TexEnvCombine::ADD);
break;
case Block::ADDITIVE:
tec->setCombine_RGB(osg::TexEnvCombine::ADD);
break;
case Block::SUBTRACTIVE:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Subtractive' blending mode is not supported, falling back to 'Difference' mode" << std::endl;
case Block::DIFFERENCE:
tec->setCombine_RGB(osg::TexEnvCombine::SUBTRACT);
break;
case Block::SUBTRACTIVE:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Subtractive' blending mode is not supported, falling back to 'Difference' mode" << std::endl;
case Block::DIFFERENCE:
tec->setCombine_RGB(osg::TexEnvCombine::SUBTRACT);
break;
case Block::MULTIPLY:
tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);
break;
case Block::MULTIPLY:
tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);
break;
case Block::DIVIDE:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Divide' blending mode is not supported" << std::endl;
break;
case Block::DIVIDE:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Divide' blending mode is not supported" << std::endl;
break;
case Block::ALPHA:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Alpha' blending mode is not supported" << std::endl;
break;
case Block::ALPHA:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Alpha' blending mode is not supported" << std::endl;
break;
case Block::TEXTURE_DISPLACEMENT:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Texture Displacement' blending mode is not supported" << std::endl;
break;
case Block::TEXTURE_DISPLACEMENT:
osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Texture Displacement' blending mode is not supported" << std::endl;
break;
default: ;
};
default: ;
};
stateset_->setTextureAttributeAndModes(unit, tec.get());
++unit;
}
}
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: texture channels of type '" << block.get_channel() << "' are not supported, this block will be ignored" << std::endl;
}
}
}
}
stateset_->setTextureAttributeAndModes(unit, tec.get());
++unit;
}
}
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: texture channels of type '" << block.get_channel() << "' are not supported, this block will be ignored" << std::endl;
}
}
}
}
}
osg::Group *Surface::apply(osg::Geometry *geo, const VertexMap_map *texture_maps, const VertexMap_map *rgb_maps, const VertexMap_map *rgba_maps, int max_tex_units, bool use_osgfx, bool force_arb_compression, const osgDB::ReaderWriter::Options* db_options) const
{
int num_points = 0;
int num_points = 0;
if (geo->getVertexArray()) {
num_points = static_cast<int>(geo->getVertexArray()->getNumElements());
}
if (geo->getVertexArray()) {
num_points = static_cast<int>(geo->getVertexArray()->getNumElements());
}
generate_stateset(max_tex_units, force_arb_compression, db_options);
geo->setStateSet(stateset_.get());
generate_stateset(max_tex_units, force_arb_compression, db_options);
geo->setStateSet(stateset_.get());
int unit = 0;
for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) {
const Block &block = i->second;
if (block.get_type() == "IMAP" && block.get_channel() == "COLR" && block.get_image_map().clip) {
std::string image_file = block.get_image_map().clip->get_still_filename();
if (!image_file.empty()) {
if (block.get_image_map().projection == Image_map::UV) {
VertexMap_map::const_iterator i = texture_maps->find(block.get_image_map().uv_map);
if (i != texture_maps->end()) {
geo->setTexCoordArray(unit, i->second->asVec2Array(num_points));
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs texture map named '" << block.get_image_map().uv_map << "' but I can't find it" << std::endl;
}
}
++unit;
}
}
}
osg::Vec4 color = osg::Vec4(base_color_, 1-transparency_);
int unit = 0;
for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) {
const Block &block = i->second;
if (block.get_type() == "IMAP" && block.get_channel() == "COLR" && block.get_image_map().clip) {
std::string image_file = block.get_image_map().clip->get_still_filename();
if (!image_file.empty()) {
if (block.get_image_map().projection == Image_map::UV) {
VertexMap_map::const_iterator i = texture_maps->find(block.get_image_map().uv_map);
if (i != texture_maps->end()) {
geo->setTexCoordArray(unit, i->second->asVec2Array(num_points));
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs texture map named '" << block.get_image_map().uv_map << "' but I can't find it" << std::endl;
}
}
++unit;
}
}
}
osg::Vec4 color = osg::Vec4(base_color_, 1-transparency_);
const VertexMap_map *color_maps = 0;
const VertexMap_map *color_maps = 0;
if (color_map_type_ == "RGB ") {
color_maps = rgb_maps;
}
if (color_map_type_ == "RGB ") {
color_maps = rgb_maps;
}
if (color_map_type_ == "RGBA") {
color_maps = rgba_maps;
}
if (color_map_type_ == "RGBA") {
color_maps = rgba_maps;
}
if (color_maps) {
VertexMap_map::const_iterator i = color_maps->find(color_map_name_);
if (i != color_maps->end() && !i->second->empty()) {
geo->setColorArray(i->second->asVec4Array(num_points, color * color_map_intensity_, color * color_map_intensity_));
geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs color map named '" << color_map_name_ << "' but I can't find it" << std::endl;
}
}
if (color_maps) {
VertexMap_map::const_iterator i = color_maps->find(color_map_name_);
if (i != color_maps->end() && !i->second->empty()) {
geo->setColorArray(i->second->asVec4Array(num_points, color * color_map_intensity_, color * color_map_intensity_));
geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
} else {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs color map named '" << color_map_name_ << "' but I can't find it" << std::endl;
}
}
// create osgFX specularity if needed
if (use_osgfx && glossiness_ > 0 && specularity_ > 0) {
if (unit >= max_tex_units && max_tex_units > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: can't apply osgFX specular lighting: maximum number of texture units (" << max_tex_units << ") has been reached" << std::endl;
} else {
osg::ref_ptr<osgFX::SpecularHighlights> sh = new osgFX::SpecularHighlights;
sh->setTextureUnit(unit);
osg::Material *material = dynamic_cast<osg::Material *>(stateset_->getAttribute(osg::StateAttribute::MATERIAL));
if (material) {
sh->setSpecularColor(material->getSpecular(osg::Material::FRONT_AND_BACK));
sh->setSpecularExponent(powf(2, 10 * glossiness_ + 2));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 0));
material->setShininess(osg::Material::FRONT_AND_BACK, 0);
}
return sh.take();
}
}
// create osgFX specularity if needed
if (use_osgfx && glossiness_ > 0 && specularity_ > 0) {
if (unit >= max_tex_units && max_tex_units > 0) {
osg::notify(osg::WARN) << "Warning: lwosg::Surface: can't apply osgFX specular lighting: maximum number of texture units (" << max_tex_units << ") has been reached" << std::endl;
} else {
osg::ref_ptr<osgFX::SpecularHighlights> sh = new osgFX::SpecularHighlights;
sh->setTextureUnit(unit);
osg::Material *material = dynamic_cast<osg::Material *>(stateset_->getAttribute(osg::StateAttribute::MATERIAL));
if (material) {
sh->setSpecularColor(material->getSpecular(osg::Material::FRONT_AND_BACK));
sh->setSpecularExponent(powf(2, 10 * glossiness_ + 2));
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 0));
material->setShininess(osg::Material::FRONT_AND_BACK, 0);
}
return sh.take();
}
}
return 0;
return 0;
}

View File

@@ -12,74 +12,74 @@ using namespace lwosg;
namespace lwosg
{
void CALLBACK cb_begin_data(GLenum type, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->prim_type_ = type;
tess->incoming_.clear();
}
void CALLBACK cb_begin_data(GLenum type, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->prim_type_ = type;
tess->incoming_.clear();
}
void CALLBACK cb_vertex_data(void *vertex_data, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->incoming_.push_back(*static_cast<int *>(vertex_data));
}
void CALLBACK cb_vertex_data(void *vertex_data, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->incoming_.push_back(*static_cast<int *>(vertex_data));
}
void CALLBACK cb_end_data(void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->finalize_primitive();
}
void CALLBACK cb_end_data(void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->finalize_primitive();
}
void CALLBACK cb_error_data(GLenum error, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->last_error_ = error;
}
void CALLBACK cb_error_data(GLenum error, void *data)
{
Tessellator *tess = static_cast<Tessellator *>(data);
tess->last_error_ = error;
}
}
bool Tessellator::tessellate(const Polygon &poly, const osg::Vec3Array *points, osg::DrawElementsUInt *out, const std::vector<int> *remap)
{
out_ = out;
last_error_ = 0;
out_ = out;
last_error_ = 0;
GLUtesselator *tess = gluNewTess();
GLUtesselator *tess = gluNewTess();
gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLU_TESS_CALLBACK) (cb_begin_data));
gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLU_TESS_CALLBACK) (cb_vertex_data));
gluTessCallback(tess, GLU_TESS_END_DATA, (GLU_TESS_CALLBACK) (cb_end_data));
gluTessCallback(tess, GLU_TESS_ERROR_DATA, (GLU_TESS_CALLBACK) (cb_error_data));
gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLU_TESS_CALLBACK) (cb_begin_data));
gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLU_TESS_CALLBACK) (cb_vertex_data));
gluTessCallback(tess, GLU_TESS_END_DATA, (GLU_TESS_CALLBACK) (cb_end_data));
gluTessCallback(tess, GLU_TESS_ERROR_DATA, (GLU_TESS_CALLBACK) (cb_error_data));
gluTessBeginPolygon(tess, this);
gluTessBeginContour(tess);
gluTessBeginPolygon(tess, this);
gluTessBeginContour(tess);
double *vertices = new double[poly.indices().size() * 3];
int *indices = new int[poly.indices().size()];
double *vertices = new double[poly.indices().size() * 3];
int *indices = new int[poly.indices().size()];
double *v = vertices;
int *x = indices;
for (Polygon::Index_list::const_iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, v+=3, ++x) {
const osg::Vec3 &P = (*points)[*i];
v[0] = P.x();
v[1] = P.y();
v[2] = P.z();
if (remap) {
*x = (*remap)[*i];
} else {
*x = *i;
}
gluTessVertex(tess, v, x);
}
double *v = vertices;
int *x = indices;
for (Polygon::Index_list::const_iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, v+=3, ++x) {
const osg::Vec3 &P = (*points)[*i];
v[0] = P.x();
v[1] = P.y();
v[2] = P.z();
if (remap) {
*x = (*remap)[*i];
} else {
*x = *i;
}
gluTessVertex(tess, v, x);
}
gluTessEndContour(tess);
gluTessEndPolygon(tess);
gluDeleteTess(tess);
gluTessEndContour(tess);
gluTessEndPolygon(tess);
gluDeleteTess(tess);
delete[] vertices;
delete[] indices;
delete[] vertices;
delete[] indices;
return last_error_ == 0;
return last_error_ == 0;
}
Tessellator::~Tessellator()
@@ -88,34 +88,34 @@ Tessellator::~Tessellator()
void Tessellator::finalize_primitive()
{
if (incoming_.size() < 3) return;
if (incoming_.size() < 3) return;
if (prim_type_ == GL_TRIANGLES) {
for (Index_list::const_iterator i=incoming_.begin(); i!=incoming_.end(); ++i) {
out_->push_back(*i);
}
}
if (prim_type_ == GL_TRIANGLES) {
for (Index_list::const_iterator i=incoming_.begin(); i!=incoming_.end(); ++i) {
out_->push_back(*i);
}
}
if (prim_type_ == GL_TRIANGLE_FAN) {
for (Index_list::const_iterator i=incoming_.begin()+1; (i+1)!=incoming_.end(); ++i) {
out_->push_back(incoming_.front());
out_->push_back(*i);
out_->push_back(*(i+1));
}
}
if (prim_type_ == GL_TRIANGLE_FAN) {
for (Index_list::const_iterator i=incoming_.begin()+1; (i+1)!=incoming_.end(); ++i) {
out_->push_back(incoming_.front());
out_->push_back(*i);
out_->push_back(*(i+1));
}
}
if (prim_type_ == GL_TRIANGLE_STRIP) {
int j = 0;
for (Index_list::const_iterator i=incoming_.begin(); (i+2)!=incoming_.end(); ++i, ++j) {
if ((j % 2) == 0) {
out_->push_back(*i);
out_->push_back(*(i+1));
out_->push_back(*(i+2));
} else {
out_->push_back(*i);
out_->push_back(*(i+2));
out_->push_back(*(i+1));
}
}
}
if (prim_type_ == GL_TRIANGLE_STRIP) {
int j = 0;
for (Index_list::const_iterator i=incoming_.begin(); (i+2)!=incoming_.end(); ++i, ++j) {
if ((j % 2) == 0) {
out_->push_back(*i);
out_->push_back(*(i+1));
out_->push_back(*(i+2));
} else {
out_->push_back(*i);
out_->push_back(*(i+2));
out_->push_back(*(i+1));
}
}
}
}

View File

@@ -10,233 +10,233 @@
using namespace lwosg;
Unit::Unit()
: points_(new osg::Vec3Array),
normals_(new VertexMap),
weight_maps_(new VertexMap_map),
subpatch_weight_maps_(new VertexMap_map),
texture_maps_(new VertexMap_map),
rgb_maps_(new VertexMap_map),
rgba_maps_(new VertexMap_map),
displacement_maps_(new VertexMap_map),
spot_maps_(new VertexMap_map)
: points_(new osg::Vec3Array),
normals_(new VertexMap),
weight_maps_(new VertexMap_map),
subpatch_weight_maps_(new VertexMap_map),
texture_maps_(new VertexMap_map),
rgb_maps_(new VertexMap_map),
rgba_maps_(new VertexMap_map),
displacement_maps_(new VertexMap_map),
spot_maps_(new VertexMap_map)
{
}
float Unit::angle_between_polygons(const Polygon &p1, const Polygon &p2) const
{
float a = p1.face_normal(points_.get()) * p2.face_normal(points_.get());
if (a > 1) return 0;
if (a < -1) return osg::PI;
return acosf(a);
float a = p1.face_normal(points_.get()) * p2.face_normal(points_.get());
if (a > 1) return 0;
if (a < -1) return osg::PI;
return acosf(a);
}
void Unit::find_shared_polygons(int vertex_index, std::vector<int> &poly_indices)
{
int k = 0;
for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i, ++k) {
for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
if (*j == vertex_index) {
poly_indices.push_back(k);
break;
}
}
}
int k = 0;
for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i, ++k) {
for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
if (*j == vertex_index) {
poly_indices.push_back(k);
break;
}
}
}
}
void Unit::generate_normals()
{
// create smoothed normals
for (Polygon_list::iterator i=polygons_.begin(); i!=polygons_.end(); ++i) {
osg::Vec4 N = osg::Vec4(i->face_normal(points_.get()), 0);
for (Polygon::Index_list::iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
(*normals_.get())[*j] += N;
}
}
// create smoothed normals
for (Polygon_list::iterator i=polygons_.begin(); i!=polygons_.end(); ++i) {
osg::Vec4 N = osg::Vec4(i->face_normal(points_.get()), 0);
for (Polygon::Index_list::iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
(*normals_.get())[*j] += N;
}
}
// normalize smoothed normals
for (VertexMap::iterator ni=normals_->begin(); ni!=normals_->end(); ++ni) {
float l = ni->second.length();
if (l != 0) ni->second /= l;
}
// normalize smoothed normals
for (VertexMap::iterator ni=normals_->begin(); ni!=normals_->end(); ++ni) {
float l = ni->second.length();
if (l != 0) ni->second /= l;
}
// compute per-polygon normals
int pn = 0;
for (Polygon_list::iterator pi=polygons_.begin(); pi!=polygons_.end(); ++pi, ++pn) {
// compute per-polygon normals
int pn = 0;
for (Polygon_list::iterator pi=polygons_.begin(); pi!=polygons_.end(); ++pi, ++pn) {
Polygon &poly = *pi;
Polygon &poly = *pi;
float max_smoothing_angle = 0;
if (poly.has_surface()) {
max_smoothing_angle = poly.get_surface()->get_max_smoothing_angle();
}
float max_smoothing_angle = 0;
if (poly.has_surface()) {
max_smoothing_angle = poly.get_surface()->get_max_smoothing_angle();
}
for (Polygon::Index_list::const_iterator j=poly.indices().begin(); j!=poly.indices().end(); ++j) {
osg::Vec4 N(poly.face_normal(points_.get()), 0);
unsigned num_smoothed = 1;
for (Polygon::Index_list::const_iterator j=poly.indices().begin(); j!=poly.indices().end(); ++j) {
osg::Vec4 N(poly.face_normal(points_.get()), 0);
unsigned num_smoothed = 1;
const Index_list &shared_polys = shares_.at(*j);
const Index_list &shared_polys = shares_.at(*j);
for (unsigned k=0; k<shared_polys.size(); ++k) {
if (shared_polys[k] != pn) {
const Polygon &shared_poly = polygons_.at(shared_polys[k]);
float angle = angle_between_polygons(poly, shared_poly);
if (angle <= max_smoothing_angle && (poly.get_smoothing_group() == shared_poly.get_smoothing_group())) {
N += osg::Vec4(shared_poly.face_normal(points_.get()), 0);
++num_smoothed;
}
}
}
for (unsigned k=0; k<shared_polys.size(); ++k) {
if (shared_polys[k] != pn) {
const Polygon &shared_poly = polygons_.at(shared_polys[k]);
float angle = angle_between_polygons(poly, shared_poly);
if (angle <= max_smoothing_angle && (poly.get_smoothing_group() == shared_poly.get_smoothing_group())) {
N += osg::Vec4(shared_poly.face_normal(points_.get()), 0);
++num_smoothed;
}
}
}
if (num_smoothed != shared_polys.size()) {
float l = N.length();
if (l != 0) N /= l;
(*poly.local_normals())[*j] = N;
}
}
}
if (num_smoothed != shared_polys.size()) {
float l = N.length();
if (l != 0) N /= l;
(*poly.local_normals())[*j] = N;
}
}
}
}
void Unit::flatten_maps()
{
for (Polygon_list::iterator i=polygons().begin(); i!=polygons().end(); ++i) {
for (Polygon_list::iterator i=polygons().begin(); i!=polygons().end(); ++i) {
// flatten normal map
flatten_map(*i, i->local_normals(), normals_.get());
i->local_normals()->clear();
// flatten normal map
flatten_map(*i, i->local_normals(), normals_.get());
i->local_normals()->clear();
VertexMap_map::const_iterator j;
// flatten weight maps
while (!i->weight_maps()->empty()) {
VertexMap_map::iterator j = i->weight_maps()->begin();
flatten_map(*i, j->second.get(), weight_maps_->getOrCreate(j->first));
i->weight_maps()->erase(j);
}
VertexMap_map::const_iterator j;
// flatten weight maps
while (!i->weight_maps()->empty()) {
VertexMap_map::iterator j = i->weight_maps()->begin();
flatten_map(*i, j->second.get(), weight_maps_->getOrCreate(j->first));
i->weight_maps()->erase(j);
}
// flatten texture maps
while (!i->texture_maps()->empty()) {
VertexMap_map::iterator j = i->texture_maps()->begin();
flatten_map(*i, j->second.get(), texture_maps_->getOrCreate(j->first));
i->texture_maps()->erase(j);
}
// flatten texture maps
while (!i->texture_maps()->empty()) {
VertexMap_map::iterator j = i->texture_maps()->begin();
flatten_map(*i, j->second.get(), texture_maps_->getOrCreate(j->first));
i->texture_maps()->erase(j);
}
// flatten rgb maps
while (!i->rgb_maps()->empty()) {
VertexMap_map::iterator j = i->rgb_maps()->begin();
flatten_map(*i, j->second.get(), rgb_maps_->getOrCreate(j->first));
i->rgb_maps()->erase(j);
}
// flatten rgb maps
while (!i->rgb_maps()->empty()) {
VertexMap_map::iterator j = i->rgb_maps()->begin();
flatten_map(*i, j->second.get(), rgb_maps_->getOrCreate(j->first));
i->rgb_maps()->erase(j);
}
// flatten rgba maps
while (!i->rgba_maps()->empty()) {
VertexMap_map::iterator j = i->rgba_maps()->begin();
flatten_map(*i, j->second.get(), rgba_maps_->getOrCreate(j->first));
i->rgba_maps()->erase(j);
}
// flatten rgba maps
while (!i->rgba_maps()->empty()) {
VertexMap_map::iterator j = i->rgba_maps()->begin();
flatten_map(*i, j->second.get(), rgba_maps_->getOrCreate(j->first));
i->rgba_maps()->erase(j);
}
}
}
}
void Unit::flatten_map(Polygon &poly, const VertexMap *local_map, VertexMap *global_map)
{
int j = 0;
for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, ++j) {
int j = 0;
for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, ++j) {
// try original vertex index
VertexMap::const_iterator k = local_map->find(*i);
// try original vertex index
VertexMap::const_iterator k = local_map->find(*i);
// try duplicated vertex index
if (k == local_map->end()) {
k = local_map->find(poly.dup_vertices()[j]);
}
// try duplicated vertex index
if (k == local_map->end()) {
k = local_map->find(poly.dup_vertices()[j]);
}
if (k != local_map->end()) {
if (k != local_map->end()) {
// duplication may be needed!
if (poly.dup_vertices()[j] == 0) {
// duplication may be needed!
if (poly.dup_vertices()[j] == 0) {
// duplicate point
points_->push_back(points_->at(*i));
// duplicate point
points_->push_back(points_->at(*i));
int new_index = static_cast<int>(points_->size())-1;
int new_index = static_cast<int>(points_->size())-1;
// duplicate normal
(*normals_.get())[new_index] = (*normals_.get())[*i];
// duplicate normal
(*normals_.get())[new_index] = (*normals_.get())[*i];
// duplicate share
shares_.push_back(shares_.at(*i));
// duplicate share
shares_.push_back(shares_.at(*i));
VertexMap_map::iterator vm;
VertexMap_map::iterator vm;
// duplicate weights
for (vm=weight_maps()->begin(); vm!=weight_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate subpatch weights
for (vm=subpatch_weight_maps()->begin(); vm!=subpatch_weight_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate weights
for (vm=weight_maps()->begin(); vm!=weight_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate subpatch weights
for (vm=subpatch_weight_maps()->begin(); vm!=subpatch_weight_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate texture UVs
for (vm=texture_maps()->begin(); vm!=texture_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate RGBs
for (vm=rgb_maps()->begin(); vm!=rgb_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate RGBAs
for (vm=rgba_maps()->begin(); vm!=rgba_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate displacements
for (vm=displacement_maps()->begin(); vm!=displacement_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate spots
for (vm=spot_maps()->begin(); vm!=spot_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// update vertex index
poly.dup_vertices()[j] = *i;
*i = new_index;
}
// duplicate texture UVs
for (vm=texture_maps()->begin(); vm!=texture_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate RGBs
for (vm=rgb_maps()->begin(); vm!=rgb_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate RGBAs
for (vm=rgba_maps()->begin(); vm!=rgba_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate displacements
for (vm=displacement_maps()->begin(); vm!=displacement_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// duplicate spots
for (vm=spot_maps()->begin(); vm!=spot_maps()->end(); ++vm) {
if (vm->second->find(*i) != vm->second->end())
(*vm->second.get())[new_index] = (*vm->second.get())[*i];
}
// update vertex index
poly.dup_vertices()[j] = *i;
*i = new_index;
}
(*global_map)[*i] = k->second;
}
}
(*global_map)[*i] = k->second;
}
}
}
void Unit::compute_vertex_remapping(const Surface *surf, Index_list &remap) const
{
remap.assign(points_->size(), -1);
for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i) {
if (i->get_surface() == surf) {
for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
remap[*j] = *j;
}
}
}
int offset = 0;
for (Index_list::iterator j=remap.begin(); j!=remap.end(); ++j) {
if (*j == -1) {
++offset;
} else {
*j -= offset;
}
}
remap.assign(points_->size(), -1);
for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i) {
if (i->get_surface() == surf) {
for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) {
remap[*j] = *j;
}
}
}
int offset = 0;
for (Index_list::iterator j=remap.begin(); j!=remap.end(); ++j) {
if (*j == -1) {
++offset;
} else {
*j -= offset;
}
}
}

View File

@@ -13,69 +13,69 @@ using namespace lwosg;
osg::Vec4Array *VertexMap::asVec4Array(int num_vertices, const osg::Vec4 &default_value, const osg::Vec4 &modulator) const
{
osg::ref_ptr<osg::Vec4Array> array = new osg::Vec4Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
value.z() *= modulator.z();
value.w() *= modulator.w();
array->at(i->first) = value;
}
return array.take();
osg::ref_ptr<osg::Vec4Array> array = new osg::Vec4Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
value.z() *= modulator.z();
value.w() *= modulator.w();
array->at(i->first) = value;
}
return array.take();
}
osg::Vec2Array *VertexMap::asVec2Array(int num_vertices, const osg::Vec2 &default_value, const osg::Vec2 &modulator) const
{
osg::ref_ptr<osg::Vec2Array> array = new osg::Vec2Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
array->at(i->first) = osg::Vec2(value.x(), value.y());
}
return array.take();
osg::ref_ptr<osg::Vec2Array> array = new osg::Vec2Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
array->at(i->first) = osg::Vec2(value.x(), value.y());
}
return array.take();
}
osg::Vec3Array *VertexMap::asVec3Array(int num_vertices, const osg::Vec3 &default_value, const osg::Vec3 &modulator) const
{
osg::ref_ptr<osg::Vec3Array> array = new osg::Vec3Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
value.z() *= modulator.z();
array->at(i->first) = osg::Vec3(value.x(), value.y(), value.z());
}
return array.take();
osg::ref_ptr<osg::Vec3Array> array = new osg::Vec3Array;
array->assign(num_vertices, default_value);
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
osg::Vec4 value = i->second;
value.x() *= modulator.x();
value.y() *= modulator.y();
value.z() *= modulator.z();
array->at(i->first) = osg::Vec3(value.x(), value.y(), value.z());
}
return array.take();
}
VertexMap *VertexMap::remap(const std::vector<int> &remapping) const
{
osg::ref_ptr<VertexMap> result = new VertexMap;
osg::ref_ptr<VertexMap> result = new VertexMap;
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
if (i->first >= static_cast<int>(remapping.size())) {
osg::notify(osg::WARN) << "Warning: lwosg::remap(): remapping index not found for vertex " << i->first << " (map size " << remapping.size() << ")" << std::endl;
} else {
int new_index = remapping[i->first];
if (new_index != -1) {
(*result.get())[new_index] = i->second;
}
}
}
for (VertexMap::const_iterator i=begin(); i!=end(); ++i) {
if (i->first >= static_cast<int>(remapping.size())) {
osg::notify(osg::WARN) << "Warning: lwosg::remap(): remapping index not found for vertex " << i->first << " (map size " << remapping.size() << ")" << std::endl;
} else {
int new_index = remapping[i->first];
if (new_index != -1) {
(*result.get())[new_index] = i->second;
}
}
}
return result.take();
return result.take();
}
VertexMap_map *VertexMap_map::remap(const std::vector<int> &remapping) const
{
osg::ref_ptr<VertexMap_map> result = new VertexMap_map;
for (VertexMap_map::const_iterator i=begin(); i!=end(); ++i) {
(*result.get())[i->first] = i->second->remap(remapping);
}
return result.take();
osg::ref_ptr<VertexMap_map> result = new VertexMap_map;
for (VertexMap_map::const_iterator i=begin(); i!=end(); ++i) {
(*result.get())[i->first] = i->second->remap(remapping);
}
return result.take();
}

File diff suppressed because it is too large Load Diff

View File

@@ -67,9 +67,9 @@ Lwo2Layer::notify(NotifySeverity severity)
{
osg::notify(severity) << " \t" << polygon_index << " ("<< (*polygon_iterator).size() << " vertexes" << "):" << endl;
for (itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
osg::notify(severity) << " \t" << (*itr).coord << "\t\t" << (*itr).texcoord << endl;
}
{
osg::notify(severity) << " \t" << (*itr).coord << "\t\t" << (*itr).texcoord << endl;
}
osg::notify(severity) << endl;
}
@@ -109,23 +109,23 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count, DrawableToTagMapping&
PolygonsList polygons;
IteratorPolygonsList polygon_iterator;
for (polygon_iterator = _polygons.begin(); polygon_iterator != _polygons.end(); polygon_iterator++, polygon_index++)
{
// *polygon_iterator it's a PolygonsList
{
// *polygon_iterator it's a PolygonsList
// polygons of current tag only
if (_polygons_tag[polygon_index] == current_tag)
{
// polygons of current tag only
if (_polygons_tag[polygon_index] == current_tag)
{
// reset point_index member for later comparing poins data
PointsList points_list = *polygon_iterator;
for (unsigned int i = 0; i < points_list.size(); i++)
{
points_list[i].point_index = 0;
}
// reset point_index member for later comparing poins data
PointsList points_list = *polygon_iterator;
for (unsigned int i = 0; i < points_list.size(); i++)
{
points_list[i].point_index = 0;
}
polygons.push_back(*polygon_iterator);
}
}
polygons.push_back(*polygon_iterator);
}
}
// find and compose triangle fans
PolygonsList triangle_fans;
@@ -138,111 +138,111 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count, DrawableToTagMapping&
// polygons of current layer
polygon_index = 0;
for (polygon_iterator = polygons.begin(); polygon_iterator != polygons.end(); polygon_iterator++, polygon_index++)
{
if ((*polygon_iterator)[0].point_index != -1)
{
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
{
if ((*polygon_iterator)[0].point_index != -1)
{
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
if (points_count == 3)
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, points_start, points_count));
}
else if (points_count == 4)
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, points_start, points_count));
}
else
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::POLYGON, points_start, points_count));
}
}
}
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
if (points_count == 3)
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, points_start, points_count));
}
else if (points_count == 4)
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, points_start, points_count));
}
else
{
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::POLYGON, points_start, points_count));
}
}
}
// triangle fans of current layer
polygon_index = 0;
for (polygon_iterator = triangle_fans.begin(); polygon_iterator != triangle_fans.end(); polygon_iterator++, polygon_index++)
{
{
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN, points_start, points_count));
}
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN, points_start, points_count));
}
// triangle strips of current layer
polygon_index = 0;
for (polygon_iterator = triangle_strips.begin(); polygon_iterator != triangle_strips.end(); polygon_iterator++, polygon_index++)
{
{
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
// all points of polygon
for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++)
{
// *itr - it's a PointData
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
// polygons data
(*coords).push_back((*itr).coord);
(*texcoords).push_back((*itr).texcoord);
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, points_start, points_count));
}
if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f)
{
have_texture_coords = true;
}
}
unsigned int points_start = (*coords).size() - (*polygon_iterator).size();
unsigned int points_count = (*polygon_iterator).size();
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, points_start, points_count));
}
// add geometry if it contains any points
if (coords->size() != 0)
{
geometry->setVertexArray(coords.get());
{
geometry->setVertexArray(coords.get());
// assign texture array
if (have_texture_coords)
{
geometry->setTexCoordArray(0, texcoords.get());
}
// assign texture array
if (have_texture_coords)
{
geometry->setTexCoordArray(0, texcoords.get());
}
// generate normals
osgUtil::SmoothingVisitor smoother;
smoother.smooth(*(geometry.get()));
// generate normals
osgUtil::SmoothingVisitor smoother;
smoother.smooth(*(geometry.get()));
geode.addDrawable(geometry.get());
geode.addDrawable(geometry.get());
osg::notify(DEBUG_INFO) << " inserting tag " << geode.getNumDrawables() - 1 << ":" << current_tag << std::endl;
tag_mapping.insert(PairDrawableToTag(geode.getNumDrawables() - 1, current_tag));
}
osg::notify(DEBUG_INFO) << " inserting tag " << geode.getNumDrawables() - 1 << ":" << current_tag << std::endl;
tag_mapping.insert(PairDrawableToTag(geode.getNumDrawables() - 1, current_tag));
}
}
}
@@ -291,44 +291,44 @@ Lwo2Layer::_find_triangle_fan(PolygonsList& polygons, PolygonsList& triangle_fan
{
PointsList& points_list = *polygon_iterator;
if (points_list.size() == 3 && points_list[0].point_index != -1)
{
PointData a = points_list[0];
PointData b = points_list[1];
PointData c = points_list[2];
{
PointData a = points_list[0];
PointData b = points_list[1];
PointData c = points_list[2];
int next_polygon_index = _find_triangle_begins_with(polygons, a, c);
while (next_polygon_index >= 0)
{
found = true;
PointData d = polygons[next_polygon_index][2];
int next_polygon_index = _find_triangle_begins_with(polygons, a, c);
while (next_polygon_index >= 0)
{
found = true;
PointData d = polygons[next_polygon_index][2];
PointsList point_list;
point_list.push_back(a);
point_list.push_back(b);
point_list.push_back(c);
point_list.push_back(d);
PointsList point_list;
point_list.push_back(a);
point_list.push_back(b);
point_list.push_back(c);
point_list.push_back(d);
// delete second triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
// delete second triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
// delete current (first) triangle (mark as deleted)
(*polygon_iterator)[0].point_index = -1;
// delete current (first) triangle (mark as deleted)
(*polygon_iterator)[0].point_index = -1;
c = d;
while ((next_polygon_index = _find_triangle_begins_with(polygons, a, c)) >= 0)
{
PointData d = polygons[next_polygon_index][2];
point_list.push_back(d);
c = d;
while ((next_polygon_index = _find_triangle_begins_with(polygons, a, c)) >= 0)
{
PointData d = polygons[next_polygon_index][2];
point_list.push_back(d);
// delete next triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
// delete next triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
c = d;
}
triangle_fans.push_back(point_list);
}
}
c = d;
}
triangle_fans.push_back(point_list);
}
}
polygon_iterator++;
}
return found;
@@ -344,56 +344,56 @@ Lwo2Layer::_find_triangle_strip(PolygonsList& polygons, PolygonsList& triangle_s
{
PointsList& points_list = *polygon_iterator;
if (points_list.size() == 3 && points_list[0].point_index != -1)
{
PointData a = points_list[0];
PointData b = points_list[1];
PointData c = points_list[2];
{
PointData a = points_list[0];
PointData b = points_list[1];
PointData c = points_list[2];
int next_polygon_index = _find_triangle_begins_with(polygons, c, b);
int next_polygon_index = _find_triangle_begins_with(polygons, c, b);
while (next_polygon_index >= 0)
{
found = true;
PointData d = polygons[next_polygon_index][2];
while (next_polygon_index >= 0)
{
found = true;
PointData d = polygons[next_polygon_index][2];
PointsList point_list;
point_list.push_back(a);
point_list.push_back(b);
point_list.push_back(c);
point_list.push_back(d);
PointsList point_list;
point_list.push_back(a);
point_list.push_back(b);
point_list.push_back(c);
point_list.push_back(d);
// delete second triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
// delete second triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
// delete current (first) triangle (mark as deleted)
(*polygon_iterator)[0].point_index = -1;
// delete current (first) triangle (mark as deleted)
(*polygon_iterator)[0].point_index = -1;
PointData strip_a = c;
PointData strip_b = d;
bool current_strip_a = true;
PointData strip_a = c;
PointData strip_b = d;
bool current_strip_a = true;
while ((next_polygon_index = _find_triangle_begins_with(polygons, strip_a, strip_b)) >= 0)
{
PointData d = polygons[next_polygon_index][2];
point_list.push_back(d);
while ((next_polygon_index = _find_triangle_begins_with(polygons, strip_a, strip_b)) >= 0)
{
PointData d = polygons[next_polygon_index][2];
point_list.push_back(d);
if (current_strip_a)
{
strip_a = d;
}
else
{
strip_b = d;
}
current_strip_a = !current_strip_a;
if (current_strip_a)
{
strip_a = d;
}
else
{
strip_b = d;
}
current_strip_a = !current_strip_a;
// delete next triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
}
triangle_strips.push_back(point_list);
}
}
// delete next triangle (mark as deleted)
(*(polygons.begin() + next_polygon_index))[0].point_index = -1;
}
triangle_strips.push_back(point_list);
}
}
polygon_iterator++;
polygon_index++;
}
@@ -410,35 +410,35 @@ Lwo2Layer::_find_triangle_begins_with(PolygonsList& polygons, PointData& a, Poin
{
PointsList& points_list = *polygon_iterator;
if (points_list.size() == 3 && points_list[0].point_index != -1)
{
if (points_list[0] == a && points_list[1] == b)
{
result = polygon_index;
break;
}
else if (points_list[1] == a && points_list[2] == b)
{
// shift points
PointData temp = points_list[0];
points_list[0] = points_list[1];
points_list[1] = points_list[2];
points_list[2] = temp;
{
if (points_list[0] == a && points_list[1] == b)
{
result = polygon_index;
break;
}
else if (points_list[1] == a && points_list[2] == b)
{
// shift points
PointData temp = points_list[0];
points_list[0] = points_list[1];
points_list[1] = points_list[2];
points_list[2] = temp;
result = polygon_index;
break;
}
else if (points_list[2] == a && points_list[0] == b)
{
// shift points
PointData temp = points_list[2];
points_list[2] = points_list[1];
points_list[1] = points_list[0];
points_list[0] = temp;
result = polygon_index;
break;
}
else if (points_list[2] == a && points_list[0] == b)
{
// shift points
PointData temp = points_list[2];
points_list[2] = points_list[1];
points_list[1] = points_list[0];
points_list[0] = temp;
result = polygon_index;
break;
}
}
result = polygon_index;
break;
}
}
}
return result;
}

View File

@@ -23,9 +23,9 @@
#include <string.h>
#define MK_ID(a,b,c,d) ((((guint32)(a))<<24)| \
(((guint32)(b))<<16)| \
(((guint32)(c))<< 8)| \
(((guint32)(d)) ))
(((guint32)(b))<<16)| \
(((guint32)(c))<< 8)| \
(((guint32)(d)) ))
#define ID_FORM MK_ID('F','O','R','M')
#define ID_LWOB MK_ID('L','W','O','B')
@@ -294,9 +294,9 @@ static void read_pols(FILE *f, int nbytes, lwObject *lwo)
det_cnt = read_short(f);
nbytes -= 2;
while (det_cnt-- > 0) {
int cnt = read_short(f);
fseek(f, cnt*2+2, SEEK_CUR);
nbytes -= cnt*2+2;
int cnt = read_short(f);
fseek(f, cnt*2+2, SEEK_CUR);
nbytes -= cnt*2+2;
}
}
face->material -= 1;

View File

@@ -46,11 +46,11 @@ public:
ReaderWriterMD2 () { }
virtual const char* className () const {
return "Quake MD2 Reader";
return "Quake MD2 Reader";
}
virtual bool acceptsExtension (const std::string& extension) const {
return osgDB::equalCaseInsensitive (extension, "md2") ? true : false;
return osgDB::equalCaseInsensitive (extension, "md2") ? true : false;
}
virtual ReadResult readNode (const std::string& filename, const osgDB::ReaderWriter::Options* options) const;
@@ -82,18 +82,18 @@ typedef struct {
int version;
int skinWidth;
int skinHeight;
int frameSize; // size of each frame in bytes
int frameSize; // size of each frame in bytes
int numSkins;
int numVertices; // number of vertices in each frame
int numTexcoords; // number of texcoords in each frame (usually same as numVertices)
int numTriangles; // number of triangles in each frame
int numVertices; // number of vertices in each frame
int numTexcoords; // number of texcoords in each frame (usually same as numVertices)
int numTriangles; // number of triangles in each frame
int numGlCommands;
int numFrames; // number of frames
int numFrames; // number of frames
int offsetSkins;
int offsetTexCoords;
int offsetTriangles;
int offsetFrames;
int offsetGlCommands; // num dwords in gl commands list
int offsetGlCommands; // num dwords in gl commands list
int offsetEnd;
} MD2_HEADER;
@@ -158,19 +158,19 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options)
osg::Node* result = NULL;
if (stat (filename, &st) < 0) {
return NULL;
return NULL;
}
file_fd = open (filename, O_RDONLY);
if (file_fd <= 0) {
return NULL;
return NULL;
}
#if 0
mapbase = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, file_fd, 0);
if (mapbase == NULL) {
close (file_fd);
return NULL;
close (file_fd);
return NULL;
}
#else
mapbase = malloc (st.st_size);
@@ -178,21 +178,21 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options)
#endif
if (g_md2NormalsArray == NULL) {
g_md2NormalsArray = new osg::Vec3Array;
for (int i = 0; i < NUMVERTEXNORMALS; i++)
g_md2NormalsArray->push_back (osg::Vec3 (g_md2VertexNormals[i][0], g_md2VertexNormals[i][1], g_md2VertexNormals[i][2]));
g_md2NormalsArray = new osg::Vec3Array;
for (int i = 0; i < NUMVERTEXNORMALS; i++)
g_md2NormalsArray->push_back (osg::Vec3 (g_md2VertexNormals[i][0], g_md2VertexNormals[i][1], g_md2VertexNormals[i][2]));
}
MD2_HEADER *md2_header = (MD2_HEADER *) mapbase;
if (md2_header->magic != MD2_HEADER_MAGIC || md2_header->version != 8) {
#if 0
munmap (mapbase);
munmap (mapbase);
#else
free (mapbase);
free (mapbase);
#endif
close (file_fd);
return NULL;
close (file_fd);
return NULL;
}
MD2_SKIN *md2_skins = (MD2_SKIN *) ((unsigned char *) mapbase + md2_header->offsetSkins);
@@ -221,45 +221,45 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options)
std::vector<osg::Texture2D*> skin_textures;
for (int si = 0; si < md2_header->numSkins; si++) {
osg::Image *img;
osg::Texture2D *tex;
std::string imgname (md2_skins[si].name);
osg::Image *img;
osg::Texture2D *tex;
std::string imgname (md2_skins[si].name);
// first try loading the imgname straight
img = osgDB::readImageFile (imgname, options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
// first try loading the imgname straight
img = osgDB::readImageFile (imgname, options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
// we failed, so check if it's a PCX image
if (imgname.size() > 4 &&
osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx"))
{
// it's a pcx, so try bmp and tga, since pcx sucks
std::string basename = imgname.substr (0, imgname.size() - 3);
img = osgDB::readImageFile (basename + "bmp", options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
// we failed, so check if it's a PCX image
if (imgname.size() > 4 &&
osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx"))
{
// it's a pcx, so try bmp and tga, since pcx sucks
std::string basename = imgname.substr (0, imgname.size() - 3);
img = osgDB::readImageFile (basename + "bmp", options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
img = osgDB::readImageFile (basename + "tga", options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
}
img = osgDB::readImageFile (basename + "tga", options);
if (img) {
tex = new osg::Texture2D;
tex->setImage (img);
skin_textures.push_back (tex);
continue;
}
}
// couldn't find the referenced texture skin for this model
skin_textures.push_back (NULL);
osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl;
// couldn't find the referenced texture skin for this model
skin_textures.push_back (NULL);
osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl;
}
#else
// load the single skin
@@ -267,35 +267,35 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options)
osg::Texture2D *skin_texture = NULL;
if (md2_header->numSkins > 0) {
std::string imgname (md2_skins[0].name);
std::string imgname (md2_skins[0].name);
do {
// first try loading the imgname straight
skin_image = osgDB::readImageFile (imgname, options);
if (skin_image) break;
do {
// first try loading the imgname straight
skin_image = osgDB::readImageFile (imgname, options);
if (skin_image) break;
// we failed, so check if it's a PCX image
if (imgname.size() > 4 &&
osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx"))
{
// it's a pcx, so try bmp and tga, since pcx sucks
std::string basename = imgname.substr (0, imgname.size() - 3);
skin_image = osgDB::readImageFile (basename + "bmp", options);
if (skin_image) break;
// we failed, so check if it's a PCX image
if (imgname.size() > 4 &&
osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx"))
{
// it's a pcx, so try bmp and tga, since pcx sucks
std::string basename = imgname.substr (0, imgname.size() - 3);
skin_image = osgDB::readImageFile (basename + "bmp", options);
if (skin_image) break;
skin_image = osgDB::readImageFile (basename + "tga", options);
if (skin_image) break;
}
} while (0);
skin_image = osgDB::readImageFile (basename + "tga", options);
if (skin_image) break;
}
} while (0);
if (skin_image) {
skin_texture = new osg::Texture2D;
skin_texture->setImage (skin_image);
skin_texture->setFilter (osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
} else {
// couldn't find the referenced texture skin for this model
osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl;
}
if (skin_image) {
skin_texture = new osg::Texture2D;
skin_texture->setImage (skin_image);
skin_texture->setFilter (osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
} else {
// couldn't find the referenced texture skin for this model
osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl;
}
}
#endif
@@ -303,107 +303,107 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options)
int sequence_frame = 0;
for (int curFrame = 0; curFrame < md2_header->numFrames; curFrame++) {
// std::cerr << "Num vertices " << md2_header->numVertices << std::endl;
// std::cerr << "Num vertices " << md2_header->numVertices << std::endl;
//long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands);
//long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands);
MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame));
MD2_VERTEX *frame_vertices = frame->vertices;
MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame));
MD2_VERTEX *frame_vertices = frame->vertices;
// std::cerr << "Reading frame " << curFrame << " (gl offset: " << md2_header->offsetGlCommands << ") name: " << frame->name << std::endl;
// std::cerr << "Reading frame " << curFrame << " (gl offset: " << md2_header->offsetGlCommands << ") name: " << frame->name << std::endl;
int last_len = last_frame_name ? strcspn (last_frame_name, "0123456789") : 0;
int cur_len = strcspn (frame->name, "0123456789");
int last_len = last_frame_name ? strcspn (last_frame_name, "0123456789") : 0;
int cur_len = strcspn (frame->name, "0123456789");
if (last_len != cur_len || strncmp (last_frame_name, frame->name, last_len) != 0) {
if (current_sequence) {
current_sequence->setInterval (osg::Sequence::LOOP, 0, -1);
base_switch->addChild (current_sequence);
}
if (last_len != cur_len || strncmp (last_frame_name, frame->name, last_len) != 0) {
if (current_sequence) {
current_sequence->setInterval (osg::Sequence::LOOP, 0, -1);
base_switch->addChild (current_sequence);
}
current_sequence = new osg::Sequence ();
current_sequence->setMode (osg::Sequence::START);
current_sequence->setDuration (1.0f, -1);
sequence_frame = 0;
current_sequence = new osg::Sequence ();
current_sequence->setMode (osg::Sequence::START);
current_sequence->setDuration (1.0f, -1);
sequence_frame = 0;
current_sequence->setName (std::string (frame->name, cur_len));
}
current_sequence->setName (std::string (frame->name, cur_len));
}
vertexCoords = new osg::Vec3Array;
normalCoords = new osg::Vec3Array;
vertexCoords = new osg::Vec3Array;
normalCoords = new osg::Vec3Array;
for (int vi = 0; vi < md2_header->numVertices; vi++) {
vertexCoords->push_back
(osg::Vec3
(frame_vertices[vi].vertex[0] * frame->scale[0] + frame->translate[0],
-1 * (frame_vertices[vi].vertex[2] * frame->scale[2] + frame->translate[2]),
frame_vertices[vi].vertex[1] * frame->scale[1] + frame->translate[1]));
osg::Vec3 z = (*g_md2NormalsArray) [frame_vertices[vi].lightNormalIndex];
normalCoords->push_back (z);
}
for (int vi = 0; vi < md2_header->numVertices; vi++) {
vertexCoords->push_back
(osg::Vec3
(frame_vertices[vi].vertex[0] * frame->scale[0] + frame->translate[0],
-1 * (frame_vertices[vi].vertex[2] * frame->scale[2] + frame->translate[2]),
frame_vertices[vi].vertex[1] * frame->scale[1] + frame->translate[1]));
osg::Vec3 z = (*g_md2NormalsArray) [frame_vertices[vi].lightNormalIndex];
normalCoords->push_back (z);
}
if (curFrame == 0) {
vertexIndices = new osg::UIntArray;
normalIndices = new osg::UIntArray;
if (curFrame == 0) {
vertexIndices = new osg::UIntArray;
normalIndices = new osg::UIntArray;
texCoords = new osg::Vec2Array;
texIndices = new osg::UIntArray;
texCoords = new osg::Vec2Array;
texIndices = new osg::UIntArray;
for (int vi = 0; vi < md2_header->numTexcoords; vi++) {
texCoords->push_back
(osg::Vec2 ((float) md2_texcoords[vi].s / md2_header->skinWidth,
1.0f - (float) md2_texcoords[vi].t / md2_header->skinHeight));
}
for (int vi = 0; vi < md2_header->numTexcoords; vi++) {
texCoords->push_back
(osg::Vec2 ((float) md2_texcoords[vi].s / md2_header->skinWidth,
1.0f - (float) md2_texcoords[vi].t / md2_header->skinHeight));
}
for (int ti = 0; ti < md2_header->numTriangles; ti++) {
vertexIndices->push_back (md2_triangles[ti].vertexIndices[0]);
vertexIndices->push_back (md2_triangles[ti].vertexIndices[1]);
vertexIndices->push_back (md2_triangles[ti].vertexIndices[2]);
for (int ti = 0; ti < md2_header->numTriangles; ti++) {
vertexIndices->push_back (md2_triangles[ti].vertexIndices[0]);
vertexIndices->push_back (md2_triangles[ti].vertexIndices[1]);
vertexIndices->push_back (md2_triangles[ti].vertexIndices[2]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[0]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[1]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[2]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[0]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[1]);
normalIndices->push_back (md2_triangles[ti].vertexIndices[2]);
texIndices->push_back (md2_triangles[ti].textureIndices[0]);
texIndices->push_back (md2_triangles[ti].textureIndices[1]);
texIndices->push_back (md2_triangles[ti].textureIndices[2]);
}
}
texIndices->push_back (md2_triangles[ti].textureIndices[0]);
texIndices->push_back (md2_triangles[ti].textureIndices[1]);
texIndices->push_back (md2_triangles[ti].textureIndices[2]);
}
}
osg::Geometry *geom = new osg::Geometry;
osg::Geometry *geom = new osg::Geometry;
geom->setVertexArray (vertexCoords);
geom->setVertexIndices (vertexIndices);
geom->setVertexArray (vertexCoords);
geom->setVertexIndices (vertexIndices);
geom->setTexCoordArray (0, texCoords);
geom->setTexCoordIndices (0, texIndices);
geom->setTexCoordArray (0, texCoords);
geom->setTexCoordIndices (0, texIndices);
geom->setNormalArray (g_md2NormalsArray);
geom->setNormalIndices (normalIndices);
geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
geom->setNormalArray (g_md2NormalsArray);
geom->setNormalIndices (normalIndices);
geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
geom->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0, vertexIndices->size ()));
geom->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0, vertexIndices->size ()));
osg::Geode *geode = new osg::Geode;
geode->addDrawable (geom);
osg::Geode *geode = new osg::Geode;
geode->addDrawable (geom);
current_sequence->addChild (geode);
current_sequence->setTime (sequence_frame, 0.2f);
sequence_frame++;
current_sequence->addChild (geode);
current_sequence->setTime (sequence_frame, 0.2f);
sequence_frame++;
last_frame_name = frame->name;
last_frame_name = frame->name;
}
if (current_sequence) {
current_sequence->setInterval (osg::Sequence::LOOP, 0, -1);
base_switch->addChild (current_sequence);
current_sequence->setInterval (osg::Sequence::LOOP, 0, -1);
base_switch->addChild (current_sequence);
}
osg::StateSet *state = new osg::StateSet;
if (skin_texture != NULL) {
state->setTextureAttributeAndModes (0, skin_texture, osg::StateAttribute::ON);
state->setTextureAttributeAndModes (0, skin_texture, osg::StateAttribute::ON);
}
base_switch->setStateSet (state);

View File

@@ -24,9 +24,9 @@
//
// Version: 12Jan97 1.11
// 2002-07-25 Version 1.2 (C) Herbert Straub
// Adding improved Error Handling in sockerr class
// sockinetaddr::setport if the first character of the port parameter is a
// digit, then the parameter is interpreted as a number
// Adding improved Error Handling in sockerr class
// sockinetaddr::setport if the first character of the port parameter is a
// digit, then the parameter is interpreted as a number
// 2002-07-28 Version 1.2 (C) Herbert Straub
// Eliminating sorry_about_global_temp inititialisation. This don't work
// in combination with NewsCache. My idea is: initializing the classes with (0)
@@ -40,36 +40,36 @@ typedef int socklen_t;
#if defined(__CYGWIN__) || !defined(WIN32)
extern "C" {
# include <netdb.h>
# include <sys/time.h>
# include <sys/socket.h>
# include <stdlib.h>
# include <unistd.h>
# include <errno.h>
# include <netinet/tcp.h>
# include <netdb.h>
# include <sys/time.h>
# include <sys/socket.h>
# include <stdlib.h>
# include <unistd.h>
# include <errno.h>
# include <netinet/tcp.h>
# include <netinet/in.h>
# include <netinet/in.h>
# include <arpa/inet.h>
}
#else
# define socklen_t int
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define EADDRINUSE WSAEADDRINUSE
# define ENOPROTOOPT WSAENOPROTOOPT
# define socklen_t int
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define EADDRINUSE WSAEADDRINUSE
# define ENOPROTOOPT WSAENOPROTOOPT
#endif // !WIN32
#ifndef INADDR_NONE
#define INADDR_NONE ((in_addr_t) 0xffffffff)
#endif
void herror(const char*);
void herror(const char*);
sockinetaddr::sockinetaddr ()
{
sin_family = sockinetbuf::af_inet;
sin_family = sockinetbuf::af_inet;
sin_addr.s_addr = htonl(INADDR_ANY);
sin_port = 0;
sin_port = 0;
}
sockinetaddr::sockinetaddr(unsigned long addr, int port_no)
@@ -77,7 +77,7 @@ sockinetaddr::sockinetaddr(unsigned long addr, int port_no)
{
sin_family = sockinetbuf::af_inet;
sin_addr.s_addr = htonl(addr);
sin_port = htons(port_no);
sin_port = htons(port_no);
}
sockinetaddr::sockinetaddr(unsigned long addr, const char* sn, const char* pn)
@@ -105,18 +105,18 @@ sockinetaddr::sockinetaddr (const sockinetaddr& sina): sockAddr()
{
sin_family = sockinetbuf::af_inet;
sin_addr.s_addr = sina.sin_addr.s_addr;
sin_port = sina.sin_port;
sin_port = sina.sin_port;
}
void sockinetaddr::setport(const char* sn, const char* pn)
{
if (isdigit (*sn)) {
sin_port = htons(atoi(sn));
} else {
servent* sp = getservbyname(sn, pn);
if (sp == 0) throw sockerr (EADDRNOTAVAIL, "sockinetaddr::setport");
sin_port = sp->s_port;
}
if (isdigit (*sn)) {
sin_port = htons(atoi(sn));
} else {
servent* sp = getservbyname(sn, pn);
if (sp == 0) throw sockerr (EADDRNOTAVAIL, "sockinetaddr::setport");
sin_port = sp->s_port;
}
}
int sockinetaddr::getport () const
@@ -140,12 +140,12 @@ const char* sockinetaddr::gethostname () const
if (sin_addr.s_addr == htonl(INADDR_ANY)) {
static char hostname[64];
if (::gethostname(hostname, 63) == -1) return "";
return hostname;
return hostname;
}
hostent* hp = gethostbyaddr((const char*) &sin_addr,
sizeof(sin_addr),
family());
sizeof(sin_addr),
family());
if (hp == 0) return "";
if (hp->h_name) return hp->h_name;
return "";
@@ -259,16 +259,16 @@ void sockinetbuf::bind (const char* host_name, int port_no)
}
void sockinetbuf::bind (unsigned long addr,
const char* service_name,
const char* protocol_name)
const char* service_name,
const char* protocol_name)
{
sockinetaddr sa (addr, service_name, protocol_name);
bind (sa);
}
void sockinetbuf::bind (const char* host_name,
const char* service_name,
const char* protocol_name)
const char* service_name,
const char* protocol_name)
{
sockinetaddr sa (host_name, service_name, protocol_name);
bind (sa);
@@ -293,16 +293,16 @@ void sockinetbuf::connect (const char* host_name, int port_no)
}
void sockinetbuf::connect (unsigned long addr,
const char* service_name,
const char* protocol_name)
const char* service_name,
const char* protocol_name)
{
sockinetaddr sa (addr, service_name, protocol_name);
connect (sa);
}
void sockinetbuf::connect (const char* host_name,
const char* service_name,
const char* protocol_name)
const char* service_name,
const char* protocol_name)
{
sockinetaddr sa (host_name, service_name, protocol_name);
connect (sa);
@@ -319,14 +319,14 @@ sockbuf::sockdesc sockinetbuf::accept (sockAddr& sa)
}
sockbuf::sockdesc sockinetbuf::accept (unsigned long addr,
int port_no)
int port_no)
{
sockinetaddr sa (addr, port_no);
return accept (sa);
}
sockbuf::sockdesc sockinetbuf::accept (const char* host_name,
int port_no)
int port_no)
{
sockinetaddr sa (host_name, port_no);
return accept (sa);
@@ -357,28 +357,28 @@ bool sockinetbuf::tcpnodelay (bool set) const
isockinet::isockinet (const sockbuf::sockdesc& sd)
: ios(0), isockstream(0)
{
sockinetbuf *t = new sockinetbuf (sd);
sockinetbuf *t = new sockinetbuf (sd);
ios::init (t);
isockstream::init (t);
ios::init (t);
isockstream::init (t);
}
isockinet::isockinet (sockbuf::type ty, int proto)
: ios (0), isockstream(0)
{
sockinetbuf *t = new sockinetbuf (ty, proto);
sockinetbuf *t = new sockinetbuf (ty, proto);
ios::init (t);
isockstream::init (t);
ios::init (t);
isockstream::init (t);
}
isockinet::isockinet (const sockinetbuf& sb)
: ios (0), isockstream(0)
{
sockinetbuf *t = new sockinetbuf (sb);
sockinetbuf *t = new sockinetbuf (sb);
ios::init (t);
isockstream::init (t);
ios::init (t);
isockstream::init (t);
}
isockinet::~isockinet ()
@@ -389,28 +389,28 @@ isockinet::~isockinet ()
osockinet::osockinet (const sockbuf::sockdesc& sd)
: ios (0), osockstream(0)
{
sockinetbuf *t = new sockinetbuf (sd);
sockinetbuf *t = new sockinetbuf (sd);
ios::init (t);
osockstream::init (t);
ios::init (t);
osockstream::init (t);
}
osockinet::osockinet (sockbuf::type ty, int proto)
: ios (0), osockstream(0)
{
sockinetbuf *t = new sockinetbuf (ty, proto);
sockinetbuf *t = new sockinetbuf (ty, proto);
ios::init (t);
osockstream::init (t);
ios::init (t);
osockstream::init (t);
}
osockinet::osockinet (const sockinetbuf& sb)
: ios (0), osockstream(0)
{
sockinetbuf *t = new sockinetbuf (sb);
sockinetbuf *t = new sockinetbuf (sb);
ios::init (t);
osockstream::init (t);
ios::init (t);
osockstream::init (t);
}
osockinet::~osockinet ()
@@ -421,28 +421,28 @@ osockinet::~osockinet ()
iosockinet::iosockinet (const sockbuf::sockdesc& sd)
: ios (0), iosockstream(0)
{
sockinetbuf *t = new sockinetbuf(sd);
sockinetbuf *t = new sockinetbuf(sd);
ios::init (t);
iosockstream::init (t);
ios::init (t);
iosockstream::init (t);
}
iosockinet::iosockinet (sockbuf::type ty, int proto)
: ios (0), iosockstream (0)
: ios (0), iosockstream (0)
{
sockinetbuf *t = new sockinetbuf (ty, proto);
sockinetbuf *t = new sockinetbuf (ty, proto);
ios::init (t);
iosockstream::init (t);
ios::init (t);
iosockstream::init (t);
}
iosockinet::iosockinet (const sockinetbuf& sb)
: ios (0), iosockstream(0)
{
sockinetbuf *t = new sockinetbuf (sb);
sockinetbuf *t = new sockinetbuf (sb);
ios::init (t);
iosockstream::init (t);
ios::init (t);
iosockstream::init (t);
}
iosockinet::~iosockinet ()

View File

@@ -57,7 +57,7 @@
// epptr() == pbase().
//
// Version: 1.2 2002-07-25 Herbert Straub
// Improved Error Handling - extending the sockerr class by cOperation
// Improved Error Handling - extending the sockerr class by cOperation
#include "sockstream.h"
@@ -70,57 +70,57 @@ typedef int socklen_t;
#if defined(__CYGWIN__) || !defined(WIN32)
extern "C" {
# include <sys/time.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# include <unistd.h>
# include <errno.h>
# include <sys/time.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# include <unistd.h>
# include <errno.h>
}
#else
# if (_MSC_VER >= 1400)
# include <errno.h>
# endif
# define EWOULDBLOCK WSAEWOULDBLOCK
# define EINPROGRESS WSAEINPROGRESS
# define EALREADY WSAEALREADY
# define ENOTSOCK WSAENOTSOCK
# define EDESTADDRREQ WSAEDESTADDRREQ
# define EMSGSIZE WSAEMSGSIZE
# define EPROTOTYPE WSAEPROTOTYPE
# define ENOPROTOOPT WSAENOPROTOOPT
# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
# define EOPNOTSUPP WSAEOPNOTSUPP
# define EPFNOSUPPORT WSAEPFNOSUPPORT
# define EAFNOSUPPORT WSAEAFNOSUPPORT
# define EADDRINUSE WSAEADDRINUSE
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define ENETDOWN WSAENETDOWN
# define ENETUNREACH WSAENETUNREACH
# define ENETRESET WSAENETRESET
# define ECONNABORTED WSAECONNABORTED
# define ECONNRESET WSAECONNRESET
# define ENOBUFS WSAENOBUFS
# define EISCONN WSAEISCONN
# define ENOTCONN WSAENOTCONN
# define ESHUTDOWN WSAESHUTDOWN
# define ETOOMANYREFS WSAETOOMANYREFS
# define ETIMEDOUT WSAETIMEDOUT
# define ECONNREFUSED WSAECONNREFUSED
# define ELOOP WSAELOOP
# define EHOSTDOWN WSAEHOSTDOWN
# define EHOSTUNREACH WSAEHOSTUNREACH
# define EPROCLIM WSAEPROCLIM
# define EUSERS WSAEUSERS
# define EDQUOT WSAEDQUOT
# define EISCONN WSAEISCONN
# define ENOTCONN WSAENOTCONN
# define ECONNRESET WSAECONNRESET
# define ECONNREFUSED WSAECONNREFUSED
# define ETIMEDOUT WSAETIMEDOUT
# define EADDRINUSE WSAEADDRINUSE
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define EWOULDBLOCK WSAEWOULDBLOCK
# define EWOULDBLOCK WSAEWOULDBLOCK
# define EINPROGRESS WSAEINPROGRESS
# define EALREADY WSAEALREADY
# define ENOTSOCK WSAENOTSOCK
# define EDESTADDRREQ WSAEDESTADDRREQ
# define EMSGSIZE WSAEMSGSIZE
# define EPROTOTYPE WSAEPROTOTYPE
# define ENOPROTOOPT WSAENOPROTOOPT
# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
# define EOPNOTSUPP WSAEOPNOTSUPP
# define EPFNOSUPPORT WSAEPFNOSUPPORT
# define EAFNOSUPPORT WSAEAFNOSUPPORT
# define EADDRINUSE WSAEADDRINUSE
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define ENETDOWN WSAENETDOWN
# define ENETUNREACH WSAENETUNREACH
# define ENETRESET WSAENETRESET
# define ECONNABORTED WSAECONNABORTED
# define ECONNRESET WSAECONNRESET
# define ENOBUFS WSAENOBUFS
# define EISCONN WSAEISCONN
# define ENOTCONN WSAENOTCONN
# define ESHUTDOWN WSAESHUTDOWN
# define ETOOMANYREFS WSAETOOMANYREFS
# define ETIMEDOUT WSAETIMEDOUT
# define ECONNREFUSED WSAECONNREFUSED
# define ELOOP WSAELOOP
# define EHOSTDOWN WSAEHOSTDOWN
# define EHOSTUNREACH WSAEHOSTUNREACH
# define EPROCLIM WSAEPROCLIM
# define EUSERS WSAEUSERS
# define EDQUOT WSAEDQUOT
# define EISCONN WSAEISCONN
# define ENOTCONN WSAENOTCONN
# define ECONNRESET WSAECONNRESET
# define ECONNREFUSED WSAECONNREFUSED
# define ETIMEDOUT WSAETIMEDOUT
# define EADDRINUSE WSAEADDRINUSE
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define EWOULDBLOCK WSAEWOULDBLOCK
#endif // !WIN32
@@ -145,7 +145,7 @@ const char* sockerr::errstr () const
#if defined(__CYGWIN__) || !defined(WIN32)
return strerror(err);
#else
return 0; // TODO
return 0; // TODO
#endif
}
@@ -203,9 +203,9 @@ bool sockerr::op () const
case EHOSTDOWN:
case EHOSTUNREACH:
case ENOTEMPTY:
# if !defined(__linux__) && !defined(__sun) && !defined(__hpux)// LN
# if !defined(__linux__) && !defined(__sun) && !defined(__hpux)// LN
case EPROCLIM:
# endif
# endif
case EUSERS:
case EDQUOT:
return true;
@@ -223,7 +223,7 @@ bool sockerr::conn () const
case ECONNRESET:
case ECONNREFUSED:
case ETIMEDOUT:
case EPIPE:
case EPIPE:
return true;
}
return false;
@@ -266,7 +266,7 @@ sockbuf::sockbuf (const sockbuf::sockdesc& sd)
setp (pbuf, pbuf + BUFSIZ);
rep->gend = gbuf + BUFSIZ;
rep->pend = pbuf + BUFSIZ;
}
}
sockbuf::sockbuf (int domain, sockbuf::type st, int proto)
: rep (0)
@@ -282,7 +282,7 @@ sockbuf::sockbuf (int domain, sockbuf::type st, int proto)
#if defined(__CYGWIN__) || !defined(WIN32)
throw sockerr (errno, "sockbuf::sockbuf");
#else
throw sockerr(WSAGetLastError(), "sockbuf::sockbuf");
throw sockerr(WSAGetLastError(), "sockbuf::sockbuf");
#endif
rep = new sockbuf::sockcnt (soc);
@@ -330,14 +330,14 @@ sockbuf::~sockbuf ()
#if defined(__CYGWIN__) || !defined(WIN32)
int c = close (rep->sock);
#else
int c = closesocket(rep->sock);
int c = closesocket(rep->sock);
#endif
delete rep;
if (c == SOCKET_ERROR)
#if defined(__CYGWIN__) || !defined(WIN32)
throw sockerr (errno, "sockbuf::~sockbuf", sockname.c_str());
throw sockerr (errno, "sockbuf::~sockbuf", sockname.c_str());
#else
throw sockerr(WSAGetLastError(), "sockbuf::~sockbuf", sockname.c_str());
throw sockerr(WSAGetLastError(), "sockbuf::~sockbuf", sockname.c_str());
#endif
}
}
@@ -346,52 +346,54 @@ bool sockbuf::is_open () const
// if socket is still connected to the peer, return true
// else return false
{
return false;
return false;
}
int sockbuf::sync ()
// we never return -1 because we throw sockerr
// exception in the event of an error.
{
if (pptr () && pbase () < pptr () && pptr () <= epptr ()) {
// we have some data to flush
try {
write (pbase (), pptr () - pbase ());
}
catch (int wlen) {
// write was not completely successful
stringstream sb;
string err ("sockbuf::sync");
err += "(" + sockname + ")";
if (wlen) {
// reposition unwritten chars
char* pto = pbase ();
char* pfrom = pbase () + wlen;
int len = pptr () - pbase () - wlen;
while (pfrom < pptr ()) *pto++ = *pfrom++;
setp (pbase (), (char_type*) rep->pend);
pbump (len);
sb << " wlen=(" << wlen << ")";
err += sb.rdbuf()->str();
}
throw sockerr (errno, err.c_str ());
if (pptr () && pbase () < pptr () && pptr () <= epptr ())
{
// we have some data to flush
try {
write (pbase (), pptr () - pbase ());
}
catch (int wlen)
{
// write was not completely successful
stringstream sb;
string err ("sockbuf::sync");
err += "(" + sockname + ")";
if (wlen) {
// reposition unwritten chars
char* pto = pbase ();
char* pfrom = pbase () + wlen;
int len = pptr () - pbase () - wlen;
while (pfrom < pptr ()) *pto++ = *pfrom++;
setp (pbase (), (char_type*) rep->pend);
pbump (len);
sb << " wlen=(" << wlen << ")";
err += sb.rdbuf()->str();
}
throw sockerr (errno, err.c_str ());
}
setp (pbase (), (char_type*) rep->pend);
}
setp (pbase (), (char_type*) rep->pend);
}
// we cannot restore input data back to the socket stream
// thus we do not do anything on the input stream
// we cannot restore input data back to the socket stream
// thus we do not do anything on the input stream
return 0;
return 0;
}
int sockbuf::showmanyc () const
// return the number of chars in the input sequence
{
if (gptr () && gptr () < egptr ())
return egptr () - gptr ();
return 0;
if (gptr () && gptr () < egptr ())
return egptr () - gptr ();
return 0;
}
sockbuf::int_type sockbuf::underflow ()
@@ -576,8 +578,8 @@ int sockbuf::write(const void* buf, int len)
int wlen=0;
while(len>0) {
//int wval = ::write (rep->sock, (char*) buf, len);
int wval = ::send (rep->sock, (char*) buf, len, 0);
//int wval = ::write (rep->sock, (char*) buf, len);
int wval = ::send (rep->sock, (char*) buf, len, 0);
if (wval == -1) throw wlen;
len -= wval;
wlen += wval;
@@ -594,7 +596,7 @@ int sockbuf::send (const void* buf, int len, int msgf)
int wlen=0;
while(len>0) {
int wval = ::send (rep->sock, (char*) buf, len, msgf);
int wval = ::send (rep->sock, (char*) buf, len, msgf);
if (wval == -1) throw wlen;
len -= wval;
wlen += wval;
@@ -611,8 +613,8 @@ int sockbuf::sendto (sockAddr& sa, const void* buf, int len, int msgf)
int wlen=0;
while(len>0) {
int wval = ::sendto (rep->sock, (char*) buf, len, msgf,
sa.addr (), sa.size());
int wval = ::sendto (rep->sock, (char*) buf, len, msgf,
sa.addr (), sa.size());
if (wval == -1) throw wlen;
len -= wval;
wlen += wval;
@@ -620,7 +622,7 @@ int sockbuf::sendto (sockAddr& sa, const void* buf, int len, int msgf)
return wlen;
}
#if !defined(__linux__) && !defined(WIN32)
#if !defined(__linux__) && !defined(WIN32)
// does not have sendmsg or recvmsg
int sockbuf::recvmsg (msghdr* msg, int msgf)
@@ -908,11 +910,11 @@ bool sockbuf::atmark () const
// out of band data
{
#if !defined(WIN32) || defined(__CYGWIN__)
int arg;
int arg;
if (::ioctl (rep->sock, SIOCATMARK, &arg) == -1)
throw sockerr (errno, "sockbuf::atmark", sockname.c_str());
#else
unsigned long arg = 0;
unsigned long arg = 0;
if (::ioctlsocket(rep->sock, SIOCATMARK, &arg) == SOCKET_ERROR)
throw sockerr (WSAGetLastError(), "sockbuf::atmark", sockname.c_str());
#endif // !WIN32
@@ -961,12 +963,12 @@ long sockbuf::nread () const
// return how many chars are available for reading in the recvbuf of
// the socket.
{
long arg;
long arg;
#if defined(__CYGWIN__) || !defined(WIN32)
if (::ioctl (rep->sock, FIONREAD, &arg) == -1)
throw sockerr (errno, "sockbuf::nread", sockname.c_str());
#else
if (::ioctlsocket (rep->sock, FIONREAD, (unsigned long *) &arg) == SOCKET_ERROR)
if (::ioctlsocket (rep->sock, FIONREAD, (unsigned long *) &arg) == SOCKET_ERROR)
throw sockerr (WSAGetLastError(), "sockbuf::nread", sockname.c_str());
#endif // !WIN32
return arg;

View File

@@ -82,41 +82,41 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
if (fr.matchSequence("autoUpdateEyeMovementTolerance %f"))
{
float f;
fr[1].getFloat(f);
transform.setAutoUpdateEyeMovementTolerance(f);
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoUpdateEyeMovementTolerance %f"))
{
float f;
fr[1].getFloat(f);
transform.setAutoUpdateEyeMovementTolerance(f);
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoRotateToScreen %w"))
{
std::string w(fr[1].getStr());
transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION);
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoRotateToScreen %w"))
{
std::string w(fr[1].getStr());
transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION);
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoRotateMode %w"))
{
std::string w(fr[1].getStr());
if (fr.matchSequence("autoRotateMode %w"))
{
std::string w(fr[1].getStr());
if (w=="ROTATE_TO_SCREEN") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
else if (w=="ROTATE_TO_CAMERA") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_CAMERA);
else if (w=="NO_ROTATION") transform.setAutoRotateMode(osg::AutoTransform::NO_ROTATION);
fr += 2;
iteratorAdvanced = true;
}
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoScaleToScreen %w"))
{
std::string w(fr[1].getStr());
transform.setAutoScaleToScreen(w == "TRUE");
fr += 2;
iteratorAdvanced = true;
}
if (fr.matchSequence("autoScaleToScreen %w"))
{
std::string w(fr[1].getStr());
transform.setAutoScaleToScreen(w == "TRUE");
fr += 2;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include <osg/ClipPlane>

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/ConvexPlanarOccluder"

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include <osg/Fog>

View File

@@ -52,12 +52,12 @@ bool FragmentProgram_readLocalData(Object& obj, Input& fr)
{
int index;
fr[1].getInt(index);
fr += 2;
osg::Matrix matrix;
if (readMatrix(matrix,fr))
{
fragmentProgram.setMatrix(index, matrix);
}
fr += 2;
osg::Matrix matrix;
if (readMatrix(matrix,fr))
{
fragmentProgram.setMatrix(index, matrix);
}
iteratorAdvanced = true;
}
@@ -116,7 +116,7 @@ bool FragmentProgram_writeLocalData(const Object& obj,Output& fw)
for(mi=mpl.begin(); mi!=mpl.end(); mi++)
{
fw.indent() << "Matrix " << (*mi).first << " ";
writeMatrix((*mi).second,fw);
writeMatrix((*mi).second,fw);
}
std::vector<std::string> lines;

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/Light"

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include <osg/LineWidth>

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/Material"

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/Point"

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/PointSprite"

View File

@@ -95,8 +95,10 @@ class OSGReaderWriter : public ReaderWriter
{
std::istringstream iss(options->getOptionString());
std::string opt;
while (iss >> opt) {
if(opt=="PRECISION" || opt=="precision") {
while (iss >> opt)
{
if(opt=="PRECISION" || opt=="precision")
{
int prec;
iss >> prec;
fout.precision(prec);
@@ -132,8 +134,8 @@ class OSGReaderWriter : public ReaderWriter
Output foutput;
foutput.setOptions(options);
std::ios &fios = foutput;
fios.rdbuf(fout.rdbuf());
std::ios &fios = foutput;
fios.rdbuf(fout.rdbuf());
if (fout)
{
@@ -170,8 +172,8 @@ class OSGReaderWriter : public ReaderWriter
Output foutput;
foutput.setOptions(options);
std::ios &fios = foutput;
fios.rdbuf(fout.rdbuf());
std::ios &fios = foutput;
fios.rdbuf(fout.rdbuf());
if (fout)
{

View File

@@ -33,23 +33,25 @@ bool Shader_readLocalData(Object& obj, Input& fr)
if (fr.matchSequence("type %w"))
{
shader.setType( Shader::getTypeId(fr[1].getStr()) );
fr+=2;
iteratorAdvanced = true;
shader.setType( Shader::getTypeId(fr[1].getStr()) );
fr+=2;
iteratorAdvanced = true;
}
if (fr.matchSequence("code {")) {
std::string code;
fr += 2;
iteratorAdvanced = true;
int entry = fr[0].getNoNestedBrackets();
while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) {
if (fr[0].getStr()) {
code.append(std::string(fr[0].getStr()));
code += '\n' ;
}
++fr;
}
if (fr.matchSequence("code {"))
{
std::string code;
fr += 2;
iteratorAdvanced = true;
int entry = fr[0].getNoNestedBrackets();
while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry)
{
if (fr[0].getStr()) {
code.append(std::string(fr[0].getStr()));
code += '\n' ;
}
++fr;
}
shader.setShaderSource(code.c_str());
}
@@ -68,7 +70,7 @@ bool Shader_writeLocalData(const Object& obj,Output& fw)
std::istringstream iss(shader.getShaderSource());
std::string line;
while (std::getline(iss, line)) {
lines.push_back(line);
lines.push_back(line);
}
fw.indent() << "code {\n";
@@ -76,7 +78,7 @@ bool Shader_writeLocalData(const Object& obj,Output& fw)
std::vector<std::string>::const_iterator j;
for (j=lines.begin(); j!=lines.end(); ++j) {
fw.indent() << fw.wrapString(*j) << "\n";
fw.indent() << fw.wrapString(*j) << "\n";
}
fw.moveOut();

View File

@@ -583,7 +583,7 @@ bool CompositeShape_readLocalData(Object& obj, Input& fr)
}
}
while((readObject=fr.readObjectOfType(type_wrapper<osg::Shape>())).valid())
while((readObject=fr.readObjectOfType(type_wrapper<osg::Shape>())).valid())
{
osg::Shape* shape = static_cast<osg::Shape*>(readObject.get());
composite.addChild(shape);

View File

@@ -1,5 +1,5 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#pragma warning( disable : 4786 )
#endif
#include "osg/TexGen"

View File

@@ -52,48 +52,51 @@ bool VertexProgram_readLocalData(Object& obj, Input& fr)
{
int index;
fr[1].getInt(index);
fr += 2;
osg::Matrix matrix;
if (readMatrix(matrix,fr))
{
vertexProgram.setMatrix(index, matrix);
}
fr += 2;
osg::Matrix matrix;
if (readMatrix(matrix,fr))
{
vertexProgram.setMatrix(index, matrix);
}
iteratorAdvanced = true;
}
if (fr.matchSequence("code {")) {
std::string code;
fr += 2;
iteratorAdvanced = true;
int entry = fr[0].getNoNestedBrackets();
while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) {
if (fr[0].getStr()) {
code.append(std::string(fr[0].getStr()));
code += '\n'
;
}
++fr;
}
std::string code;
fr += 2;
iteratorAdvanced = true;
int entry = fr[0].getNoNestedBrackets();
while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry)
{
if (fr[0].getStr())
{
code.append(std::string(fr[0].getStr()));
code += '\n';
}
++fr;
}
vertexProgram.setVertexProgram(code);
}
if( fr.matchSequence("file %s")) {
std::string filename = fr[1].getStr();
fr+=2;
iteratorAdvanced = true;
ifstream vfstream( filename.c_str() );
if( vfstream ) {
ostringstream vstream;
char ch;
/* xxx better way to transfer a ifstream to a string?? */
while( vfstream.get(ch)) vstream.put(ch);
vertexProgram.setVertexProgram( vstream.str() );
}
if( fr.matchSequence("file %s"))
{
std::string filename = fr[1].getStr();
fr+=2;
iteratorAdvanced = true;
ifstream vfstream( filename.c_str() );
if( vfstream )
{
ostringstream vstream;
char ch;
/* xxx better way to transfer a ifstream to a string?? */
while( vfstream.get(ch)) vstream.put(ch);
vertexProgram.setVertexProgram( vstream.str() );
}
}
return iteratorAdvanced;
@@ -116,7 +119,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw)
for(mi=mpl.begin(); mi!=mpl.end(); mi++)
{
fw.indent() << "Matrix " << (*mi).first << " ";
writeMatrix((*mi).second,fw);
writeMatrix((*mi).second,fw);
}
@@ -124,7 +127,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw)
std::istringstream iss(vertexProgram.getVertexProgram());
std::string line;
while (std::getline(iss, line)) {
lines.push_back(line);
lines.push_back(line);
}
fw.indent() << "code {\n";
@@ -132,7 +135,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw)
std::vector<std::string>::const_iterator j;
for (j=lines.begin(); j!=lines.end(); ++j) {
fw.indent() << "\"" << *j << "\"\n";
fw.indent() << "\"" << *j << "\"\n";
}
fw.moveOut();

View File

@@ -9,51 +9,51 @@ bool AnisotropicLighting_writeLocalData(const osg::Object &obj, osgDB::Output &f
osgDB::RegisterDotOsgWrapperProxy AnisotropicLighting_Proxy
(
new osgFX::AnisotropicLighting,
"osgFX::AnisotropicLighting",
"Object Node Group osgFX::Effect osgFX::AnisotropicLighting",
new osgFX::AnisotropicLighting,
"osgFX::AnisotropicLighting",
"Object Node Group osgFX::Effect osgFX::AnisotropicLighting",
AnisotropicLighting_readLocalData,
AnisotropicLighting_writeLocalData
);
bool AnisotropicLighting_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgFX::AnisotropicLighting &myobj = static_cast<osgFX::AnisotropicLighting &>(obj);
bool itAdvanced = false;
osgFX::AnisotropicLighting &myobj = static_cast<osgFX::AnisotropicLighting &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) {
osg::Image *lmap = fr.readImage(fr[1].getStr());
if (lmap) {
myobj.setLightingMap(lmap);
}
fr += 2;
itAdvanced = true;
}
if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) {
osg::Image *lmap = fr.readImage(fr[1].getStr());
if (lmap) {
myobj.setLightingMap(lmap);
}
fr += 2;
itAdvanced = true;
}
return itAdvanced;
return itAdvanced;
}
bool AnisotropicLighting_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgFX::AnisotropicLighting &myobj = static_cast<const osgFX::AnisotropicLighting &>(obj);
const osgFX::AnisotropicLighting &myobj = static_cast<const osgFX::AnisotropicLighting &>(obj);
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
const osg::Image *lmap = myobj.getLightingMap();
if (lmap) {
if (!lmap->getFileName().empty()) {
fw.indent() << "lightingMapFileName \"" << lmap->getFileName() << "\"\n";
}
}
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
const osg::Image *lmap = myobj.getLightingMap();
if (lmap) {
if (!lmap->getFileName().empty()) {
fw.indent() << "lightingMapFileName \"" << lmap->getFileName() << "\"\n";
}
}
return true;
}

View File

@@ -9,75 +9,75 @@ bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy BumpMapping_Proxy
(
new osgFX::BumpMapping,
"osgFX::BumpMapping",
"Object Node Group osgFX::Effect osgFX::BumpMapping",
new osgFX::BumpMapping,
"osgFX::BumpMapping",
"Object Node Group osgFX::Effect osgFX::BumpMapping",
BumpMapping_readLocalData,
BumpMapping_writeLocalData
);
bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgFX::BumpMapping &myobj = static_cast<osgFX::BumpMapping &>(obj);
bool itAdvanced = false;
osgFX::BumpMapping &myobj = static_cast<osgFX::BumpMapping &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("diffuseUnit")) {
int n;
if (fr[1].getInt(n)) {
myobj.setDiffuseTextureUnit(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("diffuseUnit")) {
int n;
if (fr[1].getInt(n)) {
myobj.setDiffuseTextureUnit(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("normalMapUnit")) {
int n;
if (fr[1].getInt(n)) {
myobj.setNormalMapTextureUnit(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("normalMapUnit")) {
int n;
if (fr[1].getInt(n)) {
myobj.setNormalMapTextureUnit(n);
fr += 2;
itAdvanced = true;
}
}
osg::ref_ptr<osg::Texture2D> diffuse_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
if (diffuse_tex.valid()) {
myobj.setOverrideDiffuseTexture(diffuse_tex.get());
itAdvanced = true;
}
osg::ref_ptr<osg::Texture2D> diffuse_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
if (diffuse_tex.valid()) {
myobj.setOverrideDiffuseTexture(diffuse_tex.get());
itAdvanced = true;
}
osg::ref_ptr<osg::Texture2D> normal_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
if (normal_tex.valid()) {
myobj.setOverrideNormalMapTexture(normal_tex.get());
itAdvanced = true;
}
osg::ref_ptr<osg::Texture2D> normal_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
if (normal_tex.valid()) {
myobj.setOverrideNormalMapTexture(normal_tex.get());
itAdvanced = true;
}
return itAdvanced;
return itAdvanced;
}
bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgFX::BumpMapping &myobj = static_cast<const osgFX::BumpMapping &>(obj);
const osgFX::BumpMapping &myobj = static_cast<const osgFX::BumpMapping &>(obj);
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
fw.indent() << "diffuseUnit " << myobj.getDiffuseTextureUnit() << "\n";
fw.indent() << "normalMapUnit " << myobj.getNormalMapTextureUnit() << "\n";
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
fw.indent() << "diffuseUnit " << myobj.getDiffuseTextureUnit() << "\n";
fw.indent() << "normalMapUnit " << myobj.getNormalMapTextureUnit() << "\n";
if (myobj.getOverrideDiffuseTexture()) {
fw.writeObject(*myobj.getOverrideDiffuseTexture());
}
if (myobj.getOverrideDiffuseTexture()) {
fw.writeObject(*myobj.getOverrideDiffuseTexture());
}
if (myobj.getOverrideNormalMapTexture()) {
fw.writeObject(*myobj.getOverrideNormalMapTexture());
}
if (myobj.getOverrideNormalMapTexture()) {
fw.writeObject(*myobj.getOverrideNormalMapTexture());
}
return true;
}

View File

@@ -10,56 +10,56 @@ bool Cartoon_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Cartoon_Proxy
(
new osgFX::Cartoon,
new osgFX::Cartoon,
"osgFX::Cartoon",
"Object Node Group osgFX::Effect osgFX::Cartoon",
"Object Node Group osgFX::Effect osgFX::Cartoon",
Cartoon_readLocalData,
Cartoon_writeLocalData
);
bool Cartoon_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgFX::Cartoon &myobj = static_cast<osgFX::Cartoon &>(obj);
bool itAdvanced = false;
osgFX::Cartoon &myobj = static_cast<osgFX::Cartoon &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("lightNumber")) {
int n;
if (fr[1].getInt(n)) {
myobj.setLightNumber(n);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("outlineColor")) {
osg::Vec4 w;
if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) &&
fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) {
myobj.setOutlineColor(w);
fr += 5;
itAdvanced = true;
}
}
if (fr[0].matchWord("outlineColor")) {
osg::Vec4 w;
if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) &&
fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) {
myobj.setOutlineColor(w);
fr += 5;
itAdvanced = true;
}
}
if (fr[0].matchWord("outlineLineWidth")) {
float f;
if (fr[1].getFloat(f)) {
myobj.setOutlineLineWidth(f);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("outlineLineWidth")) {
float f;
if (fr[1].getFloat(f)) {
myobj.setOutlineLineWidth(f);
fr += 2;
itAdvanced = true;
}
}
return itAdvanced;
return itAdvanced;
}
bool Cartoon_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgFX::Cartoon &myobj = static_cast<const osgFX::Cartoon &>(obj);
const osgFX::Cartoon &myobj = static_cast<const osgFX::Cartoon &>(obj);
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
fw.indent() << "outlineColor " << myobj.getOutlineColor() << "\n";
fw.indent() << "outlineLineWidth " << myobj.getOutlineLineWidth() << "\n";
fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n";
fw.indent() << "outlineColor " << myobj.getOutlineColor() << "\n";
fw.indent() << "outlineLineWidth " << myobj.getOutlineLineWidth() << "\n";
return true;
}

View File

@@ -9,57 +9,57 @@ bool Effect_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Effect_Proxy
(
0,
0,
"osgFX::Effect",
"Object Node Group osgFX::Effect",
"Object Node Group osgFX::Effect",
Effect_readLocalData,
Effect_writeLocalData
);
bool Effect_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgFX::Effect &myobj = static_cast<osgFX::Effect &>(obj);
bool itAdvanced = false;
osgFX::Effect &myobj = static_cast<osgFX::Effect &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("enabled")) {
if (fr[1].matchWord("FALSE")) {
myobj.setEnabled(false);
} else {
myobj.setEnabled(true);
}
fr += 2;
itAdvanced = true;
}
if (fr[0].matchWord("enabled")) {
if (fr[1].matchWord("FALSE")) {
myobj.setEnabled(false);
} else {
myobj.setEnabled(true);
}
fr += 2;
itAdvanced = true;
}
if (fr[0].matchWord("selectedTechnique")) {
if (fr[1].matchWord("AUTO_DETECT")) {
myobj.selectTechnique(osgFX::Effect::AUTO_DETECT);
fr += 2;
itAdvanced = true;
} else {
int i;
if (fr[1].getInt(i)) {
myobj.selectTechnique(i);
fr += 2;
itAdvanced = true;
}
}
}
if (fr[0].matchWord("selectedTechnique")) {
if (fr[1].matchWord("AUTO_DETECT")) {
myobj.selectTechnique(osgFX::Effect::AUTO_DETECT);
fr += 2;
itAdvanced = true;
} else {
int i;
if (fr[1].getInt(i)) {
myobj.selectTechnique(i);
fr += 2;
itAdvanced = true;
}
}
}
return itAdvanced;
return itAdvanced;
}
bool Effect_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgFX::Effect &myobj = static_cast<const osgFX::Effect &>(obj);
const osgFX::Effect &myobj = static_cast<const osgFX::Effect &>(obj);
fw.indent() << "enabled " << (myobj.getEnabled() ? "TRUE" : "FALSE") << "\n";
fw.indent() << "selectedTechnique ";
if (myobj.getSelectedTechnique() == osgFX::Effect::AUTO_DETECT) {
fw << "AUTO_DETECT\n";
} else {
fw << myobj.getSelectedTechnique() << "\n";
}
fw.indent() << "enabled " << (myobj.getEnabled() ? "TRUE" : "FALSE") << "\n";
fw.indent() << "selectedTechnique ";
if (myobj.getSelectedTechnique() == osgFX::Effect::AUTO_DETECT) {
fw << "AUTO_DETECT\n";
} else {
fw << myobj.getSelectedTechnique() << "\n";
}
return true;
}

View File

@@ -10,46 +10,46 @@ bool Scribe_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Scribe_Proxy
(
new osgFX::Scribe,
new osgFX::Scribe,
"osgFX::Scribe",
"Object Node Group osgFX::Effect osgFX::Scribe",
"Object Node Group osgFX::Effect osgFX::Scribe",
Scribe_readLocalData,
Scribe_writeLocalData
);
bool Scribe_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgFX::Scribe &myobj = static_cast<osgFX::Scribe &>(obj);
bool itAdvanced = false;
osgFX::Scribe &myobj = static_cast<osgFX::Scribe &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("wireframeColor")) {
osg::Vec4 w;
if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) &&
fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) {
myobj.setWireframeColor(w);
fr += 5;
itAdvanced = true;
}
}
if (fr[0].matchWord("wireframeColor")) {
osg::Vec4 w;
if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) &&
fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) {
myobj.setWireframeColor(w);
fr += 5;
itAdvanced = true;
}
}
if (fr[0].matchWord("wireframeLineWidth")) {
float f;
if (fr[1].getFloat(f)) {
myobj.setWireframeLineWidth(f);
fr += 2;
itAdvanced = true;
}
}
if (fr[0].matchWord("wireframeLineWidth")) {
float f;
if (fr[1].getFloat(f)) {
myobj.setWireframeLineWidth(f);
fr += 2;
itAdvanced = true;
}
}
return itAdvanced;
return itAdvanced;
}
bool Scribe_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgFX::Scribe &myobj = static_cast<const osgFX::Scribe &>(obj);
const osgFX::Scribe &myobj = static_cast<const osgFX::Scribe &>(obj);
fw.indent() << "wireframeColor " << myobj.getWireframeColor() << "\n";
fw.indent() << "wireframeLineWidth " << myobj.getWireframeLineWidth() << "\n";
fw.indent() << "wireframeColor " << myobj.getWireframeColor() << "\n";
fw.indent() << "wireframeLineWidth " << myobj.getWireframeLineWidth() << "\n";
return true;
}

Some files were not shown because too many files have changed in this diff Show More