{"id":20589729,"url":"https://github.com/patrick-s-young/react-three-cannon-hinge-constraint","last_synced_at":"2026-04-28T16:35:47.804Z","repository":{"id":54095300,"uuid":"522040326","full_name":"patrick-s-young/react-three-cannon-hinge-constraint","owner":"patrick-s-young","description":"Demo of @react-three/cannon's useHingeConstraint physics hook","archived":false,"fork":false,"pushed_at":"2022-08-06T20:55:19.000Z","size":295,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-09T00:23:39.806Z","etag":null,"topics":["leva","physics-simulation","react-three-cannon","react-three-fiber","threejs","zustand"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrick-s-young.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-06T19:50:51.000Z","updated_at":"2022-08-06T19:56:07.000Z","dependencies_parsed_at":"2022-08-13T06:40:48.279Z","dependency_job_id":null,"html_url":"https://github.com/patrick-s-young/react-three-cannon-hinge-constraint","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/patrick-s-young/react-three-cannon-hinge-constraint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-s-young%2Freact-three-cannon-hinge-constraint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-s-young%2Freact-three-cannon-hinge-constraint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-s-young%2Freact-three-cannon-hinge-constraint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-s-young%2Freact-three-cannon-hinge-constraint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrick-s-young","download_url":"https://codeload.github.com/patrick-s-young/react-three-cannon-hinge-constraint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrick-s-young%2Freact-three-cannon-hinge-constraint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32390049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["leva","physics-simulation","react-three-cannon","react-three-fiber","threejs","zustand"],"created_at":"2024-11-16T07:31:11.186Z","updated_at":"2026-04-28T16:35:47.788Z","avatar_url":"https://github.com/patrick-s-young.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hinge Constraint With Cannon Hooks  \n\nIn this [@react-three/fiber](https://www.npmjs.com/package/@react-three/fiber) example, I leveraged [use-cannons](https://github.com/pmndrs/use-cannon)'s useHingeConstraint to create a collections of 'paddles' that can be set to\nrotate clockwise/counterclockwise at varying speeds. \n\nWith the hooks version of useHingeContraint, a ref is returned for accessing the api:\n\n```\nconst [, , hingeApi] = useHingeConstraint(doorRef, doorFrameRef, {\n collideConnected: false,\n axisA: [0, 1, 0],\n   axisB: [0, 1, 0],\n   pivotA: [-1.05, 0, 0],\n   pivotB: [0, 0, 0]\n }\n);\n```\n\nThen wrap the api in a useEffect with the speed state variable as a depency:\n\n```\nuseEffect(() =\u003e {\n hingeApi.setMotorSpeed(speed)\n}, [speed]);\n```\n\n![use-cannon-hinge-constraint_24fps](https://user-images.githubusercontent.com/42591798/183264955-0e765437-d773-4ae3-ac4d-082d63202f57.gif)\n\nThe slider was enabled by [leva](https://github.com/pmndrs/leva), a hook-based GUI library, and [zustand](https://www.npmjs.com/package/zustand), a state management solution. Both are brought to you by [Poimandres](https://pmnd.rs/).\n\n## View In Sandbox\n[codesandbox.io/s/rgccxz](https://codesandbox.io/s/rgccxz)\n\n## Running Locally\n\nMake sure you have [Node.js](http://nodejs.org/) installed.\n\n```sh\ngit clone https://github.com/patrick-s-young/react-three-cannon-hinge-constraint.git # or clone your own fork\ncd react-three-cannon-hinge-constraint\nnpm install\nnpm start\n```\n\n## Built With\n* [@react-three/fiber](https://www.npmjs.com/package/@react-three/fiber) - React renderer for three.js.\n* [@react-three/cannon](https://www.npmjs.com/package/@react-three/cannon) - React hooks for cannon-es, a rigid body physics engine.\n* [zustand](https://www.npmjs.com/package/zustand) - state-management solution that uses simplified flux principles.\n* [leva](https://github.com/pmndrs/leva) - hook-based GUI library.\n* [@react-three/drei](https://www.npmjs.com/package/@react-three/drei) - Helper library for @react-three/fiber.\n\n## Author\n\n* **Patrick Young** - [Patrick Young](https://github.com/patrick-s-young)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrick-s-young%2Freact-three-cannon-hinge-constraint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrick-s-young%2Freact-three-cannon-hinge-constraint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrick-s-young%2Freact-three-cannon-hinge-constraint/lists"}