SparkAR Community Scripting Docs
  • Spark AR Scripting Reference
  • Audio Analyzer / Energy Meter
  • Asynchronous API Changes (v85+)
  • Custom Instructions
  • AnimationModule
    • ValueDriver
    • TimeDriver
    • SignalRecorder
    • SignalRecord
    • ScalarSampler
    • SamplerFactory
    • RotationSampler
    • Driver
    • ColorSampler
    • ArrayOfScalarSignals
    • ArrayOfScalarSamplers
  • AudioModule
    • PlaybackController
  • CameraInfoModule
    • CameraPosition
  • DeepLinkModule
  • DeviceMotionModule
  • DiagnosticsModule
  • FaceGesturesModule
  • FaceTracking2DModule
    • Face2D
  • FaceTrackingModule
    • Cheek
    • Chin
    • Eye
    • Eyebrow
    • Face
    • Forehead
    • Mouth
    • Nose
  • FontsModule
    • FontId
  • HandTrackingModule
    • Hand
  • InstructionModule
  • IrisTrackingModule
    • Eyeball
  • LightingEstimationModule
  • LiveStreamingModule
    • LiveStreamingModule.State
    • LiveStreamingReactions
    • LiveStreamingComments
  • LocaleModule
  • MaterialsModule
    • TextureTransform
    • RetouchingMaterial
    • MetallicRoughnessPbrMaterial
    • MaterialBase
    • DefaultMaterial
    • ColorPaintMaterial
    • BlendShapeToWarpMapMaterial
    • BlendedMaterial
  • NativeUIModule
    • Picker
  • NetworkingModule
  • PatchesModule
  • PersistenceModule
    • StorageScope
  • PersonSegmentationModule
  • RandomModule
  • ReactiveModule
    • AntiderivativeOverflowBehaviour
    • BoundingBoxSignal
    • ISignal
    • PixelPointSignal
    • PixelSizeSignal
    • Point2D
    • Point2DSignal
    • Point3D
    • Point4DSignal
    • PointSignal
    • PrimitiveOrShaderSignal
    • RgbaSignal
    • BoolSignal
    • Rotation
    • RotationSignal
    • ScalarSignal
    • ScalarValue
    • ScaleSignal
    • ShaderSignal
    • StringSignal
    • StringValue
    • Subscription
    • BoolValue
    • VectorSignal
    • TransformSignal
    • ColorSignal
    • EulerAnglesSignal
    • EventSource
    • HsvaSignal
    • InsetsSignal
  • SceneModule
    • AmbientLightSource
    • BrushType
    • HorizontalAlignment
    • RenderMode
    • ScalingOption
    • TextAlignment
    • TrackingMode
    • SpotLightSource
    • PointLightSource
    • DirectionalLightSource
    • HandTrackerSceneObject
    • Canvas
    • DynamicExtrusion
    • FaceAnchor
    • FaceMesh
    • VerticalTextAlignment
    • VerticalAlignment
    • FaceTracker
    • FocalPlane
    • FocalDistance
    • OutputVisibility
    • Mesh
    • Joint
    • PlaneTracker
    • Plane
    • PlanarText
    • PlanarObject
    • PlanarImage
    • PlanarFlexItem
    • PlanarDiv
    • ParticleTypeDescriptions
    • ParticleSystem
    • ParticleTypeDescription
    • PlanarFlexContainer
    • TextExtrusion
    • SvgImage
    • BlendShapesMesh
    • BlockSceneRoot
    • BoundingBox
    • Bounds2D
    • Camera
    • CameraVisibility
    • BlendShape
    • Scene
    • SceneObjectBase
    • ScreenPlane
    • Skeleton
    • segmentation
    • Speaker
    • Transform
    • TargetTracker
    • TextAlignmentWrapper
    • WorldTransform
    • SceneObject
  • ShadersModule
    • VertexAttribute
    • SdfVariant
    • PhysicallyBasedMaterialTextures
    • GradientType
    • FacePaintMaterialTextures
    • DerivativeType
    • DefaultMaterialTextures
    • ColorSpace
    • BuiltinUniform
    • BlendMode
    • BlendedMaterialTextures
  • SvgsModule
  • TexturesModule
    • State
    • SourceImageRegionTexture
    • SubTexture
    • TextureBase
    • CameraTexture
    • CanvasTexture
    • ColorTexture
    • DeepLinkTexture
    • ExternalTexture
    • ImageTexture
    • SegmentationTexture
    • SequenceTexture
  • TimeModule
  • TouchGesturesModule
    • Type
    • TouchGestureModule.Gesture.State
    • Gesture
    • LongPressGesture
    • PanGesture
    • PinchGesture
    • RawTouchGesture
    • RotateGesture
    • TapGesture
  • UnitsModule
Powered by GitBook
On this page
  • Example
  • Properties
  • Methods

Was this helpful?

  1. ReactiveModule

Rotation

The Rotation class encapsulates an object's rotation.

Example

// The following example uses ReactiveModule.rotation(w,x,y,z) to construct a rotation
// from a quaternion-based representation of it. The constructed rotation is used with
// AnimationModule.samplers.polyline to create a rotation animation that is expressed as a RotationSignal.

var SceneModule = require('Scene');
var AnimationModule = require('Animation');
var ReactiveModule = require('Reactive');

// Construct a Rotation object from a quaternion-based values.
function axisRotation(axis_x, axis_y, axis_z, angle_degrees) {
    var norm = Math.sqrt(axis_x*axis_x + axis_y*axis_y + axis_z*axis_z);
    axis_x /= norm;
    axis_y /= norm;
    axis_z /= norm;
    var angle_radians = angle_degrees * Math.PI / 180.0;
    var cos = Math.cos(angle_radians/2);
    var sin = Math.sin(angle_radians/2);
    return ReactiveModule.rotation(
        cos, axis_x*sin, axis_y*sin, axis_z*sin);
}

var time_driver = AnimationModule.timeDriver({
    durationMilliseconds: 2000,
    loopCount: Infinity
});

// Create a rotation sampler using Rotation objects generated
// by the previously-defined axisRotation() method.
var rotation_sampler = AnimationModule.samplers.polyline({
    keyframes: [
        axisRotation(1,0,0,0),
        axisRotation(1,0,0,45),
        axisRotation(1,1,0,45),
        axisRotation(1,0,1,45),
        axisRotation(1,0,0,0)
    ],
    knots: [
        0, 1, 3, 5, 7
    ]
});

// Start the animation
var rotation_signal = AnimationModule.animate(time_driver, rotation_sampler);
time_driver.start();

// Apply the rotation transform to a scene object.
var plane = SceneModule.root.find('plane0');
plane.transform.rotation = rotation_signal;

Properties

This module exposes no properties.

Methods

This module exposes no methods.

PreviousBoolSignalNextRotationSignal

Last updated 5 years ago

Was this helpful?