Advertisement
Guest User

SVGLoader.parse() issue

a guest
Mar 18th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static toGeometry({ svg, id }: SetupFromSvgParams) {
  2.     svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  3.     // svg.removeAttribute('width');
  4.     // svg.removeAttribute('height');
  5.     svg.removeAttribute('fill');
  6.     svg.removeAttribute('aria-hidden');
  7.     svg.removeAttribute('data-icon-path');
  8.     svg.removeAttribute('class');
  9.     svg.removeAttribute('data-js-selector');
  10.  
  11.     // let svgMarkup = svg.outerHTML;
  12.  
  13.     let svgMarkup = `<svg width="28" height="28" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg"><path d="M27.24 23.917L15.01 2.736a1.167 1.167 0 00-2.02 0L.76 23.916c-.448.778.113 1.75 1.011 1.75h24.457c.899 0 1.46-.972 1.011-1.75zM13.416 9.333h1.166v8.75h-1.166v-8.75zM14 21.583a.875.875 0 110-1.75.875.875 0 010 1.75z"></path></svg>`;
  14.  
  15.     const loader = new SVGLoader();
  16.     const svgData = loader.parse(svgMarkup);
  17.  
  18.     console.log('svg: ', svgMarkup);
  19.     console.log('id: ', id);
  20.  
  21.     const svgGroup = new THREE.Group();
  22.  
  23.     svgGroup.scale.set(10, 10, 1);
  24.  
  25.     svgData.paths.forEach((path) => {
  26.       const shapes = path.toShapes(false);
  27.  
  28.       const material = new THREE.MeshBasicMaterial({
  29.         color: path.color,
  30.         side: THREE.FrontSide,
  31.         depthWrite: false,
  32.       });
  33.  
  34.       shapes.forEach((shape) => {
  35.         const geometry = new THREE.ShapeGeometry(shape);
  36.  
  37.         const mesh = new THREE.Mesh(geometry, material);
  38.  
  39.         svgGroup.add(mesh);
  40.       });
  41.     });
  42.  
  43.     svgGroup.scale.y *= -1;
  44.     this._svgGeometries.set(id, svgGroup);
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement