A method for outputting model data in Unity programming

By introducing the basic geometric unit concept of element ID + material ID into the Revit model output and utilizing the IExportContext interface, the problem of material differentiation in Revit models is solved, enabling comprehensive data output and network sharing, and improving the display and management capabilities of Revit models in Unity.

CN115964025BActive Publication Date: 2026-03-06BEIJING GENERAL MUNICIPAL ENG DESIGN & RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211721891.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2026-03-06
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

Existing technologies cannot effectively distinguish the geometric positions of multiple materials contained in a single element when outputting Revit models. As a result, the output basic geometric ID cannot distinguish between different materials, affecting subsequent display and management.

Method used

The concept of basic geometric units is adopted, with the element ID + material ID as the ID of the basic geometric unit. The context parameters and data extraction and processing methods are written through the Revit secondary development interface provided by Autodesk - IExportContext, including steps such as Start(), OnViewBegin(), OnElementBegin(), OnMaterial(), OnFaceBegin(), OnPolymesh(), and OnElementEnd(), to ensure the accurate output of material information.

Benefits of technology

It enables comprehensive output of Revit model data, solves the material differentiation problem, improves the ability to share and manage data in a network environment, and supports graphical display and management from Revit to Unity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115964025B_ABST
    Figure CN115964025B_ABST
Patent Text Reader

Abstract

This invention relates to a method for outputting model data in Unity programming. It utilizes the Autodesk Revit secondary development interface – IExportContext – to output all target data by writing context parameters and adding methods for data extraction and processing within the context. This includes nine context-dependent process methods: Start(), OnViewBegin(), OnElementBegin(), OnMaterial(), OnFaceBegin(), OnPolymesh(), OnElementEnd(), OnViewEnd(), and Finish(). This invention expands the data medium of Revit data and increases the usability of architectural information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method for outputting model data in Unity programming, which can be applied to fields such as municipal infrastructure design, BIM (Building Information Modeling) technology, 3D visualization, and engineering management, covering professional disciplines such as computer science, civil engineering, and architecture. Background Technology

[0002] Analysis of several currently available technologies reveals that they all use Revit models to output JSON files. The JSON file describes the Revit model through serialized objects or arrays, describing the model's geometric information, architectural non-geometric information, and attached custom information. The JSON data is then read into the 3D graphics engine program or script, and displayed and managed within the graphics engine to achieve its functionality.

[0003] However, currently available technologies do not include specific operational methods; they only provide a brief description of the above process. When encountering practical problems, comprehensive solutions cannot be found in these published technologies. These specific problems not only hinder Revit's data output but also affect subsequent display and management. The aforementioned problems are properly resolved in the embodiments of this invention. Summary of the Invention

[0004] This invention proposes the concept of a basic geometric unit. In terms of data, the ID of the basic geometric unit is the primitive ID + material ID. This avoids the fatal problem that a single primitive contains multiple materials, causing the output basic geometric ID to be unable to distinguish the geometric positions of different materials.

[0005] Based on this, the present invention provides a method for outputting model data in Unity program creation. Using the Revit secondary development interface - IExportContext provided by Autodesk, and by writing context parameters and adding methods for data extraction and processing within the context, all target data is output, including the following steps:

[0006] The Start() step requires initializing the data dictionary and context instance, and storing project information, a collection of all project elevation information, project base point information, etc.

[0007] The OnViewBegin() step is used to set and store LOD (Level of Detail) information;

[0008] The OnElementBegin() step obtains the ID value of the output geometric element (component Element), namely ElementId, which is used to obtain the ID value of the component in the model;

[0009] The OnMaterial() step retrieves all MaterialNodes in the model component corresponding to the current ElementId, and then obtains the UniqueId of the corresponding Material and a series of information about the material based on each node.

[0010] The OnFaceBegin() step takes a facenode object as a parameter to obtain the face node;

[0011] The OnPolymesh() step, with PolymeshTopology as the object parameter, obtains all vertex data, face data, normal data, and UV data of the smallest object unit;

[0012] The OnElementEnd() step, with ElementId as the parameter, will complete the preparation of all output data, including data processing of vertices and vertex sequences, data processing of vertex normals and normal sequences, calculation and processing of vertex UVs, and acquisition of custom data;

[0013] The OnViewEnd() step ends the call to the View object;

[0014] The Finish() step outputs all the prepared data to a JSON file.

[0015] In the OnViewBegin() step, the user sets a Level of Detail (LOD) from 0 to 15 on the interface of the output program to output at this level of detail.

[0016] In the OnElementBegin() step, the model is retrieved and called using this value, and the UniqueId of the component is obtained to prevent duplicate ElementId names.

[0017] In the OnMaterial() step, a series of information includes: ambient diffuse color (i.e., the representative color of the material), transparency, texture coordinates, texture file, and the path of the texture file.

[0018] In step OnPolymesh(), the smallest object unit is an Element UniqueId + "_" + MaterialUniqueId object.

