Three-dimensional model pickup method and device, equipment and storage medium

By assigning random colors to the three-dimensional model and rendering them to the color pickup cache, the problem of inefficient three-dimensional model pickup in the prior art is solved, fast and convenient model pickup is achieved, and the computing load is reduced.

CN119418072APending Publication Date: 2025-02-11PCI TECH GRP CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411447140.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

The prior art requires a lot of geometric calculations when picking up three-dimensional models or three-dimensional coordinates in a three-dimensional scene, resulting in inefficiency.

Method used

By assigning non-repetitive random colors to each model as pickup colors, the model is rendered into the pre-built color pickup cache using the shader. When it is necessary to pick up the model, the corresponding color value is obtained from the cache to determine the target model.

Benefits of technology

It reduces the time and calculation amount required for model pickup, improves the pickup efficiency, makes the pickup of three-dimensional models faster and more convenient, and does not rely on scene rendering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119418072A_ABST
    Figure CN119418072A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of images, and discloses a three-dimensional model pickup method, device and equipment and a storage medium, and the method comprises the steps: distributing non-repeated random colors for each model as pickup colors corresponding to each model; each model is used for being displayed in a target scene; respectively rendering each model to a pre-constructed color pick-up cache through a shader according to the pick-up color corresponding to each model; and when the three-dimensional model is picked up, obtaining a two-dimensional coordinate of a first position in a target scene, obtaining a corresponding target pickup color from the color pickup cache according to the two-dimensional coordinate of the first position, and determining a target model corresponding to the first position according to a corresponding relationship between each model and the pickup color. The model is rendered to the pre-constructed color cache region, and the color value is extracted according to the coordinate of the target position so as to obtain the target model needing to be picked up, so that the time consumed by model picking up is shortened, and the efficiency of model picking up is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image technology, and in particular to a three-dimensional model picking method, device, equipment and storage medium. Background Art

[0002] When picking up a 3D model or 3D coordinates in a 3D scene, the related technology generally uses a ray collision detection method, which emits a ray from the screen mouse position or the touch click position to the scene, and then traverses all object models in the scene, detects whether each triangle face of each object intersects with the ray, obtains the intersection point, and then sorts the distance between the intersection point and the ray emission point (origin) from near to far, and finally obtains the intersection point (intersect point) closest to the ray emission point (origin), which is the picked model and coordinates. However, this method requires a lot of geometric calculations.

[0003] Therefore, there is an urgent need for a 3D model picking method that does not require generating rays, traversing a large number of model objects, or performing a large amount of geometric calculations in JavaScript. Summary of the invention

[0004] In view of this, the present application provides a 3D model picking method, device, equipment and storage medium, which reduces the time required for 3D model picking and improves the execution efficiency of 3D model picking. The technical solution is as follows.

[0005] In a first aspect, the present invention provides a three-dimensional model picking method, the method comprising:

[0006] Assigning a non-repeating random color to each model as a picked color corresponding to each model; each model is used to be displayed in a target scene;

[0007] Render each model into the pre-built color picking cache according to the picking color corresponding to each model through the shader;

[0008] When picking a three-dimensional model, obtain the two-dimensional coordinates of the first position in the target scene, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

[0009] The three-dimensional model picking method provided by the present invention has the following advantages:

[0010] The three-dimensional model picking method of the present invention pre-creates a color picking cache, then allocates a non-repeating random color to each model, establishes a corresponding relationship between each model and the color, and uses the color as the picking color of each model. Then, according to the picking color corresponding to each model, each model is rendered into the color picking cache through a shader. When a user needs to pick up a three-dimensional model, the two-dimensional coordinates of the target position in the target scene indicated by the user are read, and the corresponding target picking color is obtained from the color picking cache through the two-dimensional coordinates. The target model to be picked up by the user is determined through the corresponding relationship between each model and the picking color. By storing the rendering result in the pre-created color picking cache, it is not necessary to fill the model with a solid color in the scene, it is not necessary to generate rays like the traditional method, it is not necessary to traverse a large number of model objects, and it is not necessary to perform a large number of geometric calculations in JavaScript. It is only necessary to extract the color value according to the coordinates of the target position to obtain the target model to be picked up, thereby shortening the time consumed by model picking, improving the efficiency of model picking, and making the picking of the three-dimensional model faster and more convenient. Furthermore, since the model is rendered into a separately created color picking cache through a shader, the picking of the 3D model and the rendering of the scene do not interfere with each other and do not need to rely on the rendering of the scene.

