All files / engine/Source/Scene GltfVertexBufferLoader.js

92.77% Statements 257/277
85.45% Branches 94/110
100% Functions 23/23
92.72% Lines 255/275

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635                                                                                          4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x 4660x     4660x 4658x 4657x 4656x 4654x           4654x 4654x 4654x 4654x 4654x 4654x 4654x 3x         4651x           4651x 1x         4650x 1x         4649x 88x 88x 88x 88x         4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x 4649x     1x 1x 1x     1x                       19115x                           9672x                           5061x                           94x           9185x                       1x 5274x 629x     4645x 114x 114x     4531x 87x 87x     4444x 4444x                 71x 71x 71x   71x 71x 71x 71x 71x   71x 24x 24x   47x 47x             47x     47x     47x     47x       47x 123x   47x       71x       114x 114x 114x 114x             114x 114x   114x       114x 114x                 90x     90x       90x 90x   90x 90x   90x 90x   90x       114x 114x   114x   114x 6x 108x       6x 102x         6x 96x 6x 6x 6x 6x 860685x         860685x         860685x         860685x           90x 90x     90x 90x 90x 90x               90x 90x   90x 90x 90x 90x 12910275x 12910275x 12910275x 12910275x           87x 87x 87x 87x             87x 87x   87x         87x 87x                     79x 79x     79x 79x 79x 79x 79x 79x 79x 79x 79x 71x               79x               4444x 4444x 4444x 4444x           4444x 4444x   4441x 7x     4434x 4434x 4434x   3x       3x         5x 5x 5x 5x       1x 1x 1x     1x 4440x 4440x     1x 4434x       4438x         4438x 4438x     1x               1x   11727x     11727x 920x     10807x       5734x     5073x 348x 348x 346x 267x     2x     79x     4804x 285x 285x 285x 171x           114x       4633x 4633x 4440x 4440x 4440x 4440x   6x   4434x 193x 4x       4627x   4627x 4627x 4627x 4627x 4627x             1x 9273x 4433x     9273x   9273x       4444x     9273x 87x     9273x 114x     9273x 9273x 9273x 9273x 9273x 9273x 9273x        
import Check from "../Core/Check.js";
import Frozen from "../Core/Frozen.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Buffer from "../Renderer/Buffer.js";
import BufferUsage from "../Renderer/BufferUsage.js";
import AttributeType from "./AttributeType.js";
import JobType from "./JobType.js";
import ModelComponents from "./ModelComponents.js";
import ResourceLoader from "./ResourceLoader.js";
import ResourceLoaderState from "./ResourceLoaderState.js";
import CesiumMath from "../Core/Math.js";
 
/**
 * Loads a vertex buffer from a glTF buffer view.
 * <p>
 * Implements the {@link ResourceLoader} interface.
 * </p>
 *
 * @alias GltfVertexBufferLoader
 * @constructor
 * @augments ResourceLoader
 *
 * @param {object} options Object with the following properties:
 * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).
 * @param {object} options.gltf The glTF JSON.
 * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.
 * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.
 * @param {number} [options.bufferViewId] The bufferView ID corresponding to the vertex buffer.
 * @param {object} [options.primitive] The primitive containing the Draco extension.
 * @param {object} [options.draco] The Draco extension object.
 * @param {string} [options.attributeSemantic] The attribute semantic, e.g. POSITION or NORMAL.
 * @param {number} [options.accessorId] The accessor id.
 * @param {string} [options.cacheKey] The cache key of the resource.
 * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.
 * @param {boolean} [options.loadBuffer=false] Load vertex buffer as a GPU vertex buffer.
 * @param {boolean} [options.loadTypedArray=false] Load vertex buffer as a typed array.
 *
 * @exception {DeveloperError} One of options.bufferViewId and options.draco must be defined.
 * @exception {DeveloperError} When options.draco is defined options.attributeSemantic must also be defined.
 * @exception {DeveloperError} When options.draco is defined options.accessorId must also be defined.
 *
 * @private
 */
