mirror of
https://github.com/anatolykopyl/vue-three-d-mockup.git
synced 2026-03-26 12:55:08 +00:00
Home position and smooth return
This commit is contained in:
@@ -1,21 +1,12 @@
|
||||
import { Group, Vector3 } from 'three';
|
||||
|
||||
export default class MockupModel extends Group {
|
||||
constructor() {
|
||||
constructor(home) {
|
||||
super();
|
||||
|
||||
this.home = {
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
},
|
||||
rotation: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
},
|
||||
};
|
||||
this.goingHome = false;
|
||||
|
||||
this.home = home;
|
||||
|
||||
this.speed = {
|
||||
x: 0,
|
||||
@@ -23,6 +14,12 @@ export default class MockupModel extends Group {
|
||||
z: 0,
|
||||
};
|
||||
|
||||
this.rotSpeed = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
};
|
||||
|
||||
this.acceleration = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
@@ -30,6 +27,35 @@ export default class MockupModel extends Group {
|
||||
};
|
||||
}
|
||||
|
||||
homeAnim() {
|
||||
if (!this.goingHome) {
|
||||
this.goingHome = true;
|
||||
|
||||
const rT = 10;
|
||||
this.speed.x = (this.home.position.x - this.position.x) / rT;
|
||||
this.speed.y = (this.home.position.y - this.position.y) / rT;
|
||||
this.speed.z = (this.home.position.z - this.position.z) / rT;
|
||||
|
||||
this.rotSpeed.x = (this.home.rotation.x - this.rotation.x) / rT;
|
||||
this.rotSpeed.y = (this.home.rotation.y - this.rotation.y) / rT;
|
||||
this.rotSpeed.z = (this.home.rotation.z - this.rotation.z) / rT;
|
||||
|
||||
setTimeout(() => {
|
||||
this.goingHome = false;
|
||||
}, rT);
|
||||
}
|
||||
|
||||
this.position.x += this.speed.x;
|
||||
this.position.y += this.speed.y;
|
||||
this.position.z += this.speed.z;
|
||||
|
||||
this.rotation.x += this.rotSpeed.x;
|
||||
this.rotation.y += this.rotSpeed.y;
|
||||
this.rotation.z += this.rotSpeed.z;
|
||||
|
||||
return !this.goingHome;
|
||||
}
|
||||
|
||||
floatAnim() {
|
||||
const maxSpeed = 0.1;
|
||||
const acceleration = 0.01;
|
||||
|
||||
Reference in New Issue
Block a user