[0011] In an optional implementation, a non-repeating random color is assigned to each model as a pickup color corresponding to each model, including:

[0012] Assign different numerical values ​​to each color in the color space; establish a mapping table between colors and numerical values ​​corresponding to the colors; assign different numerical values ​​to each model, and obtain the color corresponding to each model as the picked-up color corresponding to each model according to the mapping table.

[0013] In an optional implementation, the three-dimensional model picking method further includes:

[0014] Obtain the depth value of each model; convert the depth value into a grayscale value as the grayscale pickup value corresponding to each model, and render each model into a pre-built scene depth buffer according to the grayscale pickup value corresponding to each model through a shader.

[0015] When picking up three-dimensional coordinates, obtain the two-dimensional coordinates of the second position in the target scene, obtain the corresponding target grayscale picking value from the scene depth cache according to the two-dimensional coordinates of the second position, and determine the depth value corresponding to the second position based on the correspondence between each model and the grayscale picking value; calculate the three-dimensional coordinates of the second position according to the depth value.

[0016] In an optional implementation, the depth value is converted into a grayscale value as a grayscale pickup value corresponding to each model, and each model is rendered into a pre-built scene depth buffer according to the grayscale pickup value corresponding to each model through a shader, including:

[0017] The depth value is converted into a grayscale value of a floating point type, and then the grayscale value of the floating point type is converted into a grayscale value of a byte type to obtain a byte type grayscale pickup value corresponding to each model; the data type of the depth value is a floating point type; through a shader, the byte type grayscale value is converted into a grayscale pickup value corresponding to each model, and each model is rendered into a pre-built scene depth cache.

[0018] In an optional implementation, obtaining a corresponding target grayscale pickup value from a scene depth buffer according to the two-dimensional coordinates of the second position, and determining a depth value corresponding to the second position according to a correspondence between each model and the grayscale pickup value, includes:

[0019] The grayscale value corresponding to the target grayscale pickup value is converted into a grayscale value of floating point type; the data type of the target grayscale pickup value is byte type; the corresponding depth value is obtained according to the grayscale value of floating point type, and the data type of the depth value is floating point type.

[0020] In an optional implementation, the three-dimensional model picking method further includes:

[0021] The target scene is rendered into a pre-built scene cache; when the target scene is displayed, the target scene in the scene cache is read and displayed through a display screen.

[0022] In an optional implementation, the three-dimensional model picking method further includes:

[0023] There is a pick-up selection control on the interface of the display screen, and the model pick-up mode or the three-dimensional coordinate pick-up mode is selected according to the user's selection operation on the pick-up selection control.

[0024] In response to a model picking mode instruction of a user, a target model corresponding to the target position is determined according to the target position indicated by the model picking mode instruction.

[0025] In response to a three-dimensional coordinate picking mode instruction from a user, the three-dimensional coordinates corresponding to the target position are determined according to the target position indicated by the three-dimensional coordinate picking mode instruction.

[0026] In a second aspect, the present invention provides a three-dimensional model picking device, the device comprising:

[0027] The allocation module is used to allocate a non-repeating random color to each model as a picked color corresponding to each model; each model is used to be displayed in a target scene.

[0028] The rendering module is used to render each model into a pre-built color picking cache according to the picking color corresponding to each model through a shader.

[0029] The picking module is used to obtain the two-dimensional coordinates of the first position in the target scene when picking a three-dimensional model, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

[0030] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, computer instructions being stored in the memory, and the processor executing the three-dimensional model picking method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0031] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the three-dimensional model picking method of the first aspect or any corresponding embodiment thereof.

