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 | 6900x 6900x 6900x 6900x 6900x 6900x 6900x 6900x 6899x 6898x 6897x 6896x 6895x 6895x 6895x 6895x 6895x 6895x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 6895x 1x 1x 1x 1x 21316x 7496x 6894x 6894x 6894x 6894x 6880x 30x 6850x 6850x 6850x 6850x 6850x 1x 1x 1x 1x 1x 6850x 6850x 14x 14x 14x 14x 14x 1x 7546x 652x 6894x 6894x 6894x 6894x 6894x 6894x 1571x 1571x 1571x 5323x 5323x 1x 13755x 6894x 13755x 13755x | import Check from "../Core/Check.js";
import Frozen from "../Core/Frozen.js";
import defined from "../Core/defined.js";
import hasExtension from "./hasExtension.js";
import { MeshoptDecoder } from "meshoptimizer";
import ResourceLoader from "./ResourceLoader.js";
import ResourceLoaderState from "./ResourceLoaderState.js";
/**
* Loads a glTF buffer view.
* <p>
* Implements the {@link ResourceLoader} interface.
* </p>
*
* @alias GltfBufferViewLoader
* @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 {number} options.bufferViewId The buffer view ID.
* @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 {string} [options.cacheKey] The cache key of the resource.
*
* @private
*/
function GltfBufferViewLoader(options) {
options = options ?? Frozen.EMPTY_OBJECT;
const resourceCache = options.resourceCache;
const gltf = options.gltf;
const bufferViewId = options.bufferViewId;
const gltfResource = options.gltfResource;
const baseResource = options.baseResource;
const cacheKey = options.cacheKey;
//>>includeStart('debug', pragmas.debug);
Check.typeOf.func("options.resourceCache", resourceCache);
Check.typeOf.object("options.gltf", gltf);
Check.typeOf.number("options.bufferViewId", bufferViewId);
Check.typeOf.object("options.gltfResource", gltfResource);
Check.typeOf.object("options.baseResource", baseResource);
//>>includeEnd('debug');
const bufferView = gltf.bufferViews[bufferViewId];
let bufferId = bufferView.buffer;
let byteOffset = bufferView.byteOffset;
let byteLength = bufferView.byteLength;
let hasMeshopt = false;
let meshoptByteStride;
let meshoptCount;
let meshoptMode;
let meshoptFilter;
if (hasExtension(bufferView, "EXT_meshopt_compression")) {
const meshopt = bufferView.extensions.EXT_meshopt_compression;
bufferId = meshopt.buffer;
byteOffset = meshopt.byteOffset ?? 0;
byteLength = meshopt.byteLength;
hasMeshopt = true;
meshoptByteStride = meshopt.byteStride;
meshoptCount = meshopt.count;
meshoptMode = meshopt.mode;
meshoptFilter = meshopt.filter ?? "NONE";
}
const buffer = gltf.buffers[bufferId];
this._hasMeshopt = hasMeshopt;
this._meshoptByteStride = meshoptByteStride;
this._meshoptCount = meshoptCount;
this._meshoptMode = meshoptMode;
this._meshoptFilter = meshoptFilter;
this._resourceCache = resourceCache;
this._gltfResource = gltfResource;
this._baseResource = baseResource;
this._buffer = buffer;
this._bufferId = bufferId;
this._byteOffset = byteOffset;
this._byteLength = byteLength;
this._cacheKey = cacheKey;
this._bufferLoader = undefined;
this._typedArray = undefined;
this._state = ResourceLoaderState.UNLOADED;
this._promise = undefined;
}
Eif (defined(Object.create)) {
GltfBufferViewLoader.prototype = Object.create(ResourceLoader.prototype);
GltfBufferViewLoader.prototype.constructor = GltfBufferViewLoader;
}
Object.defineProperties(GltfBufferViewLoader.prototype, {
/**
* The cache key of the resource.
*
* @memberof GltfBufferViewLoader.prototype
*
* @type {string}
* @readonly
* @private
*/
cacheKey: {
get: function () {
return this._cacheKey;
},
},
/**
* The typed array containing buffer view data.
*
* @memberof GltfBufferViewLoader.prototype
*
* @type {Uint8Array}
* @readonly
* @private
*/
typedArray: {
get: function () {
return this._typedArray;
},
},
});
/**
* Load the resources associated with the loader.
* @private
* @param {GltfBufferViewLoader} loader
* @returns {Promise<GltfBufferViewLoader>}
*/
async function loadResources(loader) {
try {
const bufferLoader = getBufferLoader(loader);
loader._bufferLoader = bufferLoader;
await bufferLoader.load();
if (loader.isDestroyed()) {
return;
}
const bufferTypedArray = bufferLoader.typedArray;
const bufferViewTypedArray = new Uint8Array(
bufferTypedArray.buffer,
bufferTypedArray.byteOffset + loader._byteOffset,
loader._byteLength,
);
// Unload the buffer
loader.unload();
loader._typedArray = bufferViewTypedArray;
if (loader._hasMeshopt) {
const count = loader._meshoptCount;
const byteStride = loader._meshoptByteStride;
const result = new Uint8Array(count * byteStride);
MeshoptDecoder.decodeGltfBuffer(
result,
count,
byteStride,
loader._typedArray,
loader._meshoptMode,
loader._meshoptFilter,
);
loader._typedArray = result;
}
loader._state = ResourceLoaderState.READY;
return loader;
} catch (error) {
Iif (loader.isDestroyed()) {
return;
}
loader.unload();
loader._state = ResourceLoaderState.FAILED;
const errorMessage = "Failed to load buffer view";
throw loader.getError(errorMessage, error);
}
}
/**
* Loads the resource.
* @returns {Promise<GltfBufferViewLoader>} A promise which resolves to the loader when the resource loading is completed.
* @private
*/
GltfBufferViewLoader.prototype.load = async function () {
if (defined(this._promise)) {
return this._promise;
}
this._state = ResourceLoaderState.LOADING;
this._promise = loadResources(this);
return this._promise;
};
/**
* Get the buffer loader for the specified buffer view loader.
* Attempts to retrieve from the resource cache first. If a buffer loader is
* not found, creates a new buffer loader and adds it to the resource cache.
* @private
* @param {GltfBufferViewLoader} bufferViewLoader The loader.
* @returns {BufferLoader} The buffer loader.
*/
function getBufferLoader(bufferViewLoader) {
const resourceCache = bufferViewLoader._resourceCache;
const buffer = bufferViewLoader._buffer;
if (defined(buffer.uri)) {
const baseResource = bufferViewLoader._baseResource;
const resource = baseResource.getDerivedResource({
url: buffer.uri,
});
return resourceCache.getExternalBufferLoader({
resource: resource,
});
}
const source = buffer.extras?._pipeline?.source;
return resourceCache.getEmbeddedBufferLoader({
parentResource: bufferViewLoader._gltfResource,
bufferId: bufferViewLoader._bufferId,
typedArray: source,
});
}
/**
* Unloads the resource.
* @private
*/
GltfBufferViewLoader.prototype.unload = function () {
if (defined(this._bufferLoader) && !this._bufferLoader.isDestroyed()) {
this._resourceCache.unload(this._bufferLoader);
}
this._bufferLoader = undefined;
this._typedArray = undefined;
};
export default GltfBufferViewLoader;
|