{"id":20173508,"url":"https://github.com/w3reality/three-laser-pointer","last_synced_at":"2025-04-10T03:17:29.986Z","repository":{"id":32534676,"uuid":"134953858","full_name":"w3reality/three-laser-pointer","owner":"w3reality","description":"Interactive laser object for VR-like scenes","archived":false,"fork":false,"pushed_at":"2025-02-04T01:19:38.000Z","size":9421,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T03:17:21.885Z","etag":null,"topics":["laser","pointer","threejs","vr"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/w3reality.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-26T11:00:59.000Z","updated_at":"2025-03-04T15:55:45.000Z","dependencies_parsed_at":"2023-02-12T00:01:28.962Z","dependency_job_id":"f4bc59ce-e62f-491a-aea9-b610417443b2","html_url":"https://github.com/w3reality/three-laser-pointer","commit_stats":{"total_commits":184,"total_committers":3,"mean_commits":"61.333333333333336","dds":0.3532608695652174,"last_synced_commit":"b2cf075fdd5e7b39575ea653498af61459a886f6"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3reality%2Fthree-laser-pointer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3reality%2Fthree-laser-pointer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3reality%2Fthree-laser-pointer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3reality%2Fthree-laser-pointer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w3reality","download_url":"https://codeload.github.com/w3reality/three-laser-pointer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148247,"owners_count":21055548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laser","pointer","threejs","vr"],"created_at":"2024-11-14T01:36:26.110Z","updated_at":"2025-04-10T03:17:29.964Z","avatar_url":"https://github.com/w3reality.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# three-laser-pointer\n\n[![NPM][npm-badge]][npm-url]\n[![MIT licensed][mit-badge]][mit-url]\n[![CI][actions-badge]][actions-url]\n\n[npm-badge]: https://img.shields.io/npm/v/three-laser-pointer.svg\n[npm-url]: https://www.npmjs.com/package/three-laser-pointer\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: https://github.com/w3reality/three-laser-pointer/blob/master/LICENSE\n[actions-badge]: https://github.com/w3reality/three-laser-pointer/workflows/CI/badge.svg\n[actions-url]: https://github.com/w3reality/three-laser-pointer/actions\n\n**three-laser-pointer** is a three.js based library class that provides a reflective laser pointer. It is especially suitable for adding a laser pointing interface in VR-like scenes where the camera is serving as first-person shooter, and not limited to this use case.\n\nThe laser object has methods that are useful for\n\n- shooting interactive laser beams that self-reflect on `THREE.Mesh` objects in the scene,\n- drawing dynamic 3D lines that consist of multiple line segments (good for making CAD-like tools), and\n- mouse-to-laser translation (see how it works in demos).\n\n## Demo\n\nWe present two live demos using this three-laser-pointer library.\n\n- [demo-api](https://w3reality.github.io/three-laser-pointer/examples/demo-api/index.html):\n    Shooting a reflective laser onto simple `THREE.Mesh` objects. Observe that the source/target points, colors, and raytracing parameters are fully configurable via API.\n\n    [![image](https://w3reality.github.io/three-laser-pointer/examples/demo-api/laser-0.jpg)](https://w3reality.github.io/three-laser-pointer/examples/demo-api/index.html)\n\n- [demo-terrains](https://w3reality.github.io/three-laser-pointer/examples/demo-terrains/dist/index.html):\n    Laser interaction with `THREE.Mesh` models including a terrain. Selecting \"Measure\" in Laser Mode allows us to pick precise 3D points on the models and measure the Euclidean distances between them. Credits: we have used [the THREE.Terrain library](https://github.com/IceCreamYou/THREE.Terrain) for generating the terrain model.\n\n    [![image](https://w3reality.github.io/three-laser-pointer/examples/demo-terrains/dist/measure-0.jpg)](https://w3reality.github.io/three-laser-pointer/examples/demo-terrains/dist/index.html)\n\n## Setup\n\n**Installation**\n\n```\n$ npm i three-laser-pointer\n```\n\n**Loading**\n\nScript tag: use `Laser` after\n\n```\n\u003cscript src=\"dist/three-laser-pointer.min.js\"\u003e\u003c/script\u003e\n```\n\nES6:\n\n```\nimport Laser from 'dist/three-laser-pointer.esm.js';\n```\n\n## Usage\n\n- VR-like laser pointing\n\n```js\n// create and add a red laser in the scene\nvar laser = new Laser({color: 0xff0000});\nscene.add(laser);\n\nvar pt = new THREE.Vector3(0, 0, -1); // the target point to shoot\n\n// set the source point relative to the camera\n// with offset (0.3, -0.4, -0.2)\nlaser.setSource(new THREE.Vector3(0.3, -0.4, -0.2), camera);\n\n// shoot the target from the source point\nlaser.point(pt);\n```\n\n- VR-like laser pointing with raytrace enabled against `THREE.Mesh` objects in the scene\n\n```js\n// create and add a green laser in the scene\nvar laser = new Laser({color: 0x00ff00});\nscene.add(laser);\n\nvar pt = new THREE.Vector3(0, 0, 1); // the target point to shoot\n\n// prepare an array of THREE.Mesh objects that interact with the laser\nvar meshes = [...];\n\n// set the source point relative to the camera\nlaser.setSource(new THREE.Vector3(0.3, -0.4, -0.2), camera);\n\n// shoot the target with raytrace considering the meshes in the scene\nlaser.pointWithRaytrace(pt, meshes);\n```\n\n## API\n\n`Laser`\n\n- `constructor(opts={})`\n\n    Create a laser object with optional parameters. For example, `new Laser({color: 0x00ff00, maxPoints: 16})` creates a green laser object that can maximally consist of 15 (=16-1) line segments.\n\n    - `opts.color`=0xff0000 **number (integer)** An integer (0x000000 - 0xffffff) encoding an RGB color.\n    - `opts.maxPoints`=256 **number (integer)** The max number of 3D points that consist of the laser.\n    - `opts.infLength`=9999.0 **number** The length of the last laser segment when raytracing goes to an infinity point.\n\n- `setSource(src, camera=null)`\n\n    Set the values of `src` to the source point of the laser. When `camera` is provided, `src` is regarded as relative to the camera (i.e. camera coordinates). If not, `src` is interpreted as world coordinates.\n\n    - `src` **THREE.Vector3**\n    - `camera` **THREE.PerspectiveCamera**\n\n- `getSource()`\n\n    Get a new vector instance with values corresponding to the current source point.\n\n    Returns **THREE.Vector3**\n\n- `point(pt, color=null)`\n\n    Shoot `pt` by the laser rendering a line segment connecting the source point of the laser and `pt`. Optionally, `color` can be specified.\n\n    - `pt` **THREE.Vector3** The target point to shoot.\n    - `color` **number (integer)** 0x000000 - 0xffffff\n\n- `pointWithRaytrace(pt, meshes=[], color=null, maxReflect=16)`\n\n    Shoot `pt` by the laser with raytracing enabled. Up to `maxReflect` times, ray reflections by provided `meshes` are computed and rendered. (Note: regardless of `maxReflect`, the number of reflections is also bounded less than or equal to `maxPoints-2`. `maxPoints` can be adjusted when creating a laser object.)\n\n    - `pt` **THREE.Vector3** The target point to shoot.\n    - `meshes` **Array\\\u003cTHREE.Mesh\\\u003e**\n    - `color` **number (integer)** 0x000000 - 0xffffff\n    - `maxReflect` **number (integer)** The max number of reflections considered.\n\n- `getPoints()`\n\n    Get an array of the (copied) points that consist of the laser.\n\n    Returns **Array\\\u003cTHREE.Vector3\\\u003e**\n\n- `getMeshesHit()`\n\n    Get an array of the meshes that are hit by the laser after calling `pointWithRaytrace()`.\n\n    Returns **Array\\\u003cTHREE.Mesh\\\u003e**\n\n- `updatePoints(arr, isFlatten=false)`\n\n    Update (by overriding) the points that represent the laser. If `isFlatten` is `true`, `arr` can be a flatten **number** array, i.e. `[x0, y0, z0, x1, y1, z1, ...]`.\n\n    - `arr` **Array\\\u003cTHREE.Vector3 \\| number\\\u003e**\n    - `isFlatten` **boolean**\n\n- `clearPoints()`\n\n    Clear the points that consist of the laser. (Thereafter, `getPoints()` will return `[]`.)\n\n- `raycastFromCamera(mx, my, width, height, camera, meshes, recursive=false)`\n\n    A utility method that casts a mouse-ray to `meshes` provided. If there are intersects, it returns the nearest intersect from the camera. Otherwise, it returns `null`.\n\n    - `mx` **number** Coordinate x of a canvas point.\n    - `my` **number** Coordinate y of a canvas point.\n    - `width` **number** Canvas width.\n    - `height` **number** Canvas height.\n    - `camera` **THREE.PerspectiveCamera**\n    - `meshes` **Array\\\u003cTHREE.Mesh\\\u003e** An array of meshes to test raycasting with.\n    - `recursive` **boolean** If true, test for all descendant mesh objects.\n\n    Returns **Object \\| null** An [intersect object](https://threejs.org/docs/#api/core/Raycaster.intersectObject) of three.js.\n\n- `setColor(color)`\n\n    Set the RGB color of the laser.\n\n    - `color` **number (integer)** An integer (0x000000 - 0xffffff) encoding an RGB color.\n\n- `getColor()`\n\n    Get the RGB color of the laser.\n\n    Returns **number (integer)** An integer (0x000000 - 0xffffff) encoding an RGB color.\n\n## Build\n\n```\n$ npm i\n$ npm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3reality%2Fthree-laser-pointer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw3reality%2Fthree-laser-pointer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3reality%2Fthree-laser-pointer/lists"}