Unigine.WorldSplineGraph Class
Inherits: | Node |
This class is used to generate specified nodes (called source nodes) along a spline graph.
A world spline graph consists of segments and has a list of source nodes (currently ObjectMeshStatic only) that can be stretched or tiled along the segments. Each WorldSplineGraph node can have a single or a set of source nodes. An arbitrary number of WorldSplineGraph nodes can be added to the scene.
WorldSplineGraph has the following features:
- Vertices and segments of the spline graph are managed via the SplineGraph class.
- 3 modes are supported:
- stretching: source nodes are stretched along the spline segment.
- tiling: source nodes are duplicated along the spline segment.
- adaptive - represents a combination of the first two: source nodes are duplicated along the spline segment, but the length of each node (stretching) is determined by the curvature of the corresponding part of the segment. Thus, long nodes are placed along the straight parts of segments, while short ones - along the curved parts, providing a reasonable balance between the plausible look and performance.
- Forward axis selection for stretching/tiling source nodes.
See Also
See the following C++ API samples to learn how to manage the WorldSplineGraph class:
<UnigineSDK>/data/samples/worlds/world_spline_graph_00 featuring:
- Creation of a WorldSplineGraph node from a SplineGraph file.
- Generation of geometry along the graph segments in stretching mode.
<UnigineSDK>/data/samples/worlds/world_spline_graph_01 featuring:
- Creation of a WorldSplineGraph node from a SplineGraph file.
- Generation of geometry along the graph segments in tiling mode.
WorldSplineGraph Class
Members
static WorldSplineGraph()
Default constructor. Creates an empty world spline graph.static WorldSplineGraph(string name)
Constructor. Creates an empty world spline graph with a given name.Arguments
- string name - World spline graph name.
static WorldSplineGraph cast(Node node)
Casts a WorldSplineGraph out of the Node instance.Arguments
- Node node - Node instance.
Return value
WorldSplineGraph instance.int getNumPoints()
Returns the total number of points in the world spline graph.Return value
Number of points.int getNumSourceNodes()
Returns the total number of source nodes in the list.Return value
Number of source nodes.int getNumSegmentNodes()
Returns the total number of nodes assigned to the segments of the world spline graph.Return value
Number of nodes assigned to the segments of the world spline graph.int getNumSegments()
Returns the total number of segments in the world spline graph.Return value
Number of segments.vec3 calcSegmentPoint(int index, float t)
Returns the coordinates of the point on the given segment.Arguments
- int index - Segment index.
- float t - Position of the point on the segment, in increments of the segment's length normalized to 1.
Return value
Coordinates of the point on the given segment.vec3 calcSegmentTangent(int index, float t)
Returns the tangent coordinates for the point on the given segment.Arguments
- int index - Segment index.
- float t - Position of the point on the segment, in increments of the segment's length normalized to 1.
Return value
Tangent coordinates for the point on the given segment.vec3 calcSegmentUpVector(int index, float t)
Returns the "up" vector coordinates for the point on the given segment.Arguments
- int index - Segment index.
- float t - Position of the point on the segment, in increments of the segment's length normalized to 1.
Return value
"Up" vector coordinates for the point on the given segment.void setPoint(int index, vec3 point)
Sets the coordinates of the point with a given index.Arguments
- int index - Point index.
- vec3 point - Point coordinates.
vec3 getPoint(int index)
Returns the coordinates of the point with a given index.Arguments
- int index - Point index.
Return value
Point coordinates.int addPoint(vec3 point)
Adds a point with specified coordinates to the spline graph.Arguments
- vec3 point - Point coordinates.
Return value
Current number of points in the spline graph.void removePoint(int index, int merge = 0)
Removes a point with a given index from the spline graph.Arguments
- int index - Point index.
- int merge - Merge flag. When there are two segments attached to the point, use 1 to merge these segments into one; 0 removes all segments attached to the point (by default).
void splitPoint(int index)
Splits the point with the specified index into N points, where N is the number of segments attached to the point. The number of points in the graph shall increase by N-1. All new points will be attached to the corresponding segments.Arguments
- int index - Point index.
void weldPoints(int[] indices)
Merges all points with given indices into one.All common segments between these points shall be removed. All points with given indices are removed from the graph, except for the one having the minimum index value, all segments shall be attached to this point. Resulting point shall be moved to the position of the first point in the given array.
Arguments
- int[] indices - Array containing indices of points to be merged into one.
void insertPointToSegment(int index, float new_point_t)
Inserts a new point into the given segment with the specified offset from the starting point.Arguments
- int index - Segment index.
- float new_point_t - Offset of the new point to be added from the starting point of the segment in the range [0.0f, 1.0f].
void getPointSegmentsIndices(int index, int[] indices)
Retrieves indices of all segments attached to the specified point and puts them to the given index buffer.Arguments
- int index - Point index.
- int[] indices - Index buffer to which segment indices will be added.
float getLength(int index)
Retuns the length of the segment with a given index.Arguments
- int index - Segment index.
Return value
Segment length.int addSegment(int start_index, vec3 start_tangent, vec3 start_up, int end_index, vec3 end_tangent, vec3 end_up)
Adds a segment to the spline graph.Arguments
- int start_index - Start point index.
- vec3 start_tangent - Start point tangent coordinates.
- vec3 start_up - Start point "up" vector coordinates.
- int end_index - End point index.
- vec3 end_tangent - End point tangent coordinates.
- vec3 end_up - End point "up" vector coordinates.
Return value
Number of segments in the spline graph if a segment was addes successfully; otherwise, -1void removeSegment(int index, int with_points = 0)
Removes the segment with a given index.Arguments
- int index - Segment index.
- int with_points - Use 1 to remove segment with its starting and ending points, or 0 to remove the segment only.Points will be removed only in case if they do not belong to other segments. After removal, the last element of the vector of spline graph segments shall be moved to the position of the one removed.
void setSegmentEndPoint(int index, vec3 point)
Sets the coordinates of the end point for the segment with a given index.Arguments
- int index - Segment index.
- vec3 point - Segment end point coordinates to be set.
vec3 getSegmentEndPoint(int index)
Returns the coordinates of the end point for the segment with a given index.Arguments
- int index - Segment index.
Return value
Segment end point coordinates.int getSegmentEndPointIndex(int index)
Returns the index of the end point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
Segment end point index.void setSegmentEndTangent(int index, vec3 tangent)
Sets the tangent coordinates for the end point of the spline segment with a given index.Arguments
- int index - Segment index.
- vec3 tangent - End point tangent coordinates.
vec3 getSegmentEndTangent(int index)
Returns the tangent coordinates for the end point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
End point tangent coordinates.void setSegmentEndUpVector(int index, vec3 up)
Sets the "up" vector coordinates for the end point of the spline segment with a given index.Arguments
- int index - Segment index.
- vec3 up - End point "up" vector coordinates.
vec3 getSegmentEndUpVector(int index)
Returns the "up" vector coordinates for the end point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
End point "up" vector coordinates.int getSegmentMode(int segment_index)
Returns the current mode for the secment with a given index.Arguments
- int segment_index - Segment index.
Return value
Mode. One of the SEGMENT_* variables.void getSegmentNodes(Node[] nodes, int segment_index = -1)
Retrieves the list of nodes assigned to the specified segment of the world spline graph and puts it to the buffer.Arguments
- Node[] nodes - Buffer to store the nodes assigned to the segments of the world spline graph.
- int segment_index - Segment index. If no segment index is specified, the method retrieves the list of source nodes assigned to all segments.
int getSegmentSourceIndex(int segment_index)
Returns the index of the source node currently assigned to the segment with a given index.Arguments
- int segment_index - Segment index.
Return value
Source node index or -1 if no source node is assigned to the segment with a given index.void setSegmentStartPoint(int index, vec3 point)
Sets the coordinates of the start point for the segment with a given index.Arguments
- int index - Segment index.
- vec3 point - Segment start point coordinates to be set.
vec3 getSegmentStartPoint(int index)
Returns the coordinates of the start point for the segment with a given index.Arguments
- int index - Segment index.
Return value
Segment start point coordinates.int getSegmentStartPointIndex(int index)
Returns the index of the start point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
Segment start point index.void setSegmentStartTangent(int index, vec3 tangent)
Sets the tangent coordinates for the start point of the spline segment with a given index.Arguments
- int index - Segment index.
- vec3 tangent - Start point tangent coordinates.
vec3 getSegmentStartTangent(int index)
Returns the tangent coordinates for the start point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
Start point tangent coordinates.void setSegmentStartUpVector(int index, vec3 up)
Sets the "up" vector coordinates for the start point of the segment with a given index.Arguments
- int index - Segment index.
- vec3 up - Start point "up" vector coordinates.
vec3 getSegmentStartUpVector(int index)
Returns the "up" vector coordinates for the start point of the spline segment with a given index.Arguments
- int index - Segment index.
Return value
Start point "up" vector coordinates.int assignSegmentSource(int segment_index, int source_num, int mode = 0, int enable_uv_tiling = 0, float delta_angle_threshold = 1.0f)
Assigns the specified source node to the given segment of the spline graph.Arguments
- int segment_index - Segment index.
- int source_num - Source node index.
- int mode - Mode. One of the SEGMENT_* variables. The default mode is SEGMENT_STRETCH.
- int enable_uv_tiling - 1 to enable UV tiling for the material textures of the source node, 0 - to stretch textures. The default value is 0.
- float delta_angle_threshold - Angle threshold value for splitting nodes, in degrees. If an angle between the tangents for the two subsequent parts of the spline segment exceeds this value, the node will be split. The default value is 1.
This parameter is used only for the SEGMENT_ADAPTIVE mode.
Return value
1 if the source node was successfully assigned to the segment; otherwise, 0.void clearSegmentSource(int segment_index = -1)
Removes the assigned source node from the segment with a given index.Arguments
- int segment_index - Segment index. If no segment index is specified, the method removes assigned source nodes from all segments.
int addSourceNode(string name, int forward_axis = 0)
Adds a source node with a given name to the list.Arguments
- string name - Source node name with file extension. E.g.: my_node.node.
- int forward_axis - Forward axis. One of the FORWARD_* variables. The default value is FORWARD_X.
int addSourceNode(Node node, int forward_axis = 0)
Adds the given source node to the list.Arguments
- Node node - Source node instance.
- int forward_axis - Forward axis. One of the FORWARD_* variables. The default value is FORWARD_X.
void removeSourceNode(int num)
Removes the source node with a given index from the list. This method also removes all nodes of all segments linked to this source node and performs correction of source node indices for all segments.Arguments
- int num - Source node index.
int setSourceForwardAxis(int num, int forward_axis)
Sets the forward axis for a given source node.Arguments
- int num - Source node index.
- int forward_axis - Forward axis. One of the FORWARD_* variables.
Return value
1 if the forward axis for the source node was set successfully; otherwise, 0.int getSourceForwardAxis(int num)
Returns the forward axis for a given source node.Arguments
- int num - Source node index.
Return value
Forward axis. One of the FORWARD_* variables.string getSourceNodeName(int num)
Returns the name of the source node with a given index.Arguments
- int num - Source node index.
Return value
Source node name.void setSplineGraph(SplineGraph splinegraph)
Sets the specified source spline graph as the current one.Arguments
- SplineGraph splinegraph - Source spline graph.
void getSplineGraph(SplineGraph splinegraph)
Copies current spline graph to the destination spline graph.Arguments
- SplineGraph splinegraph - Destination spline graph.
void setSplineGraphName(string name, int force_load = 0)
Sets the name of the world spline graph.Arguments
- string name - World spline graph name.
- int force_load - Force flag.
- If 1 is specified, the world spline graph will immediately loaded from a file.
- If 0 is specified, only the world spline graph name will be updated.
string getSplineGraphName()
Returns the name of the world spline graph.Return value
World spline graph name.void loadSegmentNodes(int segment_index = -1)
Loads source nodes assigned to the specified spline segment immediately.Arguments
- int segment_index - Segment index. If no segment index is specified, the method loads source nodes assigned to all segments.
int getNodeSegmentIndex(Node node)
Returns the index of the segment to which the given node belongs.Arguments
- Node node - Node instance.
Return value
Segment index on success; otherwise, -1.int getNodeSegmentTileIndex(Node node)
Returns the index of the given node within the segment it belongs to.Arguments
- Node node - Node instance.
Return value
Node index within the segment it belongs to on success; otherwise, -1.int getNodeSourceIndex(Node node)
Returns the index of the source node for the specified node.Arguments
- Node node - Node instance.
Return value
Source node index on success; otherwise, -1.void clear()
Clears the world spline graph.int isCurved()
Returns a value indicating if the world spline graph is curved.Return value
1 if the world spline graph is curved; otherwise, 0.void makeCurved()
Curves the world spline graph using its geodetic pivot. The spline file is saved upon completion of the curving operation.The world spline graph must be a child of a Geodetic Pivot node.
void makeFlat()
Flattens the world spline graph using its geodetic pivot. The spline file is saved upon completion of the flattening operation.The world spline graph must be a child of a Geodetic Pivot node.
int load(string name)
Loads a spline graph from the specified XML-file.Arguments
- string name - Name of the XML-file to load the spline graph from.
Return value
1 if the spline graph was successfully loaded; otherwise, 0.int save(string name)
Saves a spline graph to the specified XML-file.Arguments
- string name - Name of the XML-file to save the spline graph to.
Return value
1 if the spline graph was successfully saved; otherwise, 0.static int type()
Returns the type of the node.Return value
WorldSplineGraph type identifier.int FORWARD_X
Description
X is a forward axis for stretching.int FORWARD_Y
Description
Y is a forward axis for stretching.int FORWARD_Z
Description
Z is a forward axis for stretching.int SEGMENT_STRETCH
Description
The source node is stretched along the segment. This mode is the most performance-friendly, as only a single node is created for a segment. However, the stretched geometry will cut the curves of the spline to straight lines.int SEGMENT_TILING
Description
The source node is duplicated along the segment. Selecting this mode for a large spline graph may siginficantly reduce performance, due to a large number of tiled nodes.int SEGMENT_ADAPTIVE
Description
This mode represents a combination of stretching and tiling to make the geometry placed along the spline graph look more plausible for a lower performance cost.Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)