Spaces:
Sleeping
Sleeping
File size: 2,325 Bytes
2b7aae2 | 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 | import * as MathUtils from '../math/MathUtils.js';
import { StaticDrawUsage } from '../constants.js';
class InterleavedBuffer {
constructor(array, stride) {
this.array = array;
this.stride = stride;
this.count = array !== undefined ? array.length / stride : 0;
this.usage = StaticDrawUsage;
this.updateRange = { offset: 0, count: -1 };
this.version = 0;
this.uuid = MathUtils.generateUUID();
}
onUploadCallback() {}
set needsUpdate(value) {
if (value === true) this.version++;
}
setUsage(value) {
this.usage = value;
return this;
}
copy(source) {
this.array = new source.array.constructor(source.array);
this.count = source.count;
this.stride = source.stride;
this.usage = source.usage;
return this;
}
copyAt(index1, attribute, index2) {
index1 *= this.stride;
index2 *= attribute.stride;
for (let i = 0, l = this.stride; i < l; i++) {
this.array[index1 + i] = attribute.array[index2 + i];
}
return this;
}
set(value, offset = 0) {
this.array.set(value, offset);
return this;
}
clone(data) {
if (data.arrayBuffers === undefined) {
data.arrayBuffers = {};
}
if (this.array.buffer._uuid === undefined) {
this.array.buffer._uuid = MathUtils.generateUUID();
}
if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
}
const array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
const ib = new this.constructor(array, this.stride);
ib.setUsage(this.usage);
return ib;
}
onUpload(callback) {
this.onUploadCallback = callback;
return this;
}
toJSON(data) {
if (data.arrayBuffers === undefined) {
data.arrayBuffers = {};
}
// generate UUID for array buffer if necessary
if (this.array.buffer._uuid === undefined) {
this.array.buffer._uuid = MathUtils.generateUUID();
}
if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
}
//
return {
uuid: this.uuid,
buffer: this.array.buffer._uuid,
type: this.array.constructor.name,
stride: this.stride,
};
}
}
InterleavedBuffer.prototype.isInterleavedBuffer = true;
export { InterleavedBuffer };
|