import { Box3, DoubleSide, Group, Mesh, MeshBasicMaterial, ShapeGeometry, Vector3 } from "three";
import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
import { NEEDLE_LOGO_SVG_URL } from "./static.js";
/** Logo Only */
export const needleLogoOnlySVG: string = NEEDLE_LOGO_SVG_URL;
const madeWithNeedleSvgString = ` `
const madeWithNeedleBlob = btoa(madeWithNeedleSvgString);
const madeWithNeedleUrl = "data:image/svg+xml;charset=utf-8;base64," + madeWithNeedleBlob;
/** Made With Needle Logo */
export const madeWithNeedleSVG: string = madeWithNeedleUrl;
const needleLogoSvgString = ``;
const needleLogoBlob = btoa(needleLogoSvgString);
const needleLogoUrl = "data:image/svg+xml;charset=utf-8;base64," + needleLogoBlob;
/** Logo + Needle Typo */
export const needleLogoSVG: string = needleLogoUrl
/** experimental
* @returns {Group} needle logo as a group of meshes with the needle logo. Size is normalized to one unit
*/
export function needleLogoAsSVGObject() {
const loader = new SVGLoader();
const res = loader.parse(needleLogoSvgString);
const paths = res.paths;
const group = new Group();
const bounds = new Box3();
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
const material = new MeshBasicMaterial({
color: path.color,
side: DoubleSide,
depthWrite: false
});
const shapes = SVGLoader.createShapes(path);
for (let j = 0; j < shapes.length; j++) {
const shape = shapes[j];
const geometry = new ShapeGeometry(shape);
const mesh = new Mesh(geometry, material);
group.add(mesh);
mesh.geometry.computeBoundingBox();
bounds.union(mesh.geometry.boundingBox!);
}
}
const maxSize = Math.max(bounds.max.x - bounds.min.x, bounds.max.y - bounds.min.y);
const normalizedScale = 1 / maxSize;
group.scale.set(normalizedScale, normalizedScale, normalizedScale);
group.rotateZ(Math.PI);
return group;
}