[0032] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the three-dimensional model picking method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0034] Figure 1 It is a schematic diagram of the flow of a three-dimensional model picking method provided by an embodiment of the present invention.

[0035] Figure 2 It is a schematic diagram of the flow of a three-dimensional coordinate picking method provided by an embodiment of the present invention.

[0036] Figure 3 It is a flowchart of a three-dimensional scene display method provided by an embodiment of the present invention.

[0037] Figure 4 This is a schematic diagram of a standard three-dimensional scene rendering process provided by an embodiment of the present invention.

[0038] Figure 5It is a schematic diagram of a three-dimensional scene rendering process provided in a specific application of the present invention.

[0039] Figure 6 It is a schematic diagram of the three-dimensional model picking process provided in the specific application of the present invention.

[0040] Figure 7 It is a schematic diagram of the three-dimensional coordinate picking process provided in the specific application of the present invention.

[0041] Figure 8 It is a structural block diagram of a three-dimensional model picking device provided by an embodiment of the present invention.

[0042] Fig. 9 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0044] In the description of the embodiments of the present application, the term "corresponding" may indicate a direct or indirect correspondence between two items, or an association relationship between the two items, or a relationship between indication and being indicated, configuration and being configured, and the like.

[0045] With the development of 3D technology, many browser applications support the use of 3D technology to display three-dimensional models. When users need to interact with three-dimensional models, they can use positioning devices such as mice to pick up a certain position of the three-dimensional model for interaction. When the user clicks a certain point on the screen with the mouse, the application should be able to deduce which object is selected.

[0046] At present, the commonly used ray intersection method is to determine which object the user clicks on with the mouse. The main principle is: from the position of the human eye, a ray is drawn to the position used for the mouse click. Since the surface of a three-dimensional object is composed of triangles, as long as the central processing unit (CPU) determines one by one whether the ray intersects with a certain triangle on the surface of a certain object, the object where the triangle intersecting with the ray is located is the object clicked by the user's mouse. However, when the CPU uses the ray intersection method to determine which object is picked up, when there are too many objects or the shape of the surface of the object is complex, the number of triangles that the CPU needs to determine is too large, resulting in an excessively high CPU load, and the CPU determination process takes a long time, which will bring a large load to the CPU, and even cause the browser page to freeze, giving users a very bad user experience.

[0047] To solve the above problems, an embodiment of the present invention provides an embodiment of a 3D model picking method, which can put the calculation into the GPU to reduce the load of the CPU. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system (computer device) including a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.

[0048] In this embodiment, a three-dimensional model picking method is provided, which can be used in the above-mentioned terminal equipment, such as a mobile phone, a tablet computer, etc. Figure 1 3D model picking method according to an embodiment of the present invention is shown in FIG. Figure 1 As shown, the process includes the following steps:

[0049] Step S101, assigning a non-repeating random color to each model as a picked color corresponding to each model; each model is used to be displayed in a target scene.

[0050] Optionally, in step S101, assigning colors to each model does not depend on the establishment of the scene, and the rendering of the scene and the rendering of the model can be performed simultaneously without interfering with each other. Assigning different colors to each model specifically includes: assigning different values ​​to each color in the color space; establishing a mapping table of colors and values ​​corresponding to the colors; assigning different values ​​to each model, and obtaining the color corresponding to each model as the pickup color corresponding to each model according to the mapping table. By establishing a mapping relationship between colors and values, the corresponding numerical data is stored in the color pickup cache, rather than directly storing the colors in the color pickup cache.

[0051] Step S102 , rendering each model into a pre-built color picking buffer according to the picking color corresponding to each model through a shader.

[0052] Optionally, in step S102, a corresponding pure color shader is generated according to the picked color corresponding to each model, and each model is rendered into a pre-built color picking cache according to the picked color corresponding to each model through each shader. It should be noted that based on the mapping relationship between the picked color and the numerical value, and the mapping relationship between each model and the numerical value, the mapping relationship between the picked color, the numerical value and each model is obtained, and finally the corresponding numerical data is stored in the color picking cache, and the numerical data corresponding to the picked color is stored in the color picking cache.