function GltfVertexBufferLoader(options) {
  options = options ?? Frozen.EMPTY_OBJECT;
  const resourceCache = options.resourceCache;
  const gltf = options.gltf;
  const gltfResource = options.gltfResource;
  const baseResource = options.baseResource;
  const bufferViewId = options.bufferViewId;
  const primitive = options.primitive;
  const draco = options.draco;
  const attributeSemantic = options.attributeSemantic;
  const accessorId = options.accessorId;
  const cacheKey = options.cacheKey;
  const spz = options.spz;
  const asynchronous = options.asynchronous ?? true;
  const loadBuffer = options.loadBuffer ?? false;
  const loadTypedArray = options.loadTypedArray ?? false;
 
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.func("options.resourceCache", resourceCache);
  Check.typeOf.object("options.gltf", gltf);
  Check.typeOf.object("options.gltfResource", gltfResource);
  Check.typeOf.object("options.baseResource", baseResource);
  Iif (!loadBuffer && !loadTypedArray) {
    throw new DeveloperError(
      "At least one of loadBuffer and loadTypedArray must be true.",
    );
  }
 
  const hasBufferViewId = defined(bufferViewId);
  const hasPrimitive = defined(primitive);
  const hasDraco = hasDracoCompression(draco, attributeSemantic);
  const hasAttributeSemantic = defined(attributeSemantic);
  const hasAccessorId = defined(accessorId);
  const hasSpz = defined(spz);
  if (hasBufferViewId === (hasDraco !== hasSpz)) {
    throw new DeveloperError(
      "One of options.bufferViewId, options.draco, or options.spz must be defined.",
    );
  }
 
  Iif (hasDraco && !hasAttributeSemantic) {
    throw new DeveloperError(
      "When options.draco is defined options.attributeSemantic must also be defined.",
    );
  }
 
  if (hasDraco && !hasAccessorId) {
    throw new DeveloperError(
      "When options.draco is defined options.accessorId must also be defined.",
    );
  }
 
  if (hasDraco && !hasPrimitive) {
    throw new DeveloperError(
      "When options.draco is defined options.primitive must also be defined.",
    );
  }
 
  if (hasDraco) {
    Check.typeOf.object("options.primitive", primitive);
    Check.typeOf.object("options.draco", draco);
    Check.typeOf.string("options.attributeSemantic", attributeSemantic);
    Check.typeOf.number("options.accessorId", accessorId);
  }
 
  //>>includeEnd('debug');
 
  this._resourceCache = resourceCache;
  this._gltfResource = gltfResource;
  this._baseResource = baseResource;
  this._gltf = gltf;
  this._bufferViewId = bufferViewId;
  this._primitive = primitive;
  this._draco = draco;
  this._spz = spz;
  this._attributeSemantic = attributeSemantic;
  this._accessorId = accessorId;
  this._cacheKey = cacheKey;
  this._asynchronous = asynchronous;
  this._loadBuffer = loadBuffer;
  this._loadTypedArray = loadTypedArray;
  this._bufferViewLoader = undefined;
  this._dracoLoader = undefined;
  this._quantization = undefined;
  this._typedArray = undefined;
  this._buffer = undefined;
  this._state = ResourceLoaderState.UNLOADED;
  this._promise = undefined;
}
 
Eif (defined(Object.create)) {
  GltfVertexBufferLoader.prototype = Object.create(ResourceLoader.prototype);
  GltfVertexBufferLoader.prototype.constructor = GltfVertexBufferLoader;
}
 
Object.defineProperties(GltfVertexBufferLoader.prototype, {
  /**
   * The cache key of the resource.
   *
   * @memberof GltfVertexBufferLoader.prototype
   *
   * @type {string}
   * @readonly
   * @private
   */
  cacheKey: {
    get: function () {
      return this._cacheKey;
    },
  },
  /**
   * The vertex buffer. This is only defined when <code>loadAsTypedArray</code> is false.
   *
   * @memberof GltfVertexBufferLoader.prototype
   *
   * @type {Buffer}
   * @readonly
   * @private
   */
  buffer: {
    get: function () {
      return this._buffer;
    },
  },
  /**
   * The typed array containing vertex buffer data. This is only defined when <code>loadAsTypedArray</code> is true.
   *
   * @memberof GltfVertexBufferLoader.prototype
   *
   * @type {Uint8Array}
   * @readonly
   * @private
   */
  typedArray: {
    get: function () {
      return this._typedArray;
    },
  },
  /**
   * Information about the quantized vertex attribute after Draco decode.
   *
   * @memberof GltfVertexBufferLoader.prototype
   *
   * @type {ModelComponents.Quantization}
   * @readonly
   * @private
   */
  quantization: {
    get: function () {
      return this._quantization;
    },
  },
});
 
function hasDracoCompression(draco, semantic) {
  return (
    defined(draco) &&
    defined(draco.attributes) &&
    defined(draco.attributes[semantic])
  );
}
 
/**
 * Loads the resource.
 * @returns {Promise<GltfVertexBufferLoader>} A promise which resolves to the loader when the resource loading is completed.
 * @private
 */
