Namespace: three

Mapspace.util. three

This namespace contains definitions of static functions for common Three.js operations wih geometries.

Source:
mapspace/util/three/three.jsdoc

Methods


<static> convertCoordsToLine(coords, lines)

Converts an array of Mapspace.Coordinate to a THREE.Line.

Parameters:
Name Type Argument Description
coords Array.<Mapspace.Coordinate>

Coordinates in local coordinates.

lines Array.<THREE.Line> <nullable>

An optional array to send the new line.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Line

<static> convertCoordsToRedefinitionObject(coords, index, resolution)

Convert an array of Mapspace.Coordinate to a THREE.Object3D that is a group of labels to show that the points are redefinable points.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

Coordinates in local coordinates. Local coord means relative to real orientation of the camera when the image was taken, so it takes account of the angle rotations of the camera. It also means relative to a XYZ planes where -Z is looking north, +X is looking east and +Y is looking cenit. This are the axis commonly used in WebGL.

index number

A number to use for the label of the coordinates. Use -1 if the number must be the order of the coordinate in the array.

resolution number

The resolution, meters per pixel.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> convertGeometryToFlashObject(geometry, materialDef)

Converts a ol.geom.Geometry to a THREE.Object3D that is suitable for be shown as a flashing object, which means that the object can be highlighted in some way.

Parameters:
Name Type Description
geometry ol.geom.Geometry

Geometry with coordinates in local coordinates. Local coord means relative to real orientation of the camera when the image was taken, so it takes account of the angle rotations of the camera. It also means relative to a XYZ planes where -Z is looking north, +X is looking east and +Y is looking cenit. This are the axis commonly used in WebGL.

materialDef Mapspace.MaterialDefinition

The material definition to apply to the resulting 3D object.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> convertGeometryToObject(geometry, materialDef)

Converts a ol.geom.Geometry to a THREE.Object3D. It returns null if geometry is undefined.

Parameters:
Name Type Description
geometry ol.geom.Geometry

Geometry with coordinates in local coordinates. Local coord means relative to real orientation of the camera when the image was taken, so it takes account of the angle rotations of the camera. It also means relative to a XYZ planes where -Z is looking north, +X is looking east and +Y is looking cenit. This are the axis commonly used in WebGL.

materialDef Mapspace.MaterialDefinition

The material definition to apply to the resulting 3D object.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> convertLineStringToTube(geom, materialDef)

Converts a ol.geom.LineString in a THREE.Object3D using a THREE.TubeGeometry. This geometry is useful for highlighting a linestring, making it having a shadow or glow around it.

Parameters:
Name Type Description
geom ol.geom.LineString | ol.geom.LinearRing

LineString or LinearRing.

materialDef Mapspace.MaterialDefinition

The material definition to apply to the resulting 3D object.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> convertStyleToMaterialDefinition(style)

Converts a ol.style.Style to a Mapspace.MaterialDefinition.

Parameters:
Name Type Description
style ol.style.Style

OpenLayers style.

Source:
mapspace/util/three/util.js
Returns:
Type
Mapspace.MaterialDefinition

<static> convertSVGIconToObject(svg, w, h, scale)

Converts a SVG icon to a 3D object using a THREE.Group. It requires a valid SVG formatted text.

Parameters:
Name Type Argument Description
svg string

The SVG formatted text.

w number

Width of SVG in pixels.

h number

Height of SVG in pixels.

scale number <nullable>

Scale to apply to returned object. If SVG is defined with default units (pixels) one pixel is converted to one meter. To avoid large SVG icons in the scene the passed scale will be used or 1 if no scale is passed.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Group

<static> convertTextToObject(text, resolution [, fontColor] [, backgroundColor], selected, align)

Converts a text to a 3D popup using a THREE.Mesh. If requires that the text is HTML formatted with

tags for each line and tags for bold text. For example: '

Lon: 10.742097

Lat: 59.911818

' would be a valid text but not 'Elevation: 101m'. The correct for this last one would be '

Elevation: 101m

'.

Parameters:
Name Type Argument Description
text string

The text.

resolution number

The resolution, meters per pixel.

fontColor string <optional>

Optional color for the font. Defaults to 'rgba(0,0,0,1)'.

backgroundColor boolean | string <optional>

Optional color for a background. If it is false then no background is rendered. If it is a string then it will be the background color. Defaults to 'rgba(255,255,255,1)'.

selected boolean <nullable>

Optional param for style the popup as selected or not. By default is false.

align boolean <nullable>

Optional param for align the text. By default is true. If false then the text is aligned to the right.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> convertToCoords2D(coords, quaternion)

Converts an array of three or more coplanar 3D local coordinates to an array of 2D local coordinates in XY plane, with origin in the first coordinate and X axis increasing towards the second coordinate and Y upwards. The returned array only has two values for each coordinate, while input coordinates must have three values. It can return an optional quaternion to rotate resulting coordinates to original ones.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

Array of three or more coplanar 3D coordinates with three values per coordinate.

quaternion THREE.Quaternion | undefined

