voxel-camera

0.1.1 • Public • Published

voxel-camera

A camera for voxeljs.

View the voxel-drone demo as it uses this camera.

example

// voxel-camera returns a method to create a camera controller
var createCameraControl = require('voxel-camera');
 
// Create a camera control, pass a copy of the game
var cameraControl = createCameraControl(game);
 
// Add the camera to the scene
game.scene.add(cameraControl.camera());
 
// Build a monitor (essentially a box to map the video screen to)
var monitor = new game.THREE.Mesh(
  new game.THREE.CubeGeometry(100, 100, 1),
  new game.THREE.MeshBasicMaterial({
    map: cameraControl.monitor()
  })
);
 
// Add monitor mesh to the scene
game.scene.add(monitor);
 
// Then render the camera on tick
game.on('tick', function(dt) {
  cameraControl.render();
 
  // or to have the camera follow a voxeljs item
  // cameraControl.render(followItem);
});

If you need a marker on where the camera is set marker to true:

var createCameraControl = require('voxel-camera');
var cameraControl = createCameraControl({game: game, marker: true});

If you would like to get a PNG stream from the camera:

var cameraControl = createCameraControl(game);
cameraControl.resume();
 
var img = document.getElementById('myimg');
cameraControl.on('data', function(pngData) {
  img.src = pngData;
});

Warning: This uses canvas.toDataURL('image/png') which is currently a really expensive operation in the browser. Might want to consider throttling. If anyone has a suggestion on a less expensive way, I'd love to hear it!

install

With npm do:

npm install voxel-camera

release history

  • 0.1.1 - convert into a stream and emit pngs :D
  • 0.1.0 - initial release

license

Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i voxel-camera

Weekly Downloads

1

Version

0.1.1

License

none

Last publish

Collaborators

  • shama