A GIS digital twin system based on Unity3D
By using the Unity3D engine to develop the GIS digital twin system, the problems of complex and insufficient security in the GIS system development in the existing technology are solved, and a more efficient, secure and scalable GIS digital twin system is achieved.
Patent Information
- Application Number
- CN202211524789.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-30
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-11-30
AI Technical Summary
The development of existing GIS digital twin systems is complex and requires the use of third-party platforms. They have privacy and security risks, and lack scalability and platform compatibility.
The Unity3D open source engine is used to develop the GIS digital twin system, and the system functions and security are realized through resource download, perspective control, perspective transition, model interaction, monitoring management and account management modules.
It lowers the complexity and threshold of GIS system development, improves the security and scalability of the system, supports cross-platform development, and enhances data privacy protection.
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of geographic information systems, and in particular to a GIS digital twin system based on Unity3D. Background Art
[0002] At present, 3D data is gaining more and more attention and being used more and more widely because it has advantages over 2D data such as being intuitive and comprehensive. Therefore, it is necessary to use 3D data to build a GIS digital twin system. However, what tools to use to develop a GIS digital twin system and how to develop it are the challenges currently faced.
[0003] Geographic Information System (GIS) can display spatial geographic coordinate data, process spatial locations, and study various effective management methods for various data. Through comprehensive analysis, it can quickly obtain certain necessary information about the application and display the processing results in the form of maps, graphics or data.
[0004] Digital twin system refers to the mapping of objects in physical and virtual space by making full use of the measurement of existing physical models, model parameter updates, and three-dimensional historical data in the virtual space of the computer, thereby reflecting the processes and functions of the entire life cycle of the corresponding physical models in real life. In recent years, due to the continuous development of computer vision technology and the continuous refinement of 3D modeling models, GIS digital twin systems have gained further application space and played an important role in many fields such as urban planning, enterprise digitalization, traffic control, navigation and online tourism.
[0005] In response to these application scenarios, some companies have developed corresponding software or website systems for developers to use. However, the digital twin system developed in this way needs to be developed with the help of a third-party platform, and various data in the development system will also pass through the third-party platform, which poses a great privacy and security risk. At the same time, the traditional GIS system development methods and development platforms are often too complicated and cumbersome. The development of a large GIS system is usually based on a small number of visual tests but contains a large amount of stacking and nesting of logical codes. It usually requires multiple people to collaborate on the design and development of the GIS system. At the same time, the more difficult problem is how to integrate the codes of a large number of different developers into a complete and smooth-running system. This makes the development difficulty and problem-solving difficulty of developers soar.
[0006] Moreover, these application systems are generally developed for a specific application scenario, lacking the scalability and platform compatibility that a complete GIS digital twin system should have. Traditional GIS often integrates source code together and uses link libraries or components at the same time, but it is often the case that each program integration and code maintenance requires recompiling and linking the source code, and then re-releasing the new software. This work is not only troublesome but also increases the workload of system maintenance. Therefore, we choose to use the Unity3D open source engine for the development of the GIS digital twin system, which can avoid or slow down the occurrence of the above problems.
[0007] Unity3D engine is an open source visual development platform that can create 3D games and projects in real time. The platform provides a complete set of software solutions, supporting platforms including mobile phones, tablets, PCs, game consoles, augmented reality and virtual reality devices. The platform has a mature visual interface, physical engine system and built-in integrated library. Developers can often complete the construction of scenes and the implementation of specific logic and functions through a small number of scripts and by dragging or adding state machines. Developers can also write or modify related plug-ins and other advanced operations to achieve specific functions required. When the project is running, it can easily and quickly modify and debug the parameters of the project in real time, quickly modify the level of refinement of model loading, and connect to the database and backend. Unity3D not only has a complete, mature and fast development mode, but also supports compatibility with all platforms. Projects running on the PC side often only need to modify a small part of the code to run on Android, Mac, Web, and other platforms. Summary of the invention
[0008] The purpose of the present invention is to provide a GIS digital twin system based on Unity3D, which uses virtual 3D data to map real life and ensures the coordination between the digital and physical worlds. It can perform real-time monitoring, data analysis and various simulations based on digital models to solve the shortcomings of the existing technology.
[0009] The technical solution of the present invention is as follows: a GIS digital twin system based on Unity3D, comprising a resource download module, a perspective control module, a perspective transition module, a model interaction module, a monitoring management module and an account management module; the resource download module is used to download resources from a server and decompress them; the perspective control module is used to zoom the perspective, rotate the perspective and translate the perspective; the perspective transition module is used to zoom the perspective when the monitoring is displayed in full screen, zoom the perspective away when exiting the full screen, and zoom the perspective when entering a floor; the model interaction module is used to click on a building to display information and highlight it, click on a floor to highlight it, enter a floor, and click on a room to display information and highlight it; the monitoring management module is used to control the display or hiding of monitoring by buttons, display monitoring buttons by billboard technology, click on monitoring to display information, and display monitoring in full screen; the account management module is used to connect to a user database to realize account management.
[0010] The resource download module is specifically:
[0011] Step 1.1, store compressed resource files on the server, the resource files contain resources such as 3D models and videos;
[0012] Step 1.2, in the initialization phase of the digital twin system operation, determine whether the resource file has been downloaded and check the version number of the resource file; when the resource has not been downloaded or the version number is inconsistent, send the resource file information to be downloaded to the server, and download the latest version of the resource file from the server. After the download is complete, decompress it to the specified directory; when the resource has been downloaded and the version number is consistent, enter the program directly;
[0013] Step 1.3, resource file download is used in conjunction with hot update; when the program changes the UI display or modifies the program logic, the developer does not repackage the program and the user does not re-download the client.
[0014] The viewing angle control module is specifically:
[0015] Step 2.1, create a custom view control script Click2Rotate.cs, define the rotation object target, moving speed moveSpeed, rotation speed rotateSpeed, and zoom speed zoomSpeed;
[0016] Step 2.2, in the Update() function of the perspective control script Click2Rotate.cs, customize the camera movement function cameraRotate(), and obtain the movement information of the mouse X-axis and Y-axis through the Unity editor's Input.GetAxis() to change the position of the main camera. The calculation formula is as follows:
[0017] mainCamera.transform.Translate(Vector3.left*(mouse_x*moveSpeed)*
[0018] Time.deltaTime);
[0019] mainCamera.transform.Translate(Vector3.up*(mouse_y*moveSpeed)*
[0020] Time.deltaTime);
[0021] Among them, mainCamera is the main camera, transform.Translate() is the function of the Unity editor, Vector3 represents a three-dimensional vector, left is the left vector of the main camera, up is the upward vector of the main camera, mouse_x is the movement information of the mouse X axis, mouse_y is the movement information of the mouse Y axis, moveSpeed is the movement speed, and Time.deltaTime is the incremental time of the Unity editor;
[0022] When the right mouse button is pressed and moved, the main camera position is moved according to the moving speed to complete the function of moving the viewing angle;
[0023] Step 2.3, define the custom rotation view function cameraZoom() in the Update() function of the view control script. The calculation formula is as follows:
[0024] mainCamera.transform.RotateAround(transform.position,Vector3.up,mouse_x*rotateSpeed);
[0025] mainCamera.transform.RotateAround(transform.position,Vector3.right,mouse_y*rotateSpeed);
[0026] Among them, transform.RotateAround() is the rotation function of the Unity editor, transform.position is the position coordinate of the main camera, right is the right vector of the main camera, and rotateSpeed is the rotation speed;
[0027] When the left mouse button is pressed and moved, the camera view rotates according to the rotation speed; the function of rotating the view is completed;
[0028] Step 2.4, customize the perspective scaling function in the Update() function of the perspective control script. The calculation formula is as follows:
[0029] When Input.GetAxis("Mouse ScrollWheel")>0, the calculation formula is
[0030] mainCamera.transform.Translate(Vector3.forward*zoomSpeed);
[0031] When Input.GetAxis("Mouse ScrollWheel")<0, the calculation formula is
[0032] mainCamera.transform.Translate(Vector3.forward*-zoomSpeed);
[0033] Among them, Input.GetAxis("Mouse ScrollWheel") is the function used by the Unity editor to obtain the scroll information of the mouse wheel, forward is the forward vector of the main camera, and zoomSpeed is the zoom speed;
[0034] When the mouse wheel is rolled, the main camera moves forward or backward in the direction of the camera according to the zoom speed to complete the zoom perspective;
[0035] Step 2.5, in the Unity editor, add the view control script to the main camera, set the values of movement speed, rotation speed, and scaling speed, and assign the main camera to the rotating object.
[0036] The perspective transition module is specifically:
[0037] Step 3.1, create a custom zoom-in script CameraFollow.cs, define the target object, target object moving speed, target object rotation speed, minimum angle, and minimum distance;
[0038] Step 3.2, in the LateUpdate() function of the zoom-in script CameraFollow.cs, obtain the real-time position of the target object and the position of the main camera, calculate the direction vector from the main camera to the target object through the real-time position of the target object and the real-time position of the main camera, calculate the angle between the main camera orientation and the direction vector from the main camera to the target object, and calculate the distance between the real-time position of the target object and the real-time position of the main camera;
[0039] Step 3.3, when the angle between the main camera orientation and the direction vector from the main camera to the target object is greater than the minimum angle, the main camera perspective is rotated by the Lerp() interpolation function. The main camera perspective is expressed as camRoatae, and its calculation formula is as follows:
[0040] camRotate=Quaternion.Lerp(transform.rotation,dir,rotateSpeed*Time.deltaTime)
[0041] Among them, Quaternion.Lerp() is the interpolation function, transform.rotation is the real-time viewing angle of the main camera, dir is the direction vector from the main camera to the target object, rotateSpeed is the rotation speed of the target object, and Time.deltaTime is the incremental time provided by the Unity editor;
[0042] When the distance between the real-time position of the target object and the real-time position of the main camera is greater than the minimum distance, the main camera position is moved closer to the target object through the Lerp() interpolation function. The main camera position is represented as camPos, and its calculation formula is as follows:
[0043] camPos=Vector3.Lerp(camPos,tarPos,moveSpeed*Time.deltaTime)
[0044] Among them, Vector3.Lerp() is the interpolation function, transform.position is the real-time position of the main camera, camPos is the main camera position, tarPos is the real-time position of the target object, and moveSpeed is the moving speed of the target object;
[0045] When the conditions that the angle between the main camera orientation and the direction vector from the main camera to the target object > the minimum angle and the distance between the real-time position of the target object and the real-time position of the main camera > the minimum distance are not met, close or remove the custom perspective zoom-in script to complete the perspective zoom-in function;
[0046] Step 3.4, create a custom zoom-out script CameraFar.cs, define the zoom-out speed and maximum distance; get the initial position of the main camera in the Start() function; get the real-time position of the main camera in the Update() function, and calculate the distance between the main camera and the initial position through the initial position and the real-time position of the main camera; when the distance between the main camera and the initial position is less than the maximum distance, move the main camera in the opposite direction of the camera's perspective at the zoom-out speed; when the condition that the distance between the main camera and the initial position is less than the maximum distance is not met, close or remove the custom zoom-out script; complete the zoom-out function;
[0047] Step 3.5, create a custom script control script ScriptControl.cs to control the above zoom-in script and zoom-out script; define a private zoom-in class object; add a zoom-in script to the camera object in the Start() function, and the formula is as follows:
[0048] camFow=mainCamera.AddComponent <camerafollow>(),
[0049] Among them, camFow is the zoom-in view class object, mainCamera is the camera object, AddComponent is the add script function of the Unity editor, and CameraFollow is the zoom-in view script;
[0050] Finally, assign values to the target object moving speed, target object rotation speed, minimum angle, and minimum distance in camFow.
[0051] The model interaction module is specifically:
[0052] Step 4.1, create a custom ray click script ClkHiliCtrl.cs to complete the collision body detection function and determine whether the mouse ray collides with the model to generate an interactive function; the input is the mouse click operation and the mouse click coordinates, and the output is the object detected by the ray collision;
[0053] Create a mouse ray, represented by ray, and its formula is as follows:
[0054] ray=Camera.main.ScreenPointToRay(Input.mousePosition)
[0055] Among them, Camera.main is the main camera, Input.mousePosition is the coordinates of the mouse click, and ScreenPointToRay() is a function provided by the Unity editor;
[0056] Then perform collision detection, whether a collision occurs is expressed as isHit, and the calculation formula is as follows:
[0057] isHit=Physics.Raycast(ray,out hit,maxDistance,clickableLayer)
[0058] Among them, hit contains the object information detected by the collision, maxDistance is the maximum length of the ray, clickableLayer is the clickable object layer, and Physics.Raycast() is a function provided by the Unity editor;
[0059] When isHit is true, get the object detected by the collision, represented as obj, and the calculation formula is as follows:
[0060] obj = hit.collider.gameObject
[0061] Among them, collider is the collider property of the Unity editor, and gameObject is the object property of the Unity editor;
[0062] When the mouse is clicked, the mouse click information is obtained, the corresponding ray is created, and the collision object is obtained when the ray detects a collision body;
[0063] Step 4.2, obtain the label of the collision object, and then obtain the information of the collision object from the database according to the label, the information includes the object name, object position, object function, and then update the object information to the text content area for display;
[0064] Step 4.3, load the HighlighterPlus highlight plug-in, load the highlight attribute on the collision body of the corresponding label, set the highlight display to always on, the color to yellow, activate the highlight attribute, and complete the highlight display; use global variables to resolve highlight conflicts, detect whether the ray pressed by the mouse collides with the 3D model, and when it collides with the 3D model and there is a highlighted object in the global variable, cancel the highlight of the highlighted object in the global variable and highlight the collided building.
[0065] The maximum length of the ray in step 4.1 is 1000.
[0066] The monitoring management module is specifically:
[0067] Step 5.1, create a custom button control script. When you click to show or hide monitoring, get all monitoring camera icons and display or hide all monitoring icons; set the material of the monitoring icon to render in the front row to ensure that the monitoring icon is not covered by objects in the scene;
[0068] Step 5.2, use billboard technology to display the monitoring button, so that the monitoring button is always facing the main camera's perspective, and the display size is not affected by the scene zooming in or out; create a custom billboard shader file, define the button's upward vector to be consistent with the camera's upward vector, define the forward vector as the normal vector pointing to the front of the camera plane, and define the right vector as the cross product of the upward vector and the forward vector; transform all the button's vertex coordinates through the upward vector, forward vector, and right vector to obtain the final display button's vertex coordinates, expressed as localPos, and the calculation formula is as follows:
[0069] localPos=center+centerOffs*[rightDir,upDir,normalDir]
[0070] Among them, centerOffs is the coordinates of all vertices of the button, which is a three-dimensional column vector, which are the coordinates of the x, y, and z axes respectively, and center is the origin of the coordinates; rightDir is the right vector; upDir is the upward vector; normalDir is the forward vector; * is matrix multiplication;
[0071] Then control the scaling of the button; create a custom billboard script, the scaling factor is expressed as k, and its calculation formula is as follows:
[0072] k=(depth-nearPlaneDis) / (farPlaneDis-nearPlaneDis)
[0073] Where k is the scaling factor; depth is the distance from the button to the main camera; nearPlaneDis is the distance from the near plane of the main camera to the main camera; farPlaneDis is the distance from the far plane of the main camera to the main camera;
[0074] Finally, the vertex coordinates of the final display button are scaled according to the scaling factor to obtain the final billboard display effect;
[0075] Step 5.3, when the user views the surveillance image in full screen, the customized perspective zoom-in script is called to make the main camera rotate smoothly to the angle facing the target object, and then smoothly zoom in the distance to the target object to complete the perspective transition function; when the distance between the main camera and the target object is less than the set value, the real-time surveillance video is loaded, and the transparency channel value of the video gradually changes to 1, and finally the surveillance video is displayed in full screen;
[0076] Step 5.4, when you click the close button in the upper right corner of the full-screen monitoring screen, the transparency channel value of the video will gradually change to 1, and finally the display of the full-screen monitoring screen will be cancelled. Then the custom perspective zoom-in script will be called to gradually zoom out the main camera to its original position.
[0077] The setting value in step 5.3 is 100.
[0078] The account management module is specifically:
[0079] Step 6.1: Install the MySQL runtime environment on the server side, and reference the MySql.Data.dll dynamic link library file in the Unity editor to operate the database;
[0080] Step 6.2: Reference the MySql.Data.MySqlClient package to connect to the database and operate database data, and create a custom database access class MySqlAccess. The class contains 5 string variables to store database information, namely IP address, port number, user name, password, and database name; customize the functions in the MySqlAccess class, including open database function, create table function, insert data function, query function, update function, delete function, and close connection function;
[0081] Step 6.3: Operate the database; reference the MySqlAccess class in step 6.2, declare its class object to connect to and operate the database; call the custom open database function in step 6.2 to connect to the database, call the custom create table function to create a user information table, which includes the user's username, user password, and user role; different user roles correspond to different permissions; call the custom insert data function to insert data into the user information table; call the custom close connection function to close the database connection.
[0082] The above interpolation function is used to achieve a smooth transition of the main camera's viewing angle. When the user interacts with the system, entering a certain floor or displaying the monitoring in full screen will automatically trigger a transition to zoom in, and the viewing angle will smoothly turn to the target object and shorten the distance. Exiting a floor or canceling the full-screen display of the monitoring will automatically trigger a transition to zoom out.
[0083] Beneficial effects of the present invention: The present invention provides a GIS digital twin system based on Unity3D. The Unity3D editor used is an open source engine with low cost; the platform is powerful, has excellent visual effects, and can be connected to the database; it is convenient for cross-platform development (PC, Web, Android); it is highly versatile, supports various third-party plug-ins, has a high degree of customization, and can complete more specific functions on this basis; it has high controllability, and the data does not need to pass through a third-party platform, and the privacy is more secure; ray clicks are used for model interaction, and global variables are used to resolve highlight conflicts; billboard technology is used to display monitoring buttons, which are not affected by scene zooming in and out; an interpolation algorithm is used to achieve a smooth transition of the main camera's viewing angle. It provides a reliable solution for subsequent GIS system developers, allowing GIS developers to pay more attention to specific needs and lower the development threshold of digital twin systems. DETAILED DESCRIPTION
[0084] The present invention is further described below in conjunction with the technical solution.
[0085] The present invention provides a GIS digital twin system based on Unity3D, and uses custom scripts and plug-ins to complete specific functions in the digital twin system, uses virtual 3D data to map real life, and ensures that the digital and physical worlds are coordinated and consistent, and can perform real-time monitoring, data analysis, and various simulations based on digital models. The use of this system can avoid the complexity and cumbersomeness of traditional GIS development platforms and lower the development threshold. The development platform used is Unity3D, which has low cost, can be developed across platforms, supports third-party plug-ins, has a high degree of customization, and can complete more specific functions on this basis. The most important thing is that it is highly controllable, data does not need to pass through a third-party platform, and privacy is more secure.
[0086] Embodiment 1: Viewing angle control and viewing angle transition.
[0087] In the Unity3D-based GIS digital twin system of the present invention, the mouse can be used to control the viewing angle of the 3D scene. When the right button of the mouse is pressed and moved in the 3D scene interface, the viewing angle can be moved; when the left button of the mouse is pressed and moved, the viewing angle can be rotated; when the mouse wheel is rolled, the viewing angle can be zoomed.
[0088] When users interact with the system, certain operations will automatically trigger the perspective transition function. When entering a certain floor or displaying the surveillance in full screen, the perspective will automatically trigger the transition of zooming in, and the perspective will smoothly turn to the target object and get closer; when exiting the floor or canceling the surveillance in full screen, the perspective will automatically trigger the transition of zooming out.
[0089] Example 2: Model interaction.
[0090] Clicking on a building in the 3D scene will display the building information in the sidebar and highlight the corresponding building. Clicking on a floor in the sidebar will display the floor information and highlight the corresponding floor. Clicking the "Enter" button on the floor in the sidebar will enter the floor and allow you to interact with the rooms and furniture on the floor.
[0091] Embodiment 3: Monitoring and management.
[0092] The system can control the display or hiding of monitoring through buttons. When monitoring is displayed, the monitoring button will be displayed using billboard technology. This button is always facing the main viewing angle, and the absolute size is not affected by the scene zooming in or out, that is, in scenes with different zoom ratios, the absolute size of the monitoring button is the same. Clicking on monitoring will display detailed information and display the monitoring thumbnail video. Clicking the full screen button below the thumbnail video will display the monitoring video in full screen.
[0093] Example 4: Account management.
[0094] The system can manage accounts by connecting to the database, and can add, delete, modify, and search users through the interactive interface. The database is stored in a private server without going through a third-party platform, making data privacy more secure.< / camerafollow>
Claims
1. A GIS digital twin system based on Unity3D, characterized in that: The GIS digital twin system based on Unity3D includes a resource download module, a perspective control module, a perspective transition module, a model interaction module, a monitoring management module and an account management module; the resource download module is used to download resources from the server and decompress them; the perspective control module is used to zoom the perspective, rotate the perspective and translate the perspective; The perspective transition module is used to zoom in when the monitoring is displayed in full screen, zoom out when exiting the full screen, and zoom in when entering a floor; the model interaction module is used to click on the building to display information and highlight it, click on the floor to highlight it, enter the floor, and click on the room to display information and highlight it; the monitoring management module is used to control the display or hiding of monitoring with buttons, and the billboard technology displays the monitoring button, click the monitoring to display information, and display the monitoring in full screen; the account management module is used to connect to the user database to realize account management; The perspective transition module is specifically: Step 3.1, create a custom zoom-in script, define the target object, target object movement speed, target object rotation speed, minimum angle, and minimum distance; Step 3.2, in the LateUpdate() function of the zoom-in script, obtain the real-time position of the target object and the position of the main camera, calculate the direction vector from the main camera to the target object through the real-time position of the target object and the real-time position of the main camera, calculate the angle between the main camera orientation and the direction vector from the main camera to the target object, and calculate the distance between the real-time position of the target object and the real-time position of the main camera; Step 3.3, when the angle between the main camera orientation and the direction vector from the main camera to the target object is greater than the minimum angle, the main camera perspective is rotated by the Lerp() interpolation function. The main camera perspective is represented by camRotate, and its calculation formula is as follows: camRotate=Quaternion.Lerp(transform.rotation,dir,rotateSpeed*Time.deltaTime) Among them, Quaternion.Lerp() is the interpolation function, transform.rotation is the real-time viewing angle of the main camera, dir is the direction vector from the main camera to the target object, rotateSpeed is the rotation speed of the target object, and Time.deltaTime is the incremental time provided by the Unity editor; When the distance between the real-time position of the target object and the real-time position of the main camera is greater than the minimum distance, the main camera position is moved closer to the target object through the Lerp() interpolation function. The main camera position is represented as camPos, and its calculation formula is as follows: camPos=Vector3.Lerp(camPos,tarPos,moveSpeed*Time.deltaTime) Among them, Vector3.Lerp() is the interpolation function, camPos is the main camera position, tarPos is the real-time position of the target object, and moveSpeed is the moving speed of the target object; When the conditions that the angle between the main camera orientation and the direction vector from the main camera to the target object > the minimum angle and the distance between the real-time position of the target object and the real-time position of the main camera > the minimum distance are not met, close or remove the custom perspective zoom-in script to complete the perspective zoom-in function; Step 3.4, create a custom zoom-out script, define the zoom-out speed and maximum distance; get the initial position of the main camera in the Start() function; get the real-time position of the main camera in the Update() function, and calculate the distance between the main camera and the initial position through the initial position and the real-time position of the main camera; when the distance between the main camera and the initial position is less than the maximum distance, move the main camera in the opposite direction of the camera's perspective at the zoom-out speed; when the condition that the distance between the main camera and the initial position is less than the maximum distance is not met, close or remove the custom zoom-out script; complete the zoom-out function; Step 3.5, create a custom script control script to control the above zoom-in script and zoom-out script; define a private zoom-in class object; add a zoom-in script to the camera object in the Start() function, and the formula is as follows: camFow=mainCamera.AddComponent <camerafollow> (),< / camerafollow> Among them, camFow is the zoom-in view object, mainCamera is the main camera, AddComponent is the add script function of the Unity editor, and CameraFollow is the zoom-in view script; Finally, assign values to the target object moving speed, target object rotation speed, minimum angle, and minimum distance in camFow.
2. The GIS digital twin system based on Unity3D according to claim 1, characterized in that: The resource download module is specifically: Step 1.1, store the compressed resource files on the server, the resource files contain 3D models and video resources; Step 1.2, in the initialization phase of the digital twin system operation, determine whether the resource file has been downloaded and check the version number of the resource file; when the resource has not been downloaded or the version number is inconsistent, send the resource file information to be downloaded to the server, and download the latest version of the resource file from the server. After the download is complete, decompress it to the specified directory; when the resource has been downloaded and the version number is consistent, enter the program directly; Step 1.3, resource file download and hot update; when the program changes the UI display or modifies the program logic, the developer does not repackage the program and the user does not re-download the client; The viewing angle control module is specifically: Step 2.1, create a custom view control script to define the rotation object, movement speed, rotation speed, and scaling speed; Step 2.2, customize the camera movement function in the Update() function of the perspective control script, and obtain the movement information of the mouse X-axis and Y-axis through the Input.GetAxis() of the Unity editor to change the position of the main camera. The calculation formula is as follows: mainCamera.transform.Translate(Vector3.left*(mouse_x*moveSpeed)*Time.deltaTime); mainCamera.transform.Translate(Vector3.up*(mouse_y*moveSpeed)*Time.deltaTime); Among them, mainCamera is the main camera, transform.Translate() is the function of the Unity editor, Vector3 represents a three-dimensional vector, left is the left vector of the main camera, up is the upward vector of the main camera, mouse_x is the movement information of the mouse X axis, mouse_y is the movement information of the mouse Y axis, moveSpeed is the movement speed, and Time.deltaTime is the incremental time of the Unity editor; When the right mouse button is pressed and moved, the main camera position is moved according to the moving speed to complete the function of moving the viewing angle; Step 2.3, define a custom rotation view function in the Update() function of the view control script. The calculation formula is as follows: mainCamera.transform.RotateAround(transform.position,Vector3.up,mouse_x*rotateSpee d); mainCamera.transform.RotateAround(transform.position,Vector3.right,mouse_y*rotateSp eed); Among them, transform.RotateAround() is the rotation function of the Unity editor, transform.position is the position coordinate of the main camera, right is the right vector of the main camera, and rotateSpeed is the rotation speed; When the left mouse button is pressed and moved, the camera view rotates according to the rotation speed; the function of rotating the view is completed; Step 2.4, customize the perspective scaling function in the Update() function of the perspective control script. The calculation formula is as follows: When Input.GetAxis("Mouse ScrollWheel")>0, the calculation formula is mainCamera.transform.Translate(Vector3.forward*zoomSpeed); When Input.GetAxis("Mouse ScrollWheel")<0, the calculation formula is mainCamera.transform.Translate[Vector3.forward*(-zoomSpeed)]; Among them, Input.GetAxis("Mouse ScrollWheel") is the function used by the Unity editor to obtain the scroll information of the mouse wheel, forward is the forward vector of the main camera, and zoomSpeed is the zoom speed; When the mouse wheel is rolled, the main camera moves forward or backward in the direction of the camera according to the zoom speed to complete the zoom perspective; Step 2.5, in the Unity editor, add the view control script to the main camera, set the values of the moving speed, rotation speed, and scaling speed, and assign the main camera to the rotating object; The model interaction module is specifically: Step 4.1, create a custom ray click script to complete the collision body detection function and determine whether the mouse ray collides with the model to generate an interactive function; the input is the mouse click operation and the mouse click coordinates, and the output is the object detected by the ray collision; Create a mouse ray, represented by ray, and its formula is as follows: ray=mainCamera.ScreenPointToRay(Input.mousePosition) Among them, mainCamera is the main camera, Input.mousePosition is the coordinates of the mouse click, and ScreenPointToRay() is a function provided by the Unity editor; Then perform collision detection, whether a collision occurs is expressed as isHit, and the calculation formula is as follows: isHit=Physics.Raycast(ray,out hit,maxDistance,clickableLayer) Among them, hit contains the object information detected by the collision, maxDistance is the maximum length of the ray, clickableLayer is the clickable object layer, and Physics.Raycast() is a function provided by the Unity editor; When isHit is true, get the object detected by the collision, represented as obj, and the calculation formula is as follows: obj = hit.collider.gameObject Among them, collider is the collider property of the Unity editor, and gameObject is the object property of the Unity editor; When the mouse is clicked, the mouse click information is obtained, the corresponding ray is created, and the collision object is obtained when the ray detects a collision body; Step 4.2, obtain the label of the collision object, and then obtain the information of the collision object from the database according to the label, the information includes the object name, object position, object function, and then update the object information to the text content area for display; Step 4.3, load the HighlighterPlus highlight plug-in, add the highlight attribute to the collision body of the corresponding label, set the highlight display to always on, the color to yellow, activate the highlight attribute, and complete the highlight display; use global variables to resolve highlight conflicts, detect whether the ray pressed by the mouse collides with the 3D model, and when it collides with the 3D model and there is a highlighted object in the global variable, cancel the highlight of the highlighted object in the global variable and highlight the collided building; The monitoring management module is specifically: Step 5.1, create a custom button control script. When you click to show or hide monitoring, get all monitoring camera icons and display or hide all monitoring icons; set the material of the monitoring icon to render in the front row to ensure that the monitoring icon is not covered by objects in the scene; Step 5.2, use billboard technology to display the monitoring button, so that the monitoring button is always facing the main camera's perspective, and the display size is not affected by the scene zooming in or out; create a custom billboard shader file, define the button's upward vector to be consistent with the camera's upward vector, define the forward vector as the normal vector pointing to the front of the camera plane, and define the right vector as the cross product of the upward vector and the forward vector; transform all the button's vertex coordinates through the upward vector, forward vector, and right vector to obtain the final display button's vertex coordinates, expressed as localPos, and the calculation formula is as follows: localPos=center+centerOffs*[rightDir,upDir,normalDir] Among them, centerOffs is the coordinates of all vertices of the button, which is a three-dimensional column vector, which are the coordinates of the x, y, and z axes respectively, and center is the origin of the coordinates; rightDir is the right vector; upDir is the upward vector; normalDi r is the forward vector; * is matrix multiplication; Then control the scaling of the button; create a custom billboard script, the scaling factor is expressed as k, and its calculation formula is as follows: k=(depth-nearPlaneDis) / (farPlaneDis-nearPlaneDis) Where k is the scaling factor; depth is the distance from the button to the main camera; nearPlaneDis is the distance from the near plane of the main camera to the main camera; farPlaneDis is the distance from the far plane of the main camera to the main camera; Finally, the vertex coordinates of the final display button are scaled according to the scaling factor to obtain the final billboard display effect; Step 5.3, when the user views the surveillance image in full screen, the customized perspective zoom-in script is called to make the main camera rotate smoothly to the angle facing the target object, and then smoothly zoom in the distance to the target object to complete the perspective transition function; when the distance between the main camera and the target object is less than the set value, the real-time surveillance video is loaded, and the transparency channel value of the video gradually changes to 1, and finally the surveillance video is displayed in full screen; Step 5.4, when you click the close button in the upper right corner of the full-screen monitoring screen, the transparency channel value of the video gradually changes to 1, and finally cancels the display of the full-screen monitoring screen, and then calls the custom perspective zoom-in script to gradually zoom out the main camera to its original position; The account management module is specifically: Step 6.1: Install the MySQL runtime environment on the server side, and reference the MySql.Data.dll dynamic link library file in the Unity editor to operate the database; Step 6.2: Reference the MySql.Data.MySqlClient package to connect to the database and operate database data, and create a custom database access class MySqlAccess. The class contains 5 string variables to store database information, namely IP address, port number, user name, password, and database name; customize the functions in the MySqlAccess class, including open database function, create table function, insert data function, query function, update function, delete function, and close connection function; Step 6.3: Operate the database; reference the MySqlAccess class in step 6.2, declare its class object to connect to and operate the database; call the custom open database function in step 6.2 to connect to the database, call the custom create table function to create a user information table, which includes the user's username, user password, and user role; different user roles correspond to different permissions; call the custom insert data function to insert data into the user information table; call the custom close connection function to close the database connection.
3. The Unity3D-based GIS digital twin system according to claim 2, characterized in that: The maximum length of the ray in step 4.1 is 1000.
4. The Unity3D-based GIS digital twin system according to claim 2, characterized in that: The setting value in step 5.3 is 100.
5. The Unity3D-based GIS digital twin system according to claim 1, characterized in that: The above interpolation function is used to achieve a smooth transition of the main camera's viewing angle. When the user interacts with the system, entering a certain floor or displaying the monitoring in full screen will automatically trigger a transition of the viewing angle zooming in, and the viewing angle will smoothly turn to the target object and shorten the distance. Exiting a floor or canceling the full-screen display of the monitoring will automatically trigger a transition of the viewing angle zooming out.
Citation Information
Patent Citations
Three-dimensional game animation system
CN104077797A
A campus tour guide platform system based on Unity3d
CN109521999A