Optional THREE.Quaternion.

Source:
mapspace/util/three/util.js
Returns:

Array of 2D coordinates.

Type
Array.<Mapspace.Coordinate>

<static> coplanarizeCoordinates(coords, coplanarity, ring)

Returns a new array of local coordinates from given ones ensuring that coplanarity constraints are followed in the returned array, stopping the array in the first coordinate that cannot be forced to comply with, excluding it and above from the result. Local coordinate means relative to real orientation of the camera when the image was taken, so it takes account of the rotation angles of the camera. It also means relative to a XYZ planes where -Z is looking north, +X is looking east and +Y is looking cenit. This are the axis commonly used in WebGL.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

The local coordinates.

coplanarity Mapspace.CoplanarityType

If points must be enforced to be coplanar and what type of coplanarity to enforce. To ignore this use NONE. To enforce that all points are in a vertical plane, use VERTICAL. In this case the first two coordinates that are not vertically overlapped will be used to define a plane. To enforce that all points are in a horizontal plane, use HORIZONTAL. In this case the first point will define a plane using its height. To enforce any other coplanarity, use ANY. In this case the first three not-coincident points will be used to define a plane.

ring boolean

If the coordinates are a linear ring, so last vertex must be ensured to be the same as first one.

Source:
mapspace/util/three/util.js
Returns:

A new local coordinates but modified.

Type
Array.<Mapspace.Coordinate>

<static> coplanarizePolygons(geometry)

Returns a new fixed geometry with the polygons in it coplanarized.

Parameters:
Name Type Description
geometry ol.geom.Geometry

The input geometry.

Source:
mapspace/util/three/util.js
Returns:

The returned geometry.

Type
ol.geom.Geometry

<static> createRoundedRectShape(width, height, radius)

Creates a rounded rectangular THREE.Shape object.

Parameters:
Name Type Description
width number

Width of the shape.

height number

Height of the shape.

radius number

Radius of the borders in the shape. Must be smaller that width and height.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Shape

<static> createWrappedObject(obj)

Creates a new THREE.Object3D that wraps another one. The new object is located at position of the passed object and the passed object is relocated to [0,0,0] so the same location is maintained.

Parameters:
Name Type Description
obj THREE.Object3D

Object to wrap.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Object3D

<static> fitPlaneToCoordinates(coords)

Calculates the best plane that fits an array of coordinates.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

The local coordinates.

Source:
mapspace/util/three/util.js
Returns:
Type
THREE.Plane

<static> getArea(coordinates)

Calculates geodetic area of an array of coordinates. Coordinates are in Mercator with elevation.

Parameters:
Name Type Description
coordinates Array.<Mapspace.Coordinate>

Coordinates in Mercator with elevation.

Source:
mapspace/util/three/util.js
Returns:
Type
number

<static> getArea3D(coords)

Calculates the area of a ring defined by the given coordinates. Coordinates must be cartesian 3D coordinates and must be coplanar. Coplanarity is not checked.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

Coordinates.

Source:
mapspace/util/three/util.js
Returns:
Type
number

<static> getCenterPoint(linearRing)

Returns a center point of a LinearRing. The LinearRing is expected to have a stride of 3 (3D coordinates).

Parameters:
Name Type Description
linearRing ol.geom.LinearRing

LinearRing. Coordinates are expected to be Local coordinates. See Mapspace.util.three#convertGeometryToObject.

Source:
mapspace/util/three/util.js
Returns:
Type
ol.Coordinate

<static> getDistance(coordinates)

Calculates distance of an array of coordinates. Coordinates are in Mercator with elevation.

Parameters:
Name Type Description
coordinates Array.<Mapspace.Coordinate>

Coordinates in Mercator with elevation.

Source:
mapspace/util/three/util.js
Returns:

An array containing three values with full distance, horizontal distance and vertical distance.

Type
Array.<number>

<static> getLength(lineString)

Returns the length of a LineString. The LineString is expected to have a stride of 3 (3D coordinates).

Parameters:
Name Type Description
lineString ol.geom.LineString

LineString.

Source:
mapspace/util/three/util.js
Returns:
Type
number

<static> getMeasurementLabelPosition(geometry, type, pointSize)

Gets the 3d coordinate to locate a measurement label given the geometry of the measurement and the type of measurement.

Parameters:
Name Type Argument Description
geometry ol.geom.Geometry

Geometry. Coordinates are expected to be Local coordinates. See Mapspace.util.three#convertGeometryToObject.

type Mapspace.MeasurementType

Type of measurement.

pointSize number <nullable>

An optional size for points.

Source:
mapspace/util/three/util.js
Returns:
Type
Mapspace.Coordinate

<static> getMidpoint(lineString)

Returns the mid point of a LineString. The LineString is expected to have a stride of 3 (3D coordinates).

Parameters:
Name Type Description
lineString ol.geom.LineString

LineString. Coordinates are expected to be Local coordinates. See Mapspace.util.three#convertGeometryToObject.

Source:
mapspace/util/three/util.js
Returns:
Type
ol.Coordinate

