ModuleSystem

πŸ‘

This class includes basic event system

.on(), .off(), .emit() methods are supported

ModuleSystem provides API for classes that will use Modules

.integrateModules(source[optional])

This method applies all modules from .modules collection. If source (should be a component) is provided - will replace .modules with source's one before executing modules.

πŸ‘

This method is frequently used in core

.applyBridge(bridgeMap)

.applyBridge() makes component-specific API to work with modules. Let's say your bridgeMap is:

{
  "geometry": new THREE.Geometry()
}

Then .applyBridge() will pass this value (THREE.Geometry) to first module if it has the following bridge in it's structure.

πŸ“˜

Helper

Remember that bridge that we talk about is a function that has input and output. bridge modifies your input and returns you an output.

The following implementation allows modules access your geometry & material objects and modify them and is strongly recommended if you want to get maximum flexibility from WhitestormJS.

// ...

export default class BasicSphere extends MeshComponent {
  build() {
    const {geometry, material} = this.applyBridge({
      geometry: new THREE.SphereGeometry(3, 16, 16),
      material: new THREE.MeshBasicMaterial({color: 0xff0000})
    })
    
    return new THREE.Mesh(
      geometry,
      material
    );
  }
}

πŸ‘

Returns object of modified values.

.applyModule(module, push = true)

.applyModule is also used in .integrateModules() function. It does exactly what its name says (applies module to component or app).

app.applyModule(new WHS.controls.OrbitModule()); // OrbitControls.

πŸ‘

Returns module that was applied.

.module()

πŸ“˜

.module() is a piped version of .applyModule(). It returns this - app/component.

component
  .module(new Module1())
  .module(new Module2())
  .module(new Module3())