Git Product home page Git Product logo

yuka-babylonjs-examples's Introduction

yuka-babylonjs-examples

Yuka Game AI + 3D rendering with Babylon.js.

Yuka library source: https://github.com/Mugen87/yuka

Babylon.js 3D engine source: https://github.com/BabylonJS/Babylon.js

Installation

VS Code extensions to install

https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer

How to run the examples

Open the index.html file located in examples/js/example_dir with LiveServer in VS Code.

Best practices

  1. try to avoid parented TransformNodes with YUKA. YUKA will place your object in world space.Use YUKA's parenting instead.
  2. you must scale, rotate and position your mesh before registering it as a YUKA renderComponent and bake the transformations into the vertices and freeze the world matrix of your mesh before doing so.
  3. you must register your Mesh/TransformNode/Camera on the YUKA entity by setting it as a renderComponent and pass the syncFunction which will take care of syncing your BabylonJS object's position/rotation/scaling into with the YUKA world's position.
const entity = new YUKA.GameEntity()
entity.setRenderComponent(mesh, syncFunction)
  1. syncFunctions: For syncing a TransformNode with the YUKA entity use this method:
private _sync(entity, renderComponent) {
   Matrix.FromValues(...entity.worldMatrix.elements).decomposeToTransformNode(renderComponent)
}

If it doesn't work for you try this one:

renderComponent.getWorldMatrix().copyFrom(BABYLON.Matrix.FromValues(...entity.worldMatrix.elements))

For the camera use this:

private _syncCamera(entity, camera) {
    camera.getViewMatrix().copyFrom(Matrix.FromValues(...entity.worldMatrix.elements).invert())
}
  1. you must register your YUKA entity in the YUKA.EntityManager with it's add function
  2. you must update the YUKA EntityManager's time (make steps in YUKA world) to make things moving like this:
private _time = new YUKA.Time()
this._scene.onBeforeRenderObservable.add(() => {
    const delta = this._time.update().getDelta()
    this._entityManager.update(delta) // YUKA world step
})

License

All these examples are open source, MIT License.

Babylon.js: Apache-2.0 License

Yuka.js: MIT License

3D Models: CC Attribution License (see readme.md in relevant folders)

yuka-babylonjs-examples's People

Contributors

eldinor avatar rolandcsibrei avatar

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.