[0053] Step S103, when picking up a three-dimensional model, obtain the two-dimensional coordinates of the first position in the target scene, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

[0054] Optionally, in step S103, when the user needs to pick up a three-dimensional model, the user can obtain the two-dimensional coordinates of the first position by clicking or touching the first position in the target scene with the mouse, and can obtain corresponding numerical data from the color picking cache based on the two-dimensional coordinates, and obtain the picked color corresponding to the first position according to the mapping relationship between the numerical value and the picked color, and determine the target model corresponding to the first position according to the picked color and the mapping relationship between the picked color and each model.

[0055] In summary, the three-dimensional model picking method provided in this embodiment creates a color picking cache in advance, assigns a non-repeating random color to each model, establishes a corresponding relationship between each model and color, and uses the color as the picking color of each model. Then, according to the picking color corresponding to each model, each model is rendered into the color picking cache through a shader. When the user needs to pick up a three-dimensional model, the two-dimensional coordinates of the target position in the target scene indicated by the user are read, and the corresponding target picking color is obtained from the color picking cache through the two-dimensional coordinates. The target model to be picked by the user is determined through the corresponding relationship between each model and the picking color. By storing the rendering result in the pre-created color picking cache, there is no need to fill the model with a solid color in the scene, no need to generate rays like the traditional method, no need to traverse a large number of model objects, and no need to perform a large number of geometric calculations in JavaScript. It is only necessary to extract the color value according to the coordinates of the target position to obtain the target model to be picked, which shortens the time consumed by model picking, improves the efficiency of model picking, and makes the picking of three-dimensional models faster and more convenient. Furthermore, since the model is rendered into a separately created color picking cache through a shader, the picking of the 3D model and the rendering of the scene do not interfere with each other and do not need to rely on the rendering of the scene.

[0056] Picking a 3D model also includes picking 3D coordinates. The currently used ray casting picking method requires a series of coordinate system transformation calculations that are opposite to the rendering process for each picking calculation. The vertex data of the 3D object is transformed from the object coordinate system to the model view to obtain the coordinates in the camera coordinate system, and then to the projection transformation (orthographic projection or perspective projection) to obtain the coordinates in the clipping space coordinate system. Then, it is normalized to obtain the coordinates in the normalized device coordinate system, and then to the viewport transformation to obtain the coordinates in the screen coordinate system, which is the final rendering result. It can be seen that the series of reverse transformations used in position picking are very computationally intensive, which will bring a large load to the CPU, and may even cause the browser page to freeze, giving users a very bad user experience.

[0057] Therefore, this embodiment also provides a method for picking up three-dimensional coordinates. Figure 2 3D coordinate picking method according to an embodiment of the present invention is shown in FIG. Figure 2 As shown, the process includes the following steps:

[0058] Step S201, obtaining the depth value of each model.

[0059] Optionally, in step S201, the data type of the depth value of each model is a floating point type.

[0060] Step S202: convert the depth value into a grayscale value as a grayscale pickup value corresponding to each model, and render each model into a pre-built scene depth buffer according to the grayscale pickup value corresponding to each model through a shader.

[0061] Optionally, in step S202, the depth value is converted into a grayscale value of a floating point type, and then the grayscale value of the floating point type is converted into a grayscale value of a byte type to obtain a grayscale pickup value of a byte type corresponding to each model. The byte type grayscale value is converted into a grayscale pickup value corresponding to each model by a shader, and each model is rendered into a pre-built scene depth buffer.

[0062] Step S203, when picking up three-dimensional coordinates, obtain the two-dimensional coordinates of the second position in the target scene, obtain the corresponding target grayscale picking value from the scene depth cache according to the two-dimensional coordinates of the second position, and determine the depth value corresponding to the second position based on the correspondence between each model and the grayscale picking value; calculate the three-dimensional coordinates of the second position according to the depth value.

[0063] Optionally, in step S203, the grayscale value corresponding to the target grayscale pickup value is converted into a grayscale value of floating point type; the data type of the target grayscale pickup value is byte type; the corresponding depth value is obtained according to the grayscale value of the floating point type, and the data type of the depth value is floating point type.

