Coder Social home page Coder Social logo

leapjs-rigged-hand's Introduction

JS Rigged Hand Plugin

This allows a Leap-Enabled hand to be added to any Three.JS scene. Requires LeapJS Skeletal 0.4.2 or greater with LeapJS-Plugins 0.1.3 or greater.

hands

Automatically adds or removes hand meshes to/from the scene as they come in to or out of view of the leap controller.

Usage:

Basic

# simplest possible usage, see `quickstart.html`
(window.controller = new Leap.Controller)
  .use('riggedHand')
  .connect()

This will create a canvas with fixed position which covers the entire screen. A neat trick is to allow pointer-events to pass through the canvas with one CSS rule, so that you can interact with your page like normal.

canvas{
  pointer-events: none;
}

Advanced

# advanced configuration, see `index.html` and `main.coffee`
(window.controller = new Leap.Controller)
  # handHold and handEntry are dependencies of this plugin, available to the controller through leap-plugins.js
  # By default rigged-hand will use these, but we can call explicitly to provide configuration:
  .use('handHold', {})
  .use('handEntry', {})
  .use('riggedHand', {
    parent: scene

    # this is called on every animationFrame 
    renderFn: ->
      renderer.render(scene, camera)
      # Here we update the camera controls for clicking and rotating
      controls.update()

    # These options are merged with the material options hash
    # Any valid Three.js material options are valid here.
    materialOptions: {
      wireframe: true,
      color: new THREE.Color(0xff0000)
    }
    geometryOptions: {}

    # This will show pink dots at the raw position of every leap joint.
    # they will be slightly offset from the rig shape, due to it having slightly different proportions.
    dotsMode: true

    # Sets the default position offset from the parent/scene. Default of new THREE.Vector3(0,-10,0)
    offset: new THREE.Vector3(0,0,0)

    # sets the scale of the mesh in the scene.  The default scale works with a camera of distance ~15.
    scale: 1.5

    # Allows hand movement to be scaled independently of hand size.
    # With a value of 2, the hand will cover twice the distance on screen as it does in the world.
    positionScale: 2

    # allows 2d text to be attached to joint positions on the screen
    # Labels are by default white text with a black dropshadow
    # this method is called for every bone on each frame
    # boneMeshes are named Finger_xx, where the first digit is the finger number, and the second the bone, 0 indexed.
    boneLabels: (boneMesh, leapHand)->
      return boneMesh.name

    # allows individual bones to be colorized
    # Here we turn thumb and index finger blue while pinching
    # this method is called for every bone on each frame
    # should return an object with hue, saturation, and an optional lightness ranging from 0 to 1
    # http://threejs.org/docs/#Reference/Math/Color [setHSL]
    boneColors: (boneMesh, leapHand)->
      if (boneMesh.name.indexOf('Finger_0') == 0) || (boneMesh.name.indexOf('Finger_1') == 0)
        return {
          hue: 0.6,
          saturation: leapHand.pinchStrength
        }

    # This will add a warning message to the page on browsers which do not support WebGL or do not have it enabled.
    # By default, this will be used unless a `parent` scene is passed in.
    # This uses @mrdoob's Detector.js
    # Chrome, Firefox, Safari Developer mode, and IE11 all support WebGL.  http://caniuse.com/webgl
    checkWebGL: true

  })
  .connect()

Note that the size of this file is quite large, as it includes left and right hand models. It is recommended that you include the files from our CDN, as that will encourage browser caching and ensure the assets are gzipped from 845KB to 348KB before sending.

Scope objects

Certain objects are made available on the plugin scope. This is the same "options" object which is passed in to use.

scope = controller.plugins.riggedHand; 

scope.camera # THREE.js camera

scope.scene # THREE.js camera

scope.Detector # Can be used to detect webgl availability through `if !!Detector.webgl`

There are many which are currently undocumented. Inspect the object manually to discover.

Events

riggedHand.meshAdded and riggedHand.meshRemoved are available. These may be useful to customize behaviors of the hand or change defaults. By default, material.opacity == 0.7, material.depthTest == true, and handMesh.castShadow == true, but these could be customized in the event callback.

controller.on('riggedHand.meshAdded', function(handMesh, leapHand){
  handMesh.material.opacity = 1;
});

Scene Position

handMesh.scenePosition(leapPosition, scenePosition) can be used to convert coordinates from Leap Space to THREE scene space. leapPosition should be an array [x,y,z] as found on Leap frames, scenePosition should be a THREE.Vector3 which will be edited in-place.

LIVE DEMO

sphere = new THREE.Mesh(
  new THREE.SphereGeometry(1),
  new THREE.MeshBasicMaterial(0x0000ff)
)
scene.add(sphere)

controller.on 'frame', (frame)->
  if hand = frame.hands[0]
    handMesh = frame.hands[0].data('riggedHand.mesh')

    handMesh.scenePosition(hand.indexFinger.tipPosition, sphere.position)

Screen Position

When a hand is on the screen, that hand will be available to your application (such as in a plugin or on 'frame' callback) through frame.hands[index].data('riggedHand.mesh'). This will be the Three.js mesh, as is.

To get the css window coordinates of anything in leap-space, use the handMesh.screenPosition method, as seen in main.coffee. The number returned will be distance from the bottom left corner of the WebGL canvas.

Note that if a custom scene is passed in, scope.renderer must also be passed in/set.

controller.on 'frame', (frame)->
  if hand = frame.hands[0]
    handMesh = frame.hands[0].data('riggedHand.mesh')
    # to use screenPosition, we pass in any leap vector3 and the camera
    screenPosition = handMesh.screenPosition(
      hand.fingers[1].tipPosition
    )
    cursor.style.left = screenPosition.x
    cursor.style.bottom = screenPosition.y

