Smart Spline Generator

Some game assets are meant to be used only in specific level locations, conforming to unique scene geometry. For example, vines or other plants that hang from point A to point B. Assets like these can be cumbersome to create, especially when there is a need to modify the underlying level geometry or add a new element that interferes with current asset design.

Smart Spline Generator is a tool that allows the user to procedurally generate assets that automatically align to level geometry. The user can use any custom mesh, so the generator can produce vines, fences, ropes, cables, walls, drainpipes and more. It is available on the UE4 Marketplace, along with a video preview for additional insights (Figure 12.30).

Main Concepts

Procedural surface-aligning asset generation works with any collision enabled surface. The user can drag an asset preset from the Unreal Engine 4 editor content browser and drop it into a 3D scene to immediately see the effect. The generator detects surface in a specified direction, over a specified distance, using many parameters exposed from the Blueprint system.

Recursive Surface Align Algorithm

A custom algorithm was created in order to implement the surface align feature. After setting the main direction vector and finding the start point using Line Trace functions, it executes a recursive function for surface detection in a previously calculated direction (Figure 12.31).

SetMainDirectionVector allows the user to specify in what direction the asset should generate. The main direction vector is saved as a variable inside the main generator class, so the other functions inside it can access it later. The variable is also used in other parts of the tool, so the value is not passed through the function outputs in this case.

FindStartPoint function performs a Line Trace By Channel, where it detects a starting point from near the surface in a specified direction. It also returns the normal vector of a detected surface, so the next function can use it to align the detection points properly.

DoCheckSegment: most of the surface detection logic is contained in this function. It is recursive, in this case it executes itself if a specified condition is not met yet, for example, if the user wants to generate X amount of spline segments along the surface, it will keep generating until the desired number of segments are created.

After each execution, the function passes new calculated values for inputs StartLocation and RelativeNormal when calling itself from inside. This way, it can use the last calculated point as a new starting point to detect and generate points one after another, progressing through the detected surface.

Surface detection relies on LineTrace functions from calculated locations to check the hit location and normal values to determine further generation steps. In general, the algorithm works as shown in Figure 12.32.

Additionally, the algorithm checks if the specified point amount is already reached. If that is true, it does not execute the function, breaking the recursive execution chain.

The set of points calculated in the DoCheckSegment recursive function are passed to the next function which creates Spline Mesh Component along the points.

Vert Count Optimization with Spline Thicken Function

Using modular cylinder meshes as Spline Mesh Component sections will provide good results for most cases, but for larger assets, it introduces a significant vertex count increase. To reduce the vertex amount, the system uses the Spline Thicken function inside the main material. This function is a part of the Unreal Engine 4 toolset and it allows the use of simple polygon strips instead of cylinders while retaining the cylindrical look (Figure 12.33).

Wireframe and regular view of polygon strip with the Spline Thicken function applied

FIGURE 12.33 Wireframe and regular view of polygon strip with the Spline Thicken function applied.

Thickness is controlled inside the material by getting vertex color values from polygon strip mesh. The mesh is painted with the PaintVerticesLerpAlongAxis function with 0-1 value that represents thickness. It is saved into the Red channel of vertex color. This way the user can control the thickness along surface aligned points, usually it is used to taper vine stems at the end or set the overall volume of stems, cables, ropes and so on (Figure 12.34).

Controlling the stem look via vertex colors also allows to add more visual tweaks inside the material. There is also room for more features that can be controlled using other vertex color channels (green and blue).

Merging to Static Mesh

Assets generated with Smart Spline Generator are ready to use immediately, but it is recommended to merge them into a regular static mesh as a final step. This significantly reduces the draw call amount for each asset by combining all spline mesh sections and, for example, many leaves mesh into one object. It can be achieved with the Merge Actors tool that is available in Unreal Engine 4, under the Developer Tools menu.

Merging an asset into one static mesh also provides a way to easily save generated assets and export them in FBX or OBJ format to external 3D applications for further editing.

Vertex color used to control stem thickness inside material graph

FIGURE 12.34 Vertex color used to control stem thickness inside material graph.

< Prev   CONTENTS   Source   Next >