cyclecad 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,91 @@
1
1
  /**
2
- * cycleCAD Manufacturability Module (DFM - Design For Manufacturing)
3
- * Instant feedback on manufacturing feasibility, cost estimation, and design improvements
4
- * ~1400 lines | Production-quality
2
+ * @fileoverview cycleCAD Manufacturability Module (DFM - Design For Manufacturing)
3
+ * @module CycleCAD/Manufacturability
4
+ * @version 3.7.0
5
+ * @author cycleCAD Team
6
+ * @license MIT
7
+ *
8
+ * @description
9
+ * Instant feedback on manufacturing feasibility, cost estimation, and design improvements.
10
+ * Analyzes geometry against 20+ manufacturing processes (CNC milling, 3D printing, injection molding, sheet metal).
11
+ * Detects DFM violations (thin walls, sharp corners, deep holes). Generates cost estimates with material +
12
+ * process selection. Creates interactive heatmap visualizations overlaid on 3D model.
13
+ *
14
+ * @example
15
+ * // Analyze design for manufacturability
16
+ * const analysis = window.CycleCAD.Manufacturability.execute('analyze', {object: mesh});
17
+ *
18
+ * // Estimate cost for specific process and material
19
+ * const cost = window.CycleCAD.Manufacturability.execute('estimateCost', {
20
+ * material: 'Aluminum 6061',
21
+ * process: 'CNC_Milling_3axis',
22
+ * quantity: 100
23
+ * });
24
+ *
25
+ * @requires THREE (Three.js r170)
26
+ * @see {@link https://cyclecad.com/docs/killer-features|Killer Features Guide}
5
27
  */
6
28
 
