Method and device for generating 3D characters

文档序号:9431 发布日期:2021-09-17 浏览:107次 中文

1. A method of generating 3D text, comprising the steps of:

acquiring outline information of the 2D characters, wherein the outline information comprises an outline point coordinate set and an outline index list;

performing triangulation according to the contour information to obtain 2D vertex data;

obtaining 3D vertex data according to the preset text thickness and the 2D vertex data;

and generating 3D characters according to the 3D vertex data.

2. The method of claim 1, wherein: the acquiring contour information of the 2D text comprises:

receiving 2D content input by a user, wherein the 2D content is used for being added into a video and comprises at least one 2D character;

and identifying the outline of each 2D character to obtain an outline point coordinate set and an outline index list of each 2D character under the corresponding font.

3. The method of claim 2, wherein: the identifying the outline of each 2D word includes: the contour of each 2D word is identified using the Freetype2 library.

4. The method of claim 1, wherein: the triangulating the contour information to obtain 2D vertex data comprises:

and performing triangulation on the contour information by adopting an OpenGL open source GLU library.

5. The method of claim 1, wherein: the triangulating the contour information to obtain 2D vertex data comprises:

sending the contour point coordinate set and a contour index list to a tesselator for division, wherein basic elements in the tesselator are set to be triangles;

obtaining newly-added vertex data after the division from the success callback of the tesselator;

and adding the vertex data to the contour point coordinate set to obtain 2D vertex data.

6. The method of claim 1, wherein: the obtaining of the 3D vertex data according to the preset text thickness and the 2D vertex data comprises:

taking the 2D vertex data as the coordinates and index data in front of the 3D characters;

obtaining subsequent coordinates and index data according to the preset thickness;

constructing coordinates and index data required by each side of the 3D characters according to the coordinates and the index data of the front and the back; the coordinates and index data of the front and back faces and the respective side faces are 3D vertex data.

7. The method of claim 1, wherein: the generating of the 3D text according to the 3D vertex data comprises:

and generating the 3D vertex data into 3D texts by using OpenGL.

8. The method of claim 7, wherein: the generating 3D text from the 3D vertex data using OpenGL comprises:

inputting the 3D vertex data into a coordinate system, and using OpenGL to render to obtain a 3D outline;

receiving rendering setting input by a user, and rendering the 3D outline to generate 3D characters, wherein the rendering setting comprises illumination, material, character color, diffuse reflection and refraction attribute setting.

9. The method of claim 2, further comprising:

acquiring an input sequence of each 2D character;

and after the 3D characters are generated, sequencing the generated 3D characters according to the input sequence.

10. An apparatus for generating 3D text, comprising:

the 2D contour information acquisition module is used for acquiring contour information of the 2D characters, and the contour information comprises a contour point coordinate set and a contour index list;

the 2D vertex data acquisition module is used for carrying out triangulation according to the outline information to obtain 2D vertex data;

the 3D vertex data acquisition module is used for obtaining 3D vertex data according to the preset text thickness and the 2D vertex data;

and the 3D character generation module is used for generating 3D characters according to the 3D vertex data.

Background

When special effect video editing is carried out, characters are subjected to 3D conversion, animation special effects are superposed, and the common high-grade video special effect is achieved. In the existing mobile terminal APP, there is little effect of converting the user input text into 3D text.

A small number of APPs that can achieve a text 3D effect all have various problems. The first is simply to superimpose a surface on the basis of the 2D text, which is relatively rough in realization effect. The second method is to export a 3D character model by computer software such as AE and then load the 3D character model by OpenGL, and the 3D character with this structure has a perfect 3D effect, but because of the export model, the character content is fixed and cannot be changed by the user.

Disclosure of Invention

In order to overcome the defects of the prior art, the invention provides a method and a device for generating 3D characters, which are used for solving the problems that 3D characters cannot be generated in the conventional mobile terminal APP, the generated 3D characters are rough in effect, or a user with fixed character content cannot change the character content autonomously.

