Spaces:
Running
Running
File size: 21,139 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 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 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | import { Vector3 } from '../math/Vector3.js';
import { Vector2 } from '../math/Vector2.js';
import { Box3 } from '../math/Box3.js';
import { EventDispatcher } from './EventDispatcher.js';
import { BufferAttribute, Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from './BufferAttribute.js';
import { Sphere } from '../math/Sphere.js';
import { Object3D } from './Object3D.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Matrix3 } from '../math/Matrix3.js';
import * as MathUtils from '../math/MathUtils.js';
import { arrayMax } from '../utils.js';
let _id = 0;
const _m1 = /*@__PURE__*/ new Matrix4();
const _obj = /*@__PURE__*/ new Object3D();
const _offset = /*@__PURE__*/ new Vector3();
const _box = /*@__PURE__*/ new Box3();
const _boxMorphTargets = /*@__PURE__*/ new Box3();
const _vector = /*@__PURE__*/ new Vector3();
class BufferGeometry extends EventDispatcher {
constructor() {
super();
Object.defineProperty(this, 'id', { value: _id++ });
this.uuid = MathUtils.generateUUID();
this.name = '';
this.type = 'BufferGeometry';
this.index = null;
this.attributes = {};
this.morphAttributes = {};
this.morphTargetsRelative = false;
this.groups = [];
this.boundingBox = null;
this.boundingSphere = null;
this.drawRange = { start: 0, count: Infinity };
this.userData = {};
}
getIndex() {
return this.index;
}
setIndex(index) {
if (Array.isArray(index)) {
this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
} else {
this.index = index;
}
return this;
}
getAttribute(name) {
return this.attributes[name];
}
setAttribute(name, attribute) {
this.attributes[name] = attribute;
return this;
}
deleteAttribute(name) {
delete this.attributes[name];
return this;
}
hasAttribute(name) {
return this.attributes[name] !== undefined;
}
addGroup(start, count, materialIndex = 0) {
this.groups.push({
start: start,
count: count,
materialIndex: materialIndex,
});
}
clearGroups() {
this.groups = [];
}
setDrawRange(start, count) {
this.drawRange.start = start;
this.drawRange.count = count;
}
applyMatrix4(matrix) {
const position = this.attributes.position;
if (position !== undefined) {
position.applyMatrix4(matrix);
position.needsUpdate = true;
}
const normal = this.attributes.normal;
if (normal !== undefined) {
const normalMatrix = new Matrix3().getNormalMatrix(matrix);
normal.applyNormalMatrix(normalMatrix);
normal.needsUpdate = true;
}
const tangent = this.attributes.tangent;
if (tangent !== undefined) {
tangent.transformDirection(matrix);
tangent.needsUpdate = true;
}
if (this.boundingBox !== null) {
this.computeBoundingBox();
}
if (this.boundingSphere !== null) {
this.computeBoundingSphere();
}
return this;
}
applyQuaternion(q) {
_m1.makeRotationFromQuaternion(q);
this.applyMatrix4(_m1);
return this;
}
rotateX(angle) {
// rotate geometry around world x-axis
_m1.makeRotationX(angle);
this.applyMatrix4(_m1);
return this;
}
rotateY(angle) {
// rotate geometry around world y-axis
_m1.makeRotationY(angle);
this.applyMatrix4(_m1);
return this;
}
rotateZ(angle) {
// rotate geometry around world z-axis
_m1.makeRotationZ(angle);
this.applyMatrix4(_m1);
return this;
}
translate(x, y, z) {
// translate geometry
_m1.makeTranslation(x, y, z);
this.applyMatrix4(_m1);
return this;
}
scale(x, y, z) {
// scale geometry
_m1.makeScale(x, y, z);
this.applyMatrix4(_m1);
return this;
}
lookAt(vector) {
_obj.lookAt(vector);
_obj.updateMatrix();
this.applyMatrix4(_obj.matrix);
return this;
}
center() {
this.computeBoundingBox();
this.boundingBox.getCenter(_offset).negate();
this.translate(_offset.x, _offset.y, _offset.z);
return this;
}
setFromPoints(points) {
const position = [];
for (let i = 0, l = points.length; i < l; i++) {
const point = points[i];
position.push(point.x, point.y, point.z || 0);
}
this.setAttribute('position', new Float32BufferAttribute(position, 3));
return this;
}
computeBoundingBox() {
if (this.boundingBox === null) {
this.boundingBox = new Box3();
}
const position = this.attributes.position;
const morphAttributesPosition = this.morphAttributes.position;
if (position && position.isGLBufferAttribute) {
console.error(
'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".',
this
);
this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
return;
}
if (position !== undefined) {
this.boundingBox.setFromBufferAttribute(position);
// process morph attributes if present
if (morphAttributesPosition) {
for (let i = 0, il = morphAttributesPosition.length; i < il; i++) {
const morphAttribute = morphAttributesPosition[i];
_box.setFromBufferAttribute(morphAttribute);
if (this.morphTargetsRelative) {
_vector.addVectors(this.boundingBox.min, _box.min);
this.boundingBox.expandByPoint(_vector);
_vector.addVectors(this.boundingBox.max, _box.max);
this.boundingBox.expandByPoint(_vector);
} else {
this.boundingBox.expandByPoint(_box.min);
this.boundingBox.expandByPoint(_box.max);
}
}
}
} else {
this.boundingBox.makeEmpty();
}
if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
console.error(
'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',
this
);
}
}
computeBoundingSphere() {
if (this.boundingSphere === null) {
this.boundingSphere = new Sphere();
}
const position = this.attributes.position;
const morphAttributesPosition = this.morphAttributes.position;
if (position && position.isGLBufferAttribute) {
console.error(
'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".',
this
);
this.boundingSphere.set(new Vector3(), Infinity);
return;
}
if (position) {
// first, find the center of the bounding sphere
const center = this.boundingSphere.center;
_box.setFromBufferAttribute(position);
// process morph attributes if present
if (morphAttributesPosition) {
for (let i = 0, il = morphAttributesPosition.length; i < il; i++) {
const morphAttribute = morphAttributesPosition[i];
_boxMorphTargets.setFromBufferAttribute(morphAttribute);
if (this.morphTargetsRelative) {
_vector.addVectors(_box.min, _boxMorphTargets.min);
_box.expandByPoint(_vector);
_vector.addVectors(_box.max, _boxMorphTargets.max);
_box.expandByPoint(_vector);
} else {
_box.expandByPoint(_boxMorphTargets.min);
_box.expandByPoint(_boxMorphTargets.max);
}
}
}
_box.getCenter(center);
// second, try to find a boundingSphere with a radius smaller than the
// boundingSphere of the boundingBox: sqrt(3) smaller in the best case
let maxRadiusSq = 0;
for (let i = 0, il = position.count; i < il; i++) {
_vector.fromBufferAttribute(position, i);
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
}
// process morph attributes if present
if (morphAttributesPosition) {
for (let i = 0, il = morphAttributesPosition.length; i < il; i++) {
const morphAttribute = morphAttributesPosition[i];
const morphTargetsRelative = this.morphTargetsRelative;
for (let j = 0, jl = morphAttribute.count; j < jl; j++) {
_vector.fromBufferAttribute(morphAttribute, j);
if (morphTargetsRelative) {
_offset.fromBufferAttribute(position, j);
_vector.add(_offset);
}
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
}
}
}
this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
if (isNaN(this.boundingSphere.radius)) {
console.error(
'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',
this
);
}
}
}
computeTangents() {
const index = this.index;
const attributes = this.attributes;
// based on http://www.terathon.com/code/tangent.html
// (per vertex tangents)
if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
return;
}
const indices = index.array;
const positions = attributes.position.array;
const normals = attributes.normal.array;
const uvs = attributes.uv.array;
const nVertices = positions.length / 3;
if (attributes.tangent === undefined) {
this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
}
const tangents = attributes.tangent.array;
const tan1 = [],
tan2 = [];
for (let i = 0; i < nVertices; i++) {
tan1[i] = new Vector3();
tan2[i] = new Vector3();
}
const vA = new Vector3(),
vB = new Vector3(),
vC = new Vector3(),
uvA = new Vector2(),
uvB = new Vector2(),
uvC = new Vector2(),
sdir = new Vector3(),
tdir = new Vector3();
function handleTriangle(a, b, c) {
vA.fromArray(positions, a * 3);
vB.fromArray(positions, b * 3);
vC.fromArray(positions, c * 3);
uvA.fromArray(uvs, a * 2);
uvB.fromArray(uvs, b * 2);
uvC.fromArray(uvs, c * 2);
vB.sub(vA);
vC.sub(vA);
uvB.sub(uvA);
uvC.sub(uvA);
const r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y);
// silently ignore degenerate uv triangles having coincident or colinear vertices
if (!isFinite(r)) return;
sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
tan1[a].add(sdir);
tan1[b].add(sdir);
tan1[c].add(sdir);
tan2[a].add(tdir);
tan2[b].add(tdir);
tan2[c].add(tdir);
}
let groups = this.groups;
if (groups.length === 0) {
groups = [
{
start: 0,
count: indices.length,
},
];
}
for (let i = 0, il = groups.length; i < il; ++i) {
const group = groups[i];
const start = group.start;
const count = group.count;
for (let j = start, jl = start + count; j < jl; j += 3) {
handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
}
}
const tmp = new Vector3(),
tmp2 = new Vector3();
const n = new Vector3(),
n2 = new Vector3();
function handleVertex(v) {
n.fromArray(normals, v * 3);
n2.copy(n);
const t = tan1[v];
// Gram-Schmidt orthogonalize
tmp.copy(t);
tmp.sub(n.multiplyScalar(n.dot(t))).normalize();
// Calculate handedness
tmp2.crossVectors(n2, t);
const test = tmp2.dot(tan2[v]);
const w = test < 0.0 ? -1.0 : 1.0;
tangents[v * 4] = tmp.x;
tangents[v * 4 + 1] = tmp.y;
tangents[v * 4 + 2] = tmp.z;
tangents[v * 4 + 3] = w;
}
for (let i = 0, il = groups.length; i < il; ++i) {
const group = groups[i];
const start = group.start;
const count = group.count;
for (let j = start, jl = start + count; j < jl; j += 3) {
handleVertex(indices[j + 0]);
handleVertex(indices[j + 1]);
handleVertex(indices[j + 2]);
}
}
}
computeVertexNormals() {
const index = this.index;
const positionAttribute = this.getAttribute('position');
if (positionAttribute !== undefined) {
let normalAttribute = this.getAttribute('normal');
if (normalAttribute === undefined) {
normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
this.setAttribute('normal', normalAttribute);
} else {
// reset existing normals to zero
for (let i = 0, il = normalAttribute.count; i < il; i++) {
normalAttribute.setXYZ(i, 0, 0, 0);
}
}
const pA = new Vector3(),
pB = new Vector3(),
pC = new Vector3();
const nA = new Vector3(),
nB = new Vector3(),
nC = new Vector3();
const cb = new Vector3(),
ab = new Vector3();
// indexed elements
if (index) {
for (let i = 0, il = index.count; i < il; i += 3) {
const vA = index.getX(i + 0);
const vB = index.getX(i + 1);
const vC = index.getX(i + 2);
pA.fromBufferAttribute(positionAttribute, vA);
pB.fromBufferAttribute(positionAttribute, vB);
pC.fromBufferAttribute(positionAttribute, vC);
cb.subVectors(pC, pB);
ab.subVectors(pA, pB);
cb.cross(ab);
nA.fromBufferAttribute(normalAttribute, vA);
nB.fromBufferAttribute(normalAttribute, vB);
nC.fromBufferAttribute(normalAttribute, vC);
nA.add(cb);
nB.add(cb);
nC.add(cb);
normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
}
} else {
// non-indexed elements (unconnected triangle soup)
for (let i = 0, il = positionAttribute.count; i < il; i += 3) {
pA.fromBufferAttribute(positionAttribute, i + 0);
pB.fromBufferAttribute(positionAttribute, i + 1);
pC.fromBufferAttribute(positionAttribute, i + 2);
cb.subVectors(pC, pB);
ab.subVectors(pA, pB);
cb.cross(ab);
normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z);
normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z);
normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z);
}
}
this.normalizeNormals();
normalAttribute.needsUpdate = true;
}
}
merge(geometry, offset) {
if (!(geometry && geometry.isBufferGeometry)) {
console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
return;
}
if (offset === undefined) {
offset = 0;
console.warn(
'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' +
'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
);
}
const attributes = this.attributes;
for (const key in attributes) {
if (geometry.attributes[key] === undefined) continue;
const attribute1 = attributes[key];
const attributeArray1 = attribute1.array;
const attribute2 = geometry.attributes[key];
const attributeArray2 = attribute2.array;
const attributeOffset = attribute2.itemSize * offset;
const length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
for (let i = 0, j = attributeOffset; i < length; i++, j++) {
attributeArray1[j] = attributeArray2[i];
}
}
return this;
}
normalizeNormals() {
const normals = this.attributes.normal;
for (let i = 0, il = normals.count; i < il; i++) {
_vector.fromBufferAttribute(normals, i);
_vector.normalize();
normals.setXYZ(i, _vector.x, _vector.y, _vector.z);
}
}
toNonIndexed() {
function convertBufferAttribute(attribute, indices) {
const array = attribute.array;
const itemSize = attribute.itemSize;
const normalized = attribute.normalized;
const array2 = new array.constructor(indices.length * itemSize);
let index = 0,
index2 = 0;
for (let i = 0, l = indices.length; i < l; i++) {
if (attribute.isInterleavedBufferAttribute) {
index = indices[i] * attribute.data.stride + attribute.offset;
} else {
index = indices[i] * itemSize;
}
for (let j = 0; j < itemSize; j++) {
array2[index2++] = array[index++];
}
}
return new BufferAttribute(array2, itemSize, normalized);
}
//
if (this.index === null) {
console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
return this;
}
const geometry2 = new BufferGeometry();
const indices = this.index.array;
const attributes = this.attributes;
// attributes
for (const name in attributes) {
const attribute = attributes[name];
const newAttribute = convertBufferAttribute(attribute, indices);
geometry2.setAttribute(name, newAttribute);
}
// morph attributes
const morphAttributes = this.morphAttributes;
for (const name in morphAttributes) {
const morphArray = [];
const morphAttribute = morphAttributes[name]; // morphAttribute: array of Float32BufferAttributes
for (let i = 0, il = morphAttribute.length; i < il; i++) {
const attribute = morphAttribute[i];
const newAttribute = convertBufferAttribute(attribute, indices);
morphArray.push(newAttribute);
}
geometry2.morphAttributes[name] = morphArray;
}
geometry2.morphTargetsRelative = this.morphTargetsRelative;
// groups
const groups = this.groups;
for (let i = 0, l = groups.length; i < l; i++) {
const group = groups[i];
geometry2.addGroup(group.start, group.count, group.materialIndex);
}
return geometry2;
}
toJSON() {
const data = {
metadata: {
version: 4.5,
type: 'BufferGeometry',
generator: 'BufferGeometry.toJSON',
},
};
// standard BufferGeometry serialization
data.uuid = this.uuid;
data.type = this.type;
if (this.name !== '') data.name = this.name;
if (Object.keys(this.userData).length > 0) data.userData = this.userData;
if (this.parameters !== undefined) {
const parameters = this.parameters;
for (const key in parameters) {
if (parameters[key] !== undefined) data[key] = parameters[key];
}
return data;
}
// for simplicity the code assumes attributes are not shared across geometries, see #15811
data.data = { attributes: {} };
const index = this.index;
if (index !== null) {
data.data.index = {
type: index.array.constructor.name,
array: Array.prototype.slice.call(index.array),
};
}
const attributes = this.attributes;
for (const key in attributes) {
const attribute = attributes[key];
data.data.attributes[key] = attribute.toJSON(data.data);
}
const morphAttributes = {};
let hasMorphAttributes = false;
for (const key in this.morphAttributes) {
const attributeArray = this.morphAttributes[key];
const array = [];
for (let i = 0, il = attributeArray.length; i < il; i++) {
const attribute = attributeArray[i];
array.push(attribute.toJSON(data.data));
}
if (array.length > 0) {
morphAttributes[key] = array;
hasMorphAttributes = true;
}
}
if (hasMorphAttributes) {
data.data.morphAttributes = morphAttributes;
data.data.morphTargetsRelative = this.morphTargetsRelative;
}
const groups = this.groups;
if (groups.length > 0) {
data.data.groups = JSON.parse(JSON.stringify(groups));
}
const boundingSphere = this.boundingSphere;
if (boundingSphere !== null) {
data.data.boundingSphere = {
center: boundingSphere.center.toArray(),
radius: boundingSphere.radius,
};
}
return data;
}
clone() {
return new this.constructor().copy(this);
}
copy(source) {
// reset
this.index = null;
this.attributes = {};
this.morphAttributes = {};
this.groups = [];
this.boundingBox = null;
this.boundingSphere = null;
// used for storing cloned, shared data
const data = {};
// name
this.name = source.name;
// index
const index = source.index;
if (index !== null) {
this.setIndex(index.clone(data));
}
// attributes
const attributes = source.attributes;
for (const name in attributes) {
const attribute = attributes[name];
this.setAttribute(name, attribute.clone(data));
}
// morph attributes
const morphAttributes = source.morphAttributes;
for (const name in morphAttributes) {
const array = [];
const morphAttribute = morphAttributes[name]; // morphAttribute: array of Float32BufferAttributes
for (let i = 0, l = morphAttribute.length; i < l; i++) {
array.push(morphAttribute[i].clone(data));
}
this.morphAttributes[name] = array;
}
this.morphTargetsRelative = source.morphTargetsRelative;
// groups
const groups = source.groups;
for (let i = 0, l = groups.length; i < l; i++) {
const group = groups[i];
this.addGroup(group.start, group.count, group.materialIndex);
}
// bounding box
const boundingBox = source.boundingBox;
if (boundingBox !== null) {
this.boundingBox = boundingBox.clone();
}
// bounding sphere
const boundingSphere = source.boundingSphere;
if (boundingSphere !== null) {
this.boundingSphere = boundingSphere.clone();
}
// draw range
this.drawRange.start = source.drawRange.start;
this.drawRange.count = source.drawRange.count;
// user data
this.userData = source.userData;
// geometry generator parameters
if (source.parameters !== undefined) this.parameters = Object.assign({}, source.parameters);
return this;
}
dispose() {
this.dispatchEvent({ type: 'dispose' });
}
}
BufferGeometry.prototype.isBufferGeometry = true;
export { BufferGeometry };
|