-
Notifications
You must be signed in to change notification settings - Fork 124
Creating Collision Meshes
We use the Physics Body Editor (download here) to create collision meshes.
The editor is provided as a JAR file. On Windows, you can usually run it by double-clicking it in the file explorer. If that doesn't work, or if you're using MacOS or Linux, then you can also start it from the command line.
java -jar physics-body-editor.jar
To start with, create a new project (file name <object>.json
).
Once that's done, you can create a new collision mesh using the [+] New
button. Select Create body from image
and it should prompt you to pick a sprite to trace over. Once selected, the editor should create a new rigidbody for you to start editing.
You can draw polygons by left-clicking on the image. Each click will place a new vertex of the shape. To end the shape, click back onto the first vertex again.
You can draw circles by holding down the Control key and then the left mouse button, dragging the mouse outwards from the centre-point of the circle. Release the left mouse button to place the circle.
Save the project with the Save
button and open-up the save file in your preferred text editor. You should see something like the following.
{"rigidBodies":[{"name":"Name","imagePath":"<DestSolPath>/modules/core/assets/ships/techieOrbiter.png","origin":{"x":0,"y":0},"polygons":[[{"x":0.5100000500679016,"y":0.2487500011920929},{"x":0.4000000059604645,"y":0.013750016689300537},{"x":0.5074999928474426,"y":0.013750016689300537},{"x":0.7300000190734863,"y":0.23875001072883606},{"x":0.7300000190734863,"y":0.2837500274181366}],[{"x":0.7275000214576721,"y":0.7162500023841858},{"x":0.7225000262260437,"y":0.7712500095367432},{"x":0.5049999952316284,"y":0.9887499809265137},{"x":0.4024999737739563,"y":0.9812500476837158},{"x":0.5274999737739563,"y":0.7337499856948853}],[{"x":0.5274999737739563,"y":0.7337499856948853},{"x":0.4625000059604645,"y":0.6512500047683716},{"x":0.4749999940395355,"y":0.3487499952316284},{"x":0.5100000500679016,"y":0.2487500011920929},{"x":0.7300000190734863,"y":0.2837500274181366}],[{"x":0.7300000190734863,"y":0.2837500274181366},{"x":0.7900000214576721,"y":0.29374998807907104},{"x":0.9724999666213989,"y":0.5062500238418579},{"x":0.7775000333786011,"y":0.7112499475479126},{"x":0.7275000214576721,"y":0.7162500023841858},{"x":0.5274999737739563,"y":0.7337499856948853}],[{"x":0.3124999701976776,"y":0.7712500095367432},{"x":0.3050000071525574,"y":0.8087500333786011},{"x":0.13249996304512024,"y":0.9887499809265137},{"x":0.024999946355819702,"y":0.9787499308586121},{"x":0.14749997854232788,"y":0.7362499833106995}],[{"x":0.14749997854232788,"y":0.7362499833106995},{"x":0.07249999046325684,"y":0.731249988079071},{"x":0.17750000953674316,"y":0.5087499618530273},{"x":0.3675000071525574,"y":0.7162500023841858}],[{"x":0.3675000071525574,"y":0.7162500023841858},{"x":0.3124999701976776,"y":0.7712500095367432},{"x":0.14749997854232788,"y":0.7362499833106995}],[{"x":0.17750000953674316,"y":0.5087499618530273},{"x":0.35750001668930054,"y":0.2862499952316284},{"x":0.4074999988079071,"y":0.2912500202655792},{"x":0.4749999940395355,"y":0.3487499952316284},{"x":0.4625000059604645,"y":0.6512500047683716},{"x":0.4099999964237213,"y":0.71875},{"x":0.3675000071525574,"y":0.7162500023841858}],[{"x":0.17750000953674316,"y":0.5087499618530273},{"x":0.08249998092651367,"y":0.26625001430511475},{"x":0.14249995350837708,"y":0.2512500286102295},{"x":0.3174999952316284,"y":0.23125001788139343},{"x":0.35750001668930054,"y":0.2862499952316284}],[{"x":0.14249995350837708,"y":0.2512500286102295},{"x":0.024999946355819702,"y":0.0337500274181366},{"x":0.12749993801116943,"y":0.02375003695487976},{"x":0.33500000834465027,"y":0.2187500298023224},{"x":0.3174999952316284,"y":0.23125001788139343}]],"circles":[],"shapes":[{"type":"POLYGON","vertices":[{"x":0.024999946355819702,"y":0.0337500274181366},{"x":0.14249995350837708,"y":0.2512500286102295},{"x":0.08249998092651367,"y":0.26625001430511475},{"x":0.17750000953674316,"y":0.5087499618530273},{"x":0.07249999046325684,"y":0.731249988079071},{"x":0.14749997854232788,"y":0.7362499833106995},{"x":0.024999946355819702,"y":0.9787499308586121},{"x":0.13249996304512024,"y":0.9887499809265137},{"x":0.3050000071525574,"y":0.8087500333786011},{"x":0.3124999701976776,"y":0.7712500095367432},{"x":0.3675000071525574,"y":0.7162500023841858},{"x":0.4099999964237213,"y":0.71875},{"x":0.4625000059604645,"y":0.6512500047683716},{"x":0.5274999737739563,"y":0.7337499856948853},{"x":0.4024999737739563,"y":0.9812500476837158},{"x":0.5049999952316284,"y":0.9887499809265137},{"x":0.7225000262260437,"y":0.7712500095367432},{"x":0.7275000214576721,"y":0.7162500023841858},{"x":0.7775000333786011,"y":0.7112499475479126},{"x":0.9724999666213989,"y":0.5062500238418579},{"x":0.7900000214576721,"y":0.29374998807907104},{"x":0.7300000190734863,"y":0.2837500274181366},{"x":0.7300000190734863,"y":0.23875001072883606},{"x":0.5074999928474426,"y":0.013750016689300537},{"x":0.4000000059604645,"y":0.013750016689300537},{"x":0.5100000500679016,"y":0.2487500011920929},{"x":0.4749999940395355,"y":0.3487499952316284},{"x":0.4074999988079071,"y":0.2912500202655792},{"x":0.35750001668930054,"y":0.2862499952316284},{"x":0.3174999952316284,"y":0.23125001788139343},{"x":0.33500000834465027,"y":0.2187500298023224},{"x":0.12749993801116943,"y":0.02375003695487976}]}]}],"dynamicObjects":[]}
What you'll want to do with this depends on which type of object you are creating a collision mesh for.
For ships, copy the first element of the rigidBodies
array and insert it as the rigidBody
value in the ship JSON.
Copy the entire project file into assets/asteroids/asteroids.json
.
Copy the entire project file into assets/mazes/<mazeType>/<mazeType>Maze.json
, re-naming the name
values to correspond to the ResourceUrn
of the sprite used (e.g. core:jumkMazePass_0
).