The technical scheme adopted by the invention for solving the technical problems is as follows:

on the one hand, the method comprises the following steps of,

a method of generating 3D text comprising the steps of:

acquiring outline information of the 2D characters, wherein the outline information comprises an outline point coordinate set and an outline index list;

performing triangulation according to the contour information to obtain 2D vertex data;

obtaining 3D vertex data according to the preset text thickness and the 2D vertex data;

and generating 3D characters according to the 3D vertex data.

Further, the acquiring the contour information of the 2D text includes:

receiving 2D content input by a user, wherein the 2D content is used for being added into a video and comprises at least one 2D character;

and identifying the outline of each 2D character to obtain an outline point coordinate set and an outline index list of each 2D character under the corresponding font.

Further, the identifying the outline of each 2D word comprises: the contour of each 2D word is identified using the Freetype2 library.

Further, the triangulating the contour information to obtain 2D vertex data includes:

and performing triangulation on the contour information by adopting an OpenGL open source GLU library.

Further, the triangulating the contour information to obtain 2D vertex data includes:

sending the contour point coordinate set and a contour index list to a tesselator for division, wherein basic elements in the tesselator are set to be triangles;

obtaining newly-added vertex data after the division from the success callback of the tesselator;

and adding the vertex data to the contour point coordinate set to obtain 2D vertex data.

Further, the obtaining of the 3D vertex data according to the preset text thickness and the 2D vertex data includes:

taking the 2D vertex data as the coordinates and index data in front of the 3D characters;

obtaining subsequent coordinates and index data according to the preset thickness;

constructing coordinates and index data required by each side of the 3D characters according to the coordinates and the index data of the front and the back; the coordinates and index data of the front and back faces and the respective side faces are 3D vertex data.

Further, the generating 3D text according to the 3D vertex data includes:

and generating the 3D vertex data into 3D texts by using OpenGL.

Further, the generating 3D text from the 3D vertex data using OpenGL includes:

inputting the 3D vertex data into a coordinate system, and using OpenGL to render to obtain a 3D outline;

receiving rendering setting input by a user, and rendering the 3D outline to generate 3D characters, wherein the rendering setting comprises illumination, material, character color, diffuse reflection and refraction attribute setting.

Further, still include:

acquiring an input sequence of each 2D character;

and after the 3D characters are generated, sequencing the generated 3D characters according to the input sequence.

On the other hand, in the case of a liquid,

an apparatus for generating 3D text, comprising:

the 2D contour information acquisition module is used for acquiring contour information of the 2D characters, and the contour information comprises a contour point coordinate set and a contour index list;

the 2D vertex data acquisition module is used for carrying out triangulation according to the outline information to obtain 2D vertex data;

the 3D vertex data acquisition module is used for obtaining 3D vertex data according to the preset text thickness and the 2D vertex data;

and the 3D character generation module is used for generating 3D characters according to the 3D vertex data.

This application adopts above technical scheme, possesses following beneficial effect at least:

the technical scheme of the application provides a method and a device for generating 3D characters, firstly, contour information of 2D characters is obtained, then, triangulation is carried out according to the contour information to obtain 2D vertex data, and then, the 3D vertex data is obtained according to preset character thickness and the 2D vertex data; and finally, generating 3D characters according to the 3D vertex data. When the scheme of the application generates the 3D characters, the vertex data of the 2D outline is obtained by carrying out triangulation according to the 2D outline information, then the vertex data of the 3D character outline is constructed according to the preset character thickness and the 2D vertex data, the 3D characters are generated according to the 3D vertex data finally, the generated 3D characters are clear, and the effect that the generated 3D characters are changed by changing the preset character thickness by a user is very convenient.

Drawings

In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.

Fig. 1 is a flowchart of a method for generating 3D text according to an embodiment of the present invention;

