@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.
40 lines • 1.89 kB
JavaScript
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_decorator.js";
import * as utils from "./../engine/engine_three_utils.js";
import { Behaviour, GameObject } from "./Component.js";
export class AlignmentConstraint extends Behaviour {
from;
to;
width = 0;
centered = true;
_centerPos;
awake() {
this._centerPos = new Vector3();
}
update() {
if (!this.from || !this.to)
return;
const fromWorldPos = utils.getWorldPosition(this.from).clone();
const toWorldPos = utils.getWorldPosition(this.to).clone();
const dist = fromWorldPos.distanceTo(toWorldPos);
this._centerPos.copy(fromWorldPos);
this._centerPos.add(toWorldPos);
this._centerPos.multiplyScalar(0.5);
utils.setWorldPosition(this.gameObject, this.centered ? this._centerPos : fromWorldPos);
this.gameObject.lookAt(utils.getWorldPosition(this.to).clone());
this.gameObject.scale.set(this.width, this.width, dist);
}
}
__decorate([
serializable(GameObject)
], AlignmentConstraint.prototype, "from", void 0);
__decorate([
serializable(GameObject)
], AlignmentConstraint.prototype, "to", void 0);
//# sourceMappingURL=AlignmentConstraint.js.map