A method for quickly generating a collider based on Unity model interaction

By importing 3D models into Unity and using recursive algorithms and C# technology to generate Colliders, the problem of time-consuming and labor-intensive manual creation is solved, achieving rapid generation and correct physical interaction.

CN116524164BActive Publication Date: 2025-11-21齐丰科技股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310512434.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-09
Publication Date
2025-11-21
Estimated Expiration
2043-05-09

AI Technical Summary

Technical Problem

Manually creating Collider components for complex models in Unity is time-consuming and labor-intensive, impacting development efficiency.

Method used

By importing a 3D model, entering edit mode, selecting the physics component, and clicking the "Create BoxCollider" button, a Collider is generated using a recursive algorithm and C# technology. The properties and position are then adjusted to ensure that collisions are correctly prevented.

Benefits of technology

It enables rapid generation of Colliders, reducing the workload of developers, improving development efficiency, and simplifying the physical interaction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116524164B_ABST
    Figure CN116524164B_ABST
Patent Text Reader

Abstract

The application provides a method for quickly generating Collider based on Unity model interaction, using a three-dimensional modeling tool to export a three-dimensional model, importing the three-dimensional model which needs to generate Collider into a unity engine, ensuring that there is no Collider component in the imported three-dimensional model; entering unity, selecting the model which needs to be edited, and entering the editing mode; in the main panel, selecting the "physical component" option; clicking the "create BoxCollider" button, waiting for the completion of Collider generation, exiting the editing mode after the completion of Collider generation, saving the scene; and testing Collider, the application is very simple to use, and can greatly improve the development efficiency. Through the use of the method, Collider can be quickly created, and physical interaction can be realized in the scene. The traditional manual binding process of Collider is avoided, the human cost of the developer is reduced, and the work efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application is suitable for game development, virtual reality, architectural design and other fields, and specifically relates to a method for quickly generating Collider based on Unity model interaction. BACKGROUND

[0002] Unity is a very popular game engine that has powerful 3D modeling and interaction capabilities. In Unity, we can use Collider components to implement collision detection and physical simulation of models. However, manually creating Collider components requires a lot of time and effort, especially for complex models. To this end, the present application proposes a method for quickly generating Collider based on Unity model interaction to solve the above technical problems. SUMMARY

[0003] To solve the above technical problems, the present application proposes a method for quickly generating Collider based on Unity model interaction, which is suitable for Collider components in Unity3D, to solve the above technical problems and reduce the time and effort required to build scenes.

[0004] To achieve the above purpose, the technical solution adopted by the present application is as follows:

[0005] A method for quickly generating Collider based on Unity model interaction, characterized by the following steps:

[0006] S1. Use a three-dimensional modeling tool to export a three-dimensional model, import the three-dimensional model that needs to generate Collider into the unity engine, and ensure that there is no Collider component in the imported three-dimensional model;

[0007] S2. Enter unity and select the model that needs to be edited, and enter edit mode;

[0008] S3. In the main panel, select the "Physics component" option;

[0009] S4. Click the "Create BoxCollider" button and wait for the Collider to be generated;

[0010] S5. After the Collider is generated, exit the edit mode and save the scene;

[0011] S6. Test the Collider: Test the Collider in the scene to ensure that it matches the model that needs to be edited and correctly prevents collision.

[0012] As a preferred technical solution of the present application: the Unity model is visualized, and the Unity3D editor import file is used for visual reading;

[0013] All levels NodeLevel in the current model expansion mode are obtained through a recursive algorithm, and are stacked to the model list objectList,

[0014] As described above, the model Collider set M is obtained:

[0015] The vertex information of each 3D MeshModel in the stack container is obtained by using the MeshFilter method built in Unity3D;

[0016] In combination with the Unity3D technology and the C# technology, the relative spatial coordinates V=(x, y, z) and the relative spatial rotation angle R=(x, y, z, w) and the relative spatial scaling size S=(x, y, z) of the model node N are read;

[0017] In combination with the Unity technology and the C# technology, the size K=(x, y, z) of the space box of the component is obtained;