[0019] In the OnPolymesh() step, the geometric output data is established as follows: First, the vertex set is deduplicated to obtain the deduplicated PTS vertex set and the corresponding dictionary; PolymeshTopology.GetFacets() is called to traverse all obtained Facets (faces in the basic geometric unit), and a lookup relationship is established between the vertices of the Facet and the PTS vertex dictionary. The positions of the lookup dictionary are arranged and stored according to the order of traversing the Facets and the order of the vertices arranged in the Facet itself, thus obtaining the vertex sequence of all points in the mesh corresponding to the Facets; when traversing all Facets, the value of the DistributionOfNormals parameter is used to determine the facet. The method for recording normal vectors is as follows: when the value is OnePerFace or OnEachFacet, the normal vector values ​​of the three vertices are taken as the values ​​of the first vertex of the object or the current face. When the value is AtEachPoint, the vertex normal vector values ​​are obtained according to the vertex order of the facet. A set and dictionary of vertex normal vectors are obtained based on the different vertex normal values. When traversing all facets, the UV coordinate values ​​corresponding to each vertex are obtained through PolymeshTopology.GetUVs(). The physical meaning of this value is the texture coordinate value of the texture file used by this facet, not the relative coordinate value of the uvw coordinate system in the traditional sense. The set of this value is used to build a UV set and a dictionary.

[0020] In the OnElementEnd() step, before generating the complete UV set corresponding to the mesh, the UV coordinate values ​​in the UV set of each corresponding basic geometric unit obtained in the OnPolymesh() process method are divided and remainder calculated on the same coordinate axis by the total pixel coordinate values ​​of the texture file corresponding to the facet of this basic geometric unit, and the original UV set is replaced. Then, duplicates are removed and sequence data is calculated to finally obtain the UV array and UV sequence array, thereby completing the preparation of all geometric information.

[0021] In the OnElementEnd() step, the custom data for each basic geometric unit is the same, all corresponding to ElementId. However, the material and geometric information of all basic geometric units under the same ElementId may not be the same.

[0022] In the Finish() step, the Newtonsoft.Json library file is used to output JSON data.

[0023] The method of this invention outputs data in steps according to the output process of the IExportContext interface. Due to the calls to objects in the process, a method is generated to distinguish objects (store them in a table) by using the object's GUID + the material's GUID as the ID name of the smallest object unit. Furthermore, in order to output as much data as possible during the output process, a method of storing the data of a single object is adopted to ensure the possibility of outputting all data under a certain LOD setting.

[0024] The method stores all data, combining the object's GUID and material ID to create the smallest unit object's ID name. Its advantage lies in more comprehensively and accurately preserving all object features. Another technical advantage is that during execution, IExportContext first iterates through the object's GUID, simultaneously iterating through all material IDs on that object. This can lead to situations where an object has multiple materials. From a physical perspective, similar situations can occur, such as welding different metal objects together, with different materials on either side of the weld joint, yet using a single object ID. Using the object's GUID would make it appear as one object, but it actually represents two different welded materials, requiring separate storage. This is a unique phenomenon caused by Revit's object representation method and IExportContext's data output process. This method specifically studies these characteristics and applies the invention's approach based on technical features and physical laws. In addition, the aforementioned storage is also a feature of the method of this invention. When IExportContext is called, because the amount of data output by Visual Studio (VS) when calling the JSON output interface is limited by VS, the interface, and the system itself, an overflow phenomenon may occur when the output quantity is very large. This is caused by system characteristics and can also be regarded as a system error.

[0025] The method of this invention avoids the overflow caused by the excessive amount of data of a single object by standardizing the storage of folders and files. In other words, each object is stored as a file, and the files are placed in regular folders.

[0026] The present invention has the following positive and beneficial effects:

[0027] First, it expands the data medium of Revit data. While displaying and managing Revit models within Revit is extremely convenient, Revit is a native program and cannot share design results across networks. In an era where BIM design is gradually replacing traditional design, the limitations of native operation are obvious. By exporting Revit models, encapsulating and displaying them, the problem of information transmission is solved (encapsulated files facilitate information flow), and the problem of reading information in a network environment is also solved, increasing the methods for dissemination and management.

[0028] Secondly, it increases the usability of building information. From the entire lifecycle management of construction to digital twins, from VR, AR, MR to the metaverse, the key to utilizing building information lies in what the data is, how it is stored, and how it is accessed. This technical solution includes a complete set of methods for outputting, storing, and accessing building information. From Revit to JSON, and then to Unity graphics, it perfectly illustrates the methods for utilizing building information. Attached Figure Description

[0029] A more complete understanding of the invention and its accompanying advantages and features will be more readily apparent from the accompanying drawings and the following detailed description, wherein:

[0030] Figure 1 This is a flowchart illustrating the method of outputting JSON files from Revit and displaying and managing them in 3D engines such as Unity3D, according to the present invention.

[0031] Figure 2 This is the overall process of Revit outputting data through IExportContext in the method of this invention.

[0032] Figure 3 This refers to the output content of each process in the reivt output process of the method of this invention.

[0033] Figure 4 This is a diagram showing the composition of the global data framework of this invention.

[0034] Figure 5 This is a diagram showing the composition of the geometric dataset in the method of this invention.

[0035] Figure 6 This is a structural diagram of the output folder in the method of this invention.

[0036] Figure 7 The method of this invention is used to output and display the construction model results of the Tongzhou Sub-center Hub Station.

[0037] Figure 8 The method of this invention is used to output and display the effect diagram of a railway sleeper system model at a certain station.

[0038] Figure 9 The screenshots show the results of the demonstration in the new airport city, using the method of this invention. Detailed Implementation

