UNPKG

hpg-r3f-model-scene

Version:

Pretty Footer react component used in ant.design

50 lines 2 kB
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { useEventBus } from '../common/events'; import { Process } from '../utils/enums'; import { useThree } from '@react-three/fiber'; function closeWin() { if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('Chrome') != -1) { window.location.href = 'about:blank'; window.close(); } else { window.opener = null; window.open('', '_self'); window.close(); } } var ScreenShot = function ScreenShot(_ref) { var onScreenShot = _ref.onScreenShot; var _useThree = useThree(), gl = _useThree.gl, camera = _useThree.camera, scene = _useThree.scene; useEventBus(Process.SCREEN_SHOT, /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) { var image; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: //其实就是相当于渲染一帧,并把这一帧输出而如果需要截某个部分的图片,只需要将相机变一下,换成自己想要范围,并渲染一帧再截屏出来。 gl.render(scene, camera); image = gl.domElement.toDataURL('image/png'); console.log('ScreenShot', image); onScreenShot === null || onScreenShot === void 0 ? void 0 : onScreenShot(image); if (params === null || params === void 0 ? void 0 : params.isClosePage) { console.log('closePage'); closeWin(); } case 5: case "end": return _context.stop(); } }, _callee); })); return function (_x) { return _ref2.apply(this, arguments); }; }()); return /*#__PURE__*/React.createElement(React.Fragment, null); }; export default ScreenShot;