[0018] Based on the C# technology, the actual occupancy coefficient F(x, y, z) of the model node N in the space is calculated N ;

[0019]

[0020] According to the above results, when the corresponding space change data or the size of the space box of the model node N is 0, filtering is performed, and the model structure level L=(L-i) is updated

[0021]

[0022] As described above, the Collider set M obtained is combined with the Unity3D component construction technology to initialize the model N node Collider data M(x, y, z) N

[0023] As a preferred technical solution of the present application: the recursive algorithm screening process is as follows:

[0024] a. Recursive start

[0025] path(lint i, lint j, int m, int n, Map<String, Integer> map);

[0026] b. Judge boundary condition and out of bounds

[0027] If i == m && j == n, then it has been walked to, enter return1, if i > m || j > n, then it is out of bounds, enter return0

[0028] c. Set key

[0029] Set key: String key = i + m - n + j;

[0030] d. Determine whether it has been calculated

[0031] Look up in map, if it can be found in map, then it has been calculated, if not in map, then it needs to be calculated, calculate as follows:

[0032] / / There are several ways to walk down, int down = path(i + 1, j, m, n, map);

[0033] / / There are several ways to walk right, int right = path(i, j + 1, m, n, map);

[0034] / / The total number of paths is the sum of down and right, int sum = down + right;

[0035] Put the calculation result into map to avoid repeated calculation next time;

[0036] e. return map.get(key)

[0037] Put the calculated result into return map.get(key);

[0038] f. return sum

[0039] The calculation result is input into return sum through return map.get(key), and the calculation result of int sum = down + right is also input into return sum;

[0040] g. Complete.

[0041] As a preferred technical solution of the application: in step S2: after entering the editing mode, select the model in the scene as the parent object of the model.

[0042] As a preferred technical solution of the application: in step S4:

[0043] Add the Mesh Collider component: Select the parent object, click the Create Collider button in the main panel;

[0044] In the Script component, get the Mesh data of the model using the unity built-in tool function "MeshFilter.mesh" function;

[0045] Generate Collider according to Mesh data, use unity built-in tool function "MeshCollider.sharedMesh" function;

[0046] Adjust the properties and positions of Colliders to fit the surface of the 3D model;

[0047] As a preferred technical solution of the present application: in step S6: test whether the Colliders work normally, if not, adjust their properties and positions until they work normally, after the Colliders work normally, save the scene and run, and verify whether the Colliders can correctly interact with other objects.

[0048] As a preferred technical solution of the present application: import the model that needs to generate Collider as a new model or a model exported from existing software.

[0049] Compared with the prior art, the present application has the following advantages:

[0050] The method for quickly generating Collider based on Unity model interaction provided by the present application is very simple and easy to use, which can greatly improve the development efficiency. By using this method, Collider can be quickly created, and physical interaction can be realized in the scene.

[0051] The present application avoids the traditional manual binding process of Collider, reduces the labor cost of developers, and improves the work efficiency. DETAILED DESCRIPTION OF DRAWINGS

[0052] Figure 1 Flowchart of the present application;

[0053] Figure 2 is a model diagram before application in actual use of the present application;

[0054] Figure 3 is a model diagram after application in actual use of the present application;

[0055] Figure 4 is a model diagram of adding physical properties in the main variable area;

[0056] Figure 5The physical property model diagram is added in the 220kV interval. DETAILED DESCRIPTION

[0057] The application will be described in further detail below in conjunction with the accompanying drawings and specific embodiments:

[0058] As Figures 1-5 shown: the application proposes a method for quickly generating Collider based on Unity model interaction, including the following steps:

[0059] S1. Use a three-dimensional modeling tool to export a three-dimensional model, import the three-dimensional model that needs to generate Collider into the unity engine, and ensure that there is no Collider component in the imported three-dimensional model;

[0060] S2. Enter unity, select the model that needs to be edited, and enter edit mode;

[0061] S3. In the main panel, select the "Physical Component" option;

[0062] S4. Click the "Create BoxCollider" button and wait for the Collider to be generated;

[0063] S5. After the Collider is generated, exit the edit mode and save the scene;