GltfVertexBufferLoader.prototype.load = async function () {
  if (defined(this._promise)) {
    return this._promise;
  }
 
  if (defined(this._spz)) {
    this._promise = loadFromSpz(this);
    return this._promise;
  }
 
  if (hasDracoCompression(this._draco, this._attributeSemantic)) {
    this._promise = loadFromDraco(this);
    return this._promise;
  }
 
  this._promise = loadFromBufferView(this);
  return this._promise;
};
 
function getQuantizationInformation(
  dracoQuantization,
  componentDatatype,
  componentCount,
  type,
) {
  const quantizationBits = dracoQuantization.quantizationBits;
  const normalizationRange = (1 << quantizationBits) - 1;
  const normalizationDivisor = 1.0 / normalizationRange;
 
  const quantization = new ModelComponents.Quantization();
  quantization.componentDatatype = componentDatatype;
  quantization.octEncoded = dracoQuantization.octEncoded;
  quantization.octEncodedZXY = true;
  quantization.type = type;
 
  if (quantization.octEncoded) {
    quantization.type = AttributeType.VEC2;
    quantization.normalizationRange = normalizationRange;
  } else {
    const MathType = AttributeType.getMathType(type);
    Iif (MathType === Number) {
      const dimensions = dracoQuantization.range;
      quantization.quantizedVolumeOffset = dracoQuantization.minValues[0];
      quantization.quantizedVolumeDimensions = dimensions;
      quantization.normalizationRange = normalizationRange;
      quantization.quantizedVolumeStepSize = dimensions * normalizationDivisor;
    } else {
      quantization.quantizedVolumeOffset = MathType.unpack(
        dracoQuantization.minValues,
      );
      quantization.normalizationRange = MathType.unpack(
        new Array(componentCount).fill(normalizationRange),
      );
      const packedDimensions = new Array(componentCount).fill(
        dracoQuantization.range,
      );
      quantization.quantizedVolumeDimensions =
        MathType.unpack(packedDimensions);
 
      // Computing the step size
      const packedSteps = packedDimensions.map(function (dimension) {
        return dimension * normalizationDivisor;
      });
      quantization.quantizedVolumeStepSize = MathType.unpack(packedSteps);
    }
  }
 
  return quantization;
}
 
async function loadFromSpz(vertexBufferLoader) {
  vertexBufferLoader._state = ResourceLoaderState.LOADING;
  const resourceCache = vertexBufferLoader._resourceCache;
  try {
    const spzLoader = resourceCache.getSpzLoader({
      gltf: vertexBufferLoader._gltf,
      primitive: vertexBufferLoader._primitive,
      spz: vertexBufferLoader._spz,
      gltfResource: vertexBufferLoader._gltfResource,
      baseResource: vertexBufferLoader._baseResource,
    });
    vertexBufferLoader._spzLoader = spzLoader;
    await spzLoader.load();
 
    Iif (vertexBufferLoader.isDestroyed()) {
      return;
    }
 
    vertexBufferLoader._state = ResourceLoaderState.LOADED;
    return vertexBufferLoader;
  } catch {
    if (vertexBufferLoader.isDestroyed()) {
      return;
    }
  }
}
 
function getShAttributePrefix(attribute) {
  const prefix = attribute.startsWith("KHR_gaussian_splatting:")
    ? "KHR_gaussian_splatting:"
    : "_";
  return `${prefix}SH_DEGREE_`;
}
 
function extractSHDegreeAndCoef(attribute) {
  const prefix = getShAttributePrefix(attribute);
  const separator = "_COEF_";
 
  const lStart = prefix.length;
  const coefIndex = attribute.indexOf(separator, lStart);
 
  const l = parseInt(attribute.slice(lStart, coefIndex), 10);
  const n = parseInt(attribute.slice(coefIndex + separator.length), 10);
 
  return { l, n };
}
 
