使用VS 2019编译Mitsuba渲染器

Mitsuba 1 代已经很老旧了。它最新的版本要求使用VS 2017编译,我只装了VS 2019,在编译的时候踩了很多坑。

使用 master branch 的坑

一开始按照这篇博文讲的方法操作,用 annaconda 创建了一个 python 2.7 的环境,然后安装了 dependecies_win64 里的 Scons 2.5.1。结果在编译的时候,提示找不到 MSVC 编译器。后面还用 visual studio installer 安装的 2017 的 vc,但怎么尝试都是一样的问题。

使用 scons-python3 branch 的坑

后面发现 mitsuba 有一个叫 scons-python3 的 branch,是支持用 python 3 编译的。使用这个 branch 的代码就不用特地创建一个 python 2.7 的环境。

在自己的 python 3 环境中安装了 Scons 3.0.0 之后,可以成功编译 mitsuba 了。注意要把 config.py 里 vc 的版本号改成 Scons 在电脑上找到的编译器的版本号。

但是 mtsgui.exe 这个 gui 程序没有编译,编译的时候提示找不到 Qt。但是之前用 master branch 的时候是可以找到 Qt 的。后面终于发现,scons-python3 这个 branch 只修改了 build/SConscript.configure 和 build/SConscript.install 这两个配置文件,但 mtsgui 还有自己的配置文件。data/scons/qt5.py 和 src/mtsgui/SConscript 这两个文件是需要修改的。它们是用 python 2 写的,需要升级到 python 3。

直接用 python 自带的 2to3 升级代码是不够的,还是会报错。具体做法是:

对于 qt5.py:

line 154 cpp_contents = cpp.get_contents()

cpp_contents = cpp.get_contents()
if not isinstance(cpp_contents, str):
        cpp_contents = str(cpp_contents)

line 166 h_contents = h.get_contents()

h_contents = h.get_contents()
if not isinstance(h_contents, str):
        h_contents = str(h_contents)

line 305 contents = node.get_contents()

contents = node.get_contents()
if not isinstance(contents, str):
      contents = str(contents)

以上语句修改之后,再使用 2to3 工具修改 qt5.py。

对于 SConscript,先用 2to3 工具修改,然后修改以下语句:

def unique(list) :
        return list(dict.fromkeys(list).keys())

def unique(l) :
        return list(dict.fromkeys(l).keys())

编译完成后还需要添加一些依赖文件

编译完成后,dist 目录下就是编译好的渲染器。这时候直接打开 mtsgui.exe 会弹窗报错,提示Application failed to start because it could not find or load the QT platform plugin “windows”...

这时候可以直接用 Qt 自带的工具来自动添加所需要的依赖文件:

your_qt_dir\msvc2017_64\bin\windeployqt.exe .\dist\mtsgui.exe

然后 mtsgui.exe 就能启动了。

使用VS 2019编译Mitsuba渲染器_第1张图片

你可能感兴趣的:(图形图像,qt,python,渲染器)