Browse Source

尝试旋转bi1,但bi有时不旋转的bug导致后续不好进行

master
刘向辉 3 years ago
parent
commit
3ca5efa843
  1. 49
      src/app/babylonjs/FireTruck.ts
  2. BIN
      src/assets/GPC/CarColor.png
  3. BIN
      src/assets/GPC/FireCar.jpg
  4. BIN
      src/assets/GPC/GPC.bin
  5. 2868
      src/assets/GPC/GPC.gltf

49
src/app/babylonjs/FireTruck.ts

@ -59,8 +59,18 @@ export class FireTruck {
this.scene = scene;
this.input = new FireTruckInput(scene);
SceneLoader.ImportMeshAsync("", "assets/GPC/", "GPC.gltf", scene).then(result => {
this.animations = scene.getAnimationGroupByName("All Animations");
this.animations.stop();
// this.animations = scene.getAnimationGroupByName("All Animations");
if (result.animationGroups != null) {
if (result.animationGroups.length > 0) {
this.animations = result.animationGroups[0]
}
for (let i = 0; i < result.animationGroups.length; i++) {
result.animationGroups[i].stop();
}
}
this.root = result.meshes[0] as Mesh;
this.Bi = scene.getMeshByName("Bi") as Mesh;
this.Bi1 = scene.getMeshByName("Bi1") as Mesh;
@ -280,9 +290,9 @@ export class FireTruck {
// const d2T = Math.floor(Vector3.Distance(this.Bi.absolutePosition, this.targetPoint));//臂底端到目标的距离
// const distance = Math.round(Vector3.Distance(this.Bi6.absolutePosition, this.targetPoint)); //Bi6到目标距离
const v1 = (new Vector3(this.targetPoint.x, this.targetPoint.y, this.targetPoint.z).subtract(this.Bi1.position)).normalize();
const v2 = this.Bi.forward.normalize();
const targetDir = Vector3.Cross(v1, v2).x > 0 ? -1 : 1;
// const v1 = (new Vector3(this.targetPoint.x, this.targetPoint.y, this.targetPoint.z).subtract(this.Bi1.position)).normalize();
// const v2 = this.Bi.forward.normalize();
// const targetDir = Vector3.Cross(v1, v2).x > 0 ? -1 : 1;
// const lookPos = this.targetPoint.subtract(this.Bi1.position).normalize();
@ -290,18 +300,18 @@ export class FireTruck {
// this.Bi1.rotationQuaternion = Quaternion.Slerp(this.Bi1.rotationQuaternion, new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), this.deltaTime * 10);
const targetAngle = Math.acos(Vector3.Dot(v1, v2)) * 180 / Math.PI * targetDir;
const currentAngle = this.Bi1.rotationQuaternion.toEulerAngles().x * 180 / Math.PI;
// const targetAngle = Math.acos(Vector3.Dot(v1, v2)) * 180 / Math.PI * targetDir;
// const currentAngle = this.Bi1.rotationQuaternion.toEulerAngles().x * 180 / Math.PI;
// console.log(currentAngle,);
// console.log(targetAngle, "=================");
if (Math.abs(targetAngle - currentAngle) > 0.5) {
const speedDir = (targetAngle - currentAngle) >= 0 ? 1 : -1;
this.RotateBi1(speedDir * 0.01);
} else {
this.armActionState = ArmActionState.Bi6;
}
// if (Math.abs(targetAngle - currentAngle) > 0.5) {
// const speedDir = (targetAngle - currentAngle) >= 0 ? 1 : -1;
// this.RotateBi1(speedDir * 0.01);
// } else {
// this.armActionState = ArmActionState.Bi6;
// }
// console.log(distance, '')
// if (d2E < d2T) {
@ -317,6 +327,19 @@ export class FireTruck {
// this.armActionState = ArmActionState.Bi6;
// }
// }
const v1 = (this.targetPoint.subtract(this.Bi1.absolutePosition)).normalize();
const v2 = this.Bi1.forward.normalize();
const sinA = Vector3.Cross(v1, v2);
// console.log(sinA);
let rotateDir = sinA.x > 0 ? -1 : 1;
let loaclSpeed = sinA.length() * rotateDir;
// console.log(loaclSpeed, "speed");
this.RotateBi1(loaclSpeed);
}
public RotateBi6(angle: number) {
this.Bi6.rotate(Axis.X, angle, Space.LOCAL);

BIN
src/assets/GPC/CarColor.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 19 KiB

BIN
src/assets/GPC/FireCar.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 540 KiB

After

Width:  |  Height:  |  Size: 638 KiB

BIN
src/assets/GPC/GPC.bin

Binary file not shown.

2868
src/assets/GPC/GPC.gltf

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save