How to use the Bone function from three

Find comprehensive JavaScript three.Bone code examples handpicked from public code repositorys.

three.Bone is a type of object in the Three.js library that represents a bone in a skeletal animation system.

2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
})().then(function (objects) {
  var node;

  // .isBone isn't in glTF spec. See .markDefs
  if (nodeDef.isBone === true) {
    node = new THREE.Bone();
  } else if (objects.length > 1) {
    node = new THREE.Group();
  } else if (objects.length === 1) {
    node = objects[0];
fork icon3
star icon7
watch icon8

+ 14 other calls in file

2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
    });
    return Promise.all(pending);
}()).then(objects => {
    let node;
    if (nodeDef.isBone === true) {
        node = new three.Bone();
    }
    else if (objects.length > 1) {
        node = new three.Group();
    }
fork icon2
star icon7
watch icon0

How does three.Bone work?

three.Bone is a class in the Three.js library that represents a bone used in skeletal animations, which is part of a hierarchy of bones that can be used to animate a 3D model by manipulating its vertices. When a bone is transformed, all of its descendants are transformed as well, making it a useful tool for animating complex models.

298
299
300
301
302
303
304
305
306
307
if (geometry && geometry.bones !== undefined) {
    // first, create array of 'Bone' objects from geometry data
    for (let i = 0, il = geometry.bones.length; i < il; i += 1) {
        const gbone = geometry.bones[i];
        // create new 'Bone' object
        const bone = new three_1.Bone();
        bones.push(bone);
        // apply values
        bone.name = gbone.name;
        bone.position.fromArray(gbone.pos);
fork icon1
star icon3
watch icon0

+ 4 other calls in file

1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
var matrix = new THREE.Matrix4();

var _node;

if (node.jointName) {
  _node = new THREE.Bone();
  _node.name = node.name !== undefined ? node.name : node.jointName;
  _node.jointName = node.jointName;
} else {
  _node = new THREE.Object3D();
fork icon0
star icon1
watch icon0

+ 9 other calls in file

Ai Example

1
2
3
4
const bone = new THREE.Bone();
bone.position.y = 5;
bone.position.x = 2;
bone.rotation.z = Math.PI / 2;

This code creates a new Bone instance, sets its position and rotation properties, and stores it in the bone variable. The Bone can then be added to a Skeleton instance or used to create a hierarchical bone structure.

2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
  return Promise.all(pending);
}().then(function (objects) {
  var node; // .isBone isn't in glTF spec. See ._markDefs

  if (nodeDef.isBone === true) {
    node = new _three.Bone();
  } else if (objects.length > 1) {
    node = new _three.Group();
  } else if (objects.length === 1) {
    node = objects[0];
fork icon0
star icon1
watch icon0

1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
skeleton.rawBones.forEach( function ( rawBone, i ) {

	if ( rawBone.ID === parent.ID ) {

		var subBone = bone;
		bone = new THREE.Bone();

		// set name and id here - otherwise in cases where "subBone" is created it will not have a name / id
		bone.name = THREE.PropertyBinding.sanitizeNodeName( name );
		bone.ID = id;
fork icon0
star icon0
watch icon1

+ 88 other calls in file

2945
2946
2947
2948
2949
2950
2951
2952
2953
var nodeDef = json.nodes[nodeIndex];

return new Promise(function (resolve) {
  // .isBone isn't in glTF spec. See .markDefs
  if (nodeDef.isBone === true) {
    resolve(new THREE.Bone());
  } else if (nodeDef.mesh !== undefined) {
    parser.getDependency('mesh', nodeDef.mesh).then(function (mesh) {
      var node;
fork icon0
star icon0
watch icon0

+ 7 other calls in file

7
8
9
10
11
12
13
14
15
16
17
18
// https://threejs.org/docs/#api/en/helpers/SkeletonHelper
// https://threejs.org/docs/#api/en/objects/SkinnedMesh


const THREE = require('three');
const _Skeleton = THREE.Skeleton;
const _Bone = THREE.Bone;
//const Vector3 = THREE.Vector3;
//const Matrix4 = THREE.Matrix4;


const Bone = require("./Bone");
fork icon0
star icon0
watch icon0

784
785
786
787
788
789
790
791
792
793
case 'NurbsCurve':
  model = this.createCurve(relationships, geometryMap);
  break;
case 'LimbNode':
case 'Root':
  model = new THREE.Bone();
  break;
case 'Null':
default:
  model = new THREE.Group();
fork icon0
star icon0
watch icon0

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)