<button onclick="saveSkeleton()">Save</button>
body {
	background-color: #000;
	margin: 0px;
	overflow: hidden;
}
// Simple three.js example

var mesh, renderer, scene, camera, controls,armSkeleton;

init();
animate();

function init() {

    // renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

    // scene
    scene = new THREE.Scene();
    
    // camera
    camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.set( 20, 20, 20 );

    // controls
    controls = new THREE.OrbitControls( camera );
    
    // ambient
    scene.add( new THREE.AmbientLight( 0x222222 ) );
    
    // light
    var light = new THREE.DirectionalLight( 0xffffff, 1 );
    light.position.set( 20, 20, 0 );
    scene.add( light );
    
    // axes
    scene.add( new THREE.AxesHelper( 20 ) );

    // geometry
    var geometry = new THREE.SphereGeometry( 5, 12, 8 );
    
    // material
    var material = new THREE.MeshPhongMaterial( {
        color: 0x00ffff, 
        flatShading: true,
        transparent: true,
        opacity: 0.7,
    } );
    
    // mesh
    mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
  
var bones = [];

var shoulder = new THREE.Bone();
var elbow = new THREE.Bone();
var hand = new THREE.Bone();

shoulder.add( elbow );
elbow.add( hand );

bones.push( shoulder );
bones.push( elbow );
bones.push( hand );

shoulder.position.y = -5;
elbow.position.y = 0;
hand.position.y = 5;

  armSkeleton = new THREE.Skeleton( bones );  
  console.log('Skeleton after creation',armSkeleton)
    
}

function animate() {

    requestAnimationFrame( animate );

    renderer.render( scene, camera );

}
function saveSkeleton(){
  
 		var options = {
			trs: false,
			onlyVisible: true,
			truncateDrawRange: true,
			embedImages: true,
			animations: [],
			forceIndices: false,
			forcePowerOfTwoTextures: false
		}; 
  
  // Instantiate a exporter
  var exporter = new THREE.GLTFExporter( options );
  
  //Create dummy mesh to attach skeleton to
	var geometry = new THREE.SphereGeometry( 5, 32, 32 );
	var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
	var mesh = new THREE.SkinnedMesh( geometry, material );
	
	var rootBone = armSkeleton.bones[ 0 ];
	mesh.add( rootBone );
	mesh.bind( armSkeleton );  
  

  // Parse the input and generate the     glTF output
  exporter.parse( mesh, function ( gltf ) {
	  console.log( 'Data to save', gltf );
	  //downloadJSON( gltf );
}, options );  
}
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://threejs.org/build/three.js
  2. https://threejs.org/examples/js/controls/OrbitControls.js
  3. https://threejs.org/examples/js/exporters/GLTFExporter.js