Skip to content

Commit

Permalink
Prettifier definition file (BabylonJS#8571)
Browse files Browse the repository at this point in the history
* Prettier definition

* formatting the webxr code as an example

* singlequote off

Former-commit-id: a2cab5b58c08e50f2de1e5e15205c57de8a1402d
  • Loading branch information
RaananW authored Jul 21, 2020
1 parent 3b46242 commit 70f9034
Show file tree
Hide file tree
Showing 32 changed files with 1,457 additions and 1,434 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 300
}
15 changes: 7 additions & 8 deletions src/XR/features/WebXRAbstractFeature.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IWebXRFeature } from '../webXRFeaturesManager';
import { Observer, Observable, EventState } from '../../Misc/observable';
import { Nullable } from '../../types';
import { WebXRSessionManager } from '../webXRSessionManager';
import { IWebXRFeature } from "../webXRFeaturesManager";
import { Observer, Observable, EventState } from "../../Misc/observable";
import { Nullable } from "../../types";
import { WebXRSessionManager } from "../webXRSessionManager";

/**
* This is the base class for all WebXR features.
Expand All @@ -24,8 +24,7 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
* Construct a new (abstract) WebXR feature
* @param _xrSessionManager the xr session manager for this feature
*/
constructor(protected _xrSessionManager: WebXRSessionManager) {
}
constructor(protected _xrSessionManager: WebXRSessionManager) {}

/**
* Is this feature attached
Expand Down Expand Up @@ -89,7 +88,7 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
protected _addNewAttachObserver<T>(observable: Observable<T>, callback: (eventData: T, eventState: EventState) => void) {
this._removeOnDetach.push({
observable,
observer: observable.add(callback)
observer: observable.add(callback),
});
}

Expand All @@ -99,4 +98,4 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
* @param _xrFrame the current frame
*/
protected abstract _onXRFrame(_xrFrame: XRFrame): void;
}
}
62 changes: 33 additions & 29 deletions src/XR/features/WebXRAnchorSystem.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { WebXRFeatureName, WebXRFeaturesManager } from '../webXRFeaturesManager';
import { WebXRSessionManager } from '../webXRSessionManager';
import { Observable } from '../../Misc/observable';
import { Matrix, Vector3, Quaternion } from '../../Maths/math.vector';
import { TransformNode } from '../../Meshes/transformNode';
import { WebXRAbstractFeature } from './WebXRAbstractFeature';
import { IWebXRHitResult } from './WebXRHitTest';
import { Tools } from '../../Misc/tools';
import { WebXRFeatureName, WebXRFeaturesManager } from "../webXRFeaturesManager";
import { WebXRSessionManager } from "../webXRSessionManager";
import { Observable } from "../../Misc/observable";
import { Matrix, Vector3, Quaternion } from "../../Maths/math.vector";
import { TransformNode } from "../../Meshes/transformNode";
import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
import { IWebXRHitResult } from "./WebXRHitTest";
import { Tools } from "../../Misc/tools";

