@megavr/ecsy-babylon
Version:
babylon.js ecsy binding and helpers
351 lines (348 loc) • 19.4 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ecsy-babylon@0.0.10</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">ecsy-babylon@0.0.10</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
<input type="checkbox" id="tsd-filter-only-exported" />
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<li>
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> ecsy-babylon@0.0.10</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#ecsy-babylon" id="ecsy-babylon" style="color: inherit; text-decoration: none;">
<h1>ecsy-babylon</h1>
</a>
<p>babylon.js ecsy binding and helpers</p>
<a href="#getting-started" id="getting-started" style="color: inherit; text-decoration: none;">
<h3>Getting Started</h3>
</a>
<ol>
<li><p>Add script tags of Babylon.js, ecsy and ecsy-babylon.</p>
</li>
<li><p>Add a canvas tag as container.</p>
</li>
<li><p>Build a basic scene.</p>
<pre><code class="language-javascript"><html>
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://unpkg.com/ecsy@0.2.1/build/ecsy.min.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://unpkg.com/babylonjs@4.1.0-beta.18/babylon.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://unpkg.com/@megavr/ecsy-babylon@0.0.10/dist/ecsy-babylon.min.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"></<span class="hljs-name">head</span>></span></span>
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">body</span>></span>
<span class="hljs-tag"><<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"renderCanvas"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"width: 100%; height: 100%"</span>></span><span class="hljs-tag"></<span class="hljs-name">canvas</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="actionscript">
<span class="hljs-comment">/** Step 1 - Preparation */</span>
<span class="hljs-comment">// create a ECSY world object</span>
<span class="hljs-keyword">const</span> world = <span class="hljs-keyword">new</span> ECSY.World();
<span class="hljs-comment">// register necessary systems from ecsy-babylon(global name: EB)</span>
world
.registerSystem(EB.GameSystem)
.registerSystem(EB.TransformSystem)
.registerSystem(EB.CameraSystem)
.registerSystem(EB.MeshSystem)
.registerSystem(EB.InputSystem);
<span class="hljs-comment">/** Step 2 - Start the game engine */</span>
<span class="hljs-comment">// get canvas element</span>
<span class="hljs-keyword">const</span> canvas = document.getElementById(<span class="hljs-string">"renderCanvas"</span>);
<span class="hljs-comment">// get GameSystem object</span>
<span class="hljs-keyword">const</span> game = world.getSystem(EB.GameSystem);
<span class="hljs-comment">// start GameSystem by providing canvas object</span>
game.start(canvas);
<span class="hljs-comment">/** Step 3 - Start to build your scene */</span>
<span class="hljs-comment">// add a scene</span>
<span class="hljs-keyword">const</span> scene = world.createEntity().addComponent(EB.Scene);
<span class="hljs-comment">// add a camera</span>
<span class="hljs-keyword">const</span> camera = world.createEntity()
.addComponent(EB.Transform)
.addComponent(EB.Camera);
<span class="hljs-comment">// up camera to height of eyes at standing human</span>
camera.getMutableComponent(EB.Transform).position.y = <span class="hljs-number">1.7</span>;
<span class="hljs-comment">// add a box</span>
<span class="hljs-keyword">const</span> box = world.createEntity()
.addComponent(EB.Transform)
.addComponent(EB.Mesh);
<span class="hljs-comment">// put box in front of camera</span>
box.getMutableComponent(EB.Transform).position.z = <span class="hljs-number">3</span>;
<span class="hljs-comment">/** Step 4 - Add some interaction to your scene */</span>
<span class="hljs-comment">// add keyboard input</span>
world.createEntity().addComponent(EB.Input, { onKey: onKey });
<span class="hljs-comment">// rotate box when press R/r key</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onKey</span><span class="hljs-params">(key, down)</span> </span>{
<span class="hljs-keyword">if</span> (down) {
<span class="hljs-keyword">if</span> (key === <span class="hljs-string">"R"</span> || key === <span class="hljs-string">"r"</span>) {
box.getMutableComponent(EB.Transform).rotation.y += <span class="hljs-number">30</span>;
}
}
}
</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"></<span class="hljs-name">body</span>></span></span>
<span class="xml"><span class="hljs-tag"></<span class="hljs-name">html</span>></span></span></code></pre>
</li>
</ol>
<a href="#examples" id="examples" style="color: inherit; text-decoration: none;">
<h3>Examples</h3>
</a>
<p><a href="https://megavr.github.io/ecsy-babylon-examples/">https://megavr.github.io/ecsy-babylon-examples/</a></p>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="globals.html"><em>Globals</em></a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-enum tsd-is-external">
<a href="enums/inputtypes.html" class="tsd-kind-icon">Input<wbr>Types</a>
</li>
<li class=" tsd-kind-enum tsd-is-external">
<a href="enums/lighttypes.html" class="tsd-kind-icon">Light<wbr>Types</a>
</li>
<li class=" tsd-kind-enum tsd-is-external">
<a href="enums/meshtypes.html" class="tsd-kind-icon">Mesh<wbr>Types</a>
</li>
<li class=" tsd-kind-enum tsd-is-external">
<a href="enums/particletypes.html" class="tsd-kind-icon">Particle<wbr>Types</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/camera.html" class="tsd-kind-icon">Camera</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/camerasystem.html" class="tsd-kind-icon">Camera<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/gamesystem.html" class="tsd-kind-icon">Game<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/input.html" class="tsd-kind-icon">Input</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/inputsystem.html" class="tsd-kind-icon">Input<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/light.html" class="tsd-kind-icon">Light</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/lightsystem.html" class="tsd-kind-icon">Light<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/material.html" class="tsd-kind-icon">Material</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/materialsystem.html" class="tsd-kind-icon">Material<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/mesh.html" class="tsd-kind-icon">Mesh</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/meshsystem.html" class="tsd-kind-icon">Mesh<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/particle.html" class="tsd-kind-icon">Particle</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/particlesystem.html" class="tsd-kind-icon">Particle<wbr>System</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/scene.html" class="tsd-kind-icon">Scene</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/transform.html" class="tsd-kind-icon">Transform</a>
</li>
<li class=" tsd-kind-class tsd-is-external">
<a href="classes/transformsystem.html" class="tsd-kind-icon">Transform<wbr>System</a>
</li>
<li class=" tsd-kind-interface tsd-has-type-parameter tsd-is-external">
<a href="interfaces/colorcomponent.html" class="tsd-kind-icon">Color<wbr>Component</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/lightcolorproperties.html" class="tsd-kind-icon">Light<wbr>Color<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/materialcolorproperties.html" class="tsd-kind-icon">Material<wbr>Color<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/materialtextureproperties.html" class="tsd-kind-icon">Material<wbr>Texture<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/meshoptions.html" class="tsd-kind-icon">Mesh<wbr>Options</a>
</li>
<li class=" tsd-kind-interface tsd-has-type-parameter tsd-is-external">
<a href="interfaces/objectcomponent.html" class="tsd-kind-icon">Object<wbr>Component</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/particlecolorproperties.html" class="tsd-kind-icon">Particle<wbr>Color<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/particletextureproperties.html" class="tsd-kind-icon">Particle<wbr>Texture<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/scenecolorproperties.html" class="tsd-kind-icon">Scene<wbr>Color<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/scenecomponent.html" class="tsd-kind-icon">Scene<wbr>Component</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/scenetextureproperties.html" class="tsd-kind-icon">Scene<wbr>Texture<wbr>Properties</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/textureattributes.html" class="tsd-kind-icon">Texture<wbr>Attributes</a>
</li>
<li class=" tsd-kind-interface tsd-has-type-parameter tsd-is-external">
<a href="interfaces/texturecomponent.html" class="tsd-kind-icon">Texture<wbr>Component</a>
</li>
<li class=" tsd-kind-interface tsd-is-external">
<a href="interfaces/xyzproperties.html" class="tsd-kind-icon">XYZProperties</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#degreetoradians" class="tsd-kind-icon">degree<wbr>ToRadians</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#getassetmanager" class="tsd-kind-icon">get<wbr>Asset<wbr>Manager</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#getscene" class="tsd-kind-icon">get<wbr>Scene</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#hextocolor3" class="tsd-kind-icon">hex<wbr>ToColor3</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#hextocolor4" class="tsd-kind-icon">hex<wbr>ToColor4</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#xyztovector3" class="tsd-kind-icon">xyz<wbr>ToVector3</a>
</li>
<li class=" tsd-kind-function tsd-is-external">
<a href="globals.html#xyztovector3radians" class="tsd-kind-icon">xyz<wbr>ToVector3<wbr>Radians</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
<li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
<script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script>
</body>
</html>