<static> getVerticalArea(coordinates)

Return the area of an array of vertical and coplanar coordinates. The first and last coordinate must be the same. Inspired by: http://geomalgorithms.com/a01-_area.html

Parameters:
Name Type Description
coordinates Array.<Mapspace.Coordinate>

The coordinates.

Source:
mapspace/util/three/util.js
Returns:

The area.

Type
number

<static> getVerticalCenterPoint(linearRing)

Returns a center point of a vertical LinearRing. The LinearRing is expected to have a stride of 3 (3D coordinates).

Parameters:
Name Type Description
linearRing ol.geom.LinearRing

LinearRing. Coordinates are expected to be Local coordinates. See Mapspace.util.three#convertGeometryToObject.

Source:
mapspace/util/three/util.js
Returns:
Type
ol.Coordinate

<static> normalizeCoords(coords, isVertical)

Normalizes an array of local coordinates and return it or null if coords self-intersect.

Parameters:
Name Type Description
coords Array.<Mapspace.Coordinate>

The array of local coordinates.

isVertical boolan

If coordinates must be vertical.

Source:
mapspace/util/three/util.js
Returns:
Type
Array.<Mapspace.Coordinate> | null

<static> setObjectAsSelected(obj, selected)

Modifies a THREE.Object3D and its subobjects to show it as a selected object or not. Any Object3D in the scene that is suitable for selection has three subobjects:

  • first an Object3D with the geometry not selected,
  • second an optional Object3D (a popup) with a value Mapspace.css.CLASS_MEASUREMENT_TOOLTIP or Mapspace.css.CLASS_ANNOTATION_TOOLTIP in userData,
  • third an optional Object3D with the geometry but in selected mode.
Parameters:
Name Type Description
obj THREE.Object3D

The 3D object to modify.

selected boolean

If the object must be shown as selected or not.

Source:
mapspace/util/three/util.js

<static> toLocalGeometry(feature, image, localCoords, coplanarize)

Returns a new geometry but transformed from Mercator Spheric coordinates to local coordinates (these are the coordinates that can be drawn in a Street viewer).

Parameters:
Name Type Argument Description
feature ol.Feature

Feature with geometry in Mercator Spheric coordinates.

image Mapspace.street.Image

The image object to use for coordinate conversions. If no image provided or image has not transform functions initialized then this function returns null.

localCoords Array.<ol.Coordinate> <nullable>

An optional array where store the coordinates of the geometry in local coordinates.

coplanarize boolean <nullable>

An optional boolean. If true any polygon geometry is coplanarized using the best plane that fits each polygon. By default is false.

Source:
mapspace/util/three/util.js
Returns:

The geometry in local coordinates.

Type
ol.geom.Geometry

<static> toMercatorGeometry(geometry, image)

Returns a new geometry but transformed from local coordinates to Mercator Spheric coordinates, that are the ones stored in features.

Parameters:
Name Type Description
geometry ol.geom.Geometry

Geometry.

image Mapspace.street.Image

The image object to use for coordinate conversions. If no image provided or image has not transform functions initialized then this function returns null.

Source:
mapspace/util/three/util.js
Returns:

The geometry in Mercator Spheric coordinates.

Type
ol.geom.Geometry

<static> updateFeature(feature, layer, image, sceneManager, opt_options)

Updates a ol.Feature with a new observable property called Mapspace.STREET_GEOMETRY_NAME saving in it a new THREE.Object3D object with the default geometry transformed from world coordinates in 'EPSG:3857' Spherical Mercator to local coordinates of the provided street image. If default geometry has no Z values or Z values are zeros (that usually is a default value for non Z values), then a default Z value is added at the ground level for the Object3D (z = -cameraHeight in local coords).

Parameters:
Name Type Argument Description
feature ol.Feature

Input feature. Default 'EPSG:3857' geometry is stored in the observable property Mapspace.GEOMETRY_NAME. New local coordinate object is stored in an observable property called Mapspace.STREET_GEOMETRY_NAME.

layer Mapspace.layer.Vector <nullable>

The layer the feature belongs to or null if it is a temporary feature.

image Mapspace.street.Image

The image object to use for coordinate conversions. If no image provided or image has not transform functions initialized then this function does nothing.

sceneManager Mapspace.street.threejs.SceneManager

Scene Manager.

opt_options Object <nullable>

An optional object containing several options.

Properties
Name Type Argument Description
selected boolean <optional>

A boolean indicating if the feature is selected or not. By default is false.

hide boolean <optional>

A boolean indicating if the main geometry of the feature must be hidden or not. By default is false.

redefine boolean <optional>

A boolean indicating if the feature must show redefinable points in each vertex. This points are clickable points that can be selected to do refinement of the geometry. By default is false.

redefineIndex number <optional>

A number to show when redefine is true and the feature is a Point instead of the usual number 1 that should appear. By default is -1 meaning no number must be used.

materialDefinition Mapspace.MaterialDefinition <nullable>

A material definition to use instead of the one returned from the layer.

Source:
mapspace/util/three/util.js