Boids is an implementation of the boids algorithm. This can be used for simulation flock behavior such as birds or fish in 3D space. It uses a grid implementation for fast lookups.
BoidsController class defines a container for boids entities. All entities (flock or obstalces) are added to BoidsController. BoidsController calculates and updates entity positions and velocities.
BoidSystem is the wrapper for BoidsController to make it work inside a Decentraland SDK. The responsibility of this class is to create a new BoidsController instance with the received data and run the requested iterations in this isolated context.
setupBoids is the setup class. It will initialize the BoidController. Here can define here the area, flock, obsticles, predators, subGrid count
BoidEntity class defines an entitiy model which has a position and a velocity. Also it has some utiliy methods.
Grid class creates cubic grid for spatial partitioning. This helps lookups to be performed faster for nearby entities. More information can be found here: http://gameprogrammingpatterns.com/spatial-partition.html
/src/boids/Constants.js
See Debug Markers such as grid markers, boundary top/bottom, obstacles, seek and prediator entities
//see debug markers for seek/obsticle/predator
VISIBLE_OBSTACLES:boolean = true
VISIBLE_SEEK:boolean = true
VISIBLE_PREDATOR:boolean = true
// see boundary grid markers
SHOW_DEBUG_BOUNDARY_MARKERS:boolean = true
// see boundary planes (top,bottom)
SHOW_DEBUG_BOUNDARY_PLANES:boolean = true
/src/config.ts
TEST_CONTROLS_ENABLE = true
/src/boids/setupBoids.js
see initBoidController for creation of all entities types. Some flags of note include
//SETUP BOUNDARIES
const parcelSize = 15.5
const width = parcelSize
const depth = parcelSize * 2
const height = 5
const heightBottomOffset = 1
const subGrids = 4 //large grid count makes all fish operating the same get reduced
/*
300 - 1 subgrid
600 - 2 subgrid
700 - 3 subgrid*
*/
//SETUP INITIALIZATION OF BOIDS
const flockEntityCount = 80
//will randomly place these
const obstacleEntityCount = 0
const predatorCount = 0
const seekCount = 0
Install the CLI
Download and install the Decentraland CLI by running the following command:
npm i -g decentraland
Previewing the scene
Open this folder on the command line, then run:
dcl start
Any dependencies are installed and then the CLI opens the scene in a new browser tab.
If you own any parcels of land in Decentraland, or have permissions to deploy to someone else's, you can publish this project.
- Make sure the scene parcels in
scene.json
match those you own or have permissions on. - Run
dcl deploy
on the project folder - This will open a browser tab to confirm. Metamask will prompt you to sign.
Note: Make sure you are using the wallet that owns the parcels or has permissions.
If you don't own parcels in Decentraland or are not ready to publish your scene to the world, you can share your creations by uploading your scenes to a free hosting service.
See Upload a preview for instructions on how to do this.
Learn more about how to build your own scenes in our documentation site.
Find more example scenes, tutorials and helper libraries in the Awesome Repository.
If you need any help, join Decentraland's Discord, where you'll find a vibrant community of other creators who are eager to help. You're sure to find help in the #SDK support channel.
This scene is protected with a standard Apache 2 licence. See the terms and conditions in the LICENSE file.
Code here is an adaptation of https://ercang.github.io/boids-js/3-boids-webworkers/
https://github.com/ercang/boids-js
BoidJS has standard MIT licence. See the terms and conditions in the LICENSE file.