在OSG中安装vrml插件openvrml

在OSG中安装vrml插件:

主要步骤:先编译openvrml,而osg中支持vrml插件,所以然后在cmake中指定vrml宏的include路径和lib文件(openvrml生成的.lib文件),cmake编译成功后,则可在VS2008的OSG的.sln的视图中找到工程plugins vrml,再在VS2008中单独编译工程plugins vrml即可.

(1)   编译openvrml:

(1.1)在windows下,osg支持的openvrml版本是0.14.3,下载该版本源码http://sourceforge.net/project/downloading.php?groupname=artoolkit&filename=OpenVRML-0.14.3-win32.zip                 

或在

http://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/VisualStudio/VisualStudioPlugins上点击标题<VRML plugin>下的<this package>超链接来下载openvrml 0.14.3的源代码.

(1.2)解压缩后,打开解决方案.sln文件:

…\OpenVRML-0.14.3-win32\OpenVRML\src\openvrml-0.14.3\ide-projects\Windows\VisualC7\OpenVRML\OpenVRML.sln

只需要用到该解决方案中的三个工程:antlr,openvrml,regex.其他的工程可以卸载掉.注意:在debug模式下输出的.lib文件名要加'd'(如antlrd.lib,openvrmld.lib,regexd.lib).

编译antlr,openvrml,regex这三个工程,会遇到3个错误:

错误1:Token.hpp line 76:

inline operator<(RefToken l,RefToken r); //{return true;}

将它替换为:

inline bool operator<(RefToken l,RefToken r); //{return true;}

错误2:AST.hpp line 151:

inline operator<(RefAST l,RefAST r); // {return true;}

将它替换为:

inline bool operator<(RefAST l,RefAST r); // {return true;}

错误3:在regerror.c中,使用了旧的C函数定义:

size_t

regerror(errcode, preg, errbuf, errbuf_size)

int errcode;

const regex_t *preg;

char *errbuf;

size_t errbuf_size;

{

将它替换为:

size_t

regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)\\

