-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy paththree-6dof.amd.js.map
1 lines (1 loc) · 12.9 KB
/
three-6dof.amd.js.map
1
{"version":3,"file":"three-6dof.amd.js","sources":["../src/components/three.ts","../src/components/uniforms.ts","../src/components/constants.ts","../src/components/viewer.ts"],"sourcesContent":["/**\n * A small wrapper for THREE imports so rollup tree-shakes only the parts we need better\n */\n\n/* eslint @typescript-eslint/camelcase: 0 */\n\nexport {\n Object3D,\n ShaderMaterial,\n BackSide,\n Mesh,\n Points,\n SphereBufferGeometry,\n Texture,\n NearestFilter,\n LinearFilter,\n RGBFormat,\n} from 'three'\n","export const Uniforms: object = {\n colorTexture: {\n type: 't',\n value: null,\n },\n depthTexture: {\n type: 't',\n value: null,\n },\n time: {\n type: 'f',\n value: 0.0,\n },\n opacity: {\n type: 'f',\n value: 1.0,\n },\n pointSize: {\n type: 'f',\n value: 3.0,\n },\n debugDepth: {\n type: 'f',\n value: 0.0,\n },\n displacement: {\n type: 'f',\n value: 1.0,\n },\n}\n","enum MeshDensity {\n LOW = 64,\n MEDIUM = 128,\n HIGH = 256,\n EXTRA_HIGH = 512,\n EPIC = 1024,\n}\n\nenum Style {\n WIRE = 0,\n POINTS = 1,\n MESH = 2,\n}\n\nenum TextureType {\n TOP_BOTTOM,\n SEPERATE,\n}\n\nclass Props {\n public type: TextureType = TextureType.SEPERATE\n public density: MeshDensity = MeshDensity.HIGH\n public style: Style = Style.MESH\n public displacement: number = 4.0\n public radius: number = 6\n}\n\nexport { MeshDensity, Style, TextureType, Props }\n","import {\n Object3D,\n ShaderMaterial,\n BackSide,\n Mesh,\n Points,\n SphereBufferGeometry,\n Texture,\n NearestFilter,\n LinearFilter,\n RGBFormat,\n} from './three'\n\n// @ts-ignore\nimport frag from '../shaders/sixdof.frag'\n// @ts-ignore\nimport vert from '../shaders/sixdof.vert'\n\nimport { Uniforms } from './uniforms'\nimport { Style, MeshDensity, TextureType, Props } from './constants'\n\nexport default class Viewer extends Object3D {\n /** Default props if not provided */\n private props: Props = new Props()\n\n private static geometry: SphereBufferGeometry\n private material: ShaderMaterial = new ShaderMaterial({\n uniforms: Uniforms,\n vertexShader: vert,\n fragmentShader: frag,\n transparent: true,\n side: BackSide,\n })\n\n constructor(texture: Texture, depth?: Texture, props?: object) {\n super()\n\n /** Assign the user provided props, if any */\n this.setProps(this.props, props)\n\n // /** Add the compiler definitions needed to pick the right GLSL methods */\n this.setShaderDefines(this.material, [TextureType[this.props.type]])\n\n /**\n * Create the geometry only once, it can be shared between instances\n * of the viewer since it's kept as a static class member\n **/\n if (!Viewer.geometry) {\n Viewer.geometry = this.createSphereGeometry(\n this.props.radius,\n this.props.density,\n )\n }\n\n /** Assign the textures and update the shader uniforms */\n this.assignTexture(this.props.type, texture, depth)\n\n /** Set the displacement using the public setter */\n this.displacement = this.props.displacement\n\n /** Create the Mesh/Points and add it to the viewer object */\n super.add(this.createMesh(Viewer.geometry, this.material, this.props.style))\n }\n\n /** Small util to set the defines of the GLSL program based on textureType */\n private setShaderDefines(\n material: ShaderMaterial,\n defines: Array<string>,\n ): void {\n defines.forEach(define => (material.defines[define] = ''))\n }\n\n /** Internal util to create buffer geometry */\n private createSphereGeometry(\n radius: number,\n meshDensity: MeshDensity,\n ): SphereBufferGeometry {\n return new SphereBufferGeometry(radius, meshDensity, meshDensity)\n }\n\n /** Internal util to set viewer props from config object */\n private setProps(viewerProps: Props, userProps?: object): void {\n if (!userProps) return\n\n /** Iterate over user provided props and assign to viewer props */\n for (let prop in userProps) {\n if (viewerProps[prop]) {\n viewerProps[prop] = userProps[prop]\n } else {\n console.warn(\n `THREE.SixDOF: Provided ${prop} in config but it is not a valid property and being ignored`,\n )\n }\n }\n }\n\n /** Internal util to assign the textures to the shader uniforms */\n private assignTexture(\n type: TextureType,\n colorTexture: Texture,\n depthTexture?: Texture,\n ): void {\n /** Check wheter we are rendering top bottom or just single textures */\n if (type === TextureType.SEPERATE) {\n if (!depthTexture)\n throw new Error(\n 'When using seperate texture type, depthmap must be provided',\n )\n this.depth = this.setDefaultTextureProps(depthTexture)\n }\n\n /** Assign the main texture */\n this.texture = this.setDefaultTextureProps(colorTexture)\n }\n\n private setDefaultTextureProps(texture: Texture): Texture {\n texture.minFilter = NearestFilter\n texture.magFilter = LinearFilter\n texture.format = RGBFormat\n texture.generateMipmaps = false\n return texture\n }\n\n /** An internal util to create the Mesh Object3D */\n private createMesh(\n geo: SphereBufferGeometry,\n mat: ShaderMaterial,\n style: Style,\n ): Object3D {\n switch (style) {\n case Style.WIRE:\n if (!this.material.wireframe) this.material.wireframe = true\n return new Mesh(geo, mat)\n case Style.MESH:\n if (this.material.wireframe) this.material.wireframe = false\n return new Mesh(geo, mat)\n case Style.POINTS:\n return new Points(geo, mat)\n }\n }\n\n /** Toggle vieweing texture or depthmap in viewer */\n public toggleDepthDebug(state?: boolean): void {\n this.material.uniforms.debugDepth.value =\n state != undefined ? state : !this.material.uniforms.debugDepth.value\n }\n\n /** Setter for displacement amount */\n public set displacement(val: number) {\n this.material.uniforms.displacement.value = val\n }\n\n /** Setter for depthmap uniform */\n public set depth(map: Texture) {\n this.material.uniforms.depthTexture.value = map\n }\n\n /** Setter for depthmap uniform */\n public set texture(map: Texture) {\n this.material.uniforms.colorTexture.value = map\n }\n\n /** Setter for the opacity */\n public set opacity(val: number) {\n this.material.uniforms.opacity.value = val\n }\n\n /** Setter for the point size */\n public set pointSize(val: number) {\n this.material.uniforms.pointSize.value = val\n }\n\n /** Getter for the current viewer props */\n public get config(): Props {\n return this.props\n }\n\n /** Getter for the opacity */\n public get opacity(): number {\n return this.material.uniforms.opacity.value\n }\n\n /** Getter for the point size */\n public get pointSize(): number {\n return this.material.uniforms.pointSize.value\n }\n\n /** Getter for displacement amount */\n public get displacement(): number {\n return this.material.uniforms.displacement.value\n }\n\n /** Getter for texture */\n public get texture(): Texture {\n return this.material.uniforms.colorTexture.value\n }\n\n /** Getter for the depth texture */\n public get depth(): Texture {\n return this.material.uniforms.opacity.value\n }\n}\n"],"names":["Uniforms","colorTexture","type","value","depthTexture","time","opacity","pointSize","debugDepth","displacement","MeshDensity","Style","TextureType","Props","SEPERATE","density","HIGH","style","MESH","radius","Viewer","Object3D","constructor","texture","depth","props","material","ShaderMaterial","uniforms","vertexShader","vert","fragmentShader","frag","transparent","side","BackSide","setProps","setShaderDefines","geometry","createSphereGeometry","assignTexture","add","createMesh","defines","forEach","define","meshDensity","SphereBufferGeometry","viewerProps","userProps","prop","console","warn","Error","setDefaultTextureProps","minFilter","NearestFilter","magFilter","LinearFilter","format","RGBFormat","generateMipmaps","geo","mat","WIRE","wireframe","Mesh","POINTS","Points","toggleDepthDebug","state","undefined","val","map","config"],"mappings":";;EAAA;;;;;;;;ECAO,IAAMA,QAAgB,GAAG;EAC9BC,EAAAA,YAAY,EAAE;EACZC,IAAAA,IAAI,EAAE,GADM;EAEZC,IAAAA,KAAK,EAAE;EAFK,GADgB;EAK9BC,EAAAA,YAAY,EAAE;EACZF,IAAAA,IAAI,EAAE,GADM;EAEZC,IAAAA,KAAK,EAAE;EAFK,GALgB;EAS9BE,EAAAA,IAAI,EAAE;EACJH,IAAAA,IAAI,EAAE,GADF;EAEJC,IAAAA,KAAK,EAAE;EAFH,GATwB;EAa9BG,EAAAA,OAAO,EAAE;EACPJ,IAAAA,IAAI,EAAE,GADC;EAEPC,IAAAA,KAAK,EAAE;EAFA,GAbqB;EAiB9BI,EAAAA,SAAS,EAAE;EACTL,IAAAA,IAAI,EAAE,GADG;EAETC,IAAAA,KAAK,EAAE;EAFE,GAjBmB;EAqB9BK,EAAAA,UAAU,EAAE;EACVN,IAAAA,IAAI,EAAE,GADI;EAEVC,IAAAA,KAAK,EAAE;EAFG,GArBkB;EAyB9BM,EAAAA,YAAY,EAAE;EACZP,IAAAA,IAAI,EAAE,GADM;EAEZC,IAAAA,KAAK,EAAE;EAFK;EAzBgB,CAAzB;;aCAFO;EAAAA,EAAAA,YAAAA;EAAAA,EAAAA,YAAAA;EAAAA,EAAAA,YAAAA;E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