/**
* Configuration options of the anchor system
Expand Down Expand Up @@ -134,7 +134,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
}
return {
position: this._tmpVector,
rotationQuaternion: this._tmpQuaternion
rotationQuaternion: this._tmpQuaternion,
};
}

Expand All @@ -152,15 +152,13 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
// convert to XR space (right handed) if needed
this._populateTmpTransformation(position, rotationQuaternion);
// the matrix that we'll use
const m = new XRRigidTransform({x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z},
{x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w});
const m = new XRRigidTransform({ x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z }, { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w });
if (!hitTestResult.xrHitResult.createAnchor) {
throw new Error('Anchors not enabled in this browsed. Add "anchors" to optional features');
} else {
try {
return hitTestResult.xrHitResult.createAnchor(m);
}
catch (error) {
} catch (error) {
throw new Error(error);
}
}
Expand All @@ -182,8 +180,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
// convert to XR space (right handed) if needed
this._populateTmpTransformation(position, rotationQuaternion);
// the matrix that we'll use
const xrTransformation = new XRRigidTransform({x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z},
{x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w});
const xrTransformation = new XRRigidTransform({ x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z }, { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w });
if (forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame) {
return this._createAnchorAtTransformation(xrTransformation, this._xrSessionManager.currentFrame);
} else {
Expand All @@ -192,7 +189,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
this._futureAnchors.push({
xrTransformation,
resolve,
reject
reject,
});
});
}
Expand Down Expand Up @@ -232,14 +229,18 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
}

protected _onXRFrame(frame: XRFrame) {
if (!this.attached || !frame) { return; }
if (!this.attached || !frame) {
return;
}

const trackedAnchors = frame.trackedAnchors;
if (trackedAnchors) {
const toRemove = this._trackedAnchors.filter((anchor) => !trackedAnchors.has(anchor.xrAnchor)).map((anchor) => {
const index = this._trackedAnchors.indexOf(anchor);
return index;
});
const toRemove = this._trackedAnchors
.filter((anchor) => !trackedAnchors.has(anchor.xrAnchor))
.map((anchor) => {
const index = this._trackedAnchors.indexOf(anchor);
return index;
});
let idxTracker = 0;
toRemove.forEach((index) => {
const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];
Expand All @@ -251,7 +252,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
if (!this._lastFrameDetected.has(xrAnchor)) {
const newAnchor: Partial<IWebXRAnchor> = {
id: anchorIdProvider++,
xrAnchor: xrAnchor
xrAnchor: xrAnchor,
};
const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);
this._trackedAnchors.push(anchor);
Expand Down Expand Up @@ -282,7 +283,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
return;
}
if (!frame.createAnchor) {
futureAnchor.reject('Anchors not enabled in this browser');
futureAnchor.reject("Anchors not enabled in this browser");
}
this._createAnchorAtTransformation(futureAnchor.xrTransformation, frame).then(futureAnchor.resolve, futureAnchor.reject);
}
Expand Down Expand Up @@ -325,17 +326,20 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
if (xrFrame.createAnchor) {
try {
return xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);
}
catch (error) {
} catch (error) {
throw new Error(error);
}
} else {
throw new Error('Anchors are not enabled in your browser');
throw new Error("Anchors are not enabled in your browser");
}
}
}

// register the plugin
WebXRFeaturesManager.AddWebXRFeature(WebXRAnchorSystem.Name, (xrSessionManager, options) => {
return () => new WebXRAnchorSystem(xrSessionManager, options);
}, WebXRAnchorSystem.Version);
WebXRFeaturesManager.AddWebXRFeature(
WebXRAnchorSystem.Name,
(xrSessionManager, options) => {
return () => new WebXRAnchorSystem(xrSessionManager, options);
},
WebXRAnchorSystem.Version
);
25 changes: 16 additions & 9 deletions src/XR/features/WebXRBackgroundRemover.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WebXRFeaturesManager, WebXRFeatureName } from "../webXRFeaturesManager";
import { WebXRSessionManager } from '../webXRSessionManager';
import { AbstractMesh } from '../../Meshes/abstractMesh';
import { Observable } from '../../Misc/observable';
import { WebXRAbstractFeature } from './WebXRAbstractFeature';
import { WebXRSessionManager } from "../webXRSessionManager";
import { AbstractMesh } from "../../Meshes/abstractMesh";
import { Observable } from "../../Misc/observable";
import { WebXRAbstractFeature } from "./WebXRAbstractFeature";

/**
* Options interface for the background remover plugin
Expand Down Expand Up @@ -57,11 +57,13 @@ export class WebXRBackgroundRemover extends WebXRAbstractFeature {
* @param _xrSessionManager the session manager for this module
* @param options read-only options to be used in this module
*/
constructor(_xrSessionManager: WebXRSessionManager,
constructor(
_xrSessionManager: WebXRSessionManager,
/**
* read-only options to be used in this module
*/
public readonly options: IWebXRBackgroundRemoverOptions = {}) {
public readonly options: IWebXRBackgroundRemoverOptions = {}
) {
super(_xrSessionManager);
}

Expand Down Expand Up @@ -132,6 +134,11 @@ export class WebXRBackgroundRemover extends WebXRAbstractFeature {
}

//register the plugin
WebXRFeaturesManager.AddWebXRFeature(WebXRBackgroundRemover.Name, (xrSessionManager, options) => {
return () => new WebXRBackgroundRemover(xrSessionManager, options);
}, WebXRBackgroundRemover.Version, true);
WebXRFeaturesManager.AddWebXRFeature(
WebXRBackgroundRemover.Name,
(xrSessionManager, options) => {
return () => new WebXRBackgroundRemover(xrSessionManager, options);
},
WebXRBackgroundRemover.Version,
true
);
Loading

0 comments on commit 70f9034

Please sign in to comment.