1、下载vtkjs-master.zip
2、package.json分析
"size": "size-limit --why --config ./webpack.config.js", "validate": "prettier --config ./prettier.config.js --list-different "Sources/**/*.js" "Examples/**/*.js"", "reformat": "prettier --config ./prettier.config.js --write "Sources/**/*.js" "Examples/**/*.js"", "reformat-only": "prettier --single-quote --trailing-comma es5 --print-width 80 --arrow-parens always --write", "doc": "kw-doc -c ./Documentation/config.js", "doc:www": "npm t -- --single-run && kw-doc -c ./Documentation/config.js -s", "doc:publish": "kw-doc -c ./Documentation/config.js -mp", "example": "node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js", "build": "webpack-dev-server --config webpack.dev.js", "build:release": "webpack --config webpack.prod.js --progress --hide-modules", "test": "karma start ./karma.conf.js", "test:travis": "karma start ./karma.conf.js --browsers ChromeHeadlessNoSandbox --single-run", "test:debug": "karma start ./karma.conf.js --no-single-run", "test:firefox": "karma start ./karma.conf.js --browsers Firefox", "test:firefox-debug": "karma start ./karma.conf.js --browsers Firefox --no-single-run", "commit": "git cz", "semantic-release": "semantic-release"
3、文件结构分析
4、编译
npm run build:release
5、测试vtk.js
打开dist目录
双击index.html,浏览器出现
6、代码分析
<!DOCTYPE html> <html> <head> <title>vtk.js</title> </head> <body> <script type="text/javascript" src="https://unpkg.com/@babel/polyfill@7.0.0/dist/polyfill.js"></script> <script type="text/javascript" src="vtk.js"></script> <script type="text/javascript"> var fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance(); var actor = vtk.Rendering.Core.vtkActor.newInstance(); var mapper = vtk.Rendering.Core.vtkMapper.newInstance(); var cone = vtk.Filters.Sources.vtkConeSource.newInstance(); actor.setMapper(mapper); mapper.setInputConnection(cone.getOutputPort()); var renderer = fullScreenRenderer.getRenderer(); renderer.addActor(actor); renderer.resetCamera(); var renderWindow = fullScreenRenderer.getRenderWindow(); renderWindow.render(); </script> </body> </html>