{

再次编译,应该则成功.分别在release和debug下编译成功后,得到(antlr.lib,openvrml.lib,regex.lib)和(antlrd.lib,openvrmld.lib,regexd.lib).

(1.3)建立一个文件夹(如D:\openVrml\home-build,注:要用英文名,如用汉字可能会出错),在home-build下建立2个子文件夹(include和lib),然后把openvrml的源文件中的OpenVRML-0.14.3-win32\OpenVRML\include\openvrml文件夹的文件复制到home-build下的include中(有gl子文件夹,common.h,vrml97node.h等头文件),再把那6个库文件(antlr.lib,openvrml.lib,regex.lib)和(antlrd.lib,openvrmld.lib,regexd.lib)放入home-build下的lib中,这样openvrml的.h和.lib文件就准备好了,就可以在cmake中设置宏OPENVRML的路径了.

 

(2)   cmake 编译osg源代码,以在VS2008的OSG的.sln的视图中产生工程plugins vrml(开始是没有的,只有在camke中设置生成后才有):

(2.1)因为还要用到第三方插件,所以要下载网上VS2008对应的版本的3rd Party压缩包:

在网页

http://www.openscenegraph.org/projects/osg/wiki/Downloads/Dependencies中点击< VisualStudio 9 (2008) SP1 >下<32 & 64 bit >下的超链接http://openscenegraph.alphapixel.com/osg/downloads/openscenegraph-third-party-library-downloads,即可下载第三方插件(其中有JPEG,PNG,ZLIB等的头文件和库文件),解压,如:

D:/osg/3rdParty/windows-VS9.0.30729-x86-release/

D:\osg\3rdParty\windows-VS9.0.30729-x86-debug

其中都有include,lib,bin三个子文件夹.

(2.2)将osg源代码中的顶层CMakeLists.txt拖放到cmake程序中,点击<configure>,会有红色的错误标志,是因为没有设置openvrml的路径,设置如下:

1.OEPNVRML_ALTLR_LIBRARY: D:/openVrml/home-build/lib/antlr.lib

2.OEPNVRML_ALTLR_LIBRARY_DEBU: D:/openVrml/home-build/lib/antlrd.lib

3.OPENVRML_INCLUDE_DIR: D:/openVrml/home-build/include

OPENVRML_LIBRARY: D:/openVrml/home-build/lib/openvrml.lib

4.OPENVRML_LIBRARY_DEBUG: D:/openVrml/home-build/lib/openvrmld.lib

5.OPENVRML_REGEX_LIBRARY: D:/openVrml/home-build/lib/regex.lib

6.OPENVRML_REGEX_LIBRARY_DEBUG: D:/openVrml/home-build/lib/regexd.lib

7.JPEG_INCLUDE_DIR: D:/osg/3rdParty/windows-VS9.0.30729-x86-release/include

8.JPEG_LIBRARY: D:/osg/3rdParty/windows-VS9.0.30729-x86-release/lib/libjpeg.lib

9. PNG_LIBRARY:

D:/osg/3rdParty/windows-VS9.0.30729-x86-release/lib/libpng13.lib

10.PNG_PNG_INCLUDEDIR:

D:/osg/3rdParty/windows-VS9.0.30729-x86-release/include

11.ZLIB_INCLUDE_DIR:

D:/osg/3rdParty/windows-VS9.0.30729-x86-release/include

12.ZLIB_LIBRARY:

D:/osg/3rdParty/windows-VS9.0.30729-x86-release/lib

然后<configure>,<generate>,成功后,打开osg.sln文件可以看到新生成了一个工程plugins vrml,在<release>下编译该工程文件(设置它为启动项,在工程名上右键<生成>).

错误一:无法打开vrml97node.h文件:

将vrml97node.h的文件夹目录添加到工程plugins vrml的<附加包含目录>中:D:\openVrml\home-build

错误二:链接错误: openvrml.lib中,无法识别的_gzsetparams等.

在网上搜索了一下,知道了它是zlib里的文件,所以将zlib的.lib文件加入到该工程的<链接器>的<附加依赖项>中:

D:\osg\3rdParty\windows-VS9.0.30729-x86-release\lib\zlib1.lib

错误三: fatal error C1900: Il mismatch between 'P1' version '20080116' and 'P2' version '20070207':

要安装VS2008的SP1插件:Microsoft Visual Studio 2008 Service Pack 1插件官方下载地址:

http://www.microsoft.com/downloads/details.aspx?familyid=27673C47-B3B5-4C67-BD99-84E525B5CE61&displaylang=zh-cn

下载.iso文件后用虚拟光驱打开,运行SPInstaller.exe程序即可,安装要花点时间.

然后再编译工程plugins vrml,应该会成功.

 

(3)   测试生成的osgdb_vrml.dll是否正确:

将步骤(2)生成的osgdb_vrml.dll复制到OSG的bin的插件目录中,如:

D:\OpenSceneGraph-VC9.0-2.8.2\bin\osgPlugins-2.8.2

将osg源代码中cmake生成的新的三个文件osg55-osgDB.dll,osg55-osgUtil.dll和ot11-OpenThreads.dll(这三个文件在cmake生成的路径D:\osg\OpenSceneGraph-sourcecode()-2.8.2\OpenSceneGraph-2.8.2\build\bin中)复制到OSG的bin目录下(要覆盖),如:

D:\OpenSceneGraph-VC9.0-2.8.2\bin

在命令行中运行:osgviewer ***.wrl,有错误,提示无libpng13.dll,将第三方插件文件夹中的libpng13.dll复制到

D:\OpenSceneGraph-VC9.0-2.8.2\share\OpenSceneGraph\bin中,并将该目录加到环境变量中,使系统能找到该目录下的libpng13.dll.

再运行osgviewer ***.wrl,则可以像在osgview cow.osg中一样看到效果.

 

附:

参考文件:

1. osg2.8.2插件之openvrml编译安装:

http://liuxuanwalking.blogbus.com/logs/108058384.html

2. OSG编译:

http://haifeng60902.blog.163.com/blog/static/1636118732011484581233/

 

你可能感兴趣的:(在OSG中安装vrml插件openvrml)