{"_id":"@dreamoment/receptionist","name":"@dreamoment/receptionist","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@dreamoment/receptionist","version":"0.0.1","type":"module","types":"dist/index.d.ts","main":"dist/index.es.js","author":{"name":"dreamoment-npm"},"license":"MIT","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"scripts":{"dev":"vite","build:example":"vue-tsc && vite build --mode example","build:lib":"vue-tsc && vite build --mode lib","publish:patch":"npm version patch && npm publish"},"devDependencies":{"@types/node":"^20.10.5","@types/three":"^0.160.0","@types/uuid":"^9.0.7","@vitejs/plugin-vue":"^4.5.2","typescript":"^5.2.2","vite":"^5.0.8","vite-plugin-dts":"^3.6.4","vue":"^3.3.11","vue-tsc":"^1.8.25"},"dependencies":{"normalize.css":"^8.0.1","three":"^0.160.0","uuid":"^9.0.1"},"_id":"@dreamoment/receptionist@0.0.1","gitHead":"8e8a6dbfc31ed58cfbd9efebc875c17ed07db189","description":"<h1 align=\"center\">receptionist</h1>","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-yYsAZjGx3IMEopICEY4oLqyJbrCRLZGgBNc62ZQjKN0WZpqrIyy31YAX15qNbuN4ScUMzqo1mTr702lNwmEa9A==","shasum":"59610ec173c3f7de097c2dc83abd4bd6af6e96e8","tarball":"https://registry.npmjs.org/@dreamoment/receptionist/-/receptionist-0.0.1.tgz","fileCount":12,"unpackedSize":204426,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD/xb8lypErNiJR/vMNTlK/whZ1LlsXIbxWXeHv90fbBAIgaUi4yWckwkRfFQiNYn3laxjwIhMB2a1CMA5O5gvKvd4="}]},"_npmUser":{"name":"dreamoment-npm","email":"dasu709394@qq.com"},"directories":{},"maintainers":[{"name":"dreamoment-npm","email":"dasu709394@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/receptionist_0.0.1_1704259529755_0.22084232487076938"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-03T05:25:29.650Z","0.0.1":"2024-01-03T05:25:29.928Z","modified":"2024-01-03T05:25:30.234Z"},"maintainers":[{"name":"dreamoment-npm","email":"dasu709394@qq.com"}],"description":"<h1 align=\"center\">receptionist</h1>","author":{"name":"dreamoment-npm"},"license":"MIT","readme":"<h1 align=\"center\">receptionist</h1>\r\n\r\n![](/docs/flow.drawio.png)\r\n\r\nLanguage: English | [中文简体](README_zh_cn.md)\r\n\r\n## What is receptionist ?\r\n\r\n`threejs` multi-function file loader that can handle a variety of common business scenarios, such as:\r\n- Download multiple files and get the total download progress.\r\n- Download data cannot be parsed by `threejs` loader and needs to be pre-processed. Because they could be encrypted or even compressed.\r\n## Features\r\n\r\n- lightweight and easy to use\r\n\r\n- multi-file download\r\n\r\n- data preprocessing\r\n\r\n- interface with all loaders in `threejs`\r\n\r\n- support `typescript`\r\n\r\n## Install\r\n\r\n```\r\nnpm i @dreamoment/receptionist\r\n```\r\n\r\n## Examples\r\n\r\n```\r\nimport * as THREE from 'three'\r\nimport { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'\r\nimport { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'\r\nimport Receptionist from '@dreamoment/receptionist'\r\n\r\n\r\nconst scene = new THREE.Scene()\r\nconst camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000 )\r\nconst ambientLight = new THREE.AmbientLight(0xffffff)\r\nconst directionalLight = new THREE.DirectionalLight(0xffffff)\r\ndirectionalLight.position.set(1, 1, 1)\r\nscene.add(ambientLight, directionalLight)\r\n\r\nconst renderer = new THREE.WebGLRenderer()\r\nrenderer.setSize(window.innerWidth, window.innerHeight)\r\ndocument.body.appendChild(renderer.domElement)\r\n\r\nconst controls = new OrbitControls(camera, renderer.domElement)\r\n\r\ncamera.position.set(5, 5, 5)\r\n\r\n\r\n// The models is simply encrypted\r\nconst monkey = Receptionist.createAsset('./monkey_encrypted.glb')\r\nconst ball = Receptionist.createAsset('./ball_encrypted.glb')\r\n// monkey\r\n//     .onLoad(data => {\r\n//       console.log('data:', data)\r\n//     })\r\n//     .onProgress(progress => {\r\n//       console.log(`progress: ${progress}`)\r\n//     })\r\n//     .onError(err => {\r\n//       console.log(`error: ${err}`)\r\n//     })\r\n// ball\r\n//     .onLoad(data => {\r\n//       console.log('data:', data)\r\n//     })\r\n//     .onProgress(progress => {\r\n//       console.log(`progress: ${progress}`)\r\n//     })\r\n//     .onError(err => {\r\n//       console.log(`error: ${err}`)\r\n//     })\r\n\r\n// with interception\r\nconst interceptor = Receptionist.createInterceptor((buffer) => {\r\n  let view = new Uint8Array(buffer)\r\n  for (let i = 0; i < view.length; i++) {\r\n    const item = 255 - view[i]\r\n    view[i] = item\r\n  }\r\n  return view.buffer\r\n})\r\ninterceptor.bind(monkey).bind(ball)\r\n// or\r\n// interceptor.bind([ monkey, ball ])\r\n\r\n// without interception\r\n// const monkey = Receptionist.createAsset('./monkey.glb')\r\n// const ball = Receptionist.createAsset('./ball.glb')\r\n\r\nconst gltfLoader = new GLTFLoader()\r\nconst loader = Receptionist.createLoader(gltfLoader)\r\nloader.bind(monkey).bind(ball)\r\n// or\r\n// loader.bind([ monkey, ball ])\r\n\r\nconst receptionist = new Receptionist()\r\nreceptionist\r\n    .onLoad(data => {\r\n      data.forEach((item) => {\r\n        scene.add(item.scene)\r\n      })\r\n    })\r\n    .onProgress(progress => {\r\n      console.log(`progress: ${progress}`)\r\n    })\r\n    .onError(err => {\r\n      console.log(`error: ${err}`)\r\n    })\r\n\r\nreceptionist.load(monkey).load(ball)\r\n// or\r\n// receptionist.load([ monkey, ball ])\r\n\r\nconst animate = () => {\r\n  controls.update()\r\n  renderer.render(scene, camera)\r\n}\r\n\r\nconst onWindowResize = () => {\r\n  camera.aspect = window.innerWidth / window.innerHeight\r\n  camera.updateProjectionMatrix()\r\n  renderer.setSize(window.innerWidth, window.innerHeight)\r\n}\r\n\r\nwindow.addEventListener('resize', onWindowResize)\r\n\r\nrenderer.setAnimationLoop(animate)\r\n```\r\n\r\n## API\r\n\r\n```\r\nnew receptionist()\r\n```\r\n\r\n### `static` createAsset\r\n\r\nCreate a new asset instance.\r\n\r\n```\r\nReceptionist.createAsset(url: string): Asset\r\n```\r\n\r\n### `static` createLoader\r\n\r\n新建加载器实例\r\nCreate a new loader instance.\r\n\r\n```\r\nReceptionist.createLoader(loader: THREE.Loader): Loader\r\n```\r\n\r\n### `static` createInterceptor\r\n\r\nCreate a new interceptor instance.\r\n\r\n```\r\nReceptionist.createInterceptor(handler: HandlerIntercept): Interceptor\r\n```\r\n\r\n### onLoad\r\n\r\nListening for the load completion messages for all assets.\r\n\r\n```\r\ntype handlerLoad = (data: unknown) => void\r\n\r\nonLoad(onLoad: handlerLoad): this\r\n```\r\n\r\n### onProgress\r\n\r\nListening for the load progress messages for assets.\r\n\r\n```\r\ntype handlerProgress = (progress: number) => void\r\n\r\nonProgress(onProgress: handlerProgress): this\r\n```\r\n\r\n### onError\r\n\r\nListening for the error messages for all assets.\r\n\r\n```\r\ntype handlerError = (err: unknown) => void\r\n\r\nonError(onError: handlerError): this\r\n```\r\n\r\n## Asset API\r\n\r\n### onLoad\r\n\r\nListening for the load completion messages for this asset.\r\n\r\n```\r\ntype handlerLoad = (data: unknown) => void\r\n\r\nonLoad(onLoad: handlerLoad): this\r\n```\r\n\r\n### onProgress\r\n\r\nListening for the load progress messages for this asset.\r\n\r\n```\r\ntype handlerProgress = (progress: number) => void\r\n\r\nonProgress(onProgress: handlerProgress): this\r\n```\r\n\r\n### onError\r\n\r\nListening for the error messages for this asset.\r\n\r\n```\r\ntype handlerError = (err: unknown) => void\r\n\r\nonError(onError: handlerError): this\r\n```\r\n\r\n## Loader API\r\n\r\n### bind\r\n\r\nBind assets. Use loaders in the loading process for these assets. Each asset should be bound with a loader.\r\n\r\n```\r\nbind(asset: Asset | Asset[]): this\r\n```\r\n\r\n## Interceptor API\r\n\r\n### bind\r\n\r\nBind assets. Whether to use interceptors in the loading process for these assets.\r\n\r\n```\r\nbind(asset: Asset | Asset[]): this\r\n```","readmeFilename":"README.md"}