[0064] In summary, the three-dimensional coordinate picking method provided in this embodiment creates a scene depth cache in advance, and then calculates the depth value according to the distance between the model vertex and the camera, converts the depth value into a grayscale value as the grayscale picking value corresponding to each model, and renders each model into the pre-built scene depth cache according to the grayscale picking value corresponding to each model through the shader. When picking up three-dimensional coordinates, the two-dimensional coordinates of the second position in the target scene are obtained, and the corresponding target grayscale picking value is obtained from the scene depth cache according to the two-dimensional coordinates of the second position, and the depth value corresponding to the second position is determined according to the correspondence between each model and the grayscale picking value; the three-dimensional coordinates of the second position are calculated according to the depth value. There is no need to generate rays like the traditional method, there is no need to traverse a large number of model objects, and there is no need to perform a large number of geometric calculations in JavaScript. The required amount of calculation is small, and even in the case of limited CPU performance, there will be no page freeze phenomenon, which can bring a good user experience.

[0065] The 3D model picking method provided in this embodiment also includes 3D scene display, Figure 3 3D scene display method according to an embodiment of the present invention is shown in FIG. Figure 3 As shown, the process includes the following steps:

[0066] Step S301, rendering the target scene into a pre-built scene cache;

[0067] Optionally, in step S301, a scene cache is pre-built, a color picking cache is pre-built in the 3D model picking method, and a scene depth cache is pre-built in the 3D coordinate picking method, so that the picking of the 3D model, the picking of the 3D coordinates and the rendering of the scene do not interfere with each other.

[0068] Step S302, when displaying a target scene, read the target scene in the scene cache and display it through a display screen.

[0069] In an optional implementation, there is a pick selection control on the interface of the display screen, and the model pick mode or the three-dimensional coordinate pick mode is selected according to the user's selection operation on the pick selection control.

[0070] In response to a model picking mode instruction from a user, a target model corresponding to the target position is determined according to the target position indicated by the model picking mode instruction through a three-dimensional model picking method.

[0071] In response to a three-dimensional coordinate picking mode instruction from a user, a three-dimensional coordinate picking method is used to determine the three-dimensional coordinates corresponding to the target position according to the target position indicated by the three-dimensional coordinate picking mode instruction.

[0072] Combination Figure 1 , Figure 2 and Figure 3 The method can simultaneously pick up three-dimensional models, extract three-dimensional coordinates, and display three-dimensional scenes, and the corresponding operation can be selected according to the specific needs of the user.

[0073] The following is a specific example to illustrate this embodiment. Figure 1 , Figure 2 and Figure 3 The method provides 3D model picking, 3D coordinate picking and 3D scene display.

[0074] A standard 3D scene rendering process is as follows Figure 4 As shown in the figure, the rendering process is based on WebGL for 3D scene rendering. WebGL (Web Graphics Library) is a 3D drawing protocol based on OpenGL ES2.0, which provides hardware 3D accelerated rendering for HTML5Canvas. It uses JavaScript API and OpenGL Shading Language (GLSL) to write shaders, and can render 3D graphics in any Web browser that supports WebGL without using any plug-ins. The specific rendering process is:

[0075] When the 3D scene rendering process starts, the target scene is generated, and a Framebuffer is created on the generated target scene to store the rendered model. After the rendering starts, the computer loads each model in the target scene, and parses each model to generate a corresponding shader for model rendering. Each model is rendered into a pre-created cache frame through the shader. When the scene needs to be displayed, the content in the cache frame is displayed on the display.

[0076] This embodiment improves on the standard process. The improved 3D scene rendering process is as follows: Figure 5 As shown, the specific rendering process is:

[0077] When the 3D scene rendering process starts, a target scene is generated, and three buffer frames, namely, scene cache, scene depth cache and color picking cache, are created in the generated target scene for storage of subsequent rendering data.

