Skip to content

Commit

Permalink
visualize contraction
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliusNmn committed Feb 26, 2024
1 parent b4dd5b7 commit d33eb01
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/demo/Demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ export class LowLevelMuscleInteraction {
}
export class Muscle extends CANNON.Spring {
normalRestLength: number

currentContraction: number = 1
setContraction(factor: number) {
this.restLength = this.normalRestLength * factor
this.currentContraction = factor;
}

constructor(bodyA: CANNON.Body, bodyB: CANNON.Body, options?: {
Expand Down Expand Up @@ -643,6 +644,8 @@ export class Demo {
const pointA = muscle.bodyA.position.vadd(muscle.bodyA.quaternion.vmult( muscle.localAnchorA))
const pointB = muscle.bodyB.position.vadd(muscle.bodyB.quaternion.vmult( muscle.localAnchorB))
line.geometry.setFromPoints([v2v(pointA), v2v(pointB)])
const mat = (line.material as THREE.LineBasicMaterial)
mat.color = new THREE.Color(1 - muscle.currentContraction, 0, muscle.currentContraction)
}
/*
// Render contacts
Expand Down

0 comments on commit d33eb01

Please sign in to comment.