Adds a listener to an event type.
When an event of the type pType fires, the callback pListener will be called. This function
returns a unique string id that may be used in removeEventListenerById to allow simple
listener removal.
It is possible to add an object that will be included in the callback to avoid creating too many closures.
The id of the inserted callback (actually an UUID).
Adds a listener to an event type.
When an event of the type pType fires, the callback pListener will be called. This function
returns a unique string id that may be used in removeEventListenerById to allow simple
listener removal.
The id of the inserted callback (actually an UUID).
Requests an asynchronous wait for animation ended.
The promise is signaled when the animation is over, i.e. when isCameraAnimationRunning returns
false.
An example with a animation procedure :
/**
* Sample to illustrate the asynchronous screenshot procedure of the InfiniteEngineInterface.
*/
import {
InfiniteEngineInterface, LoadingStates, Vector3,
InfiniteImageInterface, ScreenshotType, AsyncDataLoadedResult, AsyncResultReason, AsyncScreenshotResult
} from 'generated/documentation/appinfiniteapi';
// We try to make a screenshot when all data is loaded
// the div to render the 3D display
let lView3D: HTMLElement;
// created previously, should receive the image data to be displayed to the user (or ask for a download maybe ?)
let lImageData : HTMLImageElement;
// created previously the position of the camera for the screenshot
let lCameraLocation : Vector3;
// created previously the camera center of interest
let lCenterOfInterest : Vector3;
// created previously the 3D engine
let lInfiniteEngine: InfiniteEngineInterface;
const takeScreenshot = async () : Promise<void> =>
{
// bind the 3D rendering to the div (should have been done earlier :) )
lInfiniteEngine.setView(lView3D);
// we will make screenshot of 1024x1024
lInfiniteEngine.setFixedResolution(1024, 1024, 1);
// go to the expected position / location
lInfiniteEngine.getCameraManager().setCameraLocation(lCameraLocation);
lInfiniteEngine.getCameraManager().lookAt(lCenterOfInterest, 0);
// What to do when all data is loaded ?
const lDataLoaded : AsyncDataLoadedResult = await lInfiniteEngine.asyncWaitForDataLoaded();
if (lDataLoaded.reason !== AsyncResultReason.ARR_Success || lDataLoaded.value === undefined)
{
// this is an error that should not happen (perhaps the engine interface has been destroyed ?)
console.log('screenshot procedure failed for some reason');
return;
}
const lDataLoadedState : LoadingStates = lDataLoaded.value.newLoadingState;
switch (lDataLoadedState)
{
case LoadingStates.S_Loading:
// this is an unexpected error
console.log('unexpected error');
return;
case LoadingStates.S_OutOfBudget:
// some fancy message
console.log('Taking a screenshot without everything loaded');
// but we still make a screenshot :)
break;
default:
break;
}
const lScreenshot : AsyncScreenshotResult = await lInfiniteEngine.asyncScreenshot(ScreenshotType.ST_Color, true, 'image/jpeg', 0.95);
if (lScreenshot.reason !== AsyncResultReason.ARR_Success || lScreenshot.value === undefined)
{
// this is an error that may happen (perhaps the engine interface has been destroyed ?, or bad inputs ?)
console.log('screenshot procedure failed for some reason');
return;
}
// What to do when screenshot is ready ?
// the image result
const lInfiniteImage : InfiniteImageInterface = lScreenshot.value;
// is the image valid ? and base64 encoded ?
if ((lInfiniteImage.width === 0) || (!lInfiniteImage.data) || (!lInfiniteImage.base64))
{
console.log('Unexpected screenshot error, aborting')
return;
}
// create the data url in base64
// even if we did not get the expected format, we still get the result
const lDataUrl : string = 'data:' + lInfiniteImage.format + ';base64,' + lInfiniteImage.data;
// resize the image markup
lImageData.width = lInfiniteImage.width;
lImageData.height = lInfiniteImage.height;
// and set data
lImageData.src = lDataUrl;
// we get back to the size of the 3d view but this is up to the application needs
lInfiniteEngine.unsetFixedResolution();
}
takeScreenshot();
A promise. The promise is resolved with the reason (success, disposed).
Enables/Disables the navigation cube (i.e. it responds to user inputs).
The navigation cube is enabled by default.
The navigation cube is an html widget located on the bottom right of the 3d rendering area, which helps the user knowing its current orientation. Information like FRONT, LEFT etc are displayed.
true else it is disabled.Changes the camera position to fit the given AABB to the screen.
The current orientation of the camera and the center of the Box are used to get a virtual line. The camera changes its position to get on that line, its orientation is unchanged. The camera position is set along this line to maximize the drawing of the Box, without any loss of content.
/**
* Sample to illustrate the CameraManagerInterface fit box.
*/
import { AABB, CameraManagerInterface, DataSessionInterface } from 'generated/documentation/appinfiniteapi';
// created previously
let lCameraManager : CameraManagerInterface;
// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// get box of given instance id (retrieved by picking ?)
const pGeometryInstanceId : number = 10;
// time of animation
const pAnimationDurationInMilliseconds : number = 150;
// create an AABB to get the box
const lAABB : AABB = new AABB();
// get the box
lDataSession.getGeometricAABB(pGeometryInstanceId, lAABB);
// and change camera orientation to fit the box
lCameraManager.fitBox(lAABB, pAnimationDurationInMilliseconds);
Changes the camera position to fit the given AABB to the screen.
The current orientation of the camera and the center of the Box are used to get a virtual line. The camera changes its position to get on that line, its orientation is unchanged. The camera position is set along this line to maximize the drawing of the Box, without any loss of content.
The default animation duration is 350 ms.
This is equivalent to :
fitBox(pAABB,350);
Changes the camera position to fit the given geometry to the screen.
This is equivalent to a fixBox with the AABB of the given geometry.
This is equivalent to :
/**
* Sample to illustrate the CameraManagerInterface fit box.
*/
import { AABB, CameraManagerInterface, DataSessionInterface } from 'generated/documentation/appinfiniteapi';
// created previously
let lCameraManager : CameraManagerInterface;
// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// get box of given instance id (retrieved by picking ?)
const pGeometryInstanceId : number = 10;
// time of animation
const pAnimationDurationInMilliseconds : number = 150;
// create an AABB to get the box
const lAABB : AABB = new AABB();
// get the box
lDataSession.getGeometricAABB(pGeometryInstanceId, lAABB);
// and change camera orientation to fit the box
lCameraManager.fitBox(lAABB, pAnimationDurationInMilliseconds);
Changes the camera position to fit the given geometry to the screen.
This is equivalent to a fixBox with the AABB of the given geometry.
The default animation duration is 350 ms.
This is equivalent to :
fitGeometry(pGeometryInstanceId,350);
Restores the CameraManagerInterface state to the one when toJson was called.
pJson should be the result of a toJson call, and restores the CameraManagerInterface
data (such as location, orientation, coi and reference frame).
true if the json is parsed and if its content is correct.
Gets the current camera controller mode.
The current camera controller mode.
Gets the sensibility of the controller.
The controller sensitivity is 1 by default.
A value greater than 1 increases the speed of the camera, a value lower than 1 decreases the speed of the camera. A zero or negative value is invalid.
Returns the sensitivity of the camera controller in the range ]0,+∞[.
The actual sensitivity of the camera controller.
Gets a Json object witch contains specific settings for the specified camera mode.
A copy of the json based settings for the given controller.
Gets the HTML representation of the navigation cube.
You may change its look and feel.
If no view is set, then returns undefined.
The HTML representation of the navigation cube or undefined if no view is set.
(WebXR) Gets the InfiniteXRReferenceSpace that represents the current orientation / position of the camera.
getXRReferenceFrame can be called with the WebXR api to make some computations on inputs.
/**
* Sample to illustrate using a webxr session.
*/
import { InfiniteEngineInterface, InfiniteEngineInterfaceSignal, InfiniteEvent, InfiniteXRSession, CameraManagerInterfaceSignal, InfiniteXRReferenceSpace } from 'generated/documentation/appinfiniteapi';
// We try to make a screenshot when all data is loaded
// created previously the 3D engine
let lInfiniteEngine: InfiniteEngineInterface;
// the webXR session
let lCurSession : InfiniteXRSession;
// store the XRSession when ready
lInfiniteEngine.addEventListener(
InfiniteEngineInterfaceSignal.XRSessionReady,
(pEvent: InfiniteEvent) : void =>
{
lCurSession = pEvent.attachments;
}
);
// make some fancy things on camera changes
// we may have used InfiniteEngineInterfaceSignal.DisplayDone
// to be called each frame
lInfiniteEngine.getCameraManager().addEventListener(
CameraManagerInterfaceSignal.CameraLocationChanged,
(_pEvent: InfiniteEvent) : void =>
{
if (!lCurSession)
{
return;
}
const lXRRefSpace : InfiniteXRReferenceSpace | undefined = lInfiniteEngine.getCameraManager().getXRReferenceFrame();
if (!lXRRefSpace)
{
return;
}
// make some computations with XRSession inputs
console.log(lCurSession.inputSources.length);
}
);
// bind the 3D rendering to the div (should have been done earlier :) )
lInfiniteEngine.setView(undefined, { type: 'webxr', options: {} });
The current XRReferenceSpace of the camera, or undefined if no XRSession is started (please refer to setView).
Tells if the EventDispatcher has such a callback registered for the given event type.
true if such a listener is installed for the given type of event.
Tells if the navigation cube is enabled (i.e. it responds to user inputs).
The navigation cube is enabled by default.
The navigation cube is an html widget located on the bottom right of the 3d rendering area, which helps the user knowing its current orientation. Information like FRONT, LEFT etc are displayed.
true if the navigation cube is enabled.
Tells if the navigation cube is visible.
The navigation cube is visible by default.
The navigation cube is an html widget located on the bottom right of the 3d rendering area, which helps the user knowing its current orientation. Information like FRONT, LEFT etc are displayed.
true if the navigation cube is visible.
Sets the position of the center of interest (COI), the camera will turn to look at the point without changing its location.
This function also sets the center of interest of the CameraManagerInterface. The default animation duration is 250 ms.
Sets the position of the center of interest (COI), the camera will turn to look at the point without changing its location.
This function also sets the center of interest of the CameraManagerInterface.
The default animation duration is 250 ms.
Sets the position and direction of the camera.
The camera orientation will be set on a virtual plane composed of the given direction and the reference frame of the camera.
Sets the position and direction of the camera.
The camera orientation will be set on a virtual plane composed of the given direction and the reference frame of the camera.
The default animation duration is 350 ms.
This is equivalent to :
moveTo(pPosition,pDirection,350);
Removes a listener from an event type.
If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.
true if the callback was removed else false.
The listener function that gets removed.
The listener object that was used when addEventListener was called.
Removes a listener from an event type.
If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.
true if the callback was removed else false.
The listener function that gets removed.
Removes a listener by its id.
If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.
true if the callback was removed else false.
Resets the camera position to fit the entire scene.
The current orientation of the camera and the center of the DMU are used to get a virtual line. The camera changes its position to get on that line, its orientation is unchanged. The camera position is set along this line to maximize the drawing of the DMU, without any loss of content.
This is actually a fitBox to the AABB of the DMU.
Resets the camera position to fit the entire scene.
The current orientation of the camera and the center of the DMU are used to get a virtual line. The camera changes its position to get on that line, its orientation is unchanged. The camera position is set along this line to maximize the drawing of the DMU, without any loss of content.
The default animation duration is 350 ms.
This is equivalent to :
resetCamera(350);
Sets the camera controller mode to use when processing user inputs.
true if the controller mode has changed.
Sets the camera frame (orientation) of the camera.
Warning, the three vectors must be orthogonal between them.
false if the three vectors do not represent an orthogonal coordinate system or at least one vector is not normalized, else true.
Sets the camera location.
The current orientation of the camera is left unchanged.
Sets the camera location.
The current orientation of the camera is changed according to the current mode. For example, if the controller mode is CCM_ORBIT or CCM_EXAMINE, the camera frame is set according to the current Center Of Interest.
Sets if the CameraManagerInterface should prevent the camera from rotating around the up-axis (rolling).
setConstraintUpAxis is true as default.
true if the call changed the constraint.
Specifies the sensibility of the controller.
The controller sensitivity is 1 by default.
A value greater than 1 will increase the speed of the camera, a value lower than 1 will decrease the speed of the camera. Setting a zero or negative value is invalid.
Returns true if the sensitivity is valid and if the sensitivity was changed.
true if pSensitivity is strictly superior to 1.
Sets the new custom settings for the given controller mode.
true if the settings object is valid and set.
Sets the DMU main vectors.
This will set the orientation of the orientation cube (FRONT, TOP etc) and also sets the up vector of the DMU, which affects the way the camera is managed, since the camera needs a top reference when rotating around an object.
Sets the navigation cube visible.
The navigation cube is visible by default.
The navigation cube is an html widget located on the bottom right of the 3d rendering area, which helps the user knowing its current orientation. Information like FRONT, LEFT etc are displayed.
true else it is hidden.(WebXR) Enables/Disables the default WebXR controllers behavior.
The CameraManagerInterface interface is used to manipulate the camera, and thus to change the viewpoint.
This interface allows to create camera animations and manipulate the orientation cube (a cube that allows the user to see its current orientation).
The CameraManagerInterface also features a way to change the camera manipulator, which is the way user inputs are processed to infer a camera move, by using the CameraControllerMode. The CameraManagerInterface uses the CCM_ORBIT as default. Whenever the camera location and orientation (frame) are changed, CameraManagerInterfaceSignal signals are sent.
This interface also allows to set the camera sensibility, which is the default distance and rotation angle induced by a single user input. This may increase or lower the camera speed. The camera sensitivity is a strictly positive number, that defaults to 1.
If the developer wants to create its own camera manipulator, he may disable the CameraManagerInterface by :
There is no way to create a new CameraManagerInterface, the camera handler is owned and accessed by the InfiniteEngineInterface.
The camera features a perspective projection (pyramid) expressed as frustum values. See ViewFrustum. The frustum values are used to compute the perspective projection of the virtual camera. There are a lot of online courses available if you want to get more information about perspective projections.
The camera is composed of 6 planes : A near and far plane orthogonal to the camera at the distance respectively near and far. Up, Bottom, Right and Left planes go through the camera location and intersect the near plane forming 4 points (see the figure).
The coordinates of these 4 points can be expressed as :
Be P0 the bottom left point, P1 the bottom right point, P2 the top right point, P3 the top left point.
Be D the normalized directional vector of the camera, U the normalized Up vector of the camera, R the normalized right vector of the camera and L the camera location.
P0 = L + Dmin * D + Rmin * R + Umin * U
P1 = L + Dmin * D + Rmax * R + Umin * U
P2 = L + Dmin * D + Rmax * R + Umax * U
P3 = L + Dmin * D + Rmin * R + Umax * U
In cases of symmetrical frustum (usually the case) :
Rmin = -Rmax
Dmin = -Dmax.
The CameraManagerInterface send signals when animations are started and stopped.
The orientation cube allows the user to set some specific orientation by clicking on some area of the cube (orthogonal to a face, straight to an edge, to a vertex of the cube).
See