Fixed LWO2 ReaderWriter problem which was down to an the compiler reodering

the evaluation of a Vec3 paramter.
This commit is contained in:
Robert Osfield 2002-09-03 13:04:53 +00:00
parent 46585242a1
commit 0cb75d42e0
6 changed files with 67 additions and 49 deletions

View File

@ -7,14 +7,12 @@ using namespace osg;
/** /**
* ClearNode constructor. * ClearNode constructor.
*/ */
ClearNode::ClearNode() ClearNode::ClearNode():
_requiresClear(true),
_clearColor(0.0f,0.0f,0.0f,1.0f)
{ {
StateSet* stateset = osgNew StateSet; StateSet* stateset = osgNew StateSet;
stateset->setRenderBinDetails(-1,"RenderBin"); stateset->setRenderBinDetails(-1,"RenderBin");
setStateSet(stateset); setStateSet(stateset);
_requiresClear = true;
_clearColor.set(0.0f,0.0f,0.0f,1.0f);
} }

View File

@ -39,10 +39,12 @@
#include "Lwo2.h" #include "Lwo2.h"
#include "Lwo2Layer.h" #include "Lwo2Layer.h"
Lwo2::Lwo2() Lwo2::Lwo2():
_current_layer(0),
_geode(0),
_successfully_read(false)
{ {
_successfully_read = false; }
};
Lwo2::~Lwo2() Lwo2::~Lwo2()
{ {
@ -101,7 +103,7 @@ Lwo2::ReadFile( const string& filename )
notify(INFO) << "Detected LWO2 format" << endl; notify(INFO) << "Detected LWO2 format" << endl;
} }
_geode = new osg::Geode(); _geode = osgNew osg::Geode();
unsigned long read_bytes = 4; unsigned long read_bytes = 4;
unsigned long current_tag_name; unsigned long current_tag_name;
@ -205,7 +207,8 @@ Lwo2::_read_string(string& str)
{ {
char c; char c;
do { do {
str += c = _read_char(); c = _read_char();
str += c;
} while (c != 0); } while (c != 0);
// if length of string (including \0) is odd skip another byte // if length of string (including \0) is odd skip another byte
@ -252,7 +255,7 @@ Lwo2::_read_tag_strings(unsigned long size)
size -= name.length() + name.length() % 2; size -= name.length() + name.length() % 2;
_tags.push_back(name); _tags.push_back(name);
notify(DEBUG_INFO) << " name \t'" << name << "'" << endl; notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << endl;
} }
} }
@ -264,7 +267,7 @@ Lwo2::_read_layer(unsigned long size)
unsigned short number = _read_short(); unsigned short number = _read_short();
size -= 2; size -= 2;
Lwo2Layer* layer = new Lwo2Layer(); Lwo2Layer* layer = osgNew Lwo2Layer();
_layers[number] = layer; _layers[number] = layer;
_current_layer = layer; _current_layer = layer;
layer->_number = number; layer->_number = number;
@ -272,7 +275,10 @@ Lwo2::_read_layer(unsigned long size)
layer->_flags = _read_short(); layer->_flags = _read_short();
size -= 2; size -= 2;
layer->_pivot.set(_read_float(), _read_float(), _read_float()); float x = _read_float();
float y = _read_float();
float z = _read_float();
layer->_pivot.set(x, y, z);
size -= 4 * 3; size -= 4 * 3;
_read_string(layer->_name); _read_string(layer->_name);
@ -296,7 +302,10 @@ Lwo2::_read_points(unsigned long size)
while (count--) while (count--)
{ {
_current_layer->_points.push_back(Vec3(_read_float(), _read_float(), _read_float())); float x = _read_float();
float y = _read_float();
float z = _read_float();
_current_layer->_points.push_back(Vec3(x, y,z));
} }
} }
@ -319,7 +328,7 @@ Lwo2::_read_polygons(unsigned long size)
vertex_count = _read_short() & 0x03FF; vertex_count = _read_short() & 0x03FF;
size -= 2; size -= 2;
PointsList* points_list = new PointsList; PointsList* points_list = osgNew PointsList;
_current_layer->_polygons.push_back(points_list); _current_layer->_polygons.push_back(points_list);
while (vertex_count--) while (vertex_count--)
@ -356,7 +365,7 @@ Lwo2::_read_vertex_mapping(unsigned long size)
string name; string name;
_read_string(name); _read_string(name);
size -= name.length() + name.length() % 2; size -= name.length() + name.length() % 2;
notify(DEBUG_INFO) << " name \t'" << name << "'" << endl; notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << endl;
if (type == tag_TXUV && dimension == 2) if (type == tag_TXUV && dimension == 2)
{ {
@ -402,7 +411,7 @@ Lwo2::_read_polygons_mapping(unsigned long size)
string name; string name;
_read_string(name); _read_string(name);
size -= name.length() + name.length() % 2; size -= name.length() + name.length() % 2;
notify(DEBUG_INFO) << " name \t'" << name << "'" << endl; notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << endl;
if (type == tag_TXUV && dimension == 2) if (type == tag_TXUV && dimension == 2)
{ {
@ -502,7 +511,7 @@ Lwo2::_read_image_definition(unsigned long size)
_images[index] = name.c_str(); _images[index] = name.c_str();
notify(DEBUG_INFO) << " name \t'" << name << "'" << endl; notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << endl;
} }
} }
@ -511,18 +520,18 @@ Lwo2::_read_image_definition(unsigned long size)
void void
Lwo2::_read_surface(unsigned long size) Lwo2::_read_surface(unsigned long size)
{ {
Lwo2Surface* surface = new Lwo2Surface(); Lwo2Surface* surface = osgNew Lwo2Surface();
surface->image_index = -1; surface->image_index = -1;
surface->state_set = NULL; surface->state_set = NULL;
_read_string(surface->name); _read_string(surface->name);
size -= surface->name.length() + surface->name.length() % 2; size -= surface->name.length() + surface->name.length() % 2;
notify(DEBUG_INFO) << " name \t'" << surface->name << "'" << endl; notify(DEBUG_INFO) << " name \t'" << surface->name.c_str() << "'" << endl;
string source; string source;
_read_string(source); _read_string(source);
size -= source.length() + source.length() % 2; size -= source.length() + source.length() % 2;
notify(DEBUG_INFO) << " source \t'" << source << "'" << endl; notify(DEBUG_INFO) << " source \t'" << source.c_str() << "'" << endl;
unsigned long current_tag_name; unsigned long current_tag_name;
unsigned short current_tag_size; unsigned short current_tag_size;
@ -567,7 +576,7 @@ Lwo2::_read_surface(unsigned long size)
string ordinal; string ordinal;
_read_string(ordinal); _read_string(ordinal);
imap_size -= ordinal.length() + ordinal.length() % 2; imap_size -= ordinal.length() + ordinal.length() % 2;
notify(DEBUG_INFO) << " ordinal \t'" << ordinal << "'" << endl; notify(DEBUG_INFO) << " ordinal \t'" << ordinal.c_str() << "'" << endl;
while(imap_size > 0) while(imap_size > 0)
{ {
@ -591,7 +600,10 @@ Lwo2::_read_surface(unsigned long size)
} }
else if (current_tag_name == tag_COLR) else if (current_tag_name == tag_COLR)
{ {
surface->color = Vec3(_read_float(), _read_float(), _read_float()); float r = _read_float();
float g = _read_float();
float b = _read_float();
surface->color.set(r,g,b);
notify(DEBUG_INFO) << " color \t" << surface->color << endl; notify(DEBUG_INFO) << " color \t" << surface->color << endl;
current_tag_size -= 12; current_tag_size -= 12;
size -= 12; size -= 12;
@ -623,7 +635,7 @@ Lwo2::GenerateGroup( Group& group )
// create geometry from all layers // create geometry from all layers
for (IteratorLayers itr = _layers.begin(); itr != _layers.end(); itr++) for (IteratorLayers itr = _layers.begin(); itr != _layers.end(); itr++)
{ {
osg::Geode* geode = new osg::Geode(); osg::Geode* geode = osgNew osg::Geode();
(*itr).second->GenerateGeode(*geode, _tags.size()); (*itr).second->GenerateGeode(*geode, _tags.size());
// assign StateSet for each PTAG group // assign StateSet for each PTAG group
@ -645,7 +657,7 @@ Lwo2::_generate_statesets_from_surfaces()
for (IteratorSurfaces itr_surf = _surfaces.begin(); itr_surf != _surfaces.end(); itr_surf++) for (IteratorSurfaces itr_surf = _surfaces.begin(); itr_surf != _surfaces.end(); itr_surf++)
{ {
Lwo2Surface* surface = (*itr_surf).second; Lwo2Surface* surface = (*itr_surf).second;
StateSet* state_set = new osg::StateSet; StateSet* state_set = osgNew osg::StateSet;
// check if exist texture image for this surface // check if exist texture image for this surface
if (surface->image_index >= 0) if (surface->image_index >= 0)
@ -655,14 +667,14 @@ Lwo2::_generate_statesets_from_surfaces()
notify(DEBUG_INFO) << "\tresult - " << image << endl; notify(DEBUG_INFO) << "\tresult - " << image << endl;
if (image) if (image)
{ {
Texture2D* texture = new osg::Texture2D; Texture2D* texture = osgNew osg::Texture2D;
texture->setImage(image); texture->setImage(image);
state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON); state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON);
} }
} }
// set color // set color
Material* material = new Material(); Material* material = osgNew Material();
Vec4 color(surface->color[0], Vec4 color(surface->color[0],
surface->color[1], surface->color[1],
surface->color[2], surface->color[2],
@ -671,7 +683,7 @@ Lwo2::_generate_statesets_from_surfaces()
state_set->setAttribute(material); state_set->setAttribute(material);
// setup culling // setup culling
CullFace* cull = new CullFace(); CullFace* cull = osgNew CullFace();
cull->setMode(CullFace::BACK); cull->setMode(CullFace::BACK);
state_set->setAttribute(cull); state_set->setAttribute(cull);
state_set->setMode(GL_CULL_FACE, StateAttribute::ON); state_set->setMode(GL_CULL_FACE, StateAttribute::ON);

View File

@ -25,9 +25,11 @@
#include "Lwo2Layer.h" #include "Lwo2Layer.h"
Lwo2Layer::Lwo2Layer() Lwo2Layer::Lwo2Layer():
_number(0),
_flags(0),
_parent(0)
{ {
_parent = 0;
} }
Lwo2Layer::~Lwo2Layer() Lwo2Layer::~Lwo2Layer()
@ -37,7 +39,7 @@ Lwo2Layer::~Lwo2Layer()
IteratorPointsList pol_itr; IteratorPointsList pol_itr;
for (pol_itr = _polygons.begin(); pol_itr != _polygons.end(); pol_itr++) for (pol_itr = _polygons.begin(); pol_itr != _polygons.end(); pol_itr++)
{ {
delete (*pol_itr); osgDelete (*pol_itr);
} }
} }
@ -48,7 +50,7 @@ Lwo2Layer::notify(NotifySeverity severity)
osg::notify(severity) << "Current layer: " << _number << endl; osg::notify(severity) << "Current layer: " << _number << endl;
osg::notify(severity) << " flags \t" << _flags << endl; osg::notify(severity) << " flags \t" << _flags << endl;
osg::notify(severity) << " pivot \t" << _pivot << endl; osg::notify(severity) << " pivot \t" << _pivot << endl;
osg::notify(severity) << " name: \t'" << _name << "'" << endl; osg::notify(severity) << " name: \t'" << _name.c_str() << "'" << endl;
osg::notify(severity) << " parent:\t" << _parent << endl; osg::notify(severity) << " parent:\t" << _parent << endl;
// points // points
@ -108,7 +110,7 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count )
// variables for VMAD data processing // variables for VMAD data processing
pair<multimap< short, Lwo2PolygonMapping >::iterator, pair<multimap< short, Lwo2PolygonMapping >::iterator,
multimap< short, Lwo2PolygonMapping >::iterator> range; multimap< short, Lwo2PolygonMapping >::iterator> range;
multimap< short, Lwo2PolygonMapping >::iterator itr; multimap< short, Lwo2PolygonMapping >::iterator itr;
// all polygons // all polygons
@ -155,7 +157,7 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count )
(*texcoords).push_back(uv); (*texcoords).push_back(uv);
} }
} }
geometry->addPrimitive(new DrawArrays(Primitive::POLYGON, geometry->addPrimitive(osgNew DrawArrays(Primitive::POLYGON,
(*coords).size() - (*pol_itr)->size(), (*coords).size() - (*pol_itr)->size(),
(*pol_itr)->size())); (*pol_itr)->size()));
} }

