How to use the @microsoft/mixed-reality-extension-sdk.DegreesToRadians function in @microsoft/mixed-reality-extension-sdk

To help you get started, we’ve selected a few @microsoft/mixed-reality-extension-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / mixed-reality-extension-sdk-samples / samples / solar-system / src / app.ts View on Github external
private createBody(bodyName: string) {
        console.log(`Loading ${bodyName}`);

        const facts = database[bodyName];

        const distanceMultiplier = Math.pow(facts.distance, 1 / 3);
        const scaleMultiplier = Math.pow(facts.diameter, 1 / 3) / 25;

        const positionValue = { x: distanceMultiplier, y: 0, z: 0 };
        const scaleValue = { x: scaleMultiplier / 2, y: scaleMultiplier / 2, z: scaleMultiplier / 2 };
        const obliquityValue = MRESDK.Quaternion.RotationAxis(
            MRESDK.Vector3.Forward(), facts.obliquity * MRESDK.DegreesToRadians);
        const inclinationValue = MRESDK.Quaternion.RotationAxis(
            MRESDK.Vector3.Forward(), facts.inclination * MRESDK.DegreesToRadians);

        // Object layout for celestial body is:
        //  inclination                 -- orbital plane. centered on sol and tilted
        //      position                -- position of center of celestial body (orbits sol)
        //          label               -- centered above position. location of label.
        //          obliquity0          -- centered on position. hidden node to account
        //                                 for the fact that obliquity is a world-relative axis
        //              obliquity1      -- centered on position. tilt of obliquity axis
        //                  model       -- centered on position. the celestial body (rotates)
        try {
            const inclination = MRESDK.Actor.CreateEmpty(this.context, {
                actor: {
                    name: `${bodyName}-inclination`,
                    transform: {
                        rotation: inclinationValue
                    }
github microsoft / mixed-reality-extension-sdk-samples / samples / solar-system / src / app.ts View on Github external
private createBody(bodyName: string) {
        console.log(`Loading ${bodyName}`);

        const facts = database[bodyName];

        const distanceMultiplier = Math.pow(facts.distance, 1 / 3);
        const scaleMultiplier = Math.pow(facts.diameter, 1 / 3) / 25;

        const positionValue = { x: distanceMultiplier, y: 0, z: 0 };
        const scaleValue = { x: scaleMultiplier / 2, y: scaleMultiplier / 2, z: scaleMultiplier / 2 };
        const obliquityValue = MRESDK.Quaternion.RotationAxis(
            MRESDK.Vector3.Forward(), facts.obliquity * MRESDK.DegreesToRadians);
        const inclinationValue = MRESDK.Quaternion.RotationAxis(
            MRESDK.Vector3.Forward(), facts.inclination * MRESDK.DegreesToRadians);

        // Object layout for celestial body is:
        //  inclination                 -- orbital plane. centered on sol and tilted
        //      position                -- position of center of celestial body (orbits sol)
        //          label               -- centered above position. location of label.
        //          obliquity0          -- centered on position. hidden node to account
        //                                 for the fact that obliquity is a world-relative axis
        //              obliquity1      -- centered on position. tilt of obliquity axis
        //                  model       -- centered on position. the celestial body (rotates)
        try {
            const inclination = MRESDK.Actor.CreateEmpty(this.context, {
                actor: {
                    name: `${bodyName}-inclination`,
                    transform: {
                        app: { rotation: inclinationValue }
                    }
github microsoft / mixed-reality-extension-sdk-samples / samples / wear-a-hat / src / app.ts View on Github external
// If the user selected 'none', then early out.
        if (!hatRecord.resourceName) {
            return;
        }

        // Create the hat model and attach it to the avatar's head.
        this.attachedHats[userId] = MRESDK.Actor.CreateFromPrefab(this.context, {
            prefabId: this.prefabs[hatId].prefabs.byIndex(0).id,
            actor: {
                transform: {
                    local: {
                        position: hatRecord.position,
                        rotation: MRESDK.Quaternion.FromEulerAngles(
                            hatRecord.rotation.x * MRESDK.DegreesToRadians,
                            hatRecord.rotation.y * MRESDK.DegreesToRadians,
                            hatRecord.rotation.z * MRESDK.DegreesToRadians),
                        scale: hatRecord.scale,
                    }
                },
                attachment: {
                    attachPoint: 'head',
                    userId
                }
            }
        }).value;
    }
}
github microsoft / mixed-reality-extension-sdk-samples / samples / wear-a-hat / src / app.ts View on Github external
// If the user selected 'none', then early out.
        if (!hatRecord.resourceName) {
            return;
        }

        // Create the hat model and attach it to the avatar's head.
        this.attachedHats[userId] = MRESDK.Actor.CreateFromPrefab(this.context, {
            prefabId: this.prefabs[hatId].prefabs.byIndex(0).id,
            actor: {
                transform: {
                    local: {
                        position: hatRecord.position,
                        rotation: MRESDK.Quaternion.FromEulerAngles(
                            hatRecord.rotation.x * MRESDK.DegreesToRadians,
                            hatRecord.rotation.y * MRESDK.DegreesToRadians,
                            hatRecord.rotation.z * MRESDK.DegreesToRadians),
                        scale: hatRecord.scale,
                    }
                },
                attachment: {
                    attachPoint: 'head',
                    userId
                }
            }
        }).value;
    }
}
github microsoft / mixed-reality-extension-sdk-samples / samples / solar-system / src / app.ts View on Github external
private createOrbitalAnimation(bodyName: string) {
        const facts = database[bodyName];
        const celestialBody = this.celestialBodies[bodyName];

        if (facts.year > 0) {
            // years = seconds (not in agreement with axial animation)
            const orbitTimeInSeconds = facts.year / this.timeFactor;
            const timeStep = orbitTimeInSeconds / this.orbitalKeyframeCount;
            const angleStep = 360 / this.orbitalKeyframeCount;
            const keyframes: MRESDK.AnimationKeyframe[] = [];
            const initial = celestialBody.position.transform.position.clone();
            let value: Partial;

            for (let i = 0; i < this.orbitalKeyframeCount; ++i) {
                const rotDelta = MRESDK.Quaternion.RotationAxis(
                    MRESDK.Vector3.Up(), (-angleStep * i) * MRESDK.DegreesToRadians);
                const position = initial.rotateByQuaternionToRef(rotDelta, new MRESDK.Vector3());
                value = {
                    transform: {
                        position
                    }
                };
                keyframes.push({
                    time: timeStep * i,
                    value,
                });
            }

            // Final frame
            value = {
                transform: {
                    position: celestialBody.position.transform.position
github microsoft / mixed-reality-extension-sdk-samples / samples / solar-system / src / app.ts View on Github external
const facts = database[bodyName];
        const celestialBody = this.celestialBodies[bodyName];

        if (facts.day > 0) {
            const spin = facts.retrograde ? -1 : 1;
            // days = seconds (not in agreement with orbital animation)
            const axisTimeInSeconds = facts.day / this.timeFactor;
            const timeStep = axisTimeInSeconds / this.axialKeyframeCount;
            const keyframes: MRESDK.AnimationKeyframe[] = [];
            const angleStep = 360 / this.axialKeyframeCount;
            const initial = celestialBody.model.transform.local.rotation.clone();
            let value: Partial;

            for (let i = 0; i < this.axialKeyframeCount; ++i) {
                const rotDelta = MRESDK.Quaternion.RotationAxis(
                    MRESDK.Vector3.Up(), (-angleStep * i * spin) * MRESDK.DegreesToRadians);
                const rotation = initial.multiply(rotDelta);
                value = {
                    transform: {
                        local: { rotation }
                    }
                };
                keyframes.push({
                    time: timeStep * i,
                    value,
                });
            }

            // Final frame
            value = {
                transform: {
                    local: { rotation: celestialBody.model.transform.local.rotation }

@microsoft/mixed-reality-extension-sdk

The Mixed Reality Extension SDK enables developers to build 3D world extensions for AltspaceVR, using Node.JS.

MIT
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis