{"version":3,"sources":["jsdelivr-header.js","/third_party/mediapipe/web/solutions/control_utils_3d/mesh_viewer.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACqBA,IAAA,UAAa,E,KAWT,MAAW,G,QAYZ,O,uBAcC,2B,oFAnCF,EAAA,GAAyC,KAAA,OACzC,EAAA,KAAA,QAAqD,IAAA,EAAA,Y,wDACrD,GAAA,EAAA,aAA0B,IAA1B,E,8EAiEG,KAAA,SAAa,EAAA,I","file":"/npm/@mediapipe/control_utils_3d@0.3.1675466062/control_utils_3d.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@mediapipe/control_utils_3d@0.3.1675466062/control_utils_3d.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @fileoverview This file contains a mesh viewer that allows for a simple\n * viewing of a mesh with an optional texture\n */\n\nimport {NormalizedLandmarkList} from 'google3/third_party/mediapipe/web/solutions/utils/transform_utils/landmark';\nimport * as THREE from 'three';\n\nimport * as util from './util';\n\n\n/**\n * Configuration object for MeshViewerConfig\n */\nexport interface MeshViewerConfig extends util.ViewerWidgetConfig {\n  materialColor?: number;\n  texture?: string|null;\n}\n\nconst DEFAULT_CONFIG: util.BaseRequired<MeshViewerConfig> = {\n  materialColor: 0xffffff,\n  texture: null,\n};\n\n/**\n * A viewer widget for meshes with or without textures\n */\nexport class MeshViewer extends util.ViewerWidget {\n  protected override config!: Required<MeshViewerConfig>;\n  private readonly light: THREE.PointLight;\n  private readonly material: THREE.MeshLambertMaterial;\n  private mesh?: THREE.Mesh;\n\n  constructor(parent: HTMLElement, config: MeshViewerConfig = {}) {\n    super(parent, {...DEFAULT_CONFIG, ...config});\n\n    this.light = new THREE.PointLight(0xffffff, 1);\n    this.light.position.copy(this.camera.position);\n    this.scene.add(this.light);\n\n    this.material = new THREE.MeshLambertMaterial(\n        {color: this.config.materialColor, side: THREE.DoubleSide});\n    if (this.config.texture) {\n      this.setTexture(this.config.texture);\n    }\n  }\n\n  protected override render() {\n    this.light.position.copy(this.camera.position);\n    super.render();\n  }\n\n  updateMeshFromLandmarks(\n      landmarks: NormalizedLandmarkList, faces: ArrayLike<number>,\n      textureCoords?: ArrayLike<number>) {\n    const vectors: number[] = landmarks.reduce(\n        (acc, cur) => acc.concat(cur.x, cur.y, cur.z), [] as number[]);\n    this.updateMeshFromData(vectors, faces, textureCoords);\n  }\n\n  updateMeshFromData(\n      points: ArrayLike<number>, faces: ArrayLike<number>,\n      textureCoords?: ArrayLike<number>) {\n    const geometry = new THREE.BufferGeometry();\n    geometry.setAttribute(\n        'position', new THREE.BufferAttribute(new Float32Array(points), 3));\n    geometry.setIndex(Array.from(faces));\n\n    if (textureCoords) {\n      geometry.setAttribute(\n          'uv', new THREE.BufferAttribute(new Float32Array(textureCoords), 2));\n    }\n    geometry.computeVertexNormals();\n    geometry.computeBoundingBox();\n    const center =\n        geometry.boundingBox!.getCenter(new THREE.Vector3()).negate();\n    geometry.translate(center.x, center.y, center.z);\n\n    this.updateMesh(new THREE.Mesh(geometry, this.material));\n  }\n\n  updateMesh(mesh: THREE.Mesh) {\n    if (this.mesh) {\n      this.scene.remove(this.mesh);\n    }\n    this.scene.add(mesh);\n    this.mesh = mesh;\n    this.requestFrame();\n  }\n\n  setTexture(url: string) {\n    const texture = new THREE.TextureLoader().load(url);\n    this.material.setValues({map: texture});\n  }\n}\n\ngoog.exportSymbol('MeshViewer', MeshViewer);\n"]}