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

Transform updates not propagating for attachments when using subscription 'transform' #740

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions packages/functional-tests/src/tests/button-behavior-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import * as MRE from '@microsoft/mixed-reality-extension-sdk';

import { Test } from '../test';

export default class ButtonBehaviorTest extends Test {
private defaultLabel = "Test the difference between click and hold";
public expectedResultDescription = "Button behavior";

private testButton: MRE.Actor;
private testBehavior: MRE.ButtonBehavior;
private buttonLabel: MRE.Actor;
private assets: MRE.AssetContainer;
private timer: NodeJS.Timeout;

public cleanup() {
this.assets.unload();
}

public async run(root: MRE.Actor): Promise<boolean> {
this.assets = new MRE.AssetContainer(this.app.context);

this.createEraseButton();

// Create scene light
MRE.Actor.Create(this.app.context, {
actor: {
name: "Light",
parentId: root.id,
light: {
type: 'point',
range: 5,
intensity: 2,
color: { r: 1, g: 0.5, b: 0.3 }
},
transform: {
local: {
position: { x: -2, y: 2, z: -2 }
}
}
}
});

await this.stoppedAsync();
return true;
}

private displayString(string: string) {
if(this.timer) {
clearTimeout(this.timer);
}
this.buttonLabel.text.contents = string;
this.timer = setTimeout(() => { this.buttonLabel.text.contents = this.defaultLabel; }, 1000);
}

private createEraseButton() {
// Create erase button for the surface
const buttonMesh = this.assets.createBoxMesh('eraseButton', .5, .5, .01);
this.testButton = MRE.Actor.Create(this.app.context, {
actor: {
name: 'testButton',
transform: { local: { position: { z: -.2, y: .7 } } },
appearance: { meshId: buttonMesh.id },
collider: { geometry: { shape: MRE.ColliderType.Auto } }
}
});

this.buttonLabel = MRE.Actor.Create(this.app.context, {
actor: {
name: 'testLabel',
parentId: this.testButton.id,
transform: { local: { position: { y: .3 } } },
text: {
contents: this.defaultLabel,
height: .1,
anchor: MRE.TextAnchorLocation.BottomCenter,
color: MRE.Color3.Teal()
}
}
})

const testButtonBehavior = this.testButton.setBehavior(MRE.ButtonBehavior);
testButtonBehavior.onClick((_, __) => this.displayString("Click Detected!"));
testButtonBehavior.onButton('holding', () => this.displayString("Hold Detected!"));
}
}
2 changes: 2 additions & 0 deletions packages/functional-tests/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import AssetEarlyAssignmentTest from './asset-early-assignment-test';
import AssetMutabilityTest from './asset-mutability-test';
import AssetPreloadTest from './asset-preload-test';
import AssetUnloadTest from './asset-unload-test';
import ButtonBehaviorTest from './button-behavior-test';
import ButtonTargetingTest from './button-targeting-test';
import ClockSyncTest from './clock-sync-test';
import CollisionLayerTest from './collision-layer-test';
Expand Down Expand Up @@ -79,6 +80,7 @@ export const Factories = {
'asset-mutability': (...args) => new AssetMutabilityTest(...args),
'asset-preload': (...args) => new AssetPreloadTest(...args),
'asset-unload': (...args) => new AssetUnloadTest(...args),
'button-behavior': (...args) => new ButtonBehaviorTest(...args),
'button-targeting': (...args) => new ButtonTargetingTest(...args),
'clock-sync': (...args) => new ClockSyncTest(...args),
'collision-layer': (...args) => new CollisionLayerTest(...args),
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/internal/adapters/multipeer/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ export const Rules: { [id in Payloads.PayloadType]: Rule } = {
message: Message<Payloads.ActorUpdate>
) => {
const syncActor = session.actorSet.get(message.payload.actor.id);
if (syncActor && ((client.authoritative && !syncActor.grabbedBy) ||
(syncActor.grabbedBy === client.id))) {
const attachment = syncActor.initialization.message.payload.actor.attachment;
if (syncActor && ((client.authoritative && !syncActor.grabbedBy) ||
(syncActor.grabbedBy === client.id) ||
(attachment && attachment.userId === client.userId))) {
// Merge the update into the existing actor.
session.cacheActorUpdateMessage(message);

Expand Down