Based on https://github.com/RaananW/babylonjs-webpack-es6 and https://github.com/eldinor/yuka-babylonjs-examples
To run the basic scene:
npm install
to install the needed dependencies.npm start
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 !
public
folder for the index.html
file.src/scenes
folder for the index.ts
and additional ts files.webpack.common.js
and duplicate the HtmlWebpackPlugin
block in the plugins
object and replace the filename
with the name you will use in the url
. Set template
path to the index.html
on the filesystem.http://localhost:8080/filename-set-in-webpack?scene=path/to/index.ts
of your scene without the ts
suffixThe 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
TransformNodes
with YUKA. YUKA will place your object in world space.Use YUKA's parenting instead.renderComponent
and bake the transformations into the vertices and freeze the world matrix of your mesh before doing so.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)
syncFunctions
:
For syncing a TransformNode
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())
}
YUKA.EntityManager
with it's add
functionprivate _time: YUKA.Time = new YUKA.Time()
this._scene.onBeforeRenderObservable.add(() => {
const delta = this._time.update().getDelta()
this._entityManager.update(delta) // YUKA world step
})
Enjoy!