Fix to iv/vrml loader so that it correctly passes back the right ReadResult

and checks the validity of the file extension being passed to the plugin.
Removed main.cpp * .h moving all its functionality into readerwriter.cpp.
This commit is contained in:
Robert Osfield
2002-08-04 21:11:00 +00:00
parent 93403a54db
commit 6b52e17c48
7 changed files with 52 additions and 102 deletions

View File

@@ -93,10 +93,6 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\iv\main.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\iv\nodecache.cpp
# End Source File
# Begin Source File
@@ -169,10 +165,6 @@ SOURCE=..\..\..\src\osgPlugins\iv\ltstr.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\iv\main.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\iv\material.h
# End Source File
# Begin Source File

View File

@@ -2,7 +2,6 @@ TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
main.cpp\
nodecache.cpp\
normals.cpp\
osgvisitor.cpp\

View File

@@ -1,56 +0,0 @@
/*
* osgDB::wrl - a VRML 1.0 loader for OpenSceneGraph
* Copyright (C) 2002 Ruben Lopez <ryu@gpul.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef WIN32
# pragma warning (disable:4786)
# pragma warning (disable:4541)
#endif
#include <stdio.h>
#include <iostream>
#include "mynode.h"
#include "osgvisitor.h"
#include <osgGLUT/Viewer>
#include <osgGLUT/glut>
extern int yyparse();
extern int yydebug;
extern MyNode *getRoot();
extern FILE *yyin;
int isatty(int) { return 0; }
extern void flush_scanner();
osg::Node *readVRMLNode(const char *file) {
yydebug=0;
yyin=fopen(file,"r");
std::cout << "Parsing..." << std::endl;
if (yyparse()!=0) {
flush_scanner();
return 0;
}
osg::ref_ptr<MyNode> n=getRoot();
try {
std::cout << "Generating OSG tree..." << std::endl;
osg::ref_ptr<OSGVisitor> visitante=new OSGVisitor(n.get());
return visitante->getRoot();
} catch (...) {
std::cerr << "VRML: error reading" << std::endl;
return 0;
}
}

View File

@@ -1,22 +0,0 @@
/*
* osgDB::wrl - a VRML 1.0 loader for OpenSceneGraph
* Copyright (C) 2002 Ruben Lopez <ryu@gpul.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <osg/Node>
osg::Node *readVRMLNode(const char *file);

View File

@@ -17,10 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef WIN32
# pragma warning (disable:4786)
# pragma warning (disable:4541)
#endif
#include <osg/Notify>
#include <iostream>
#include "osgvisitor.h"
#include "material.h"
@@ -98,7 +96,7 @@ public:
texture->setImage(osgDB::readImageFile(_texture));
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
std::cout << "Loading texture " << _texture << std::endl;
osg::notify(osg::INFO) << "Loading texture " << _texture << std::endl;
textures[_texture]=texture;
}
return textures[_texture].get();
@@ -128,7 +126,7 @@ OSGVisitor::OSGVisitor(MyNode *nodo) {
total_vert=0;
two_sided=false;
nodo->accept(this);
std::cout << "Model of " << total_vert << " vertices" << std::endl;
osg::notify(osg::INFO) << "Model of " << total_vert << " vertices" << std::endl;
}
void OSGVisitor::applyMyNode(MyNode *) {
@@ -228,7 +226,7 @@ void OSGVisitor::makeGeode(osg::Geode *geode, osg::Geometry *geometry, bool twoS
if (!twoSided) {
state->setAttributeAndModes(cull,osg::StateAttribute::ON);
} else {
//std::cout << "Deactivating culling for this object" << std::endl;
//osg::notify(osg::INFO) << "Deactivating culling for this object" << std::endl;
state->setAttributeAndModes(cull,osg::StateAttribute::OFF);
osg::Transparency *transp=new osg::Transparency();
transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -255,13 +253,13 @@ void OSGVisitor::makeGeode(osg::Geode *geode, osg::Geometry *geometry, bool twoS
if (material_active) {
AtrVec3List *diffuse=dynamic_cast<AtrVec3List*>(material_active->getAttribute("diffuseColor"));
if (diffuse) { // Has per-vertex colors
std::cout << "Per vertex colors" << std::endl;
osg::notify(osg::INFO) << "Per vertex colors" << std::endl;
VertexList *colors=diffuse->getList();
osg::Vec3Array *colors_osg=new osg::Vec3Array();
for (unsigned i=0;i<colors->size();i++) {
colors_osg->push_back((*colors)[i]);
}
std::cout << colors->size() << " colors" << std::endl;
osg::notify(osg::INFO) << colors->size() << " colors" << std::endl;
geometry->setColorArray(colors_osg);
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
}

View File

@@ -22,11 +22,49 @@
# pragma warning (disable:4541)
#endif
#include "readerwriter.h"
#include "main.h"
#include <stdio.h>
#include <iostream>
#include <osg/Notify>
#include "mynode.h"
#include "osgvisitor.h"
extern int yyparse();
extern int yydebug;
extern MyNode *getRoot();
extern FILE *yyin;
int isatty(int) { return 0; }
extern void flush_scanner();
osgDB::ReaderWriter::ReadResult VrmlReaderWriter::readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options*) {
return readVRMLNode(fileName.c_str());
const osgDB::ReaderWriter::Options*)
{
std::string ext = osgDB::getFileExtension(fileName);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
yydebug=0;
yyin=fopen(fileName.c_str(),"r");
osg::notify(osg::INFO) << "Parsing..." << std::endl;
if (yyparse()!=0)
{
flush_scanner();
return ReadResult::FILE_NOT_HANDLED;
}
osg::ref_ptr<MyNode> n=getRoot();
try
{
osg::notify(osg::INFO) << "Generating OSG tree..." << std::endl;
osg::ref_ptr<OSGVisitor> visitante=new OSGVisitor(n.get());
return visitante->getRoot();
}
catch (...)
{
osg::notify(osg::INFO) << "VRML: error reading" << std::endl;
return ReadResult::ERROR_IN_READING_FILE;
}
}
osgDB::RegisterReaderWriterProxy<VrmlReaderWriter> g_readerWriter_VRML_Proxy;

View File

@@ -30,9 +30,10 @@ class VrmlReaderWriter: public osgDB::ReaderWriter {
public:
VrmlReaderWriter() { }
virtual const char* className() { return "VRML"; }
virtual bool acceptsExtension(const std::string& extension) {
return osgDB::equalCaseInsensitive(extension,"wrl")
|| osgDB::equalCaseInsensitive(extension,"iv");
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension,"wrl") ||
osgDB::equalCaseInsensitive(extension,"iv");
}
virtual ReadResult readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*);
};