Files
vue-three-d-mockup/src/MockupModel.js
2022-01-29 19:13:36 +03:00

61 lines
982 B
JavaScript

import { Group, Vector3 } from 'three';
export default class MockupModel extends Group {
constructor() {
super();
this.home = {
position: {
x: 0,
y: 0,
z: 0,
},
rotation: {
x: 0,
y: 0,
z: 0,
},
};
this.speed = {
x: 0,
y: 0,
z: 0,
};
this.acceleration = {
x: 0,
y: 0,
z: 0,
};
}
floatAnim() {
const maxSpeed = 0.1;
const acceleration = 0.01;
if (this.position.y < -2) {
this.acceleration.y = acceleration;
}
if (this.position.y > 2) {
this.acceleration.y = -acceleration;
}
this.speed.y = Math.min(this.speed.y + this.acceleration.y, maxSpeed);
this.position.y += this.speed.y;
}
rotateAnim() {
this.rotation.y += 0.02;
}
lookAtAnim(x, y, cameraZ) {
const target = new Vector3();
target.x = x;
target.y = y;
target.z = cameraZ;
this.lookAt(target);
}
}