[0039] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0040] The technical solution of the invention consists of four parts, see below. Figure 1 :

[0041] (1) Revit data output

[0042] First, Revit data output includes geometric information, design information from the model building process, and custom information carried by the model as a carrier of information. Geometric information includes vertex spatial location data, vertex index data, normal vector data, normal vector index data, UV data, texture data, and map data describing Revit geometry. The model's design data mainly includes: model type information, family library information, elevation data, and data generated based on design principles. Custom data can include information that needs to be attached throughout the model's lifecycle, such as the construction unit of the model and the management unit of the corresponding real entity. This information is stored after the model is built through attachment and is associated with the model's retrieval ID.

[0043] The above three categories of information are output separately. In Revit, this requires combining API calls. According to the Revit SDK provided by Autodesk (Revit's manufacturer), there are roughly two methods for outputting geometric data from Revit-generated models: IExportContext and IExportElement. IExportContext allows you to call the entire view object of the Revit file by editing the parameters of the Context, obtaining data during the view's generation process. IExportElement, on the other hand, outputs pure geometry from the Revit database, using the BREP method to obtain the calculated data from analytical to discrete geometry. In summary, IExportContext uses data already drawn by the Revit graphics engine during output, thus ensuring a certain level of visualization quality. IExportElement, however, uses the BREP method to transform analytical geometry into discrete geometric data; therefore, it is not the result data drawn by the graphics engine, and thus its visualization is not detailed or comprehensive. For example, when outputting UV data, it does not correspond to vertices from the same process, making this UV data unusable in the graphics engine. Therefore, most publicly available technical processes use the IExportContext procedure method for output, and this invention also uses this method; if IExportElement is used, it is naturally impossible to obtain usable UV data.

[0044] In existing technical solutions that use the IExportContext process method for output, no specific solution is proposed for recording the IDs of objects (components, or Element in Revit objects), or the Revit ElementId or component name is directly used for recording. Furthermore, no method for storing and recording materials is mentioned. These technical methods clearly overlook the case where different materials are used within a single component, and this part is omitted during the Revit output process. This invention effectively supplements this omitted component information through an update method.

[0045] The biggest difference between this technical solution and the previously disclosed technical solutions is that it proposes the concept of a basic geometric unit. In terms of data, the ID of the basic geometric unit is the primitive ID + the material ID. This avoids the fatal problem that a single primitive contains multiple materials, which makes it impossible for the output basic geometric ID to distinguish the geometric positions of different materials.

[0046] Technical solution:

[0047] This solution uses the Revit secondary development interface provided by Autodesk - IExportContext. By writing the parameters of the context and adding methods for data extraction and processing during the context process, all target data can be output.

[0048] IExportContext includes nine procedural methods that connect to the context: Start(), OnViewBegin(), OnElementBegin(), OnMaterial(), OnFaceBegin(), OnPolymesh(), OnElementEnd(), OnViewEnd(), and Finish(). These nine methods form a complete flow based on the context. See [link to documentation]. Figure 2 IExportContext is a necessary method for the secondary development interface proposed by Autodesk. How to edit the context program within each procedural method to achieve its own functionality is the innovation point of each technical solution, and IExportContext is the carrier of these innovations. The main outputs of each part are shown below. Figure 3 The content of each output section is related to the design of the JSON data in the second part of the overall technical solution.

[0049] The `Start()` method initializes the data dictionary and context instance, and stores project information, a collection of all project elevation information, and project base point information. This process is an initialization step, and the information obtained is all global project information, with the project scope being the content scope of the Revit file.

[0050] OnViewBegin() is used to set and store LOD (Level of Detail) information. Users set a LOD level from 0 to 15 on the output program's interface for output at that level. After OnViewBegin() starts, it retrieves the LOD value from the form variables of the above process and sets it in the variable of this method. This value is then used as the level of detail for model data output. After output, the value is saved in a JSON file, thus allowing users to customize the output model's level of detail. If no customization is made, the method defaults to setting it to 7. Testing shows that while level 7 is a moderate level of detail, it already represents a fairly detailed model. In this invention, if no selection is made, level 4 is used by default for output, which provides a acceptable level of detail.

[0051] The `OnElementBegin()` method obtains the ID value of the output geometric element (component element), i.e., `ElementId`. This value is used to obtain the ID value of components in the model, and is used for model retrieval and retrieval. It also retrieves the component's `UniqueId` to prevent duplicate `ElementId` names. From this point onward, all Revit elements are iterated through in the `View` object. In publicly available technologies, this value is used as the ID value of the geometric output element, or an undisclosed technical detail is used to store or retrieve geometric components.

[0052] From the overall fixed flow of IExportContext execution, the OnElementBegin procedure method precedes the OnMaterial procedure. Therefore, a model component with a specific ElementId can contain multiple MaterialNodes from the OnMaterial method. Each node is retrieved using a single specific MaterialID. This results in the inability to retrieve and obtain objects from MaterialNodes using ElementId, but only objects with the ElementId. Consequently, it is impossible to distinguish the geometric parts of different materials on the object, and data management for different materials cannot be implemented. Secondly, ElementId is the element ID for retrieving RVT files in Revit, but this value may be duplicated in different RVT files. Therefore, in this method, after obtaining the ElementId through the OnElementBegin() procedure method, the UniqueId of the current component is obtained through the ElementId and used as part of the output component ID. This avoids the possibility of duplicate ElementId names when outputting multiple Revit data files (RVT files).

[0053] The OnMaterial() method retrieves all MaterialNodes within the model component corresponding to the current ElementId. Then, based on each node, it obtains the UniqueId of the corresponding Material and a series of material-specific information, such as the ambient diffuse color (the representative color of the material), transparency, texture coordinates, texture file, and texture file path. Note that the texture coordinates mentioned here are the pixel coordinates of the texture file.

[0054] The uniqueId of the material and the uniqueId of the current element are combined to form the name and retrieval ID of the current object (a sub-component of different materials under the current model component). This is the difference between the method of this invention and other technical methods. In summary, obtaining the element uniqueId instead of the elementID is one difference; using the element uniqueId + "_" + material uniqueId, with the two uniqueIds connected by an underscore (_), as the ID of the basic geometric unit, and outputting it as the basic geometric unit, is the second difference.

[0055] Furthermore, this method includes a special processing method for texture coordinates that is not covered in publicly available technical solutions. All coordinate methods provided by the Revit SDK for texture mapping are not UV-relative coordinates as defined by computer graphics, but rather pixel coordinates calculated based on the texture file size. The method of this invention includes a method for converting pixel coordinate values ​​into relative coordinate values ​​in the UVW coordinate system, which will be explained in the subsequent process steps.

[0056] The OnFaceBegin() procedure is the fifth step of IExportContext. The parameter of this step is a facenode object, namely OnFaceBegin(FaceNode node), which obtains the face node and thus obtains the face. The face is not provided in the method of this invention.

[0057] The OnPolymesh() procedure is the sixth step of IExportContext. The parameter for this step is a PolymeshTopology object. Through the properties and methods of the PolymeshTopology object, you can obtain all vertex data, face data, normal data, and UV data of the ElementUniqueId+"_"+Material UniqueId object (hereinafter referred to as the smallest object unit). The following is the specific method for creating the geometric output data:

[0058] The `PolymeshTopology.GetPoints()` method provides a vertex set containing all vertices of the basic geometric unit. Since mesh faces on an object's surface may share vertices, the vertex set is first deduplicated to obtain a deduplicated set of PTS vertices and a corresponding dictionary. Then, `PolymeshTopology.GetFacets()` is called to iterate through all obtained Facets (faces in the basic geometric unit), establishing a lookup relationship between the Facet vertices and the PTS vertex dictionary. The resulting dictionary positions are then sorted and stored according to the order of facet traversal and the order of the facet's own vertices, thus obtaining the vertex sequence of all mesh points corresponding to the facet faces. While traversing all facets, the distribution... The value of the `ionOfNormals` parameter determines the method for recording facet normal vectors. When the value is `OnePerFace` or `OnEachFacet`, the normal vector values ​​of the three vertices are taken as the values ​​of the first vertex of the object or the current face. When the value is `AtEachPoint`, the vertex normal vector values ​​are obtained according to the vertex order of the facet. A set and dictionary of vertex normal vectors are obtained based on the different methods of taking vertex normal values. When traversing all facets, the UV coordinate values ​​corresponding to each vertex are obtained through `PolymeshTopology.GetUVs()`. The physical meaning of this value is the texture coordinate value of the texture file used for this facet, not the relative coordinate value of the uvw coordinate system in the traditional sense. A UV set and dictionary are built from this set of values. The above is a preliminary description of the method for obtaining geometric data. Since the geometric range of the smallest object unit is used when traversing facets, all sets and corresponding dictionaries are stored and retrieved using the name `ElementUniqueId + "_" + Material UniqueId`. This ensures the full output of all geometric shapes of different materials, which is the biggest advantage of this invention.

[0059] OnElementEnd() is the seventh step of IExportContext. The parameter of this step is ElementId. This step will complete the preparation of all output data, including the data processing of vertices and vertex sequences, the data processing of vertex normals and normal sequences, the calculation and processing of vertex UVs, and the acquisition of custom data. The PTS set generated in OnPolymesh() and the sequence data serialized by facet can describe how each triangle facet of the spatial geometry is arranged, i.e., the PTS array and the corresponding sequence array of PTS, which are the vertex data results. This process method traverses each ElementId, that is, it traverses each basic geometric unit, and stores the PTS and the corresponding sequence array of PTS according to the method of the basic geometric unit, forming the vertex data set of all meshes. The vertex normal value set generated by OnPolymesh() is deduplicated to obtain a vertex normal value and dictionary. Then, each vertex value in the non-deduplicated vertex normal array is looked up with the deduplicated vertex normal dictionary to obtain the sort position in the dictionary, resulting in a sequence set. Then, the deduplicated vertex normal array and sequence array of all meshes are formed in the traversed basic geometric units. The calculation of UV coordinate values ​​includes its own algorithm. The texture coordinate value corresponding to each facet has been obtained in the OnMaterial() process method. This value is in the facet. The method uses the total pixel coordinates of the texture file used on the facet, while the UV coordinates obtained in the OnPolymesh() process are the pixel coordinates of the texture file corresponding to this facet. To obtain the coordinates of the traditional uvw coordinate system, before generating the complete uv set corresponding to the mesh, this invention performs a division and remainder calculation on the same coordinate axis between the UV coordinates of the uv set of each corresponding basic geometric unit obtained in the OnPolymesh() process and the total pixel coordinates of the texture file corresponding to this basic geometric unit on the facet. This calculation replaces the original uv set, and then deduplication and sequence data are calculated to finally obtain the UV array and UV sequence array, thus completing the preparation of all geometric information. When traversing ElementId, the GetOrderedParameters() method is called to traverse and obtain the attribute names and attribute values ​​of all custom data of the current Element, which are saved separately and saved to the array and dictionary of each corresponding basic geometric unit according to the ID of the basic geometric unit.

[0060] Special Explanation: The custom data for each basic geometric unit is identical because they correspond to ElementId. The material and geometric information of all basic geometric units under the same ElementId may differ. This highlights the most important technical advantage of this invention: minimizing differences in the data. Furthermore, when processing UV data, this invention does not directly use the UV pixel coordinates obtained from PolymeshTopology.GetUVs() in the OnPolymesh() procedure. Instead, it obtains the relative UV coordinates by dividing and taking the remainder of the total pixel coordinates of the corresponding pixel file. This corresponds to the physical meaning of many graphics engines. It should be noted that in computer graphics, UV coordinates are not specific to facets but to the entire mesh geometry. That is, a mesh corresponds to a complete texture file. However, Revit does not follow this common sense in graphics; instead, it maps each facet in the mesh to a texture file, and the UV coordinates of each texture file on that facet are based on that facet. The method of this invention is based on the data extraction of the results calculated by the Revit graphics engine, so it cannot change this inherent deficiency. However, the updated method is still applicable after Revit changed to use mesh to correspond to a single texture file.

[0061] OnViewEnd() is the eighth procedure method in the IExportContext context flow. This method ends the call to the View object. The method of this invention does not perform context programming in this procedure method.

[0062] Finish() is the last procedure method in the entire IExportContext process. In this procedure, all the prepared data is output as a JSON file. The method of this invention uses the commonly used Newtonsoft.Json library to output the JSON data.

[0063] This concludes the first part, which covers the entire process of outputting model data in Revit.

[0064] (2) The design of JSON usage

[0065] By writing the context from the Revit IExportContext API interface and completing the interface call, the Revit geometric data is obtained. As mentioned earlier, the data not only includes geometric data, but also design information data and custom information data. How to store these three types of data is another challenge in the technical solutions of this field.

[0066] From most publicly available technical solutions, it can be seen that when calling IExportContext for context editing, the .NET support library for JSON files is also invoked. There are many types of support libraries, but almost all of them output a single JSON file, encapsulating and saving geometry (which also contains multiple data categories), non-geometric information (design information), and custom data through different objects and arrays within a single JSON file. This method was initially used for storage, but in actual output, it was found that some models had extremely large single-component and overall output data volumes. If a single data segment (an instance of a single object or array) exceeded 300MB, and the total data volume exceeded 1GB, the JSON support library could not provide output. Therefore, in actual output, some optimizations to the data segment output method are needed to ensure efficient output of all data. These methods are not mentioned in currently available technologies.

[0067] How to include serialized objects and arrays that need to be output in the JSON file also needs to be designed. This method not only affects the output effect, but also the effect of data display and management in the 3D graphics engine.

[0068] Using JSON files as the data output carrier, two techniques in the method of this invention are specifically matched to the method of this invention.

[0069] First, the path for storing JSON files is designed; second, the design methods for data objects and arrays in each JSON file are discussed.

[0070] When exporting model data from Revit, publicly available technologies lack detailed descriptions of how to store JSON files. Initially, the Revit data file (RTVT file) is treated as a corresponding JSON file in the Finish() process for centralized output of geometry, design information, and custom data. However, testing across multiple projects has revealed a significant increase in data volume after Revit components are represented by discrete geometry vertices, normals, and UVs. A typical RVT file of tens of megabytes can generate gigabytes of geometric data. This situation worsens when the RVT references family files from a family library, especially when the family file contains a large number of mesh geometry faces (each geometry has many mesh faces and is referenced multiple times), resulting in an extremely large amount of geometric data across all meshes. This can lead to freezes and crashes during the export process.

[0071] To address the aforementioned issues, the present invention modifies the output strategy by storing geometric and non-geometric data separately. Geometric data is stored separately for each mesh (corresponding to a basic geometric unit). All JSON files are retrieved based on their filenames and the logical correspondence of the data objects within the JSON. This solves the problem of a single JSON file having a large data volume that cannot be output.

[0072] Each geometric and non-geometric file specifies the output content, which can be called and managed in the data engine according to its physical meaning.

[0073] The designed JSON files are divided into two categories. The first category is the global data file, the contents of which can be found in the list of global data frames and... Figure 4 (Diagram of the global data framework content); another type is geometric datasets, see the list of geometric datasets for details. Figure 5 (Diagram showing the composition of the geometric dataset). The data column tables for the two categories mentioned above are as follows:

[0074]

[0075]

[0076]

[0077]

[0078] Both of the above data lists follow the data class declaration procedure in C#. In actual use, you only need to replace the Chinese characters with variable names that conform to the C# language.

[0079] The output includes three parts:

[0080] a. Geometric Data: The file is output separately and contains subclass data from the geometric dataset class. The file name uses "Geometric ID-Material ID" from the object attribute class (here a connector is used, which is different from the underscore in the output program). Before outputting this file, create a folder with the same name as the Revit file name, and store all the above geometric data files in this folder.

[0081] b. Global Data: This file corresponds to a Revit filename. Each Revit file contains global data specific to that file. When outputting, the global data is stored in the same folder as the Revit file. It seems that the global data framework's class should be used for output.

[0082] c. Texture files: Texture files are not part of the JSON. As part of the project output, to ensure that the texture files are correctly referenced in the 3D data engine, first create a folder named "texture" in the same folder as the Revit file, and extract the texture files according to the texture paths in the material set of the global JSON data and store them in the texture folder.

[0083] This concludes the data output and saving process, achieved through the use of JSON files and folders, and the design of the entire output data. See the folder structure diagram for the output of multiple Revit file projects. Figure 6 .

[0084] (3) Lightweighting of geometric data

[0085] Existing technical solutions involve two types of data processing: the first is mesh splitting; the second is geometric processing within the mesh. The first type concerns data storage and does not involve deformation; the second type deals with the spatial relationship of mesh facets, reducing the data volume through facet reduction. This invention employs the second type of technology, without involving specific facet reduction methods, but rather implementing classification during the facet reduction process to obtain more appropriate model data.

[0086] By displaying the output data, it was found that some of the geometric files were extremely cumbersome and large, indicating that some 3D graphics engines could not read them or display them properly. Therefore, the method of this invention takes this into account and implements a lightweighting method for the output data. This method uses the commercial software PiXYZ-Studio for lightweighting.

[0087] Since the geometric and non-geometric information has been separated and saved in the JSON file in the method of this invention, this method only needs to import the geometric data of the model into PiXYZ-Studio, and then use Python scripts to perform lightweight processing on the geometric data one by one.

[0088] The mesh is divided into three segments based on the number of vertices, and each segment is processed using a different method:

[0089] A. Number of vertices greater than 65536

[0090] To adapt to hardware capabilities, graphics engines divide the number of vertices in a single mesh into 65536 (2^16). Advanced hardware supports displaying more than 65536 vertices, while low-end hardware struggles to handle such displays. Therefore, graphics engines also impose limitations on this value. To ensure compatibility across more graphics engines and hardware, this invention's method lightweights mesh geometry data with more than 65536 vertices to within 65536 vertices. Therefore, a Python script is used to call `algo.decimateTarget(mesh,["triangleCount",a],b1,b2,b3,b4,b5,C1,C2)`, where `a` is the target number of triangles, `b1`, `b2`, `b3`, `b4`, and `b5` are weight parameters (default values ​​are selected), `c1` and `c2` are texture coefficients (default values ​​are selected), and `mesh` is the imported geometric mesh object. Since the target of this method is a triangular facet, but the target value in the method of this invention is the number of vertices, a trial calculation method is adopted. Each trial calculation decreases the value of a by 500 based on the previous trial calculation, and the trial calculation stops when the number of vertices is less than 65536.

[0091] B. The number of vertices is between 5000 and 65536.

[0092] This section uses gradient calculation, assigning 5000 to the value 1 and 65536 to the value X (X is selected between 0.5 and 1). The values ​​are chosen based on the data lightweighting results. The gradient values ​​from 5000 to 65536 are calculated based on the number of vertices in the mesh, and then `algo.decimateTarget(mesh, ...)` is called.

[0093] ["ratio",ratioV],b1,b2,b3,b4,b5,C1,C2), where ratioV is the gradient value.

