Last updated

API / geotoolkit3d / util / Helper / Helper

Class: Helper

util.Helper.Helper

Utility class providing help functions for 3D scene operations.

Table of contents

Constructors
Accessors
Methods

Contents

Constructors

new Helper()

new Helper()

Accessors

BBOX_EPSILON

Static get BBOX_EPSILON(): number

Returns

number

Methods

getClassName

getClassName(): string

Returns

string


businessToLocal

Static businessToLocal(point, object, plot): Vector3

Convert the given 3D point from "business" coordinates into local coordinates. For more information see Helper#localToBusiness(). The given Vector3 is modified in the process, and is returned for method-chaining.

Parameters

Name Type Description
pointVector3the 3D point position in business coordinates.
objectObject3Dthe 3D object the point belong to.
plotPlotthe 3D plot view, in which the object is rendered.

Returns

Vector3


businessToWorld

Static businessToWorld(point, plot): Vector3

Convert the given 3D point from "business" coordinates into world coordinates. Business coordinates are world coordinates minus the Plot's scale applied.
The given Vector3 is modified in the process, and is returned for method-chaining.
For more informations on transformations, see https://threejs.org/docs/#manual/en/introduction/Matrix-transformations

Parameters

Name Type Description
pointVector3the 3D point position in business coordinates.
plotPlotthe 3D plot view, in which the object is rendered.

Returns

Vector3


computeBoxPositions

Static computeBoxPositions(box, offset): number[]

Returns position in an array by given THREE.Box3
The positions are repeating triangles in order of x,y,z
If an offset is provided, the resulting positions will be multiplied by the offset.

Parameters

Name Type Description
boxBox3the input box
offsetnumberthe offset that applies to positions

Returns

number[]

positions


computeWorldBoundingBox

Static computeWorldBoundingBox(object, filter?, alwaysTraverseChildren?, excludeGrid?): Box3

Computes the world bounding box of the given object and its children.
This function uses geometries boundingBox and matrixWold to do so.
Note that this function uses all nodes by default (even the not visible ones)

Deprecated

since 5.0, because this method would return the result only in world coordinates without reversing the Plot's scale. Please use Helper.getNodeBoundingBox instead.

Parameters

Name Type Description
objectObject3D<Object3DEventMap>The object to compute world bounding box of
Optional filterFilterCallbackA filter function to ignore some nodes
Optional alwaysTraverseChildrenbooleanForces the calculation to traverse children to get the extents of the whole view
Optional excludeGridbooleanWhen used to update grid model limits, it should not take grid itself into account

Returns

Box3

The computed world bounding box


convertToColorProvider

Static convertToColorProvider(options): ColorProvider

Convert any type of color to DefaultColorProvider

Parameters

Name Type
optionsOptionsWithColor

Returns

ColorProvider

the resulting ColorProvider. The given JSON.colorprovider field will also be updated.


createUpdateThreePlane

Static createUpdateThreePlane(planarObject, threePlane?, direction?): Plane

Create or update a THREE.js Plane based on the provided planar object, like a Slice or a Plane. Because planar objects are actually quads, it might be more accurate to say this method will make a THREE.js Plane that 'contains' the (quad) plane.

Parameters

Name Type Description
planarObjectPlane | SliceThe reference object to create a THREE.js Plane from.
Optional threePlanePlaneIf provided, this THREE Plane will be updated and returned. If null, a new THREE plane is created.
Optional directionVector3If provided, the created/updated plane will face that direction. Usefull when used for clipping. If this direction is perpendicular to the reference plane, this will result in undefined behavior.

Returns

Plane


deviceToWorld

Static deviceToWorld(position, camera, rendererSize, target?): Vector3

Compute the world coordinates for the given device coordinates (require a device coordinate with depth).
This function will compute the un-projection of the given position using the given parameters.

Parameters

Name Type Description
positionVector3The position to un-project from device to world space.
cameraCameraThe camera.
rendererSizeDimensionThe renderer dimension in virtual pixels.
Optional targetVector3An optional target to store the result.

Returns

Vector3

The resulting position in world space coordinates.


dispose

Static dispose(object): void

Dispose an object's WebGL resources and all its children recursively.
The sequence in witch the dispose steps will occur is:

  • disposeResources : If the object has any specific resources to dispose, the disposeResources() function will be called.
  • dispose children: Calls Helper.dispose() on the children of this object.
  • dispose object: If the object has any custom implementation of the dispose function.
  • remove object: Removes the object from its parent.
  • dispose geometry: Disposes the geometry, releasing the memory used on the graphic card.
  • dispose material: Disposes the material, releasing the memory used on the graphic card.
    • dispose texture: Disposes the texture stored in the material (if any).

Parameters

Name Type Description
objectObject3D<Object3DEventMap> | Group<Object3DEventMap> | Object3D<Object3DEventMap>[]The object or array of objects to dispose

Returns

void


disposeMaterial

Static disposeMaterial(matsToDispose): void

Dispose material as well as map and images within it. Specifically meant for THREE.Material and nothing else. Warning, if your Material share a texture with another one, this will dispose both: only use when the material's texture are no longer used. If disposing a Mesh use util.Helper.dispose()

Parameters

Name Type
matsToDisposeMaterial | Material[]

Returns

void


disposeTexture

Static disposeTexture(texture): void

Safely dispose the given texture.

Parameters

Name Type
textureTexture

Returns

void


getBoxSize

Static getBoxSize(box): number

