Assembly Spline – Import
Imports existing scene objects (TSStatic groups) into assembly splines by analyzing positions, fitting curves, and reconstructing spline data with undo support.
Imports existing scene objects (TSStatic groups) into assembly splines by analyzing positions, fitting curves, and reconstructing spline data with undo support.
Module Info
| Key | Value |
|---|---|
| File | lua/ge/extensions/editor/assemblySpline/import.lua |
| Type | Required module (not an extension) |
| Dependencies | splineMgr, molecule, rdp, fitPoly, geom, util |
Constants
| Constant | Default | Description |
|---|---|---|
anchorPrefixStr | "nail" | Expected prefix for anchor point names |
rdpLightTolerance | 0.5 | RDP simplification tolerance for light fitting |
Public Functions
| Function | Description |
|---|---|
M.handleDelayedSplineUpdates() | Called per-frame; waits for collision mesh updates before marking spline dirty |
M.validateToolCompatibleTSStatic(obj) | Validates if a TSStatic has tool-compatible anchor points (nail.* prefix) |
M.convertTSStatics2AssemblySpline(collection) | Converts selected TSStatic object IDs into an assembly spline with undo support |
M.importFromPolygon(polygon) | Finds all TSStatic objects inside a polygon and converts them to an assembly spline |
Import Pipeline
- Backup: Saves all TSStatic objects' ID, name, position, rotation, scale, group before deletion
- Position extraction: Collects world positions from component objects
- Distance calculation: Computes inter-object distances for spacing
- RDP simplification: Reduces point density using Ramer-Douglas-Peucker algorithm
- Curve fitting: Uses
fitPolyto generate smooth spline control points - Orientation detection: Votes on component alignment using tangent/binormal analysis
- Spline creation: Creates a new assembly spline with imported nodes and width
- Delayed update: Waits 2 frames for collision mesh rebuild before final update
Backup/Restore (Undo)
-- Backup structure per TSStatic
{
id = number,
name = string,
shapeName = string,
pos = vec3,
rot = string, -- "x y z w" rotation field
scale = vec3,
groupId = number -- parent SimGroup ID
}
-- Restore recreates TSStatic objects with original properties
-- (restoreTSStatics is an internal function, not exported)Orientation Voting
The importer determines component orientation by:
- Computing tangent vectors along the spline
- Calculating expected vs actual binormal directions
- Voting across 4 rotation quadrants (0°, 90°, 180°, 270°)
- Applying the winning rotation offset to all placements
Usage Example
local import = require('editor/assemblySpline/import')
-- Import selected scene objects into a new spline
local components = getSelectedTSStatics()
local spline = splineMgr.createNewSpline()
local backup = import.importFromSceneObjects(components, spline)
-- Undo: restore original objects
import.undoImport(backup)Functions
validateToolCompatibleTSStatic(obj)
Checks if a TSStatic object has tool-compatible anchor points (names starting with nail.).
obj(userdata) - A scene object to validate
Returns: boolean - true if the object is a TSStatic with at least one nail.* anchor point
convertTSStatics2AssemblySpline(collection)
Converts a collection of TSStatic object IDs into an assembly spline. Validates objects, reconstructs the assembly kit, fits a polyline, determines spacing/orientation, creates the spline, deletes originals, and commits to undo history.
collection(table) - Array of TSStatic object IDs
Returns: nil
importFromPolygon(polygon)
Finds all TSStatic objects whose positions fall inside the given polygon and converts them to an assembly spline via convertTSStatics2AssemblySpline.
polygon(table) - Array of vec3 points defining the selection polygon
Returns: nil
See Also
- Assembly Spline - Main tool
- Assembly Spline Distribution - Component distribution
Assembly Spline – Distribution
Generates mesh distribution patterns (random or round-robin) for assembly spline component placement, with probability weighting and variation support.
Assembly Spline Molecule
Handles mesh assembly kit parsing, attachment point extraction, and molecule building for the assembly spline tool. A "molecule" is a group of rigid meshes joined via attachment anchor points, with op