API / geotoolkit3d / util / Helper / Helper
Utility class providing help functions for 3D scene operations.
Constructors
Accessors
Methods
Methods
▸ getClassName(): string
string
▸ 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.
| Name | Type | Description |
|---|---|---|
point | Vector3 | the 3D point position in business coordinates. |
object | Object3D | the 3D object the point belong to. |
plot | Plot | the 3D plot view, in which the object is rendered. |
Vector3
▸ 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
| Name | Type | Description |
|---|---|---|
point | Vector3 | the 3D point position in business coordinates. |
plot | Plot | the 3D plot view, in which the object is rendered. |
Vector3
▸ 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.
| Name | Type | Description |
|---|---|---|
box | Box3 | the input box |
offset | number | the offset that applies to positions |
number[]
positions
▸ 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.
| Name | Type | Description |
|---|---|---|
object | Object3D<Object3DEventMap> | The object to compute world bounding box of |
Optional filter | FilterCallback | A filter function to ignore some nodes |
Optional alwaysTraverseChildren | boolean | Forces the calculation to traverse children to get the extents of the whole view |
Optional excludeGrid | boolean | When used to update grid model limits, it should not take grid itself into account |
Box3
The computed world bounding box
▸ Static convertToColorProvider(options): ColorProvider
Convert any type of color to DefaultColorProvider
| Name | Type |
|---|---|
options | OptionsWithColor |
the resulting ColorProvider. The given JSON.colorprovider field will also be updated.
▸ 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.
| Name | Type | Description |
|---|---|---|
planarObject | Plane | Slice | The reference object to create a THREE.js Plane from. |
Optional threePlane | Plane | If provided, this THREE Plane will be updated and returned. If null, a new THREE plane is created. |
Optional direction | Vector3 | If 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. |
Plane
▸ 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.
| Name | Type | Description |
|---|---|---|
position | Vector3 | The position to un-project from device to world space. |
camera | Camera | The camera. |
rendererSize | Dimension | The renderer dimension in virtual pixels. |
Optional target | Vector3 | An optional target to store the result. |
Vector3
The resulting position in world space coordinates.
▸ 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).
| Name | Type | Description |
|---|---|---|
object | Object3D<Object3DEventMap> | Group<Object3DEventMap> | Object3D<Object3DEventMap>[] | The object or array of objects to dispose |
void
▸ 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()
| Name | Type |
|---|---|
matsToDispose | Material | Material[] |
void
▸ Static disposeTexture(texture): void
Safely dispose the given texture.
| Name | Type |
|---|---|
texture | Texture |
void
▸ 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.
| Name | Type |
|---|---|
box | Box3 |
number
▸ Static getClassName(): string
string
▸ 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.
| Name | Type | Description |
|---|---|---|
node | Object3D<Object3DEventMap> | The node to compute bounding box of |
target | Box3 | The target Box3 |
Optional options | NodeBoundingBoxOptions | Options for Helper.getNodeBoundingBox method |
Boolean
true upon success, false upon failure
▸ Static getWGS84DefaultExtent(): Box2
Returns WGS84 full extent (default model limits for map)
Box2
▸ 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.
| Name | Type | Description |
|---|---|---|
verticesPosition | number[] | TypedArray | ReservoirAttributes | the box positions, in a contiguous [x,y,z...] array or split in 3 BufferAttributes. |
boolean
if the triangles of the given boxes geometries are facing inward.
▸ 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);| Name | Type | Description |
|---|---|---|
localPoint | Vector3 | the 3D point position in local coordinates. |
object | Object3D | the 3D object the point belong to. |
plot | Plot | the 3D plot view, in which the object is rendered. |
Vector3
▸ 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.
| Name | Type |
|---|---|
mesh | Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap> |
void
▸ 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
| Name | Type | Description |
|---|---|---|
point | Vector3 | the 3D point position in world coordinates. |
plot | Plot | the 3D plot view, in which the object is rendered. |
Vector3
▸ 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.
| Name | Type | Description |
|---|---|---|
position | Vector3 | The position to project |
camera | Camera | The camera |
rendererSize | Dimension | The renderer dimension in virtual pixels |
Optional target | Vector3 | An optional target to store the result |
Optional matrixWorld | Matrix4 | The world transform matrix of this point |
Vector3
The z is the 'depth' in the screen
▸ 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.
| Name | Type | Description |
|---|---|---|
position | Vector3 | The position to project |
camera | Camera | The camera |
rendererSize | Dimension | The renderer dimension in virtual pixels |
Optional target | Vector2 | An optional target to store the result |
Vector2
the device position as a Vector2