1 line
22 KiB
Plaintext
1 line
22 KiB
Plaintext
|
|
{"version":3,"file":"SVGRenderer.cjs","sources":["../../src/renderers/SVGRenderer.js"],"sourcesContent":["import { Box2, Camera, Color, Matrix3, Matrix4, Object3D, Vector3 } from 'three'\nimport { Projector, RenderableFace, RenderableLine, RenderableSprite } from '../renderers/Projector'\n\nclass SVGObject extends Object3D {\n constructor(node) {\n super()\n\n this.isSVGObject = true\n\n this.node = node\n }\n}\n\nclass SVGRenderer {\n constructor() {\n let _renderData,\n _elements,\n _lights,\n _svgWidth,\n _svgHeight,\n _svgWidthHalf,\n _svgHeightHalf,\n _v1,\n _v2,\n _v3,\n _svgNode,\n _pathCount = 0,\n _precision = null,\n _quality = 1,\n _currentPath,\n _currentStyle\n\n const _this = this,\n _clipBox = new Box2(),\n _elemBox = new Box2(),\n _color = new Color(),\n _diffuseColor = new Color(),\n _ambientLight = new Color(),\n _directionalLights = new Color(),\n _pointLights = new Color(),\n _clearColor = new Color(),\n _vector3 = new Vector3(), // Needed for PointLight\n _centroid = new Vector3(),\n _normal = new Vector3(),\n _normalViewMatrix = new Matrix3(),\n _viewMatrix = new Matrix4(),\n _viewProjectionMatrix = new Matrix4(),\n _svgPathPool = [],\n _projector = new Projector(),\n _svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')\n\n this.domElement = _svg\n\n this.autoClear = true\n this.sortObjects = true\n this.sortElements = true\n\n this.overdraw = 0.5\n\n this.info = {\n render: {\n vertices: 0,\n faces: 0,\n },\n }\n\n this.setQuality = function (quality) {\n switch (quality) {\n case 'high':\n _quality = 1\n break\n case 'low':\n _quality = 0\n break\n }\n }\n\n this.setClearColor = function (color) {\n _clearColor.set(color)\n }\n\n this.setPixelRatio = function () {}\n\n this.setSize = function (width, height) {\n _svgWidth = width\n _svgHeight = height\n _svgWidthHalf = _svgWidth / 2\n _svgHeightHalf = _svgHeight / 2\n\n _svg.setAttribute('viewBox', -_svgWidthHalf + ' ' + -_svgHeightHalf + ' ' + _svgWidth + ' ' + _svgHeight)\n _svg.setAttribute('width', _svgWidth)\n _svg.setAttribute('height', _svgHeight)\n\n _clipBox.min.set(-_svgWidthHalf, -_svgHeightHalf)\n _clipBox.max.set(_svgWidthHalf, _svgHeightHalf)\n }\n\n this.getSize = function () {\n return {\n width: _svgWidth,\n height: _svgHeight,\n }\n }\n\n this.setPrecision = function (precision) {\n _precision = precision\n }\n\n function removeChildNodes() {\n _pathCount = 0\n\n while (_svg.childNodes.length > 0) {\n _svg.removeChild(_svg.childNodes[0])\n }\n }\n\n function convert(c) {\n return _precision !== null ? c.toFixed(_precision) : c\n }\n\n this.clear = function () {\n removeChildNodes()\n _svg.style.backgroundColor = _clearColor.getStyle()\n }\n\n this.render = function (scene, camera) {\n if (camera instanceof Camera === false) {\n console.error('THREE.SVGRenderer.render: camera is not an instance of Camera.')\n return\n }\n\n const background = scene.background\n\n if (background && background.isColor) {\n removeChildNodes()\n _svg.style.backgroundColor = background.getStyle()\n } else if (this.autoClear === true) {\n this.clear()\n }\n\n _this.info.render.vertices = 0\n _this.info.render.faces = 0\n\n _viewMatrix.copy(camera.matrixWorldInverse)\n _viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, _viewMatrix)\n\n _renderData = _projector.projectScene(scene, camera, this.sortObjects, this.sortElements)\n _elements = _renderData.elements\n _lights = _renderData.lights\n\n _normalViewMatrix.getNormalMatrix(camera.matrixWorldInverse)\n\n calculateLights(
|