Skip to content

Commit

Permalink
fix: BEZIER_CURVE_PATH 计算返回都改为 Vector3 (#326)
Browse files Browse the repository at this point in the history
* fix: 相机路径计算兼容Vector3

* fix: 类型修改

* fix: 修改路径单关键帧取值

* fix: 修复路径单关键帧取值

* test: 修复相机位移单测
  • Loading branch information
RGCHN authored May 6, 2024
1 parent 3927a2c commit ae0c2cb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
16 changes: 8 additions & 8 deletions packages/effects-core/src/math/value-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export class BezierCurve extends ValueGetter<number> {
}
}

export class BezierCurvePath extends ValueGetter<spec.vec3> {
export class BezierCurvePath extends ValueGetter<Vector3> {
curveSegments: Record<string, {
points: Vector2[],
// 缓动曲线
Expand Down Expand Up @@ -584,13 +584,13 @@ export class BezierCurvePath extends ValueGetter<spec.vec3> {

}

override getValue (time: number) {
override getValue (time: number): Vector3 {
const t = numberToFix(time, 5);
let perc = 0, point = new Vector3();
const keyTimeData = Object.keys(this.curveSegments);

if (!keyTimeData.length) {
return point.toArray();
return point;
}
const keyTimeStart = Number(keyTimeData[0].split('&')[0]);
const keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
Expand All @@ -600,15 +600,15 @@ export class BezierCurvePath extends ValueGetter<spec.vec3> {

point = pathCurve.getPointInPercent(0);

return point.toArray();
return point;

}
if (t >= keyTimeEnd) {
const pathCurve = this.curveSegments[keyTimeData[keyTimeData.length - 1]].pathCurve;

point = pathCurve.getPointInPercent(1);

return point.toArray();
return point;
}

for (let i = 0; i < keyTimeData.length; i++) {
Expand All @@ -623,7 +623,7 @@ export class BezierCurvePath extends ValueGetter<spec.vec3> {
}
}

return point.toArray();
return point;
}

getPercValue (curveKey: string, time: number) {
Expand Down Expand Up @@ -686,9 +686,9 @@ const map: Record<any, any> = {

return new BezierCurve(props);
},
[spec.ValueType.BEZIER_CURVE_PATH] (props: number[][][][]) {
[spec.ValueType.BEZIER_CURVE_PATH] (props: number[][][]) {
if (props[0].length === 1) {
return new StaticValue(new Vector3(props[0][0][1][1], props[1][0][1][1], props[2][0][1][1]));
return new StaticValue(new Vector3(...props[1][0]));
}

return new BezierCurvePath(props);
Expand Down
2 changes: 1 addition & 1 deletion packages/effects-core/src/plugins/cal/calculate-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ItemBasicTransform = {
position: Vector3,
rotation: Euler,
scale: Vector3,
path?: ValueGetter<spec.vec3>,
path?: ValueGetter<Vector3>,
};

export type ItemLinearVelOverLifetime = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CameraController {
fov: ValueGetter<number>,
};
private readonly translateOverLifetime?: {
path?: ValueGetter<spec.vec3>,
path?: ValueGetter<Vector3>,
x: ValueGetter<number>,
y: ValueGetter<number>,
z: ValueGetter<number>,
Expand Down Expand Up @@ -91,9 +91,7 @@ export class CameraController {
if (translateOverLifetime.path) {
const val = translateOverLifetime.path.getValue(lifetime);

position.x += val[0];
position.y += val[1];
position.z += val[2];
position.add(val);
}
}
if (rotationOverLifetime) {
Expand Down
3 changes: 2 additions & 1 deletion web-packages/demo/src/single.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Player } from '@galacean/effects';
import inspireList from './assets/inspire-list';

const json = 'https://mdn.alipayobjects.com/mars/afts/file/A*ZrU7SIuNOdkAAAAAAAAAAAAADlB4AQ';
const json = 'https://mdn.alipayobjects.com/mars/afts/file/A*NXOAQ6Su4sMAAAAAAAAAAAAADlB4AQ';
// 'https://mdn.alipayobjects.com/mars/afts/file/A*ZrU7SIuNOdkAAAAAAAAAAAAADlB4AQ';
// 'https://mdn.alipayobjects.com/mars/afts/file/A*_DqDToRcM7oAAAAAAAAAAAAADlB4AQ';
// 'https://mdn.alipayobjects.com/mars/afts/file/A*VPbASpxweKAAAAAAAAAAAAAADlB4AQ';
// 'https://mdn.alipayobjects.com/mars/afts/file/A*a8bbR4Zew5AAAAAAAAAAAAAADlB4AQ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ describe('camera item', () => {
const pos1 = comp1.camera.position;
const val = new BezierCurvePath(lineatPath).getValue(0.5);

expect(pos1.x).to.eql(val[0], 'curve path');
expect(pos1.y).to.eql(val[1], 'curve path');
expect(pos1.z).to.eql(val[2], 'curve path');
expect(pos1.x).to.eql(val.x, 'curve path');
expect(pos1.y).to.eql(val.y, 'curve path');
expect(pos1.z).to.eql(val.z, 'curve path');
});

it('camera 2D item affected by parent', async () => {
Expand Down

0 comments on commit ae0c2cb

Please sign in to comment.