- * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
- * @param context The context when loading the asset
- * @param material The glTF material property
- * @param assign A function called synchronously after parsing the glTF properties
- * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
+ * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
+ * @param context The context when loading the asset
+ * @param material The glTF material property
+ * @param assign A function called synchronously after parsing the glTF properties
+ * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
+ for (var index = 0; index < runtimeAnimations.length; index++) {
+ runtimeAnimations[index].goToFrame(frame);
}
+ }
- /**
- * Stop and delete the current animation
- * @param animationName defines a string used to only stop some of the runtime animations instead of all
- * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)
+ * @param animationName defines a string used to only stop some of the runtime animations instead of all
+ * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty)
- if (this._isStarted || this._targetedAnimations.length === 0) {
- return this;
- }
+ for (const targetedAnimation of this._targetedAnimations) {
+ let animatable = this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio);
- for (const targetedAnimation of this._targetedAnimations) {
- let animatable = this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio);
import { Animatable } from "../../Animations/animatable";
import { Animation } from "../../Animations/animation";
+/**
+ * The framing behavior (FramingBehavior) is designed to automatically position an ArcRotateCamera when its target is set to a mesh. It is also useful if you want to prevent the camera to go under a virtual horizontal plane.
+export class FramingBehavior implements Behavior<ArcRotateCamera> {
/**
- * The framing behavior (FramingBehavior) is designed to automatically position an ArcRotateCamera when its target is set to a mesh. It is also useful if you want to prevent the camera to go under a virtual horizontal plane.
@@ -6,167 +6,167 @@ import { Nullable } from "../../types";
import { Observer } from "../../Misc/observable";
import { Behavior } from "../../Behaviors/behavior";
+/**
+ * @hidden
+ */
+class FaceDirectionInfo {
+ constructor(public direction: Vector3, public rotatedDirection = new Vector3(), public diff = 0, public ignore = false) { }
+}
+
+/**
+ * A behavior that when attached to a mesh will will place a specified node on the meshes face pointing towards the camera
+ */
+export class AttachToBoxBehavior implements Behavior<Mesh> {
+ /**
+ * The name of the behavior
+ */
+ public name = "AttachToBoxBehavior";
+ /**
+ * The distance away from the face of the mesh that the UI should be attached to (default: 0.15)
+ */
+ public distanceAwayFromFace = 0.15;
/**
- * @hidden
+ * The distance from the bottom of the face that the UI should be attached to (default: 0.15)
*/
- class FaceDirectionInfo {
- constructor(public direction: Vector3, public rotatedDirection = new Vector3(), public diff = 0, public ignore = false) {}
+ public distanceAwayFromBottomOfFace = 0.15;
+ private _faceVectors = [new FaceDirectionInfo(Vector3.Up()), new FaceDirectionInfo(Vector3.Down()), new FaceDirectionInfo(Vector3.Left()), new FaceDirectionInfo(Vector3.Right()), new FaceDirectionInfo(Vector3.Forward()), new FaceDirectionInfo(Vector3.Forward().scaleInPlace(-1))];
+ * Creates the AttachToBoxBehavior, used to attach UI to the closest face of the box to a camera
+ * @param ui The transform node that should be attched to the mesh
+ */
+ constructor(private ui: TransformNode) {
+ /* Does nothing */
}
/**
- * A behavior that when attached to a mesh will will place a specified node on the meshes face pointing towards the camera
+ * Initializes the behavior
*/
- export class AttachToBoxBehavior implements Behavior<Mesh> {
- /**
- * The name of the behavior
- */
- public name = "AttachToBoxBehavior";
- /**
- * The distance away from the face of the mesh that the UI should be attached to (default: 0.15)
- */
- public distanceAwayFromFace = 0.15;
- /**
- * The distance from the bottom of the face that the UI should be attached to (default: 0.15)
- */
- public distanceAwayFromBottomOfFace = 0.15;
- private _faceVectors = [new FaceDirectionInfo(Vector3.Up()), new FaceDirectionInfo(Vector3.Down()), new FaceDirectionInfo(Vector3.Left()), new FaceDirectionInfo(Vector3.Right()), new FaceDirectionInfo(Vector3.Forward()), new FaceDirectionInfo(Vector3.Forward().scaleInPlace(-1))];
- * Creates a pointer drag behavior that can be attached to a mesh
- * @param options The drag axis or normal of the plane that will be dragged across. If no options are specified the drag plane will always face the ray's origin (eg. camera)
+ * Creates a pointer drag behavior that can be attached to a mesh
+ * @param options The drag axis or normal of the plane that will be dragged across. If no options are specified the drag plane will always face the ray's origin (eg. camera)
+ private _startingOrientation = new Quaternion();
/**
- * A behavior that when attached to a mesh will allow the mesh to be dragged around based on directions and origin of the pointer's ray
+ * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 3)
*/
- export class SixDofDragBehavior implements Behavior<Mesh> {
- private _startingOrientation = new Quaternion();
- /**
- * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 3)
- */
- private zDragFactor = 3;
- /**
- * If the object should rotate to face the drag origin
- */
- public rotateDraggedObject = true;
- /**
- * If the behavior is currently in a dragging state
- */
- public dragging = false;
- /**
- * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
- */
- public dragDeltaRatio = 0.2;
- /**
- * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
- */
- public currentDraggingPointerID = -1;
- /**
- * If camera controls should be detached during the drag
- */
- public detachCameraControls = true;
- /**
- * Fires each time a drag starts
- */
- public onDragStartObservable = new Observable<{}>();
- /**
- * Fires each time a drag ends (eg. mouse release after drag)
- */
- public onDragEndObservable = new Observable<{}>();
-
- /**
- * Instantiates a behavior that when attached to a mesh will allow the mesh to be dragged around based on directions and origin of the pointer's ray
- */
- constructor() {
- }
+ private zDragFactor = 3;
+ /**
+ * If the object should rotate to face the drag origin
+ */
+ public rotateDraggedObject = true;
+ /**
+ * If the behavior is currently in a dragging state
+ */
+ public dragging = false;
+ /**
+ * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+ */
+ public dragDeltaRatio = 0.2;
+ /**
+ * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
+ */
+ public currentDraggingPointerID = -1;
+ /**
+ * If camera controls should be detached during the drag
+ */
+ public detachCameraControls = true;
+ /**
+ * Fires each time a drag starts
+ */
+ public onDragStartObservable = new Observable<{}>();
+ /**
+ * Fires each time a drag ends (eg. mouse release after drag)
+ */
+ public onDragEndObservable = new Observable<{}>();
- /**
- * The name of the behavior
- */
- public get name(): string {
- return "SixDofDrag";
- }
+ /**
+ * Instantiates a behavior that when attached to a mesh will allow the mesh to be dragged around based on directions and origin of the pointer's ray
+ */
+ constructor() {
+ }
- /**
- * Initializes the behavior
- */
- public init() { }
-
- /**
- * Attaches the scale behavior the passed in mesh
- * @param ownerNode The mesh that will be scaled around once attached
- */
- public attach(ownerNode: Mesh): void {
- this._ownerNode = ownerNode;
- this._scene = this._ownerNode.getScene();
- if (!SixDofDragBehavior._virtualScene) {
- SixDofDragBehavior._virtualScene = new Scene(this._scene.getEngine());
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- let manager = this.camera.getScene().gamepadManager;
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ let manager = this.camera.getScene().gamepadManager;
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- this._wheel = (p, s) => {
- //sanity check - this should be a PointerWheel event.
- if (p.type !== PointerEventTypes.POINTERWHEEL) { return; }
- var event = <MouseWheelEvent>p.event;
- var delta = 0;
+ /**
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ this._wheel = (p, s) => {
+ //sanity check - this should be a PointerWheel event.
+ if (p.type !== PointerEventTypes.POINTERWHEEL) { return; }
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- var engine = this.camera.getEngine();
- var cacheSoloPointer: Nullable<{ x: number, y: number, pointerId: number, type: any }>; // cache pointer object for better perf on camera rotation
- var pointA: Nullable<{ x: number, y: number, pointerId: number, type: any }> = null;
- var pointB: Nullable<{ x: number, y: number, pointerId: number, type: any }> = null;
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ var engine = this.camera.getEngine();
+ var cacheSoloPointer: Nullable<{ x: number, y: number, pointerId: number, type: any }>; // cache pointer object for better perf on camera rotation
+ var pointA: Nullable<{ x: number, y: number, pointerId: number, type: any }> = null;
+ var pointB: Nullable<{ x: number, y: number, pointerId: number, type: any }> = null;
- } else if (p.type === PointerEventTypes.POINTERMOVE) {
- if (!noPreventDefault) {
- evt.preventDefault();
+
+ cacheSoloPointer.x = evt.clientX;
+ cacheSoloPointer.y = evt.clientY;
+ }
+
+ // Two buttons down: pinch/pan
+ else if (pointA && pointB) {
+ //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be useful to force preventDefault to avoid html page scroll/zoom in some mobile browsers
+ var ed = (pointA.pointerId === evt.pointerId) ? pointA : pointB;
- //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be useful to force preventDefault to avoid html page scroll/zoom in some mobile browsers
- var ed = (pointA.pointerId === evt.pointerId) ? pointA : pointB;
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- if (this._onCanvasBlurObserver) {
- return;
- }
+ public camera: FlyCamera;
+
+ /**
+ * The list of keyboard keys used to control the forward move of the camera.
+ */
+ @serialize()
+ public keysForward = [87];
+
+ /**
+ * The list of keyboard keys used to control the backward move of the camera.
+ */
+ @serialize()
+ public keysBackward = [83];
+
+ /**
+ * The list of keyboard keys used to control the forward move of the camera.
+ */
+ @serialize()
+ public keysUp = [69];
+
+ /**
+ * The list of keyboard keys used to control the backward move of the camera.
+ */
+ @serialize()
+ public keysDown = [81];
+
+ /**
+ * The list of keyboard keys used to control the right strafe move of the camera.
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- if (this._onCanvasBlurObserver) {
- return;
- }
+ public camera: FollowCamera;
- this._scene = this.camera.getScene();
- this._engine = this._scene.getEngine();
+ /**
+ * Defines the list of key codes associated with the up action (increase heightOffset)
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ this._constantTranform = new Quaternion(- Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));
+ this._orientationChanged();
+ }
- /**
- * Define the camera controlled by the input.
- */
- public get camera(): FreeCamera {
- return this._camera;
- }
+ /**
+ * Define the camera controlled by the input.
+ */
+ public get camera(): FreeCamera {
+ return this._camera;
+ }
- public set camera(camera: FreeCamera) {
- this._camera = camera;
- if (this._camera != null && !this._camera.rotationQuaternion) {
- this._camera.rotationQuaternion = new Quaternion();
- }
+ public set camera(camera: FreeCamera) {
+ this._camera = camera;
+ if (this._camera != null && !this._camera.rotationQuaternion) {
+ this._camera.rotationQuaternion = new Quaternion();
}
+ }
- /**
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- //In certain cases, the attach control is called AFTER orientation was changed,
- //So this is needed.
- this._orientationChanged();
- }
+ /**
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- let manager = this.camera.getScene().gamepadManager;
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ let manager = this.camera.getScene().gamepadManager;
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- if (this._onCanvasBlurObserver) {
- return;
- }
+ public camera: FreeCamera;
+
+ /**
+ * Gets or Set the list of keyboard keys used to control the forward move of the camera.
+ */
+ @serialize()
+ public keysUp = [38];
+
+ /**
+ * Gets or Set the list of keyboard keys used to control the backward move of the camera.
+ */
+ @serialize()
+ public keysDown = [40];
+
+ /**
+ * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.
+ */
+ @serialize()
+ public keysLeft = [37];
+
+ /**
+ * Gets or Set the list of keyboard keys used to control the right strafe move of the camera.
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * @param touchEnabled Defines if touch is enabled or not
+ * Define if touch is enabled in the mouse input
*/
- constructor(
- /**
- * Define if touch is enabled in the mouse input
- */
- public touchEnabled = true) {
- }
+ public touchEnabled = true) {
+ }
- /**
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- var engine = this.camera.getEngine();
+ /**
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ var engine = this.camera.getEngine();
- if (!this._pointerInput) {
- this._pointerInput = (p) => {
- var evt = <PointerEvent>p.event;
+ if (!this._pointerInput) {
+ this._pointerInput = (p) => {
+ var evt = <PointerEvent>p.event;
- if (engine.isInVRExclusivePointerMode) {
- return;
- }
+ if (engine.isInVRExclusivePointerMode) {
+ return;
+ }
- if (!this.touchEnabled && evt.pointerType === "touch") {
- return;
- }
+ if (!this.touchEnabled && evt.pointerType === "touch") {
+ return;
+ }
- if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {
- return;
- }
+ if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {
+ return;
+ }
- let srcElement = <HTMLElement>(evt.srcElement || evt.target);
+ let srcElement = <HTMLElement>(evt.srcElement || evt.target);
- if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
- try {
- srcElement.setPointerCapture(evt.pointerId);
- } catch (e) {
- //Nothing to do with the error. Execution will continue.
- }
+ if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
+ try {
+ srcElement.setPointerCapture(evt.pointerId);
+ } catch (e) {
+ //Nothing to do with the error. Execution will continue.
+ }
- this.previousPosition = {
- x: evt.clientX,
- y: evt.clientY
- };
+ this.previousPosition = {
+ x: evt.clientX,
+ y: evt.clientY
+ };
- if (!noPreventDefault) {
- evt.preventDefault();
- element.focus();
- }
+ if (!noPreventDefault) {
+ evt.preventDefault();
+ element.focus();
}
- else if (p.type === PointerEventTypes.POINTERUP && srcElement) {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- var previousPosition: Nullable<{ x: number, y: number }> = null;
-
- if (this._pointerInput === undefined) {
- this._onLostFocus = () => {
- this._offsetX = null;
- this._offsetY = null;
- };
+ public camera: FreeCamera;
- this._pointerInput = (p) => {
- var evt = <PointerEvent>p.event;
+ /**
+ * Defines the touch sensibility for rotation.
+ * The higher the faster.
+ */
+ @serialize()
+ public touchAngularSensibility: number = 200000.0;
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ var previousPosition: Nullable<{ x: number, y: number }> = null;
+
+ if (this._pointerInput === undefined) {
+ this._onLostFocus = () => {
+ this._offsetX = null;
+ this._offsetY = null;
+ };
- if (!noPreventDefault) {
- evt.preventDefault();
- }
+ this._pointerInput = (p) => {
+ var evt = <PointerEvent>p.event;
- this._pointerPressed.push(evt.pointerId);
+ if (evt.pointerType === "mouse") {
+ return;
+ }
- if (this._pointerPressed.length !== 1) {
- return;
- }
+ if (p.type === PointerEventTypes.POINTERDOWN) {
- previousPosition = {
- x: evt.clientX,
- y: evt.clientY
- };
+ if (!noPreventDefault) {
+ evt.preventDefault();
}
- else if (p.type === PointerEventTypes.POINTERUP) {
- if (!noPreventDefault) {
- evt.preventDefault();
- }
+ this._pointerPressed.push(evt.pointerId);
- var index: number = this._pointerPressed.indexOf(evt.pointerId);
+ if (this._pointerPressed.length !== 1) {
+ return;
+ }
- if (index === -1) {
- return;
- }
- this._pointerPressed.splice(index, 1);
+ previousPosition = {
+ x: evt.clientX,
+ y: evt.clientY
+ };
+ }
- if (index != 0) {
- return;
- }
- previousPosition = null;
- this._offsetX = null;
- this._offsetY = null;
+ else if (p.type === PointerEventTypes.POINTERUP) {
+ if (!noPreventDefault) {
+ evt.preventDefault();
}
- else if (p.type === PointerEventTypes.POINTERMOVE) {
- if (!noPreventDefault) {
- evt.preventDefault();
- }
+ var index: number = this._pointerPressed.indexOf(evt.pointerId);
- if (!previousPosition) {
- return;
- }
+ if (index === -1) {
+ return;
+ }
+ this._pointerPressed.splice(index, 1);
- var index: number = this._pointerPressed.indexOf(evt.pointerId);
+ if (index != 0) {
+ return;
+ }
+ previousPosition = null;
+ this._offsetX = null;
+ this._offsetY = null;
+ }
- if (index != 0) {
- return;
- }
+ else if (p.type === PointerEventTypes.POINTERMOVE) {
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
@@ -7,194 +7,194 @@ import { Ray } from "../../Culling/ray";
import { Camera } from "../../Cameras/camera";
import { WebXRSessionManager } from "./webXRSessionManager";
import { WebXRCamera } from "./webXRCamera";
+/**
+ * States of the webXR experience
+ */
+export enum WebXRState {
/**
- * States of the webXR experience
- */
- export enum WebXRState {
- /**
- * Transitioning to being in XR mode
- */
- ENTERING_XR,
- /**
- * Transitioning to non XR mode
- */
- EXITING_XR,
- /**
- * In XR mode and presenting
- */
- IN_XR,
- /**
- * Not entered XR mode
- */
- NOT_IN_XR
+ * Transitioning to being in XR mode
+ */
+ ENTERING_XR,
+ /**
+ * Transitioning to non XR mode
+ */
+ EXITING_XR,
+ /**
+ * In XR mode and presenting
+ */
+ IN_XR,
+ /**
+ * Not entered XR mode
+ */
+ NOT_IN_XR
+}
+/**
+ * Helper class used to enable XR
+ * @see https://doc.babylonjs.com/how_to/webxr
+ */
+export class WebXRExperienceHelper implements IDisposable {
+ /**
+ * Container which stores the xr camera and controllers as children. This can be used to move the camera/user as the camera's position is updated by the xr device
+ */
+ public container: AbstractMesh;
+ /**
+ * Camera used to render xr content
+ */
+ public camera: WebXRCamera;
+
+ /**
+ * The current state of the XR experience (eg. transitioning, in XR or not in XR)
+ */
+ public state: WebXRState = WebXRState.NOT_IN_XR;
- export class WebXRExperienceHelper implements IDisposable {
- /**
- * Container which stores the xr camera and controllers as children. This can be used to move the camera/user as the camera's position is updated by the xr device
- */
- public container: AbstractMesh;
- /**
- * Camera used to render xr content
- */
- public camera: WebXRCamera;
-
- /**
- * The current state of the XR experience (eg. transitioning, in XR or not in XR)
- */
- public state: WebXRState = WebXRState.NOT_IN_XR;
import { AbstractMesh } from "../../Meshes/abstractMesh";
import { WebXRExperienceHelper } from "./webXRExperienceHelper";
+/**
+ * Represents an XR input
+ */
+export class WebXRController {
/**
- * Represents an XR input
+ * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if thats the case only the pointer from the head will be availible
*/
- export class WebXRController {
- /**
- * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if thats the case only the pointer from the head will be availible
- */
- public grip?: AbstractMesh;
- /**
- * Pointer which can be used to select objects or attach a visible laser to
- */
- public pointer: AbstractMesh;
+ public grip?: AbstractMesh;
+ /**
+ * Pointer which can be used to select objects or attach a visible laser to
+ */
+ public pointer: AbstractMesh;
- /**
- * Creates the controller
- * @see https://doc.babylonjs.com/how_to/webxr
- * @param scene the scene which the controller should be associated to
- */
- constructor(scene: Scene) {
- this.pointer = new AbstractMesh("controllerPointer", scene);
- }
- /**
- * Disposes of the object
- */
- dispose() {
- if (this.grip) {
- this.grip.dispose();
- }
- this.pointer.dispose();
+ /**
+ * Creates the controller
+ * @see https://doc.babylonjs.com/how_to/webxr
+ * @param scene the scene which the controller should be associated to
+ */
+ constructor(scene: Scene) {
+ this.pointer = new AbstractMesh("controllerPointer", scene);
+ }
+ /**
+ * Disposes of the object
+ */
+ dispose() {
+ if (this.grip) {
+ this.grip.dispose();
}
+ this.pointer.dispose();
}
+}
+/**
+ * XR input used to track XR inputs such as controllers/rays
+ */
+export class WebXRInput implements IDisposable {
/**
- * XR input used to track XR inputs such as controllers/rays
+ * XR controllers being tracked
*/
- export class WebXRInput implements IDisposable {
- /**
- * XR controllers being tracked
- */
- public controllers: Array<WebXRController> = [];
- // The canvas is added to the screen before entering XR because currently the xr session must be initialized while the canvas is added render properly
- this._addCanvas();
- }else if (helper.state == WebXRState.NOT_IN_XR) {
- this._removeCanvas();
- }
- });
- }
- /**
- * Disposes of the object
- */
- public dispose() {
- this._removeCanvas();
- this._setManagedOutputCanvas(null);
+ public canvasContext: Nullable<WebGLRenderingContext> = null;
+ /**
+ * Initializes the canvas to be added/removed upon entering/exiting xr
+ * @param helper the xr experience helper used to trigger adding/removing of the canvas
+ * @param canvas The canvas to be added/removed (If not specified a full screen canvas will be created)
+ */
+ public constructor(helper: WebXRExperienceHelper, canvas?: HTMLCanvasElement) {
+ // The canvas is added to the screen before entering XR because currently the xr session must be initialized while the canvas is added render properly
+ this._addCanvas();
+ } else if (helper.state == WebXRState.NOT_IN_XR) {
+ * Get the friendly name associated with the input class.
+ * @returns the input friendly name
+ */
+ getSimpleName(): string;
+ /**
+ * Attach the input controls to a specific dom element to get the input from.
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- * Get the friendly name associated with the input class.
- * @returns the input friendly name
- */
- getSimpleName(): string;
- /**
- * Attach the input controls to a specific dom element to get the input from.
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- * Attach the current manager inputs controls to a specific dom element to listen the events from.
- * @param element Defines the dom element to collect the events from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachElement(element: HTMLElement, noPreventDefault: boolean = false): void {
- if (this.attachedElement) {
- return;
- }
+ /**
+ * Attach the current manager inputs controls to a specific dom element to listen the events from.
+ * @param element Defines the dom element to collect the events from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachElement(element: HTMLElement, noPreventDefault: boolean = false): void {
+ var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
+ if (keyboard) {
+ keyboard.keysLeft = value;
}
+ }
- /**
- * Attach a control to the HTML DOM element.
- * @param element Defines the element that listens to the input events.
- * @param noPreventDefault Defines whether events caught by the controls should call preventdefault(). https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- public _collideWithWorld(displacement: Vector3): void {
- var globalPosition: Vector3;
+ /**
+ * Attach a control to the HTML DOM element.
+ * @param element Defines the element that listens to the input events.
+ * @param noPreventDefault Defines whether events caught by the controls should call preventdefault(). https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
- * @param element Defines the element the controls should be listened from
- * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
- */
- public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+ * @param element Defines the element the controls should be listened from
+ * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
+ */
+ public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {