Details of the FlockXR API and its methods are in API.md.
The blocks are defined in either blocks.js or blocks/ for each mesh, transformation (such as rotation) and other characteristic and operation. Those in blocks/ typically store block definitions in multiple files depending on their purpose. For example:
blocks/transform.jsstores the Blockly definitions for the blocks that handle transformations.create_boxinblocks/shapes.jscreates a box mesh in the Babylon.js canvas.load_objectinblocks/models.jsloads a mesh onto the canvas (where the actual game view is).
Each block has an init function and this function is intended to contain an event handler (this.setOnChange((changeEvent) => {...})) that enacts the change onto the mesh in the canvas itself once it is enacted inside the block. For example:
- the
create_boxblock definition inblocks/shapes.jscalls ahandleBlockChange(block, changeEvent)method when a modification is detected, whether that be within a field of the block or it simply being added to the existing FlockXR code.
For many blocks, this has already been implemented, and implementing synchronisation for the blocks that still require it is an ongoing work in progress.
Each block has code generated for it through Blockly (as described in CONTRIBUTING.md). Every time the canvas is initialised, whether that be at the start of running FlockXR or through the play button, this generated code is run via the executeCode function in execution.js.
When a change happens in the canvas editor, the blocks themselves also get updated. ui/gizmos.js handles all of this live updating through the way of a "gizmo" manager (called gizmoManager) that observes changes from the editor and updates the related blocks as they are enacted.
Within this code are several methods that get called to enact these changes within blocks to items in the canvas. These functions are not in the FlockXR API.
Defined in: ui/blockmesh.js
Called within updateOrCreateMeshFromBlock and updateMeshFromBlock
Retrieves the mesh associated with a particular block (block).
Defined in: ui/blockmesh.js
Called within handleBlockChange in each block's event handler.
Enacts an event (changeEvent) on a mesh associated with a particular block (block), whether that be the creation of that mesh itself or a transformation on it.
Defined in ui/blockmesh.js
Called within updateOrCreateMeshFromBlock
Enacts an update (changeEvent) on an existing mesh (mesh) associated with a particular block (block) using data entered within said block.
Defined in ui/addmeshes.js
Called within updateOrCreateMeshFromBlock
Creates a mesh on the Babylon.js canvas.
Defined in ui/blockmesh.js
Called within handleBlockDelete(event) and handleMeshLifecycleChange(block, changeEvent) in blocks.js
Removes a mesh associated with a particular block blockId from the mesh map (meshMap in the FlockXR codebase).