CN117152237A - Distance field generation method and device, electronic equipment and storage medium - Google Patents

Distance field generation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117152237A
CN117152237A CN202311250350.9A CN202311250350A CN117152237A CN 117152237 A CN117152237 A CN 117152237A CN 202311250350 A CN202311250350 A CN 202311250350A CN 117152237 A CN117152237 A CN 117152237A
Authority
CN
China
Prior art keywords
target
point
sphere
distance
sampling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311250350.9A
Other languages
Chinese (zh)
Inventor
张沐阳
杜双泓
韦洪宇
苏磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuming Technology Hangzhou Co ltd
Original Assignee
Wuming Technology Hangzhou Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuming Technology Hangzhou Co ltd filed Critical Wuming Technology Hangzhou Co ltd
Priority to CN202311250350.9A priority Critical patent/CN117152237A/en
Publication of CN117152237A publication Critical patent/CN117152237A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • G06T7/62Analysis of geometric attributes of area, perimeter, diameter or volume
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/70Determining position or orientation of objects or cameras

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Geometry (AREA)
  • Processing Or Creating Images (AREA)

Abstract

The embodiment of the invention provides a distance field generation method, a device, electronic equipment and a storage medium, and relates to the technical field of three dimensions, wherein the method comprises the following steps: determining target position points of a distance field to be generated in a target area in a three-dimensional space; determining a target child node corresponding to the target position point from a hierarchical bounding volume BVH tree corresponding to the target region; determining an object characterized by bounding box information in the target child node to obtain at least one object adjacent to the target position point; a distance field of the target location point is calculated based on a distance relationship of the target location point to spheres comprised by a set of spheres of the at least one object. The distance field generation efficiency can be improved through the scheme.

Description