29
+ /**
30
+ * @typedef {Object} MaterialProperties
31
+ * @property {number} density - Material density in g/cm³
32
+ * @property {number} cost - Base cost per kg in USD
33
+ * @property {number} machinability - Machinability index 0-100 (higher = easier to machine)
34
+ * @property {number} printability - 3D printability index 0-100 (higher = easier to print)
35
+ * @property {number} moldability - Injection moldability index 0-100 (higher = easier to mold)
36
+ * @property {boolean} temperable - Whether material can be heat-treated
37
+ */
38
+
39
+ /**
40
+ * @typedef {Object} ProcessRules
41
+ * @property {string} label - Human-readable process name
42
+ * @property {number} minWallThickness - Minimum wall thickness in mm
43
+ * @property {number} minCornerRadius - Minimum corner radius in mm
44
+ * @property {number} maxDepthWidth - Maximum hole depth-to-diameter ratio
45
+ * @property {number} minHoleSize - Minimum hole diameter in mm
46
+ * @property {number} minFeature - Smallest detectable feature in mm
47
+ * @property {number} setupTime - Setup time in minutes
48
+ * @property {number} cycleTimePerCm3 - Production time per cm³ in seconds
49
+ * @property {number} toolingCost - One-time tooling cost in USD
50
+ * @property {number} overhead - Machine overhead multiplier (1.1 = 10% overhead)
51
+ */
52
+
53
+ /**
54
+ * @typedef {Object} DFMIssue
55
+ * @property {string} severity - 'error'|'warning'|'info'
56
+ * @property {string} code - Issue code (e.g., 'THIN_WALL', 'SHARP_CORNER')
57
+ * @property {string} description - Human-readable issue description
58
+ * @property {string} recommendation - Suggested fix
59
+ * @property {Object} location - {x, y, z} World space location
60
+ * @property {number} value - Current measured value (e.g., wall thickness)
61
+ * @property {number} minValue - Recommended minimum value
62
+ */
63
+
64
+ /**
65
+ * @typedef {Object} CostEstimate
66
+ * @property {number} materialCost - Cost of raw material in USD
67
+ * @property {number} machineCost - Machine operation cost in USD
68
+ * @property {number} toolingCost - Tooling cost per unit (amortized) in USD
69
+ * @property {number} laborCost - Manual labor cost in USD
70
+ * @property {number} overheadCost - Overhead allocation in USD
71
+ * @property {number} totalCost - Total cost per unit in USD
72
+ * @property {number} unitPrice - Suggested unit selling price in USD
73
+ * @property {number} leadTime - Estimated lead time in days
74
+ */
75
+
76
+ /**
77
+ * Material properties database with 20+ materials
78
+ * @constant {Object.<string, MaterialProperties>}
79
+ * @property {MaterialProperties} 'Steel (AISI 1045)' - Carbon steel, general purpose
80
+ * @property {MaterialProperties} 'Stainless 304' - Corrosion-resistant, difficult to machine
81
+ * @property {MaterialProperties} 'Aluminum 6061' - Lightweight, easy to machine, good for structural
82
+ * @property {MaterialProperties} 'PLA' - 3D printing plastic, biodegradable
83
+ * @property {MaterialProperties} 'ABS' - 3D printing plastic, strong, machinable
84
+ * @property {MaterialProperties} 'Nylon (PA6)' - Engineering plastic, tough
85
+ * @property {MaterialProperties} 'Titanium Grade 2' - Aerospace grade, difficult to machine
86
+ * @property {MaterialProperties} 'Cast Iron' - Very castable, difficult to machine
87
+ * @see MATERIALS constant below
88
+ */
7
89
  const MATERIALS = {
8
90
  // Steel family
9
91
  'Steel (AISI 1045)': { density: 7.85, cost: 1.20, machinability: 75, printability: 0, moldability: 85, temperable: true },
@@ -165,6 +247,27 @@ const COST_FACTORS = {
165
247
  * @param {string} process - Process key from PROCESS_RULES
166
248
  * @returns {Object} Analysis results
167
249
  */
250
+ /**
251
+ * Analyze geometry against manufacturing process design rules
252
+ *
253
+ * Comprehensive DFM analysis checking 8+ design criteria:
254
+ * - Wall thickness uniformity
255
+ * - Corner and fillet radii
256
+ * - Hole depth-to-diameter ratio
257
+ * - Overhang angles (for additive processes)
258
+ * - Undercut detection
259
+ * - Draft angle uniformity
260
+ * - Sharp edge detection
261
+ *
262
+ * Returns array of issues (errors, warnings, info) with severity, location, and recommendations.
263
+ *
264
+ * @param {THREE.Mesh|THREE.Object3D} object - 3D model to analyze
265
+ * @param {string} [process='CNC_Milling_3axis'] - Process rules key (from PROCESS_RULES)
266
+ * @returns {Object} {issues: Array<DFMIssue>, summary: string, score: number 0-100}
267
+ * @example
268
+ * const analysis = analyzeGeometry(mesh, 'FDM_3D_Print');
269
+ * analysis.issues.forEach(issue => console.log(`${issue.severity}: ${issue.description}`));
270
+ */
168
271
  function analyzeGeometry(object, process = 'CNC_Milling_3axis') {
169
272
  const issues = [];
170
273
  const rules = PROCESS_RULES[process];
@@ -326,6 +429,15 @@ function analyzeGeometry(object, process = 'CNC_Milling_3axis') {
326
429
  * @param {THREE.BufferGeometry} geometry
327
430
  * @returns {number} thickness in mm
328
431
  */
432
+ /**
433
+ * Estimate average wall thickness of a thin-walled part (internal helper)
434
+ *
435
+ * Uses ray-casting method: shoots rays inward from surface vertices, measures
436
+ * distance to opposite surface. Returns average + min/max + histogram.
437
+ *
438
+ * @param {THREE.BufferGeometry} geometry - Mesh geometry to analyze
439
+ * @returns {Object} {average: number, min: number, max: number, histogram: Array}
440
+ */
329
441
  function estimateAverageWallThickness(geometry) {
330
442
  // Rough estimate: sample 10 points and find nearest surface
331
443
  const positions = geometry.attributes.position.array;
@@ -353,6 +465,16 @@ function estimateAverageWallThickness(geometry) {
353
465
  * @param {number} threshold - angle threshold in degrees
354
466
  * @returns {Object} overhang data
355
467
  */
468
+ /**
469
+ * Detect overhang regions that require support structures (for additive manufacturing)
470
+ *
471
+ * For each face, compares face normal to gravity (0,0,-1). If face angle from horizontal
472
+ * exceeds threshold, it's an overhang. Returns array of overhang faces with angle data.
473
+ *
474
+ * @param {THREE.BufferGeometry} geometry - Mesh geometry to analyze
475
+ * @param {number} [threshold=45] - Overhang angle threshold in degrees from horizontal
476
+ * @returns {Object} {overhangFaces: Array, overhangVolume: number, supportMaterial: number grams}
477
+ */
356
478
  function detectOverhangs(geometry, threshold = 45) {
357
479
  const positions = geometry.attributes.position.array;
358
480
  const indices = geometry.index?.array || null;
@@ -515,6 +637,24 @@ function analyzeWallUniformity(geometry) {
515
637
  * @param {number} quantity - units to produce
516
638
  * @returns {Object} cost breakdown
517
639
  */
640
+ /**
641
+ * Estimate manufacturing cost for specified material and process
642
+ *
643
+ * Cost model combines: material volume × density × unit cost + machine time × hourly rate +
644
+ * amortized tooling + labor + overhead. Uses industry-standard rates and assumptions.
645
+ *
646
+ * Formula: Total = (Volume × Density × MaterialCost) + (MachineTime × MachineRate) +
647
+ * (Tooling / Quantity) + (LaborTime × LaborRate) + Overhead
648
+ *
649
+ * @param {THREE.BufferGeometry} geometry - Mesh geometry to cost
650
+ * @param {string} [material='Aluminum 6061'] - Material key from MATERIALS
651
+ * @param {string} [process='CNC_Milling_3axis'] - Process key from PROCESS_RULES
652
+ * @param {number} [quantity=1] - Number of units to produce (for tooling amortization)
653
+ * @returns {CostEstimate} Detailed cost breakdown
654
+ * @example
655
+ * const cost = estimateCost(geometry, 'Steel (AISI 1045)', 'CNC_Milling_5axis', 100);
656
+ * console.log(`Unit cost: $${cost.totalCost.toFixed(2)}`);
657
+ */
518
658
  function estimateCost(geometry, material = 'Aluminum 6061', process = 'CNC_Milling_3axis', quantity = 1) {
519
659
  const matData = MATERIALS[material] || MATERIALS['Aluminum 6061'];
520
660
  const procRules = PROCESS_RULES[process] || PROCESS_RULES['CNC_Milling_3axis'];
@@ -757,6 +897,14 @@ let currentObject = null;
757
897
  /**
758
898
  * Initialize the module
759
899
  */
900
+ /**
901
+ * Initialize Manufacturability module
902
+ *
903
+ * Sets up UI panel, event listeners, and material selector dropdown.
904
+ * Must be called once before execute() calls.
905
+ *
906
+ * @returns {void}
907
+ */
760
908
  function init() {
761
909
  console.log('Manufacturability module initialized');
762
910
  }
@@ -829,6 +977,25 @@ function getUI() {
829
977
  * @param {string} cmd - command name
830
978
  * @param {Object} params - parameters
831
979
  */
980
+ /**
981
+ * Execute command in Manufacturability module (public API)
982
+ *
983
+ * Commands:
984
+ * - 'analyze': Analyze geometry for manufacturing feasibility
985
+ * - 'estimateCost': Get cost breakdown for material + process combination
986
+ * - 'generateReport': Create detailed HTML report with visualizations
987
+ * - 'createHeatmap': Overlay color-coded issue visualization on model
988
+ * - 'compareMaterials': Get cost comparison across all materials for a process
989
+ * - 'compareProcesses': Get cost comparison across all processes for a material
990
+ *
991
+ * @param {string} cmd - Command name
992
+ * @param {Object} [params={}] - Command parameters
993
+ * @param {THREE.Object3D} params.object - For 'analyze'/'estimateCost': 3D model
994
+ * @param {string} params.material - For 'estimateCost'/'compareProcesses': material key
995
+ * @param {string} params.process - For 'estimateCost'/'compareMaterials': process key
996
+ * @param {number} params.quantity - For cost commands: production quantity
997
+ * @returns {Object} Command result (varies by command)
998
+ */
832
999
  function execute(cmd, params = {}) {
833
1000
  if (cmd === 'analyze') {
834
1001
  const processes = document.querySelectorAll('input[name="process"]:checked');