[0078] Optionally, after generating the scene, first create three different framebuffers: scene buffer ColorTexture (Color Buffer), scene depth buffer DepthTexture (Depth Buffer), and color picking buffer PickingTexture (ColorPickBuffer).

[0079] After rendering starts, the computer loads each model in the scene, parses each model to generate a corresponding shader for model rendering, and assigns a different pick color to each model and generates a corresponding color pick shader for rendering the model into different cache spaces. The target scene is rendered into the scene cache and scene depth cache through the shader, and then the model is rendered into the color pick cache through the color pick shader. When the scene needs to be displayed, the scene data in the scene cache is displayed on the display.

[0080] Optionally, when parsing each model material and generating a shader, a non-repeating random color is generated as the picking color of the model, and a pure color shader is generated, recorded as a color picking shader, which is used to render each model. After rendering the scene to the scene buffer, render the scene to the scene depth buffer again. Set the color picking shader as the model shader in the scene, and provide the color picking shader to render the scene to the color picking buffer, so that we can get three different Framebuffers (cached frames) of the rendered ColorTexture (scene buffer), DepthTexture (scene depth buffer), and PickingTexture (color picking buffer).

[0081] It should be noted that the color picking buffer stores the picked color data corresponding to each model, and the scene depth buffer stores the grayscale value data corresponding to each model. The grayscale value is converted based on the calculated depth value of each model. The floating-point depth value is converted into a byte-type grayscale value and stored in the scene depth buffer.

[0082] When a 3D model needs to be picked up, the model to be picked up is determined by the picked color data in the color picking cache. The specific 3D model picking process is as follows: Figure 6 shown.

[0083] The user selects the model picking mode on the picking selection control of the display screen interface.

[0084] In response to the user's model picking mode instruction, the computer reads the two-dimensional coordinates of the user's mouse or touch position, reads the picking color of the position from the color picking cache, queries the corresponding model object in the memory according to the picking color, and thus determines the target model corresponding to the position.

[0085] When the 3D coordinates need to be picked, the grayscale value in the scene depth buffer is used to determine the 3D coordinates to be picked. The specific 3D coordinate picking process is as follows: Figure 7 shown.

[0086] The user selects the three-dimensional coordinate picking mode on the picking selection control of the display screen interface.

[0087] In response to the user's three-dimensional coordinate picking mode instruction, the computer reads the two-dimensional coordinates of the user's mouse or touch position, extracts the grayscale value from the scene depth buffer, calculates the depth value Depth based on the grayscale value, and then calculates the three-dimensional coordinates of the target position based on the depth value.

[0088] It should be noted that the grayscale value is a byte array of a preset length. The following takes the grayscale value being a byte array of length 4 as an example to illustrate the three-dimensional coordinate picking process.

[0089] First, the grayscale value picked up from the scene depth buffer is a byte array with a length of 4. The array content is converted to a floating point value according to the byte to float conversion formula: byte / 255 = float.

[0090] Based on the obtained floating-point grayscale value, the floating-point depth value Depth is calculated according to the depth value calculation formula. The formula is:

[0091]

[0092] According to the mouse or touch point coordinates P (x,y) Calculate the NDC coordinates based on the pixel width and height of the display screen. Specifically:

[0093] Generate a Vector4 type object ndc, the expression of the object ncd is:

[0094]

[0095] ndc.z = depth × 2.0 - 1.0

[0096] ndc.w = 1.0;

[0097] According to the matrix-vector multiplication formula, multiplying the inverse matrix of the view projection (ViewProjection) of the 3D scene camera by the ndc coordinates can get a view coordinate VP of type Vector4. (x,y,z,w) The matrix-vector multiplication formula is:

[0098] Matrix 4x4 ×Vector4=Vector4;

[0099] Based on the view coordinates of the Vector4 type, the three-dimensional coordinate W is calculated (x,y,z) , the calculation formula is:

[0100]