function processSpz(vertexBufferLoader) {
  vertexBufferLoader._state = ResourceLoaderState.PROCESSING;
  const spzLoader = vertexBufferLoader._spzLoader;
 
  const gcloudData = spzLoader.decodedData.gcloud;
 
  if (vertexBufferLoader._attributeSemantic === "POSITION") {
    vertexBufferLoader._typedArray = gcloudData.positions;
  } else if (
    vertexBufferLoader._attributeSemantic === "KHR_gaussian_splatting:SCALE" ||
    vertexBufferLoader._attributeSemantic === "_SCALE"
  ) {
    vertexBufferLoader._typedArray = gcloudData.scales;
  } else if (
    vertexBufferLoader._attributeSemantic ===
      "KHR_gaussian_splatting:ROTATION" ||
    vertexBufferLoader._attributeSemantic === "_ROTATION"
  ) {
    vertexBufferLoader._typedArray = gcloudData.rotations;
  } else if (vertexBufferLoader._attributeSemantic === "COLOR_0") {
    const colors = gcloudData.colors;
    const alphas = gcloudData.alphas;
    vertexBufferLoader._typedArray = new Uint8Array((colors.length / 3) * 4);
    for (let i = 0; i < colors.length / 3; i++) {
      vertexBufferLoader._typedArray[i * 4] = CesiumMath.clamp(
        colors[i * 3] * 255.0,
        0.0,
        255.0,
      );
      vertexBufferLoader._typedArray[i * 4 + 1] = CesiumMath.clamp(
        colors[i * 3 + 1] * 255.0,
        0.0,
        255.0,
      );
      vertexBufferLoader._typedArray[i * 4 + 2] = CesiumMath.clamp(
        colors[i * 3 + 2] * 255.0,
        0.0,
        255.0,
      );
      vertexBufferLoader._typedArray[i * 4 + 3] = CesiumMath.clamp(
        alphas[i] * 255.0,
        0.0,
        255.0,
      );
    }
  } else Eif (vertexBufferLoader._attributeSemantic.includes("SH_DEGREE_")) {
    const { l, n } = extractSHDegreeAndCoef(
      vertexBufferLoader._attributeSemantic,
    );
    const sphericalHarmonicDegree = gcloudData.shDegree;
    let stride = 0;
    const base = [0, 9, 24];
    switch (sphericalHarmonicDegree) {
      case 1:
        stride = 9;
        break;
      case 2:
        stride = 24;
        break;
      case 3:
        stride = 45;
        break;
    }
    const count = gcloudData.numPoints;
    const sh = gcloudData.sh;
    vertexBufferLoader._typedArray = new Float32Array(count * 3);
    for (let i = 0; i < count; i++) {
      const idx = i * stride + base[l - 1] + n * 3;
      vertexBufferLoader._typedArray[i * 3] = sh[idx];
      vertexBufferLoader._typedArray[i * 3 + 1] = sh[idx + 1];
      vertexBufferLoader._typedArray[i * 3 + 2] = sh[idx + 2];
    }
  }
}
 
async function loadFromDraco(vertexBufferLoader) {
  vertexBufferLoader._state = ResourceLoaderState.LOADING;
  const resourceCache = vertexBufferLoader._resourceCache;
  try {
    const dracoLoader = resourceCache.getDracoLoader({
      gltf: vertexBufferLoader._gltf,
      primitive: vertexBufferLoader._primitive,
      draco: vertexBufferLoader._draco,
      gltfResource: vertexBufferLoader._gltfResource,
      baseResource: vertexBufferLoader._baseResource,
    });
    vertexBufferLoader._dracoLoader = dracoLoader;
    await dracoLoader.load();
 
    Iif (vertexBufferLoader.isDestroyed()) {
      return;
    }
 
    // Now wait for process() to run to finish loading
    vertexBufferLoader._state = ResourceLoaderState.LOADED;
    return vertexBufferLoader;
  } catch {
    if (vertexBufferLoader.isDestroyed()) {
      return;
    }
 
    handleError(vertexBufferLoader);
  }
}
 
function processDraco(vertexBufferLoader) {
  vertexBufferLoader._state = ResourceLoaderState.PROCESSING;
  const dracoLoader = vertexBufferLoader._dracoLoader;
 
  // Get the typed array and quantization information
  const decodedVertexAttributes = dracoLoader.decodedData.vertexAttributes;
  const attributeSemantic = vertexBufferLoader._attributeSemantic;
  const dracoAttribute = decodedVertexAttributes[attributeSemantic];
  const accessorId = vertexBufferLoader._accessorId;
  const accessor = vertexBufferLoader._gltf.accessors[accessorId];
  const type = accessor.type;
  const typedArray = dracoAttribute.array;
  const dracoQuantization = dracoAttribute.data.quantization;
  if (defined(dracoQuantization)) {
    vertexBufferLoader._quantization = getQuantizationInformation(
      dracoQuantization,
      dracoAttribute.data.componentDatatype,
      dracoAttribute.data.componentsPerAttribute,
      type,
    );
  }
 
  vertexBufferLoader._typedArray = new Uint8Array(
    typedArray.buffer,
    typedArray.byteOffset,
    typedArray.byteLength,
  );
}
 
