Based on https://github.com/RaananW/babylonjs-webpack-es6 and https://github.com/eldinor/yuka-babylonjs-examples
To run the basic scene:
- Clone / download this repository
- run
npm install
to install the needed dependencies. - run
npm start
- A new window should open in your default browser. if it doesn't, open
http://localhost:8080
Running npm start
will start the webpack dev server with hot-reloading turned on. Open your favorite code editor and start editing, that's all.
The entry point for the entire TypeScript application is ./src/index.ts
. Any other file imported in this file will be included in the build.
To debug, open the browser's dev tool. Source maps are ready to be used. In case you are using VSCode, simply run the default debugger task (Launch Chrome against localhost
) while making sure npm start
is still running. This will allow you to debug your application straight in your editor.
For more information about Typescript setup please refer to the base Typescript project at https://github.com/RaananW/babylonjs-webpack-es6
For more examples please have a look at the JS based examples located at https://github.com/eldinor/yuka-babylonjs-examples
! Subject to change !
- Create the directory/directories in the
public
folder for theindex.html
file. - Create the directory/directories in the
src/scenes
folder for theindex.ts
and additional ts files. - Modify
webpack.common.js
and duplicate theHtmlWebpackPlugin
block in theplugins
object and replace thefilename
with the name you will use in theurl
. Settemplate
path to theindex.html
on the filesystem. - Access your new scene at
http://localhost:8080/filename-set-in-webpack?scene=path/to/index.ts
of your scene without thets
suffix
The scene entrypoint index.ts
is located in src/scenes/steering/arrive/
. The index.html
is located in public/steering/arrive/
.
new HtmlWebpackPlugin({
inject: true,
filename: 'steering-arrive.html',
template: path.resolve(appDirectory, 'public/steering/arrive/index.html'),
}),
URL will be: http://localhost:8080/steering-arrive.html?scene=steering/arrive/index
- try to avoid parented
TransformNodes
with YUKA. YUKA will place your object in world space.Use YUKA's parenting instead. - 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. - you must register your Mesh/TransformNode/Camera on the YUKA entity by setting it as a
renderComponent
and pass thesyncFunction
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)
syncFunctions
: For syncing aTransformNode
with the YUKA entity use this method:
private _sync(entity: YUKA.GameEntity, renderComponent: TransformNode) {
Matrix.FromValues(...(entity.worldMatrix.elements as FlatMatrix4x4)).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: YUKA.GameEntity, camera: Camera) {
camera.getViewMatrix().copyFrom(Matrix.FromValues(...(entity.worldMatrix.elements as FlatMatrix4x4)).invert())
}
- you must register your YUKA entity in the
YUKA.EntityManager
with it'sadd
function - you must update the YUKA EntityManager's time (make steps in YUKA world) to make things moving like this:
private _time: YUKA.Time = new YUKA.Time()
this._scene.onBeforeRenderObservable.add(() => {
const delta = this._time.update().getDelta()
this._entityManager.update(delta) // YUKA world step
})
Enjoy!