Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fatica-flessione.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ <h2>Avviso Schermo Piccolo</h2>
<!-- Load shared modules -->
<script src="src/js/ui-utils.js"></script>
<script src="src/js/performance-monitor.js"></script>
<script src="src/js/particle-system.js"></script>
<script src="src/js/chart-modal.js"></script>
<script src="src/js/sim-fatigue-bending.js"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions fatica-termica.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ <h2>Avviso Schermo Piccolo</h2>
<!-- Load shared modules -->
<script src="src/js/ui-utils.js"></script>
<script src="src/js/performance-monitor.js"></script>
<script src="src/js/particle-system.js"></script>
<script src="src/js/chart-modal.js"></script>
<script src="src/js/sim-thermal-fatigue.js"></script>
</body>
Expand Down
44 changes: 42 additions & 2 deletions src/js/sim-fatigue-bending.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const FatigueBendingSimulator = {
this.initThree();
this.initChart();
this.initCracks();
this.initParticleSystems();
this.updateMaterialDisplay();
this.calculateFatigueLife();
PerformanceMonitor.init({ visible: false });
Expand Down Expand Up @@ -449,9 +450,37 @@ const FatigueBendingSimulator = {
},

/**
* Add a visible crack to the specimen
* Initialize particle systems for debris effects on failure
*/
initParticleSystems() {
if (typeof ParticleSystem === 'undefined') {
console.warn('RainerumSim: particle-system.js not loaded; debris effects disabled.');
return;
}

const material = this.materials[this.currentMaterial];

this.debrisSystem = ParticleSystem.createMeshDebris(this.scene, {
pieceCount: FATIGUE_CONSTANTS.DEBRIS_PARTICLE_COUNT,
color: material.color,
size: 2,
lifetime: 2000,
gravity: -150,
initialVelocity: 30
});
},

/**
* Update active particle systems each frame
*/
addCrack(severity) {
updateParticleSystems(deltaTime) {
if (this.debrisSystem && this.debrisSystem.active) {
this.debrisSystem.update(deltaTime);
}
},

/**
* Add a visible crack to the specimen
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addCrack(severity) lost its function declaration here (the body starts immediately with if (!this.showCracks) return;). This makes the object literal invalid JS and will break the whole simulator script. Restore the addCrack(severity) { line before the body and ensure the JSDoc block is properly closed.

Suggested change
* Add a visible crack to the specimen
* Add a visible crack to the specimen
*/
addCrack(severity) {

Copilot uses AI. Check for mistakes.
if (!this.showCracks) return;

const crackGeometry = new THREE.PlaneGeometry(
Expand Down Expand Up @@ -692,6 +721,7 @@ const FatigueBendingSimulator = {
this.animateBend(deltaTime);
}

this.updateParticleSystems(deltaTime);
this.updateCameraShake();
this.controls.update();
this.updateInfo();
Expand Down Expand Up @@ -840,6 +870,11 @@ const FatigueBendingSimulator = {
// Camera shake
this.triggerCameraShake(FATIGUE_CONSTANTS.VIBRATION_INTENSITY);

// Emit debris particles if particle system is active
if (this.debrisSystem && this.showDebris) {
this.debrisSystem.emit({ x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }, 10);
}

// Visual break effect
this.animateBreak();
},
Expand Down Expand Up @@ -1140,6 +1175,11 @@ function resetSimulation() {
sim.rebuildSpecimen();
sim.updateDamageBar();
sim.updateFormulas();

if (sim.debrisSystem) {
sim.debrisSystem.active = false;
sim.debrisSystem.group.visible = false;
}
}

function stepCycle() {
Expand Down
43 changes: 43 additions & 0 deletions src/js/sim-thermal-fatigue.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const ThermalFatigueSimulator = {

// Visual effects
cracks: [],
debrisSystem: null,
showDebris: true,
showCracks: true,
cameraShake: true,
Expand Down Expand Up @@ -179,6 +180,7 @@ const ThermalFatigueSimulator = {
this.initThree();
this.initChart();
this.initCracks();
this.initParticleSystems();
this.updateMaterialDisplay();
this.calculateFatigueLife();
PerformanceMonitor.init({ visible: false });
Expand Down Expand Up @@ -452,6 +454,36 @@ const ThermalFatigueSimulator = {
this.cracks = [];
},

/**
* Initialize particle systems for debris effects on failure
*/
initParticleSystems() {
if (typeof ParticleSystem === 'undefined') {
console.warn('RainerumSim: particle-system.js not loaded; debris effects disabled.');
return;
}

const material = this.materials[this.currentMaterial];

this.debrisSystem = ParticleSystem.createMeshDebris(this.scene, {
pieceCount: THERMAL_CONSTANTS.DEBRIS_PARTICLE_COUNT,
color: material.color,
size: 3,
lifetime: 2000,
gravity: -150,
initialVelocity: 30
});
},

/**
* Update active particle systems each frame
*/
updateParticleSystems(deltaTime) {
if (this.debrisSystem && this.debrisSystem.active) {
this.debrisSystem.update(deltaTime);
}
},

/**
* Add a visible crack to the specimen
*/
Expand Down Expand Up @@ -699,6 +731,7 @@ const ThermalFatigueSimulator = {
this.updateSimulation(deltaTime);
}

this.updateParticleSystems(deltaTime);
this.updateCameraShake();
this.controls.update();
this.updateInfo();
Expand Down Expand Up @@ -880,6 +913,11 @@ const ThermalFatigueSimulator = {
// Camera shake
this.triggerCameraShake(THERMAL_CONSTANTS.VIBRATION_INTENSITY);

// Emit debris particles if particle system is active
if (this.debrisSystem && this.showDebris) {
this.debrisSystem.emit({ x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }, 15);
}

// Visual break effect
this.animateBreak();
},
Expand Down Expand Up @@ -1153,6 +1191,11 @@ function resetSimulation() {
sim.rebuildSpecimen();
sim.updateDamageBar();
sim.updateFormulas();

if (sim.debrisSystem) {
sim.debrisSystem.active = false;
sim.debrisSystem.group.visible = false;
}
}

function stepCycle() {
Expand Down