async function loadFromBufferView(vertexBufferLoader) {
  vertexBufferLoader._state = ResourceLoaderState.LOADING;
  const resourceCache = vertexBufferLoader._resourceCache;
  try {
    const bufferViewLoader = resourceCache.getBufferViewLoader({
      gltf: vertexBufferLoader._gltf,
      bufferViewId: vertexBufferLoader._bufferViewId,
      gltfResource: vertexBufferLoader._gltfResource,
      baseResource: vertexBufferLoader._baseResource,
    });
    vertexBufferLoader._bufferViewLoader = bufferViewLoader;
    await bufferViewLoader.load();
 
    if (vertexBufferLoader.isDestroyed()) {
      return;
    }
 
    vertexBufferLoader._typedArray = bufferViewLoader.typedArray;
    vertexBufferLoader._state = ResourceLoaderState.PROCESSING;
    return vertexBufferLoader;
  } catch (error) {
    Iif (vertexBufferLoader.isDestroyed()) {
      return;
    }
 
    handleError(vertexBufferLoader, error);
  }
}
 
function handleError(vertexBufferLoader, error) {
  vertexBufferLoader.unload();
  vertexBufferLoader._state = ResourceLoaderState.FAILED;
  const errorMessage = "Failed to load vertex buffer";
  throw vertexBufferLoader.getError(errorMessage, error);
}
 
function CreateVertexBufferJob() {
  this.typedArray = undefined;
  this.context = undefined;
  this.buffer = undefined;
}
 
CreateVertexBufferJob.prototype.set = function (typedArray, context) {
  this.typedArray = typedArray;
  this.context = context;
};
 
CreateVertexBufferJob.prototype.execute = function () {
  this.buffer = createVertexBuffer(this.typedArray, this.context);
};
 
function createVertexBuffer(typedArray, context) {
  const buffer = Buffer.createVertexBuffer({
    typedArray: typedArray,
    context: context,
    usage: BufferUsage.STATIC_DRAW,
  });
  buffer.vertexArrayDestroyable = false;
  return buffer;
}
 
const scratchVertexBufferJob = new CreateVertexBufferJob();
 
/**
 * Processes the resource until it becomes ready.
 *
 * @param {FrameState} frameState The frame state.
 * @private
 */
GltfVertexBufferLoader.prototype.process = function (frameState) {
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.object("frameState", frameState);
  //>>includeEnd('debug');
 
  if (this._state === ResourceLoaderState.READY) {
    return true;
  }
 
  if (
    this._state !== ResourceLoaderState.LOADED &&
    this._state !== ResourceLoaderState.PROCESSING
  ) {
    return false;
  }
 
  if (defined(this._dracoLoader)) {
    try {
      const ready = this._dracoLoader.process(frameState);
      if (!ready) {
        return false;
      }
    } catch (error) {
      handleError(this, error);
    }
 
    processDraco(this);
  }
 
  if (defined(this._spzLoader)) {
    try {
      const ready = this._spzLoader.process(frameState);
      if (!ready) {
        return false;
      }
    } catch (error) {
      handleError(this, error);
    }
 
    processSpz(this);
  }
 
  let buffer;
  const typedArray = this._typedArray;
  if (this._loadBuffer && this._asynchronous) {
    const vertexBufferJob = scratchVertexBufferJob;
    vertexBufferJob.set(typedArray, frameState.context);
    const jobScheduler = frameState.jobScheduler;
    if (!jobScheduler.execute(vertexBufferJob, JobType.BUFFER)) {
      // Job scheduler is full. Try again next frame.
      return false;
    }
    buffer = vertexBufferJob.buffer;
  } else if (this._loadBuffer) {
    buffer = createVertexBuffer(typedArray, frameState.context);
  }
 
  // Unload everything except the vertex buffer
  this.unload();
 
  this._buffer = buffer;
  this._typedArray = this._loadTypedArray ? typedArray : undefined;
  this._state = ResourceLoaderState.READY;
  this._resourceCache.statistics.addGeometryLoader(this);
  return true;
};
 
/**
 * Unloads the resource.
 * @private
 */
GltfVertexBufferLoader.prototype.unload = function () {
  if (defined(this._buffer)) {
    this._buffer.destroy();
  }
 
  const resourceCache = this._resourceCache;
 
  if (
    defined(this._bufferViewLoader) &&
    !this._bufferViewLoader.isDestroyed()
  ) {
    resourceCache.unload(this._bufferViewLoader);
  }
 
  if (defined(this._dracoLoader)) {
    resourceCache.unload(this._dracoLoader);
  }
 
  if (defined(this._spzLoader)) {
    resourceCache.unload(this._spzLoader);
  }
 
  this._bufferViewLoader = undefined;
  this._dracoLoader = undefined;
  this._spzLoader = undefined;
  this._typedArray = undefined;
  this._buffer = undefined;
  this._gltf = undefined;
  this._primitive = undefined;
};
 
export default GltfVertexBufferLoader;