GithubHelp home page GithubHelp logo

megavr / ecsy-babylon Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.19 MB

babylon.js ecsy binding and helpers

License: MIT License

JavaScript 44.40% TypeScript 55.60%
ecsy babylonjs typescript webgl webvr webxr

ecsy-babylon's Introduction

ecsy-babylon

babylon.js ecsy binding and helpers

Getting Started

  1. Add script tags of Babylon.js, ecsy and ecsy-babylon.
  2. Add a canvas tag as container.
  3. Build a basic scene.
<html>
  <head>
    <script src="https://unpkg.com/[email protected]/build/ecsy.min.js"></script>
    <script src="https://unpkg.com/[email protected]/babylon.js"></script>
    <script src="https://unpkg.com/@megavr/[email protected]/dist/ecsy-babylon.min.js"></script>
  </head>
  <body>
    <canvas id="renderCanvas" style="width: 100%; height: 100%"></canvas>
    <script>
      /** Step 1 - Preparation */
      // create a ECSY world object
      const world = new ECSY.World();
      // register necessary systems from ecsy-babylon(global name: EB)
      world
        .registerSystem(EB.GameSystem)
        .registerSystem(EB.TransformSystem)
        .registerSystem(EB.CameraSystem)
        .registerSystem(EB.MeshSystem)
        .registerSystem(EB.InputSystem);
      
      /** Step 2 - Start the game engine */
      // get canvas element
      const canvas = document.getElementById("renderCanvas");
      // get GameSystem object
      const game = world.getSystem(EB.GameSystem);
      // start GameSystem by providing canvas object
      game.start(canvas);
      
      /** Step 3 - Start to build your scene */
      // add a scene
      const scene = world.createEntity().addComponent(EB.Scene);
      // add a camera
      const camera = world.createEntity()
        .addComponent(EB.Transform)
        .addComponent(EB.Camera);
      // up camera to height of eyes at standing human
      camera.getMutableComponent(EB.Transform).position.y = 1.7;
      // add a box
      const box = world.createEntity()
        .addComponent(EB.Transform)
        .addComponent(EB.Mesh);
      // put box in front of camera
      box.getMutableComponent(EB.Transform).position.z = 3;
      
      /** Step 4 - Add some interaction to your scene */
      // add keyboard input
      world.createEntity().addComponent(EB.Input, { onKey: onKey });
      // rotate box when press R/r key
      function onKey(key, down) {
        if (down) {
          if (key === "R" || key === "r") {
            box.getMutableComponent(EB.Transform).rotation.y += 30;
          }
        }
      }
    </script>
  </body>
</html>

Examples

https://megavr.github.io/ecsy-babylon-examples/

ecsy-babylon's People

Contributors

shang-huang avatar

Stargazers

 avatar  avatar

Watchers

 avatar

ecsy-babylon's Issues

Rename Repository

Could be worth renaming this repo as it conflicts with the ecsy-babylon repo cited in the docs. This one shows up first in a google search first which can confuse people.

google

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.