async function create3dFromSvgV8(svg, type, scaleBy){
const loader = new THREE.SVGLoader();
let paths = loader.parse( svg.outerHTML ).paths
let style = paths[0].userData.style
const shapes = [], points = [];
paths.forEach((path, i) => {
paths[i].toShapes( true, false).forEach((shape, i) => { shapes.push( shape ); })
for ( let j = 0, jl = path.subPaths.length; j < jl; j ++ ) { points.push( path.subPaths[ j ].getPoints() ) }
} )
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide } );
const extrudeOptions = { depth: 40, bevelEnabled: false }
if( ['geoms'].includes(type) ){
shapes.forEach(shape => {
const geometry = new THREE.ExtrudeBufferGeometry(shape, extrudeOptions);
material.color = new THREE.Color().setHex( Math.random() * 0xffffff );
const mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
});
}
if( ['lines'].includes(type) ){
points.forEach((pointsArr, i) => {
const geometry = THREE.SVGLoader.pointsToStroke( pointsArr, style )
material.color = new THREE.Color().setStyle( 'pink' )
const mesh = new THREE.Mesh( geometry, material );
group.add( mesh );
});
}
if( ['extrude'].includes(type) ){
let x = 20
let y = 2
let z = 2
const squareShape = new THREE.Shape().moveTo( x, 0 ).lineTo( x, y ).lineTo( y, z ).lineTo( z, 0 )
const shapeBufferGeometry = [];
points.forEach((twoVectorArray, i) => {
let threeVectorArray = []
twoVectorArray.forEach((v, i) => { threeVectorArray.push( new THREE.Vector3( v.x, v.y, 8 ) ) } )
const spline = new THREE.CatmullRomCurve3( threeVectorArray )
spline.curveType = 'catmullrom';
spline.closed = false;
var step = spline.points.length;
var geometry = new THREE.ExtrudeBufferGeometry(squareShape, {
extrudePath: spline,
steps: 200,
bevelEnabled: false
});
material.color = new THREE.Color().setHex( Math.random() * 0xffffff );
shapeBufferGeometry.push( geometry )
} )
const iconGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries( shapeBufferGeometry, true );
const mesh = new THREE.Mesh( iconGeometry, material );
mesh.translateZ( 40 );
group.add( mesh );
}
group.rotateX(Math.PI);
group.scale.multiplyScalar( scaleBy );
return group
}