/** * 3D Foundation Project * Copyright 2025 Smithsonian Institution * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Group, MeshStandardMaterial, Mesh, Vector2, LatheGeometry, Material } from "three"; //////////////////////////////////////////////////////////////////////////////// export default class Pin extends Group { protected needle: Mesh; protected handle: Mesh; constructor() { super(); const needlePoints = [ 0, 0, 0.25, 0.4, 0.4, 10, ]; const handlePoints = [ 0, 10, 3.4, 10, 3.5, 10.1, 3.5, 11, 3.45, 11.1, 2.05, 12.5, 2, 12.6, 2, 17.4, 2.05, 17.5, 3.45, 18.9, 3.5, 19, 3.5, 19.9, 3.4, 20, 0, 20, ]; const needleMaterial = new MeshStandardMaterial({ color: "white", metalness: 1 }); needleMaterial.transparent = true; this.needle = new Mesh( this.createLatheGeometry(needlePoints), needleMaterial ); const handleMaterial = new MeshStandardMaterial(({ color: "#ffcd00", roughness: 0.8, metalness: 0.1 })); handleMaterial.transparent = true; this.handle = new Mesh( this.createLatheGeometry(handlePoints), handleMaterial ); this.needle.matrixAutoUpdate = false; this.add(this.needle); this.handle.matrixAutoUpdate = false; this.add(this.handle); } dispose() { this.remove(this.handle, this.needle); (this.needle.material as Material).dispose(); (this.handle.material as Material).dispose(); this.needle.geometry.dispose(); this.handle.geometry.dispose(); } protected createLatheGeometry(points: number[]) { const vectors = []; for (let i = 0, n = points.length; i < n; i += 2) { vectors.push(new Vector2(points[i], points[i + 1])); } return new LatheGeometry(vectors, 16); } }