UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

52 lines 2.03 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { Vector3 } from "three"; import { serializable } from "../engine/engine_serialization.js"; import { Behaviour } from "./Component.js"; import { Rigidbody } from "./RigidBody.js"; export class Joint extends Behaviour { connectedBody; get rigidBody() { return this._rigidBody; } _rigidBody = null; onEnable() { if (!this._rigidBody) this._rigidBody = this.gameObject.getComponent(Rigidbody); if (this.rigidBody && this.connectedBody) this.startCoroutine(this.create()); } *create() { yield; if (this.rigidBody && this.connectedBody && this.activeAndEnabled) { this.createJoint(this.rigidBody, this.connectedBody); } } } __decorate([ serializable(Rigidbody) ], Joint.prototype, "connectedBody", void 0); export class FixedJoint extends Joint { createJoint(self, other) { this.context.physics.engine?.addFixedJoint(self, other); } } export class HingeJoint extends Joint { anchor; axis; createJoint(self, other) { if (this.axis && this.anchor) this.context.physics.engine?.addHingeJoint(self, other, this.anchor, this.axis); } } __decorate([ serializable(Vector3) ], HingeJoint.prototype, "anchor", void 0); __decorate([ serializable(Vector3) ], HingeJoint.prototype, "axis", void 0); //# sourceMappingURL=Joints.js.map