Javascript ES6 runtime with WebGL rendering.
Use NPM to get the dependencies and then build with webpack:
npm install
webpack --watch
Take a look at example/archer.html for a pretty complete use case.
Setting up Nima's OpenGL runtime just requires instancing the Graphics class and passing along a reference to the canvas in your Dom:
let canvas = document.getElementById("myCanvas");
let graphics = new Nima.Graphics(canvas)
First load a character file into a runtime actor that can be used to then create multiple instances of the character.
// Instance a loader.
let loader = new Nima.ActorLoader();
loader.load("/my-character.nima", function(actor)
{
if(!actor || actor.error)
{
console.error("Failed to load actor.");
return;
}
// Initialize the actor with the graphics class, this allows loading any shared resources like images and vertex/index buffers that can be shared across multiple instances of the character.
actor.initialize(graphics);
});
Once the Actor has been initialized, it's ready to be instanced and drawn into your scene. Create an instance of an actor as necessary for your project, instances are pretty lightweight and are designed to be created and destroyed at runtime as needed.
let actorInstance = actor.makeInstance();
actorInstance.initialize(graphics);
As your game loop updates, you'll want to apply animations and update each instance before rendering it to the screen such that all the necessary calculations are performed in a batched and efficient way.
let animationTime = 0.0;
let animation = actor.getAnimation("Run");
function renderLoop(elapsedSeconds)
{
animationTime += elapsedSeconds;
// Apply the run animation at a specific time on the actor instance. Note that you can layer animations in order here and even applying mixing values into the last argument.
animation.apply(animationTime, actorInstance, 1.0);
// N.B. any transformations you wish to manually apply to the actorInstance should be applied before calling advance.
// Call advance once per frame on each instance before drawing it.
actorInstance.advance(elapsedSeconds);
// Draw the instance to the screen.
actorInstance.draw(graphics);
}
Actor and ActorInstance objects should be disposed of once you are done using them. This will free up any graphics memory that was used up by the Actor.
actor.dispose(graphics);
actorInstance.dispose(graphics);
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
See the LICENSE file for license rights and limitations (MIT).