Distance field generation method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a distance field generating method, a device, an electronic apparatus, and a storage medium.
Background
The distance field of the point has wide application in scenes such as collision detection, ray tracing, ambient light shielding, global illumination and the like, namely, the shortest distance from any point in the three-dimensional space to the surface of each object in the three-dimensional space, and the positive and negative of the distance field respectively represent the point outside or inside the object.
In the related art, an object in a three-dimensional space is voxelized, and a distance field of a certain point (such as a center point) in each voxel, namely, a distance field of the voxel is calculated by adopting an offline ray tracing method and is stored; and according to the stored content, combining the distance occasions of the voxels of the multiple objects in a certain range in the three-dimensional space, namely combining the multiple objects into a whole object to obtain a global distance field of the whole object in the range, and calculating and inquiring the distance field of any point in the range based on the global distance field, namely calculating the shortest distance between any point and the whole object as the distance field of the point. For any object, voxelization is to divide a bounding box of the object into a plurality of cubes which are the same and smaller than the bounding box, and any cube after division is a voxel; the bounding box of an object is approximately replaced by a somewhat larger cube, i.e. bounding box.
Therefore, the distance field generating mode in the related technology has large calculation amount and low distance field generating efficiency.
Disclosure of Invention
The embodiment of the invention aims to provide a distance field generation method, a device, electronic equipment and a storage medium, so as to improve the generation efficiency of a distance field. The specific technical scheme is as follows:
In a first aspect, an embodiment of the present invention provides a distance field generating method, where the method includes:
determining target position points of a distance field to be generated in a target area in a three-dimensional space;
determining a target child node corresponding to the target position point from a hierarchical bounding volume BVH tree corresponding to the target region; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
determining an object characterized by bounding box information in the target child node to obtain at least one object adjacent to the target position point;
a distance field of the target location point is calculated based on a distance relationship of the target location point to spheres comprised by a set of spheres of the at least one object.
Optionally, the hierarchical bounding volume BVH tree corresponding to the target area includes a plurality of BVH trees, each BVH tree has unique correspondence with one of a plurality of hierarchical areas set for the target area, each hierarchical area includes a partial area of the target area, the areas included in the plurality of hierarchical areas form the target area, and bounding box information of each object included in the corresponding hierarchical area is stored in each BVH tree;
The determining the target sub-node corresponding to the target location point from the hierarchical bounding volume BVH tree corresponding to the target area includes:
determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions;
and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region.
Optionally, the calculating the distance field of the target location point based on the distance relation between the target location point and the sphere included in the sphere set of the at least one object includes:
calculating, for each of the at least one object, a shortest distance between the target location point and the object surface based on a distance relationship of the target location point to spheres comprised by a set of spheres of the object;
the minimum value of the calculated shortest distances is determined as a distance field of the target position point.
Optionally, for each object in the at least one object, calculating the shortest distance between the target location point and the object surface based on the distance relation between the target location point and the sphere contained in the sphere set of the object includes:
Calculating the shortest distance between the surfaces of each ball in the ball set of the object and the target position point respectively for each object in the at least one object to obtain a plurality of intermediate distances;
and determining the minimum distance in the plurality of intermediate distances as the shortest distance between the target position point and the object surface.
Optionally, the generating manner of the sphere set of any object in the three-dimensional space includes:
determining a plurality of surface sampling points and a plurality of internal sampling points of the object;
selecting a plurality of seed points from the plurality of internal sampling points;
for each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point; wherein the intermediate sampling points include: sampling points except the selected seed points in the internal sampling points and the surface sampling points;
based on the distance relation between each residual sampling point in the intermediate sampling points and the sphere represented by each initial set, each residual sampling point is added into one initial set to obtain a plurality of target sets; the sphere characterized by each initial set takes a seed point in the initial set as a circle center, and takes the distance between the seed point in the initial set and a target sampling point as a radius, so that a sphere is formed;
A set of spheres of the object is generated based on the plurality of target sets.
Optionally, the adding each remaining sampling point to an initial set based on the distance relation between each remaining sampling point in the intermediate sampling points and the sphere represented by each initial set to obtain a plurality of target sets includes:
calculating the normal direction along the triangle in the triangular mesh to which the first sampling point belongs for each first sampling point in the residual sampling points, wherein the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set contained in the first sampling point is calculated, so as to obtain the distance corresponding to at least one initial set contained in the first sampling point; adding the first sampling point into an initial set with the minimum corresponding distance; wherein any first sampling point is a surface sampling point at least contained in a sphere represented by an initial set in each remaining sampling point;
adding the second sampling point into an initial set corresponding to a seed point nearest to the second sampling point aiming at each second sampling point in the residual sampling points; each second sampling point is added to an initial set to obtain a plurality of target sets; wherein any one of the second sampling points is a sampling point of the remaining sampling points except the first sampling points.
Optionally, before generating the sphere set of the object based on the plurality of target sets, the method further includes:
calculating the mass centers corresponding to all points in each target set aiming at each target set, taking the calculated mass centers as new seed points, returning to each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into the set corresponding to the seed point to obtain an initial set corresponding to the seed point until each target set is subjected to the steps of generating the seed point utilized by the target set and the distance between the mass centers corresponding to all points in the target set, and obtaining a plurality of target seed sets;
the generating a sphere set of the object based on the plurality of target sets includes:
a set of spheres of the object is generated based on the plurality of target seed sets.
Optionally, the number of the plurality of surface sampling points is a first number, and the determining manner of the plurality of surface sampling points includes:
aiming at triangles in any triangular mesh of the object surface, calculating the target number of surface sampling points to be generated in the triangles according to the first number, and randomly generating initial surface sampling points of the target number in the triangles;
Determining and obtaining a plurality of surface sampling points based on initial surface sampling points generated in triangles in each triangular grid of the object surface;
the number of the plurality of internal sampling points is a second number, and the determining manner of the plurality of internal sampling points includes:
calculating target side lengths of cube voxels to be split according to the sum of areas of the triangles and the second quantity aiming at the triangles in each triangular grid of the object surface;
dividing the object into cube voxels according to the target side length, and taking the center points belonging to the object among the center points of the cube voxels as the plurality of internal sampling points.
Optionally, the construction method of the BVH tree corresponding to any hierarchical region includes:
determining the central coordinates of all objects contained in the hierarchical region, and generating Morton codes corresponding to the central coordinates of all objects;
and storing bounding box information of any object contained in the hierarchical region to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
Optionally, the BVH tree corresponding to any hierarchical region includes: a first BVH tree for storing bounding box information about static objects and/or a second BVH tree for storing bounding box information about dynamic objects;
The method further comprises the steps of:
when the target area changes, aiming at a first BVH tree corresponding to any hierarchical area, if the hierarchical area has a removed static object, invalidating bounding box information about the removed static object stored in the first BVH tree; if the hierarchy area has a newly added static object, reconstructing the first BVH tree according to the newly added static object;
and reconstructing a second BVH tree corresponding to any hierarchical region after the target region is changed.
In a second aspect, an embodiment of the present invention provides a distance field generating apparatus, the apparatus including:
the first determining module is used for determining target position points of a distance field to be generated in a target area in the three-dimensional space;
the second determining module is used for determining a target child node corresponding to the target position point from the hierarchical bounding volume BVH tree corresponding to the target region; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
A third determining module, configured to determine an object represented by bounding box information in the target child node, to obtain at least one object adjacent to the target location point;
and the calculating module is used for calculating the distance field of the target position point based on the distance relation between the target position point and the sphere contained in the sphere set of the at least one object.
Optionally, the hierarchical bounding volume BVH tree corresponding to the target area includes a plurality of BVH trees, each BVH tree has unique correspondence with one of a plurality of hierarchical areas set for the target area, each hierarchical area includes a partial area of the target area, the areas included in the plurality of hierarchical areas form the target area, and bounding box information of each object included in the corresponding hierarchical area is stored in each BVH tree;
the second determining module is specifically configured to:
determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions;
and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region.
Optionally, the computing module includes:
A calculating sub-module, configured to calculate, for each object of the at least one object, a shortest distance between the target location point and a surface of the object based on a distance relationship between the target location point and a sphere included in a sphere set of the object;
and the determining submodule is used for determining the minimum value in the calculated shortest distance as a distance field of the target position point.
Optionally, the computing submodule is specifically configured to:
calculating the shortest distance between the surfaces of each ball in the ball set of the object and the target position point respectively for each object in the at least one object to obtain a plurality of intermediate distances;
and determining the minimum distance in the plurality of intermediate distances as the shortest distance between the target position point and the object surface.
Optionally, the generating manner of the sphere set of any object in the three-dimensional space includes:
determining a plurality of surface sampling points and a plurality of internal sampling points of the object;
selecting a plurality of seed points from the plurality of internal sampling points;
for each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point; wherein the intermediate sampling points include: sampling points except the selected seed points in the internal sampling points and the surface sampling points;
Based on the distance relation between each residual sampling point in the intermediate sampling points and the sphere represented by each initial set, each residual sampling point is added into one initial set to obtain a plurality of target sets; the sphere characterized by each initial set takes a seed point in the initial set as a circle center, and takes the distance between the seed point in the initial set and a target sampling point as a radius, so that a sphere is formed;
a set of spheres of the object is generated based on the plurality of target sets.
Optionally, the adding each remaining sampling point to an initial set based on the distance relation between each remaining sampling point in the intermediate sampling points and the sphere represented by each initial set to obtain a plurality of target sets includes:
calculating the normal direction along the triangle in the triangular mesh to which the first sampling point belongs for each first sampling point in the residual sampling points, wherein the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set contained in the first sampling point is calculated, so as to obtain the distance corresponding to at least one initial set contained in the first sampling point; adding the first sampling point into an initial set with the minimum corresponding distance; wherein any first sampling point is a surface sampling point at least contained in a sphere represented by an initial set in each remaining sampling point;
Adding the second sampling point into an initial set corresponding to a seed point nearest to the second sampling point aiming at each second sampling point in the residual sampling points; each second sampling point is added to an initial set to obtain a plurality of target sets; wherein any one of the second sampling points is a sampling point of the remaining sampling points except the first sampling points.
Optionally, before generating the sphere set of the object based on the target sets, the method further includes:
calculating the mass centers corresponding to all points in each target set aiming at each target set, taking the calculated mass centers as new seed points, returning to each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into the set corresponding to the seed point to obtain an initial set corresponding to the seed point until each target set is subjected to the steps of generating the seed point utilized by the target set and the distance between the mass centers corresponding to all points in the target set, and obtaining a plurality of target seed sets;
the generating a sphere set of the object based on the plurality of target sets includes:
A set of spheres of the object is generated based on the plurality of target seed sets.
Optionally, the number of the plurality of surface sampling points is a first number, and the determining manner of the plurality of surface sampling points includes:
aiming at triangles in any triangular mesh of the object surface, calculating the target number of surface sampling points to be generated in the triangles according to the first number, and randomly generating initial surface sampling points of the target number in the triangles;
determining and obtaining a plurality of surface sampling points based on initial surface sampling points generated in triangles in each triangular grid of the object surface;
the number of the plurality of internal sampling points is a second number, and the determining manner of the plurality of internal sampling points includes:
calculating target side lengths of cube voxels to be split according to the sum of areas of the triangles and the second quantity aiming at the triangles in each triangular grid of the object surface;
dividing the object into cube voxels according to the target side length, and taking the center points belonging to the object among the center points of the cube voxels as the plurality of internal sampling points.
Optionally, the construction method of the BVH tree corresponding to any hierarchical region includes:
Determining the central coordinates of all objects contained in the hierarchical region, and generating Morton codes corresponding to the central coordinates of all objects;
and storing bounding box information of any object contained in the hierarchical region to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
Optionally, the BVH tree corresponding to any hierarchical region includes: a first BVH tree for storing bounding box information about static objects and/or a second BVH tree for storing bounding box information about dynamic objects;
further comprises:
when the target area changes, aiming at a first BVH tree corresponding to any hierarchical area, if the hierarchical area has a removed static object, invalidating bounding box information about the removed static object stored in the first BVH tree; if the hierarchy area has a newly added static object, reconstructing the first BVH tree according to the newly added static object;
and reconstructing a second BVH tree corresponding to any hierarchical region after the target region is changed.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing any distance field generation method when executing the program stored in the memory.
In a fourth aspect, embodiments of the present invention provide a computer-readable storage medium having stored therein a computer program which, when executed by a processor, implements any of the distance field generating methods.
The embodiments of the present invention also provide a computer program product comprising instructions which, when run on a computer, cause the computer to perform any of the distance field generating methods described above.
The embodiment of the invention has the beneficial effects that:
according to the distance field generation method provided by the embodiment of the invention, the target position point of the distance field to be generated in the target area in the three-dimensional space is firstly determined, in the invention, the bounding box information of each object contained in the target area is stored in the BVH tree corresponding to the target area, the target sub-node corresponding to the target position point can be determined from the BVH tree corresponding to the target area, and the object represented by the bounding box information stored in the target sub-node, namely, the object adjacent to the target position point, can be used for determining at least one object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, the sphere set of any object is used for representing the object through sphere approximation, and the distance field of the target position point can be rapidly calculated based on the distance relation between the target position point and the sphere contained in the sphere set of at least one object. It can be seen that, unlike the related art that calculates the distance field of voxels of each object in the three-dimensional space and generates the global distance field, the method provided by the invention is provided with the corresponding BVH tree aiming at the target area, so that the target sub-node corresponding to the target position point can be rapidly determined, and the distance field of the target position point can be simply, conveniently and rapidly obtained by calculating the target position distance field through the sphere set. Therefore, the generation efficiency of the distance field can be improved through the scheme.
Of course, it is not necessary for any one product or method of practicing the invention to achieve all of the advantages set forth above at the same time.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the invention, and other embodiments may be obtained according to these drawings to those skilled in the art.
FIG. 1 is a schematic diagram of sphere set approximation provided by an embodiment of the present invention;
FIG. 2 is a schematic diagram of a hierarchical bounding volume according to an embodiment of the present invention;
FIG. 3 is a schematic flow chart of a distance field generating method according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a plurality of hierarchical regions of a target region according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of another flow chart of a distance field generating method according to an embodiment of the present invention;
FIG. 6 (A) is a schematic diagram showing a manner of calculating a distance between a surface sampling point and a sphere surface of a sphere enclosed by the surface sampling point along a normal direction of a triangle to which the surface sampling point belongs according to an embodiment of the present invention;
FIG. 6 (B) is another schematic diagram showing a manner of calculating a distance between a surface sampling point and a sphere surface of a sphere enclosed by the surface sampling point along a normal direction of a triangle to which the surface sampling point belongs according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a distance field generating device according to an embodiment of the present invention;
fig. 8 is a block diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by the person skilled in the art based on the present invention are included in the scope of protection of the present invention.
For ease of understanding, the following description first refers to the terminology used in connection with the present invention.
Directional distance field (SDF Signed Distance Field): the distance field defines the shortest distance from any point in space to the surface of all objects in space, and if the distance from a point in the object to the surface of the object is set to be negative, the distance from a point outside the object to the surface of the object is set to be positive, that is, the directed distance field.
Sphere set approximation (Sphere Set Approximation) approximates a three-dimensional entity with a series of spheres of size, which, due to their rotational independence and ease of computation, achieve the goal of simplifying computation and expression. In general, the goal of sphere set approximation is to make the volume of spheres beyond the three-dimensional body as small as possible given the number of spheres, i.e., the tighter the bag, the better because the smaller the approximation to the object construction. As shown in fig. 1, the uppermost is an exemplary three-dimensional entity, respectively: object 1 and object 2; for each three-dimensional entity, the sphere set approximation, n, of the three-dimensional entity is sequentially downwards s Characterizing the number of balls in the sphere set approximation, E r Representing the error of the sphere set approximation of the object, for object 1, the number of spheres in the sphere set approximation increases in sequence from top to bottom, and the sphere size decreases in sequence, n s The variation of (2) is: 32-64-128; the error of the sphere set approaching the object is reduced from top to bottom in turn, E r The variation of (2) is 1.07-0.74-0.50; for the object 2, the number of balls in the sphere set approximation thereof increases in sequence from top to bottom, and the size of the balls decreases in sequence, n s The variation of (2) is: 32-64-128; the error of the sphere set approaching the object is reduced from top to bottom in turn, E r The variation of (2) is 1.83-0.95-0.43; wherein, for object 1, n s =32,E r Sphere set approximation at=1.07, sphere size greater than n s =64,E r Sphere set approximation at=0.74, number of spheres less than n s =64,E r Sphere set approximation at=0.74. When the number of the balls is the same, the error of the approximate representation of the three-dimensional entity of the ball set can be different, and the smaller the ball is, the smaller the error is. Wherein the sphere set is approximated by the sphere set.
Hierarchical bounding volume (BVH, bounding volume hierarchy): the BVH tree is a binary tree in which all geometric objects are wrapped in leaf nodes of the bounding volume, the bounding volume continues to wrap around a larger bounding volume, recursively wraps around, and finally the root node that is formed wraps around the entire scene. An AABB bounding box (axisymmetric bounding box, i.e., 6 faces of the box parallel to the xy, xz, yz plane) is typically used as a bounding volume for an object. As shown in the left side of fig. 2, the bounding box C contains an object 3, the bounding box B contains an object 1 and an object 2, the bounding box a contains a bounding box B and a bounding box C, the corresponding BVH tree of the bounding box is shown in the right side of fig. 2, it can be seen that the bounding box a is used as a father node of the bounding box B and the bounding box C, the child node of the bounding box B stores the object 1 and the object 2, and the child node of the bounding box C stores the object 3.
In the related art, the distance field of each voxel needs to be calculated, and there are usually many objects in the three-dimensional space, for example: 10000 objects, when calculating the distance field of any voxel, the shortest distance between a certain point in the voxel and the surface of the object needs to be calculated for each object, the calculated amount is huge, and a large amount of storage space is needed to store the calculated result.
In addition, in real-time operation, for a range, the distance field of the object in the range needs to be loaded and unloaded, for example: and loading the distance field of the object in the range, and unloading the distance field of the object if a certain object leaves the range, wherein the distance field of the object is characterized by the distance fields of a plurality of voxels divided by the object, so that a large amount of video memory is consumed in real-time operation.
Moreover, the distance field generation method in the related art has huge calculation amount, cannot be calculated in real time, and can only be calculated in advance in an offline mode, so that the dynamic object cannot be processed, namely the calculation of the distance field cannot be performed on the dynamic object, and the method has higher limitation.
Based on the above, the embodiment of the invention provides a distance field generation method, a device, electronic equipment and a storage medium, so as to improve the generation efficiency of the distance field.
The following describes a distance field generating method provided by the invention.
The distance field generating method provided by the embodiment of the invention can be applied to a three-dimensional engine, the three-dimensional engine can be used as 3D software, in practical application, the three-dimensional engine can be arranged on electronic equipment, the electronic equipment can be terminal equipment or a server, the terminal equipment can be a mobile phone, a computer and the like, and the invention does not limit the specific form of the electronic equipment. The distance field generating method provided by the embodiment of the invention can be applied to any scene with a distance field generating requirement, for example: in ray tracing, a scene of a distance field at a certain point needs to be calculated; or, in global illumination, a scene of a distance field at a certain point needs to be calculated, and the like.
The object according to the present invention is an object in a three-dimensional space, that is, a three-dimensional model in the three-dimensional space, and the target area according to the present invention is a certain area in the three-dimensional space, and the shape of the area may be a cube shape, a sphere shape, or the like, which is not limited in this aspect of the present invention. The target area can be any area in the three-dimensional space, and the three-dimensional space can be understood to comprise a plurality of target areas, and the distance field of a certain point in the target area can be calculated by adopting the distance field generating method provided by the invention for any target area; alternatively, it is understood that the target region may be changed to include any point in three-dimensional space, thereby enabling calculation of a distance field for any point in three-dimensional space.
The distance field generating method provided by the embodiment of the invention can comprise the following steps:
determining target position points of a distance field to be generated in a target area in a three-dimensional space;
determining a target child node corresponding to the target position point from a hierarchical bounding volume BVH tree corresponding to the target region; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
determining an object characterized by bounding box information in the target child node to obtain at least one object adjacent to the target position point;
a distance field of the target location point is calculated based on a distance relationship of the target location point to spheres comprised by a set of spheres of the at least one object.
According to the distance field generation method provided by the embodiment of the invention, the target position point of the distance field to be generated in the target area in the three-dimensional space is firstly determined, in the invention, the bounding box information of each object contained in the target area is stored in the BVH tree corresponding to the target area, the target sub-node corresponding to the target position point can be determined from the BVH tree corresponding to the target area, and the object represented by the bounding box information stored in the target sub-node, namely, the object adjacent to the target position point, can be used for determining at least one object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, the sphere set of any object is used for representing the object through sphere approximation, and the distance field of the target position point can be rapidly calculated based on the distance relation between the target position point and the sphere contained in the sphere set of at least one object. It can be seen that, unlike the related art that calculates the distance field of voxels of each object in the three-dimensional space and generates the global distance field, the method provided by the invention is provided with the corresponding BVH tree aiming at the target area, so that the target sub-node corresponding to the target position point can be rapidly determined, and the distance field of the target position point can be simply, conveniently and rapidly obtained by calculating the target position distance field through the sphere set. Therefore, the generation efficiency of the distance field can be improved through the scheme.
An exemplary description of a distance field generating method according to the present application is provided below with reference to the accompanying drawings.
As shown in fig. 3, the distance field generating method provided by the present application may include the following steps:
s301: determining target position points of a distance field to be generated in a target area in a three-dimensional space;
the distance field generated by the embodiment of the application is a distance field aiming at a certain point, firstly, the target position point of the distance field to be generated in the target area in the three-dimensional space can be determined, and the distance field of the target position point can be generated through the subsequent steps.
It should be noted that the target area may be a partial area in the three-dimensional space, and the size, shape, position, etc. of the target area are not limited in the present application, and the target area may be an area including a virtual camera in the three-dimensional space, and the shape of the target area may be a cube shape, and the side length may be 8. Of course, it is reasonable to center a certain virtual camera in the three-dimensional space and set an area included in a certain range around the virtual camera as a target area.
For the target position point in the target area, only the distance between the target position point and the object surface contained in the target area is needed to be calculated in the follow-up process, so that the distance field of the target position point is obtained, the distance between the target position point and each object surface in the three-dimensional space is not needed to be calculated, and the calculated amount when the distance field is generated can be reduced preliminarily.
In addition, the target location point may be any distance field location point to be generated in the target area, and the determination manner of the target location point may be: randomly selecting a point from the target area to serve as a target position point; or, taking a position point in the target area input by the user as a target position point; the user may input coordinates of a point in the target area based on the target area, and the electronic device may determine the target location point through the interactive interface.
S302: determining a target child node corresponding to the target position point from a hierarchical bounding volume BVH tree corresponding to the target region;
the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area has its corresponding set of spheres used to approximate the object through a sphere.
In the invention, a corresponding BVH tree is arranged for a target area, bounding box information of each object contained in the target area exists in the BVH tree, after a target position point is determined, a target sub-node corresponding to the target position point can be determined from the BVH tree of the target area, an object represented by the bounding box information stored in the target sub-node is an object adjacent to the target position point, any object contained in the target area is provided with a corresponding sphere set, the sphere set of any object is used for representing the object through sphere approximation, and then at least one object adjacent to the target position point can be rapidly determined according to the determined target sub-node and the sphere set of the object represented by the target sub-node.
In the embodiment of the invention, aiming at different precision requirements, a target area is further provided with a plurality of level areas, a level bounding volume BVH tree corresponding to the target area comprises a plurality of BVH trees, each BVH tree has unique correspondence with one level area in the plurality of level areas which are arranged aiming at the target area, each level area comprises a partial area of the target area, the areas contained in the plurality of level areas form the target area, and bounding box information of each object contained in the corresponding level area is stored in each BVH tree;
the determining the target sub-node corresponding to the target location point from the hierarchical bounding volume BVH tree corresponding to the target area includes:
determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions;
and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region.
For the target location point, the target level region to which the target location point belongs may be determined from the plurality of level regions, the target level region is also provided with a corresponding BVH tree, and the target child node corresponding to the target location point may be determined from the BVH tree corresponding to the target level region.
It should be noted that, by setting a plurality of hierarchical regions in the target region, the target hierarchical region corresponding to the target location point may be determined under the condition of meeting different precision requirements, so as to determine the target hierarchical level to determine the target child node in the corresponding BVH tree.
For example, if the center point of the target area is a virtual camera in three-dimensional space, a plurality of hierarchical areas may be set for the target area according to the shape of the target area and a certain proportion, for example: the target area is a cube-shaped virtual camera with a center point being a three-dimensional space, the side length of the cube structure of the target area can be 8, and the 0 th-level area is an area contained by a cube with the virtual camera as the center and the side length of the cube being 2; the 1 st level region is a region (except the 0 th level region) included in a cube having a side length of 4 with the virtual camera as the center; the 2 nd level region is a region (excluding the 0 th level region and the 1 st level region) included in a cube having a side length of 8 with the virtual camera as the center.
As shown in fig. 4, the multiple hierarchical regions of the target region provided by the embodiment of the present invention may include: cascade1, cascade2 and Cascade3, namely the 0 th, 1 st and 2 nd level areas, cascade1 is an area containing a range close to the camera, cascade2 contains Cascade1, cascade3 contains Cascade 2. Wherein, cascade2 can be understood as a square area of Cascade2 in the figure, and the area except Cascade 1; cascade3 is understood to mean the square region of Cascade3 in the figure, except Cascade1 and regions other than Cascade 2. The camera in the invention can be used as the center point of the Cascade1, and of course, the camera can also be any point in the Cascade1, and the invention is not limited to the center point.
Each level region corresponds to a unique BVH tree, the BVH tree corresponding to the level region stores bounding box information of each object contained in the level region, and for the target level region to which the target location point belongs, a target child node corresponding to the target location point can be determined from the BVH tree corresponding to the target level region, and illustratively, the target location point can be input into the BVH tree corresponding to the target level region, the BVH tree corresponding to the target level region traverses down from the root node to the target child node, and the object represented by the bounding box information stored in the target child node, namely, the object adjacent to the target location point. It is also understood that the target location point is input into the BVH tree corresponding to the target hierarchical region, and the output node is the target child node.
It should be noted that, for any object, the object may also belong to multiple hierarchical regions, for example: part of the object is positioned in a 0 th level area, and the other part of the object is positioned in a 1 st level area, wherein the bounding box information of the object is stored in a BVH tree corresponding to the 0 th level area, and the bounding box information of the object is also stored in a BVH tree corresponding to the 1 st level area; alternatively, a part of the object is located in the 0 th hierarchical region, a part of the object is located in the 1 st hierarchical region, and a part of the object is located in the 2 nd hierarchical region, and at this time, bounding box information of the object is stored in BVH trees corresponding to the 0 th hierarchical region, the 1 st hierarchical region, and the 2 nd hierarchical region, which is not limited in the present invention.
Of course, for a child node in the BVH tree, the child node may store bounding box information of one or more objects therein, and the invention does not limit the number of objects to which the bounding box information stored in any child node belongs.
Wherein the determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions includes: and judging a hierarchical region to which the coordinates of the target position point belong as a target hierarchical region according to the coordinates of the target position point. For example: establishing a coordinate system by taking a virtual camera in a three-dimensional space as a center, wherein a 0 th-level region is a region of a cube with the virtual camera as the center and the side length of 2; the 1 st level region is a region of a cube having a side length of 4 (except the 0 th level region) centered on the virtual camera; the 2 nd level region is a region of a cube having a side length of 8 (except the 0 th level region and the 1 st level region) centered on the virtual camera; if the coordinates of the target position point are (0.5,0.5,0.5), the 0 th hierarchical region can be determined as the target hierarchical region to which the target position point belongs, and if the coordinates of the target position point are (3, 3), the 2 nd hierarchical region can be determined as the target hierarchical region to which the target position point belongs.
It should be noted that, the virtual camera may not be a center point of the target area, and the division manner of the multiple hierarchical areas of the target area may be divided according to the requirement; of course, the target area may not be divided into multiple hierarchical areas, the accuracy of each object in the target area is the same, and the BVH tree corresponding to the target area stores bounding box information of each object included in the target area, which is not limited in the present invention.
S303: determining an object characterized by bounding box information in the target child node to obtain at least one object adjacent to the target position point;
after determining the target sub-node corresponding to the target position point, an object represented by bounding box information in the target sub-node can be determined, and at least one object adjacent to the target position point is obtained.
In the invention, any child node in the BVH tree can store bounding box information of one or more objects, and an object represented by the bounding box information in the target child node can be used as at least one object adjacent to the target position point; of course, any object in the three-dimensional space may also be provided with an object ID, and at this time, an object having the object ID stored in the target child node may be taken as at least one object adjacent to the target location point.
S304: a distance field of the target location point is calculated based on a distance relationship of the target location point to spheres comprised by a set of spheres of the at least one object.
In the embodiment of the invention, for any object in the target area, a sphere set of the object is pre-constructed, and each sphere contained in the sphere set is used for approximately representing the object, so that the purposes of simplifying calculation and expression are achieved, and at the moment, the distance field of the target position point can be simply, conveniently and quickly calculated based on the sphere set of at least one object.
In one implementation, the calculating the distance field of the target location point based on the distance relation between the target location point and the sphere included in the sphere set of the at least one object includes:
calculating, for each of the at least one object, a shortest distance between the target location point and the object surface based on a distance relationship of the target location point to spheres comprised by a set of spheres of the object;
the minimum value of the calculated shortest distances is determined as a distance field of the target position point.
When determining the distance field of the target position point based on the distance relation between the target position point and the sphere contained in the sphere set of at least one object, the shortest distance between the target position point and the surface of at least one object can be calculated firstly, namely, for each object in at least one object, the shortest distance between the target position point and the surface of the object is calculated based on the distance relation between the target position point and the sphere contained in the sphere set of the object; the minimum value of the calculated shortest distances, i.e. the shortest distance between the target location point and the at least one object in the vicinity, i.e. the distance field of the target location point.
Wherein for each of the at least one object, calculating the shortest distance between the target location point and the object surface based on the distance relationship between the target location point and the sphere contained in the sphere set of the object comprises:
calculating the shortest distance between the surfaces of each ball in the ball set of the object and the target position point respectively for each object in the at least one object to obtain a plurality of intermediate distances;
and determining the minimum distance in the plurality of intermediate distances as the shortest distance between the target position point and the object surface.
When calculating the shortest distance between the target position point and the surface of the object, the shortest distance between the target position point and the surfaces of the balls in the ball set of the object, namely the shortest distance between the surfaces of the balls in the ball set of the object and the target position point, can be calculated first to obtain a plurality of intermediate distances; at this time, the target position point corresponds to a plurality of intermediate distances for each of the at least one object, and the minimum distance among the plurality of intermediate distances may be taken as the shortest distance between the target position point and the surface of the object.
It should be noted that, for any object, the sizes of the balls in the ball set corresponding to the object may be different, and on the premise that the object is approximately represented, the sizes of the balls in the ball set corresponding to the object are not limited. In addition, for any object, a sphere set corresponding to a plurality of hierarchical regions, that is, the plurality of regions divided for the target region may be generated in advance; the number of balls in the set of balls in different hierarchical regions may be different for the same object, for example: the number of balls in the ball set corresponding to the 0 th hierarchical region of the object is 256, the number of balls in the ball set corresponding to the 1 st hierarchical region of the object is 128, and the number of balls in the ball set corresponding to the 2 nd hierarchical region of the object is 64. The level of the object in the target area may change, a sphere set corresponding to a plurality of level areas is generated for each object in the target area, and in different level areas, the sphere set corresponding to the level area where the object is currently located can be selected from sphere sets corresponding to a plurality of level areas generated in advance, so that the accuracy requirement of the level area for approximate representation of the object through the sphere set is met. For any object, the more the number of balls in the ball set corresponding to the object, the higher the accuracy of the ball set approximate representation of the object. The above description of the number of balls in the ball set corresponding to any object in different hierarchical regions is merely an example, and the number may be increased or decreased in an equal ratio according to actual requirements, which is not limited in the present invention.
When calculating the distance field of the target position point based on the distance relation between the target position point and the spheres contained in the sphere set of the at least one object, the sphere set corresponding to the at least one object in the target level area can be determined first, and the distance field of the target position point can be calculated by using the sphere set corresponding to the at least one object in the target level area. For example: the target level region is the 0 th level region, and the distance field of the target position point can be calculated according to the mode based on a sphere set corresponding to at least one object in the 0 th level region (the number of spheres in the sphere set of each object can be 256); of course, for any one of at least one object, the object may be located in multiple hierarchical regions simultaneously, for example: the object-corresponding target hierarchical region may be a 0 th hierarchical region (the number of balls in the ball set of each object may be 256), and a 1 st hierarchical region (the number of balls in the ball set of each object may be 128), at which time the distance field of the target position point may be calculated based on the ball set corresponding to the portion of the object in the 0 th hierarchical region and the ball set corresponding to the portion of the object in the 1 st hierarchical region, in the above-described manner.
Of course, for any object in the target area, the sphere set of the object may not divide the hierarchical area, that is, no matter in which area in the target area the object is, the number of spheres in the corresponding sphere set is a default fixed number, for example: at this time, no matter which hierarchical region the target position point belongs to, the distance field of the target position point may be calculated according to a default fixed number of balls in the sphere set of at least one object.
According to the distance field generation method provided by the embodiment of the invention, the target position point of the distance field to be generated in the target area in the three-dimensional space is firstly determined, in the invention, the bounding box information of each object contained in the target area is stored in the BVH tree corresponding to the target area, the target sub-node corresponding to the target position point can be determined from the BVH tree corresponding to the target area, and the object represented by the bounding box information stored in the target sub-node, namely, the object adjacent to the target position point, can be used for determining at least one object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, the sphere set of any object is used for representing the object through sphere approximation, and the distance field of the target position point can be rapidly calculated based on the distance relation between the target position point and the sphere contained in the sphere set of at least one object. It can be seen that, unlike the related art that calculates the distance field of voxels of each object in the three-dimensional space and generates the global distance field, the method provided by the invention is provided with the corresponding BVH tree aiming at the target area, so that the target sub-node corresponding to the target position point can be rapidly determined, and the distance field of the target position point can be simply, conveniently and rapidly obtained by calculating the target position distance field through the sphere set. Therefore, the generation efficiency of the distance field can be improved through the scheme.
Optionally, the construction method of the BVH tree corresponding to any hierarchical region includes:
determining the central coordinates of all objects contained in the hierarchical region, and generating Morton codes corresponding to the central coordinates of all objects;
and storing bounding box information of any object contained in the hierarchical region to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
In the embodiment of the invention, for any one of a plurality of hierarchical regions of a target region, a unique BVH tree is corresponding to any one of the hierarchical regions, when the BVH tree corresponding to any one of the hierarchical regions is constructed, the center coordinates of each object contained in the hierarchical region can be determined first, the moire codes corresponding to the center coordinates of each object are generated, the moire codes corresponding to the center coordinates of any one of the objects can represent the bounding box information of the object to be stored in the child nodes of the BVH tree, and for any one of the objects contained in the hierarchical region, the bounding box information of the object can be stored in the child nodes in the BVH tree represented by the moire codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
For example, for any object, an average value of coordinates of each point included in the object may be calculated to obtain coordinates of a center point of the object, that is, center coordinates; the manner of generating the Morton code corresponding to the center coordinates of each object and storing the bounding box information of the object to the child nodes in the BVH tree represented by the Morton code corresponding to the center coordinates of the object for any object included in the hierarchical region to obtain the BVH tree corresponding to the hierarchical region will be described in detail in the following embodiments, and will not be described herein.
By means of Morton coding, the BVH tree can be built by Morton coding, which sub-node of the BVH tree the bounding box information of the object should be stored with can be characterized, so that the bounding box information of the object is stored to the corresponding sub-node in the BVH tree, and the BVH tree of any regional level can be built quickly. In addition, the BVH tree is usually required to be built in real time, and the BVH tree can be quickly built in a mode of building the BVH tree through Morton coding, and the real-time performance and the accuracy of the built BVH tree are ensured.
Optionally, the BVH tree corresponding to any hierarchical region includes: a first BVH tree for storing bounding box information about static objects and/or a second BVH tree for storing bounding box information about dynamic objects;
The method further comprises the steps of:
when the target area changes, aiming at a first BVH tree corresponding to any hierarchical area, if the hierarchical area has a removed static object, invalidating bounding box information about the removed static object stored in the first BVH tree; if the hierarchy area has a newly added static object, reconstructing the first BVH tree according to the newly added static object;
and reconstructing a second BVH tree corresponding to any hierarchical region after the target region is changed.
The embodiment of the invention supports the calculation of the distance field aiming at the static object and the dynamic object, and the calculated distance field is also the real-time distance field of the target position point due to the real-time property of the BVH tree; wherein, the BVH trees corresponding to the dynamic object and the static object are usually required to be distinguished, that is, the BVH tree of any hierarchical structure includes a first BVH tree storing bounding box information about the static object and/or a second BVH tree storing bounding box information about the dynamic object; the target area may change, for example: translation, rotation, scaling, etc., in order to ensure the real-time performance of the constructed BVH tree, after the target area changes, if a removed static object exists in the level area for the first BVH tree corresponding to any level area, invalidating bounding box information about the removed static object in the first BVH tree, for example: marked as invalid or culled, etc.; if there is a new static object in the hierarchical region, the first BVH tree may be reconstructed based on the new static object. After the target area changes, reconstructing a second BVH tree corresponding to any hierarchical area according to the second BVH tree.
It should be noted that, the change of the target area may be: the virtual camera at the center point of the target area moves beyond a predetermined distance range, which may be the target side length calculated later. The priority of constructing BVH trees for different hierarchical regions may be different for dynamic objects, for example: the 0 th level region and the 1 st level region can each construct corresponding BVH tree in real time, the 2 nd level region can construct BVH tree once every 2 frames, the 3 rd level region can construct BVH tree once every 4 frames, and the like, and the maximum BVH tree can be constructed once every 6 frames, so that flexible scheduling can be performed under the condition of limited computing resources.
According to the scheme provided by the embodiment of the invention, the generation of the distance field of the target position point for the dynamic object and the static object can be supported, the static object and the dynamic object can store corresponding bounding box information through the first BVH tree and the second BVH tree respectively for any level region, and after the target region changes, the dynamic object and the static object can update the corresponding BVH tree according to different modes, so that the real-time performance and the accuracy of the BVH tree are ensured.
It will be appreciated that the set of spheres of the dynamic object contained in the target area will also change due to the movement of the dynamic object, at which point the set of spheres of the dynamic object may be updated. In particular, for a dynamic object without skeletal animation, the change is usually a change in position and/or direction, and the position of the ball in the ball set of the dynamic object without skeletal animation can be adjusted due to the rotation invariance of the ball; for a dynamic object with skeleton animation, when generating a ball set, the dynamic object with skeleton animation can be divided into a plurality of sub-objects according to the skeleton animation, and a ball set is generated for each sub-object, at this time, for any dynamic object with skeleton animation, the position of each ball contained in the ball set can be adjusted for each sub-object in the ball set of the plurality of sub-objects; of course, the dynamic object with skeleton animation is a whole, the distance between the plurality of sub-objects can be smaller than a certain distance threshold, and on the premise that the distance between the plurality of sub-objects is smaller than a certain distance threshold, the positions of balls in the ball set of the plurality of sub-objects can be adjusted.
Therefore, the distance field generating method provided by the invention can construct or generate the BVH tree in real time, and update the sphere set of the dynamic object in real time, so that the accuracy and the instantaneity of the calculated distance field of the target position point are ensured.
The following describes a generation manner of a sphere set in a distance field generation method according to another embodiment of the present invention.
As shown in fig. 5, the generation method of the sphere set of any object in the three-dimensional space includes:
s501: determining a plurality of surface sampling points and a plurality of internal sampling points of the object;
in the embodiment of the invention, the sphere set of the object can be generated through the sampling points of the object, the sampling of the object comprises the surface sampling points and the internal sampling points, and for any object in the three-dimensional space, a plurality of surface sampling points and a plurality of internal sampling points of the object can be determined first, so that the sphere set of the object is generated through the subsequent steps.
In one implementation, the number of the plurality of surface sampling points is a first number, and the determining manner of the plurality of surface sampling points includes:
aiming at triangles in any triangular mesh of the object surface, calculating the target number of surface sampling points to be generated in the triangles according to the first number, and randomly generating initial surface sampling points of the target number in the triangles;
The plurality of surface sampling points are determined based on initial surface sampling points generated in triangles in each triangular mesh of the object surface.
For the surface sampling points, the number of the surface sampling points can be a first number, the object surface is rendered through a triangular mesh, the triangular mesh can be understood as a plurality of triangles, for each triangle, the target number of the surface sampling points to be generated in the triangle can be calculated according to the first number, the initial surface sampling points of the target number are randomly generated in the triangle, and the plurality of target sampling points are determined based on the initial sampling points in each triangle.
For example, the plurality of initial surface sampling points may be directly used as the plurality of surface sampling points, where the number of the plurality of initial surface sampling points is the same as the number of the plurality of surface sampling points, and the number of the plurality of initial surface sampling points is the first number; of course, sampling points may be selected from a plurality of initial surface sampling points to obtain a plurality of surface sampling points, where the number of the plurality of surface sampling points may be less than or equal to the number of the plurality of initial surface sampling points.
The method comprises the steps of calculating the target number of the surface sampling points to be generated in each triangle through the first number, enabling the target number of the sampling points to be generated in each triangle according to the proportion, enabling the initial surface sampling points to be more realistic and random in a mode of randomly generating the initial surface sampling points for each triangle, and avoiding influences caused by subjective feeling of people in generating the initial surface sampling points.
Illustratively, in one implementation, the number of the plurality of internal sampling points is a second number, and the determining manner of the plurality of internal sampling points includes:
calculating target side lengths of cube voxels to be split according to the sum of areas of the triangles and the second quantity aiming at the triangles in each triangular grid of the object surface;
dividing the object into cube voxels according to the target side length, and taking the center points belonging to the object among the center points of the cube voxels as the plurality of internal sampling points.
For a plurality of internal sampling points, the number of the plurality of sampling points which are required to be generated is a second number, and for any object, the object surface is obtained by rendering triangles in a triangular mesh; specifically, the edge length of the square voxel to be split may be calculated based on the sum of the areas of the respective triangles of the object surface and the second number, and specifically, the target edge length of the square voxel to be split may be calculated using the following formula: l=sqrt (S/M), where L is the target side length, S is the sum of the areas of the triangles of the object surface, M is the second number, sqrt is a function of the calculated square root, and S/M can characterize how large an area of the object surface is, a sampling point is generated. After the target side length is obtained, the object may be split into cube voxels according to the target side length, where the number of the split cube voxels may be a second number, in this embodiment, for simple calculation, the center point of the cube voxel may be used as a sampling point, and for the internal sampling point, the internal sampling point is a sampling point inside the object, where the center point belonging to the object inside among the center points of the cube voxels may be used as a plurality of internal sampling points, where, because there may be center points belonging to the object surface or the outside of the object in the center points of the cube voxels, the number of the finally obtained plurality of internal sampling points may be less than or equal to the second number.
S502: selecting a plurality of seed points from the plurality of internal sampling points;
after a plurality of surface sampling points and a plurality of internal sampling points of an object are determined, a sphere set of the object is generated, the object is approximately represented by each sphere in the sphere set, and a plurality of seed points can be selected from the plurality of internal sampling points; the number of the selected seed points is the same as the number of balls in the ball set generated later, and for any object, if the number of the balls in the ball set of the object is a default fixed number of balls, the number of the selected seed points can be the default fixed number of balls; for a plurality of hierarchical regions, in order to meet different precision requirements, the object can also generate ball sets with different precision, and for different hierarchical regions, the number of balls in the ball sets to be generated can be: the number of balls corresponding to the 0 th level region is 256, the number of balls corresponding to the 1 st level region is 128, and the number of balls corresponding to the 2 nd level region is 64; for any object, 256, 128 and 64 seed points can be selected respectively, and ball sets can be generated respectively.
It should be noted that, there may be various ways of selecting a plurality of seed points from the plurality of internal sampling points, and exemplary ways of randomly selecting a plurality of sampling points from a plurality of internal sampling points are used as a plurality of seed points; or selecting a plurality of sampling points with the distance between any two sampling points being larger than a preset threshold value from a plurality of internal sampling points as a plurality of seed points, wherein the selection mode of the plurality of seed points is not limited.
S503: for each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point;
wherein the intermediate sampling points include: sampling points except the selected seed points in the internal sampling points and the surface sampling points;
in the scheme provided by the invention, for each seed point, a ball corresponding to the seed point can be generated, so that a ball set of the object is obtained; after obtaining a plurality of seed points, for each seed point, firstly, adding a target sampling point and the seed point which are closest to the seed point in sampling points except the selected seed points in the internal sampling points and the surface sampling points into a set corresponding to the seed point to obtain an initial set corresponding to the seed point. Wherein, the target sampling point and the seed point are added to the corresponding set of the seed point, namely the target sampling point and the seed point are divided into a whole, the whole comprises the seed point and the target sampling point, and the whole can be characterized by any one form, for example: set, category, etc., in the present invention, the whole is characterized by means of set, that is, the initial set corresponding to the seed point.
S504: based on the distance relation between each residual sampling point in the intermediate sampling points and the sphere represented by each initial set, each residual sampling point is added into one initial set to obtain a plurality of target sets;
the sphere characterized by each initial set takes a seed point in the initial set as a circle center, and takes the distance between the seed point in the initial set and a target sampling point as a radius, so that a sphere is formed;
after obtaining initial sets corresponding to a plurality of seed points, each residual sampling point still exists in the middle sampling points, and in order to generate a sphere set of the object, the initial set can represent a sphere in a first step, and each residual sampling point can be added into the initial set corresponding to the sphere according to a certain distance relation; specifically, each remaining sampling point may be added to an initial set based on a distance relationship between each remaining sampling point in the intermediate sampling points and a sphere represented by each initial set, so as to obtain a plurality of target sets. The difference between the target set and the initial set is that the target set is a set after the initial set adds the residual sampling points, and of course, for a certain initial set, each residual sampling point in each residual sampling point may not be added to the initial set, and the initial set may be directly used as the target set; and, for each remaining sampling point, the distance relation between the remaining sampling point and the sphere represented by the plurality of initial sets can be the same, and at this time, the remaining sampling points can be added into the plurality of initial sets at the same time, which is reasonable.
In an implementation manner, the adding each remaining sampling point to an initial set based on a distance relation between each remaining sampling point in the intermediate sampling points and a sphere represented by each initial set to obtain a plurality of target sets includes:
calculating the normal direction along the triangle in the triangular mesh to which the first sampling point belongs for each first sampling point in the residual sampling points, wherein the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set contained in the first sampling point is calculated, so as to obtain the distance corresponding to at least one initial set contained in the first sampling point; adding the first sampling point into an initial set with the minimum corresponding distance; wherein any first sampling point is a surface sampling point at least contained in a sphere represented by an initial set in each remaining sampling point;
adding the second sampling point into an initial set corresponding to a seed point nearest to the second sampling point aiming at each second sampling point in the residual sampling points; each second sampling point is added to an initial set to obtain a plurality of target sets; wherein any one of the second sampling points is a sampling point of the remaining sampling points except the first sampling points.
For each remaining sampling point, the remaining sampling point may be a surface sampling point of a sphere represented by a certain initial set, where the remaining sampling point is a first sampling point, a normal direction along a triangle in a triangular mesh to which the first sampling point belongs may be calculated, a distance between the first sampling point and a sphere surface of the sphere represented by at least one initial set in which the first sampling point is included is obtained, a distance corresponding to at least one initial set in which the first sampling point is included is obtained, and the first sampling point is added to the initial set with the minimum corresponding distance. The number of the initial sets with the minimum corresponding distance added by the first sampling point may be one or more, and the first sampling point may be added to a plurality of initial sets at the same time.
The following formula may be adopted to calculate the normal direction along the triangle in the triangular mesh to which the first sampling point belongs, where the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set included in the first sampling point:
wherein P is the normal direction of the triangle in the triangle mesh to which the first sampling point belongs, and the distance between the first sampling point and the sphere surface of the sphere represented by an initial set in which the first sampling point is contained; r is the radius of a sphere represented by an initial set contained in the first sampling point, namely the distance between a seed point and a target sampling point in the initial set contained in the first sampling point; d, d 2 For the first sampling point to c Is a distance of (2); d, d 1 For c to c Is a distance of (2); c is the center of a sphere represented by an initial set contained in the first sampling point, namely the position of a seed point in the initial set contained in the first sampling point; c And c, along the normal direction of the triangle in the triangular mesh of the first sampling point, the projection point of the plane of the triangle in the triangular mesh to which the first sampling point belongs.
For each remaining sampling point, the remaining sampling point may be a surface sampling point of a sphere that is not represented by any initial set, or the remaining sampling point is an internal sampling point of an object, where the remaining sampling point is a second sampling point, and for each second sampling point, the second sampling point may be added to an initial set corresponding to a seed point closest to the second sampling point, and when each second sampling point is added to an initial set, a plurality of target sampling points are obtained. The number of the plurality of initial sets added by the second sampling point may be a plurality of similar to the first sampling point, that is, a plurality of seed points may exist, the distance between the seed points is the same as the distance between the second sampling points, and the second sampling point may be the shortest distance, and at this time, the second sampling point may be added to the initial set corresponding to the seed point closest to the second sampling point.
Through the steps, each residual sampling point can be added into an initial set according to the corresponding distance relation between the residual sampling point and the sphere represented by each initial set, so that a plurality of target sets are obtained, and then the sphere set of the object can be accurately generated based on the plurality of target sets.
Additionally, before generating the sphere set of the object based on the plurality of target sets, the method further includes:
calculating the mass centers corresponding to all points in each target set aiming at each target set, taking the calculated mass centers as new seed points, returning to each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into the set corresponding to the seed point to obtain an initial set corresponding to the seed point until each target set is subjected to the steps of generating the seed point utilized by the target set and the distance between the mass centers corresponding to all points in the target set, and obtaining a plurality of target seed sets;
the generating a sphere set of the object based on the plurality of target sets includes:
a set of spheres of the object is generated based on the plurality of target seed sets.
The object sets may also be iteratively updated prior to generating the sphere sets for the object based on the plurality of object sets, and specifically, for each object set, a centroid corresponding to each point in the object set may be calculated, for example: calculating the average value of the coordinates of all points in the target set, and obtaining the coordinates, namely the coordinates of the mass center of the target set; the calculated mass center is used as a new seed point, and the step of generating a target set aiming at each seed point is returned; for each target set, if the distances between the seed points utilized by the target set and the centroids corresponding to the points in the target set are generated and the ending condition is met, the iterative updating of the target set is considered to be finished, and the iteratively updated target set is a plurality of target seed sets. The ending condition may be less than a certain distance threshold, which is not limited in the present invention.
A more accurate set of spheres for the object may then be generated based on the plurality of target seed sets, the generated set of spheres being capable of more closely characterizing the object.
S505: generating a set of spheres for the object based on the plurality of target sets;
after obtaining a plurality of target sets, a sphere set of the object can be generated based on the plurality of target sets; there may be various ways of generating it, for example: aiming at each target set, taking a seed point utilized for generating the target set as a circle center, taking the distance between the point farthest from the circle center in the target set and the circle center as a radius, and generating a ball corresponding to the target set; and then a plurality of balls corresponding to the plurality of target sets, namely a ball set of the object is obtained.
It should be noted that, on the premise of ensuring that the generated sphere set can approximately represent the object, the method of generating the sphere set of the object based on multiple target sets is not limited in the present invention.
In addition, the sphere set of any object may be generated in advance, after the sphere set of any object is generated, the sphere set of any object may be stored, and during storage, only the circle centers and the radii of the spheres in the sphere set need to be stored, and for a plurality of hierarchical regions, for each object, sphere sets corresponding to a plurality of hierarchical regions of the object may also be generated and stored; at this time, the data stored for the sphere set only contains the position of the center of each sphere and the size of the radius, the data size is small, the sphere set of the object can be quickly generated, and the occupied storage space is small during storage.
According to the distance field generation method provided by the embodiment of the invention, for any object in a three-dimensional space, a plurality of surface sampling points and a plurality of internal sampling points of the object can be determined, a plurality of seed points are selected from the plurality of internal sampling points, and an initial set of the plurality of seed points is generated; adding each residual sampling point into an initial set through the distance relation between each residual sampling point in the middle sampling points and the sphere represented by each initial set to obtain a plurality of target sets; the method can iteratively update a plurality of target sets, and can generate a more accurate sphere set of the object based on the iteratively updated target seed set; thus, when calculating the distance field of the target position point based on the distance relation of the target position point and the sphere contained in the sphere set of the at least one object, the accuracy of the calculated distance field can be improved.
The distance field generating method provided by the invention is described below with reference to a specific embodiment.
The distance field generating method provided by the invention can comprise a pre-calculation part and a real-time part; in the pre-calculation part, objects in the three-dimensional space are calculated offline and sphere set approximations are generated, in the real-time part, objects in a certain range (such as a range around a camera) are organized through a BVH tree, when a point in the range is given, all objects with influence on the point, namely the adjacent objects of the point, can be quickly inquired through the BVH tree, and the distance field of the point is calculated by utilizing the sphere set approximations of the inquired objects.
In the pre-calculation section, a three-dimensional model of the object may be pre-processed and a sphere set approximation generated:
1.1 randomly sampling the model to generate M surface sampling points and M internal sampling points:
for any three-dimensional model, a plurality of surface sampling points and internal sampling points can be selected from the three-dimensional model; for the surface sampling points of the three-dimensional model, triangles in the triangular mesh of the three-dimensional model are ordered and summed according to the area, for any triangle, the target number of the surface sampling points to be generated in the triangle can be solved according to M, and the target number of the surface sampling points are randomly generated in the triangle, so that M surface sampling points are obtained. The position of any surface sampling point and the normal direction of the triangle where the surface sampling point is located can be recorded for subsequent use. The sampling points in the three-dimensional model are formed by voxelizing the three-dimensional model, and then the central points belonging to the three-dimensional model in the central points of each voxel are used as the internal sampling points of the three-dimensional model, so that the positions of the central points can be recorded; wherein, voxelization is obtained by dividing an AABB bounding box where a three-dimensional model is located in three directions of xyz according to a voxel side length L, and in the invention, the voxel can be a cube voxel, and the calculation method of L is as follows: l=sqrt (S/M), where S is the sum of the triangular areas of the triangular mesh of the three-dimensional model, i.e. the surface area of the three-dimensional model, sqrt is a function of the square root.
1.2, iterative optimization is carried out, and sphere set approximation is generated; the method can comprise the following steps:
1. n internal sampling points are randomly selected as seed points.
2. And adding the sampling points closest to the seed point in other sampling points except the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point.
3. Determining a surface sampling point enclosed in a sphere corresponding to the initial set according to coordinates of the sampling point, calculating the distance between the surface sampling point and the surface of the sphere of the enclosed sphere along the normal direction of the triangle to which the surface sampling point belongs for any surface sampling point enclosed in the sphere, and adding the surface sampling point into the initial set corresponding to the sphere with the minimum calculated distance; if the calculated distances are negative numbers, at this time, the balls surrounded by the surface sampling points are all located inside the object (in the directed distance field, the negative value representation is located inside the object), and the sampling points are added into the initial set corresponding to the seed points closest to the sampling points.
4. For other sampling points which are not added to any initial set (including internal sampling points except the seed points and surface sampling points which are not enclosed in any sphere), adding the sampling points to the initial set corresponding to the seed points closest to the sampling points.
5. And (3) continuously repeating the steps (3) and (4) until all the sampling points are divided into a certain initial set to obtain a target set.
6. And calculating the mass centers of the points contained in each target set, and taking the calculated mass centers corresponding to the target sets as new seed points.
7. And (3) repeating the steps 2-6 for the new seed points until the seed points utilized by the target set are generated for any target set, the distances between the seed points and the mass centers of the target set meet the ending condition (less than a certain distance threshold value), the target seed set is obtained, and the sphere set approximation of the three-dimensional model is generated based on the target seed set.
Steps 1 to 7 are similar to the implementation manner of steps S501 to S505, and specific implementation steps thereof are referred to each other, and are not described herein.
The method for calculating the distance between the surface sampling point and the surface of the sphere enclosed by the sphere along the normal direction of the triangle to which the surface sampling point belongs for any surface sampling point enclosed by the sphere comprises the following steps:
p is the normal direction of the triangle in the triangle mesh to which the surface sampling point belongs, and the distance between the surface sampling point and the sphere surface of the sphere represented by an initial set contained in the surface sampling point; r is the radius of a sphere represented by an initial set of the surface sampling points, i.e. the distance between a seed point and a target sampling point (not shown) in an initial set of the surface sampling points; d, d 2 Sampling point to c for the target Is a distance of (2); d, d 1 For c to c Is a distance of (2); c is the center of a sphere represented by an initial set contained in the target sampling point, namely the position of a seed point in the initial set contained in the surface sampling point; c And c, along the normal direction of the triangle in the triangular mesh of the surface sampling point, the projection point of the plane of the triangle in the triangular mesh to which the surface sampling point belongs.
When the center of the circle is forward of the normal direction of the p point (the normal angle between the vector from the p point to the c point and the p point is smaller than 90 degrees, namely dot (cp, n_p) > 0), the calculation method of fig. 6 (a) is adopted, namely, the calculation mode is as follows:
when the center of the circle is behind the normal direction of the p point (the normal angle between the vector from the p point to the c point and the p point is greater than 90 degrees, namely dot (cp, n_p) < 0), the calculation method of fig. 6 (B) is adopted, namely, the calculation mode is as follows:
in addition, for each object in three-dimensional space, a sphere set approximation of 3 LOD (Levels of Detail) Levels may be calculated, the number of spheres in the sphere set approximation of 3 LOD Levels is typically 256, 128 and 64, respectively, and may be increased or decreased in equal proportion to actual demands.
For a three-dimensional model with skeletal animation, the three-dimensional model may be divided into different parts by bone, each of which separately generates a sphere set approximation.
The object approximated by the above-mentioned sphere set is an object in the target area, for example: objects within a certain range in the vicinity of the virtual camera in three-dimensional space.
In the real-time part, the distance field can be built in real time:
2.1 building BVH tree in real time:
in a region within a certain range of the virtual camera, namely the target region, the dynamic object and the static object can be distinguished for the object in the region, corresponding BVH trees can be respectively constructed for the dynamic object and the static object, and if the target region comprises a plurality of hierarchical regions, the BVH trees corresponding to the dynamic object and the static object in the hierarchical region can be respectively constructed for any hierarchical region.
When the BVH tree is built, aiming at the BVH tree corresponding to any level region, the BVH tree corresponding to the object contained in the level region can be built in real time according to Morton codes corresponding to the center coordinates of the object in the level region; specifically, for any object in the hierarchical region, the center coordinates of the object may be determined first, and a morton code corresponding to the center coordinates of the object may be generated, where the morton code corresponding to the center coordinates of the object may be represented, and bounding box information of the object may be stored to a child node in the BVH tree, and the bounding box information of the object may be stored to the child node in the BVH tree based on the morton code corresponding to the center coordinates of the object, so as to generate the BVH tree corresponding to the object included in the hierarchical region; any child node in the BVH tree may store bounding box information of one or more objects, and a manner of constructing the BVH tree by using the morton code may be similar to the prior art, which is not described herein.
The BVH tree of the static in this layer may be updated each time the virtual camera moves beyond the range of the side length L of one grid (i.e. the side length of the square voxel calculated above). For any hierarchy area, namely a Cascade hierarchy, firstly, objects which enter and move out of the Cascade hierarchy newly are collected, if no object which enters newly exists, only the object which moves out of the BVH tree corresponding to the Cascade hierarchy is marked as invalid, and the BVH tree does not need to be reconstructed. If a new object is entered, the BVH tree corresponding to the Cascade hierarchy can be reconstructed according to the new object.
For dynamic objects in the scene, the BVH needs to be reconstructed each time.
The priorities of constructing BVH trees in different Cascade levels are different, BVH trees can be constructed in time for each frame in the 0 th and 1 st levels when needed, the 2 nd level can be constructed once at intervals of 2 frames, and the other is the same, and the BVH trees can be constructed once at intervals of 6 frames at maximum, so that flexible scheduling is convenient under the condition of limited calculation power.
In this embodiment, the manner of constructing the BVH tree according to the morton code corresponds to the above-mentioned determination of the center coordinates of each object included in the hierarchical region, and generates the morton code corresponding to the center coordinates of each object; and storing bounding box information of any object contained in the hierarchical region to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
It should be noted that, in the above manner of constructing a BVH tree according to the morton code, in the case of ensuring that the morton code of each object can characterize leaf nodes in the BVH tree in which bounding box information of the object is to be stored, the construction manner may be similar to that of the prior art, which is not limited by the present invention.
2.2 distance field calculation
A point in a given space (i.e., a target location point in a target area) is first determined in which layer of cascades it is located using the AABB bounding box of the cascades hierarchy, then traversed top-down in the BVH tree of that hierarchy to a leaf node, and the object id stored in that leaf node is retrieved. For each object, a thread group is started, each thread reads one ball in the sphere set approximation of the object, the distance from the point to the ball surface is calculated, the comparison is carried out through atomic operation in the thread group, and the minimum distance is stored. Finally, the minimum distance to each object is integrated again, and the minimum value is obtained and used as the value of the distance field of the point. Corresponding to the target hierarchical region to which the target position point belongs from the plurality of hierarchical regions; and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region. Calculating, for each of the at least one object, a shortest distance between the target location point and the object surface based on a distance relationship of the target location point to spheres comprised by a set of spheres of the object; and determining the minimum value in the calculated shortest distance as a distance field of the target position point.
To simplify the amount of computation, the objects at Cascade level 0 are approximated by the sphere set of LOD 0 (i.e., the number of spheres in the sphere set approximation of the object is 256), the objects at Cascade level 1 are approximated by the sphere set of LOD 1 (i.e., the number of spheres in the sphere set approximation of the object is 128), and the Cascade levels that follow are approximated by the sphere set of LOD 2 (i.e., the number of spheres in the sphere set approximation of the object is 64).
For a dynamic object in a scene, if the dynamic object has no skeletal animation, but only the position and the orientation change, the position of each ball in the sphere set approximation of the object only needs to be correspondingly adjusted, because the balls have rotation invariance. For a dynamic object of a skeleton animation, a corresponding position adjustment needs to be approximately performed on a sphere set corresponding to each skeleton (i.e., a sub-object obtained by dividing the dynamic object according to the skeleton animation).
According to the distance field generation method provided by the embodiment of the invention, the sphere set approximation of the object in the target area can be generated offline in advance, the BVH tree of the target area is built in real time, the Cascade level to which the point belongs can be determined for any point in the target area, the object adjacent to any point is determined in the Cascade level, and the distance field of any point is calculated by utilizing the sphere set approximation of the determined object. According to the distance field generation method provided by the invention, the data volume of the sphere set approximation generated offline is small, the required storage space is small, the BVH tree of the target area can be quickly constructed in a mode of constructing the BVH tree in real time through Morton coding, the object adjacent to the point can be quickly determined, the distance field of any point can be quickly and accurately calculated through the sphere set approximation of the determined object, and the real-time calculation efficiency is high. In addition, the sphere set approximation generated by the invention, the BVH tree constructed by the sphere set approximation support dynamic objects and the dynamic objects with skeleton animation have stronger applicability.
Based on the above method embodiment, the present invention further provides a distance field generating device, as shown in fig. 7, where the device includes:
a first determining module 710, configured to determine a target location point of a distance field to be generated in a target area in the three-dimensional space;
a second determining module 720, configured to determine, from a hierarchical bounding volume BVH tree corresponding to the target area, a target child node corresponding to the target location point; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
a third determining module 730, configured to determine an object represented by bounding box information in the target child node, to obtain at least one object adjacent to the target location point;
a calculating module 740, configured to calculate a distance field of the target location point based on a distance relation between the target location point and a sphere included in the sphere set of the at least one object.
The distance field generating device provided by the embodiment of the invention firstly determines the target position point of the distance field to be generated in the target area in the three-dimensional space, wherein the BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, a target sub-node corresponding to the target position point can be determined from the BVH tree corresponding to the target area, and the object represented by the bounding box information stored in the target sub-node, namely, the object adjacent to the target position point, can determine at least one object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, the sphere set of any object is used for representing the object through sphere approximation, and the distance field of the target position point can be rapidly calculated based on the distance relation between the target position point and the sphere contained in the sphere set of at least one object. It can be seen that, unlike the related art that calculates the distance field of voxels of each object in the three-dimensional space and generates the global distance field, the method provided by the invention is provided with the corresponding BVH tree aiming at the target area, so that the target sub-node corresponding to the target position point can be rapidly determined, and the distance field of the target position point can be simply, conveniently and rapidly obtained by calculating the target position distance field through the sphere set. Therefore, the generation efficiency of the distance field can be improved through the scheme.
Optionally, the hierarchical bounding volume BVH tree corresponding to the target area includes a plurality of BVH trees, each BVH tree has unique correspondence with one of a plurality of hierarchical areas set for the target area, each hierarchical area includes a partial area of the target area, the areas included in the plurality of hierarchical areas form the target area, and bounding box information of each object included in the corresponding hierarchical area is stored in each BVH tree;
the second determining module is specifically configured to:
determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions;
and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region.
Optionally, the computing module includes:
a calculating sub-module, configured to calculate, for each object of the at least one object, a shortest distance between the target location point and a surface of the object based on a distance relationship between the target location point and a sphere included in a sphere set of the object;
and the determining submodule is used for determining the minimum value in the calculated shortest distance as a distance field of the target position point.
Optionally, the computing submodule is specifically configured to:
calculating the shortest distance between the surfaces of each ball in the ball set of the object and the target position point respectively for each object in the at least one object to obtain a plurality of intermediate distances;
and determining the minimum distance in the plurality of intermediate distances as the shortest distance between the target position point and the object surface.
Optionally, the generating manner of the sphere set of any object in the three-dimensional space includes:
determining a plurality of surface sampling points and a plurality of internal sampling points of the object;
selecting a plurality of seed points from the plurality of internal sampling points;
for each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point; wherein the intermediate sampling points include: sampling points except the selected seed points in the internal sampling points and the surface sampling points;
based on the distance relation between each residual sampling point in the intermediate sampling points and the sphere represented by each initial set, each residual sampling point is added into one initial set to obtain a plurality of target sets; the sphere characterized by each initial set takes a seed point in the initial set as a circle center, and takes the distance between the seed point in the initial set and a target sampling point as a radius, so that a sphere is formed;
A set of spheres of the object is generated based on the plurality of target sets.
Optionally, the adding each remaining sampling point to an initial set based on the distance relation between each remaining sampling point in the intermediate sampling points and the sphere represented by each initial set to obtain a plurality of target sets includes:
calculating the normal direction along the triangle in the triangular mesh to which the first sampling point belongs for each first sampling point in the residual sampling points, wherein the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set contained in the first sampling point is calculated, so as to obtain the distance corresponding to at least one initial set contained in the first sampling point; adding the first sampling point into an initial set with the minimum corresponding distance; wherein any first sampling point is a surface sampling point at least contained in a sphere represented by an initial set in each remaining sampling point;
adding the second sampling point into an initial set corresponding to a seed point nearest to the second sampling point aiming at each second sampling point in the residual sampling points; each second sampling point is added to an initial set to obtain a plurality of target sets; wherein any one of the second sampling points is a sampling point of the remaining sampling points except the first sampling points.
Optionally, before generating the sphere set of the object based on the target sets, the method further includes:
calculating the mass centers corresponding to all points in each target set aiming at each target set, taking the calculated mass centers as new seed points, returning to each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into the set corresponding to the seed point to obtain an initial set corresponding to the seed point until each target set is subjected to the steps of generating the seed point utilized by the target set and the distance between the mass centers corresponding to all points in the target set, and obtaining a plurality of target seed sets;
the generating a sphere set of the object based on the plurality of target sets includes:
a set of spheres of the object is generated based on the plurality of target seed sets.
Optionally, the number of the plurality of surface sampling points is a first number, and the determining manner of the plurality of surface sampling points includes:
aiming at triangles in any triangular mesh of the object surface, calculating the target number of surface sampling points to be generated in the triangles according to the first number, and randomly generating initial surface sampling points of the target number in the triangles;
Determining and obtaining a plurality of surface sampling points based on initial surface sampling points generated in triangles in each triangular grid of the object surface;
the number of the plurality of internal sampling points is a second number, and the determining manner of the plurality of internal sampling points includes:
calculating target side lengths of cube voxels to be split according to the sum of areas of the triangles and the second quantity aiming at the triangles in each triangular grid of the object surface;
dividing the object into cube voxels according to the target side length, and taking the center points belonging to the object among the center points of the cube voxels as the plurality of internal sampling points.
Optionally, the construction method of the BVH tree corresponding to any hierarchical region includes:
determining the central coordinates of all objects contained in the hierarchical region, and generating Morton codes corresponding to the central coordinates of all objects;
and storing bounding box information of any object contained in the hierarchical region to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, so as to obtain the BVH tree corresponding to the hierarchical region.
Optionally, the BVH tree corresponding to any hierarchical region includes: a first BVH tree for storing bounding box information about static objects and/or a second BVH tree for storing bounding box information about dynamic objects;
Further comprises:
when the target area changes, aiming at a first BVH tree corresponding to any hierarchical area, if the hierarchical area has a removed static object, invalidating bounding box information about the removed static object stored in the first BVH tree; if the hierarchy area has a newly added static object, reconstructing the first BVH tree according to the newly added static object;
and reconstructing a second BVH tree corresponding to any hierarchical region after the target region is changed.
The embodiment of the present invention further provides an electronic device, as shown in fig. 8, including a processor 801, a communication interface 802, a memory 803, and a communication bus 804, where the processor 801, the communication interface 802, and the memory 803 complete communication with each other through the communication bus 804,
a memory 803 for storing a computer program;
the processor 801 is configured to implement any one of the distance field generating methods when executing the program stored in the memory 803.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In a further embodiment of the present invention, a computer readable storage medium is also provided, in which a computer program is stored, which computer program, when being executed by a processor, implements the steps of any of the distance field generating methods described above.
In a further embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the distance field generating methods of the above embodiments.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus 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 apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments in part.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. A distance field generation method, the method comprising:
determining target position points of a distance field to be generated in a target area in a three-dimensional space;
determining a target child node corresponding to the target position point from a hierarchical bounding volume BVH tree corresponding to the target region; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
determining an object characterized by bounding box information in the target child node to obtain at least one object adjacent to the target position point;
a distance field of the target location point is calculated based on a distance relationship of the target location point to spheres comprised by a set of spheres of the at least one object.
2. The method according to claim 1, wherein the hierarchical bounding volume BVH tree corresponding to the target area includes a plurality of BVH trees, each BVH tree having unique correspondence with one of a plurality of hierarchical areas set for the target area, each hierarchical area including a partial area of the target area, the areas included in the plurality of hierarchical areas constituting the target area, and bounding box information of each object included in the corresponding hierarchical area is stored in each BVH tree;
the determining the target sub-node corresponding to the target location point from the hierarchical bounding volume BVH tree corresponding to the target area includes:
determining a target hierarchical region to which the target location point belongs from the plurality of hierarchical regions;
and determining a target child node corresponding to the target position point from the BVH tree corresponding to the target hierarchical region.
3. The method according to claim 1 or 2, wherein said calculating a distance field of the target location point based on a distance relation of the target location point to spheres comprised by a set of spheres of the at least one object comprises:
calculating, for each of the at least one object, a shortest distance between the target location point and the object surface based on a distance relationship of the target location point to spheres comprised by a set of spheres of the object;
Determining a minimum value of the calculated shortest distances as a distance field of the target position point;
the calculating, for each of the at least one object, a shortest distance between the target location point and a surface of the object based on a distance relationship between the target location point and a sphere contained in a sphere set of the object, including:
calculating the shortest distance between the surfaces of each ball in the ball set of the object and the target position point respectively for each object in the at least one object to obtain a plurality of intermediate distances;
and determining the minimum distance in the plurality of intermediate distances as the shortest distance between the target position point and the object surface.
4. A method according to any one of claims 1-3, wherein the generation of the set of spheres for any object in the three-dimensional space comprises:
determining a plurality of surface sampling points and a plurality of internal sampling points of the object;
selecting a plurality of seed points from the plurality of internal sampling points;
for each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into a set corresponding to the seed point to obtain an initial set corresponding to the seed point; wherein the intermediate sampling points include: sampling points except the selected seed points in the internal sampling points and the surface sampling points;
Based on the distance relation between each residual sampling point in the intermediate sampling points and the sphere represented by each initial set, each residual sampling point is added into one initial set to obtain a plurality of target sets; the sphere characterized by each initial set takes a seed point in the initial set as a circle center, and takes the distance between the seed point in the initial set and a target sampling point as a radius, so that a sphere is formed;
a set of spheres of the object is generated based on the plurality of target sets.
5. The method of claim 4, wherein adding each remaining sample point to an initial set based on a distance relationship between each remaining sample point in the intermediate sample points and a sphere characterized by each initial set, respectively, to obtain a plurality of target sets, comprises:
calculating the normal direction along the triangle in the triangular mesh to which the first sampling point belongs for each first sampling point in the residual sampling points, wherein the distance between the first sampling point and the sphere surface of the sphere represented by at least one initial set contained in the first sampling point is calculated, so as to obtain the distance corresponding to at least one initial set contained in the first sampling point; adding the first sampling point into an initial set with the minimum corresponding distance; wherein any first sampling point is a surface sampling point at least contained in a sphere represented by an initial set in each remaining sampling point;
Adding the second sampling point into an initial set corresponding to a seed point nearest to the second sampling point aiming at each second sampling point in the residual sampling points; each second sampling point is added to an initial set to obtain a plurality of target sets; wherein any one of the second sampling points is a sampling point of the remaining sampling points except the first sampling points.
6. The method of claim 4 or 5, wherein prior to generating the set of spheres for the object based on the plurality of target sets, the method further comprises:
calculating the mass centers corresponding to all points in each target set aiming at each target set, taking the calculated mass centers as new seed points, returning to each seed point, adding a target sampling point closest to the seed point in the middle sampling points and the seed point into the set corresponding to the seed point to obtain an initial set corresponding to the seed point until each target set is subjected to the steps of generating the seed point utilized by the target set and the distance between the mass centers corresponding to all points in the target set, and obtaining a plurality of target seed sets;
The generating a sphere set of the object based on the plurality of target sets includes:
a set of spheres of the object is generated based on the plurality of target seed sets.
7. The method of claim 4, wherein the number of the plurality of surface sampling points is a first number, and wherein the determining the plurality of surface sampling points comprises:
aiming at triangles in any triangular mesh of the object surface, calculating the target number of surface sampling points to be generated in the triangles according to the first number, and randomly generating initial surface sampling points of the target number in the triangles;
determining and obtaining a plurality of surface sampling points based on initial surface sampling points generated in triangles in each triangular grid of the object surface;
the number of the plurality of internal sampling points is a second number, and the determining manner of the plurality of internal sampling points includes:
calculating target side lengths of cube voxels to be split according to the sum of areas of the triangles and the second quantity aiming at the triangles in each triangular grid of the object surface;
dividing the object into cube voxels according to the target side length, and taking the center points belonging to the object among the center points of the cube voxels as the plurality of internal sampling points.
8. The method according to claim 2, wherein the construction method of the BVH tree corresponding to any hierarchical region includes:
determining the central coordinates of all objects contained in the hierarchical region, and generating Morton codes corresponding to the central coordinates of all objects;
for any object contained in the hierarchical region, storing bounding box information of the object to child nodes in the BVH tree characterized by Morton codes corresponding to the center coordinates of the object, and obtaining the BVH tree corresponding to the hierarchical region;
the BVH tree corresponding to any hierarchical region comprises: a first BVH tree for storing bounding box information about static objects and/or a second BVH tree for storing bounding box information about dynamic objects;
the method further comprises the steps of:
when the target area changes, aiming at a first BVH tree corresponding to any hierarchical area, if the hierarchical area has a removed static object, invalidating bounding box information about the removed static object stored in the first BVH tree; if the hierarchy area has a newly added static object, reconstructing the first BVH tree according to the newly added static object;
And reconstructing a second BVH tree corresponding to any hierarchical region after the target region is changed.
9. A distance field generating device, the device comprising:
the first determining module is used for determining target position points of a distance field to be generated in a target area in the three-dimensional space;
the second determining module is used for determining a target child node corresponding to the target position point from the hierarchical bounding volume BVH tree corresponding to the target region; the hierarchical bounding volume BVH tree corresponding to the target area stores bounding box information of each object contained in the target area, and the object represented by the bounding box information stored in the target child node is an object adjacent to the target position point; any object contained in the target area is provided with a corresponding sphere set, and the sphere set of any object is used for representing the object through sphere approximation;
a third determining module, configured to determine an object represented by bounding box information in the target child node, to obtain at least one object adjacent to the target location point;
and the calculating module is used for calculating the distance field of the target position point based on the distance relation between the target position point and the sphere contained in the sphere set of the at least one object.
10. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for carrying out the method steps of any one of claims 1-8 when executing a program stored on a memory.
CN202311250350.9A 2023-09-25 2023-09-25 Distance field generation method and device, electronic equipment and storage medium Pending CN117152237A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311250350.9A CN117152237A (en) 2023-09-25 2023-09-25 Distance field generation method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311250350.9A CN117152237A (en) 2023-09-25 2023-09-25 Distance field generation method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117152237A true CN117152237A (en) 2023-12-01

