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.Coordinateto aTHREE.Line.Parameters:
Name Type Argument Description coordsArray.<Mapspace.Coordinate> Coordinates in local coordinates.
linesArray.<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.Coordinateto aTHREE.Object3Dthat is a group of labels to show that the points are redefinable points.Parameters:
Name Type Description coordsArray.<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.
indexnumber 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.
resolutionnumber The resolution, meters per pixel.
- Source:
- mapspace/util/three/util.js
Returns:
- Type
- THREE.Object3D
-
<static> convertGeometryToFlashObject(geometry, materialDef)
-
Converts a
ol.geom.Geometryto aTHREE.Object3Dthat is suitable for be shown as a flashing object, which means that the object can be highlighted in some way.Parameters:
Name Type Description geometryol.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.
materialDefMapspace.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.Geometryto aTHREE.Object3D. It returns null if geometry is undefined.Parameters:
Name Type Description geometryol.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.
materialDefMapspace.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.LineStringin aTHREE.Object3Dusing aTHREE.TubeGeometry. This geometry is useful for highlighting a linestring, making it having a shadow or glow around it.Parameters:
Name Type Description geomol.geom.LineString | ol.geom.LinearRing LineString or LinearRing.
materialDefMapspace.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.Styleto aMapspace.MaterialDefinition.Parameters:
Name Type Description styleol.style.Style OpenLayers style.
- Source:
- mapspace/util/three/util.js
Returns:
-
<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 svgstring The SVG formatted text.
wnumber Width of SVG in pixels.
hnumber Height of SVG in pixels.
scalenumber <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 withtags 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 textstring The text.
resolutionnumber The resolution, meters per pixel.
fontColorstring <optional>
Optional color for the font. Defaults to 'rgba(0,0,0,1)'.
backgroundColorboolean | 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)'.
selectedboolean <nullable>
Optional param for style the popup as selected or not. By default is false.
alignboolean <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 coordsArray.<Mapspace.Coordinate> Array of three or more coplanar 3D coordinates with three values per coordinate.
quaternionTHREE.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 coordsArray.<Mapspace.Coordinate> The local coordinates.
coplanarityMapspace.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, useVERTICAL. 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, useHORIZONTAL. 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.ringboolean 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 geometryol.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 widthnumber Width of the shape.
heightnumber Height of the shape.
radiusnumber 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.Object3Dthat 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 objTHREE.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 coordsArray.<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 coordinatesArray.<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 coordsArray.<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 linearRingol.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 coordinatesArray.<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 lineStringol.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 geometryol.geom.Geometry Geometry. Coordinates are expected to be Local coordinates. See
Mapspace.util.three#convertGeometryToObject.typeMapspace.MeasurementType Type of measurement.
pointSizenumber <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 lineStringol.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 coordinatesArray.<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 linearRingol.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 coordsArray.<Mapspace.Coordinate> The array of local coordinates.
isVerticalboolan If coordinates must be vertical.
- Source:
- mapspace/util/three/util.js
Returns:
- Type
- Array.<Mapspace.Coordinate> | null
-
<static> setObjectAsSelected(obj, selected)
-
Modifies a
THREE.Object3Dand 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_TOOLTIPorMapspace.css.CLASS_ANNOTATION_TOOLTIPin userData, - third an optional Object3D with the geometry but in selected mode.
Parameters:
Name Type Description objTHREE.Object3D The 3D object to modify.
selectedboolean 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 featureol.Feature Feature with geometry in Mercator Spheric coordinates.
imageMapspace.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.
localCoordsArray.<ol.Coordinate> <nullable>
An optional array where store the coordinates of the geometry in local coordinates.
coplanarizeboolean <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 geometryol.geom.Geometry Geometry.
imageMapspace.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.Featurewith a new observable property calledMapspace.STREET_GEOMETRY_NAMEsaving in it a newTHREE.Object3Dobject 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 featureol.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 calledMapspace.STREET_GEOMETRY_NAME.layerMapspace.layer.Vector <nullable>
The layer the feature belongs to or null if it is a temporary feature.
imageMapspace.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.
sceneManagerMapspace.street.threejs.SceneManager Scene Manager.
opt_optionsObject <nullable>
An optional object containing several options.
Properties
Name Type Argument Description selectedboolean <optional>
A boolean indicating if the feature is selected or not. By default is false.
hideboolean <optional>
A boolean indicating if the main geometry of the feature must be hidden or not. By default is false.
redefineboolean <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.
redefineIndexnumber <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.
materialDefinitionMapspace.MaterialDefinition <nullable>
A material definition to use instead of the one returned from the layer.
- Source:
- mapspace/util/three/util.js