fig. 2 is a schematic diagram of a 3D text structure according to an embodiment of the present invention;

FIG. 3 is a flowchart of a specific 3D text method according to an embodiment of the present invention;

fig. 4 is a structural diagram of an apparatus for generating 3D text according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention more apparent, the following detailed description of the technical solutions of the present invention is provided with reference to the accompanying drawings and examples. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the examples given herein without making any creative effort, shall fall within the protection scope of the present application.

Referring to fig. 1, an embodiment of the present invention provides a method for generating a 3D text, including the following steps:

acquiring contour information of the 2D characters, wherein the contour information comprises a contour point coordinate set and a contour index list;

performing triangulation according to the contour information to obtain 2D vertex data;

obtaining 3D vertex data according to the preset character thickness and the 2D vertex data;

and generating 3D characters according to the 3D vertex data.

The method for generating the 3D characters comprises the steps of firstly obtaining outline information of the 2D characters, then carrying out triangulation according to the outline information to obtain 2D vertex data, and then obtaining the 3D vertex data according to preset character thickness and the 2D vertex data; and finally, generating 3D characters according to the 3D vertex data. When the scheme of the application generates the 3D characters, the vertex data of the 2D outline is obtained by carrying out triangulation according to the 2D outline information, then the vertex data of the 3D character outline is constructed according to the preset character thickness and the 2D vertex data, the 3D characters are generated according to the 3D vertex data finally, the generated 3D characters are clear, and the effect that the generated 3D characters are changed by changing the preset character thickness by a user is very convenient.

As a supplementary explanation to the above-described embodiment, acquiring the outline information of the 2D text includes: receiving 2D content input by a user, wherein the 2D content is used for being added into a video and comprises at least one 2D character; and identifying the outline of each 2D character to obtain an outline point coordinate set and an outline index list of each 2D character under the corresponding font. Illustratively, the contour of each 2D word is identified using the Freetype2 library. Freetype2 is a software font engine intended to be small, efficient, highly customizable and portable, while producing high quality output (glyph images). It can also be used in graphics libraries, display servers, font conversion tools, text image generation tools, and many other products.

In some embodiments, triangulating the 2D vertex data according to the contour information comprises:

and performing triangulation on the profile information by adopting an OpenGL open source GLU library. OpenGL: (English: Open Graphics Library, translation name: Open Graphics Library or "Open Graphics Library") is a cross-language, cross-platform Application Programming Interface (API) for rendering 2D, 3D vector Graphics. This interface consists of nearly 350 different function calls to draw from simple graphics bits to complex three-dimensional scenes. Glu library: the method is an auxiliary library for mathematical correlation operation in OpenGL.

Further, the step of performing triangulation according to the contour information to obtain 2D vertex data includes:

sending the contour point coordinate set and the contour index list to a tesselator for division, wherein basic elements in the tesselator are set to be triangles; obtaining newly-added vertex data after the division from the success callback of the tesselator; and adding the vertex data to the contour point coordinate set to obtain 2D vertex data.

As an optional implementation manner of the embodiment of the present invention: obtaining 3D vertex data according to the preset text thickness and the 2D vertex data comprises the following steps:

taking the 2D vertex data as the coordinates and index data in front of the 3D characters; obtaining subsequent coordinates and index data according to the preset thickness; constructing coordinates and index data required by each side of the 3D characters according to the coordinates and the index data of the front and the back; the coordinates and index data of the front and back faces and the respective side faces are 3D vertex data. For example, as shown in fig. 2, a1 is a front vertex, a2 is a rear vertex, and a rear coordinate data can be automatically determined according to the preset thickness and the front coordinate data input by the user. Then 4 sides of data are generated from the front and back coordinate data to construct 3D vertex data.

