init method

void init()

Implementation

void init() {
  final bones = this.bones;
  final boneInverses = this.boneInverses;

  // layout (1 matrix = 4 pixels)
  //      RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  //  with  8x8  pixel texture max   16 bones * 4 pixels =  (8 * 8)
  //       16x16 pixel texture max   64 bones * 4 pixels = (16 * 16)
  //       32x32 pixel texture max  256 bones * 4 pixels = (32 * 32)
  //       64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)

  double getSize = math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  getSize = MathUtils.ceilPowerOfTwo(getSize).toDouble();
  getSize = math.max(getSize, 4);

  int size = getSize.toInt();

  boneTextureSize = size;
  boneMatrices?.dispose();
  boneMatrices = Float32Array(size * size * 4);

  // calculate inverse bone matrices if necessary

  if (boneInverses.isEmpty) {
    calculateInverses();
  }
  else {
    // handle special case

    if (bones.length != boneInverses.length) {
      console.warning('Skeleton: Number of inverse bone matrices does not match amount of bones.');

      this.boneInverses = [];

      for (int i = 0, il = this.bones.length; i < il; i++) {
        this.boneInverses.add(Matrix4.identity());
      }
    }
  }
}