mixed-reality-extension-sdk icon indicating copy to clipboard operation
mixed-reality-extension-sdk copied to clipboard

Resetting a transform is ignored after animating

Open shanewhitfield opened this issue 5 years ago • 3 comments

Editing a transform doesn't work after an animation has completed and a new parent is set

Repros:

  1. Animate app transform
  2. When done, change parent
  3. Set local transform

shanewhitfield avatar Aug 14 '20 18:08 shanewhitfield

Please define "doesn't work". Is the new transform ignored, or does the actor appear in the wrong place?

stevenvergenz avatar Aug 21 '20 00:08 stevenvergenz

Here's a min repro (with v0.18):

private started() {
        this.assets = new MRE.AssetContainer(this.context);
        const boxMesh = this.assets.createBoxMesh("box", 1, 1, 1);

        const child = Actor.Create(this.context, {
            actor: {
                name: "Child",
                appearance: {
                    meshId: boxMesh.id
                },
                transform: {
                    local: { scale: Vector3.One().scale(0.3) }
                }
            }
        });

        const parent = Actor.Create(this.context, {
            actor: {
                name: "Parent",
                transform: {
                    local: {
                        position: { x: 0.1 }
                    }
                }
            }
        });

        console.log("Starting timer");
        setTimeout(() => {
            const promise = child.animateTo(
                { transform: { local: {
                    position: parent.transform.local.position
                }}},
                5.0,
                AnimationEaseCurves.EaseInQuintic);

            promise.then(() => {
                child.transform.local.position = Vector3.Zero(); // <--- Doesn't work
                child.parent = parent;  // <--- Works
                child.transform.local.position = Vector3.Zero(); // <--- Doesn't work
            });
        }, 5000);
    }

afarchy avatar Aug 21 '20 21:08 afarchy

The change to the local position is ignored. It is ignored because the value being set (0,0,0) is the same as the value that was set before the animation ran. The MRE server has no subscription and is unaware that the local position has changed since then, and so it ignores what looks like a no-op.

The parent stuff does not appear to be relevant, here is a reduced repro:

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

export default class Repro {
	constructor(private context: MRE.Context, private baseUrl: string) {
		context.onStarted(() => {
			const assets = new MRE.AssetContainer(this.context);
			const box = MRE.Actor.CreatePrimitive(assets, {
				definition: {
					shape: MRE.PrimitiveShape.Box
				},
				actor: {
					name: "Box",
				}
			});

			const promise = box.animateTo({ 
				transform: { 
					local: {
						position: { x: 1 }
					}
				}
			}, 5.0, MRE.AnimationEaseCurves.Linear);


			promise.then(() => {
				console.log("Transform is " + box.transform.local.position.x); // prints "Transform is 0"
				box.transform.local.position.x = 0;  // Has no effect.  On the client, transform's X value remains 1.
			});
		});
	}
}

thespivey avatar Sep 09 '20 03:09 thespivey