[0094] C. Number of vertices is less than 5000

[0095] No processing is performed within this range.

[0096] Segmented computation ensures both the lightweighting of large volumes of data to a displayable level and the preservation of the integrity of small volumes of data. Unlike the more popular method of splitting mesh surfaces, the method of this invention retains the fundamental condition that a mesh is a geometric component. Splitting mesh surfaces is not conducive to subsequent data management; however, the display effect may not be as good as the method of splitting mesh surfaces.

[0097] After processing the geometric data, the Python script will add a folder named "Lightweight" under the original geometric data file, and output the lightweight geometric data in the JSON geometric data file format in Part 3, with the file name being the same as the original file name.

[0098] (4) Unity's display methods

[0099] Among the publicly available methods for reading JSON files in Unity3D, there are also methods that use WebGL for model rendering and management. However, the common approach is to read the data as an asset and then use Unity3D's packaging tools for display and management. This method typically calls the .NET JSON support library mentioned above. In the Unity3D program, the geometric information from the JSON file is read into Unity and saved as a mesh object within the asset. Then, texture data is read, a material sphere is created and saved to the asset, and material data from the material sphere is attached to the mesh to form materials and textures. When outputting to the Unity program, the material and geometric data are packaged together. During Unity's runtime, this packaged asset data is read into the program for display.

