Node-based automatic line generation method based on Unity engine
By automating node definition and path generation in the Unity engine, the problem of relying on manual adjustments for line generation is solved, achieving efficient and safe line modeling, supporting dynamic updates and material adjustments in complex scenes, and meeting the performance requirements of large-scale scenes.
Patent Information
- Application Number
- CN202510869749.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-10-21
AI Technical Summary
Existing technologies rely on manual adjustments to generate routes in the Unity engine, resulting in high maintenance costs, difficulty synchronizing physical and environmental constraints, and an inability to efficiently support dynamic updates and performance optimization in large-scale scenarios.
It provides a node-based automated path generation method based on the Unity engine. By initializing control nodes in the editor, setting physical and environmental constraints, it automatically determines the path type, generates intermediate paths, performs curvature verification and collision detection, constructs a 3D mesh, and supports real-time dynamic adjustment of materials.
It automates the entire process of route generation, reduces manual adjustment time, ensures the safety and usability of the generated results, supports high-performance rendering and dynamic material switching for complex topologies, and is suitable for various scene modeling needs.
Smart Images

Figure CN120823339A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of circuit modeling, and in particular to a method for automatically generating circuits according to nodes based on a Unity engine. Background Art
[0002] With the rapid development of fields such as virtual reality, digital twins, game development, and engineering simulation, the demand for efficient modeling of lines (including roads, pipelines, transmission lines, etc.) in large-scale scenarios is increasing. The Unity engine has become the developer's preferred real-time 3D development platform with its cross-platform nature, excellent rendering performance, and rich ecological components.
[0003] However, route generation in Unity typically relies on manual point-by-point placement and adjustment of spline curves in the editor, or through the use of third-party plug-ins. This approach has several drawbacks: First, developers need to manually place numerous control points in the scene and adjust their positions and curvature parameters individually in the Inspector panel. As route size increases or requirements change, repeated revisions and verifications are necessary, dramatically increasing the workload and easily introducing positional errors, reducing maintainability. Second, existing editor tools often focus solely on visual effects, with insufficient support for physical constraints such as minimum turn radius, obstacle avoidance, and penetration detection with physical collision bodies. Safety and traversability cannot be verified simultaneously during the modeling phase, often requiring separate debugging scripts or runtime collision detection, increasing development complexity. Furthermore, with the dynamic adjustments of route nodes, routes, and cross-sectional shapes within the scene, manual mesh construction based on traditional Mesh APIs often fails to meet the requirements of real-time generation and batch updates. This is especially true for complex topologies with closed loops and multiple branches, making high-performance rendering and dynamic material switching difficult.
[0004] Therefore, there is an urgent need for a route generation method in the Unity engine that can automate the entire process from node definition, path generation to mesh construction, integrate physical constraint verification, and support real-time dynamic updates. This can improve modeling efficiency, ensure the security and accessibility of generated results, and meet performance requirements in large-scale scenarios. Summary of the Invention
[0005] This invention addresses the problems encountered in Unity route generation, such as the reliance on manual point adjustments and high maintenance costs in existing Unity engines, the difficulty in synchronizing physical and environmental constraints, and the inability to efficiently support dynamic updates and performance optimization in large-scale scenarios.
[0006] Therefore, the problem to be solved by the present invention is how to provide a method for automatically generating circuits according to nodes based on the Unity engine.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] In the first aspect, an embodiment of the present invention provides a method for automatically generating routes based on nodes based on the Unity engine, including: calibrating and initializing control nodes according to the actual scene in the Unity editor to form a node set for path generation; and setting physical and environmental constraints between nodes; automatically judging the path type according to the node distribution, and supporting the selection of straight lines or Bezier curves; constructing a path framework based on the adjacency relationship between nodes, and using linear interpolation or Bezier curves to generate intermediate paths; and performing curvature verification and collision detection on the generated path; automatically detecting and processing closed loops and bifurcations, and maintaining a multi-branch path data structure; discretizing and sampling the path to obtain spatial discrete points; expanding the annular vertices along the cross-sectional direction of each sampling point and constructing a triangle index to generate a renderable three-dimensional mesh; after generating the mesh, dynamically assigning material properties according to runtime requirements to achieve real-time customization of the route appearance.
[0009] As a preferred solution of the method for automatically generating a line according to nodes based on the Unity engine described in the present invention, the control node is initialized and calibrated using the Transform component under the Unity world coordinate.
[0010] As a preferred solution of the method for automatically generating a route based on nodes in the Unity engine according to the present invention, physical collision detection is performed on each pair of adjacent nodes to prevent the path from penetrating existing physical collision bodies in the scene.
[0011] As a preferred solution of the method for automatically generating nodes based on the Unity engine described in the present invention, when the node connectivity environment is simple and straight lines are feasible, linear interpolation is used to generate the path; when smooth transition or obstacle avoidance is required, quadratic or cubic Bezier curves are used to generate the path.
[0012] As a preferred solution of the method for automatically generating a line based on nodes in the Unity engine described in the present invention, the number of discretized sampling points is calculated according to the total length of the path and the preset segment length, and the annular section vertices are generated in the normal vector plane based on each sampling point.
[0013] As a preferred solution of the method for automatic line generation based on nodes based on the Unity engine described in the present invention, after the mesh generation is completed, the material properties are dynamically adjusted according to runtime requirements to display the diverse appearance of the line. The material properties are not limited to texture tiling ratio, diffuse reflection, metallicity and smoothness.
[0014] As a preferred solution of the method for automatically generating nodes based on the Unity engine described in the present invention, the closed loops in the formed path network are automatically detected and closed, sub-paths are independently generated for branch scenes, and a unified multi-branch path data structure is maintained.
[0015] In the second aspect, in order to further solve the problems existing in line modeling, the present invention provides an automatic line generation system based on nodes based on the Unity engine, which includes: a node calibration module for receiving and storing preset control node information in the scene in the Unity editor, and initializing the Transform properties of the nodes; a constraint setting module for automatically configuring collision body detection parameters based on the physical and environmental constraint rules between nodes and ensuring that the scene model is not penetrated when the path is generated; a path generation module, connected to the node calibration module and the constraint setting module, for selecting linear interpolation or Bezier curve for path interpolation according to the adjacency relationship between nodes, and performing curvature verification and multi-branch network management on the generated path; a grid construction module for discretizing and sampling the continuous curve output by the path generation module, expanding the annular vertices according to the cross-sectional direction of the sampling point, and constructing a triangle index to form a renderable three-dimensional grid; a material assignment module for dynamically adjusting the material properties of the three-dimensional grid generated by the grid construction module according to runtime requirements.
[0016] In a third aspect, an embodiment of the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the method for automatically generating circuits according to nodes based on the Unity engine as described in the first aspect of the present invention is implemented.
[0017] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, any step of the method for automatically generating circuits according to nodes based on the Unity engine as described in the first aspect of the present invention is implemented.
[0018] The beneficial effects of the present invention are:
[0019] 1. This invention completes path planning and mesh generation in one go through unified node definition and constraint setting, automating the entire process and avoiding repeated manual adjustments in the editor, significantly shortening modeling time.
[0020] 2. This invention introduces physical constraints such as minimum turning radius and obstacle avoidance detection, making the generated route not only visually smooth but also meeting safety and feasibility requirements in subsequent simulations, vehicle or pipeline fluid simulations;
[0021] 3. This invention supports the integrated generation of straight lines, quadratic / cubic Bezier curves, closed loops, and multi-branch grids. It can be flexibly applied to modeling various types of scenarios, such as roads, pipelines, transmission lines, and rails, meeting the needs of complex terrain and multi-node networks.
[0022] 4. The present invention is based on the Unity architecture, and paths and grids can be quickly refreshed at runtime; at the same time, material properties (texture tiling, color, glossiness, etc.) can be dynamically replaced, making it convenient for designers to preview and optimize in real time according to project progress and aesthetic requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. Those skilled in the art can also derive other drawings based on these drawings without inventive effort. Among them:
[0024] Figure 1 This is a flow chart for implementing the present invention in Example 1.
[0025] Figure 2 This is a diagram showing the implementation effect of the present invention in Example 1.
[0026] Figure 3 This is a system flow chart of the present invention in Example 2. DETAILED DESCRIPTION
[0027] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0028] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0029] Secondly, the term "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in various places throughout this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive of other embodiments.
[0030] Example 1
[0031] Reference Figure 1 and Figure 2This is the first embodiment of the present invention. This embodiment provides a method for automatically generating nodes based on the Unity engine. It addresses the problems of low manual efficiency, difficulty in dynamic adjustment, and insufficient support for complex rules when modeling lines (such as roads, pipelines, and transmission lines) in large-scale scenarios. The method includes the following steps:
[0032] Step S1: Node system definition and constraints, used to guide subsequent path and mesh generation, which includes the following sub-steps:
[0033] S1-1: Initialize the control node, specifically using the Transform component in Unity world coordinates as the carrier to define the node set The position of each node is calibrated in the editor to correspond one-to-one with the actual scene (such as pile points, access points, and branch nodes);
[0034] Specifically, define a set of control nodes It can be expressed as:
[0035]
[0036] In the formula, the coordinate x i ,y i ,z i The unit is meter (m). You can fix or unlock any coordinate axis by fine-tuning it in the editor.
[0037] S1-2: Set physical and environmental constraints, specifically for any three consecutive nodes N i-1 ,N i ,N i+1 , calculate the local curvature k i and ensure that k i ≤1 / R min (R min is the minimum turning radius), and the Euclidean distance D of the adjacent nodes ij Perform obstacle collision detection to ensure that the connection line does not penetrate the scene model;
[0038] Specifically, the local curvature k i This can be expressed by the following formula:
[0039]
[0040] Where P` and P`` are the first-order and second-order derivatives of the path, respectively, to ensure the safety of the force when the vehicle or fluid passes.
[0041] For each pair of adjacent nodes N i , N j , calculate the Euclidean distance D ij , which can be expressed by the following formula:
[0042]
[0043] S1-3: Determine the path type between two nodes based on scenario requirements and node distribution;
[0044] For example, when the environment is simple and straight lines are feasible, linear interpolation is used; when smooth transition or obstacle avoidance is required, quadratic / cubic Bezier curve interpolation is enabled, and control points and curvature adjustment coefficients are set.
[0045] Step S2: Generate an intermediate path curve that satisfies physical constraints based on the node adjacency relationship, which includes the following sub-steps:
[0046] S2-1: Build adjacency relationships. Specifically, scan all nodes and calculate the Euclidean distance D for each pair of nodes according to step S1-2. ij , when D ij ≤D 阈值 When the straight lines connect without penetrating the scene physical collider, they can be considered adjacent and added to the edge set ε;
[0047] Specifically, the edge set ε can be represented by the following adjacency list:
[0048] ε={(N i , N j )|D ij ≤D 阈值};
[0049] S2-2: Construct the basic path, including the straight line segment using P 直线 (t) The cubic Bessel formula P is used for construction and smooth transition 过度 (t) construction;
[0050] Specifically, the straight line path constructs P 直线 (t) can be expressed as:
[0051] P 直线 (t) = (1-t)N i +tN j ,t∈[0,1];
[0052] Smooth transition path construction P 过度 (t) can be expressed as:
[0053] P 过度 (t) = (1-t) 3 N i +3t(1-t) 2 C1+3t 2 (1-t)C2+t 3 N j ,t∈[0,1];
[0054] Where, control point C1 = N i +μd i , C2=N j -μd j ; Among them, d i From N i Point N i+1 is the unit vector of , μ is the curvature adjustment coefficient, which can be obtained by minimizing the path curvature energy function.
[0055] S2-3: Curvature and physical verification, specifically, for each point t on the generated path curve, calculate the curvature k(t), and use Lagrange multipliers or quadratic programming to force k in the optimization process. i ≤1 / R min (R min ≥R 设备最小转弯半径 ) to ensure that the turning radius meets the equipment passage requirements.
[0056] S2-4: Closed loop and bifurcation processing, specifically automatically detecting closed loops in the path grid, and automatically closing at the endpoints if a loop is formed; independently generating sub-paths for branching scenes, and maintaining a unified path data structure to support multi-branch rendering.
[0057] Step S3: Dynamic mesh generation, which discretizes the path and generates a renderable mesh along its cross section, including the following sub-steps:
[0058] S3-1: Path discretization sampling, specifically based on the total length L and the preset segment length l seg Calculate the number of segments And obtain the parameter sequence {t k =k / K|k=0,...,K}, corresponding to the space point P(t k ).
[0059] S3-2: Section vertex expansion, specifically at each point P(t k ) in the normal vector plane, taking the cross-section radius r as the reference, according to the number of polygon vertices M s Generate ring vertex V k,m ;
[0060] Specifically, the above-mentioned ring vertex V k,m This can be expressed by the following formula:
[0061]
[0062] Where n k , b k Tangent T k =P`(t k )'s principal and binormal unit vectors.
[0063] S3-3: triangle index construction, specifically the adjacent section vertices V k,m With V k+1,m Connect two triangles in clockwise order to ensure that the normals face outward, and output the vertex array and index array of the Mesh to meet the renderer's front culling rules.
[0064] S3-4: Dynamic material assignment. Specifically, after the mesh is generated, the material properties (texture tiling ratio, diffuse reflection, metallicity, smoothness, etc.) can be adjusted according to runtime requirements to achieve real-time customization and diversified display of the line appearance.
[0065] In summary, the present invention realizes the automation of the entire process from path planning to mesh generation in the Unity engine based on unified node definitions and physical constraints, which not only avoids repeated manual adjustments in the editor and greatly shortens the modeling cycle, but also ensures that the generated routes are smooth, safe and feasible in simulation or actual operation through minimum turning radius and obstacle avoidance detection; at the same time, it supports the integrated mesh construction of straight lines, quadratic / cubic Bezier curves, closed loops and multiple branches, and flexibly adapts to the requirements of multiple scenarios such as roads, pipelines, transmission lines, and rails. It can also quickly refresh paths and meshes and dynamically replace material properties at runtime to meet the real-time optimization of design progress and visual effects.
[0066] Example 2
[0067] Reference Figure 3 Embodiment 2 is the second embodiment of the present invention. This embodiment differs from the first embodiment in that it further provides a node-based automatic line generation system based on the Unity engine, including system initialization, constraint setting module, path generation module, mesh construction module, and material assignment module. Specifically:
[0068] System Initialization: Create an empty GameObject in the Unity project, name it "LineGeneratorSystem," and attach the five script components "NodeCalibration.cs," "ConstraintSetup.cs," "PathInterpolation.cs," "MeshBuilder.cs," and "MaterialController.cs" to it. When you start the scene, the "NodeCalibration.cs" component automatically scans all GameObjects marked as "ControlNode" in the scene, reads their Transform information, stores it in the node list, and records node connectivity based on the node's coordinate distribution.
[0069] Constraint Setup Module: The "ConstraintSetup.cs" component pre-defines a set of collision detection rules, including LayerMask settings for terrain meshes, building models, and other scene obstacles. This module iterates over each pair of adjacent nodes in the node list, performs collision detection using Physics.Raycast or Physics.CheckSphere, and dynamically adjusts the shortest path between each pair of nodes to ensure that the path does not penetrate any detected collision bodies.
[0070] The path generation module, "PathInterpolation.cs," determines the path interpolation method based on the node adjacency matrix. If there are no obstructions between adjacent nodes and the straight path meets the maximum angle threshold, the LinearLerp method is called to generate straight line segments; otherwise, the BezierCurve.GenerateCurve method is called to generate smooth curve segments. The generated path data structure supports multiple branches, recursively interpolating each branch node separately. Upon completion, the branches are merged into a unified PathNetwork in depth-first order.
[0071] Mesh Construction Module: "MeshBuilder.cs" receives the PathNetwork object from "PathInterpolation.cs" and discretizes each path using a preset sampling interval, generating a series of path points. It then calculates the normal direction for each path point and generates a circular vertex ring in that direction. Adjacent vertex rings are connected using triangle indexing rules, and finally, MeshFilter and MeshRenderer are called to generate a renderable 3D line mesh.
[0072] The material assignment module, "MaterialController.cs," dynamically sets the MeshRenderer's material properties at runtime based on external inputs (such as the material template selected by the user in the Inspector or parameters configured through the UI). This includes adjusting the main texture's tiling value, setting the material's metallic and smoothness, and switching between different diffuse maps through code, enabling real-time customization of the circuit's appearance.
[0073] This embodiment also provides a computer device, which is suitable for the case of a method for automatically generating circuits according to nodes based on the Unity engine, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute computer-executable instructions to implement the method for automatically generating circuits according to nodes based on the Unity engine as proposed in the above embodiment.
[0074] The computer device may be a terminal, comprising a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device comprises a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a button, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse.
[0075] This embodiment also provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for automatically generating a circuit based on a node based on the Unity engine as proposed in the above embodiment; the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, disk or optical disk.
[0076] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for automatically generating lines based on nodes in the Unity engine, characterized by: include: Step S1: In the Unity editor, control nodes are calibrated and initialized according to the actual scene to form a node set for path generation; physical and environmental constraints between nodes are set; the path type is automatically determined based on the node distribution, supporting the selection of straight lines or Bezier curves; Step S2: construct a path framework based on the adjacency relationship between nodes, and use linear interpolation or Bezier curves to generate intermediate paths; perform curvature verification and collision detection on the generated paths; automatically detect and process closed loops and bifurcations, and maintain a multi-branch path data structure; In step S3, the path is discretized and sampled to obtain spatial discrete points; the circular vertices are expanded along the cross-sectional direction of each sampling point and triangle indices are constructed to generate a renderable three-dimensional mesh; after the mesh is generated, material properties are dynamically assigned according to runtime requirements for real-time customization of the route appearance.
2. The method for automatically generating nodes based on the Unity engine according to claim 1, characterized in that: In step S1, the control node is initialized and calibrated using the Transform component in Unity world coordinates.
3. The method for automatically generating nodes based on the Unity engine according to claim 1, characterized in that: In step S1, physical collision detection is performed on each pair of adjacent nodes to prevent the path from penetrating existing physical collision bodies in the scene.
4. The method for automatically generating nodes based on the Unity engine according to claim 1, characterized in that: In step S2, when the node connectivity environment is simple and a straight line is feasible, linear interpolation is used to generate the path; when smooth transition or obstacle avoidance is required, quadratic or cubic Bezier curves are used to generate the path.
5. The method for automatically generating a node-based circuit based on the Unity engine according to claim 1, wherein: In step S3, the number of discretized sampling points is calculated according to the total length of the path and the preset segment length, and the annular section vertices are generated in the normal vector plane based on each sampling point.
6. The method for automatically generating nodes based on the Unity engine according to claim 1, characterized in that: In step S3, after the mesh is generated, the material properties are dynamically adjusted according to the runtime requirements to display the circuit appearance in a diversified manner. The material properties include but are not limited to texture tiling ratio, diffuse reflection, metallicity and smoothness.
7. The method for automatically generating a node-based circuit based on the Unity engine according to claim 1, wherein: In step S2, closed loops in the formed path network are automatically detected and closed, sub-paths are independently generated for branch scenarios, and a unified multi-branch path data structure is maintained.
8. A system for automatically generating a route based on nodes using the Unity engine, based on a method for automatically generating a route based on nodes using the Unity engine according to any one of claims 1 to 7, characterized in that: include, The node calibration module is used to receive and store the preset control node information in the scene in the Unity editor and initialize the Transform properties of the node; The constraint setting module is used to automatically configure collision detection parameters based on the physical and environmental constraints between nodes and ensure that the path does not penetrate the scene model when it is generated; A path generation module, connected to the node calibration module and the constraint setting module, is used to select linear interpolation or Bezier curve for path interpolation based on the adjacency relationship between nodes, and perform curvature verification and multi-branch network management on the generated path; A mesh construction module, configured to discretize and sample the continuous curve output by the path generation module, expand the annular vertices according to the cross-sectional directions of the sampling points, and construct triangle indices to form a renderable three-dimensional mesh; The material assignment module is used to dynamically adjust the material properties of the three-dimensional mesh generated by the mesh construction module according to runtime requirements.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for automatically generating a line according to nodes based on the Unity engine are implemented in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for automatically generating a line according to nodes based on the Unity engine are implemented in any one of claims 1 to 7.