Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Require transform animations be in local space (#311)
Browse files Browse the repository at this point in the history
* Require transform animations be in local space

* Fix string convention
  • Loading branch information
stevenvergenz authored Apr 15, 2019
1 parent a563228 commit 3633a69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/functional-tests/src/tests/look-at-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import * as MRE from '@microsoft/mixed-reality-extension-sdk';
import { Test } from '../test';

const circleKeyframes = [
{ time: 0, value: { transform: { app: {position: { x: 0, y: 0, z: -0.5 } } } } },
{ time: 1, value: { transform: { app: {position: { x: 1, y: 1, z: -0.5 } } } } },
{ time: 2, value: { transform: { app: {position: { x: 0, y: 2, z: -0.5 } } } } },
{ time: 3, value: { transform: { app: {position: { x: -1, y: 1, z: -0.5 } } } } },
{ time: 4, value: { transform: { app: {position: { x: 0, y: 0, z: -0.5 } } } } }
{ time: 0, value: { transform: { local: { position: { x: 0, y: 0, z: -0.5 } } } } },
{ time: 1, value: { transform: { local: { position: { x: 1, y: 1, z: -0.5 } } } } },
{ time: 2, value: { transform: { local: { position: { x: 0, y: 2, z: -0.5 } } } } },
{ time: 3, value: { transform: { local: { position: { x: -1, y: 1, z: -0.5 } } } } },
{ time: 4, value: { transform: { local: { position: { x: 0, y: 0, z: -0.5 } } } } }
] as MRE.AnimationKeyframe[];

export default class LookAtTest extends Test {
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/types/internal/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { Execution } from '../../protocols/execution';
import { Handshake } from '../../protocols/handshake';
import { SetSoundStateOptions, SoundCommand } from '../../sound';
import resolveJsonValues from '../../utils/resolveJsonValues';
import safeGet from '../../utils/safeAccessPath';
import { createForwardPromise, ForwardPromise } from '../forwardPromise';
import { OperatingModel } from '../network/operatingModel';
import { Patchable } from '../patchable';
Expand Down Expand Up @@ -250,6 +251,14 @@ export class InternalContext {
wrapMode: AnimationWrapMode.Once,
...options
};

// Transform animations must be specified in local space
for (const frame of options.keyframes) {
if (frame.value.transform && !safeGet(frame.value, 'transform', 'local')) {
throw new Error("Transform animations must be specified in local space");
}
}

// Resolve by-reference values now, ensuring they won't change in the
// time between now and when this message is actually sent.
options.keyframes = resolveJsonValues(options.keyframes);
Expand Down

0 comments on commit 3633a69

Please sign in to comment.