[0100] This method is typical of Unity programming, but it lacks versatility. This invention addresses this problem by proposing a completely new technical solution that greatly improves the versatility of existing technologies.

[0101] The Unity presentation method involved in this invention is an innovative application of the output file proposed by this invention. Because the output file design adopts some fixed methods, multiple Revit files of each project can be output in the same way and stored in the same folder.

[0102] Based on the above characteristics, the present invention proposes a novel file display method, which outputs the Unity output program as a display program that can read customized geometric data and automatically generate models.

[0103] The traditional workflow for creating a Unity demo involves importing a file (usually FBX) containing geometric data that Unity can read into the Assets folder. Before exporting it as an executable, Unity imports the FBX file into Unity's editing mode to generate visualized geometric data, which is then placed into the scene. If a non-FBX geometric data file, as mentioned in this invention, is encountered, a script can be used to import the geometric data into Assets or directly into the scene during the editing stage, forming a mesh object and attaching corresponding materials. After completing these steps, a camera, motion controllers, lights, and effects are added, and then the scene is exported. This approach presents a problem: whenever such an output requirement arises, it must go through the Unity editor, making it an essential tool for converting geometric data into mesh objects within Unity.

[0104] This invention changes the traditional production process. The conversion script is attached to an object that exists from initialization, such as a camera or an empty object, but the conversion is not performed. Instead, a relative directory for the conversion is specified in the program, or a method of System.Windows.Forms is enabled, allowing the user to select the geometry file to be imported (in this invention, it is a JSON file). Then, a camera, light source, motion controller (to control the camera), canvas, and post-processing effects are added in the editor (this invention uses Unity's general rendering pipeline), and the output is an executable file.

[0105] The advantage of this method is that Unity's presentation program no longer needs to be specifically designed for the presentation of Revit output files for a single project. All Revit projects that output geometry files using the method described in this invention can be adapted to the same Unity presentation program. Unity programmers no longer need to participate in the presentation creation work for a single Revit project; they only need to distribute the output presentation program to the users who need it to open the data files for presentation.

[0106] To achieve the above functionality, the following steps are required:

[0107] (1) Create a preloading script file. In the script, the filename of the loaded model is used as a variable. The variable can be assigned a relative path to the output executable file plus a fixed filename, or the `usingSystem.Windows.Forms` namespace can be used to call Windows.Forms methods to open a file selection dialog during script execution, allowing the user to choose. The script calls the JSON support library to read JSON objects. Based on the object name, it batch converts geometric data into Unity's internal `MeshFilter` objects and converts the material data corresponding to the mesh into Unity's internal `Material` objects. This invention uses Unity's universal rendering pipeline (URP), so a universal shader needs to be created in the `resource` directory. When creating the `Material` object, this shader is used as the `Material`'s shader. This step is crucial, affecting batch preloading, and is an important part of this invention. If the script uses a relative path, the code segment needs to be placed in the `Awake()` or `Shart()` process. If the file selection is done using Windows.Forms, it can be extended to the `Update()` process, triggered by a shortcut key or a canvas button.

[0108] (2) Attach the above preloaded script to an object that appears with the scene during initialization. The simplest way is to create an empty object and attach the script to it.

[0109] (3) Add a light source and a camera

[0110] (4) Write scripts to control the camera and control the position and angle of the camera using the keyboard or mouse.

[0111] (5) Add post-processing effects: First, add global illumination processing, and then add skybox effects under urp.

[0112] (6) Add a canvas and several empty buttons on it as camera quick-access buttons. Then add motion control buttons, such as forward and stop. Attach a script to the empty object created in (2) and write the motion control code into the script. Triggering the quick-access button action is also a feature of this invention. Since the quick-access coordinates are determined based on the scene coordinates in the Revit project file, they cannot be fixed before being output as a display program. Therefore, this invention proposes an external file for the quick-access coordinates of the quick-access button, stored in the geometry data folder. When the script is executed, this external file is also read in, and the quick-access coordinates written in the external file are read and assigned to the triggered button. The name of the quick-access button is also read and written onto the canvas button, thus achieving the goal of dynamically managing the scene.

[0113] (7) Write a program with the following functions: call Windows.Forms and let the user select all non-geometric data files (JSON format) output by the plugin in the file selection box. If there are multiple Revit files for a project, they are placed in one folder. Write the path name of the non-geometric data file read into a newly created txt text file, one non-geometric file per line, and store it in the same folder as the non-geometric data folder, and give it a unified name, such as allinone.txt.

[0114] (8) Based on the content in (7), modify the script program in (1) so that the relative folder + fixed file name points to the txt specified in (7), and read the path name in the txt text and provide it to the file variable of the conversion script; if Windows.Forms is used, the file points to the txt text, and the path name in the txt text is also read and provided to the file variable in the script conversion program for geometric conversion.

[0115] (9) Add a judgment on whether the data has been processed by lightweight in the script in (2). Determine whether there is a "lightweight" folder under each Revit output folder. If there is, import the geometric data in the lightweight folder.

[0116] (10) Output as an executable file.

[0117] The method in this invention outputs the construction model of the Tongzhou Sub-center Hub Station. The construction model consists of 154 Revit files (RTV files), with a data size of 4.7GB. Levels 0-7 (LOD) were output for each file. After output, the model was lightweighted according to the lightweight model proposed in this invention, resulting in the corresponding geometric data, as shown in the table below. The geometric data was then opened using Unity's encapsulated data, and the effects before and after processing were compared. The Unity roaming frame rate was improved. The fact that the data can be displayed normally demonstrates the feasibility of this method, and the improved frame rate proves the effectiveness of the lightweight data.

[0118]

[0119] Applications of the method of this invention in several scenarios:

[0120] The construction model of the Tongzhou Sub-center Hub Station consists of 154 Revit files, totaling 4.7GB of data. Output is based on Level 0-7 Lods (LOD). Taking Level 4 LOD as an example, the total number of vertices is 101.4 million, and the number of triangles is 146.5 million. After lightweighting, the total number of vertices is 77.4 million, and the number of triangles is 114 million. The roaming frame rate before lightweighting ranges from 4-10 frames per second, while the frame rate after lightweighting ranges from 8-15 frames per second. Figure 7 The image shows the result of Level 4 lightweight rendering in a Unity application. This effect is achieved using the built-in rendering pipeline, not the output of the general rendering pipeline.

[0121] A railway sleeper system model for a certain station: One Revit file, 147MB in size, exported at level 4 LOD, outputting 83.84 million vertices and 127 million triangles. After processing, the total number of vertices is 15.71 million and the number of triangles is 22.73 million. The frame rate before processing was 40 frames per second; after processing, the frame rate jumped to 100 frames per second. The sleepers showed virtually no deformation. Figure 8 As shown.

[0122] The model of the new airport station was also output according to the method, but no data comparison was performed, such as... Figure 9 As shown.

[0123] The present invention can be implemented according to the above embodiments, but its application scope is not limited thereto. The above embodiments are merely illustrative of specific implementations of the present invention under certain specific circumstances, but should not be construed as limiting the application scope of the present invention.

Claims

1. A method for outputting model data in unity program production, using the revit secondary development interface-IExportContext provided by Autodesk, by writing the parameters of the context and adding the data extraction and processing method in the process of the context, the output of all target data is carried out, including the following steps: Step Start(), which needs to initialize the data dictionary, the context instance, and store the project information, the project all elevation information set, and the project base point information; Step OnViewBegin(), which is used to set and store the LOD information; Step OnElementBegin(), which obtains the ID value of the output geometry unit, that is, ElementId, which is used to obtain the ID value of the model component; Step OnMaterial(), which obtains all MaterialNode in the component according to the current ElementId corresponding to the model component, and then obtains the UniqueId of the corresponding Material and a series of information for the material according to each node; Step OnFaceBegin(), which takes the facenode object as a parameter to obtain the face node; Step OnPolymesh(), which takes PolymeshTopology as an object parameter to obtain all vertex data, face data, normal data and UV data of the smallest object unit, wherein the smallest object unit is Element UniqueId+"_”+Material UniqueId object; The manner of establishing the geometry output data in this step is: firstly, the vertex set is de-duplicated to obtain a de-duplicated pts vertex set and a corresponding dictionary; PolymeshTopology.GetFacets() is called to traverse all obtained Facets, which are the facets in the basic geometry unit, the vertices of the Facet are queried with the pts vertex dictionary, and the queried dictionary position numbers are arranged and stored according to the traversal facet order and the vertex order arranged by the facet itself, so as to obtain the vertex sequence of the facet corresponding to all points of the mesh; when traversing all facets, the method of recording the normal vector of the facet is judged according to the value of the DistributionOfNormals parameter, when the value is OnePerFace or OnEachFacet, the normal vector values of the three vertices are taken as the values of the first vertex of the object or the current facet, when the value is AtEachPoint, the values of the vertex normal vector are obtained according to the vertex order of the facet, and a vertex normal vector set and a dictionary are obtained according to the vertex normal value in different ways; when traversing all facets, the UV coordinate values corresponding to each vertex are obtained by PolymeshTopology.GetUVs(), the physical meaning of the value is the texture coordinate value of the texture file used for the facet, and it is not the relative coordinate value of the traditional uv coordinate system, and a uv set and a dictionary are established according to the uv coordinate value set; Step OnElementEnd(), taking ElementId as a parameter, completes all output data preparation work, including vertex and vertex sequence data processing, vertex normal and normal sequence data processing, vertex UV calculation processing, and custom data acquisition; In this step, before generating the complete uv set corresponding to the mesh, the UV coordinate value in the uv set corresponding to each basic geometry unit obtained in the OnPolymesh() process method is divided by the total pixel coordinate value of the texture file corresponding to the facet of the basic geometry unit in the same coordinate axis, and the original uv set is replaced, and then de-duplicated and sequence data is calculated, finally, the UV array and the UV sequence array are obtained, so as to complete all geometry information preparation work; Step OnViewEnd(), ending the call to the View object; Step Finish(), outputting all prepared data to a JSON file.

2. The method of claim 1, wherein, In step OnViewBegin(), the user sets a certain level of LOD from 0-15 levels on the interface of the output program to output at this level of detail.

3. The method of claim 1, wherein, In step OnElementBegin(), the model is retrieved and called through the ID value, and the UniqueId of the component is obtained to prevent ElementId from being renamed.

4. The method of claim 1, wherein, In the step OnMaterial(), a series of information includes: diffuse color ambient, transparency, texture coordinates, texture file and the path of the texture file.

5. The method of claim 1, wherein, In the step OnElementEnd(), the custom data of each base geometry element is the same, which corresponds to ElementId. The material information and geometry information of all base geometry elements under the same ElementId are not necessarily the same.

6. The method of claim 1, wherein, In the step Finish(), the output of JSON data is carried out by using the Newtonsoft.Json library file.

Citation Information

Patent Citations

  • BIM model lightweight display method based on WebGL

    CN112465958A

  • BIM mass model display method based on WebGL + VR

    CN113901367A