Further, the 3D vertex data is generated into 3D text using OpenGL. Specifically, 3D vertex data is input into a coordinate system, and a 3D contour is obtained by using OpenGL rendering; the obtained 3D outline is as shown in fig. 2, and rendering settings input by a user are received to render the 3D outline to generate 3D characters, wherein the rendering settings include illumination, material, character color, diffuse reflection and refraction attribute settings. By means of OpenGL rendering and other technologies, efficient and stable drawing of the 3D characters is achieved, and a user can make the highly user-defined 3D characters and add animation, special effects, key frames and other additional editing to the 3D characters. In addition, the reality sense of sight of the 3D characters is further optimized by supporting the addition of materials and illumination effects to the 3D characters.

Finally, acquiring the input sequence of each 2D character; and after the 3D characters are generated, sequencing the generated 3D characters according to the input sequence. It can be understood that under normal conditions, the 3D characters generated by the input characters are all placed at the same position, so that the characters can be stacked in an overlapping mode and are not beneficial to display, therefore, the characters are sorted according to the input sequence, and the characters cannot be stacked or displayed. Illustratively, the 3D generation is performed according to the input sequence, and the placing position of the 3D character generated later is separated from the placing position of the 3D character generated earlier by a preset distance, which may be set according to the actual situation, and will not be described in detail herein.

To further explain the solution of the present application, as shown in fig. 3, a specific method for generating 3D text at a mobile terminal is provided, where the mobile terminal includes mobile devices such as a mobile phone and a pad, and the method specifically includes the following steps:

1. contour information of the 2D character is acquired. 2. And carrying out triangulation to obtain a plurality of triangular surfaces. 3. The two-dimensional vertices build a three-dimensional structure 4. the 3D characters are rendered using OpenGL. 5. Generating arbitrary content 3D text using 3D characters

The specific implementation steps are as follows:

(1) obtaining outline information of the 2D text.

The present invention uses the Freetype2 library to identify contours. For each character, the outline point coordinate set and the outline index list of the character under the corresponding font can be directly obtained.

(2) Triangulating to obtain a plurality of triangular faces

And carrying out triangle division on the set of contour points obtained in the first step. The invention adopts an OpenGL open source GLU library to carry out triangulation.

And sending all the contour point sets to the tesselator, sending the obtained contour index list to the tesselator, setting the partition basic elements as triangles, starting the tesselator for partitioning, and obtaining newly-added vertex data after partitioning in the success callback of the tesselator. And finally, adding the newly added vertex data into the font outline point set in sequence to obtain the completely triangulated vertex data.

(3) Two-dimensional vertex construction of three-dimensional structures

When the contour data obtained in the step 2 is used as the front face of the 3D character and the character thickness is set, the vertex coordinates and the index of the back face can be obtained by sequentially changing the z-axis of the coordinates (x-axis coordinates and y-axis coordinates are unchanged, and the character thickness is added to the z-axis coordinates) in order from the vertex coordinates and the index of the front face. And then, according to the coordinates and indexes of the front side and the back side, the vertex coordinates and indexes needed by 4 sides can be constructed, and all vertex data needed by constructing the 3D structure can be obtained.

(4) Rendering 3D text using OpenGL

1. And inputting all the obtained vertex coordinates into a vertex coordinate system, and rendering the 3D characters in an OpenGL environment. The rendered character is only a 3D outline, the effect of the 3D character is rough due to the lack of illumination and material information, and the direct distinguishing degree of the surface is not large.

2. And adding illumination in an OpenGL environment, setting material information including the color, diffuse reflection and refraction attributes of the characters for the character model, and rendering at the moment to obtain the vivid 3D characters.

(5) Generating arbitrary content 3D text using 3D characters

And translating each 3D character to a proper position according to different character arrangement sequences and the width and height (obtained by character vertex coordinates) of a single character to construct the required 3D effect characters of the character content.