[0101] In summary, this embodiment improves the conventional three-dimensional scene rendering process and pre-creates three cache spaces for scene rendering, scene depth rendering and color picking rendering. It does not need to generate rays, traverse a large number of model objects, or perform a large number of geometric calculations in JavaScript. It only needs to use the GPU capability to draw the scene to three different buffer frames, extract the picking value or grayscale value according to the mouse or touch point coordinates, and then query or calculate according to the picking value or grayscale value to obtain the three-dimensional model or three-dimensional coordinates to be picked up. Compared with the ray collision detection method, the time overhead required is greatly reduced, and the execution efficiency of the program is greatly improved.

[0102] In the embodiments of the present application, a three-dimensional model picking device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0103] The present application embodiment provides a three-dimensional model picking device, Figure 8 : is a schematic diagram of the structure of a three-dimensional model picking device provided in an embodiment of the present application, the device comprising:

[0104] The allocation module 801 is used to allocate a non-repeating random color to each model as a picked color corresponding to each model; each model is used to be displayed in a target scene.

[0105] The rendering module 802 is used to render each model into a pre-built color picking buffer according to the picking color corresponding to each model through a shader.

[0106] The picking module 803 is used to obtain the two-dimensional coordinates of the first position in the target scene when picking a three-dimensional model, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

[0107] In an optional implementation, the allocation module 801 is specifically configured to:

[0108] Assign different numerical values ​​to each color in the color space; establish a mapping table between colors and numerical values ​​corresponding to the colors; assign different numerical values ​​to each model, and obtain the color corresponding to each model as the picked-up color corresponding to each model according to the mapping table.

[0109] In an optional implementation, the three-dimensional model picking device further includes:

[0110] The coordinate picking module 804 is used to obtain the depth value of each model; convert the depth value into a grayscale value as the grayscale picking value corresponding to each model, and render each model into a pre-built scene depth cache according to the grayscale picking value corresponding to each model through a shader; when picking up three-dimensional coordinates, obtain the two-dimensional coordinates of the second position in the target scene, obtain the corresponding target grayscale picking value from the scene depth cache according to the two-dimensional coordinates of the second position, and determine the depth value corresponding to the second position based on the correspondence between each model and the grayscale picking value; calculate the three-dimensional coordinates of the second position according to the depth value.

[0111] In an optional implementation, the coordinate picking module 804 is specifically used to:

[0112] The depth value is converted into a grayscale value of a floating point type, and then the grayscale value of the floating point type is converted into a grayscale value of a byte type to obtain a byte type grayscale pickup value corresponding to each model; the data type of the depth value is a floating point type; through a shader, the byte type grayscale value is converted into a grayscale pickup value corresponding to each model, and each model is rendered into a pre-built scene depth cache.

[0113] In an optional implementation, the coordinate picking module 804 is further used to:

[0114] The grayscale value corresponding to the target grayscale pickup value is converted into a grayscale value of floating point type; the data type of the target grayscale pickup value is byte type; the corresponding depth value is obtained according to the grayscale value of floating point type, and the data type of the depth value is floating point type.

[0115] In an optional implementation, the three-dimensional model picking device further includes:

[0116] The display module 805 is used to render the target scene into a pre-built scene cache; when displaying the target scene, the target scene in the scene cache is read and displayed through the display screen.

[0117] In an optional implementation, the display module 805 is further used to:

[0118] There is a pick-up selection control on the interface of the display screen, and the model pick-up mode or the three-dimensional coordinate pick-up mode is selected according to the user's selection operation on the pick-up selection control.

[0119] In response to the user's model picking mode instruction, the target model corresponding to the target position is determined according to the target position indicated by the model picking mode instruction; in response to the user's three-dimensional coordinate picking mode instruction, the three-dimensional coordinates corresponding to the target position are determined according to the target position indicated by the three-dimensional coordinate picking mode instruction.

[0120] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0121] The embodiment of the present invention also provides a computer device having the above Figure 8 The three-dimensional model picking device shown.

[0122] See also Fig. 9 , Fig. 9 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Fig. 9 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphic information in a graphical user interface on an external input / output device (such as a display device coupled to an interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig. 9 A processor 10 is taken as an example.

[0123] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0124] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0125] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0126] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0127] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0128] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0129] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0130] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A three-dimensional model picking method, characterized in that: include: Assigning a non-repeating random color to each model as a picked color corresponding to each model; each model is used to be displayed in a target scene; Render each model into the pre-built color picking cache according to the picking color corresponding to each model through the shader; When picking a three-dimensional model, obtain the two-dimensional coordinates of the first position in the target scene, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

