Animation generation method and device and electronic equipment
By pre-generating the rendering data of the Spine animation frames and using GPU rendering, the problem of heavy CPU burden in the Spine animation rendering method is solved, and the efficient rendering effect is improved.
Patent Information
- Application Number
- CN202510805116.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-16
- Publication Date
- 2025-10-17
AI Technical Summary
The existing Spine animation rendering method relies on the CPU to calculate bone transformation and vertex deformation, which increases the CPU burden, limits the number of vertices and bones, and makes it difficult to meet efficient rendering requirements.
By pre-generating the animation rendering data corresponding to each animation frame based on Spine animation, using GPU for rendering, setting the rendering order and transparency of the sub-model, it ensures that the CPU does not need to calculate the animation rendering data in real time, reducing the CPU computing pressure.
It improves rendering effects without limiting the number of vertices and bones, meets users' various rendering needs, and reduces CPU computing pressure.
Smart Images

Figure CN120807733A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of rendering, in particular to an animation generation method and device and electronic equipment. BACKGROUND
[0002] In related technologies, the Spine animation rendering mode mainly depends on CPU computing bone transformation and vertex deformation. In this mode, the central processing unit (CPU) needs to compute the vertex position and color of all current frame display accessories every frame, and upload the data to the graphics processing unit (GPU). When there are a large number of Spine animation instances or too many Spine vertices in the scene, the CPU burden increases significantly. In order to reduce the CPU burden, the number of vertices and the number of bones need to be limited, which leads to poor rendering effect and is difficult to meet the artistic effect requirements of users. SUMMARY
[0003] Therefore, the purpose of the present application is to provide an animation generation method, device and electronic equipment, so that the CPU does not need to compute animation rendering data in real time, reduces the computing pressure of the CPU, removes the limitation of the number of vertices and bones, improves the rendering effect, and meets the various rendering requirements of users
[0004] In a first aspect, an embodiment of the present application provides an animation generation method, which comprises: obtaining animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to the corresponding bones of the target model; the animation rendering data comprises position information, color information and rendering order information of a plurality of sub-models corresponding to a plurality of animation frames; in the process of rendering each animation frame, the target model is rendered based on the position information, color information and rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; wherein the sub-models attached to the first bone of the target model have a rendering order greater than that of other sub-models attached to the first bone, and the other sub-models are in an invisible state.
[0005] In a second aspect, an embodiment of the present application provides an animation generation apparatus, comprising: a rendering data acquisition module, configured to acquire animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to corresponding bones of the target model; the animation rendering data comprises position information, color information and rendering order information of the plurality of sub-models corresponding to a plurality of animation frames; an animation generation module, configured to, in a process of rendering each animation frame, render the target model based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; wherein, a sub-model with a rendering order greater than that of other sub-models attached to a first bone of the target model is in a visible state, and the other sub-models are in an invisible state.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, the memory storing machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the animation generation method described above.
[0007] In a fourth aspect, an embodiment of the present application provides a machine readable storage medium, the machine readable storage medium storing machine executable instructions, and the machine executable instructions, when invoked and executed by a processor, cause the processor to implement the animation generation method described above.
[0008] The embodiments of the present application have the following beneficial effects:
[0009] The animation generation method, the apparatus and the electronic device described above acquire animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to corresponding bones of the target model; the animation rendering data comprises position information, color information and rendering order information of the plurality of sub-models corresponding to a plurality of animation frames; in a process of rendering each animation frame, the target model is rendered based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; wherein, a sub-model with a rendering order greater than that of other sub-models attached to a first bone of the target model is in a visible state, and the other sub-models are in an invisible state. This way, animation rendering data corresponding to each animation frame based on Spine animation is generated in advance, so that the CPU does not need to calculate the animation rendering data in real time, the computing pressure of the CPU is reduced, the limitation on the number of vertices and the number of bones is removed, the rendering effect is improved, and various rendering requirements of users are met.
[0010] Other features and advantages of the present application will be set forth in the descriptions that follow, and in part will be apparent from the description, or can be learned by practice of the application. The purposes and other advantages of the application will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
[0011] To make the above objectives, features and advantages of the present application more obvious and easy to understand, the following preferred embodiments are specifically described below, and the accompanying drawings are referred to for details. BRIEF DESCRIPTION OF DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings described below are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0013] Figure 1 A flow chart of an animation generation method provided by an embodiment of the present application is shown in the figure;
[0014] Figure 2 A schematic diagram of an interface for displaying Spine resource information provided by an embodiment of the present application is shown in the figure;
[0015] Figure 3 A flow chart of a pre-processing stage process provided by an embodiment of the present application is shown in the figure;
[0016] Figure 4 A schematic diagram of display relationship between accessories provided by an embodiment of the present application is shown in the figure;
[0017] Figure 5 A structural schematic diagram of an animation generation device provided by an embodiment of the present application is shown in the figure;
[0018] Figure 6 A structural schematic diagram of an electronic device provided by an embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0019] In order to make the purposes, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of the present application will be described clearly and completely below with reference to the drawings. Obviously, the described embodiments are some embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the present application.
[0020] Spine is a 2D skeleton animation system widely used in games and interactive applications. The animation system has the following concepts:
[0021] 1. Skeleton: Defines the structure and hierarchy of a character and provides a hierarchy of changes.
[0022] 2. Attachment: An attachment is an actual visual element that is attached to a slot and moves with the skeleton. An attachment is a model (also called a "mesh") composed of multiple vertices and triangles. An artist can create deformation animations by editing the vertices of the mesh when editing animations. There can be multiple attachments under one slot. However, only one attachment can be displayed at a time. For example, there are three attachments under the slot corresponding to the eyes of a character, one for fully open eyes, one for half open eyes, and one for closed eyes. The three attachments are three images representing different eye states.
[0023] 3. Slot: A slot is a container for an attachment that connects the attachment to the skeleton.
[0024] The Spine animation rendering method mainly relies on CPU to calculate bone transformations and vertex deformations, and the specific implementation is as follows:
[0025] 1. First, load Spine animation data, such as skeleton, mesh, etc.
[0026] 2. Determine the attachment to be displayed in the current frame, and organize the attachment mesh to be displayed into a complete display mesh.
[0027] 3. CPU calculates the bone hierarchy and transformation matrix, applies bone weights, and superimposes attachment vertex change coordinates to calculate the final position of each attachment vertex.
[0028] 4. CPU calculates the color of the skeleton, slot, and attachment, and applies it to the final color of each attachment vertex.
[0029] 5. CPU uploads the calculated vertex data to GPU.
[0030] 6. GPU performs texture sampling and superimposes vertex color.
[0031] 7. The final image is rendered to the screen.
[0032] The main bottleneck of this process is that the CPU needs to calculate the vertex position and color of all attachments to be displayed in the current frame, and upload the data to the GPU. When there are a large number of Spine animation instances or a large number of Spine vertices in the scene, the CPU burden increases significantly.
[0033] This method has the following limitations:
[0034] 1. Limit the number of vertices and bones when artists create Spine resources. Limitation: limiting the number of vertices and bones means sacrificing artistic effects and not being able to achieve fine artistic expression
[0035] 2. The animation out of the field of view stops updating the vertex calculation, making it difficult to achieve efficient rendering of a large number of animation instances
[0036] In animation rendering, to reduce the CPU calculation pressure, the GPU Skinning (GPU skinning) method can be used to reduce the CPU side pressure. In specific implementation, the change matrix of the bone can be saved to the map by referring to the skinning calculation process of the CPU side, and then the skinning calculation process is transferred to the CPU side.
[0037] However, this method cannot be directly applied to Spine animation. Because GPU Skinning is saved to the map according to the bone unit. It cannot support the following cases of Spine animation:
[0038] a. The vertices of the attachment itself will also move, and the CPU side needs to superimpose the vertex position of the attachment itself when calculating the bone weight.
[0039] b. Spine animation is not a traditional bone animation. Traditional bone animation requires a complete mesh, and each vertex of the mesh is assigned a weight. However, Spine animation is a real-time animation mesh. Different frames may have different meshes. For example, the first frame displays an open-eyed attachment, so the current mesh is an open-eyed mesh. The second frame displays a half-opened eye attachment, so the current mesh is a half-opened eye mesh. The third frame is a closed eye attachment, so the current mesh is a closed eye mesh. The three frames are a closed eye animation in succession.
[0040] c. When the first frame of the Spine animation shows the hand in front of the clothes, and the second frame shows the hand behind the clothes, the rendering order changes, that is, the triangle index of the mesh changes. GPU Skinning has only one mesh, and one mesh has only one triangle index, which cannot correspond to multiple triangle indices.
[0041] Therefore, the embodiment of the present application provides an animation generation method, device and electronic equipment, which can be applied to the scene of generating animation based on the Spine system.
[0042] Referring to Figure 1 , first, an animation generation method provided by the embodiment of the present application is introduced. The method includes the following steps:
[0043] Step S102, obtaining animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to the corresponding bones of the target model; the animation rendering data includes position information, color information and rendering order information of a plurality of sub-models corresponding to a plurality of animation frames.
[0044] The target model has corresponding bones. The sub-models are attached to the bones corresponding to the target model, and the sub-models are equivalent to the above-mentioned accessories, which are usually attached to the bones through the slots arranged on the bones. The sub-models on each slot can be one or multiple, which can be set according to requirements.
[0045] When multiple sub-models are arranged on a slot, only one sub-model required by the user is in a visible state, and the others are in an invisible state. In the process of rendering and baking through the Spine system, the sub-models required to be in the invisible state are not rendered, and only the sub-models required to be in the visible state are rendered. Therefore, in the process of generating animation, the vertices rendered by the Spine system in different animation frames can be different. When the same model is rendered by the GPU, the vertices rendered each time usually need to be the same. In order to solve this problem, the rendering data of the vertices of all sub-models constituting the target model need to be obtained.
[0046] In the above-mentioned animation rendering data, the rendering data of the vertices of all sub-models constituting the target model, such as position information and color information, are included. In the Spine system, when multiple sub-models correspond to the same slot, the rendering order of each sub-model is related to whether the sub-model is visible. The last rendered sub-model is visible, and the other sub-models are occluded or partially occluded. Therefore, based on the sub-models required to be displayed, the rendering order of multiple sub-models needs to be set. At the same time, in order to make the sub-models not required to be displayed in the invisible state, the transparency parameters of the vertices of these sub-models can be set to be transparent, that is, not to be displayed.
[0047] The above-mentioned animation rendering data can directly include the position information, color information and rendering order information of multiple sub-models corresponding to multiple animation frames required to be rendered, or can only include the position information, color information and rendering order information of multiple sub-models corresponding to part of the animation frames required to be rendered, for example, only including the position information, color information and rendering order information of multiple sub-models corresponding to multiple key frames. The position information, color information and rendering order information of multiple sub-models corresponding to other animation frames can be obtained by interpolating the data of the key frames, and then used to render and generate the corresponding animation frames.
[0048] In step S104, in the process of rendering each animation frame, the target model is rendered based on the position information, color information and rendering order information of multiple sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; wherein the sub-models with a rendering order greater than other sub-models attached to the first bone are in a visible state, and the other sub-models are in an invisible state.
[0049] In the process of generating an animation, each animation frame needs to be rendered in sequence according to the playback order of the animation frames. The plurality of animation frames are presented on the screen in sequence, that is, the animation is formed. In the process of rendering each animation frame, the target model needs to be rendered based on the position information and color information of the plurality of sub-models corresponding to the animation frame, to form the animation frame.
[0050] As described above, the rendering order of the plurality of sub-models may change in different animation frames. Therefore, when rendering a certain animation frame, the rendering order of the plurality of sub-models needs to be determined based on the rendering order information corresponding to the animation frame, and then the rendering order of all vertices of the target model is determined. Then, based on the rendering order, the position information and color information of each vertex are obtained in sequence, and the corresponding vertex is rendered, so as to realize the rendering of the target model.
[0051] In this way, the rendering order of the plurality of sub-models is limited by the above-mentioned rendering order information, so that the display effect of the rendered target model is the same as the rendering effect of the target model by the Spine system. Assuming that the first bone corresponding to the target model is attached with a plurality of sub-models. In the Spine system, only the sub-models that need to be displayed are rendered for the plurality of sub-models attached to the first bone, and other sub-models are not rendered. However, in the process of rendering by GPU, each sub-model needs to be rendered.
[0052] In order to enable the sub-models that need to be displayed to be displayed completely, the rendering order of the sub-models needs to be set to be greater than the rendering order of other sub-models corresponding to the first bone, that is, the sub-models are rendered last. In order to prevent other sub-models from being displayed, other sub-models can also be rendered to be completely transparent in the process of rendering. Therefore, in the plurality of sub-models rendered by the above-mentioned method, the sub-models with rendering order greater than other sub-models attached to the first bone are in a visible state, and other sub-models are in an invisible state, so as to improve the rendering efficiency and achieve the required rendering effect.
[0053] The animation generation method comprises the following steps: obtaining animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to bones corresponding to the target model; the animation rendering data comprises position information, color information and rendering order information of the plurality of sub-models corresponding to a plurality of animation frames; in the process of rendering each animation frame, the target model is rendered based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame, so as to generate an animation corresponding to the target model; and in the plurality of sub-models attached to a first bone corresponding to the target model, a sub-model with a rendering order greater than that of other sub-models attached to the first bone is in a visible state, and the other sub-models are in an invisible state. The method pre-generates animation rendering data corresponding to each animation frame based on Spine animation, so that the CPU does not need to calculate the animation rendering data in real time, the computing pressure of the CPU is reduced, the limitation on the number of vertices and the number of bones is removed, the rendering effect is improved, and various rendering requirements of users are met.
[0054] In an embodiment, the animation rendering data of the target model is determined by the following method.
[0055] The rendering order information can be determined by the following method.
[0056] (1) determining vertices of a plurality of sub-models constituting the target model; a first bone corresponding to the target model is attached to a plurality of first sub-models.
[0057] The target model is composed of a plurality of sub-models. Each sub-model comprises a plurality of vertices, and the sub-model is composed of a primitive formed by the vertices. Each primitive is a polygon, which can be a triangle or a quadrilateral, and is not limited herein.
[0058] The bones corresponding to the target model are usually a plurality of bones. Each sub-model needs to be attached to a bone through a slot. The movement of the bone will cause the position of the sub-model to move, and may also cause the sub-model to deform. The user can usually set the sub-model to deform, that is, to change the relative positions between the vertices in the sub-model.
[0059] Suppose the target model corresponds to a first bone attached with multiple sub-models, these sub-models are referred to as first sub-models. There is usually and only one first sub-model in the multiple first sub-models in a visible state at each animation stage. The above-mentioned first bone can be multiple, and different first bones are attached with different multiple first sub-models. Usually, which sub-model in the multiple first sub-models is in a visible state and which sub-model is in an invisible state can be set in advance. In order to form a dynamic effect, multiple animation stages can be divided in advance, and in different animation stages, the first sub-model in a visible state is usually different, or in adjacent animation stages, the first sub-model in a visible state is different. Wherein, the animation stages can be divided according to the playing time length, or can also be divided based on the arrangement order of the animation frames, which is not limited here.
[0060] (2) For each animation frame, based on the animation stage corresponding to the animation frame, determine the order parameter of the multiple first sub-models in the animation frame.
[0061] In the same animation stage, the first sub-model in a visible state will not change, and the rendering order of the multiple first sub-models will also not change, and then for multiple animation frames in the same animation stage, the order parameter of the multiple first sub-models in the animation frame needs to be determined only once. Specifically, for the first animation frame, based on the first animation stage corresponding to the first animation frame, the order parameter of the multiple first sub-models in the first animation frame is determined. Then, for the second animation frame corresponding to the first animation stage, the order parameter of the multiple first sub-models in the first animation frame is determined as the order parameter corresponding to the second animation frame. Wherein, the second animation frame is a continuous animation frame after the first animation frame, and can be one or more. When the first animation stage becomes the second animation stage, for the third animation frame, based on the second animation stage corresponding to the third animation frame, the order parameter of the multiple first sub-models in the first animation frame is determined. By analogy, the vertex of the sub-model in the multiple animation frames can be determined
[0062] In the case that the order parameters of the plurality of first sub-models are in a certain animation frame, the first sub-models in the animation stage corresponding to the animation frame and in the visible state can be determined as the to-be-displayed sub-models. Then, based on the model quantity of the first sub-models attached to the first skeleton, the first order parameter of the to-be-displayed sub-models and the second order parameters of the other first sub-models except the to-be-displayed sub-models are determined. The first order parameter of the to-be-displayed sub-models is greater than or equal to the model quantity. For example, in the case that the model quantity of the first sub-models attached to the first skeleton is 4, the first order parameter of the to-be-displayed sub-models can be set as 4 or an integer greater than or equal to 5. The second order parameters of the other three sub-models can be set as 1, 2 and 3 respectively. It is required to ensure that the second order parameters are less than the first order parameters and the order parameters of different first sub-models are different. The order parameters of the first sub-models can be marked on the vertices of the sub-models. For example, the Spine system is usually used for animation production of two-dimensional models. The vertex coordinates of the two-dimensional models only have X and Y axis parameters. The Z axis parameter can be added to the vertices to record the order parameters. That is, when the order parameter of a certain first sub-model is 4, the Z coordinate of the vertex of the model is 4.
[0063] (3) determining the rendering order information of the vertices of the plurality of sub-models in the animation frame based on the order parameters of the plurality of first sub-models.
[0064] The vertices of each sub-model have a preset relative rendering order. The relative rendering order is used to indicate the rendering order of the primitives constituting the sub-model. The primitive is connected by a plurality of vertices. For example, when the primitive is a triangle, the primitive can be represented by three vertices. Usually, in each sub-model, the rendering order of the primitive is determined, and then the rendering order of the vertex is determined, that is, the relative rendering order is determined.
[0065] When the slot on the skeleton is only provided with one sub-model, the rendering order of the sub-model will not change. Therefore, after the order parameter of the first sub-model is determined, the rendering order of the plurality of sub-models is also determined. Specifically, based on the order parameter of the first sub-model, the rendering order of the plurality of sub-models can be determined. For example, the target model is composed of sub-models 1, 2, 3 and 4. The sub-model 1 and the sub-model 2 are attached to different skeletons, the sub-model 3 and the sub-model 4 are attached to the same skeleton, and are not in the visible state at the same time. If the rendering order of the sub-model 3 and the sub-model 4 is: rendering the sub-model 4 first, and then rendering the sub-model 3, the rendering order of the sub-models is: rendering the sub-models 1, 2, 4 and 3 in turn. Then, based on the rendering order of the plurality of sub-models and the relative rendering order of the vertices of the sub-models, the rendering order information of the vertices of the plurality of sub-models in the animation frame is determined. In the above case, that is, in the order of the sub-models 1, 2, 4 and 3, the relative rendering order of each model is sorted in turn, so that the rendering order information of the vertices of the plurality of sub-models in the animation frame is obtained.
[0066] For color information, it can be determined in the following manner:
[0067] (1) For each animation frame, based on the animation stage corresponding to the animation frame, determine the transparency parameters of the plurality of first sub-models in the animation frame.
[0068] In order to ensure that the to-be-displayed sub-model is in a visible state, the transparency parameter of the to-be-displayed sub-model can be determined as the first transparency parameter, so that the to-be-displayed sub-model is in a visible state, and the transparency parameters of the other first sub-models except the to-be-displayed sub-model are determined as the first transparency parameter, so that the to-be-displayed sub-model is in an invisible state. For example, when the transparency parameter is 0, it means opaque, and when the transparency parameter is 1, it means completely transparent; then the transparency parameter of the to-be-displayed sub-model can be set to 0, and the transparency parameters of the other first sub-models can be set to 1.
[0069] (2) Based on the transparency parameters of the vertices of the first sub-model and the preset color texture map, determine the color information of the vertices of the plurality of sub-models in the animation frame.
[0070] Each vertex can have a pre-set vertex color information. Each vertex also has a texture map (UV) coordinate, from which the vertex corresponding map color information can be read from the preset color texture map. As described above, the transparency parameter set for the vertex is also based on whether the first sub-model needs to be in a visible state. The color information of the vertices of the sub-model in the animation frame can be determined based on the above several parameters.
[0071] For position information, it can be determined in the following manner: based on the attachment relationship between the target model corresponding skeleton and the sub-model and the self-offset parameter of the vertex, determine the position information of the vertices of the plurality of sub-models in the animation frame; the self-offset parameter is used to indicate the relative position offset of the vertex and the sub-model.
[0072] As described above, under the user's setting, each sub-model can be deformed, that is, the vertices and the sub-models have a relative position offset, at this time, the self-offset parameter of the vertex can be obtained. When determining the position information of the vertex, the position, angle, etc. of the sub-model attached to the bone in the animation frame can be determined first, so as to determine the position and angle of the entire sub-model attached to the bone, and then the position information of each vertex in the animation frame can be determined by combining the self-offset parameter of each vertex and the initial relative position of the vertex in the sub-model.
[0073] It is worth noting that when the above process is implemented through the Spine system, the Spine system may disturb the arrangement order of the vertices when determining the rendering parameters of the vertices. In order to restore the arrangement order of the vertices, based on the principle that the UV coordinates of the vertices are unchanged, the position information and color information of the vertices can be saved one-to-one corresponding to the vertices based on the UV coordinates of the vertices.
[0074] In actual application, the position information of the plurality of sub-models can be saved through images. In specific implementation, a first image can be created based on the frame number of the animation frames and the vertex number of the vertices of the plurality of sub-models. For example, when the frame number of the animation frames is 50 and the vertex number is 100, a first image with a size of 1000 pixels x 50 pixels can be created. The first arrangement order of the vertices of the plurality of sub-models is determined, which can be the subscript order of the vertices. Then, the position information of the vertices in each animation frame is saved through the pixels of the first image based on the first arrangement order and the frame number of the animation frames. Generally, the vertices in each row are arranged in the first arrangement order.
[0075] The animation rendering data generated in the above manner can only include the position information, color information and rendering order information of the plurality of sub-models corresponding to the plurality of key frames. At this time, the animation rendering data can be referred to as initial animation rendering data. In order to determine the animation rendering data corresponding to each animation frame, for each animation frame, the target key frame corresponding to the animation frame and the weight of the target key frame are determined based on the playing time of the animation frame. The target key frame usually includes the previous key frame and the next key frame located in the current animation frame. The weight is usually calculated based on the time difference between the current animation frame and the previous key frame and the time difference between the current animation frame and the next key frame. Further, the position information, color information and rendering order information of the plurality of sub-models corresponding to the animation frame can be determined based on the weight of the target key frame, the position information, color information and rendering order information of the plurality of sub-models corresponding to the target key frame. Generally, the interpolation calculation can be performed based on the weight.
[0076] The following embodiments provide an implementation manner of rendering a target model based on the position information, color information and rendering order information of the plurality of sub-models corresponding to the animation frames.
[0077] The rendering order information usually includes the arrangement order of the vertices of the plurality of sub-models in each animation stage. In the process of rendering an animation frame, the arrangement order of the vertices of the plurality of sub-models corresponding to the animation frame is determined based on the animation stage corresponding to the animation frame. Then, the vertices to be rendered are determined in sequence based on the arrangement order of the vertices of the plurality of sub-models. For each vertex to be rendered, the position information of the vertex to be rendered can be determined from the position information of the plurality of sub-models. When the position information is stored by a map, the position information of the vertex can be read from the map based on the position of the vertex in the first arrangement order. The color information of the vertex to be rendered also needs to be determined from the color information of the plurality of sub-models. Similar to the position information, the color information can also be stored in a map, and the color information of the vertex also needs to be read from the map based on the position of the vertex in the arrangement order in which the map is stored. Further, the vertex to be rendered is rendered based on the position information and the color information of the vertex to be rendered, and the above-mentioned manner is continuously used to render the vertices to be rendered in sequence until the last vertex in the arrangement order is rendered.
[0078] The embodiment of the present application also provides another animation generation method, which is realized on the basis of the method shown in the figure. Figure 1 The method provides a method for converting a Spine animation into a GPU vertex animation, the method modifies the Spine source code, ensures that complete mesh information that can be used by a GPU is output when the Spine animation is played in each frame, that is, the mesh includes mesh information of all accessories. The position and color of each animation vertex are pre-calculated and stored in a map. In each frame, a check is performed, and if the rendering order changes, the current triangle index is saved. When the animation rendering is implemented, the data obtained through the above preprocessing is input into the correct mesh and map, the position and color of the vertex are sampled on the GPU side, and when the position and color of the animation vertex are calculated on the GPU, an interpolation calculation technology is used, and the memory of the saved map is greatly reduced.
[0079] The method includes a preprocessing stage and a runtime stage:
[0080] The preprocessing stage is the process of obtaining animation rendering data. First, the Spine source code is modified, so that complete mesh information that can be used by a GPU is output when the Spine animation is played in each frame, that is, the mesh includes mesh information of all accessories. Then, the position and color of each animation vertex are pre-calculated and stored in a map. In each frame, a check is performed, and if the rendering order changes, the current triangle index is saved. Through the preprocessing interface, animation rendering data can be obtained. Specifically, the following parts are included:
[0081] 1. Save the map of the position and color of the vertex.
[0082] 2. Complete mesh including all the mesh information of the attachments. For example, the complete Spine mesh has 3529 vertices and 3262 triangles.
[0083] 3. Animation description file, which records the name, time, position map and color map of each animation. The animation rendering order changes correspond to the triangle index. As shown in the following table, the Size in Spine Animation Datas is 3, indicating that there are three animations exported from the current Spine resource. Vertex Position Tex in Element0 indicates the position map currently used, and Vertex Color Tex indicates the color map. Animation Name is the name of the animation, and Duration is the animation time. The Size in Serialized Frame Mapping is 3, indicating that there are three places where the rendering order changes in the current animation. Element1 indicates the first change in the rendering order, Frame Index is the specific frame number where the change occurs, i.e., the 44th frame, and Triangle Config index is 1, indicating that the first set of triangle index data (i.e., vertex order arrangement data) is taken. Figure 2
[0084] The runtime stage is equivalent to the process of generating the animation of the target model based on the animation rendering data. In the CPU, the animation data is read, and the frame number is calculated by time. If the current frame has a rendering order change, the correct triangle index is set (i.e., the rendering order of the vertices of multiple sub-models in this animation frame is determined), ensuring that the rendering order of the animation is correct. In the CPU, the vertex position and color information of the key frames of the previous frame and the next frame are sampled through the vertex shader, and the vertex and color of the current frame are calculated through interpolation, greatly reducing the memory of the position and color maps saved in the preprocessing stage.
[0085] As shown in the following table, the preprocessing stage is implemented in the following way: Figure 3
[0086] A. Get complete mesh information
[0087] The original Spine animation, in order to reduce the vertex calculation pressure of each frame, will exclude the attachments that do not need to be displayed in the CPU stage. However, the mesh obtained in this way is not the same for each frame, and there is no way to ensure that each row of the map saves all the vertex information. Therefore, it is not possible to use GPU as a rendering accelerator. Therefore, the Spine source code needs to be modified to add all the attachments that do not need to be displayed to the mesh, but the transparency of the vertices of the attachments that do not need to be displayed is set to 0, which ensures that the mesh includes all the information of the attachments and ensures the correct display.
[0088] For example, the left picture shows that the first frame displays a rectangular attachment, and the right picture shows that the second frame displays a triangular attachment. The triangular information needs to be added to the mesh in the first frame, but the vertex transparency of the triangle is set to 0. The rectangular information is also added to the mesh in the second frame, but the vertex transparency of the rectangle is set to 0. Thus, the mesh including all attachments is ensured, and the correct picture is ensured. Figure 4
[0089] Meanwhile, the Z value of the attachment vertex (equivalent to the above-mentioned "order parameter") needs to be set according to the order of the appearance of the attachment. Since the Spine animation is a two-dimensional animation, the initial Z value of the attachment vertex is usually 0. On the one hand, it is to solve the flicker problem of Zfight, that is, all meshes are in a plane, and the picture will flicker. On the other hand, it is used for checking the change of rendering order later.
[0090] For example, if the third frame displays the rectangle and the triangle at the same time, and the rectangle is displayed in front of the triangle, the Z value of the triangle is set to 1, and the Z value of the rectangle is set to 2. If the fourth frame displays the rectangle and the triangle at the same time, and the triangle is displayed in front of the rectangle, the Z value of the rectangle is set to 1, and the Z value of the triangle is set to 2.
[0091] B saves the position information and color information of the vertex to the map
[0092] A map is created to store the position and part of the vertex color information of the vertex in the format of RGBAHalf. Since the position information changes greatly, single-precision floating-point numbers are used to save the position information of the vertex, but a RGBAHalf map has four channels of RGBA, and only three dimensions of xyz need to be saved when saving the position. The transparency of the vertex can be saved to the A channel of the position map. A vertex color map is created in the format of RBG24, and the RGB value of the vertex is saved to the RGB channel. By merging the saved map information, the memory of the map is reduced.
[0093] For example, a spine model with 3988 vertices is preprocessed for 10.875 seconds of death animation. Assuming that the sampling rate is set to 8 frames per second, the 10.875-second animation will have 1.875*8=87 frames. Then two maps with a width of 3988 and a height of 87 need to be created. The width of the map represents the number of vertices, and the height of the map represents the total number of frames. By merging the position and color maps, the memory of the A channel of the color map can be reduced
[0094] Spine animation can change the rendering order during the animation process. As mentioned above, if the third frame rectangle and triangle are displayed at the same time, and the rectangle is displayed in front of the triangle, the data of the first vertex is the vertex data of the triangle. If the fourth frame rectangle and triangle are displayed at the same time, and the triangle is displayed in front of the rectangle, the data of the first vertex is the vertex data of the rectangle. Therefore, the vertex data of the current frame cannot be directly assigned to the map. A standard mesh needs to be determined at the first frame, and the map is saved according to the vertex information of the standard mesh in the subsequent saving.
[0095] Because the mesh data only contains the concepts of vertices, UV, and triangles. The UV of the triangle is determined and will never change. The UV of the triangle can be used to determine whether the triangles of two frames are the same triangle. In this way, the corresponding position information in the subsequent frame can be found through the triangles in the standard mesh. The corresponding position and color information of the triangle are found and written into the map.
[0096] C Save the triangle index that has changed the rendering order
[0097] In the A stage, the Z value of the vertex has been set according to the rendering order. It is necessary to compare the previous frame and the current frame to determine whether the Z value of the triangle in the standard mesh has changed. If the change has occurred, the triangle index of the current frame needs to be saved. If the saved triangle index already exists, only the existing triangle index needs to be referenced. In this way, the repeated triangle index memory can be saved.
[0098] The runtime stage is implemented in the following way:
[0099] A reads the resources exported by the preprocessing stage: Spine description file, standard mesh, position and color map used.
[0100] B CPU calculates the current frame and sets the correct triangle index: According to the playback time, the frame number is converted on the CPU side, and it is determined whether the current frame needs to switch the triangle index. If it is needed, the triangle index information is correctly set to ensure the correct rendering order.
[0101] C GPU obtains the position and color information of the previous frame and the next frame according to the current frame calculated by the CPU, and calculates the position and color information of the current frame through interpolation. Return to the map saved in the preprocessing interface. If a 3-second animation is exported according to the process of the game, 60 frames are displayed per second, a map with a height of 180 will be obtained. However, the exported map is huge, and the longer the animation, the larger the exported map. If only 2 frames are exported per second, a map with a height of 6 will be obtained, which is 30 times more memory optimized than before. However, the result is that the picture is not smooth, because there are only two frames of data in one second, which means there are only two changes in the picture in one second. Therefore, it is proposed to do frame interpolation on the GPU side, so that smooth picture effect can be obtained with less data saved.
[0102] For example: the CPU calculates that the current frame is 1.7 frames, then in the GPU, the vertex positions and colors of the first frame and the second frame are sampled. The 1.7th frame position = the 1st frame position * (1-(1.7-1)) + the 2nd frame position * (2-1.7). The color calculation is the same.
[0103] The method guarantees that all accessory information is added to the mesh by modifying the Spine source code, ensuring that GPU calculation can be performed. And by setting the Z value of the accessory in sequence, the Z fight problem is solved, and whether the rendering order changes is judged; in the baking process, the position and color information of the corresponding triangle in each frame is found through the triangle UV of the standard mesh; by merging the position and color information of the vertices into the map, each channel of the RGBAHalf format map is fully utilized, and the memory of the saved map is reduced; by comparing whether the Z value of the triangle changes before and after the frame, the triangle index of the mesh is saved, and the rendering order change in the animation process is solved; by performing inter-frame interpolation calculation on the GPU side, the number of frames sampled in the preprocessing stage is greatly reduced, and the memory of the map is reduced.
[0104] For the above method embodiment, refer to Figure 5 The animation generation device shown in the drawing comprises:
[0105] The rendering data acquisition module 502 is configured to acquire animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to corresponding bones of the target model; the animation rendering data comprises position information, color information and rendering order information of a plurality of sub-models corresponding to a plurality of animation frames;
[0106] The animation generation module 504 is configured to render the target model based on the position information, the color information, and the rendering order information of the plurality of sub-models corresponding to each animation frame, to generate an animation corresponding to the target model during rendering of each animation frame; and the sub-models attached to the first bone of the target model and having a rendering order greater than that of other sub-models attached to the first bone are in a visible state, and the other sub-models are in an invisible state.
[0107] The animation generation device described above obtains animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to bones corresponding to the target model; the animation rendering data includes position information, color information, and rendering order information of a plurality of sub-models corresponding to a plurality of animation frames; during rendering of each animation frame, the target model is rendered based on the position information, the color information, and the rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; and the sub-models attached to the first bone of the target model and having a rendering order greater than that of other sub-models attached to the first bone are in a visible state, and the other sub-models are in an invisible state. This way, animation rendering data corresponding to each animation frame based on Spine animation is generated in advance, so that the CPU does not need to calculate the animation rendering data in real time, the computing pressure of the CPU is reduced, the limitation on the number of vertices and the number of bones is removed, the rendering effect is improved, and various rendering requirements of users are met.
[0108] The device described above further includes a rendering order information determination module configured to determine vertices of a plurality of sub-models composing a target model; a first bone corresponding to the target model is attached to a plurality of first sub-models; for each animation frame, based on an animation stage corresponding to the animation frame, order parameters of the plurality of first sub-models in the animation frame are determined; and based on the order parameters of the plurality of first sub-models, rendering order information of the vertices of the plurality of sub-models in the animation frame is determined.
[0109] The rendering order information determination module described above is further configured to, for a first animation frame, based on a first animation stage corresponding to the first animation frame, determine order parameters of the plurality of first sub-models in the first animation frame; for a second animation frame corresponding to the first animation stage, the order parameters of the plurality of first sub-models in the first animation frame are determined as order parameters corresponding to the second animation frame; for a third animation frame, based on a second animation stage corresponding to the third animation frame, the order parameters of the plurality of first sub-models in the first animation frame are determined; and the second animation stage is different from the first animation stage.
[0110] The rendering order information determination module is further configured to: determine a first sub-model in a visible state in an animation phase corresponding to the animation frame as a to-be-displayed sub-model; determine a first order parameter of the to-be-displayed sub-model and a second order parameter of other first sub-models than the to-be-displayed sub-model based on a model quantity of the first sub-model attached to the first bone; the first order parameter is greater than or equal to the model quantity; the second order parameter is less than the first order parameter; and the order parameters of different first sub-models are different.
[0111] Each of the sub-models has preset relative rendering orders of vertices; the relative rendering orders are used to indicate rendering orders of primitives constituting the sub-models; the primitives are connected by the vertices; and the rendering order information determination module is further configured to: determine rendering orders of the sub-models based on the order parameters of the first sub-models; and determine rendering orders of the vertices of the sub-models in the animation frame based on the rendering orders of the sub-models and the relative rendering orders of the vertices of the sub-models.
[0112] The position information of the sub-models is saved by the first image; the device comprises: an image creation module configured to create the first image based on frame numbers of the animation frames and vertex numbers of the vertices of the sub-models; an arrangement order determination module configured to determine a first arrangement order of the vertices of the sub-models; and a position information saving module configured to save the position information of the vertices in each animation frame by pixels of the first image based on the first arrangement order and the frame numbers of the animation frames.
[0113] The device further comprises a color information determination module configured to: for each animation frame, determine transparency parameters of the first sub-models in the animation frame based on an animation phase corresponding to the animation frame; and determine color information of the vertices of the sub-models in the animation frame based on the transparency parameters of the vertices of the first sub-models and a preset color texture map.
[0114] The color information determination module is further configured to: determine a first sub-model in a visible state in an animation phase corresponding to the animation frame as a to-be-displayed sub-model; determine a first transparency parameter of the to-be-displayed sub-model so that the to-be-displayed sub-model is in the visible state; and determine transparency parameters of other first sub-models than the to-be-displayed sub-model as the first transparency parameter so that the to-be-displayed sub-model is in an invisible state.
[0115] The device further comprises a position information determination module configured to: determine position information of the vertices of the sub-models in the animation frame based on an attachment relationship between a target model and the sub-models and a self-offset parameter of the vertices; and the self-offset parameter is used to indicate a relative position offset of the vertices and the sub-models.
[0116] The rendering order information includes an arrangement order of vertices of the plurality of sub-models in each animation stage; the animation generation module is further configured to: determine, based on an animation stage corresponding to an animation frame, an arrangement order of vertices of a plurality of sub-models corresponding to the animation frame; determine, based on the arrangement order of the vertices of the plurality of sub-models, a vertex to be rendered; determine, from position information of the plurality of sub-models, position information of the vertex to be rendered; determine, from color information of the plurality of sub-models, color information of the vertex to be rendered; and render the vertex to be rendered based on the position information and the color information of the vertex to be rendered, and continue to determine the vertex to be rendered based on the arrangement order of the vertices of the plurality of sub-models until the vertex to be rendered is the last vertex in the arrangement order.
[0117] The rendering data acquisition module is further configured to: acquire initial animation rendering data of the target model; the initial animation rendering data includes position information, color information, and rendering order information of a plurality of sub-models corresponding to a plurality of key frames; for each animation frame, determine a target key frame corresponding to the animation frame and a weight of the target key frame based on a playing time of the animation frame; and determine position information, color information, and rendering order information of a plurality of sub-models corresponding to the animation frame based on the weight of the target key frame, the position information, the color information, and the rendering order information of the plurality of sub-models corresponding to the target key frame.
[0118] The embodiment also provides an electronic device including a processor and a memory, the memory storing machine executable instructions executable by the processor, and the processor executes the machine executable instructions to implement the animation generation method described above, for example:
[0119] acquire animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to bones corresponding to the target model; the animation rendering data includes position information, color information, and rendering order information of a plurality of sub-models corresponding to a plurality of animation frames; in the process of rendering each animation frame, the target model is rendered based on the position information, the color information, and the rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; and among the plurality of sub-models attached to a first bone corresponding to the target model, a sub-model with a rendering order greater than that of other sub-models attached to the first bone is in a visible state, and the other sub-models are in an invisible state.
[0120] The above method pre-generates animation rendering data corresponding to each animation frame based on Spine animation, so that the CPU does not need to calculate the animation rendering data in real time, the computing pressure of the CPU is reduced, the limitation on the number of vertices and the number of bones is removed, the rendering effect is improved, and various rendering requirements of users are met.
[0121] Optionally, the above-mentioned rendering order information is determined in the following manner: determining the vertices of the multiple sub-models constituting the target model; the first bone corresponding to the target model is attached with multiple first sub-models; for each animation frame, based on the animation stage corresponding to the animation frame, determining the order parameters of the multiple first sub-models in the animation frame; based on the order parameters of the multiple first sub-models, determining the rendering order information of the vertices of the multiple sub-models in the animation frame.
[0122] Optionally, the above-mentioned step of determining, for each animation frame, the sequence parameters of multiple first sub-models in the animation frame based on the animation stage corresponding to the animation frame, includes: for the first animation frame, determining the sequence parameters of multiple first sub-models in the first animation frame based on the first animation stage corresponding to the first animation frame; for the second animation frame corresponding to the first animation stage, determining the sequence parameters of the multiple first sub-models in the first animation frame as the sequence parameters corresponding to the second animation frame; for the third animation frame, determining the sequence parameters of the multiple first sub-models in the first animation frame based on the second animation stage corresponding to the third animation frame; the second animation stage is different from the first animation stage.
[0123] Optionally, the above-mentioned step of determining the order parameters of multiple first sub-models in the animation frame based on the animation stage corresponding to the animation frame includes: determining the first sub-model that is visible in the animation stage corresponding to the animation frame as the sub-model to be displayed; determining the first order parameter of the sub-model to be displayed and the second order parameter of other first sub-models except the sub-model to be displayed based on the number of models of the first sub-model attached to the first bone; the first order parameter is greater than or equal to the number of models; and the second order parameter is less than the first order parameter.
[0124] Optionally, the vertices of each of the above sub-models have a preset relative rendering order; the relative rendering order is used to indicate: the rendering order of the primitives that constitute the sub-model; the primitives are connected by multiple vertices; based on the order parameters of the first sub-model, the step of determining the rendering order information of the vertices of multiple sub-models in the animation frame includes: determining the rendering order of the multiple sub-models based on the order parameters of the first sub-model; determining the rendering order information of the vertices of the multiple sub-models in the animation frame based on the rendering order of the multiple sub-models and the relative rendering order of the vertices of the sub-models.
[0125] Optionally, the position information of the above-mentioned multiple sub-models is saved through a first image: the above-mentioned method includes: creating a first image based on the number of animation frames and the number of vertices of the multiple sub-models; determining a first arrangement order of the vertices of the multiple sub-models; and saving the position information of the vertices in each animation frame through pixels of the first image based on the first arrangement order and the number of animation frames.
[0126] Optionally, the color information is determined by: determining, for each animation frame, transparency parameters of the plurality of first sub-models in the animation frame based on an animation stage corresponding to the animation frame; and determining color information of vertices of the plurality of sub-models in the animation frame based on the transparency parameters of the vertices and a preset color texture map.
[0127] Optionally, the step of determining, based on the animation stage corresponding to the animation frame, the transparency parameters of the plurality of first sub-models in the animation frame comprises: determining a first sub-model in a visible state in the animation stage corresponding to the animation frame as a to-be-displayed sub-model; determining a transparency parameter of the to-be-displayed sub-model as a first transparency parameter, so that the to-be-displayed sub-model is in the visible state; and determining a transparency parameter of each of the other first sub-models as the first transparency parameter, so that the to-be-displayed sub-model is in an invisible state.
[0128] Optionally, the position information is determined by: determining, based on an attachment relationship between a skeleton corresponding to the target model and the sub-models and a self-offset parameter of the vertex, the position information of the vertices of the plurality of sub-models in the animation frame; and the self-offset parameter is used to indicate a relative position offset of the vertex and the sub-model in which the vertex is located.
[0129] Optionally, the rendering order information comprises an arrangement order of the vertices of the plurality of sub-models in each animation stage; and the step of rendering the target model based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame comprises: determining, based on the animation stage corresponding to the animation frame, the arrangement order of the vertices of the plurality of sub-models corresponding to the animation frame; determining a to-be-rendered vertex based on the arrangement order of the vertices of the plurality of sub-models; determining, from the position information of the plurality of sub-models, position information of the to-be-rendered vertex; determining, from the color information of the plurality of sub-models, color information of the to-be-rendered vertex; and rendering the to-be-rendered vertex based on the position information and the color information of the to-be-rendered vertex, and continuing to determine the to-be-rendered vertex based on the arrangement order of the vertices of the plurality of sub-models until the to-be-rendered vertex is the last vertex in the arrangement order.
[0130] Optionally, the step of obtaining the animation rendering data of the target model comprises: obtaining initial animation rendering data of the target model; the initial animation rendering data comprises position information, color information and rendering order information of a plurality of sub-models corresponding to a plurality of key frames; determining, for each animation frame, a target key frame corresponding to the animation frame and a weight of the target key frame based on a playing time of the animation frame; and determining, based on the weight of the target key frame, the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the target key frame, the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame.
[0131] Referring to Figure 6As shown, the electronic device includes a processor 100 and a memory 101 storing machine executable instructions executable by the processor 100 to implement the animation generation method described above.
[0132] Further, Figure 6 As shown, the electronic device further includes a bus 102 and a communication interface 103, and the processor 100, the communication interface 103 and the memory 101 are connected through the bus 102.
[0133] The memory 101 can include a high-speed random access memory (RAM), and can also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which can be wired or wireless), and the Internet, a wide area network, a local area network, a metropolitan area network, etc. can be used. The bus 102 can be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one bidirectional arrow is used in the figure, but it does not mean that there is only one bus or only one type of bus.
[0134] The processor 100 can be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above method can be completed by the integrated logic circuit of hardware in the processor 100 or the instruction in the form of software. The processor 100 described above can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. Each method, step and logic block diagram of the application in the embodiment of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The method invented in combination with the embodiment of the present application can be directly embodied as hardware decoding processor for execution, or executed by hardware and software module combination in the decoding processor. The software module can be located in the random access memory, the flash memory, the read only memory, the programmable read only memory or the electrically erasable programmable memory, the register, etc. The storage medium in the art. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101, and combines the hardware to complete the method of the above embodiment.
[0135] The embodiment also provides a machine readable storage medium, the machine readable storage medium stores machine executable instructions, when the machine executable instructions are called and executed by the processor, the machine executable instructions cause the processor to realize the above animation generation method.
[0136] The animation generation method, device and electronic equipment provided by the embodiment of the present application include a computer readable storage medium storing program codes, the instructions included in the program codes can be used to execute the method described in the above method embodiment, for example:
[0137] Obtaining animation rendering data of a target model; the target model is composed of a plurality of sub-models; the sub-models are attached to bones corresponding to the target model; the animation rendering data comprises position information, color information and rendering order information of the plurality of sub-models corresponding to a plurality of animation frames; in the process of rendering each animation frame, the target model is rendered based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame, to generate an animation corresponding to the target model; wherein, a sub-model attached to a first bone corresponding to the target model and having a rendering order greater than that of other sub-models attached to the first bone is in a visible state, and the other sub-models are in an invisible state.
[0138] The above manner pre-generates animation rendering data corresponding to each animation frame based on Spine animation, so that the CPU does not need to calculate the animation rendering data in real time, reduces the computing pressure of the CPU, removes the limitation on the number of vertices and the number of bones, thereby improving the rendering effect and meeting various rendering requirements of users.
[0139] Optionally, the rendering order information is determined by the following manner: determining vertices of the plurality of sub-models composing the target model; the first bone corresponding to the target model is attached to a plurality of first sub-models; for each animation frame, determining order parameters of the plurality of first sub-models in the animation frame based on an animation stage corresponding to the animation frame; and determining the rendering order information of the vertices of the plurality of sub-models in the animation frame based on the order parameters of the plurality of first sub-models.
[0140] Optionally, the step of determining, for each animation frame, the order parameters of the plurality of first sub-models in the animation frame based on an animation stage corresponding to the animation frame comprises: determining, for a first animation frame, the order parameters of the plurality of first sub-models in the first animation frame based on a first animation stage corresponding to the first animation frame; determining, for a second animation frame corresponding to the first animation stage, the order parameters of the plurality of first sub-models in the first animation frame as order parameters corresponding to the second animation frame; determining, for a third animation frame, the order parameters of the plurality of first sub-models in the first animation frame based on a second animation stage corresponding to the third animation frame; and the second animation stage is different from the first animation stage.
[0141] Optionally, the step of determining, for each animation frame, the order parameters of the plurality of first sub-models in the animation frame based on an animation stage corresponding to the animation frame comprises: determining a first sub-model in a visible state in the animation stage corresponding to the animation frame as a to-be-displayed sub-model; determining a first order parameter of the to-be-displayed sub-model and a second order parameter of other first sub-models except the to-be-displayed sub-model based on a model number of the first sub-models attached to the first bone; the first order parameter is greater than or equal to the model number; the second order parameter is less than the first order parameter; and the order parameters of different first sub-models are different.
[0142] Optionally, each of the sub-models has preset relative rendering orders of vertices; the relative rendering orders are used to indicate rendering orders of primitives constituting the sub-models; the primitives are connected by the vertices; the step of determining the rendering order information of the vertices of the sub-models in the animation frames based on the order parameters of the first sub-models comprises: determining rendering orders of the sub-models based on the order parameters of the first sub-models; and determining the rendering order information of the vertices of the sub-models in the animation frames based on the rendering orders of the sub-models and the relative rendering orders of the vertices of the sub-models.
[0143] Optionally, the position information of the sub-models is saved in the first image; the method comprises: creating the first image based on the frame number of the animation frames and the vertex number of the vertices of the sub-models; determining a first arrangement order of the vertices of the sub-models; and saving the position information of the vertices in the animation frames in the pixels of the first image based on the first arrangement order and the frame number of the animation frames.
[0144] Optionally, the color information is determined in the following manner: for each animation frame, determining transparency parameters of the first sub-models in the animation frame based on an animation stage corresponding to the animation frame; and determining the color information of the vertices of the sub-models in the animation frame based on the transparency parameters of the vertices of the first sub-models and a preset color texture map.
[0145] Optionally, the step of determining the transparency parameters of the first sub-models in the animation frame based on the animation stage corresponding to the animation frame comprises: determining a first sub-model in a visible state in the animation stage corresponding to the animation frame as a to-be-displayed sub-model; determining a first transparency parameter as the transparency parameter of the to-be-displayed sub-model so that the to-be-displayed sub-model is in the visible state; and determining the transparency parameters of the other first sub-models except the to-be-displayed sub-model as the first transparency parameter so that the to-be-displayed sub-model is in an invisible state.
[0146] Optionally, the position information of the vertices of the sub-models in the animation frames is determined in the following manner: based on an attachment relationship between the target model corresponding bones and the sub-models and a self-offset parameter of the vertices, the position information of the vertices of the sub-models in the animation frames is determined; the self-offset parameter is used to indicate a relative position offset of the vertices and the sub-models where the vertices are located.
[0147] Optionally, the rendering order information comprises an arrangement order of vertices of the plurality of sub-models in each animation stage; and the step of rendering the target model based on the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the animation frame comprises: determining the arrangement order of the vertices of the plurality of sub-models corresponding to the animation frame based on the animation stage corresponding to the animation frame; determining a vertex to be rendered based on the arrangement order of the vertices of the plurality of sub-models; determining position information of the vertex to be rendered from the position information of the plurality of sub-models; determining color information of the vertex to be rendered from the color information of the plurality of sub-models; and rendering the vertex to be rendered based on the position information and the color information of the vertex to be rendered, and continuing to determine the vertex to be rendered based on the arrangement order of the vertices of the plurality of sub-models until the vertex to be rendered is the last vertex in the arrangement order.
[0148] Optionally, the step of obtaining the animation rendering data of the target model comprises: obtaining initial animation rendering data of the target model; the initial animation rendering data comprises position information, color information and rendering order information of a plurality of sub-models corresponding to a plurality of key frames; for each animation frame, determining a target key frame corresponding to the animation frame and a weight of the target key frame based on a playing time of the animation frame; and determining position information, color information and rendering order information of a plurality of sub-models corresponding to the animation frame based on the weight of the target key frame, the position information, the color information and the rendering order information of the plurality of sub-models corresponding to the target key frame.
[0149] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and the device described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here.
[0150] In addition, in the description of the embodiments of the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connecting" should be understood in a broad sense, for example, can be fixedly connected, can be detachably connected, or integrally connected; can be mechanically connected, can be electrically connected; can be directly connected, can be indirectly connected through an intermediate medium, and can be internal communication of two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0151] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of software products, which are stored in a storage medium, including a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0152] In the description of the present application, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application. In addition, the terms "first", "second", "third" are only for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0153] Finally, it should be noted that: the above embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, and are not limited thereto, the protection scope of the present application is not limited thereto, although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art within the technical scope disclosed by the present application can still modify or easily think of changes to the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to part of the technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. An animation generation method, characterized in that: include: Get the animation rendering data of the target model; The target model is composed of multiple sub-models; the sub-models are attached to the bones corresponding to the target model; The animation rendering data includes position information, color information and rendering order information of the multiple sub-models corresponding to the multiple animation frames; During the process of rendering each animation frame, the target model is rendered based on the position information, color information, and rendering order information of the multiple sub-models corresponding to the animation frame to generate an animation corresponding to the target model; Among the multiple sub-models attached to the first skeleton corresponding to the target model, the sub-model whose rendering order is greater than that of other sub-models attached to the first skeleton is in a visible state, and the other sub-models are in an invisible state.
2. The method according to claim 1, characterized in that The rendering order information is determined by: Determining vertices of a plurality of sub-models constituting the target model; a first skeleton corresponding to the target model is attached with a plurality of first sub-models; For each animation frame, determining, based on the animation stage corresponding to the animation frame, sequence parameters of the plurality of first sub-models in the animation frame; Based on the order parameters of the plurality of first sub-models, rendering order information of the vertices of the plurality of sub-models in the animation frame is determined.
3. The method according to claim 2, characterized in that The step of determining, for each animation frame, the sequence parameters of the plurality of first sub-models in the animation frame based on the animation stage corresponding to the animation frame comprises: For a first animation frame, determining sequence parameters of the plurality of first sub-models in the first animation frame based on a first animation stage corresponding to the first animation frame; For a second animation frame corresponding to the first animation stage, determining the sequence parameters of the plurality of first sub-models in the first animation frame as the sequence parameters corresponding to the second animation frame; For a third animation frame, the sequence parameters of the plurality of first sub-models in the first animation frame are determined based on a second animation stage corresponding to the third animation frame; the second animation stage is different from the first animation stage.
4. The method according to claim 2, characterized in that The step of determining the sequence parameters of the plurality of first sub-models in the animation frame based on the animation stage corresponding to the animation frame includes: Determine the first sub-model that is in a visible state in the animation stage corresponding to the animation frame as the sub-model to be displayed; Based on the number of models of the first sub-model attached to the first bone, determine the first order parameter of the sub-model to be displayed and the second order parameters of other first sub-models except the sub-model to be displayed; the first order parameter is greater than or equal to the number of models; the second order parameter is less than the first order parameter; different first sub-models have different order parameters.
5. The method according to claim 2, characterized in that The vertices of each sub-model have a preset relative rendering order; the relative rendering order is used to indicate: the rendering order of the primitives constituting the sub-model; the primitives are formed by connecting multiple vertices; The step of determining the rendering order information of the vertices of the plurality of sub-models in the animation frame based on the order parameter of the first sub-model includes: determining a rendering order of the plurality of sub-models based on an order parameter of the first sub-model; Based on the rendering order of the multiple sub-models and the relative rendering order of the vertices of the sub-models, rendering order information of the vertices of the multiple sub-models in the animation frame is determined.
6. The method according to claim 2, characterized in that The position information of the multiple sub-models is saved via the first image: The method comprises: creating a first image based on the frame number of the animation frame and the number of vertices of the plurality of sub-models; determining a first arrangement order of the vertices of the plurality of sub-models; Based on the first arrangement order and the number of the animation frames, the position information of the vertex in each animation frame is saved through the pixels of the first image.
7. The method according to claim 2, characterized in that The color information is determined by: For each animation frame, determining transparency parameters of the plurality of first sub-models in the animation frame based on the animation stage corresponding to the animation frame; Based on the transparency parameters of the vertices of the first sub-model and a preset color texture map, color information of the vertices of the multiple sub-models in the animation frame is determined.
8. The method according to claim 7, characterized in that The step of determining transparency parameters of the plurality of first sub-models in the animation frame based on the animation stage corresponding to the animation frame includes: Determine the first sub-model that is in a visible state in the animation stage corresponding to the animation frame as the sub-model to be displayed; Determining the transparency parameter of the sub-model to be displayed as a first transparency parameter, so that the sub-model to be displayed is in a visible state; The transparency parameters of the other first sub-models except the sub-model to be displayed are determined as first transparency parameters, so that the sub-model to be displayed is in an invisible state.
9. The method according to claim 2, characterized in that The location information is determined by: Determining position information of vertices of the plurality of sub-models in the animation frame based on an attachment relationship between a skeleton corresponding to the target model and the sub-model and a self-offset parameter of the vertex; The self-offset parameter is used to indicate the relative position offset between the vertex and the sub-model in which it is located.
10. The method according to claim 1, characterized in that The rendering order information includes an arrangement order of vertices of the plurality of sub-models in each animation stage; The step of rendering the target model based on the position information, color information, and rendering order information of the multiple sub-models corresponding to the animation frame includes: determining, based on the animation stage corresponding to the animation frame, an arrangement order of the vertices of the plurality of sub-models corresponding to the animation frame; Determining vertices to be rendered based on an arrangement order of vertices of the multiple sub-models; Determining position information of the to-be-rendered vertices from position information of the plurality of sub-models; Determining color information of the vertex to be rendered from color information of the multiple sub-models; Rendering the vertex to be rendered based on the position information and color information of the vertex to be rendered, and continuing to perform the step of determining the vertex to be rendered based on the arrangement order of the vertices of the multiple sub-models until the vertex to be rendered is the last vertex in the arrangement order.
11. The method according to claim 1, wherein The step of obtaining animation rendering data of the target model includes: Acquire initial animation rendering data of the target model; the initial animation rendering data includes position information, color information, and rendering order information of the multiple sub-models corresponding to the multiple key frames; For each animation frame, based on the playback time of the animation frame, determining a target key frame corresponding to the animation frame and a weight of the target key frame; Based on the weight of the target key frame, the position information, color information and rendering order information of the multiple sub-models corresponding to the target key frame, the position information, color information and rendering order information of the multiple sub-models corresponding to the animation frame are determined.
12. An animation generating device, characterized in that: include: Rendering data acquisition module, used to obtain animation rendering data of the target model; The target model is composed of multiple sub-models; the sub-models are attached to the bones corresponding to the target model; The animation rendering data includes position information, color information and rendering order information of the multiple sub-models corresponding to the multiple animation frames; An animation generation module is used to render the target model based on the position information, color information and rendering order information of the multiple sub-models corresponding to the animation frame during the rendering of each animation frame, so as to generate an animation corresponding to the target model; Among the multiple sub-models attached to the first skeleton corresponding to the target model, the sub-model whose rendering order is greater than that of other sub-models attached to the first skeleton is in a visible state, and the other sub-models are in an invisible state.
13. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the animation generation method according to any one of claims 1 to 11.
14. A machine-readable storage medium, characterized in that The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the animation generation method according to any one of claims 1 to 11.