Contributing

Open an issue!

leapjs-rigged-hand's People

Contributors

codemercenary avatar lephasme avatar pehrlich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leapjs-rigged-hand's Issues

ScreenPosition Camera

Accessing the rigged hand's screen position needs a camera parameter, which isn't in documentation.
I'm using this.plugins.riggedHand.camera inside the Leap.loop, which works.

Scale property does not work

I'm trying to scale the rigged hand using following code:

<script>
  (window.controller = new Leap.Controller)
    .use('riggedHand', {
      scale: 5.0
  })
    .connect()
</script>

Hand shows and works correctly, but scaling doesn't change anything. I'm using three.js r70, leap 0.6.4, leap-plugins 0.1.10 and leap.rigged-hand 0.1.7

Replace underscore in code

Since LeapJS 1.6.4, underscore has been exposed as Leap._. This can be used to replace the copied underscoreJS methods in the source here.

Change hand color

Is there an easy way to do it?
Function that sets bone color seems like an overkill. Also, if I set HSL value, it doesn't seem to be correct anyway (try to set red in HSL space).
I've looked at the source code and I can't see how I can provide material option that would overwrite color.

Socket.io problem

I am working on making an interface for a Leap motion controlled robot. From the server side node.js, I am emitting an event 'action' which contains the data to be displayed on a HTML page. I am using leapjs-rigged-hand for visualization (https://github.com/leapmotion/leapjs-rigged-hand)

  <body>
      <div id="display"><span id="direction">undefined</span></div>
  </body>

  <script type="text/javascript">
        var socket = io();
        socket.on('action', function(data) {
              $('$display').html(data);
        });

        var controller = new Leap.Controller;
        (controller).use('riggedHand', {
              scale: 1.5
        })
        .connect();

        controller.on('riggedHand.meshAdded', function(handMesh, leapHand){
              handMesh.material.opacity = 1;
              handMesh.material.color.set('#7b4b2a');
              handMesh.material.ambient = handMesh.material.color;
        });
  </script>

Shown above is the relevant part of the code. The problem is that socket callback works only before the first "riggedHand.meshAdded" event is fired.

How do I make them work simultaneously?

Thank you

Hand Thumbnails

leapmotion_hand_thumbnails_2
leapmotion_hand_thumbnails_1

These are rough design thumbnails created at the start of my time with the project. With the current hand model, these designs will be trimmed off at the wrist, and you can see quick examples of what some designs could look like:

leapmotion_hand_design_previzexamples

I'm most interested in exploring more futuristic hand designs, robotic or trans-human. I feel like this will maintain consistency in both message and visual tone with the controller, and pull on the user's sense of awe and exploration of a new technology, and essentially a new world of interaction.

I think there's ample opportunity to explore other designs; using LM's established marketing tenets of "Play, Create, Explore" we can direct the design of three hands to reflect these experiences and activities. An FPS themed military hand could reflect "Play", an alien hand could reflect "Explore" with it's strangeness and elusions of unseen worlds, and a rock golem hand can reflect "Create", referring to the natural elements and how they shape and build our world.

There's much discussion to be had, and I'm interested in hearing new ideas.

Cannot close thumb with flat hand

With the current model, when the hand is held flat, there is a gap between the hand and the thumb which cannot be removed by moving one's fingers. This is likely a model issue, but could possibly be a code issue.

fps drops when hands are not visible

Why does the fps drop to about 30 when hands are not visible? When hands are visible the fps is usualy around 60. Is this intentional? And can it be changed to stay at 60 fps every time?

Cannot use the provided models.

Before modeling my own rigged hand, as a Blender newbie I tried to open the models included in this plugin in order to understand how they were made and figure out the path I have to follow (since it's unfortunately impossible to re-import the working JSON file in Blender).

But none of the models here seems to work (using Blender 2.75a and Three.js r71):

  • /models/Game Quality Hand/Arm_Hand: not the same model as the one actually used by the plugin (longer forearm). The .dae files can't be imported (the scene remains empty, I see no error) and the geometry of the .fbx files is screwed up (especially around the thumb).
  • /models/Game Quality Hand/Handsolo: seems to be the right model, but the "Leapmotion_Handsolo_Rig_RIght.dae" file is completely unrelated to the left one (another model, both hands, not rigged). The .fbx files look right, but the bones are messy (then again, most notably in relation to the thumb). Couldn't use them back in Three.js (using various settings: fingers are all displayed with weird angles, the palm is upside-down, etc.).
  • /models/Revamped Hand: not the same model (nothing beyond the wrist). I tried to export it to Three.js using various settings, but then again it doesn't fit in the data model. The "handrevamp_hipoly_rig_left.dae" file is almost twice as large as the right one, which looks suspicious (missing data?).
  • /models/Test Rig: not the same model. The "Leapmotion_Basehand_Rig_Left.dae" file is almost empty (less than 5Kb). The other file (as well as both the .fbx files) look good, but then again, once exported, I always fail to use them in Three.js (wrong angles, the geometry tends to be torn apart, etc.).

What am I doing wrong? Are there some steps and settings I'm missing?

Thanks in advance for your advice.

low-poly hand

We should be able to sub in a low-poly hand for performance assessment (download speeds, runtime performance)

current status: hand appears to be rigged quite differently, causing spaghetti fingers. Could be a bone-position issue.

Add background grid

there should be planes in the background to give a sense of scale (like diagnostic visualizer)

Push to npm registry

It seems as if this code has an npm package description, but is not published to npm.

Would also be fantastic if this package would support ES 6 module imports. At the moment, I have to tweak it manually to make this work.

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.