New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

three-stdlib

Package Overview
Dependencies
Maintainers
3
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-stdlib - npm Package Compare versions

Comparing version 2.29.2 to 2.29.3

35

exporters/STLExporter.d.ts

@@ -1,21 +0,28 @@

import { Object3D } from 'three'
import { Object3D } from 'three';
export interface STLExporterOptionsBinary {
binary: true
binary: true;
}
export interface STLExporterOptionsString {
binary?: false
binary?: false;
}
export interface STLExporterOptions {
binary?: boolean
binary?: boolean;
}
export class STLExporter {
constructor()
parse(scene: Object3D, options: STLExporterOptionsBinary): DataView
parse(scene: Object3D, options?: STLExporterOptionsString): string
parse(scene: Object3D, options?: STLExporterOptions): string | DataView
export declare class STLExporter {
private binary;
private output;
private offset;
private objects;
private triangles;
private vA;
private vB;
private vC;
private cb;
private ab;
private normal;
parse(scene: Object3D, options: STLExporterOptionsBinary): DataView;
parse(scene: Object3D, options?: STLExporterOptionsString): string;
private writeFace;
private writeNormal;
private writeVertex;
}

191

exporters/STLExporter.js

@@ -0,20 +1,38 @@

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
import { Vector3 } from "three";
const isMesh = (object) => object.isMesh;
class STLExporter {
parse(scene, options = {}) {
options = Object.assign(
{
binary: false
},
options
);
const binary = options.binary;
const objects = [];
let triangles = 0;
scene.traverse(function(object) {
if (object.isMesh) {
constructor() {
__publicField(this, "binary", false);
__publicField(this, "output", "");
__publicField(this, "offset", 80);
// skip header
__publicField(this, "objects", []);
__publicField(this, "triangles", 0);
__publicField(this, "vA", new Vector3());
__publicField(this, "vB", new Vector3());
__publicField(this, "vC", new Vector3());
__publicField(this, "cb", new Vector3());
__publicField(this, "ab", new Vector3());
__publicField(this, "normal", new Vector3());
}
parse(scene, options) {
this.binary = (options == null ? void 0 : options.binary) !== void 0 ? options == null ? void 0 : options.binary : false;
scene.traverse((object) => {
if (isMesh(object)) {
const geometry = object.geometry;
if (!geometry.isBufferGeometry) {
throw new Error("THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.");
}
const index = geometry.index;
const positionAttribute = geometry.getAttribute("position");
triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
objects.push({
const positionAttribute = geometry.getAttribute("position") || null;
if (!positionAttribute)
return;
this.triangles += index !== null ? index.count / 3 : positionAttribute.count / 3;
this.objects.push({
object3d: object,

@@ -25,23 +43,15 @@ geometry

});
let output;
let offset = 80;
if (binary === true) {
const bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
if (this.binary) {
const bufferLength = this.triangles * 2 + this.triangles * 3 * 4 * 4 + 80 + 4;
const arrayBuffer = new ArrayBuffer(bufferLength);
output = new DataView(arrayBuffer);
output.setUint32(offset, triangles, true);
offset += 4;
this.output = new DataView(arrayBuffer);
this.output.setUint32(this.offset, this.triangles, true);
this.offset += 4;
} else {
output = "";
output += "solid exported\n";
this.output = "";
this.output += "solid exported\n";
}
const vA = new Vector3();
const vB = new Vector3();
const vC = new Vector3();
const cb = new Vector3();
const ab = new Vector3();
const normal = new Vector3();
for (let i = 0, il = objects.length; i < il; i++) {
const object = objects[i].object3d;
const geometry = objects[i].geometry;
for (let i = 0, il = this.objects.length; i < il; i++) {
const object = this.objects[i].object3d;
const geometry = this.objects[i].geometry;
const index = geometry.index;

@@ -54,3 +64,3 @@ const positionAttribute = geometry.getAttribute("position");

const c = index.getX(j + 2);
writeFace(a, b, c, positionAttribute, object);
this.writeFace(a, b, c, positionAttribute, object);
}

@@ -62,64 +72,73 @@ } else {

const c = j + 2;
writeFace(a, b, c, positionAttribute, object);
this.writeFace(a, b, c, positionAttribute, object);
}
}
}
if (binary === false) {
output += "endsolid exported\n";
if (!this.binary) {
this.output += "endsolid exported\n";
}
return output;
function writeFace(a, b, c, positionAttribute, object) {
vA.fromBufferAttribute(positionAttribute, a);
vB.fromBufferAttribute(positionAttribute, b);
vC.fromBufferAttribute(positionAttribute, c);
if (object.isSkinnedMesh === true) {
object.applyBoneTransform(a, vA);
object.applyBoneTransform(b, vB);
object.applyBoneTransform(c, vC);
}
vA.applyMatrix4(object.matrixWorld);
vB.applyMatrix4(object.matrixWorld);
vC.applyMatrix4(object.matrixWorld);
writeNormal(vA, vB, vC);
writeVertex(vA);
writeVertex(vB);
writeVertex(vC);
if (binary === true) {
output.setUint16(offset, 0, true);
offset += 2;
return this.output;
}
writeFace(a, b, c, positionAttribute, object) {
this.vA.fromBufferAttribute(positionAttribute, a);
this.vB.fromBufferAttribute(positionAttribute, b);
this.vC.fromBufferAttribute(positionAttribute, c);
if (object.isSkinnedMesh) {
const mesh = object;
if ("applyBoneTransform" in mesh) {
mesh.applyBoneTransform(a, this.vA);
mesh.applyBoneTransform(b, this.vB);
mesh.applyBoneTransform(c, this.vC);
} else {
output += " endloop\n";
output += " endfacet\n";
mesh.boneTransform(a, this.vA);
mesh.boneTransform(b, this.vB);
mesh.boneTransform(c, this.vC);
}
}
function writeNormal(vA2, vB2, vC2) {
cb.subVectors(vC2, vB2);
ab.subVectors(vA2, vB2);
cb.cross(ab).normalize();
normal.copy(cb).normalize();
if (binary === true) {
output.setFloat32(offset, normal.x, true);
offset += 4;
output.setFloat32(offset, normal.y, true);
offset += 4;
output.setFloat32(offset, normal.z, true);
offset += 4;
} else {
output += " facet normal " + normal.x + " " + normal.y + " " + normal.z + "\n";
output += " outer loop\n";
}
this.vA.applyMatrix4(object.matrixWorld);
this.vB.applyMatrix4(object.matrixWorld);
this.vC.applyMatrix4(object.matrixWorld);
this.writeNormal(this.vA, this.vB, this.vC);
this.writeVertex(this.vA);
this.writeVertex(this.vB);
this.writeVertex(this.vC);
if (this.binary && this.output instanceof DataView) {
this.output.setUint16(this.offset, 0, true);
this.offset += 2;
} else {
this.output += " endloop\n";
this.output += " endfacet\n";
}
function writeVertex(vertex) {
if (binary === true) {
output.setFloat32(offset, vertex.x, true);
offset += 4;
output.setFloat32(offset, vertex.y, true);
offset += 4;
output.setFloat32(offset, vertex.z, true);
offset += 4;
} else {
output += " vertex " + vertex.x + " " + vertex.y + " " + vertex.z + "\n";
}
}
writeNormal(vA, vB, vC) {
this.cb.subVectors(vC, vB);
this.ab.subVectors(vA, vB);
this.cb.cross(this.ab).normalize();
this.normal.copy(this.cb).normalize();
if (this.binary && this.output instanceof DataView) {
this.output.setFloat32(this.offset, this.normal.x, true);
this.offset += 4;
this.output.setFloat32(this.offset, this.normal.y, true);
this.offset += 4;
this.output.setFloat32(this.offset, this.normal.z, true);
this.offset += 4;
} else {
this.output += ` facet normal ${this.normal.x} ${this.normal.y} ${this.normal.z}
`;
this.output += " outer loop\n";
}
}
writeVertex(vertex) {
if (this.binary && this.output instanceof DataView) {
this.output.setFloat32(this.offset, vertex.x, true);
this.offset += 4;
this.output.setFloat32(this.offset, vertex.y, true);
this.offset += 4;
this.output.setFloat32(this.offset, vertex.z, true);
this.offset += 4;
} else {
this.output += ` vertex ${vertex.x} ${vertex.y} ${vertex.z}
`;
}
}
}

@@ -126,0 +145,0 @@ export {

{
"name": "three-stdlib",
"version": "2.29.2",
"version": "2.29.3",
"description": "stand-alone library of threejs examples",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc