-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy paththree-6dof.esm.js.map
1 lines (1 loc) · 12 KB
/
three-6dof.esm.js.map
1
{"version":3,"file":"three-6dof.esm.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":";;AAAA;;;;;;;;ACAO,IAAMA,QAAgB,GAAG;EAC9BC,YAAY,EAAE;IACZC,IAAI,EAAE,GADM;IAEZC,KAAK,EAAE;GAHqB;EAK9BC,YAAY,EAAE;IACZF,IAAI,EAAE,GADM;IAEZC,KAAK,EAAE;GAPqB;EAS9BE,IAAI,EAAE;IACJH,IAAI,EAAE,GADF;IAEJC,KAAK,EAAE;GAXqB;EAa9BG,OAAO,EAAE;IACPJ,IAAI,EAAE,GADC;IAEPC,KAAK,EAAE;GAfqB;EAiB9BI,SAAS,EAAE;IACTL,IAAI,EAAE,GADG;IAETC,KAAK,EAAE;GAnBqB;EAqB9BK,UAAU,EAAE;IACVN,IAAI,EAAE,GADI;IAEVC,KAAK,EAAE;GAvBqB;EAyB9BM,YAAY,EAAE;IACZP,IAAI,EAAE,GADM;IAEZC,KAAK,EAAE;;CA3BJ;;ICAFO;;WAAAA;EAAAA,YAAAA;EAAAA,YAAAA;EAAAA,YAAAA;EAAAA,YAAAA;EAAAA,YAAAA;GAAAA,gBAAAA;;IAQAC;;WAAAA;EAAAA,MAAAA;EAAAA,MAAAA;EAAAA,MAAAA;GAAAA,UAAAA;;IAMAC;;WAAAA;EAAAA,YAAAA;EAAAA,YAAAA;GAAAA,gBAAAA;;AAKL,MAAMC,KAAN,CAAY;;SACH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