mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-22 05:59:31 +08:00
- Support published three.js rotations, bounds, ray intersections, culling, and vertex attributes on native and WASM targets without a JavaScript engine. - Preserve JavaScript class defaults, data descriptors, and captured loop bindings in static code. - Handle typed-array input unions and constructor identities while keeping unsupported method overrides explicit.
37 lines
2.1 KiB
JavaScript
37 lines
2.1 KiB
JavaScript
import { Float32BufferAttribute, Uint8BufferAttribute, Uint16BufferAttribute } from 'three/src/core/BufferAttribute.js';
|
|
import { Matrix3 } from 'three/src/math/Matrix3.js';
|
|
import { Matrix4 } from 'three/src/math/Matrix4.js';
|
|
import { Box3 } from 'three/src/math/Box3.js';
|
|
import { Vector3 } from 'three/src/math/Vector3.js';
|
|
const positions = new Float32BufferAttribute([0, 0, 0, 1, 2, 3], 3);
|
|
console.log(positions.count, positions.itemSize, positions.getX(1), positions.getY(1), positions.getZ(1));
|
|
positions.applyMatrix4(new Matrix4().makeTranslation(2, 3, 4));
|
|
console.log(positions.getX(0), positions.getY(0), positions.getZ(0), positions.getX(1), positions.getY(1), positions.getZ(1));
|
|
const bounds = new Box3().setFromBufferAttribute(positions);
|
|
console.log(bounds.min.x, bounds.min.y, bounds.min.z, bounds.max.x, bounds.max.y, bounds.max.z);
|
|
const indices = new Uint16BufferAttribute([0, 1, 2], 1);
|
|
console.log(indices.count, indices.getX(1));
|
|
console.log(Object.hasOwn(positions, 'id'), Object.keys(positions).includes('id'));
|
|
const descriptor = Object.getOwnPropertyDescriptor(positions, 'id');
|
|
console.log(descriptor.writable, descriptor.enumerable, descriptor.configurable);
|
|
const source = new Float32Array([2, 4, 6]);
|
|
const copied = new Float32BufferAttribute(source, 3);
|
|
source[0] = 100;
|
|
console.log('copy', copied.getX(0), copied.getY(0), copied.getZ(0));
|
|
copied.setXYZ(0, 3, 2, 1);
|
|
copied.applyMatrix3(new Matrix3().set(2, 0, 0, 0, 3, 0, 0, 0, 4));
|
|
console.log('matrix3', copied.getX(0), copied.getY(0), copied.getZ(0));
|
|
const vector = new Vector3().fromBufferAttribute(copied, 0);
|
|
console.log('vector', vector.x, vector.y, vector.z);
|
|
const colors = new Uint8BufferAttribute([0, 255, 0, 255], 4, true);
|
|
console.log('normalized', colors.getX(0), colors.getY(0), colors.getW(0));
|
|
colors.setX(0, 1);
|
|
console.log('stored', colors.array[0]);
|
|
copied.addUpdateRange(0, 3);
|
|
console.log('ranges', copied.updateRanges.length, copied.updateRanges[0].start, copied.updateRanges[0].count);
|
|
copied.clearUpdateRanges();
|
|
console.log('cleared', copied.updateRanges.length);
|
|
const before = copied.version;
|
|
copied.needsUpdate = true;
|
|
console.log('updated', copied.version === before + 1);
|