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

Commit

Permalink
Add light-test, and related changes (#173)
Browse files Browse the repository at this point in the history
* Add light-test, and related changes

* Removed unnecessary call to destroyActors

* Disabling directional light, for now.
  • Loading branch information
eanders-ms authored Feb 5, 2019
1 parent 43eda00 commit 2b0830c
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 292 deletions.
16 changes: 9 additions & 7 deletions packages/functional-tests/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GltfConcurrencyTest from './tests/gltf-concurrency-test';
import GltfGenTest from './tests/gltf-gen-test';
import InputTest from './tests/input-test';
import InterpolationTest from './tests/interpolation-test';
import LightTest from './tests/light-test';
import LookAtTest from './tests/look-at-test';
import MutableAssetTest from './tests/mutable-asset-test';
import PrimitivesTest from './tests/primitives-test';
Expand All @@ -40,6 +41,7 @@ export default class App {

/**
* Registry of functional tests. Add your test here.
* *** KEEP LIST SORTED ***
*/
private testFactories: { [key: string]: (user: MRESDK.User) => Test } = {
'altspacevr-library-test': (): Test => new AltspaceVRLibraryTest(this, this.baseUrl),
Expand All @@ -51,6 +53,7 @@ export default class App {
'gltf-gen-test': (): Test => new GltfGenTest(this, this.baseUrl),
'input-test': (): Test => new InputTest(this, this.baseUrl),
'interpolation-test': (): Test => new InterpolationTest(this),
'light-test': (): Test => new LightTest(this, this.baseUrl),
'look-at-test': (user: MRESDK.User): Test => new LookAtTest(this, this.baseUrl, user),
'mutable-asset-test': (user: MRESDK.User): Test => new MutableAssetTest(this, this.baseUrl, user),
'primitives-test': (): Test => new PrimitivesTest(this, this.baseUrl),
Expand All @@ -63,14 +66,11 @@ export default class App {
constructor(private _context: MRESDK.Context, private params: MRESDK.ParameterSet, private baseUrl: string) {
this._rpc = new MRERPC.ContextRPC(_context);

this.userJoined = this.userJoined.bind(this);
this.userLeft = this.userLeft.bind(this);

this.context.onUserJoined(this.userJoined);
this.context.onUserLeft(this.userLeft);
this.context.onUserJoined((user) => this.userJoined(user));
this.context.onUserLeft((user) => this.userLeft(user));
}

private userJoined = async (user: MRESDK.User) => {
private async userJoined(user: MRESDK.User) {
console.log(`user-joined: ${user.name}, ${user.id}, ${user.properties.remoteAddress}`);
this._connectedUsers[user.id] = user;

Expand All @@ -90,10 +90,12 @@ export default class App {
this.firstUser = user;
}
}
private userLeft = (user: MRESDK.User) => {

private userLeft(user: MRESDK.User) {
console.log(`user-left: ${user.name}, ${user.id}`);
delete this._connectedUsers[user.id];
}

private async runTest(testName: string, user: MRESDK.User) {
if (this.activeTests[testName]) {
console.log(`Test already running: '${testName}'`);
Expand Down
16 changes: 8 additions & 8 deletions packages/functional-tests/src/tests/interpolation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as MRESDK from '@microsoft/mixed-reality-extension-sdk';
import App from '../app';
import destroyActors from '../utils/destroyActors';
import Test from './test';

export default class InterpolationTest extends Test {
Expand All @@ -22,26 +21,29 @@ export default class InterpolationTest extends Test {
const timeout = setTimeout(() => this.running = false, 60000);
await expressiveCubePromise;
clearTimeout(timeout);
destroyActors(this.sceneRoot);
return true;
}

private async spawnExpressiveCube() {
MRESDK.Actor.CreateEmpty(this.app.context, {
const label = MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { y: 2.5 }
},
text: {
contents: 'Lerping scale and rotation\nClick to exit (or wait a minute)',
contents:
'Lerping scale and rotation\n' +
'Click to exit (or wait a minute)',
anchor: MRESDK.TextAnchorLocation.TopCenter,
justify: MRESDK.TextJustify.Center,
height: 0.4,
color: MRESDK.Color3.Yellow()
}
}
});
}).value;
label.setBehavior(MRESDK.ButtonBehavior).onClick('released', () => this.running = false);

const cube = MRESDK.Actor.CreatePrimitive(this.app.context, {
definition: {
shape: MRESDK.PrimitiveShape.Box
Expand All @@ -51,9 +53,7 @@ export default class InterpolationTest extends Test {
parentId: this.sceneRoot.id,
}
}).value;

const buttonBehavior = cube.setBehavior(MRESDK.ButtonBehavior);
buttonBehavior.onClick('released', () => this.running = false);
cube.setBehavior(MRESDK.ButtonBehavior).onClick('released', () => this.running = false);

while (this.running) {
// Random point on unit sphere (pick random axis).
Expand Down
186 changes: 186 additions & 0 deletions packages/functional-tests/src/tests/light-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import * as MRESDK from '@microsoft/mixed-reality-extension-sdk';
import App from '../app';
import Test from './test';

// tslint:disable:no-string-literal

export default class LightTest extends Test {
private sceneRoot: MRESDK.Actor;
private running = true;

constructor(app: App, private baseUrl: string) {
super(app);
}

public async run() {
this.sceneRoot = MRESDK.Actor.CreateEmpty(this.app.context).value;
const runningTestPromise = this.runTest();
const timeout = setTimeout(() => this.running = false, 60000);
await runningTestPromise;
clearTimeout(timeout);
return true;
}

private async runTest() {
// Create scene objects.
const props = this.createProps();
const label = this.createLabel();
const sphere = this.createSphere();

// Click on anything to exit the test.
for (const actor of this.app.context.actors) {
actor.setBehavior(MRESDK.ButtonBehavior).onClick('released', () => this.running = false);
}

// Updates the label for the test stage.
const updateLabel = (lightType: string) => {
label.text.contents =
`${lightType} Light Test\n` +
'Click to exit (or wait a minute)';
};

// Picks a random color.
const randomColor = (minValue = 0.15) => {
return new MRESDK.Color3(
minValue + Math.random() * (1 - minValue),
minValue + Math.random() * (1 - minValue),
minValue + Math.random() * (1 - minValue),
);
};

// Animates the sphere along one side of the scene, with some randomness of final height, and
// rotating to face the center of the space.
const animateSide = async (dirX: number, dirZ: number, time: number) => {
if (this.running) {
const position = new MRESDK.Vector3(1.5 * dirX, 0.5 + Math.random() * 2, 1.5 * dirZ);
const rotation = MRESDK.Quaternion.LookAt(
position,
props['monkey'].transform.position,
new MRESDK.Vector3(0, -Math.PI / 8, 0));
sphere.light.color = randomColor();
await sphere.animateTo({
transform: {
position,
rotation
}
}, time, MRESDK.AnimationEaseCurves.EaseInOutSine);
}
};

// One loop of the sphere moving along each side of the scene.
const animateAround = async (time: number) => {
await animateSide(1, 1, time / 4);
await animateSide(-1, 1, time / 4);
await animateSide(-1, -1, time / 4);
await animateSide(1, -1, time / 4);
};

while (this.running) {
// Spot Light
updateLabel('Spot');
sphere.light.copy({
type: 'spot',
spotAngle: Math.PI / 3,
intensity: 15,
range: 10,
});
await animateAround(5);
// Point Light
updateLabel('Point');
sphere.light.copy({
type: 'point',
intensity: 10,
range: 10,
});
await animateAround(5);
}
}

private createProps() {
const props: { [id: string]: MRESDK.Actor } = {};
props['monkey'] = MRESDK.Actor.CreateFromGltf(this.app.context, {
resourceUrl: `${this.baseUrl}/monkey.glb`,
colliderType: 'box',
actor: {
parentId: this.sceneRoot.id,
transform: {
scale: { x: 0.75, y: 0.75, z: 0.75 },
position: { y: 1 },
rotation: MRESDK.Quaternion.RotationAxis(MRESDK.Vector3.Up(), Math.PI)
}
}
}).value;
const propWidth = 0.4;
const propHeight = 0.4;
props['left-box'] = MRESDK.Actor.CreatePrimitive(this.app.context, {
definition: {
shape: MRESDK.PrimitiveShape.Box,
dimensions: { x: propWidth, z: propWidth, y: propHeight }
},
addCollider: true,
actor: {
parentId: this.sceneRoot.id,
transform: {
position: {
x: -propWidth * 2, y: propHeight / 2
}
}
}
}).value;
props['right-box'] = MRESDK.Actor.CreatePrimitive(this.app.context, {
definition: {
shape: MRESDK.PrimitiveShape.Box,
dimensions: { x: propWidth, z: propWidth, y: propHeight }
},
addCollider: true,
actor: {
parentId: this.sceneRoot.id,
transform: {
position: {
x: propWidth * 2, y: propHeight / 2
}
}
}
}).value;
return props;
}

private createLabel() {
return MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { y: 3 }
},
text: {
anchor: MRESDK.TextAnchorLocation.TopCenter,
justify: MRESDK.TextJustify.Center,
height: 0.4,
color: MRESDK.Color3.Yellow()
}
}
}).value;
}

private createSphere() {
return MRESDK.Actor.CreatePrimitive(this.app.context, {
definition: {
shape: MRESDK.PrimitiveShape.Sphere,
radius: 0.1
},
addCollider: true,
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { y: 1 }
},
light: { type: 'spot' } // Add a light component.
}
}).value;
}
}
12 changes: 5 additions & 7 deletions packages/functional-tests/src/tests/reparent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as MRESDK from '@microsoft/mixed-reality-extension-sdk';
import App from '../app';
import delay from '../utils/delay';
import destroyActors from '../utils/destroyActors';
import Test from './test';

export default class ReparentTest extends Test {
Expand All @@ -23,12 +22,11 @@ export default class ReparentTest extends Test {
const timeout = setTimeout(() => this.running = false, 60000);
await runningTestPromise;
clearTimeout(timeout);
destroyActors(this.sceneRoot);
return true;
}

private async runTest() {
MRESDK.Actor.CreateEmpty(this.app.context, {
const label = MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
Expand All @@ -45,7 +43,9 @@ export default class ReparentTest extends Test {
color: MRESDK.Color3.Yellow()
}
}
});
}).value;
label.setBehavior(MRESDK.ButtonBehavior).onClick('released', () => this.running = false);

const leftParent = MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
Expand Down Expand Up @@ -73,13 +73,11 @@ export default class ReparentTest extends Test {
parentId: leftParent.id
}
}).value;
sphere.setBehavior(MRESDK.ButtonBehavior).onClick('released', () => this.running = false);

let currParent = 0;
const parentIds = [leftParent.id, rightParent.id];

const buttonBehavior = sphere.setBehavior(MRESDK.ButtonBehavior);
buttonBehavior.onClick('released', () => this.running = false);

while (this.running) {
for (let i = 0; i < 10 && this.running; ++i) {
await delay(100);
Expand Down
Loading

0 comments on commit 2b0830c

Please sign in to comment.