The generation method provided by the embodiment of the invention is based on OpenGL, the outline is identified through freetype, triangulation is carried out, 3D characters capable of changing contents at any time are rendered, the outline of a single character is identified, vertex data of the 3D characters are obtained through means of triangulation, two-dimensional graph 3D and the like, and then different characters are rendered through OpenGL to realize the construction of the 3D characters. Compared with other existing technologies, the 3D character effect generated by the method is vivid and clear. And simultaneously, the method also supports the rapid construction of characters with any content.

In an embodiment, the present invention further provides an apparatus for generating 3D text, as shown in fig. 4, including:

a 2D contour information obtaining module 41, configured to obtain contour information of a 2D text, where the contour information includes a contour point coordinate set and a contour index list; specifically, 2D content input by a user is received, wherein the 2D content is used for being added into a video and comprises at least one 2D character; and identifying the outline of each 2D character by adopting a Freetype2 library to obtain an outline point coordinate set and an outline index list of each 2D character under the corresponding font.

The 2D vertex data obtaining module 42 is configured to perform triangulation according to the contour information to obtain 2D vertex data; specifically, the contour information is triangulated by adopting an OpenGL open source GLU library. Further, the step of performing triangulation according to the contour information to obtain 2D vertex data includes: sending the contour point coordinate set and the contour index list to a tesselator for division, wherein basic elements in the tesselator are set to be triangles; obtaining newly-added vertex data after the division from the success callback of the tesselator; and adding the vertex data to the contour point coordinate set to obtain 2D vertex data.

A 3D vertex data obtaining module 43, configured to obtain 3D vertex data according to a preset text thickness and 2D vertex data; specifically, 2D vertex data is taken as the coordinates and index data in front of the 3D text; obtaining subsequent coordinates and index data according to the preset thickness; constructing coordinates and index data required by each side of the 3D characters according to the coordinates and the index data of the front and the back; the coordinates and index data of the front and back faces and the respective side faces are 3D vertex data.

And a 3D text generating module 44, configured to generate 3D text according to the 3D vertex data. Specifically, 3D vertex data is generated into 3D text using OpenGL. Further, comprising: inputting 3D vertex data into a coordinate system, and using OpenGL to render to obtain a 3D outline; and receiving rendering setting input by a user to render the 3D outline to generate 3D characters, wherein the rendering setting comprises illumination, material, character color, diffuse reflection and refraction attribute setting.

A 3D text ordering module 45, configured to obtain an input order of each 2D text; and after the 3D characters are generated, sequencing the generated 3D characters according to the input sequence.

According to the device for generating the 3D characters, provided by the embodiment of the invention, firstly, the contour information of the 2D characters is acquired through a 2D contour information acquisition module; then, the 2D vertex data acquisition module performs triangulation according to the contour information to obtain 2D vertex data; then, a 3D vertex data acquisition module obtains 3D vertex data according to the preset text thickness and the 2D vertex data; and then the 3D character generation module generates 3D characters according to the 3D vertex data. And finally, after the 3D characters are generated, the 3D character sorting module sorts the generated 3D characters according to the input sequence. The method comprises the steps of obtaining vertex data of 3D characters by identifying the outline of a single character, performing triangulation, performing two-dimensional graph 3D and the like, rendering different characters through OpenGL to realize construction of 3D characters, and finally sequencing according to an input sequence. Compared with other existing technologies, the 3D character effect generated by the device is vivid and clear. And simultaneously, the method also supports the rapid construction of characters with any content.

It is understood that the same or similar parts in the above embodiments may be mutually referred to, and the same or similar parts in other embodiments may be referred to for the content which is not described in detail in some embodiments.

It should be noted that, in the description of the present application, the terms "first", "second", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Further, in the description of the present application, the meaning of "a plurality" means at least two unless otherwise specified.

Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and the scope of the preferred embodiments of the present application includes other implementations in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present application.

It should be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.

It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware associated with program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

In addition, functional units in the embodiments of the present application may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.

The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc.

In the description herein, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.

Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:可驱动三维人物生成方法、装置、电子设备及存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!