mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- Compile mesh construction, transforms, cloning, and material updates for native and WASI targets. - Preserve subclass dispatch, fluent returns, and shared array identity in JavaScript packages. - Support native class arrays and recursive conversions without materializing classes for type checks.
34 lines
1.8 KiB
JavaScript
34 lines
1.8 KiB
JavaScript
import { Mesh } from 'three/src/objects/Mesh.js';
|
|
import { BoxGeometry } from 'three/src/geometries/BoxGeometry.js';
|
|
import { MeshNormalMaterial } from 'three/src/materials/MeshNormalMaterial.js';
|
|
import { Scene } from 'three/src/scenes/Scene.js';
|
|
import { Vector3 } from 'three/src/math/Vector3.js';
|
|
|
|
const geometry = new BoxGeometry(2, 4, 6);
|
|
const material = new MeshNormalMaterial();
|
|
const mesh = new Mesh(geometry, material);
|
|
console.log('mesh', mesh.type, mesh.isMesh, mesh.geometry === geometry, mesh.material === material);
|
|
const scene = new Scene();
|
|
scene.add(mesh);
|
|
mesh.position.set(1, 2, 3);
|
|
scene.updateMatrixWorld();
|
|
const point = mesh.getVertexPosition(0, new Vector3());
|
|
console.log('vertex', point.x, point.y, point.z);
|
|
console.log('world', mesh.matrixWorld.elements[12], mesh.matrixWorld.elements[13], mesh.matrixWorld.elements[14]);
|
|
const copy = mesh.clone();
|
|
console.log('copy', copy !== mesh, copy.geometry === geometry, copy.material === material, copy.position.x);
|
|
copy.position.x = 7;
|
|
console.log('independent', mesh.position.x, copy.position.x);
|
|
const other = new Mesh(geometry, material);
|
|
console.log('fluent', other.copy(mesh) === other, other.copy(mesh).geometry === geometry);
|
|
const child = new Mesh(geometry, material);
|
|
child.position.y = 3;
|
|
mesh.add(child);
|
|
const recursive = mesh.clone();
|
|
console.log('children', recursive.children.length, recursive.children[0] !== child, recursive.children[0].position.y);
|
|
console.log('shallow', mesh.clone(false).children.length);
|
|
const materials = [material, new MeshNormalMaterial({wireframe: true})];
|
|
const multi = new Mesh(geometry, materials);
|
|
const multiCopy = multi.clone();
|
|
console.log('materials', multiCopy.material !== multi.material, multiCopy.material.length, multiCopy.material[0] === material, multiCopy.material[1].wireframe);
|