hubs-plugin-api icon indicating copy to clipboard operation
hubs-plugin-api copied to clipboard

ECSY API

Open robertlong opened this issue 5 years ago • 0 comments

This is what I'm thinking right now. We'd call the register callback in Spoke and Hubs when creating the World. I think we'd need a way to conditionally register components/systems if in Spoke/Hubs.

import { Component, System, Types } from "ecsy";
import { Types } from "ecsy-three";

class Rotating extends Component {
  static schema = {
    speed: { type: Types.Number, default: 0.5 },
    axis: { type: Types.Vector3, default: 0.5 }
  };
}

class RotatingSystem extends System {
  static queries = {
    entities: { components: [Rotating] }
  };

  execute(dt) {
    this.queries.entities.forEach(entity => {
      const object3D = entity.getObject3D();
      const rotating = entity.getComponent(Rotating);
      object3D.rotateOnAxis(rotating.axis, rotating.speed * dt);
    });
  }
}

export function register(world) {
  world.registerSystem(RotatingSystem);
  world.registerComponent(Rotating);
}

robertlong avatar Jun 12 '20 15:06 robertlong