{"id":25597961,"url":"https://github.com/dukuo/physar","last_synced_at":"2025-04-13T03:41:39.513Z","repository":{"id":43980695,"uuid":"245708698","full_name":"dukuo/physar","owner":"dukuo","description":"Use Cannon.js physics in your Spark AR projects easily! ","archived":false,"fork":false,"pushed_at":"2023-01-07T15:41:33.000Z","size":3468,"stargazers_count":10,"open_issues_count":15,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:51:26.360Z","etag":null,"topics":["3d","3d-physics","arfilter","cannonjs","instagram","javascript","javascript-library","mixedreality","npm-package","physics","programming","sparkar","spook","xr"],"latest_commit_sha":null,"homepage":"https://npmjs.org/physar","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dukuo.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}},"created_at":"2020-03-07T21:33:21.000Z","updated_at":"2023-07-13T15:44:36.000Z","dependencies_parsed_at":"2023-02-07T13:46:21.407Z","dependency_job_id":null,"html_url":"https://github.com/dukuo/physar","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dukuo%2Fphysar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dukuo%2Fphysar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dukuo%2Fphysar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dukuo%2Fphysar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dukuo","download_url":"https://codeload.github.com/dukuo/physar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248660881,"owners_count":21141367,"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":["3d","3d-physics","arfilter","cannonjs","instagram","javascript","javascript-library","mixedreality","npm-package","physics","programming","sparkar","spook","xr"],"created_at":"2025-02-21T13:19:55.250Z","updated_at":"2025-04-13T03:41:39.489Z","avatar_url":"https://github.com/dukuo.png","language":"JavaScript","readme":"\u003cp style=\"text-align:center\"\u003e\n  \u003cimg src=\"assets/physar_logo.png\"\u003e\n\u003c/p\u003e\n\n\u003cp style=\"text-align:center\"\u003eCannon.js physics for your Spark AR projects.\u003c/p\u003e\n\n\u003cbr /\u003e\n\u003ch2\u003eEnhance your projects with cannon.js Physics!\u003c/h2\u003e\n\u003cp\u003eThis project is in alpha stage, with a working implementation for sphere, box and ground shapes. More documentation soon.\u003c/p\u003e\n\n\u003ch3 class=\"install\"\u003eInstallation\u003c/h3\u003e\n\n\u003cp style=\"text-align:center\"\u003e\u003ccode\u003enpm install physar\u003c/code\u003e\u003c/p\u003e\n\n\u003ch3\u003eUsage\u003c/h3\u003e\nPhysar works by creating a Physics world and mirroring your Spark objects in this world. After that, computations are done with all the physics elements and in turn Spark objects are updated with their respective positions and rotations. For each of your scene objects you must create an equal physics object in your code. \n\nAfter [installing](#install) import Physar to your code:\n\n```js\nimport Physar from 'physar'\n```\n\nAdd Spark's `Scene` module reference to add your objects from Spark.\n\n```js\nconst Scene = require('Scene');\n```\n\nInitialize the physics world:\n\n```js\nconst gravity = {\n    x: 0,\n    y: -9.82,\n    z: 0\n};\nconst physar = new Physar(gravity);\n```\n\u003ci\u003e-9.82 m/s\u003csup\u003e2\u003c/sup\u003e is the average measure of the strength of Earth's gravitational field. You can set a higher negative or positive value on any axis to enhance the strength and direction of the physics in your scene.\u003c/i\u003e\n\nImport your spark object reference. In this case, a sphere that was imported from the AR Library:\n```js\nconst sphere = Scene.root.find('SphereObject')\n```\nWhere `SphereObject` is the name of the object in your scene. \n\nAdd a plane to your Spark AR scene to create a ground. In this example the plane is called `plane01`. Reference it in your code:\n\n```js\nconst groundPlane = Scene.root.find('plane01');\n```\n\nNext, setup object properties for each of the spark objects you want to enable physics for:\n\n```js\nconst sphereProps = {\n  body: {\n    mass: 1,\n    radius: .01,\n    transform: {\n      position: {\n        x: 0,\n        y: 2, \n        z: 0\n      }\n    }\n  }\n}\n```\n\nYou could add no props, but by setting it like above you can create an initial position and rotation for your objects, as well as `mass` or `radius` properties (more about it soon). By default all axis of `position` and `rotation` are synchronized between Spark and Physar. \n\nYou can also add synchronization settings to constraint movement of your spark objects, more on that soon. \n\nNow that we have our properties, we can add the object the object to the physics world. But first, let's add a ground plane so that our objects don't fall infinitely in your scene. \n\n```js\n\nphysar.createObject(groundPlane, 'ground', {});\n\n```\n\nAdd the sphere object with its properties to the world:\n\n```js\nphysar.createObject(sphere, 'sphere', sphereProps);\n```\n\nAnd finally, start the physics simulation:\n\n```js\nphysar.start();\n```\n\nThe sphere should have physics now!\n\n\n\u003ch3\u003eExamples\u003c/h3\u003e\n\n\u003cp\u003eCheck \u003ccode\u003eexamples/spark\u003c/code\u003e for a basic physics examples with spheres and boxes.\u003c/p\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdukuo%2Fphysar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdukuo%2Fphysar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdukuo%2Fphysar/lists"}