mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 09:24:18 +01:00
26 lines
759 B
JavaScript
26 lines
759 B
JavaScript
import {BoxGeometry, BufferGeometry, BufferAttribute, Vector3} from 'three';
|
|
import {normalOfCCWSeq} from "cad/cad-utils";
|
|
|
|
export function createBoxGeometry(width, height, depth) {
|
|
return new BoxGeometry(width, height, depth);
|
|
}
|
|
|
|
export function createMeshGeometry(triangles) {
|
|
|
|
const vertices = [];
|
|
const normals = [];
|
|
triangles.forEach(tr => {
|
|
const normal = normalOfCCWSeq(tr);
|
|
tr.forEach(p => {
|
|
vertices.push(p.x, p.y, p.z);
|
|
normals.push(normal.x, normal.y, normal.z);
|
|
})
|
|
});
|
|
|
|
|
|
const geometry = new BufferGeometry();
|
|
geometry.setAttribute('position', new BufferAttribute( new Float32Array(vertices), 3 ) );
|
|
geometry.setAttribute('normal', new BufferAttribute( new Float32Array(normals), 3));
|
|
|
|
return geometry;
|
|
}
|