1 line
5.8 KiB
Plaintext
1 line
5.8 KiB
Plaintext
|
|
{"version":3,"file":"PeppersGhostEffect.cjs","sources":["../../src/effects/PeppersGhostEffect.js"],"sourcesContent":["import { PerspectiveCamera, Quaternion, Vector3 } from 'three'\n\n/**\n * peppers ghost effect based on http://www.instructables.com/id/Reflective-Prism/?ALLSTEPS\n */\n\nclass PeppersGhostEffect {\n constructor(renderer) {\n const scope = this\n\n scope.cameraDistance = 15\n scope.reflectFromAbove = false\n\n // Internals\n let _halfWidth, _width, _height\n\n const _cameraF = new PerspectiveCamera() //front\n const _cameraB = new PerspectiveCamera() //back\n const _cameraL = new PerspectiveCamera() //left\n const _cameraR = new PerspectiveCamera() //right\n\n const _position = new Vector3()\n const _quaternion = new Quaternion()\n const _scale = new Vector3()\n\n // Initialization\n renderer.autoClear = false\n\n this.setSize = function (width, height) {\n _halfWidth = width / 2\n if (width < height) {\n _width = width / 3\n _height = width / 3\n } else {\n _width = height / 3\n _height = height / 3\n }\n\n renderer.setSize(width, height)\n }\n\n this.render = function (scene, camera) {\n if (scene.matrixWorldAutoUpdate === true) scene.updateMatrixWorld()\n\n if (camera.parent === null && camera.matrixWorldAutoUpdate === true) camera.updateMatrixWorld()\n\n camera.matrixWorld.decompose(_position, _quaternion, _scale)\n\n // front\n _cameraF.position.copy(_position)\n _cameraF.quaternion.copy(_quaternion)\n _cameraF.translateZ(scope.cameraDistance)\n _cameraF.lookAt(scene.position)\n\n // back\n _cameraB.position.copy(_position)\n _cameraB.quaternion.copy(_quaternion)\n _cameraB.translateZ(-scope.cameraDistance)\n _cameraB.lookAt(scene.position)\n _cameraB.rotation.z += 180 * (Math.PI / 180)\n\n // left\n _cameraL.position.copy(_position)\n _cameraL.quaternion.copy(_quaternion)\n _cameraL.translateX(-scope.cameraDistance)\n _cameraL.lookAt(scene.position)\n _cameraL.rotation.x += 90 * (Math.PI / 180)\n\n // right\n _cameraR.position.copy(_position)\n _cameraR.quaternion.copy(_quaternion)\n _cameraR.translateX(scope.cameraDistance)\n _cameraR.lookAt(scene.position)\n _cameraR.rotation.x += 90 * (Math.PI / 180)\n\n renderer.clear()\n renderer.setScissorTest(true)\n\n renderer.setScissor(_halfWidth - _width / 2, _height * 2, _width, _height)\n renderer.setViewport(_halfWidth - _width / 2, _height * 2, _width, _height)\n\n if (scope.reflectFromAbove) {\n renderer.render(scene, _cameraB)\n } else {\n renderer.render(scene, _cameraF)\n }\n\n renderer.setScissor(_halfWidth - _width / 2, 0, _width, _height)\n renderer.setViewport(_halfWidth - _width / 2, 0, _width, _height)\n\n if (scope.reflectFromAbove) {\n renderer.render(scene, _cameraF)\n } else {\n renderer.render(scene, _cameraB)\n }\n\n renderer.setScissor(_halfWidth - _width / 2 - _width, _height, _width, _height)\n renderer.setViewport(_halfWidth - _width / 2 - _width, _height, _width, _height)\n\n if (scope.reflectFromAbove) {\n renderer.render(scene, _cameraR)\n } else {\n renderer.render(scene, _cameraL)\n }\n\n renderer.setScissor(_halfWidth + _width / 2, _height, _width, _height)\n renderer.setViewport(_halfWidth + _width / 2, _height, _width, _height)\n\n if (scope.reflectFromAbove) {\n renderer.render(scene, _cameraL)\n } else {\n renderer.render(scene, _cameraR)\n }\n\n renderer.setScissorTest(false)\n }\n }\n}\n\nexport { PeppersGhostEffect }\n"],"names":["PerspectiveCamera","Vector3","Quaternion"],"mappings":";;;AAMA,MAAM,mBAAmB;AAAA,EACvB,YAAY,UAAU;AACpB,UAAM,QAAQ;AAEd,UAAM,iBAAiB;AACvB,UAAM,mBAAmB;AAGzB,QAAI,YAAY,QAAQ;AAExB,UAAM,WAAW,IAAIA,wBAAmB;AACxC,UAAM,WAAW,IAAIA,wBAAmB;AACxC,UAAM,WAAW,IAAIA,wBAAmB;AACxC,UAAM,WAAW,IAAIA,wBAAmB;AAExC,
|