[0064] S6. Test the Collider: test the Collider in the scene to ensure that it matches the model that needs to be edited and correctly prevents collision.

[0065] In this embodiment: the Unity model is visualized, and the Unity3D editor is used to import files for visual read;

[0066] All levels of NodeLevel in the current model expansion mode are obtained through a recursive algorithm, and are stacked to the model list objectList,

[0067] As described above, the model Collider set M is obtained:

[0068] The vertex information of each 3D MeshModel in the stack container is obtained using the MeshFilter method built into Unity3D;

[0069] The relative spatial coordinates V=(x, y, z) and the relative spatial rotation angle R=(x, y, z, w) and the relative spatial scaling size S=(x, y, z) of the model node N are read in combination with the Unity3D technology for spatial change data openness and the C# technology;

[0070] Combining the Unity technology for component data readability and C# technology, get the model Renderer space box size K = (x, y, z);

[0071] Based on C# technology, calculate the actual space occupancy coefficient F(x, y, z) of model node N N ;

[0072]

[0073] According to the above results, when considering the space change data corresponding to the model node N or the space box size is 0, filter the count i, which needs to be filtered, and update the model structure level L = (L-i)

[0074]

[0075] As described above, using the obtained Collider set M and combining Unity3D component construction technology, initialize the model N node Collider data M(x, y, z) N .

[0076] In this embodiment, as shown in Figure 1 The recursive algorithm screening process is as follows:

[0077] a. Recursive start

[0078] path(lint i,lint j,int m,int n,Map<String,Integer>map);

[0079] b. Judge boundary condition and out of bounds

[0080] If i == m && j == n, it is determined that it has reached, enter return1, if i > m ll j > n, it is determined that it is out of bounds, enter return0

[0081] c. Set key

[0082] Set key: String key = i+ m - n + j;

[0083] d. Judge whether it has been calculated

[0084] Find in map, if it can be found in map, it means it has been calculated, if it is not in map, it needs to be calculated, the calculation is as follows:

[0085] / / Down, int down = path(i + 1, j, m, n, map);

[0086] / / There are several ways to the right, int right = path (i, j + 1, m, n, map);

[0087] / / The sum of down and right is the total number of roads, int sum = down + right;

[0088] Put the calculation result into the map to avoid repeated calculation next time;

[0089] e.return map.get(key)

[0090] Put the calculated result into return map.get(key);

[0091] f.return sum

[0092] The calculation result is input to return map.get(key) and return sum, and the calculation result of int sum = down + right is also input to return sum;

[0093] g. Finish.

[0094] Through the above recursive algorithm, all levels (NodeLevel) under the current model expansion mode are recursively obtained and stacked (Stacked) into the model list (objectList).

[0095] The working method of the application: first, import the model that needs to generate Collider, which can be designed by yourself or imported from other software (such as 3DS Max, Maya, etc.), and obtain the model Collider set M.

[0096] Select the model in the scene as the parent object of the model.

[0097] Add Mesh Collider component: select the parent object, click the Create Collider button in the main panel.

[0098] In the Script component, the Mesh data of the model needs to be obtained, and the tool function "MeshFilter.mesh" function provided by unity is used.

[0099] Generate Collider according to Mesh, and use the tool function "MeshCollider.sharedMesh" function provided by unity.

[0100] Adjust the properties and positions of the Colliders to adapt them to the surface of the 3D model.

[0101] Test if the colliders are working properly. If there are problems, adjust their properties and positions as appropriate until the desired effect is achieved.

[0102] Save the scene and run it to verify that the colliders are interacting correctly with other objects.

[0103] The method for quickly generating colliders based on model interaction in Unity is very simple and easy to use, which can greatly improve the development efficiency. By using this method, colliders can be quickly created and physical interaction can be achieved in the scene.

[0104] The application avoids the traditional manual binding process of colliders, reduces the labor cost of developers, and improves the work efficiency.

[0105] The above is only a preferred embodiment of the present application, not any other form of limitation on the present application, and any modification or equivalent change made according to the technical essence of the present application still belongs to the scope of the present application.