2. The method according to claim 1, characterized in that The step of assigning a non-repeating random color to each model as a pickup color corresponding to each model includes: Assign a different numerical value to each color in the color space; Establishing a mapping table between colors and numerical values ​​corresponding to the colors; Different numerical values ​​are assigned to each model, and the color corresponding to each model is obtained according to the mapping table as the picked-up color corresponding to each model.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: Get the depth value of each model; The depth value is converted into a grayscale value as a grayscale pickup value corresponding to each model, and each model is rendered into a pre-built scene depth buffer according to the grayscale pickup value corresponding to each model through a shader; When picking up three-dimensional coordinates, obtain the two-dimensional coordinates of the second position in the target scene, obtain the corresponding target grayscale picking value from the scene depth cache according to the two-dimensional coordinates of the second position, and determine the depth value corresponding to the second position based on the correspondence between each model and the grayscale picking value; calculate the three-dimensional coordinates of the second position according to the depth value.

4. The method according to claim 3, characterized in that The step of converting the depth value into a grayscale value as a grayscale pickup value corresponding to each model, and rendering each model into a pre-built scene depth buffer according to the grayscale pickup value corresponding to each model through a shader, includes: The depth value is converted into a grayscale value of a floating point type, and then the grayscale value of the floating point type is converted into a grayscale value of a byte type, to obtain a byte type grayscale pickup value corresponding to each model; the data type of the depth value is a floating point type; Through the shader, the grayscale value of the byte type is picked according to the grayscale value corresponding to each model, and each model is rendered into the pre-built scene depth buffer.

5. The method according to claim 3, characterized in that: The acquiring a corresponding target grayscale pickup value from a scene depth buffer according to the two-dimensional coordinates of the second position, and determining a depth value corresponding to the second position according to a correspondence between each model and the grayscale pickup value, includes: Convert the grayscale value corresponding to the target grayscale pickup value into a grayscale value of floating point type; the data type of the target grayscale pickup value is byte type; A corresponding depth value is obtained according to the grayscale value of the floating point type, and the data type of the depth value is a floating point type.

6. The method according to claim 1 or 2, characterized in that: The method further comprises: Render the target scene into a pre-built scene cache; When the target scene is displayed, the target scene in the scene cache is read and displayed through the display screen.

7. The method according to claim 6, characterized in that The method further comprises: There is a pick-up selection control on the interface of the display screen, and the model pick-up mode or the three-dimensional coordinate pick-up mode is selected according to the user's selection operation on the pick-up selection control; In response to a model picking mode instruction of a user, determining a target model corresponding to the target position according to the target position indicated by the model picking mode instruction; In response to a three-dimensional coordinate picking mode instruction from a user, the three-dimensional coordinates corresponding to the target position are determined according to the target position indicated by the three-dimensional coordinate picking mode instruction.

8. A three-dimensional model picking device, characterized in that: The device comprises: An allocation module, used for allocating a non-repeating random color to each model as a picking color corresponding to each model; each model is used for display in a target scene; A rendering module, used to render each model into a pre-built color picking cache according to the picking color corresponding to each model through a shader; The picking module is used to obtain the two-dimensional coordinates of the first position in the target scene when picking a three-dimensional model, obtain the corresponding target picking color from the color picking cache according to the two-dimensional coordinates of the first position, and determine the target model corresponding to the first position based on the correspondence between each model and the picking color.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the three-dimensional model picking method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the three-dimensional model picking method according to any one of claims 1 to 7.

Citation Information

Cited By

  • GPU-accelerated 3D Gaussian splash three-dimensional coordinate high-precision real-time pickup method and system

    CN121095466A

  • Gpu accelerated 3d gaussian splatting three-dimensional coordinate high-precision real-time picking method and system

    CN121095466B