例如,我试图将模块附加到THREE.js库中...
import * as THREE from 'three'// append the following routine to three when I import this file into app.js
export THREE.RenderPass = function (scene, camera, overrideMaterial, clearColor, clearAlpha) {
THREE.Pass.call(this)
this.scene = scene
this.camera = camera
this.overrideMaterial = overrideMaterial
this.clearColor = clearColor
this.clearAlpha = (clearAlpha !== undefined) ? clearAlpha : 0
this.clear = true
this.needsSwap = false
}
export THREE.RenderPass.prototype = Object.assign(Object.create(THREE.Pass.prototype), {
constructor: THREE.RenderPass,
render: function (renderer, writeBuffer, readBuffer, delta, maskActive) {
var oldAutoClear = renderer.autoClear
renderer.autoClear = false
this.scene.overrideMaterial = this.overrideMaterial
var oldClearColor, oldClearAlpha
if (this.clearColor) {
oldClearColor = renderer.getClearColor().getHex()
oldClearAlpha = renderer.getClearAlpha()
renderer.setClearColor(this.clearColor, this.clearAlpha)
}
renderer.render(this.scene, this.camera, this.renderToScreen ? null : readBuffer, this.clear)
if (this.clearColor) {
renderer.setClearColor(oldClearColor, oldClearAlpha)
}
this.scene.overrideMaterial = null
renderer.autoClear = oldAutoClear
}
})
这些例程已经根深蒂固地进入了我以前的原始Java脚本解决方案中。我已经将其移至webpack,该webpack捆绑并解析了所有需要导入和导出的内容。以前,我只是通过CDN导入库后才调用这些文件,并将其追加到文件中。在nodejs中,它的处理方式似乎有所不同,我不确定该怎么做。
我需要这些模块可从主库访问,它们用于在three.js中启用后处理。
以前我做过...
<!-- scripts appended based on the order I placed the script tags in the html, I bundle wiht webpack so this seems like a rather bad solution to continue when its already being 'bundled'-->
<script src="EffectComposer.js"></script>
<script src="CopyShader.js"></script>
<script src="RenderPass.js"></script>
<script src="MaskPass.js"></script>
<script src="ShaderPass.js"></script>