Return the diagonal size of the given THREE.Box3 The size returned is the distance between the Box min and max points. If the Box is empty (min and max are set to infinity) or if it contains NaN or the box is null, it will return 0.

Parameters

Name Type
boxBox3

Returns

number


getClassName

Static getClassName(): string

Returns

string


getNodeBoundingBox

Static getNodeBoundingBox(node, target, options?): Boolean

Computes the bounding box of the given node based on NodeBoundingBoxOptions.
This function uses geometries boundingBox and matrixWold to do so.
Note that this function uses all nodes by default (even the not visible ones)
By default, it returns the bounding box in Business coordinates, which has inverse plot scale applied.
To get the bounding box in world coordinate, set options.coordinate to Coordinate.World.

Parameters

Name Type Description
nodeObject3D<Object3DEventMap>The node to compute bounding box of
targetBox3The target Box3
Optional optionsNodeBoundingBoxOptionsOptions for Helper.getNodeBoundingBox method

Returns

Boolean

true upon success, false upon failure


getWGS84DefaultExtent

Static getWGS84DefaultExtent(): Box2

Returns WGS84 full extent (default model limits for map)

Returns

Box2


isTriangleFacingInward

Static isTriangleFacingInward(verticesPosition): boolean

Determine the orientation of triangles in a box-like shape, i.e. a reservoir cell.
If triangles are facing inward the box, then we only need to render back face (THREE.BackFace). Otherwise, we render the front face (THREE.FrontFace).
In some cases, ReservoirGrid cells can be provided with inverted vertex order, which result in inverted triangles. By deducing the vertex order, we can avoid rendering both triangle faces and improve performances.

Parameters

Name Type Description
verticesPositionnumber[] | TypedArray | ReservoirAttributesthe box positions, in a contiguous [x,y,z...] array or split in 3 BufferAttributes.

Returns

boolean

if the triangles of the given boxes geometries are facing inward.


localToBusiness

Static localToBusiness(localPoint, object, plot): Vector3

Convert the given 3D point of the given 3D object from local coordinates into "business" coordinates. Business coordinates are world coordinates minus the Plot's scale applied.
The given Vector3 is modified in the process, and is returned for method-chaining.
For more informations on transformations, see https://threejs.org/docs/#manual/en/introduction/Matrix-transformations

Example

// How to retrieve a 3D Surface 50th triangle points, and convert them to business coordinates:
import {Vector3} from 'three';
import {Surface} from 'geotoolkit3d.scene.surface.Surface';
import {Helper} from 'geotoolkit3d.util.Helper';
// ...
const surface = new Surface({
data: {
surface: surfaceData
}
});
plot.getRoot().add(surface);
// ...
const attributes = surfaceData.getAttributes();
const idx = attributes.index.getX(50 * 3);
const buffer = attributes.position;
const p1 = new Vector3().fromBufferAttribute(buffer, idx);
const p2 = new Vector3().fromBufferAttribute(buffer, idx + 1);
const p3 = new Vector3().fromBufferAttribute(buffer, idx + 2);
// Now we transform them from local to 'business' world position
Helper.localToBusiness(p1, surface, plot);
Helper.localToBusiness(p2, surface, plot);
Helper.localToBusiness(p3, surface, plot);

Parameters

Name Type Description
localPointVector3the 3D point position in local coordinates.
objectObject3Dthe 3D object the point belong to.
plotPlotthe 3D plot view, in which the object is rendered.

Returns

Vector3


translateVerticesToOrigin

Static translateVerticesToOrigin(mesh): void

Re-center the vertices of this mesh around the scene origin (0, 0, 0) by translating them by the vector: meshCenter -> origin.
The vertices world coordinates remain unaffected by applying this translation on the object local matrix instead.
This process increase accuracy in intersection and other vertex conversions, by reducing the individual vertices coordinate values.
This is especially effective in scene very far from the origin.
The mesh position, and mesh geometry local bounding box are updated in the process.

Parameters

Name Type
meshMesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>

Returns

void


worldToBusiness

Static worldToBusiness(point, plot): Vector3

Convert the given 3D point from world coordinates into "business" coordinates. Business coordinates are world coordinates minus the Plot's scale applied.
The given Vector3 is modified in the process, and is returned for method-chaining.
For more informations on transformations, see https://threejs.org/docs/#manual/en/introduction/Matrix-transformations

Parameters

Name Type Description
pointVector3the 3D point position in world coordinates.
plotPlotthe 3D plot view, in which the object is rendered.

Returns

Vector3


worldToDevice

Static worldToDevice(position, camera, rendererSize, target?, matrixWorld?): Vector3

Compute the device coordinates for the given world coordinates.
This function will compute the projection of the given position using the given parameters.

Parameters

Name Type Description
positionVector3The position to project
cameraCameraThe camera
rendererSizeDimensionThe renderer dimension in virtual pixels
Optional targetVector3An optional target to store the result
Optional matrixWorldMatrix4The world transform matrix of this point

Returns

Vector3

The z is the 'depth' in the screen


worldToDevice2D

Static worldToDevice2D(position, camera, rendererSize, target?): Vector2

Compute the device coordinates for the given world coordinates.
This function will compute the projection of the given position using the given parameters.

Parameters

Name Type Description
positionVector3The position to project
cameraCameraThe camera
rendererSizeDimensionThe renderer dimension in virtual pixels
Optional targetVector2An optional target to store the result

Returns

Vector2

the device position as a Vector2