View File

@ -51,10 +51,14 @@ typedef vector< short >::iterator IteratorShort;
struct Lwo2Surface struct Lwo2Surface
{ {
short image_index; Lwo2Surface():
string name; image_index(-1),
Vec3 color; state_set(0) {}
StateSet* state_set;
short image_index;
string name;
Vec3 color;
StateSet* state_set;
}; };
struct Lwo2PolygonMapping struct Lwo2PolygonMapping

View File

@ -69,10 +69,10 @@ osgDB::RegisterReaderWriterProxy<ReaderWriterLWO> g_lwoReaderWriterProxy;
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*)
{ {
std::auto_ptr<Lwo2> lwo2(new Lwo2()); std::auto_ptr<Lwo2> lwo2(osgNew Lwo2());
if (lwo2->ReadFile(fileName)) if (lwo2->ReadFile(fileName))
{ {
osg::ref_ptr<Group> group = new osg::Group(); osg::ref_ptr<Group> group = osgNew osg::Group();
if (lwo2->GenerateGroup(*group)) return group.take(); if (lwo2->GenerateGroup(*group)) return group.take();
} }
return ReadResult::FILE_NOT_HANDLED; return ReadResult::FILE_NOT_HANDLED;
@ -146,14 +146,14 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
{ {
lwMaterial& lw_material = lw->material[itr->first]; lwMaterial& lw_material = lw->material[itr->first];
gc._geom = new osg::Geometry; gc._geom = osgNew osg::Geometry;
osg::Vec3Array* vertArray = new osg::Vec3Array(gc._numPoints); osg::Vec3Array* vertArray = osgNew osg::Vec3Array(gc._numPoints);
gc._vertices = vertArray->begin(); gc._vertices = vertArray->begin();
gc._geom->setVertexArray(vertArray); gc._geom->setVertexArray(vertArray);
// set up color. // set up color.
osg::Vec4Array* colors = new osg::Vec4Array(1); osg::Vec4Array* colors = osgNew osg::Vec4Array(1);
(*colors)[0].set(lw_material.r, (*colors)[0].set(lw_material.r,
lw_material.g, lw_material.g,
lw_material.b, lw_material.b,
@ -171,9 +171,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
if (image) if (image)
{ {
// create state // create state
osg::StateSet* stateset = new osg::StateSet; osg::StateSet* stateset = osgNew osg::StateSet;
osg::Texture2D* texture = new osg::Texture2D; osg::Texture2D* texture = osgNew osg::Texture2D;
texture->setImage(image); texture->setImage(image);
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
@ -181,7 +181,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
gc._geom->setStateSet(stateset); gc._geom->setStateSet(stateset);
osg::Vec2Array* texcoordArray = new osg::Vec2Array(gc._numPoints); osg::Vec2Array* texcoordArray = osgNew osg::Vec2Array(gc._numPoints);
gc._texcoords = texcoordArray->begin(); gc._texcoords = texcoordArray->begin();
gc._geom->setTexCoordArray(0,texcoordArray); gc._geom->setTexCoordArray(0,texcoordArray);
} }
@ -198,7 +198,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
{ {
GeometryCollection& gc = mtgcm[face.material]; GeometryCollection& gc = mtgcm[face.material];
gc._geom->addPrimitive(new osg::DrawArrays(osg::Primitive::POLYGON,gc._coordCount,face.index_cnt)); gc._geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,gc._coordCount,face.index_cnt));
gc._coordCount += face.index_cnt; gc._coordCount += face.index_cnt;
// From the spec_low.lxt : // From the spec_low.lxt :
@ -225,7 +225,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
} }
} }
osg::Geode* geode = new osg::Geode; osg::Geode* geode = osgNew osg::Geode;
osgUtil::Tesselator tesselator; osgUtil::Tesselator tesselator;
@ -239,7 +239,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string
if (gc._geom) if (gc._geom)
{ {
tesselator.retesselatePolygons(*gc._geom); //tesselator.retesselatePolygons(*gc._geom);
smoother.smooth(*gc._geom); smoother.smooth(*gc._geom);

View File

@ -22,6 +22,8 @@ using namespace osgUtil;
void Optimizer::optimize(osg::Node* node, unsigned int options) void Optimizer::optimize(osg::Node* node, unsigned int options)
{ {
return;
if (options & COMBINE_ADJACENT_LODS) if (options & COMBINE_ADJACENT_LODS)
{ {
CombineLODsVisitor clv; CombineLODsVisitor clv;