Claims

1. A method for quickly generating Colliders based on Unity model interaction, characterized in that: Includes the following steps: S1. Use a 3D modeling tool to export a 3D model. When importing it into the Unity engine, a 3D model of the Collider needs to be generated. Ensure that the imported 3D model does not contain the Collider component. S2. Enter Unity, select the model you want to edit, and enter edit mode; Visualize Unity models by importing files into the Unity3D editor for visualization. All NodeLevels in the current model expansion mode are obtained using a recursive algorithm and pushed onto the model list objectList using a stack stacked on top of the current model expansion mode. Obtain the model Collider set as M: Use Unity3D's built-in MeshFilter method to obtain vertex information for each 3D MeshModel within the stack container; Combining Unity3D's openness to spatial change data and C# technology, the relative spatial coordinates V(x,y,z), relative spatial rotation angle R(x,y,z,w), and relative spatial scaling size S(x,y,z) of model node N are read. By combining Unity's technology for reading component data with C# technology, the size K(x,y,z) of the model's Renderer space box can be obtained. Based on C# technology, the actual spatial proportion coefficient of model node N is calculated. ; ; Based on the above results, when considering the spatial variation data corresponding to model node N or when the size of the spatial box is 0, filtering count i is required. Therefore, the model structure hierarchy L=(Li) is updated. ; Using the derived Collider set M and Unity3D component construction technology, the Collider data of the N nodes of the model is initialized. ; The recursive algorithm selection process is as follows: a. Recursion begins; path(int i, int j, int m, int n, Map<String, Integer> map); b. Determine boundary conditions and boundary violations; If i == m && j == n, then the condition has been reached, and return 1 is executed. If i > m, m, l, j > n, then the condition has been exceeded, and return 0 is executed. c. Set the key; Set the key: String key = i + m - n + j; d. Determine whether it has already been calculated; If the value is found in the map, it means it has already been calculated. If it is not found in the map, it needs to be calculated as follows: / / There are several paths down, int down = path(i+1.jm,n,map); / / How many paths are there to the right? int right = path(i,j+1,mn,map); / / The sum of the downward and rightward directions is the total number of paths, int sum = down + right; Store the calculation results in a map to avoid repeated calculations in the future; e.return map.get(key) Input the calculated result into return map.get(key); f.return sum The calculation result is input into return sum via return map.get(key), and the calculation result of int sum = down + right is also input into return sum; g. Completed; S3. In the main panel, select the "Physical Components" option; S4. Click the "Create BoxCollider" button and wait for the Collider to be generated; S5. After the Collider is generated, exit edit mode and save the scene; S6. Test Collider: Test the Collider in the scene to ensure it matches the model that needs to be edited and correctly prevents collisions.

2. The method for quickly generating Colliders based on Unity model interaction according to claim 1, characterized in that: In step S2: After entering edit mode, select the model in the scene as the model's parent object.

3. The method for quickly generating Colliders based on Unity model interaction according to claim 1, characterized in that: In step S4: To add a Mesh Collider component: Select the parent object, and in the main panel, click the Create Collider button; In the Script component, retrieve the model's Mesh data using Unity's built-in utility function "MeshFilter.mesh"; Generate a Collider based on the Mesh data using Unity's built-in utility function "MeshCollider.sharedMesh"; By adjusting the Collider's properties and position, it can be adapted to the surface of the 3D model.

4. The method for quickly generating Colliders based on Unity model interaction according to claim 1, characterized in that: In step S6: Test whether the Collider is working properly. If it is not working properly, adjust its properties and position until it works properly. After the Collider is working properly, save the scene and run it to verify whether the Collider can interact with other objects correctly.

5. The method for quickly generating Colliders based on Unity model interaction according to claim 2, characterized in that: Import the model that needs to generate the Collider as a new model or a model exported from existing software.

Citation Information

Patent Citations

  • Tool automatic binding system and method based on Unity three-dimension (3D) engine and VR equipment

    CN107145222A

  • Unity3D based three-dimensional visualization real-scene displaying method

    CN107767443A