npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ecsy-three

v0.1.3

Published

ECSY three.js bindings

Downloads

664

Readme

ecsy-three

We created ecsy-three to facilitate developing applications using ECSY and three.js. It is a set of components and systems for interacting with ThreeJS from ECSY. Right now, we have a core API design that we are iterating on and we hope to build higher level abstractions against.

Getting Started

If you aren't familiar with the ECSY API, you should read the ECSY Documentation first.

View Demo on Glitch

ECSY Three Core

The core API for ecsy-three is just a few additional concepts on top of ECSY.

First, you must create an instance of ECSYThreeWorld instead of World.

import { ECSYThreeWorld } from "ecsy-three";

const world = new ECSYThreeWorld();

ECSYThreeWorld registers a custom ECSYThreeEntity class with some helper methods for working with ThreeJS.

You can add any Object3D to an ECSYThreeEntity using addObject3DComponent(object3D, parentEntity)

import { Scene, Mesh, BoxBufferGeometry, MeshBasicMaterial, TextureLoader } from "three";

const scene = world
  .createEntity()
  .addObject3DComponent(new Scene()); // scene is the root Object3d and has no parent

const geometry = new BoxBufferGeometry(20, 20, 20);

const material = new MeshBasicMaterial({
  map: new TextureLoader().load("./textures/crate.gif")
});

const mesh = new Mesh(geometry, material);

const box = world
  .createEntity()
  .addObject3DComponent(mesh, scene); // mesh is parented to the scene entity

addObject3DComponent() will add the Object3DComponent as well as a series of TagComponents. For example, when adding a Scene object3d to an entity, it will also add the SceneTagComponent. For the Mesh object3d, a MeshTagComponent will be added. These tag components can be used in System queries to get instances of certain object3ds. You can then use entity.getObject3D() to get the object3d for that entity.

import { MeshTagComponent, Object3DComponent } from "ecsy-three";
import { System } from "ecsy";

class RandomColorSystem extends System {
  execute(delta) {
    this.queries.entities.results.forEach(entity => {
      // This will always return a Mesh since we are querying for the MeshTagComponent
      const mesh = entity.getObject3D();
      mesh.material.color.setHex(Math.random() * 0xffffff);
    });
  }
}

RandomColorSystem.queries = {
  entities: {
    components: [MeshTagComponent, Object3DComponent]
  }
};

If you want to remove an Object3D from an entity, you can call entity.removeObject3DComponent() which will remove the object3D from the entity and detach it from its current parent as well as removing any object3d TagComponents.

Finally, if you want to get the entity for a give object3d you can use object3D.entity. This property is added to the object3D when calling entity.addObject3DComponent and removed when calling entity.removeObject3DComponent().

That is essentially all there is to the ecsy-three core API at this time. With just these few additional components you can write most ThreeJS code against ECSY.