A rendering method for realizing three-dimensional simulation animation based on Modelica
By combining Modelica and the Three.js engine, the problem of rendering 3D simulation animations on the web was solved, enabling efficient display of 3D simulation animations on the browser and improving the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SUZHOU TONGYUAN SOFT CONTROL INFORMATION TECH CO LTD
- Filing Date
- 2022-10-14
- Publication Date
- 2026-04-14
AI Technical Summary
Users find it difficult to intuitively observe the 3D rendering effect of their model simulation on the web.
By using the Modelica-based 3D simulation animation rendering method, the front end calls the simulation service to obtain the animation file, uses the TCP protocol to transmit the animation frame data, and combines the Three.js engine to drive the animation modeling to achieve animation rendering.
It achieves efficient 3D simulation animation rendering on the browser side, provides a visual display of model simulation, and improves users' intuitive understanding of simulation results.
Smart Images

Figure CN115526979B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software engineering, and in particular to a rendering method for 3D simulation animation based on Modelica. Background Technology
[0002] With the improvement of browser performance and network bandwidth, as well as the implementation of the Web Graphics Library (WebGL), 3D technology is no longer the exclusive domain of desktop applications, and more and more web applications are using 3D technology.
[0003] In the field of industrial software on the web, people's needs are no longer limited to online modeling and simulation functions. They also want to understand the rendering effect of the model they have built after simulation more intuitively and clearly through online animation.
[0004] Modelica is an open, object-oriented, equation-based computer language that can be used across different fields to easily model complex physical systems.
[0005] Therefore, this invention provides a solution based on Modelica that can display 3D simulation animations of models in a browser, thereby achieving 3D simulation animation rendering. Summary of the Invention
[0006] This invention provides a rendering method for 3D simulation animation based on Modelica, which solves the problem that users have difficulty observing the rendering effect of the simulated model they have built.
[0007] A rendering method for 3D simulation animation based on Modelica, comprising:
[0008] The front end calls the simulation service, which reads the animation file generated by the Modelica solver and obtains the animation model based on the animation file.
[0009] The front end initiates a full-duplex communication protocol based on the Transmission Control Protocol (TCP) and sends a request command to the back end to obtain animation frame data. The back end then accesses the animation frame data in the database according to the request command.
[0010] The database returns the retrieved animation frame data to the backend, and the backend assembles the animation frame data and sends it to the frontend.
[0011] The front end drives the position and shape of the animated character to change based on the animation frame data in order to achieve animation rendering.
[0012] In one embodiment of this application, obtaining the animation model from the animation file specifically includes: parsing the animation file to obtain the names of each animation component; querying the database for the animation information of each animation component based on the names of the animation components; assembling the animation file and the animation information to obtain animation component data; and obtaining animation model data from the animation component data using a preset 3D animation engine.
[0013] In one embodiment of this application, after the front-end enables a TCP-based full-duplex communication protocol and sends a request command to the back-end to obtain animation frame data, the method further includes: storing the animation frame data in a cache queue introduced by the front-end; establishing an animation playback thread to continuously read the animation frame data from the cache queue; establishing a timed thread to periodically obtain the animation frame data from the back-end; when the content in the cache queue is less than half of the initial capacity, obtaining the animation frame data from the back-end and writing it into the cache queue; and the front-end matching the animation model and updating the geometric information of the animation shape according to the animation frame data in the cache queue to achieve an online animation effect on the front-end.
[0014] In one embodiment of this application, the method further includes: when the animation model initializes the animation shape, asynchronously acquiring animation frame data and caching the step size information of the animation frame data in a remote dictionary service Redis; determining the sampling frequency according to the size of the animation model and the animation playback speed; and acquiring the animation frame data from Redis according to the sampling frequency.
[0015] In one embodiment of this application, the step of obtaining animation frame data from Redis according to the sampling frequency specifically includes: if the animation playback speed is a first playback speed, then using a first sampling frequency corresponding to the first playback speed to obtain animation frame data; if the animation playback speed is a second playback speed, then using a second sampling frequency lower than the first sampling frequency to collect animation frame data; wherein, the second playback speed is slower than the first playback speed, and the second sampling frequency corresponds to the second playback speed.
[0016] In one embodiment of this application, the front end drives the change of the position and shape of the animated figure based on the animation frame data, specifically including: determining the position and posture information of the geometric object based on the animation variables in the preset 3D animation engine, wherein the position and posture information of the geometric object is represented by an array; obtaining the four-dimensional transformation matrix of the geometric object in the spatial coordinate system through matrix rotation and matrix scaling; and changing the position and shape of the animated figure according to the four-dimensional transformation matrix.
[0017] In one embodiment of this application, the method further includes: storing animation component information parsed from the animation file through a local cache (LocalCache); when the cache is full, filtering out the animation component information in the cache according to a preset expiration time by adopting a least recently used (LRU) cache eviction policy.
[0018] In one embodiment of this application, the preset 3D animation engine is the Three.js engine.
[0019] In one embodiment of this application, the method further includes: parsing the animation file to obtain a geometric type; the geometric type is represented by an animation variable in a preset 3D animation engine.
[0020] In one embodiment of this application, the method further includes: controlling the number of animation frames refreshed per unit time to be greater than a preset number of frames.
[0021] This invention provides a rendering method for 3D simulation animation based on Modelica, which includes at least the following beneficial effects: by efficiently analyzing and acquiring large amounts of simulation data, dynamically adjusting the transmission size of animation data, providing data support for 3D animation, and visualizing online simulation data based on Modelica models, a Web3D 3D animation rendering based on Modelica model simulation is realized. Attached Figure Description
[0022] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0023] Figure 1 A schematic diagram illustrating the steps of a rendering method for 3D simulation animation based on Modelica, provided in an embodiment of the present invention;
[0024] Figure 2 This is a schematic diagram of the overall online 3D animation rendering process provided in an embodiment of the present invention;
[0025] Figure 3 This is a schematic diagram of the animation model creation process provided in an embodiment of the present invention;
[0026] Figure 4 This is a schematic diagram of the front-end online animation playback process provided in an embodiment of the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described clearly and completely below in conjunction with specific embodiments. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0028] It should be noted that those skilled in the art will understand, explicitly and implicitly, that the embodiments described in this invention can be combined with other embodiments without conflict. Unless otherwise defined, the technical or scientific terms used in this invention should be understood in their ordinary sense by those skilled in the art. The terms "a," "an," "an," "the," etc., used in this invention do not indicate quantity limitation and can represent singular or plural. The terms "comprising," "including," "having," and any variations thereof used in this invention are intended to cover non-exclusive inclusion; the terms "first," "second," "third," etc., used in this invention are merely to distinguish similar objects and do not represent a specific ordering of objects.
[0029] This invention proposes a rendering method for 3D simulation animation based on Modelica. In this application, the front-end is a browser, the back-end is a simulation server, and the database used is IoTDB. 3D animation data is obtained from the server and transmitted to the web client, providing an implementation method for rendering and displaying 3D animation models driven by Modelica simulation data on the web. The details are described below.
[0030] Figure 1 A schematic diagram illustrating the steps of a rendering method for 3D simulation animation based on Modelica, provided in an embodiment of the present invention, may include the following steps:
[0031] S110: The front end calls the simulation service. After the simulation service reads the animation file generated by the Modelica solver, it obtains the animation model based on the animation file.
[0032] Specifically, the front-end calls the simulation service, which queries simulation data from the IoTDB, generates animation component data based on the simulation data, and returns it to the front-end for animation display.
[0033] like Figure 2The diagram shows the overall flowchart of online 3D simulation animation rendering. After the user clicks the animation button, the browser calls the simulation service and then verifies the simulation task. If the simulation task fails, a failure message is returned to the browser, and the browser informs the user that the animation cannot be viewed. If the simulation task succeeds, the browser returns animation component information, assembles the animation components, and sends them to the browser. The browser renders the animation model based on the assembled animation components. The browser opens a WebSocket and sends a request command to the simulation service to obtain animation frames. The simulation service queries the simulation data in the IoTDB database based on this request command and then returns the simulation data to the simulation server. The simulation server assembles the simulation data to obtain animation frame data and sends the animation frame data to the browser. The user caches the animation frame data in the browser locally, completing the rendering of the 3D simulation animation.
[0034] In one embodiment of this application, obtaining an animation model from an animation file specifically includes: parsing the animation file to obtain the names of each animation component; querying the database for the animation information of each animation component based on its name; assembling the animation file and animation information to obtain animation component data; and obtaining animation model data from the animation component data using a preset 3D animation engine, such as the Three.js engine.
[0035] Specifically, this application uses the IoTDB database to store simulation data. IoTDB is a database specifically designed for IoT time-series data, providing data acquisition, storage, and analysis functions. IoTDB offers an integrated edge-cloud solution, providing high-performance data read / write and rich query capabilities in the cloud, with an efficient directory organization structure customized for IoT scenarios. IoTDB has the following advantages: 1. SQL1-like language, low learning curve. 2. Lightweight structure, high performance, high throughput read / write. 3. Simple deployment.
[0036] The simulation service provides an interface for animation modeling, reading the animation.json file generated by the Modelica solver. This file stores data for all animation components of the model. Parsing the animation.json file reveals the name and geometry type of each animation component. By querying the simulation data for each animation component in the IoTDB database using its name, and concatenating the animation.json file and the retrieved simulation data from IoTDB, the animation modeling data can be obtained.
[0037] The data definitions for the animation components are shown in Table 1:
[0038] Parameter name Chinese instructions Data types time Total animation duration double animationData Component data array
[0039] Table 1
[0040] The data definition for the animationData component is shown in Table 2:
[0041]
[0042]
[0043] Table 2
[0044] In one embodiment of this application, animation component information parsed from animation files is stored in a local cache, LocalCache. When the cache is full, the animation component information in the cache is filtered out according to a preset expiration time by adopting a least recently used (LRU) cache eviction policy.
[0045] Specifically, a local cache, LocalCache, is used to store the animation component information parsed from the animation.json file, and an LRU cache eviction policy is adopted with corresponding expiration times set.
[0046] LRU is a commonly used page replacement algorithm that selects the least recently used page for replacement. This algorithm assigns an access field to each page to record the time t elapsed since the page was last accessed. When a page needs to be replaced, it selects the page with the largest t value among the existing pages, i.e., the least recently used page.
[0047] S120: The front end enables a full-duplex communication protocol based on TCP and sends a request command to the back end to obtain animation frame data. The back end accesses the animation frame data in the database according to the request command.
[0048] S130: The database returns the retrieved animation frame data to the backend. The backend assembles the animation frame data and sends it to the frontend.
[0049] Specifically, the front-end animation playback requests animation frame data from the back-end. The animation frame data is assembled from simulation data in IoTDB. The animation model asynchronously obtains animation frame data when it initializes its shape.
[0050] The animation frame data structure is shown in Table 3:
[0051]
[0052]
[0053] Table 3
[0054] In one embodiment of this application, when the animation model initializes its animation appearance, animation frame data is asynchronously acquired, and the step size information of the animation frame data is cached in a remote dictionary service Redis. The sampling frequency is determined based on the size of the animation model and the animation playback speed. Animation frame data is then retrieved from Redis according to the sampling frequency. If the animation playback speed is a first playback speed, the animation frame data is acquired using a first sampling frequency corresponding to the first playback speed. If the animation playback speed is a second playback speed, the animation frame data is acquired using a second sampling frequency that is lower than the first sampling frequency. The second playback speed is slower than the first playback speed, and the second sampling frequency corresponds to the second playback speed.
[0055] Specifically, the size of the acquired animation frame data is dynamically adjusted based on the size of the animation model and the animation playback speed. For animations with slow playback speeds, the animation frame data needs to be filtered by reducing the sampling rate. During the initialization of all animation models, the step size information of the animation frame data in IoTDB is cached in a remote dictionary service (RemoteDictionary Server, Redis) to facilitate frequent retrieval of frame data and improve the animation playback effect.
[0056] S140: The front end drives the position and shape of the animation model to change based on the animation frame data in order to achieve animation rendering.
[0057] Specifically, the front-end uses the Three.js engine to generate the animation model's shape and render the animation. Three.js is an open-source WebGL framework that encapsulates commonly used objects in 3D graphics programming in an easy-to-use, simple, and intuitive way. It utilizes many advanced graphics engine techniques to improve performance. It includes many commonly used objects and easy-to-use tools, making it a powerful and feature-rich application.
[0058] The online 3D animation uses Three.js as its front-end 3D animation engine. The 3D animation mainly consists of two parts: model creation and animation rendering. Seven animation variables are defined in the 3D animation; these seven variables uniquely identify an entity, and they are all included in the simulation data. The seven animation variables are as follows:
[0059] form: The geometry type of the entity
[0060] rxvisobj[3]: The x-axis of the entity (relative to the world coordinate system)
[0061] ryvisobj[3]: The y-axis of the entity (relative to the world coordinate system)
[0062] rvisobj[3]: The origin of the entity's coordinates (relative to the world coordinate system)
[0063] size[3]: Scaling factor in the three directions of length, width, and height.
[0064] material: the color of the solid and the specular reflectance.
[0065] extra: Additional information about the entity (the meaning of extra varies depending on the entity's shape).
[0066] Three.js provides geometry modeling functionality and supports modeling based on external model files, such as .stl, .obj, and .gltf formats. Furthermore, this invention supports geometric modeling of .dxf files by parsing triangular facets from .dxf model files.
[0067] In one embodiment of this application, the animation file is parsed to obtain a geometric type; the geometric type is represented by an animation variable in a preset 3D animation engine.
[0068] Specifically, the geometry type is represented by the Form variable in the animation. The entities in Modelica have the following geometry types, as shown in Table 4:
[0069]
[0070]
[0071] Table 4
[0072] In one embodiment of this application, the front end drives the position and shape of the animated figure to change based on the animation frame data, specifically including: determining the position and posture information of the geometry based on the animation variables in Three.js, wherein the position and posture information of the geometry is represented by an array; obtaining the four-dimensional transformation matrix of the geometry in the spatial coordinate system through matrix rotation and matrix scaling; and changing the position and shape of the animated figure based on the four-dimensional transformation matrix.
[0073] Specifically, the position and orientation of the geometric object are represented by four sets of variables in the animation variables: rxvisobj[3], ryvisobj[3], rvisobj[3], and size[3]. The four-dimensional transformation matrix of the geometric object in the spatial coordinate system is obtained by rotating and scaling the matrix.
[0074] The color and material of the geometry are represented by the animation variable "material". Different material information is expressed by color[3] and the reflection coefficient.
[0075] Based on the animation.json file generated from the simulation results and the initial frame data in the simulation result frame data, the data upon which the animation model's modeling depends can be obtained. The animation modeling process is as follows: Figure 3As shown.
[0076] In one embodiment of this application, the front end enables a full-duplex communication protocol based on TCP, sends a request command to the back end to obtain animation frame data, stores the animation frame data in a cache queue introduced by the front end, establishes an animation playback thread to continuously read animation frame data from the cache queue, establishes a timed thread to periodically obtain animation frame data from the back end, and when the content in the cache queue is less than half of the initial capacity, obtains animation frame data from the back end and writes it into the cache queue; the front end matches the animation model and updates the geometric information of the animation shape according to the animation frame data in the cache queue, thereby realizing the online animation effect on the front end.
[0077] In one embodiment of this application, the number of animation frames refreshed per unit time is controlled to be above a preset number of frames.
[0078] Specifically, the animation rendering effect is achieved by driving changes in the position and shape of the animated geometric shapes using simulation data. Front-end model rendering is performed based on the 3D animation data generated from the simulation, with animation frames driving the model's animation effects. The illusion of motion is created by rapidly displaying consecutive animation frames. To achieve a smooth animation effect, the frame rate (fps) needs to be controlled; generally, the animation frame rate should be controlled at 30 frames per second or higher.
[0079] The front-end uses a cache queue to store animation frames. The animation playback thread continuously reads animation frames from the cache queue, while a separate thread periodically retrieves animation frame data from the back-end service. When the content in the cache queue is less than half of its initial capacity, animation frames are retrieved from the back-end service and written to the queue.
[0080] The front-end uses animation frames from the cache queue to match animation models and updates their position, shape, color, and other information to achieve online animation effects. The specific process is as follows: Figure 4 As shown:
[0081] The parameters for the requested animation frames are shown in Table 5, and the response is shown in Table 3.
[0082]
[0083] Table 5
[0084] The various embodiments in this invention are described in a progressive manner. For the same or similar parts between the various embodiments, please refer to each other. Each embodiment focuses on describing the differences from other embodiments.
[0085] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process method or product that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process method or product. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process method or product that includes that element.
[0086] The above are merely embodiments of the present invention and are not intended to limit the invention. Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.
Claims
1. A rendering method for 3D simulation animation based on Modelica, characterized in that, include: The front end calls a simulation service. The simulation service reads the animation file generated by the Modelica solver and obtains the animation model based on the animation file. This includes: parsing the animation file to obtain the name of each animation component; querying the database for the animation information of each animation component based on the name of the animation component; assembling the animation file and the animation information to obtain animation component data; and obtaining animation model data based on the animation component data using a preset 3D animation engine. The front end initiates a full-duplex communication protocol based on the Transmission Control Protocol (TCP) and sends a request command to the back end to obtain animation frame data. The back end accesses the animation frame data in the database according to the request command; the database is an IoTDB database. The database returns the retrieved animation frame data to the backend, and the backend assembles the animation frame data and sends it to the frontend. The front end drives the position and shape of the animated character to change based on the animation frame data in order to achieve animation rendering.
2. The method according to claim 1, characterized in that, After the front-end enables a full-duplex communication protocol based on TCP and sends a request command to the back-end to obtain animation frame data, the method further includes: An animation frame data is stored in a cache queue introduced at the front end, and an animation playback thread is established to continuously read animation frame data from the cache queue. A timed thread is established to periodically retrieve animation frame data from the backend. When the content in the cache queue is less than half of the initial capacity, the animation frame data is retrieved from the backend and written into the cache queue. The front-end matches the animation model and updates the geometric information of the animation shape based on the animation frame data in the cache queue, thereby realizing the online animation effect on the front end.
3. The method according to claim 2, characterized in that, The method further includes: When the animation model initializes its animation shape, it asynchronously obtains animation frame data and caches the step size information of the animation frame data in the remote dictionary service Redis; The sampling frequency is determined based on the size of the animation model and the animation playback speed. Animation frame data is retrieved from the Redis based on the sampling frequency.
4. The method according to claim 3, characterized in that, The step of retrieving animation frame data from Redis according to the sampling frequency specifically includes: If the animation playback speed is the first playback speed, then the first sampling frequency corresponding to the first playback speed is used to obtain the animation frame data; If the animation playback speed is the second playback speed, then the second sampling frequency, which is lower than the first sampling frequency, is used to collect animation frame data; The second playback speed is slower than the first playback speed, and the second sampling frequency corresponds to the second playback speed.
5. The method according to claim 1, characterized in that, The front-end drives changes in the position and shape of the animated character based on the animation frame data, specifically including: The position and orientation information of the geometry are determined based on the animation variables in the preset 3D animation engine, and the position and orientation information of the geometry is represented by an array; The four-dimensional transformation matrix of the geometric object in the spatial coordinate system is obtained by rotating and scaling the matrix. The position and shape of the animated character are changed according to the four-dimensional transformation matrix.
6. The method according to claim 1, characterized in that, The method further includes: The animation component information parsed from the animation file is stored in a local cache; the animation component information includes the name of the animation component and the component geometry type. When the cache is full, the Least Recently Used (LRU) cache eviction policy is adopted to filter out animation component information in the cache according to the preset expiration time.
7. The method according to claim 1, characterized in that, The preset 3D animation engine is the Three.js engine.
8. The method according to claim 1, characterized in that, The method further includes: The geometry type is obtained after parsing the animation file; The geometry type is represented by animation variables in a preset 3D animation engine.
9. The method according to claim 2, characterized in that, The method further includes: Control the number of animation frames refreshed per unit of time to be above the preset number of frames.