nartc / angular-three

🧊 THREE.js integration for Angular 🧊
https://angular-three.netlify.app/
MIT License
306 stars 26 forks source link

[Feature] Add support for cannon Spring feature #99

Closed IRobot1 closed 2 years ago

IRobot1 commented 2 years ago

Looks like its partially implemented. There's an API under constraints, but its not a constraint. There appears to be message support.

Looks like a little more is needed to support this feature.

I'm trying to finish converting cannon spring example

IRobot1 commented 2 years ago

The following example shows how to use the new Spring feature

@Component({
  selector: 'spring-example',
  templateUrl: './spring-example.component.html',
  providers: [NgtPhysicBody, NgtPhysicSpring],
})
export class SpringExample {
  size = 1;
  boxsize = [this.size * 0.3, this.size, this.size] as NgtTriple;

  sphereProps = this.physicBody.useSphere(() => ({
    mass: 0,
    args: [0.1],
  }));

  boxProps = this.physicBody.useBox(() => ({
    mass: 5,
    args: this.boxsize,
    position: [0, -this.size, 0]
  }));

  spring = this.physicSpring.useSpring(this.sphereProps.ref, this.boxProps.ref,
    {
      localAnchorA: [0, -this.size, 0],
      //  localAnchorB: [0, 0, 0],
      //  restLength: 0,
      //  stiffness: 50,
      //  damping: 1,
    }
  );

  constructor(
    private physicBody: NgtPhysicBody,
    private physicSpring: NgtPhysicSpring,
  ) { }
}