3D simulation system for quickly realizing additive manufacturing
By developing a 3D simulation system on the Unity platform, the problems of large calculation and long rendering time of traditional 3D printing simulation methods are solved, and the 3D printing model is quickly loaded and rendered, which significantly improves the simulation efficiency and quality.
Patent Information
- Application Number
- CN202411463932.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-02-11
AI Technical Summary
The traditional 3D printing simulation method has a large amount of calculation and a long rendering time, which limits its application in actual production.
A 3D simulation system was developed based on the Unity platform, including model file loading processing module, slice file loading processing module, 3D model cross-section data loading module, dynamic setting module, control management module and interaction module. Through the coordinated work of these modules, it can be realized. Quickly load and render 3D printed models.
Significantly reduces the amount of calculation and rendering time during the simulation process, achieving more efficient 3D simulation, users can obtain visual previews of printed objects in a short time, and can watch the entire printing process to better evaluate and adjust printing parameters .
Smart Images

Figure CN119416473A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of additive manufacturing digital twin technology, and in particular to a 3D simulation system for rapidly implementing additive manufacturing. Background Art
[0002] The combination of digital twin technology and additive manufacturing can effectively reduce the trial and error experiments of process parameters and is a potential means to control the organizational properties of additive manufacturing prints and save printing costs. Specifically, digital twin modeling can help manufacturers predict and optimize the manufacturing process and product performance before the actual manufacturing of the product through virtual simulation methods, thereby greatly reducing manufacturing costs, improving product quality and reliability, and promoting the intelligent upgrading of the manufacturing industry.
[0003] In the field of digital twins for additive manufacturing, printing simulation is a key tool for optimizing the printing process and improving printing quality. The printing principle of additive manufacturing is "bottom-up, layer-by-layer printing". Before printing, you need to use slicing software to slice and layer the 3D model, and then print it layer by layer based on the data of each layer. In this process, the 3D model is decomposed into tens of thousands of printing layers, each of which consists of a large number of point coordinates, resulting in an extremely large amount of data. Therefore, in the existing technology, traditional 3D printing simulation methods usually face challenges such as large computational complexity and long rendering time, which limits their application in actual production. Summary of the invention
[0004] In view of the deficiencies in the prior art, the present invention provides a 3D simulation system for rapidly realizing additive manufacturing, which solves the technical problems of large computational complexity and long rendering time commonly faced by traditional 3D printing simulation methods.
[0005] In order to solve the above technical problems, the present invention provides the following technical solutions: a 3D simulation system for rapidly realizing additive manufacturing, which realizes the rapid realization of parts in the additive manufacturing printing process based on the Unity platform, comprising:
[0006] The model file loading processing module is used to load the 3D model file in the STL format in the Unity platform and convert the 3D model file in the STL format into a Mesh object in the Unity platform. The formats of the 3D model file include ASCII format and binary format;
[0007] The slice file loading and processing module is used to load and store slice files from 3D model files of different formats, which contains multiple classes and methods for processing 3D model section data;
[0008] 3D model section data loading module, used to load 3D model section data in ASCII and binary format files, and parse different types of data segments according to the structure and identifiers of the CLI file, and parse the file step by step;
[0009] A dynamic setting module, used to dynamically set the cutting plane information of the target renderer or material, the dynamic setting module contains serialized fields, namely, target Renderer, target Material Indexes, offset, inversel and target Material, which respectively represent the target renderer, the target material index array, the offset of the plane position, the plane direction and the directly specified material;
[0010] The control management module is used to control and manage the display and progress of 3D printing models, including the graphics rendering and logic control combined with the Unity platform to achieve dynamic display and printing progress control of 3D printing models. It contains multiple classes to handle different tasks.
[0011] The interactive module is used to control user interaction through the scroll bar, simulate user operations, and display dynamic effects in the scene.
[0012] Furthermore, the model file loading processing module loads the 3D model file in STL format, including three main methods: LoadAscii, LoadBinary and Load, where:
[0013] The Load Ascii method accepts an array of strings representing the STL file lines in ASCII format, parses the vertices, normals, and triangle indices, and creates a Mesh object;
[0014] The Load Binary method processes binary STL data, reads vertices, normals, and triangle indices through a byte stream, and generates a Mesh object;
[0015] The Load method decides to call the Load Ascii method or the Load Binary method to load the 3D model file based on the characters at the beginning of the 3D model file.
[0016] Furthermore, the 3D model file in STL format is converted into a Mesh object in the Unity platform, specifically:
[0017] Accepts a string array or byte array containing the contents of an STL file as input, parses the STL file content and extracts vertex, triangle and normal data, constructs a Mesh using the vertex index order of the triangle patch and returns the resulting Mesh object.
[0018] Furthermore, the model file loading processing module allows the bottom center position and scaling ratio of the Mesh to be set, and the specific method includes:
[0019] The mesh.bounds code obtains the axis-aligned bounding box of the Mesh, which contains the center point c = (c x , c y , c z ) and the minimum point m=(m x , m y , m z );
[0020] The offset used to adjust the bottom center position of the Mesh is determined based on the center point c and the minimum point m, so that the bottom center of the Mesh is aligned to the origin. The calculation formula for the offset is:
[0021] o=(c x ×s,m y ×s,c z ×s)
[0022] Where o is the calculated offset; s is the scaling factor; c x , c z is the coordinate of the center point of the bounding box; m y is the minimum Y value of the bounding box;
[0023] Scale each vertex of the bounding box and subtract the offset o to ensure that the bottom center of the Mesh is aligned and scaled according to the specified ratio. The transformation formula is as follows:
[0024] v'=v×so
[0025] Where v' is the transformed vertex coordinate; v is the original vertex coordinate;
[0026] Updates the vertex and boundary information of the Mesh according to the transformation formula and returns the updated Mesh object.
[0027] Furthermore, the multiple classes and methods for processing 3D model cross-section data are specifically:
[0028] The Model 3D Section Line class represents a single section line and contains properties such as index, start point, end point, layer height, line length, distance from the start point, speed, and line type;
[0029] The Model 3D Section class is used to load and process 3D model section data. It contains enumeration types to represent the loading results and file formats, properties to store section lines, model boundaries and scaling, and methods to standardize line points.
[0030] The Model 3D Section Loader class contains methods for loading 3D model section data in different formats and uses the GetBoundsXZ method to calculate the bounds of the model on the XZ plane based on a given array of points.
[0031] Furthermore, the process of parsing different types of data segments according to the structure and identifier of the CLI file includes:
[0032] First, define the section enumeration type SectionId used to identify different types of sections in the file. The main parsing logic is concentrated in two methods Load Aff(byte[]data) and Load Aff(Binary Reader br);
[0033] Load the CLI file from a byte array or binary data stream, using the Load Aff(Binary Reader br) method to first check whether the CLI file header is legal, and if not, return an error status;
[0034] Then use the Load Aff(byte[]data) method to convert the incoming byte array (byte[]data) into a Memory Stream object, wrap it with a Binary Reader, and call the Load Aff(Binary Reader br) method to parse the binary data stream Binary Reader.
[0035] Furthermore, in the process of gradually parsing the file, geometric information is extracted according to a specific part of the CLI file, and the length and bounding box of the line segment are calculated, wherein the length and bounding box of the line segment are calculated as follows:
[0036] During the parsing process, given the coordinates of the starting point Point0 and the end point Point1, the calculation formula for the line segment length L is:
[0037]
[0038] In the formula, x1, y1, z1 are the coordinates of the starting point Point1, and x0, y0, z0 are the coordinates of the end point Point1;
[0039] The bounding box is used to describe the bounding box of the model in space. It is defined by finding the minimum and maximum coordinates of all line segments. The minimum point Min is defined as: x min ,y min 、z min ; The maximum point Max is: x max ,y max 、z max; then the center point of the bounding box is:
[0040]
[0041] The dimensions of the bounding box are:
[0042] (x max -x min ,y max -y min , z max -z min )
[0043] Finally, store the length and bounding box of the segment in a Model 3D Section object and return the object.
[0044] Furthermore, the dynamically setting the cutting plane information of the target renderer or material specifically includes:
[0045] By checking and setting the serialization field in each frame in the Update method, traversing the target material index array, after ensuring that the index is valid, obtain the corresponding material and call the SetMat method to set it;
[0046] The SetMat method determines the direction of the cutting plane according to the inversel value, uses transform.right, transform.up and transform.forward to set the normal directions of the three cutting planes respectively, and uses the current object position plus the offset to set the position information of the cutting plane;
[0047] Set the normal direction and position information of the cutting plane to the specified material;
[0048] Control the normal direction and position information of one or more material cutting planes, and update the cutting plane properties of the target renderer and target material every frame.
[0049] Furthermore, the control management module includes multiple classes to handle different tasks, namely: Model 3DPrint Progress class, Model 3D Print Mesh class and Model 3D Section Print class, where:
[0050] The Model 3D Print Progress class is responsible for managing the progress of 3D printing. The Model 3D Print Progress class estimates the line width through the Guess Line Width method, then groups the lines of the Model 3D Section and creates multiple Model 3D Print Mesh instances according to the specified number to improve drawing efficiency. Each instance contains a line group and the estimated line width.
[0051] The Model 3D Print Mesh class is used to handle specific mesh generation and updates. The Model 3D Print Mesh class generates meshes based on given lines and line widths, and handles progress changes in the Process Generate method, adjusting the current index and line position by calculating the remaining progress;
[0052] The Model 3D Section Print class is a Unity component used to load and manage 3D print models and section data. It reads model and section files, initializes the Model 3D Print Progress class, handles file read errors, and sets the model's bounding box and scale.
[0053] Furthermore, the interaction module implements a scroll bar control script with an automatic scrolling function, and specifies three private variables through the Serialize Field attribute: a scroll bar, a Model 3D Section Print instance, and an automatic scrolling duration.
[0054] By means of the above technical solution, the present invention provides a 3D simulation system for rapidly realizing additive manufacturing, which has at least the following beneficial effects:
[0055] 1. The present invention significantly reduces the amount of calculation and rendering time in the simulation process based on the Unity platform, thereby achieving more efficient 3D simulation. Specifically, the system uses simplified geometric models and material properties, as well as efficient rendering algorithms to quickly generate realistic 3D printing simulation effects and simulate the entire printing process. In this way, users can obtain a visual preview of the printed object in a short time and can watch the entire printing process in order to better evaluate and adjust the printing parameters.
[0056] 2. This invention not only improves the rendering efficiency of additive manufacturing 3D simulation, but also provides designers and engineers with a powerful tool to better understand and optimize the additive manufacturing process, thereby improving product quality and production efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0058] Figure 1 This is a rendering of the simulation printing start displayed on the Unity platform of the present invention;
[0059] Figure 2 This is a rendering of the simulated printing of the present invention displayed on the Unity platform;
[0060] Figure 3 This is a rendering of the end of simulation printing displayed on the Unity platform of the present invention. DETAILED DESCRIPTION
[0061] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific implementation methods, so that the implementation process of how the present application uses technical means to solve technical problems and achieve technical effects can be fully understood and implemented accordingly.
[0062] In the field of digital twins of additive manufacturing, printing simulation is a key tool for optimizing the printing process and improving printing quality. The printing principle of additive manufacturing is "bottom-up, layer-by-layer printing". Before printing, you need to use slicing software to slice and layer the 3D model, and then print it layer by layer based on the data of each layer. In this process, the 3D model is decomposed into tens of thousands of printing layers, each layer consists of a large number of point coordinates, resulting in an extremely large amount of data.
[0063] This example is based on the challenges faced by traditional 3D printing simulation methods, such as large amount of calculation and long rendering time. Please refer to Figure 1-Figure 3 This embodiment proposes a 3D simulation system for rapidly realizing additive manufacturing, including loading and processing model files, loading and processing slice files, loading 3D model section data, dynamically setting the cutting plane information of the target renderer or material, controlling and managing the display and progress of the 3D printing model, and controlling user interaction through a scroll bar. Through the above operations, the rapid realization of additive manufacturing printing process parts can be realized on the Unity platform. The proposed 3D simulation system includes:
[0064] The model file loading processing module is used to load the 3D model file in STL format in the Unity platform and convert the 3D model file in STL format into a Mesh object in the Unity platform. The formats of the 3D model file include ASCII format and binary format.
[0065] As one of the preferred implementations, the model file loading processing module loads the 3D model file in STL format, including three main methods: Load Ascii, Load Binary and Load, among which:
[0066] The Load Ascii method accepts an array of strings representing the STL file lines in ASCII format, parses the vertices, normals, and triangle indices, and creates a Mesh object;
[0067] The Load Binary method processes binary STL data, reads vertices, normals, and triangle indices through a byte stream, and generates a Mesh object;
[0068] The Load method determines whether to call the Load Ascii method or the Load Binary method to load the 3D model file based on the characters at the beginning of the 3D model file. Specifically, the Load method reads the first 5 characters and compares them with the string "solid". If they match, it means that the file is an STL file in ASCII format, otherwise it is an STL file in binary format.
[0069] As one of the preferred implementations, a 3D model file in STL format is converted into a Mesh object in the Unity platform, specifically: accepting a string array or byte array containing the content of the STL file as input, parsing the STL file content and extracting vertex, triangle and normal data, using the vertex index order of the triangle face to construct a Mesh and returning the generated Mesh object.
[0070] As one of the preferred implementations, the model file loading processing module allows the bottom center position and scaling ratio of the Mesh to be set. The specific method includes:
[0071] The mesh.bounds code obtains the axis-aligned bounding box of the Mesh, which contains the center point c = (c x , c y , c z ) and the minimum point m=(m x , m y , m z );
[0072] The offset used to adjust the bottom center position of the Mesh is determined based on the center point c and the minimum point m, so that the bottom center of the Mesh is aligned to the origin. The calculation formula for the offset is:
[0073] o=(c x ×s,m y ×s,c z ×s)
[0074] Where o is the calculated offset; s is the scaling factor; c x , c z is the coordinate of the center point of the bounding box; m y is the minimum Y value of the bounding box;
[0075] Scale each vertex of the bounding box and subtract the offset o to ensure that the bottom center of the Mesh is aligned and scaled according to the specified ratio. The transformation formula is as follows:
[0076] v'=v×so
[0077] Where v' is the transformed vertex coordinate; v is the original vertex coordinate;
[0078] Updates the vertex and boundary information of the Mesh according to the transformation formula and returns the updated Mesh object.
[0079] Specifically, the model file loading processing module proposed in this embodiment can load ASCII and binary STL files from the Unity platform, determine whether it is an ASCII or binary STL file according to the beginning of the 3D model file content, call the corresponding loading method and return the generated Mesh object. Then, the vertex, triangle and normal data are extracted by parsing the STL file content and converted into a Mesh object in Unity. At the same time, a function is also provided to adjust the bottom center of the Mesh and scale it proportionally.
[0080] The slice file loading and processing module is used to load and store slice files from 3D model files of different formats, which includes multiple classes and methods for processing 3D model cross-sectional data; the multiple classes and methods for processing 3D model cross-sectional data are specifically:
[0081] The Model 3D Section Line class represents a single section line and contains properties such as index, start point, end point, layer height, line length, distance from the start point, speed, and line type;
[0082] The Model 3D Section class is used to load and process 3D model section data. It contains enumeration types to represent the loading results and file formats, properties to store section lines, model boundaries and scaling, and methods to standardize line points.
[0083] The Model 3D Section Loader class contains methods for loading 3D model section data in different formats and calculating the boundaries of the model on the XZ plane.
[0084] In this embodiment, the Practicalize Lines method standardizes the lines by subtracting the center point of the model from the start and end points of each line and scaling them by a given ratio, ensuring the consistency and accuracy of the model in different contexts. This method achieves the consistency and accuracy of the model in different contexts by subtracting the center point of the model from the start and end points of each line and scaling them by a given ratio. The core formula is:
[0085] New Point=(original Point-center Point)×scale
[0086] Among them, New Point represents the line point obtained after standardization, original Point represents the starting point or end point of the line, center Point represents the center point of the model, and scale represents the scaling ratio.
[0087] The Load method attempts to load the 3D model data using a series of functions and returns a successfully loaded section object. The GetBoundsXZ method calculates the bounding box of the model on the XZ plane based on the given point array, which is used to determine the plane range of the model.
[0088] The slice file loading and processing module proposed in this embodiment includes storing loaded 3D model slices of different formats, processing and standardizing data, and then extracting 3D model section data from slice files of different formats. Through enumeration, data structure and static methods, the functions of loading, processing and managing 3D model slice data are realized, providing infrastructure and data structure support for subsequent printing and analysis processes. At the same time, the type of 3D model slice line is defined, which can be a pattern fill or a polyline. The actual processing of the slice line includes applying units, scaling and setting the bottom center point.
[0089] The 3D model section data loading module is used to load 3D model section data in ASCII and binary format files, and parse different types of data segments according to the structure and identifiers of the CLI file, and parse the file step by step.
[0090] As a preferred specific implementation of this embodiment, different types of data segments are parsed according to the structure and identifier of the CLI file. The specific process includes:
[0091] First, define the section enumeration type SectionId used to identify different types of sections in the file. The main parsing logic is concentrated in two methods Load Aff(byte[]data) and Load Aff(Binary Reader br);
[0092] Load the CLI file from a byte array or binary data stream, using the Load Aff(Binary Reader br) method to first check whether the CLI file header is legal, and if not, return an error status;
[0093] Then use the Load Aff(byte[]data) method to convert the incoming byte array (byte[]data) into a Memory Stream object, wrap it with a Binary Reader, and call the Load Aff(Binary Reader br) method to parse the binary data stream Binary Reader.
[0094] Specifically, by loading the CLI file from the byte array or binary stream data, the parsed model slice data is returned. First, verify the header information of the file, parse the different sections in the file, and parse the data and construct objects according to the different types of sections; the file is parsed by reading the data segments one by one. Each segment starts with a specific identifier, and the code uses these identifiers to determine how to process the data in the segment next.
[0095] When parsing the file body, the code reads the file content by segment and uses the identifier of each segment to determine the segment type. These identifiers may be specific strings or byte sequences, such as "$LAYER" for layer data segments, "$POLYLINE" for polygon line data segments, and "$HATCHES" for hatch line data segments. By identifying these identifiers, the program can correctly parse the specific data content in each segment. Depending on the type of segment, the code processes data such as layer information, polygons, scan lines, laser power and speed respectively. If the segment type is polygon or scan line, the code reads the corresponding coordinate data, calculates the line segment length and other geometric properties, encapsulates it into a Model 3D Section Line object, and adds it to the Lines list of the Model 3D Section.
[0096] The 3D model section data loading module implements a static class Model 3D Section Loader, which is mainly used to load and parse 3D model data files in ASCII and binary formats. The core function is to read and parse ASCII or binary files containing 3D model information from binary data streams or text files and convert them into Model 3DSection objects. The code first defines some enumeration types SectionId to identify different types of sections in the file. The main parsing logic is concentrated in two methods Load Aff(byte[]data) and Load Aff(Binary Reader br).
[0097] In the LoadAff(byte[]data) method, the code converts the incoming byte array into a Memory Stream object, wraps it with a Binary Reader, and calls Load Aff(Binary Reader br) to perform the actual parsing. The Load Aff(Binary Reader br) method first checks whether the file header is legal, and returns an error status if it is not legal. It then parses the file header information, extracts important data such as the Z unit, and positions the file pointer to the main part of the file.
[0098] As a preferred specific implementation of this embodiment, in the process of gradually parsing the file, geometric information is extracted according to a specific part of the CLI file, and the length of the line segment and the bounding box are calculated, wherein the length of the line segment and the bounding box are calculated as follows:
[0099] During the analysis process, the length of the line segment is calculated using the distance formula between two points in three-dimensional space. Given the coordinates of the starting point Point0 and the end point Point1, the calculation formula for the line segment length L is:
[0100]
[0101] Where x1, y1, z1 are the coordinates of the starting point Point1, and x0, y0, z0 are the coordinates of the end point Point1. The code also calculates and updates the bounding box of the model for subsequent processing. The bounding box is used to describe the bounding box of the model in space and is defined by finding the minimum and maximum coordinates of all line segments. The minimum point Min is: x min ,y min 、z min ; The maximum point Max is: x max ,y max 、z max . Then the center point of the bounding box is:
[0102]
[0103] The dimensions of the bounding box are:
[0104] (x max -x min ,y max -y min , z max -z min )
[0105] Finally, the code stores the parsing results (including the model's bounding box, parsing status, etc.) in a Model3D Section object and returns the object. The entire parsing process focuses on error handling. When an error occurs at any step, the corresponding error information is recorded and the parsing is aborted to ensure that the returned Model 3D Section object contains detailed error information for debugging and troubleshooting.
[0106] This embodiment defines the identifiers of different sections that may appear in the CLI file. Load the CLI file from a byte array or binary stream and return the parsed model slice data. First, verify the header information of the file, parse the different sections in the file, parse the data and construct objects according to the different types of sections, calculate the bounding box of the model slice, process different command headers, and return a parsing error if an unknown command header is encountered.
[0107] A dynamic setting module is used to dynamically set the cutting plane information of the target renderer or material; the dynamic setting module contains serialized fields, namely target Renderer, target Material Indexes, offset, inversel and target Material, which respectively represent the target renderer, the target material index array, the offset of the plane position, the plane direction and the directly specified material.
[0108] As a preferred specific implementation of this embodiment, dynamically setting the cutting plane information of the target renderer or material specifically includes:
[0109] By checking and setting the serialization field in each frame in the Update method, traversing the target material index array, after ensuring that the index is valid, obtain the corresponding material and call the SetMat method to set it;
[0110] The SetMat method determines the direction of the cutting plane according to the inversel value, uses transform.right, transform.up, and transform.forward to set the normal directions of the three cutting planes respectively, and uses the current object position plus the offset to set the position information of the cutting plane; for example: the object position is (1,2,3), and the offset is (0,1,0), if the normal direction of the cutting plane is the right direction of the object (transform.right), and the inversel value is false, then the direction of the cutting plane is the right direction of the object. The specific position of the clipping plane is calculated as: position = (1,2,3) + (0,1,0) = (1,3,3), which can achieve dynamic cutting or sectioning effects on the model.
[0111] Set the normal direction and position information of the cutting plane to the specified material;
[0112] Control the normal direction and position information of one or more material cutting planes, and update the cutting plane properties of the target renderer and target material every frame.
[0113] This embodiment sets the normal direction and position information of the cutting plane to the specified material. The material of the target renderer is checked in each frame update, and the corresponding cutting plane information is set according to the set index and conditions. By controlling the cutting plane position and direction of one or more materials, the cutting plane properties of the target renderer and the target material can be updated in each frame. And by traversing the target material index array and the individual target material in the Update method, the cutting plane can be set for multiple materials. The SetMat method calculates the normal and position of the cutting plane according to the direction and offset of the object, and sets it to the material.
[0114] The control management module is used to control and manage the display and progress of the 3D printing model, including the graphics rendering and logic control combined with the Unity platform to realize the dynamic display and printing progress control of the 3D printing model, which contains multiple classes to handle different tasks; the control management module contains multiple classes to handle different tasks, namely: Model 3DPrint Progress class, Model 3D Print Mesh class and Model 3D Section Print class, where:
[0115] The Model 3D Print Progress class is responsible for managing the progress of 3D printing. The Model 3D Print Progress class estimates the line width through the Guess Line Width method, then groups the lines of the Model 3D Section and creates multiple Model 3D Print Mesh instances according to the specified number to improve drawing efficiency. Each instance contains a line group and the estimated line width, thereby optimizing the mesh generation and processing process.
[0116] In the Process Generate method, print content of the specified length is generated incrementally, and the situation of crossing group boundaries is handled. The print progress and the current number of layers are updated, and the method of the Model 3D Print Mesh class is called to update the mesh. The length of the print content to be generated is specified by the delta parameter. If delta is a positive value, it means moving forward; if it is a negative value, it means rolling back. If the current group index is less than the previous group index, it means that it is rolling back, and the frontmost mesh needs to be recycled and updated to the queue. The print progress Progress is updated to the starting point or end point within the valid range of the current processing line to ensure accurate progress; the current number of layers Current Layer reflects the current print layer by setting it to the number of layers of the current line.
[0117] The Model 3D Print Mesh class is used to handle specific mesh generation and updates. The Model 3D Print Mesh class generates meshes based on given lines and line widths, and handles progress changes in the Process Generate method, adjusting the current index and line position by calculating the remaining progress, as follows:
[0118] When advancing forward, increase the remaining progress remainProgress. If the remaining progress is greater than the length of the current line, the excess progress is advanced to the next line, and the current index current Index is updated. When advancing backward, decrease the remaining progress remainProgress. If the remaining progress is less than the start position of the current line, rewind to the previous line and update the current index current Index. If the remaining progress exceeds the length of the current line, the incremental delta is subtracted from the length of the current line, the current index current Index is updated, and the remaining progress remainProgress is set to the remaining part of the current line. If the remaining progress is not enough to cover the current line, the incremental delta is added to the length of the current line, the current index current Index is updated, and the remaining progress remainProgress is set to the length of the current line plus the incremental delta.
[0119] In the UpdateMesh method, update the vertex positions of the mesh, and recalculate the normals and bounding box (i.e., bounding box). The calculation of normals is generally done automatically by the Mesh.RecalculateNormals() method, which calculates the normals of the mesh based on the current vertex positions and triangle indices. The calculation of bounding boxes is generally done automatically by the Mesh.RecalculateBounds() method, which updates the bounding box (Bounds) of the mesh based on the current vertex positions. In the Recycle method, recycle the mesh for reuse.
[0120] The Model 3D Section Print class is a Unity component used to load and manage 3D print models and section data. It reads the model and section files, initializes the Model 3D Print Progress class, handles file read errors, and sets the bounding box and scale of the model. In the Update method, the print progress is updated according to the playback status, and the methods of the Model 3D Print Progress class are called to draw the grid. The position of the print progress is set in the Seek method.
[0121] In general, the dynamic settings module implements a complex 3D printing progress management system, which improves drawing efficiency through grouping and mesh updating, and dynamically adjusts the printing progress and number of layers. Therefore, in order to achieve fast simulation, the following measures are taken:
[0122] Directly load the complete model: In this loading method, the STL file of the 3D model is directly loaded and set to the Unity component so that the complete model can be quickly displayed at the beginning, by adjusting the bottom center of the model and the scale to match the actual size in the CLI file.
[0123] Generate and render meshes step by step: The lines of the 3D model are processed in groups, and each group of lines corresponds to a mesh. When a new layer needs to be rendered, these meshes are gradually generated and updated. This method avoids the calculation and rendering overhead of loading all layers at the beginning, and dynamically generates and renders only when needed, greatly improving rendering efficiency.
[0124] Update mesh on demand: Dynamically calculate the parts that need to be rendered according to user operations (such as adjusting the progress), and only generate and update the mesh of these parts. This progressive processing method ensures real-time and efficient rendering.
[0125] Use mesh cache: Avoid frequent creation and destruction of mesh objects, further improving rendering performance. When a layer of mesh is no longer needed for display, it will be recycled to the cache pool. When a new mesh needs to be generated, it will be obtained from the cache pool first, reducing the overhead of resource allocation.
[0126] In summary, the code achieves fast simulation and efficient rendering by directly loading the model and gradually generating and rendering the mesh when needed.
[0127] The control management module proposed in this embodiment achieves the layer-by-layer printing effect of the model by managing the generation and display of the grid and controlling the advancement and backtracking of the printing progress. At the same time, the lines are grouped into fixed numbers, and the grid is generated and updated. This can reduce the number of objects that need to be drawn each time rendering, thereby improving the drawing efficiency. The simulation progress is controlled by processing the generated grid in steps. In this way, only a small part of the generation task can be processed in one update, thereby avoiding performance problems caused by processing too much data at one time. The overhead of creating and destroying grids is reduced by caching and recycling grids, thereby improving performance.
[0128] The interactive module is used to control user interaction through the scroll bar, simulate user operations and display dynamic effects in the scene, and facilitate the interactive and automatic scrolling functions of the scroll bar. Specifically, the interactive module implements a scroll bar control script with automatic scrolling function; three private variables are specified through the Serialize Field attribute: scroll bar, Model 3D Section Print instance (print), and automatic scrolling duration (scrollDuration). In the Start method, a listener is added to the onValueChanged event of the scroll bar. When the value of the scroll bar changes, the new progress value is calculated, and the Seek method of the print object is called to update the print progress. In addition, a coroutine named Auto Scroll is started to achieve the automatic scrolling effect of the scroll bar.
[0129] In the Auto Scroll coroutine, two variables are first defined: the elapsed time and the start value. Then, the elapsed time is gradually increased in a while loop, and the new value of the scroll bar is calculated by the Mathf.Lerp function, which smoothly transitions the scroll bar value from the start value to 1 based on linear interpolation. After each calculation, the new scroll bar value is assigned to scrollbar.value. When the loop ends, the scroll bar value is ensured to be 1. The entire coroutine starts executing when the game object is activated, and completes the automatic scrolling effect of the scroll bar within the specified duration.
[0130] like Figure 1 The following is a simulation of the printing start effect displayed on the Unity platform. This stage is the start of the operation. In the Game window, the base of the part can be seen from the front view and top view taken by two cameras. Printing has not started yet. However, the model has been loaded in the Scene window. At the bottom is the scroll bar, which can be adjusted with the mouse to dynamically control the printing progress and view the printing results. Currently, the scroll bar is placed at the leftmost starting position.
[0131] like Figure 2 The following is a simulation of the printing process displayed on the Unity platform. When the scroll bar reaches the middle position, you can see that the additive manufacturing printing is halfway done. The printing process follows the basic principle of "bottom-up, layer-by-layer printing". The scroll bar moves slowly according to the set scanning speed, indicating the printing progress. As the scroll bar moves, the material is "generated" layer by layer, simulating the printing process of the part. Due to the use of advanced graphics processing technology and optimization algorithms, the rendering efficiency is greatly improved, making the entire printing process go smoothly.
[0132] like Figure 3 As shown in the simulation printing end effect diagram displayed on the Unity platform, you can see that the scroll bar has reached the end point, which means that the printing is complete and the part has been fully formed. In the Game window, you can see the front view and top view of the molded part. At the beginning of the run, the scroll bar moves at the set speed to simulate the forming process of the part during the additive manufacturing printing process. When the scroll bar reaches the end point, the user can also use the mouse to move the scroll bar to the printing step you want to view to view the forming status of the part. The whole process will not get stuck due to the large amount of rendering, which fully demonstrates the effectiveness of the designed optimization algorithm and rendering method in simulating additive manufacturing printed parts.
[0133] Compared with the prior art, the present invention significantly reduces the amount of calculation and rendering time in the simulation process by adopting advanced graphics processing technology and optimization algorithms, thereby achieving more efficient 3D simulation.
[0134] Those skilled in the art can understand that the implementation of the above embodiments can be completed by instructing the relevant hardware through a program, so the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0135] The above implementation methods have been described in detail. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A 3D simulation system for rapid implementation of additive manufacturing, which is based on the Unity platform to achieve rapid implementation of parts in the additive manufacturing printing process, characterized in that: include: The model file loading processing module is used to load the 3D model file in the STL format in the Unity platform and convert the 3D model file in the STL format into a Mesh object in the Unity platform. The formats of the 3D model file include ASCII format and binary format; The slice file loading and processing module is used to load and store slice files from 3D model files of different formats, which contains multiple classes and methods for processing 3D model section data; 3D model section data loading module, used to load 3D model section data in ASCII and binary format files, and parse different types of data segments according to the structure and identifiers of the CLI file, and parse the file step by step; A dynamic setting module, used to dynamically set the cutting plane information of the target renderer or material, the dynamic setting module contains serialized fields, namely, target Renderer, target Material Indexes, offset, inversel and target Material, which respectively represent the target renderer, the target material index array, the offset of the plane position, the plane direction and the directly specified material; The control management module is used to control and manage the display and progress of 3D printing models, including the graphics rendering and logic control combined with the Unity platform to achieve dynamic display and printing progress control of 3D printing models. It contains multiple classes to handle different tasks. The interactive module is used to control user interaction through the scroll bar, simulate user operations, and display dynamic effects in the scene.
2. The 3D simulation system according to claim 1, characterized in that: The model file loading processing module loads the 3D model file in STL format, including three main methods: Load Ascii, Load Binary and Load, among which: The Load Ascii method accepts an array of strings representing the STL file lines in ASCII format, parses the vertices, normals, and triangle indices, and creates a Mesh object; The Load Binary method processes binary STL data, reads vertices, normals, and triangle indices through a byte stream, and generates a Mesh object; The Load method decides to call the Load Ascii method or the Load Binary method to load the 3D model file based on the characters at the beginning of the 3D model file.
3. The 3D simulation system according to claim 1, characterized in that: The conversion of the 3D model file in STL format into a Mesh object in the Unity platform is specifically as follows: Accepts a string array or byte array containing the contents of an STL file as input, parses the STL file content and extracts vertex, triangle and normal data, constructs a Mesh using the vertex index order of the triangle patch and returns the resulting Mesh object.
4. The 3D simulation system according to claim 1, characterized in that: The model file loading processing module allows the bottom center position and scaling of the Mesh to be set. The specific methods include: The mesh.bounds code obtains the axis-aligned bounding box of the Mesh, which contains the center point c = (c x , c y , c z ) and the minimum point m=(m x , m y , m z ); The offset used to adjust the bottom center position of the Mesh is determined based on the center point c and the minimum point m, so that the bottom center of the Mesh is aligned to the origin. The calculation formula for the offset is: o=(c x ×s,m y ×s,c z ×s) Where o is the calculated offset; s is the scaling factor; c x , c z is the coordinate of the center point of the bounding box; m y is the minimum Y value of the bounding box; Scale each vertex of the bounding box and subtract the offset o to ensure that the bottom center of the Mesh is aligned and scaled according to the specified ratio. The transformation formula is as follows: v′=v×so Where v' is the transformed vertex coordinate; v is the original vertex coordinate; Updates the vertex and boundary information of the Mesh according to the transformation formula and returns the updated Mesh object.
5. The 3D simulation system according to claim 1, characterized in that: The multiple classes and methods for processing 3D model cross-section data are specifically: The Model3DSectionLine class represents a single section line and contains properties such as index, start point, end point, layer height, line length, distance from the start point, speed, and line type; The Model3DSection class is used to load and process 3D model section data. It contains enumeration types to represent the loading results and file formats, properties to store section lines, model boundaries and scaling, and methods to standardize line points. The Model3DSectionLoader class contains methods for loading 3D model section data in different formats and uses the GetBoundsXZ method to calculate the boundaries of the model on the XZ plane based on a given array of points.
6. The 3D simulation system according to claim 1, characterized in that: The specific process of parsing different types of data segments according to the structure and identifier of the CLI file includes: First, define the section enumeration type SectionId used to identify different types of sections in the file. The main parsing logic is concentrated in two methods LoadAff(byte[]data) and LoadAff(BinaryReaderbr); Load the CLI file from a byte array or binary data stream, using the LoadAff(Binary Readerbr) method to first check whether the CLI file header is legal, and return an error status if it is not legal; Then use the LoadAff(byte[]data) method to convert the incoming byte array (byte[]data) into a MemoryStream object, wrap it with BinaryReader, and call the LoadAff(Binary Readerbr) method to parse the binary data stream BinaryReader.
7. The 3D simulation system according to claim 1, characterized in that: In the process of gradually parsing the file, geometric information is extracted according to a specific part of the CLI file, and the length and bounding box of the line segment are calculated. The length and bounding box of the line segment are calculated as follows: During the parsing process, given the coordinates of the starting point Point0 and the end point Point1, the calculation formula for the line segment length L is: Where x1, y1, z1 are the coordinates of the starting point Point1, and x0, y0, z0 are the coordinates of the end point Point1; The bounding box is used to describe the bounding box of the model in space. It is defined by finding the minimum and maximum coordinates of all line segments. The minimum point Min is defined as: x min ,y min 、z min ; The maximum point Max is: x max ,y max 、z max ; then the center point of the bounding box is: The dimensions of the bounding box are: (x max -x min ,y max -y min ,z max -z min ) Finally, store the length and bounding box of the segment in a Model 3D Section object and return the object.
8. The 3D simulation system according to claim 1, characterized in that: The dynamically setting the cutting plane information of the target renderer or material specifically includes: By checking and setting the serialization field in each frame in the Update method, traversing the target material index array, after ensuring that the index is valid, obtain the corresponding material and call the SetMat method to set it; The SetMat method determines the direction of the cutting plane according to the inversel value, uses transform.right, transform.up and transform.forward to set the normal directions of the three cutting planes respectively, and uses the current object position plus the offset to set the position information of the cutting plane; Set the normal direction and position information of the cutting plane to the specified material; Control the normal direction and position information of one or more material cutting planes, and update the cutting plane properties of the target renderer and target material every frame.
9. The 3D simulation system according to claim 1, characterized in that: The control management module contains multiple classes to handle different tasks, namely: Model 3D Print Progress class, Model 3D Print Mesh class and Model3D Sectio n Print class, where: The Model 3D Print Progress class is responsible for managing the progress of 3D printing. The Model 3D Print Progress class estimates the line width through the Guess Line Width method, then groups the lines of the Model 3D Section and creates multiple Model 3D Print Mesh instances according to the specified number to improve drawing efficiency. Each instance contains a line group and the estimated line width. The Model 3D Print Mesh class is used to handle specific mesh generation and updates. The Model 3D Print Mesh class generates meshes based on given lines and line widths, and handles progress changes in the Process Generate method, adjusting the current index and line position by calculating the remaining progress; The Model 3D Section Print class is a Unity component used to load and manage 3D print models and section data. It reads model and section files, initializes the Model 3D Print Progress class, handles file read errors, and sets the model's bounding box and scale.
10. The 3D simulation system according to claim 1, characterized in that: The interaction module implements a scroll bar control script with automatic scrolling function, and specifies three private variables through the Serialize Field attribute: the scroll bar, the Model 3D Section Print instance, and the automatic scrolling duration.
Citation Information
Cited By
User personalized model generation method, device and equipment for digital human
CN120599160A
Digital human user personalized model generation method, device and equipment
CN120599160B