Disclosure of Invention
The invention mainly aims to provide a method for rendering a large number of three-dimensional models, and aims to solve the technical problem that a large amount of time and system resources are consumed for rendering the large number of three-dimensional models in the prior art.
In order to achieve the above object, the present invention provides a model rendering method, including:
receiving an artificial marking operation, and determining a model to be detected from models included in a virtual reality scene based on the artificial marking operation;
and determining a model to be rendered from the model to be detected through light detection, and rendering the model to be rendered.
Optionally, the determining, through light detection, a model to be rendered from the model to be detected includes:
and controlling the camera to emit a light ray to each pixel point on the screen where the virtual reality scene is located, and taking the model to be detected, which is irradiated by the light ray, as the model to be rendered.
Optionally, the using, as the model to be rendered, the model to be irradiated by the light in the model to be detected includes:
detecting whether each model in the models to be detected has an intersection point with at least one ray;
and taking the model with the intersection point with at least one light ray in the model to be detected as the model to be rendered.
Optionally, the detecting whether each model in the model to be detected has an intersection point with at least one ray includes:
detecting whether each surface of each model in the model to be detected has an intersection point with at least one ray;
and taking the model with the intersection point of the at least one surface and the at least one ray as the model with the intersection point of the at least one ray.
Optionally, the detecting whether each surface of each model in the model to be detected has an intersection point with at least one ray includes:
and (3) simultaneously establishing a parameter equation of any light and a parameter equation of any surface, wherein the parameter equation of any light is as follows: p ═ P
0+ ut, with the parameter equation for either side being n (a-P) ═ 0, resulting in
When t is greater than or equal to zero, the surface and the light ray have an intersection point; wherein, P
0The initial coordinate of the light ray, u is the direction vector of the light ray, different points of the light ray can be taken according to different values of t, n is the normal vector of the surface, P is the coordinate of the normal vector and the focus of the surface, and a is the coordinate of another point in the surface.
In addition, to achieve the above object, the present invention also provides a model rendering apparatus, including:
the marking module is used for receiving manual marking operation and determining a model to be detected from models included in the virtual reality scene based on the manual marking operation;
and the rendering module is used for determining a model to be rendered from the models to be rendered through light detection and rendering the model to be rendered.
Optionally, the rendering module is configured to:
and controlling the camera to emit a light ray to each pixel point on the screen where the virtual reality scene is located, and taking the model to be detected, which is irradiated by the light ray, as the model to be rendered.
Optionally, the rendering module is configured to:
detecting whether each model in the models to be detected has an intersection point with at least one ray;
and taking the model with the intersection point with at least one light ray in the model to be detected as the model to be rendered.
Optionally, the rendering module is configured to:
detecting whether each surface of each model in the model to be detected has an intersection point with at least one ray;
and taking the model with the intersection point of the at least one surface and the at least one ray as the model with the intersection point of the at least one ray.
Optionally, the rendering module is configured to:
and (3) simultaneously establishing a parameter equation of any light and a parameter equation of any surface, wherein the parameter equation of any light is as follows: p ═ P
0+ ut, with the parameter equation for either side being n (a-P) ═ 0, resulting in
When t is greater than or equal to zero, the surface and the light ray have an intersection point; wherein, P
0The initial coordinate of the light ray, u is the direction vector of the light ray, different points of the light ray can be taken according to different values of t, n is the normal vector of the surface, P is the coordinate of the normal vector and the focus of the surface, and a is the coordinate of another point in the surface.
Receiving an artificial marking operation, and determining a model to be detected from models included in a virtual reality scene based on the artificial marking operation; and determining a model to be rendered from the model to be detected through light detection, and rendering the model to be rendered. By the method and the device, unnecessary rendering is reduced, the display effect is not influenced, the rendering efficiency is improved, and system resources are saved.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a model rendering method according to an embodiment of the present invention. In one embodiment, a model rendering method includes:
step S10, receiving manual marking operation, and determining a model to be detected from models included in a virtual reality scene based on the manual marking operation;
in this embodiment, a virtual reality scene generally includes a plurality of three-dimensional models, some of which are larger and are not occluded by other objects, so that by default, this type of three-dimensional model needs to be rendered. However, since the size of other three-dimensional models is relatively small, the three-dimensional models may be hidden by other objects, and in this case, even if the hidden three-dimensional models are rendered, the three-dimensional models cannot be seen by human eyes, and therefore, rendering the hidden three-dimensional models is not necessary. Therefore, it is necessary to mark a three-dimensional model that is not a mask by a manual marking method to make a further determination. Namely, the three-dimensional model which is not the shielding object is marked through manual marking operation, and the marked three-dimensional model is used as the model to be detected.
And step S20, determining a model to be rendered from the models to be rendered through light detection, and rendering the model to be rendered.
In this embodiment, whether each model included in the model to be detected is a visible model or not is detected through light detection, and if one or more models are visible models, the one or more models are used as models to be rendered and the models to be rendered are rendered. Of course, the large three-dimensional model that is not marked in step S10 and is not occluded by other objects needs to be rendered, and such a large model that is not marked is rendered by default.
Further, in one embodiment, step S20 includes:
and controlling the camera to emit a light ray to each pixel point on the screen where the virtual reality scene is located, and taking the model to be detected, which is irradiated by the light ray, as the model to be rendered.
In this embodiment, the virtual reality scene is displayed on the screen, and if there are M pixel points on the screen, the camera is controlled to emit one light to each pixel point, that is, M light is emitted in total. Assuming that the model to be detected comprises 15 three-dimensional models, if it is detected that 10 of the three-dimensional models are all irradiated by at least one light ray, taking the 10 three-dimensional models as the model to be rendered.
Further, in an embodiment, taking the model to be detected, which is irradiated by the light, as the model to be rendered includes:
detecting whether each model in the models to be detected has an intersection point with at least one ray; and taking the model with the intersection point with at least one light ray in the model to be detected as the model to be rendered.
In this embodiment, whether each model is irradiated by at least one ray is determined by detecting whether each model has an intersection with at least one ray. And if the model and the at least one ray have intersection points, determining that the model is irradiated by the at least one ray, and considering the model as the model to be rendered.
Further, in an embodiment, the detecting whether each model of the models to be detected has an intersection with at least one ray includes:
detecting whether each surface of each model in the model to be detected has an intersection point with at least one ray; and taking the model with the intersection point of the at least one surface and the at least one ray as the model with the intersection point of the at least one ray.
In this embodiment, since each model is a three-dimensional model, each model has multiple faces, it is necessary to detect whether each face of the model has an intersection with at least one ray for one model, and if at least one face of the faces included in the model has an intersection with at least one ray, it is determined that the model has an intersection with at least one ray. For example, the model to be detected includes 15 three-dimensional models, which are respectively three-dimensional models 1 to 15, where the three-dimensional model 1 includes 5 faces, which are respectively faces 1 to 5, and then it is detected whether the face 1 has an intersection with at least one ray, whether the face 2 has an intersection with at least one ray, whether the face 3 has an intersection with at least one ray, whether the face 4 has an intersection with at least one ray, and whether the face 5 has an intersection with at least one ray. If at least one of the surfaces 1 to 5 has an intersection point with at least one light ray, the three-dimensional model 1 is considered to have an intersection point with at least one light ray, that is, the three-dimensional model 1 is considered to be irradiated by at least one light ray, that is, the three-dimensional model 1 is considered to be a model to be rendered. If the three-dimensional model 2 comprises 6 surfaces, namely, the surface 1 to the surface 6, and the detection shows that the intersection points of the surfaces 1 to the surface 6 and the light rays do not exist, the three-dimensional model 2 is considered not to be irradiated by the light rays, the three-dimensional model is considered to be an invisible model, and the three-dimensional model 2 does not need to be determined as a model to be rendered. By analogy, whether each model included in the model to be detected is the model to be rendered can be determined.
Further, in an embodiment, detecting whether each surface of each model in the model to be detected has an intersection with at least one ray includes:
and (3) simultaneously establishing a parameter equation of any light and a parameter equation of any surface, wherein the parameter equation of any light is as follows: p ═ P
0+ ut, with the parameter equation for either side being n (a-P) ═ 0, resulting in
When t is greater than or equal to zero, the surface and the light ray have an intersection point; wherein, P
0The method is that the initial coordinate of the ray, u is the direction vector of the ray, the different values of t can be taken to obtain different points of the ray, and n is the surfaceThe vector, P, is the normal vector and the coordinates of the focal point of the surface, and a is the coordinates of another point in the surface.
In this embodiment, a three-dimensional model of the models to be detected is taken as an example, and if the three-dimensional model is a 6-face body, the three-dimensional model includes 6 faces, which are denoted as faces 1 to 6. If the screen has M pixel points, M light rays are counted. Taking the example of detecting whether the plane 1 intersects with at least one ray, assuming that the plane 1 intersects with any ray, the parameter equation of any ray is P ═ P
0+ ut, the parametric equation for plane 1 is n · (a-P) ═ 0, where P is
0The starting coordinates of the light rays are u, the direction vector of the light rays are u, different points of the light rays can be taken according to different values of t, n is a normal vector of the surface 1, P is the coordinates of the normal vector and the focus of the surface 1, namely P is the coordinates of the intersection point of the surface 1 and any light ray, and a is the coordinates of another point in the surface 1. The parameter equation of any light ray and the parameter equation of the surface 1 are combined to obtain
By mixing n, a and P
0And the specific finger of u is substituted to obtain the value of t. Wherein each ray has a corresponding P
0U, then the light 1 to P of the light M respectively
0And u is substituted. When substituted P
0U is P corresponding to the ray x
0And u, if t is larger than or equal to zero, indicating that the intersection point exists between the surface 1 and the ray x, namely the intersection point exists between at least one surface of the three-dimensional model and at least one ray, determining that the three-dimensional model is irradiated by at least one ray, and considering the three-dimensional model as a model to be rendered. If the light 1 to P of the light M are respectively transmitted
0And after u is substituted, calculating that the obtained M t values are all smaller than zero, indicating that the surface 1 and the M rays do not have intersection points, and continuously monitoring whether the surface 2 and at least one ray have intersection points according to the mode. If it is detected that the intersection points of the surface 1 and the surface 6 and the M light rays do not exist, the three-dimensional model is not irradiated by the light rays, and the three-dimensional model is considered to be a model which does not need to be rendered.
Referring to fig. 2, fig. 2 is a schematic diagram illustrating an effect of rendering a virtual reality scene based on the prior art. Referring to fig. 3, fig. 3 is a schematic diagram illustrating the effect of rendering a virtual reality scene based on the model rendering method of the present invention. It can be seen from comparison between fig. 2 and fig. 3 that the number of the three-dimensional models rendered in fig. 2 is much larger than that of the three-dimensional models rendered in fig. 3, and in fig. 3, some invisible models are selectively not rendered, so that unnecessary rendering is reduced, the display effect is not affected, the rendering efficiency is improved, and the system resources are saved.
Referring to fig. 4, fig. 4 is a scene diagram illustrating a virtual reality scene rendered according to the prior art. As shown in fig. 4, in the overlap draw mode, when the occlusion condition of an object in a scene is checked, the brightness of the area marked by the rectangular frame is very high, which indicates that the object overlap in the area is serious, that is, many objects cannot be irradiated by light. Further, the status information of the scene is quantitatively checked through the status information panel, and it is found from the status information that the number of lots is 296 (the higher the value is, the more the lot is stuck), the number of triangles is about 42 ten thousand, and the number of vertices is about 62 ten thousand.
Referring to fig. 5, fig. 5 is a scene schematic diagram of rendering a virtual reality scene based on the model rendering method of the present invention. As shown in fig. 5, in the overlay mode, the brightness of the area marked by the rectangular frame is significantly reduced, which indicates that the object overlap in this area has been eliminated, i.e. the object that cannot be irradiated by the light is not rendered. Through the state information panel, the state information of the scene is quantitatively viewed, the number of batches is reduced to 62, the number of triangles is reduced to about 15 ten thousand, and the number of vertexes is reduced to about 21 ten thousand according to the state information. By the model rendering method provided by the invention, the batch number, the triangle number and the vertex number are reduced, and the lower the values are, the smoother the work operation is, otherwise, the work operation is very unstable.
In the embodiment, an artificial marking operation is received, and a model to be detected is determined from models included in a virtual reality scene based on the artificial marking operation; and determining a model to be rendered from the model to be detected through light detection, and rendering the model to be rendered. By the embodiment, unnecessary rendering is reduced, the display effect is not influenced, the rendering efficiency is improved, and system resources are saved.
Referring to fig. 6, fig. 6 is a functional module diagram of an embodiment of a model rendering apparatus according to the present invention. In one embodiment, a model rendering apparatus includes:
the marking module 10 is configured to receive an artificial marking operation, and determine a model to be detected from models included in a virtual reality scene based on the artificial marking operation;
and the rendering module 20 is configured to determine a model to be rendered from the models to be detected through light detection, and render the model to be rendered.
Further, in an embodiment, the rendering module 20 is configured to:
and controlling the camera to emit a light ray to each pixel point on the screen where the virtual reality scene is located, and taking the model to be detected, which is irradiated by the light ray, as the model to be rendered.
Further, in an embodiment, the rendering module 20 is configured to:
detecting whether each model in the models to be detected has an intersection point with at least one ray;
and taking the model with the intersection point with at least one light ray in the model to be detected as the model to be rendered.
Further, in an embodiment, the rendering module 20 is configured to:
detecting whether each surface of each model in the model to be detected has an intersection point with at least one ray;
and taking the model with the intersection point of the at least one surface and the at least one ray as the model with the intersection point of the at least one ray.
Further, in an embodiment, the rendering module 20 is configured to:
and (3) simultaneously establishing a parameter equation of any light and a parameter equation of any surface, wherein the parameter equation of any light is as follows: p ═ P
0+ ut, with the parameter equation for either side being n (a-P) ═ 0, resulting in
When t is greater than or equal to zero, the surface and the light ray have an intersection point; wherein, P
0Is the starting seat of lightThe index u is the direction vector of the light ray, different points of the light ray can be taken according to different values of t, n is the normal vector of the surface, P is the coordinate of the normal vector and the focus of the surface, and a is the coordinate of another point in the surface.
The specific embodiment of the model rendering device of the present invention is basically the same as the embodiments of the model rendering method described above, and details are not repeated here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.