Triangle face picking method, device, electronic device and computer readable medium
By counting and expanding the triangular surface index array, and using the interpolation and positioning methods of pixel shaders and vertex shaders, the problem of low triangular surface picking efficiency in three-dimensional scenes is solved, and a more efficient triangular surface picking process is achieved.
Patent Information
- Application Number
- CN201810681142.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-06-27
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2038-06-27
AI Technical Summary
In the existing technology, the number of triangular faces in a three-dimensional scene is huge, which results in inefficiency in finding intersection points through the intersection of rays and triangular faces, and the picking efficiency is not high.
By counting the triangular surface index arrays where the vertices of the model are located, all index arrays are expanded to the same number of elements, and the pixel shader is used for interpolation. The vertex shader reversely locates the triangular surface index value to avoid additional search processes.
The efficiency of triangular surface picking is improved. The interpolation process is completed through hardware, which reduces the additional search process and improves the picking efficiency.
Smart Images

Figure CN110648385B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of Internet technology, and in particular, to a triangular face picking method, device, electronic device and computer-readable medium. Background Art
[0002] The three-dimensional scene is composed of models, and the models are composed of triangular faces. Therefore, the precise selection of the model is to form a ray through the back-projection point of the virtual camera and the screen click coordinates. The ray intersects with a triangular face of the model to form an intersection, thereby obtaining the selection result.
[0003] However, the number of triangles in a three-dimensional scene is usually very large, possibly in the order of millions. The most direct way to traverse all triangles and find the intersection points by intersecting rays with the triangles is very time-consuming and will result in low picking efficiency.
[0004] Therefore, the technical solutions in the prior art still need to be improved.
[0005] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention
[0006] The present disclosure provides a triangular face picking method, device, electronic device and computer-readable medium to solve the above-mentioned technical problems.
[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0008] According to one aspect of the present disclosure, a triangular face picking method is provided, comprising:
[0009] Counting the triangular faces where the vertices are stored in the vertices constituting the model, and obtaining a triangular face index array corresponding to the vertices;
[0010] Expand the number of elements in the triangle face index array corresponding to all vertices to the same number of elements;
[0011] Get the index value of the triangle where the pixel point is located;
[0012] The pixel shader interpolates the triangle surface index array where the pixel point is located to obtain an interpolation result;
[0013] The vertex shader locates the index value of the triangle surface according to the interpolation result to obtain the corresponding target triangle surface.
[0014] In one embodiment of the present disclosure, statistics are performed on the triangular faces where the vertices stored in the vertices constituting the model are located, and the triangular face index array corresponding to the vertices is obtained, including:
[0015] The model includes n vertices, wherein every three vertices of the n vertices form a triangular face;
[0016] The elements of the triangle surface index array are formed according to the index value of the triangle surface where the vertex is located, and the triangle surface index array corresponding to the vertex is obtained.
[0017] In one embodiment of the present disclosure, expanding the number of elements in the triangle face index array corresponding to all vertices to the same number includes:
[0018] Obtain the maximum number of elements in the triangle face index array corresponding to all vertices;
[0019] The triangle surface index arrays whose number of elements does not reach the maximum number of elements are expanded so that the number of elements of all the triangle surface index arrays is the same.
[0020] In one embodiment of the present disclosure, expanding a triangle face index array whose number of elements does not reach the maximum number of elements includes:
[0021] For positions where the number of elements is less than the maximum number of elements, the preset value is used to fill them;
[0022] The expanded triangle surface index array includes the valid elements that originally constitute the triangle surface index array and the filled supplementary elements.
[0023] In one embodiment of the present disclosure, obtaining the index value of the triangle surface where the pixel point is located includes:
[0024] Sorting and exchanging the elements in the triangle index array having the same number of elements;
[0025] The triangle index value where the pixel point is located is determined by the fact that the values of the triangle index array under the same subscript are the same.
[0026] In one embodiment of the present disclosure, sorting and exchanging elements in the triangle face index arrays having the same number of elements includes:
[0027] Starting from the first vertex of the n vertices, the elements in the triangle face index array corresponding to the first vertex are traversed one by one in the order of increasing array subscripts;
[0028] If the element in the triangle index array is the preset value, skip traversing the subsequent elements until all elements in the triangle index array are traversed;
[0029] When an element in the triangle surface index array is a valid element, searching for an element having the same value as the valid element from the triangle surface index array corresponding to the subsequent vertex;
[0030] If the subscript of the found element is different from the subscript of the valid element, the element is exchanged with the element at the adjacent position so that the values of the triangle index array under the same subscript are the same.
[0031] In one embodiment of the present disclosure, the vertex shader locates the index value of the triangle according to the interpolation result, and obtains the corresponding target triangle including:
[0032] Passing the vertex number into the triangle face index array corresponding to the vertex;
[0033] A triangular face whose index value in the triangular face index array is a positive integer is selected according to the interpolation result to obtain the target triangular face.
[0034] According to another aspect of the present disclosure, there is provided a triangular face picking device, comprising:
[0035] A statistical module is configured to count the triangular faces where the vertices are located and stored in the vertices constituting the model, and obtain an index array of the triangular faces corresponding to the vertices;
[0036] An expansion module is configured to expand the number of elements in the triangle surface index array corresponding to all vertices to the same number of elements;
[0037] A pixel acquisition module is configured to obtain the index value of the triangle surface where the pixel point is located;
[0038] An interpolation module is configured as a pixel shader to interpolate the triangle surface index array where the pixel point is located to obtain an interpolation result;
[0039] The picking module is configured as a vertex shader, and locates the index value of the triangle surface according to the interpolation result to obtain the corresponding target triangle surface.
[0040] According to yet another aspect of the present disclosure, an electronic device is provided, comprising a processor; and a memory storing instructions for the processor to control the method steps as described above.
[0041] According to another aspect of the present disclosure, a computer-readable medium is provided, on which computer-executable instructions are stored. When the executable instructions are executed by a processor, the method steps described above are implemented.
[0042] According to the triangle picking method, device, electronic device and computer-readable medium provided by the embodiments of the present disclosure, the triangle index value is located from the vertex shader in reverse based on the interpolation result of the pixel shader. Since the interpolation process of the pixel shader is completed by hardware, the additional search process can be avoided, thereby improving the picking efficiency.
[0043] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The above and other objects, features and advantages of the present disclosure will become more apparent by describing in detail example embodiments thereof with reference to the attached drawings.
[0045] Figure 1 A flowchart of a triangular face picking method provided in one embodiment of the present disclosure is shown.
[0046] Figure 2 A flowchart showing specific processing steps of a triangular face picking method in one embodiment of the present disclosure is shown.
[0047] Figure 3 A schematic diagram showing a device for determining a target point provided by another embodiment of the present disclosure is shown.
[0048] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure and suitable for implementing the embodiment of the present application is shown. DETAILED DESCRIPTION
[0049] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the present disclosure will be more comprehensive and complete and fully convey the concepts of the example embodiments to those skilled in the art. The accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0050] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0051] Some of the blocks shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0052] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings.
[0053] In the relevant embodiments of the present disclosure, an octree is used to recursively divide the scene space according to three coordinate axes, and the model can be conveniently found according to the size of the bounding box of the model. Although this method can find the model node relatively quickly, it still needs to traverse a large number of triangular faces inside the model for picking, which still has a relatively large impact on efficiency, that is, the picking efficiency still cannot be improved.
[0054] Figure 1 A flowchart of a triangular face picking method provided in an embodiment of the present disclosure is shown, comprising the following steps:
[0055] like Figure 1 As shown, in step S110, the triangular faces where the vertices stored in the vertices constituting the model are located are counted to obtain a triangular face index array corresponding to the vertices.
[0056] like Figure 1 As shown, in step S120, the number of elements in the triangle surface index array corresponding to all vertices is expanded to the same number of elements.
[0057] like Figure 1 As shown, in step S130, the index value of the triangle surface where the pixel point is located is obtained.
[0058] like Figure 1 As shown, in step S140, the pixel shader interpolates the triangle surface index array where the pixel point is located to obtain an interpolation result.
[0059] like Figure 1 As shown, in step S150, the vertex shader locates the index value of the triangle surface according to the interpolation result to obtain the corresponding target triangle surface.
[0060] The triangle picking method provided by the embodiment of the present disclosure locates the triangle index value from the vertex shader in reverse according to the interpolation result of the pixel shader. Since the interpolation process of the pixel shader is completed by hardware, the additional search process can be avoided, thereby improving the picking efficiency.
[0061] The following combination Figure 1The flowchart shown in the figure introduces the triangular face picking method provided by the present disclosure in detail, as follows:
[0062] In step S110, the triangular faces where the vertices are stored in the vertices constituting the model are counted to obtain a triangular face index array corresponding to the vertices.
[0063] In one embodiment of the present disclosure, the model includes n vertices, wherein every three vertices among the n vertices constitute a triangular face, and the elements of the triangular face index array can be constructed according to the index values of the triangular faces where the vertices are located, thereby obtaining the triangular face index array corresponding to the vertices.
[0064] Assume that there are n vertices p1, p2, p3, ..., pn in the model. A vertex is a structure that stores point information in space, including the coordinates of the point, the normal of the point, the texture coordinates of the point, and so on. Multiple vertices can form polygons, and polygons further form the entire model. In this embodiment, the polygons that constitute the model are introduced by taking triangles as an example. Every three vertices form a triangle. Assume that there are m triangles, t1, t2, t3, ..., tm. The triangle where the vertex is located is stored in each vertex. Since there are multiple triangles sharing a vertex, for each vertex, the index value of the triangle where the vertex is located is stored in the array tr. For example, the triangle index array tr1 = {1, 2, 3, 4}, tr1 represents the triangle index array corresponding to the first vertex p1, where tr1 = {1, 2, 3, 4} means that the triangles with index values 1, 2, 3 and 4 all use vertex p1.
[0065] In step S120, the number of elements in the triangle surface index array corresponding to all vertices is expanded to the same number of elements.
[0066] In one embodiment of the present disclosure, step S120 first obtains the maximum number of elements in the triangle index array corresponding to all vertices; then expands the triangle index array whose number of elements does not reach the maximum number of elements, so that the number of elements of all the triangle index arrays is the same.
[0067] When the triangle index array is expanded, it can be expanded in the following way:
[0068] Positions where the number of elements is less than the maximum number of elements are filled with preset values, wherein the expanded triangle surface index array includes the valid elements that originally constitute the triangle surface index array and the filled supplementary elements.
[0069] For example, since the number of arrays corresponds to the number of vertices, there are n triangle index arrays, namely arrays tr1, tr2, tr3, ..., trn. Because the vertices are shared by triangles in different situations, the number of elements in these arrays is also different. In this step, it is necessary to find the maximum number of elements in all triangle index arrays tr, recorded as MAX_LEN; then expand the number of elements in all tr arrays to MAX_LEN. The specific expansion rule is: add some very large values, such as the largest floating-point value, to the back of the original valid elements, which is simply recorded as MAX_NUM. Taking two arrays as an example, the first array has 6 elements and the second array has 4 elements. Then, the second array needs to be expanded from 4 elements to 6 elements, that is, the two supplementary elements after the original 4 valid elements in the second array are both MAX_NUM.
[0070] In step S130, the index value of the triangle surface where the pixel point is located is obtained.
[0071] In one embodiment of the present disclosure, step S130 sorts and exchanges the elements in the triangle index array having the same number of elements; and determines the triangle index value where the pixel point is located by the same value of the triangle index array under the same subscript.
[0072] The elements in the triangle index array with the same number of elements may be sorted and exchanged in the following manner:
[0073] Starting from the first vertex of the n vertices, the elements in the triangle face index array corresponding to the first vertex are traversed one by one in the order of increasing array subscripts;
[0074] If the element in the triangle index array is the preset value, skip traversing the subsequent elements until all elements in the triangle index array are traversed;
[0075] When an element in the triangle surface index array is a valid element, searching for an element having the same value as the valid element from the triangle surface index array corresponding to the subsequent vertex;
[0076] If the subscript of the found element is different from the subscript of the valid element, the element is exchanged with the element at the adjacent position so that the values of the triangle index array under the same subscript are the same.
[0077] In step S140, the pixel shader interpolates the triangle index array where the pixel point is located to obtain an interpolation result. Since the interpolation process of the pixel shader is completed by hardware and no additional process is introduced, the impact on efficiency is small.
[0078] In step S150, the vertex shader locates the index value of the triangle surface according to the interpolation result to obtain the corresponding target triangle surface.
[0079] In one embodiment of the present disclosure, step S150 first passes the vertex number into the triangle face index array corresponding to the vertex; then selects the triangle face whose index value in the triangle face index array is a positive integer according to the interpolation result to obtain the target triangle face.
[0080] Based on the above, combined Figure 2 The flowchart of the specific processing steps of the triangular face picking method shown in the figure introduces the triangular face picking method summarized in the embodiment of the present disclosure in detail:
[0081] like Figure 2 As shown, in step S201, the vertices and triangular faces constituting the model are counted.
[0082] The vertices include p1, p2, p3, ..., pn, a total of n vertices, and the constructed triangular faces include t1, t2, t3, ..., tm. The triangular face index arrays corresponding to each vertex are tr1, tr2, tr3, ..., trn respectively.
[0083] like Figure 2 As shown, in step S202, the maximum number of elements in the triangle index array is found, recorded as MAX_LEN, and the number of elements in all triangle index arrays is expanded to MAX_LEN elements.
[0084] like Figure 2 As shown, in step S203, starting from the first vertex p1, the elements in the corresponding triangle index array tr1 perform the operation of the following step S204 in sequence. If MAX_NUM appears in an element in tr1, it is skipped and the operation of subsequent elements of tr1 is continued until all elements in tr1 are traversed.
[0085] like Figure 2 As shown, in step S204, the elements in the triangle face index array having the same number of elements are sorted and exchanged.
[0086] For vertex pi (i ranges from 1 to n), the corresponding triangle face array tri[MAX_LEN], for the kth element therein, is recorded as tri[k]=t, that is, the triangle face whose index is t where the vertex pi is located.
[0087] Search the triangle array trj[MAX_LEN] in the subsequent vertex pj (j from i+1 to n), and search for the case where the element value in trj[MAX_LEN] is t. If found, assume that trj[s] = t. If trj[s] has been adjusted (that is, the original element of trj[s] is no longer in this position, and the adjustment rule is to repeat the process of steps S203 to S204), then exchange tri[k] and its subsequent elements, and then start step S204 from the next element (that is, for the next element, restart according to the rule of step S204), otherwise exchange the sth element and the kth element in trj so that trj[k] = t; if not found, then continue to search for the next vertex until all nodes are traversed.
[0088] For example:
[0089] Adjust the elements at some positions of the first two adjacent arrays to:
[0090] Tri[i]
[0091] x
[0092] Tri[i+1]
[0093] z x
[0094] After adjustment, the elements at some positions of the two adjacent arrays are:
[0095] Tri[i]
[0096] x
[0097] Tri[i+1]
[0098] x z
[0099] like Figure 2 As shown, in step S205, the triangle index value where the pixel point is located is determined by the fact that the values of the triangle index array under the same subscript are the same.
[0100] Repeat the process of step S203 to step S204 until all are traversed. The final result is that for all tra (a ranges from 1 to n), the value of each column j (j ranges from 1 to MAX_LEN) element tri[j] is either MAX_NUM or a value t (t ranges from 1 to m), and if it is t, then there must be and only two other arrays trb and trc (where b ranges from 1 to n, and c ranges from 1 to n), such that tra[j] = trb[j] = t, that is, the corresponding vertices pa, pb, pc are on the same triangle face, and the index of the triangle face is t. Since the above steps are completed offline, although they are relatively complicated, they do not affect the rendering efficiency, and for this model, these data no longer change.
[0101] like Figure 2 As shown, in step S206, the vertex shader passes the array tri to each vertex i. The vertex shader is used to process the transformation and lighting information of each vertex.
[0102] like Figure 2 As shown, in step S207, the pixel shader interpolates the triangle index array where the pixel point is located, wherein the pixel shader is used to process each pixel, such as setting texture coordinates, attached texel colors, color mixing, and the like.
[0103] The data of each pixel is the interpolation of the vertex data of the triangle where it is located. Assuming that the index of the triangle where the pixel point x is located is t, there are three vertices pa, pb, pc (a, b, c from 1 to n), so that each element in the array trx used by the pixel point is interpolated from tra, trb and trc. According to the above steps, each element in tra, trb and trc is either the interpolation of the same index t (the interpolation of three identical values is still t), or there is at least one MAX_LEN interpolated with the elements in the other two arrays, and the result is also very large. Compared with t (t from 1 to m), we also record it as MAX_LEN, that is, the elements in trx are either t or MAX_LEN, and there is only one triangle corresponding to the pixel x (or in extreme cases on the edge or vertex of the triangle, there are multiple, any one can be taken), so find the index with a positive integer value in trx, and the corresponding triangle is the triangle where the pixel is located.
[0104] like Figure 2 As shown, in step S208, triangular faces are selected.
[0105] For example, you can get the current pixel based on the selected screen coordinates, pass it into the pixel shader, find the positive integer index in the tr array below the pixel, and the corresponding triangle face is the selected triangle face.
[0106] Step S208 can be further optimized by combining the node index (the node index can be obtained by recording the order of each node when the model is generated) + the triangle face index to form a hash value, unifying the original triangle face index, so that the corresponding nodes and triangle faces can be selected in the current drawing scene.
[0107] Based on the above steps, since the interpolation process of the pixel shader is completed by hardware and no additional process is introduced, the impact on efficiency is small and the picking time is not increased.
[0108] In summary, the triangle picking method provided by the embodiment of the present disclosure selects a suitable sorting algorithm before rendering to ensure that the triangle index array stored in the vertex has the same index under the same subscript. During the rendering stage, the vertex shader traverses all nodes for rendering, and the pixel is picked by the mouse, and the index in the vertex shader is reversely found according to the pixel shader, avoiding additional search processes, thereby improving efficiency.
[0109] Figure 3 A schematic diagram of a triangular face picking device provided by another embodiment of the present disclosure is shown as follows: Figure 3 As shown, the device 300 includes: a statistics module 310, an expansion module 320, a pixel acquisition module 330, an interpolation module 340 and a picking module 350.
[0110] The statistics module 310 is configured to count the triangular faces where the vertices stored in the vertices constituting the model are located, and obtain the triangular face index array corresponding to the vertices; the expansion module 320 is configured to expand the number of elements in the triangular face index array corresponding to all vertices to the same number of elements; the pixel acquisition module 330 is configured to obtain the triangular face index value where the pixel point is located; the interpolation module 340 is configured as a pixel shader to interpolate the triangular face index array where the pixel point is located, and obtain the interpolation result; the picking module 350 is configured as a vertex shader to locate the index value of the triangular face according to the interpolation result, and obtain the corresponding target triangular face.
[0111] The functions of each module in the device refer to the relevant description in the above method embodiment, which will not be repeated here.
[0112] On the other hand, the present disclosure further provides an electronic device, including a processor and a memory, wherein the memory stores an operation instruction for the processor to control the following method:
[0113] The triangular faces where the vertices stored in the vertices constituting the model are located are counted to obtain the triangular face index array corresponding to the vertices; the number of elements in the triangular face index array corresponding to all vertices is expanded to the same number of elements; the triangular face index value where the pixel point is located is obtained; the pixel shader interpolates the triangular face index array where the pixel point is located to obtain the interpolation result; the vertex shader locates the triangular face index value according to the interpolation result to obtain the corresponding target triangular face.
[0114] Reference below Figure 4 , which shows a schematic diagram of the structure of a computer system 400 suitable for implementing an electronic device of an embodiment of the present application. Figure 4 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0115] like Figure 4 As shown, the computer system 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 407 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the system 400 are also stored. The CPU 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0116] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.
[0117] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 409, and / or installed from a removable medium 411. When the computer program is executed by a central processing unit (CPU) 401, the above-mentioned functions defined in the system of the present application are executed.
[0118] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable medium or any combination of the above two. The computer-readable medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable medium that can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0119] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0120] The units involved in the embodiments described in the present application may be implemented by software or by hardware. The described units may also be provided in a processor, for example, may be described as: a processor including a sending unit, an acquisition unit, a determination unit, and a first processing unit. Among them, the names of these units do not constitute a limitation on the units themselves in certain circumstances, for example, the sending unit may also be described as a "unit that sends a picture acquisition request to the connected server".
[0121] On the other hand, the present disclosure also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes the following method steps:
[0122] The triangular faces where the vertices stored in the vertices constituting the model are located are counted to obtain the triangular face index array corresponding to the vertices; the number of elements in the triangular face index array corresponding to all vertices is expanded to the same number of elements; the triangular face index value where the pixel point is located is obtained; the pixel shader interpolates the triangular face index array where the pixel point is located to obtain the interpolation result; the vertex shader locates the triangular face index value according to the interpolation result to obtain the corresponding target triangular face.
[0123] It should be clearly understood that the present disclosure describes how to form and use specific examples, but the principles of the present disclosure are not limited to any details of these examples. On the contrary, based on the teachings of the contents disclosed in the present disclosure, these principles can be applied to many other embodiments.
[0124] The exemplary embodiments of the present disclosure are specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present disclosure is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.
Claims
1. A triangular face picking method, characterized in that: include: Counting the triangular faces where the vertices stored in the vertices constituting the model are located, and obtaining a triangular face index array corresponding to the vertex, wherein the triangular face index array corresponding to the vertex is constructed according to the index values of the triangular faces where the vertex is located, and one triangular face index value is used to index one triangular face; Expand the number of elements in the triangle face index array corresponding to all vertices to the same number of elements; Get the index value of the triangle where the pixel point is located; The pixel shader interpolates the triangle surface index array where the pixel point is located to obtain an interpolation result; The vertex shader locates the index value of the triangle surface according to the interpolation result to obtain the corresponding target triangle surface; Among them, obtaining the index value of the triangle where the pixel point is located includes: Sorting and exchanging the elements in the triangle index array having the same number of elements; The triangle index value where the pixel point is located is determined by the fact that the values of the triangle index array under the same subscript are the same.
2. The triangular face picking method according to claim 1, characterized in that: The triangular faces where the vertices are stored in the vertices constituting the model are counted to obtain the triangular face index array corresponding to the vertices, including: The model includes n vertices, wherein every three vertices of the n vertices form a triangular face; The elements of the triangle surface index array are formed according to the index value of the triangle surface where the vertex is located, and the triangle surface index array corresponding to the vertex is obtained.
3. The triangular face picking method according to claim 1, characterized in that: Expanding the number of elements in the triangle face index array corresponding to all vertices to the same number includes: Obtain the maximum number of elements in the triangle face index array corresponding to all vertices; The triangle surface index arrays whose number of elements does not reach the maximum number of elements are expanded so that the number of elements of all the triangle surface index arrays is the same.
4. The triangular face picking method according to claim 3, characterized in that: Expanding the triangle face index array whose number of elements does not reach the maximum number of elements includes: For positions where the number of elements is less than the maximum number of elements, the preset value is used to fill them; The expanded triangle surface index array includes the valid elements that originally constitute the triangle surface index array and the filled supplementary elements.
5. The triangular face picking method according to claim 4, characterized in that: Sorting and exchanging the elements in the triangle index array having the same number of elements includes: For n vertices, starting from the first vertex, traverse the elements in the triangle face index array corresponding to the first vertex one by one in the order of increasing array subscripts; If the element in the triangle index array is the preset value, skip traversing the subsequent elements until all elements in the triangle index array are traversed; When an element in the triangle surface index array is a valid element, searching for an element having the same value as the valid element from the triangle surface index array corresponding to the subsequent vertex; If the subscript of the found element is different from the subscript of the valid element, the element is exchanged with the element at the adjacent position so that the values of the triangle index array under the same subscript are the same.
6. The triangular face picking method according to claim 1, characterized in that: The vertex shader locates the index value of the triangle according to the interpolation result, and obtains the corresponding target triangle including: Passing the vertex number into the triangle face index array corresponding to the vertex; A triangular face whose index value in the triangular face index array is a positive integer is selected according to the interpolation result to obtain the target triangular face.
7. A triangular face picking device, characterized in that: include: A statistics module is configured to count the triangular faces where the vertices are located stored in the vertices constituting the model, and obtain a triangular face index array corresponding to the vertex, wherein the triangular face index array corresponding to the vertex is constructed according to the index value of the triangular face where the vertex is located, and one triangular face index value is used to index one triangular face; An expansion module is configured to expand the number of elements in the triangle surface index array corresponding to all vertices to the same number of elements; A pixel acquisition module is configured to obtain the index value of the triangle surface where the pixel point is located; An interpolation module is configured as a pixel shader to interpolate the triangle surface index array where the pixel point is located to obtain an interpolation result; A picking module is configured as a vertex shader, which locates the index value of the triangle according to the interpolation result to obtain the corresponding target triangle; Among them, obtaining the index value of the triangle where the pixel point is located includes: Sorting and exchanging the elements in the triangle index array having the same number of elements; The triangle index value where the pixel point is located is determined by the fact that the values of the triangle index array under the same subscript are the same.
8. An electronic device, characterized in that: include: processor; A memory storing the method steps for the processor to control according to any one of claims 1 to 6.
9. A computer-readable medium having computer-executable instructions stored thereon, characterized in that: When the executable instructions are executed by a processor, the method steps according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Fragment shaders perform vertex shader computations
US20140362101A1
Indexed uniform styles for stroke rendering
US20150332481A1