Family

ID=88886914

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311250350.9A Pending CN117152237A (en) 2023-09-25 2023-09-25 Distance field generation method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117152237A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117893670A (en) * 2024-01-15 2024-04-16 联想新视界(北京)科技有限公司 Real-time global illumination rendering method and device and electronic equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117893670A (en) * 2024-01-15 2024-04-16 联想新视界(北京)科技有限公司 Real-time global illumination rendering method and device and electronic equipment

Similar Documents

Publication Publication Date Title
JP7389846B2 (en) Hierarchy fusion
US7499053B2 (en) Real-time precision ray tracing
US7773087B2 (en) Dynamically configuring and selecting multiple ray tracing intersection methods
US7002571B2 (en) Grid-based loose octree for spatial partitioning
CN108520557B (en) Massive building drawing method with graphic and image fusion
CN112669463B (en) Method for reconstructing curved surface of three-dimensional point cloud, computer device and computer-readable storage medium
CN112347546A (en) BIM rendering method, device and computer-readable storage medium based on lightweight device
EP3940649A1 (en) Methods and systems for constructing ray tracing acceleration structures
WO2023124676A1 (en) 3d model construction method, apparatus, and electronic device
CN117152237A (en) Distance field generation method and device, electronic equipment and storage medium
US8102389B2 (en) Box casting using an integrated acceleration data structure
CN116958379A (en) Image rendering method, device, electronic equipment, storage medium and program product
CN115578536A (en) Node merging method and device for layered and partitioned three-dimensional model and electronic device
CN113593043A (en) Point cloud three-dimensional reconstruction method and system based on generation countermeasure network
CN115984440B (en) Object rendering method, device, computer equipment and storage medium
CN116740255A (en) Rendering processing method, device, equipment and medium
CN115115773B (en) Collision detection method, device, equipment and storage medium
CN117808949B (en) Scene rendering method
CN116824082B (en) Virtual terrain rendering method, device, equipment, storage medium and program product
CN117390775B (en) Viscous Cartesian grid generation method, viscous Cartesian grid generation equipment, viscous Cartesian grid medium and viscous Cartesian grid generation system
CN115576424B (en) Method for enhancing real-time performance of VR teaching interactive operation
EP3940650A1 (en) Methods and systems for constructing ray tracing acceleration structures
CN117876572A (en) Illumination rendering method, device, equipment and storage medium
CN117982891A (en) Path generation method and device in virtual scene, electronic equipment and storage medium
CN115115773A (en) Collision detection method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination