Method and apparatus for local scaling of three-dimensional model, and electronic device
Patent Information
- Application Number
- CN202211582931.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-09
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2042-12-09
AI Technical Summary
现有缩放并不考虑局部情况,对于进行细节方面的操作时候只能通过将当前模块独立出来才能进行缩放操作
[0017]本申请实施例提供的三维模型的局部缩放处理方法、装置、电子设备及可读存储介质,在获得显示屏幕上被选择的作为缩放指定区域的第一目标区域的情况下,基于透视投影变换,在世界坐标系下,根据虚拟相机的位置、第一目标区域中各第一目标像素点的位置及目标三维模型,获得目标三维顶点的三维坐标,该目标三维顶点为基于所述第一目标区域确定出来的所述目标三维模型上需要进行缩放的顶点;最后,根据获得的目标缩放信息对各目标三维顶点的三维坐标进行缩放处理,以完成对目标三维模型的局部缩放处理。如此,能够对模型进行局部缩放,可减少为实现细节缩放而进行模型分割带来的损耗,降低成本。
Smart Images

Figure CN115861067B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, and electronic device for local scaling of a three-dimensional model. Background Technology
[0002] Currently, when scaling a model, all vertex data of the model is selected, and then the positions of the vertices are modified to achieve an overall scaling effect. The current scaling method does not consider local cases; for detailed operations, scaling can only be performed by isolating the current module. Summary of the Invention
[0003] This application provides a method, apparatus, electronic device, and readable storage medium for local scaling of a three-dimensional model, which can perform local scaling of the model and reduce the burden of separating modules.
[0004] The embodiments of this application can be implemented as follows:
[0005] In a first aspect, embodiments of this application provide a method for local scaling of a three-dimensional model, the method comprising:
[0006] Obtain the first target area selected on the display screen, wherein the first target area is the zoom specified area;
[0007] Based on perspective projection transformation, in the world coordinate system, according to the position of the virtual camera, the position of each first target pixel in the first target region and the target three-dimensional model, the three-dimensional coordinates of the target three-dimensional vertices are obtained, wherein the target three-dimensional vertices are the vertices on the target three-dimensional model that need to be scaled based on the first target region;
[0008] Obtain target scaling information;
[0009] The three-dimensional coordinates of each of the target three-dimensional vertices are scaled according to the target scaling information to complete the local scaling of the target three-dimensional model.
[0010] Secondly, embodiments of this application provide a local scaling processing apparatus for a three-dimensional model, the apparatus comprising:
[0011] The region determination module is used to obtain the first target region selected on the display screen, wherein the first target region is a zoom-specified region;
[0012] The vertex determination module is used to obtain the three-dimensional coordinates of the target three-dimensional vertices in the world coordinate system based on perspective projection transformation, according to the position of the virtual camera, the first target region, and the target three-dimensional model. The target three-dimensional vertices are the vertices on the target three-dimensional model that need to be scaled based on the first target region.
[0013] The scaling information acquisition module is used to obtain target scaling information;
[0014] The processing module is used to scale the three-dimensional coordinates of each of the target three-dimensional vertices according to the target scaling information, so as to complete the local scaling processing of the target three-dimensional model.
[0015] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor can execute the machine-executable instructions to implement the local scaling processing method for the three-dimensional model described in the foregoing embodiments.
[0016] Fourthly, embodiments of this application provide a readable storage medium storing a computer program thereon, which, when executed by a processor, implements the local scaling processing method for a three-dimensional model as described in the foregoing embodiments.
[0017] The method, apparatus, electronic device, and readable storage medium for local scaling of a 3D model provided in this application, when a first target region selected on a display screen as the specified scaling area is obtained, obtains the 3D coordinates of target 3D vertices in the world coordinate system based on perspective projection transformation, according to the position of the virtual camera, the position of each first target pixel in the first target region, and the target 3D model. These target 3D vertices are the vertices on the target 3D model that need to be scaled, determined based on the first target region. Finally, the 3D coordinates of each target 3D vertex are scaled according to the obtained target scaling information to complete the local scaling of the target 3D model. This allows for local scaling of the model, reducing the losses caused by model segmentation for detailed scaling and lowering costs. Attached Figure Description
[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A block diagram illustrating an electronic device provided in an embodiment of this application;
[0020] Figure 2 A flowchart illustrating the local scaling method for a 3D model provided in an embodiment of this application;
[0021] Figure 3 for Figure 2 A flowchart illustrating the sub-steps included in step S120;
[0022] Figure 4 for Figure 2 A flowchart illustrating the sub-steps included in step S130;
[0023] Figure 5 for Figure 4 A flowchart illustrating the sub-steps included in the neutron step S131;
[0024] Figure 6 for Figure 5 A flowchart illustrating the sub-steps included in the neutron step S1313;
[0025] Figure 7 A block diagram illustrating a local scaling processing device for a three-dimensional model provided in an embodiment of this application.
[0026] Icons: 100 - Electronic device; 110 - Memory; 120 - Processor; 130 - Communication unit; 200 - Local scaling processing device for 3D models; 210 - Region determination module; 220 - Vertex determination module; 230 - Scaling information acquisition module; 240 - Processing module. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0028] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0029] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0030] The inventors of this application discovered through research that, in the process of studying plant growth changes, the growing parts of plants exhibit self-similarity. Taking the leaf of a fern as an example, its growth shape grows recursively while simultaneously expanding locally. However, the implementation using fractal geometry recursively generates an image on a graphic with predefined boundaries. Since the boundaries are fixed and the overall object does not change much, the recursion only generates more details, which does not conform to the growth process of plants from small to large. Therefore, the inventors hope to implement a local scaling method that scales locally while recursively adding details. Furthermore, using local scaling for detail operations can reduce the burden of isolating modules.
[0031] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0032] Please refer to Figure 1 , Figure 1 This is a block diagram of an electronic device 100 provided in an embodiment of this application. The electronic device 100 may be, but is not limited to, a smartphone, a computer, etc. The electronic device 100 may include a memory 110, a processor 120, and a communication unit 130. The memory 110, processor 120, and communication unit 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0033] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0034] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, the memory 110 stores a local scaling processing device 200 for a 3D model, which includes at least one software function module that can be stored in the memory 110 in the form of software or firmware. The processor 120 executes various functional applications and data processing by running the software programs and modules stored in the memory 110, such as the local scaling processing device 200 for a 3D model in this embodiment, thereby implementing the local scaling processing method for a 3D model in this embodiment.
[0035] The communication unit 130 is used to establish a communication connection between the 120 and other communication terminals through the network, and to send and receive data through the network.
[0036] It should be understood that, Figure 1 The structure shown is only a schematic diagram of the electronic device 100. The electronic device 100 may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0037] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating a method for local scaling of a 3D model provided in an embodiment of this application. The method can be applied to the aforementioned electronic device 100. The specific flow of the method for local scaling of a 3D model is described in detail below. In this embodiment, the method may include steps S110 to S140.
[0038] Step S110: Obtain the first target area selected on the display screen.
[0039] In this embodiment, the first target area is a zoomable specified area. The first target area is a specific area on the display screen. This first target area can be an area specified by another device, or it can be an area directly selected by the user using the mouse on the display screen.
[0040] Step S120: Based on perspective projection transformation, in the world coordinate system, according to the position of the virtual camera, the position of each first target pixel in the first target area and the target 3D model, the 3D coordinates of the target 3D vertices are obtained.
[0041] In this embodiment, the target 3D vertices can be determined based on perspective projection transformation, according to the coordinates of the virtual camera in the world coordinate system, the target 3D model, and the first target region. Specifically, a portion of the target 3D model needs to be scaled, and the target 3D vertices are the vertices on the target 3D model that require scaling, determined based on the first target region. The 3D coordinates of the target 3D vertex can be its coordinates in the world coordinate system. The pixels in the first target region are the first target pixels.
[0042] Step S130: Obtain target scaling information.
[0043] The target scaling information is used to specify the scaling ratio used when scaling. The target scaling information can be a scaling ratio value manually entered by the user, scaling information obtained based on other user operations, or scaling information sent by other devices. Again, the specific method of obtaining the target scaling information is not limited.
[0044] Step S140: The three-dimensional coordinates of each of the target three-dimensional vertices are scaled according to the target scaling information to complete the local scaling process of the target three-dimensional model.
[0045] Once the 3D coordinates of the target 3D vertices are determined, the 3D coordinates of each target 3D vertex are scaled accordingly based on the scaling ratio specified by the target scaling information. This allows for local scaling of the model, reducing the overhead of model segmentation for detailed scaling and lowering costs.
[0046] As one possible implementation, the user can drag the mouse to select a specific area on the display plane. Based on the user's mouse selection, a first target area on the display plane can be determined. Mouse operations can be divided into pressing, moving, and releasing, etc. The coordinates can be recorded once when the mouse is pressed and a second time when it is released. The first target area can be determined using these two coordinates.
[0047] Once the first target region is determined, the 3D coordinates of the target's vertices can be obtained in the world coordinate system based on perspective projection transformation, the positions of the virtual camera, the positions of each first target pixel in the first target region, and the target 3D model. The position of the virtual camera can be a pre-set 3D coordinate system in the world coordinate system. In the world coordinate system, the screen plane containing the first target region lies between the virtual camera and the target 3D model.
[0048] One possible implementation is based on perspective projection transformation. For each first pixel in the first target region, in the world coordinate system, a ray is drawn from the position of the virtual camera through that first pixel, and the vertex on the target 3D model that first contacts the ray is taken as the target 3D vertex. In this way, the target 3D vertex can be quickly determined.
[0049] As another possible implementation, it can be achieved through... Figure 3 The method used to obtain the target's 3D vertices ensures effective scaling. Please refer to [the relevant documentation / reference]. Figure 3 , Figure 3 for Figure 2 A flowchart illustrating the sub-steps included in step S120. In this embodiment, step S120 may include sub-steps S121 to S124.
[0050] Sub-step S121: Based on perspective projection transformation, in the world coordinate system, according to the position of the virtual camera and the position of each first target pixel, obtain the first information of the candidate three-dimensional vertex corresponding to each first target pixel.
[0051] In this embodiment, based on perspective projection transformation, for each first pixel in the first target region, a ray is drawn from the position of the virtual camera through the first pixel in the world coordinate system, and the vertex on the target 3D model that first contacts the ray is taken as a candidate 3D vertex. That is, the projection point of the candidate 3D vertex on the plane where the first target region is located is the corresponding first target pixel. The first information of the candidate 3D vertex may include the 3D position information (i.e., 3D coordinates) and color information of the candidate 3D vertex on the target 3D model. The coordinates and color information of each vertex on the target 3D model can be preset.
[0052] Sub-step S122: Based on the first information of each candidate three-dimensional vertex, obtain the second information of the target two-dimensional vertex.
[0053] Having obtained all candidate 3D vertices, for each candidate 3D vertex, perspective projection can be used to project it backwards onto the plane containing the target region to obtain the target 2D vertex corresponding to that candidate 3D vertex. The second information of the target 2D vertex includes 2D position information (i.e., 2D coordinates) and the color information of the corresponding candidate 3D vertex.
[0054] Sub-step S123: Based on the second information of the target two-dimensional vertex, determine the two-dimensional coordinates of the two-dimensional edge vertex from the obtained target two-dimensional vertex through edge detection.
[0055] Having obtained the second information of each target 2D vertex, the color information of each target 2D vertex can be converted to grayscale. The resulting grayscale value is between 0 and 255. Data with grayscale values outside this range is truncated. The grayscale conversion can be performed using the following formula:
[0056] Grayi=Ri×0.299+Gi×0.587+Bi×0.114
[0057] Where Grayi represents the grayscale information of the i-th target 2D vertex, Ri represents the grayscale value of the i-th target 2D vertex in the red channel, Gi represents the grayscale value of the i-th target 2D vertex in the green channel, and Bi represents the grayscale value of the i-th target 2D vertex in the blue channel.
[0058] Next, filtering can be performed on each target 2D vertex based on its grayscale value. For example, filtering can be performed based on the grayscale information of the surrounding 3x3 area of the target 2D vertex. In the filtering operation, convolutions are performed along the X-axis and Y-axis respectively to filter the acquired grayscale information. In this way, the information can be simplified while reducing the impact of noise.
[0059] After filtering, gradient detection can be performed using edge detection operators. For example, it can be done according to the formula... Calculate the gradient, where R i " represents the gradient information of the i'-th target 2D vertex, R i R represents the grayscale information of the i-th target 2D vertex after filtering. i G i This represents the value obtained by multiplying the grayscale information of the i-th target 2D vertex after filtering by the corresponding value of the edge detection operator, where n represents the size of the detection operator. The calculated value is processed to be within the range of 0 to 255. Gradient detection can be used to obtain the magnitude of the vertex gradient within the grayscale range of 0 to 255, thereby determining the specific edge vertex; that is, determining the 2D edge vertex from the target 2D vertex.
[0060] Sub-step S124: The vertex projected onto the target 3D model within the second target region corresponding to the determined 2D edge vertex is taken as the target 3D vertex.
[0061] Given the two-dimensional edge vertices, a second target region can be determined on the screen, where the edge pixels of this second target region include at least a portion of the aforementioned two-dimensional edge vertices. For example, the region enclosed by the determined two-dimensional edge vertices can be directly used as the second target region. Based on perspective projection transformation, and according to the position of the virtual camera and the three-dimensional coordinates of the vertices of the target 3D model, it can be analyzed which vertices on the target 3D model have projections within the second target region, and these vertices are used as the target 3D vertices. That is, based on perspective projection transformation, each second target pixel within the second target region is projected onto the target 3D model, and the projected points are the target 3D vertices. The pixels in the second target region are the second target pixels. In this way, the coordinates of the target 3D vertices can be obtained, and the obtained target 3D vertices form a complete region on the target 3D model, thus minimizing the possibility of some vertices in one region being scaled while others are not during subsequent scaling processing.
[0062] As one possible implementation method, it can be achieved through Figure 4 The target scaling information is obtained using the method shown. Please refer to... Figure 4 , Figure 4 for Figure 2 A flowchart illustrating the sub-steps included in step S130. In this embodiment, step S130 may include sub-steps S131 to S134.
[0063] Sub-step S131: Obtain the three-dimensional coordinates of the center point corresponding to the three-dimensional vertex of the target.
[0064] In this embodiment, each target 3D vertex can be directly analyzed to determine the center point corresponding to the obtained target 3D vertex. That is, the center point is located at the center of the obtained target 3D vertex.
[0065] Alternatively, the center of the first target region can be determined, and then the center can be projected back onto the target 3D model, with the obtained projection point serving as the center point.
[0066] Alternatively, it can also be done through Figure 5 The center point is obtained as shown. Please refer to... Figure 5 , Figure 5 for Figure 4 A flowchart illustrating the sub-steps included in neutron step S131. In this embodiment, sub-step S131 may include sub-steps S1311 to S1313.
[0067] Sub-step S1311: Obtain the two-dimensional coordinates of the two-dimensional edge vertices.
[0068] Wherein, the two-dimensional edge vertex is the edge vertex among the target two-dimensional vertices, and the target two-dimensional vertex is the point on the plane where the first target pixel is first back-projected onto the target three-dimensional model and then projected onto the plane where the first target region is located. The specific method of obtaining the two-dimensional coordinates of the two-dimensional edge vertex can be referred to the detailed description of sub-steps S121 to S123 above, and will not be repeated here.
[0069] It is worth noting that, in passing Figure 3 When the target 3D vertex is obtained in the manner shown, the 2D coordinates of the 2D edge vertices obtained through sub-step S123 can be directly obtained. When the target 3D vertex is obtained through other methods, the 2D coordinates of the 2D edge vertices can be obtained by executing sub-steps S121 to S123.
[0070] Sub-step S1312: Based on the two-dimensional coordinates of the two-dimensional edge vertices, obtain the coordinates of the center of the second target region enclosed by the two-dimensional edge vertices.
[0071] In this embodiment, a second target region can be determined based on the obtained two-dimensional edge vertices, and then the second target region can be analyzed to obtain the two-dimensional coordinates of the center of the region.
[0072] As one possible implementation, to improve the accuracy of the center of the obtained second target region, the coordinates of the center can be obtained by calculating the center distance of the second target region based on the two-dimensional coordinates of the two-dimensional edge vertices. The formula for calculating the center distance is:
[0073]
[0074]
[0075] array1(x,y) represents the pixel value at pixel (x,y) in the second target region.
[0076] Sub-step S1313: Obtain the three-dimensional coordinates of the center point based on the coordinates of the center.
[0077] Optionally, if the two-dimensional coordinates of the center are obtained, the center can be projected backwards onto the target three-dimensional model based on the position of the virtual camera and the coordinates of the center, according to the transmission projection transformation, so as to determine the three-dimensional coordinates of the center point.
[0078] Alternatively, it can also be done through Figure 6The three-dimensional coordinates of the center point are obtained as shown. Please refer to... Figure 6 , Figure 6 for Figure 5 A flowchart illustrating the sub-steps included in neutron step S1313. In this embodiment, sub-step S1313 may include sub-steps S13131 to S13133.
[0079] Sub-step S13131: Obtain the three-dimensional coordinates of the three-dimensional edge vertex based on the two-dimensional coordinates of the two-dimensional edge vertex.
[0080] The three-dimensional edge vertex is the point on the target three-dimensional model projected backward from the two-dimensional edge vertex. That is, based on perspective projection transformation, the two-dimensional edge vertex is projected backward onto the target three-dimensional model, and the projected vertex is taken as the three-dimensional edge vertex.
[0081] Sub-step S13132: Construct the target plane based on the three-dimensional coordinates of the three-dimensional edge vertices.
[0082] Sub-step S13133: Based on perspective projection transformation, the three-dimensional coordinates of the center point are obtained by projecting the center onto the target plane according to the two-dimensional coordinates of the center.
[0083] A ray can be drawn from the virtual camera's position, passing through the center, and the point of contact between this ray and the target plane can be taken as the center point. In this way, the three-dimensional coordinates of the center point can be obtained.
[0084] Sub-step S132: Obtain the first vector based on the three-dimensional coordinates of any one of the target three-dimensional vertices and the three-dimensional coordinates of the center point.
[0085] Given the target 3D vertex and center point, a first vector can be constructed based on the 3D coordinates of the target 3D vertex and the center point. This first vector can be a vector pointing from the target 3D vertex to the center point, or a vector pointing from the center point to the target 3D vertex; the specific vector can be set according to actual needs.
[0086] Sub-step S133: Obtain the second vector determined based on the movement of the mouse on the plane where the first target area is located.
[0087] Optionally, the user can control the mouse to perform sequential press and release operations. The coordinates can be recorded once when the mouse is pressed (i.e., the coordinates on the screen when the mouse is pressed) and again when the mouse is released. Based on these two coordinates, the second vector can be determined. The second vector can be a vector pointing from the coordinates on the screen when the mouse is pressed to the coordinates when the mouse is released.
[0088] It is understandable that, when the first target area is determined based on the user's mouse movement and release operations, the first target area can be determined based on the first received mouse movement and release operations, and the second vector can be determined based on the later received mouse movement and release operations.
[0089] Sub-step S134: Determine the target scaling information based on the first vector and the second vector.
[0090] Optionally, the first and second vectors can be processed into the same space, and then the target scaling information can be determined based on the projection length of the processed vector in the direction of the other vector. For example, the scaling ratio is the sum of the product of the projection length and a preset constant, and a preset value.
[0091] Optionally, the scaling method can be preset to either overall scaling or scaling each axis individually.
[0092] Alternatively, the user can perform an operation before scaling, and the scaling method (whether to scale the entire system or scale each axis individually) can be determined based on the user's action. For example, given the 3D coordinates of the center point, an XYZ coordinate system can be established and displayed at the location indicated by those coordinates. The scaling method to be used is determined based on the mouse click position. When the mouse click position is at the origin of the XYZ coordinate system, it can be determined that overall scaling is used; when the mouse click position is at any axis of the XYZ coordinate system, it can be determined that scaling is performed on each axis individually.
[0093] To reduce user operations and improve user experience, when the second vector is determined based on mouse press and release operations, the scaling method can also be determined directly based on the coordinates of the mouse press operation used to determine the second vector in the above-mentioned XYZ coordinate system or one of its axes.
[0094] As one possible implementation, during overall scaling, the first vector can be projected onto the screen containing the first target area to obtain a third vector. It is understood that the projection method used is a transmission projection transformation. Then, based on the projection length of the second vector along the direction of the third vector, the target scaling information is calculated.
[0095] Optionally, the scaling ratio represented by the target scaling information is 1+m1, where, C represents a preset constant that indicates the sensitivity of mouse zoom control; it is usually set to a very small number. Represents the second vector; This represents the third vector.
[0096] During overall scaling, upon obtaining the target scaling information, the 3D coordinates of each target 3D vertex can be scaled according to this target scaling information. This process can be represented as:
[0097]
[0098] Here, array2(x,y,z) represents the 3D coordinates of the target 3D vertex after scaling, and (x,y,z) represents the 3D coordinates of the target 3D vertex before scaling.
[0099] As another possible implementation, when scaling individually for each axis, the first component of the first vector on each axis can be projected onto the plane containing the first target region to obtain a first projection component; then, the scaling ratio corresponding to that axis can be calculated based on the projection length of the second vector in the direction of the first projection component. The target scaling information includes the scaling ratios corresponding to each of the three axes.
[0100] Optionally, the target scaling information includes scaling ratios for the three axes X, Y, and Z, respectively: 1+mx, 1+my, and 1+mz. This represents the projection vector of the X-axis component of the first vector onto the plane containing the first target region. Represents the second vector; This represents the projection vector of the Y-axis component of the first vector onto the plane containing the first target region. This represents the projection vector of the Z-axis component of the first vector onto the plane containing the first target region.
[0101] When scaling is performed individually for each axis, upon obtaining the target scaling information, the 3D coordinates of each target 3D vertex can be scaled according to this target scaling information. This process can be represented as:
[0102]
[0103] Here, array3(x,y,z) represents the three-dimensional coordinates of the target three-dimensional vertex after scaling, and (x,y,z) represents the three-dimensional coordinates of the target three-dimensional vertex before scaling.
[0104] Alternatively, as a possible implementation, each time scaling is performed, the user needs to specify the scaling area and scaling ratio, and then execute steps S110 to S140 as described above based on the user's operation. That is, regardless of whether scaling is performed on a local model of the same model, steps S110 to sub-step S140 need to be executed.
[0105] Alternatively, as another possible implementation, before each scaling operation, it can be determined whether the current scaling is the first time scaling a local model of the target 3D model corresponding to the first target region. The specific determination method can be set according to actual needs.
[0106] For example, following the example above where the scaling method is determined based on the mouse press position and the XYZ coordinate system established at the center point of the 3D model, if the XYZ coordinate system is displayed, and the mouse press position is not on the XYZ coordinate system, then it can be determined that this time the scaling operation is performed on a local model of the 3D model corresponding to a new region.
[0107] If the mouse is pressed at the origin of the XYZ coordinate system or on another axis, meaning the mouse is always pressed on the XYZ coordinate system, it means that the zoom is always applied to this area. This indicates that the user is continuously zooming on the same part of the same model, and this is not the first time that the local model of the target 3D model corresponding to the first target area has been zoomed.
[0108] If it is the first time, you can jump to step S110, take the rectangle formed by the two coordinate points of the mouse being pressed and released as the new first target area, and execute steps S120 to S140.
[0109] If it is not the first time, then it is only necessary to obtain the target scaling information again, and then scale the coordinates of the three-dimensional position information of each of the target three-dimensional vertices again according to the target scaling information obtained again.
[0110] The target scaling information can be obtained again in the following way: First, obtain the first vector obtained when scaling the local model corresponding to the first target region for the first time; then, obtain the second vector determined based on the current mouse movement on the plane where the first target region is located; based on the newly obtained second vector and the first vector, calculate the target scaling information required this time. In this way, scaling can be achieved quickly without having to calculate the 3D coordinates of the center point and the 3D coordinates of the vertices of the target to be scaled again.
[0111] It is worth noting that the above descriptions of the available scaling methods, specific selection methods for scaling methods, and methods for determining target scaling information are merely illustrative examples. The scaling methods and target scaling information used can also be determined according to actual needs, and no specific limitations are imposed here.
[0112] In this embodiment, based on back projection, projection, and edge detection, the boundary region corresponding to the mouse selection area is obtained, and then the model local to be projected into the region is scaled. Furthermore, the vector formed by the vertex to be scaled in the world coordinate system and a center point is projected onto a two-dimensional plane on the screen, and then the scaling ratio is determined by the mouse movement vector and the aforementioned vector projected on the screen.
[0113] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a local scaling processing device 200 for a three-dimensional model is given below. Optionally, the local scaling processing device 200 for the three-dimensional model can adopt the above-described... Figure 1 The device structure of the electronic device 100 shown. Further, please refer to... Figure 7 , Figure 7 This is a block diagram of a local scaling processing device 200 for a 3D model provided in this embodiment. It should be noted that the basic principle and technical effects of the local scaling processing device 200 for a 3D model provided in this embodiment are the same as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. In this embodiment, the local scaling processing device 200 for a 3D model may include: a region determination module 210, a vertex determination module 220, a scaling information determination module 230, and a processing module 240.
[0114] The region determination module 210 is used to obtain a first target region selected on the display screen. The first target region is a zoom-specified region.
[0115] The vertex determination module 220 is used to obtain the three-dimensional coordinates of the target three-dimensional vertices in the world coordinate system based on perspective projection transformation, according to the position of the virtual camera, the first target region, and the target three-dimensional model. The target three-dimensional vertices are the vertices on the target three-dimensional model that need to be scaled based on the first target region.
[0116] The scaling information acquisition module 230 is used to acquire target scaling information.
[0117] The processing module 240 is used to scale the three-dimensional coordinates of each of the target three-dimensional vertices according to the target scaling information, so as to complete the local scaling processing of the target three-dimensional model.
[0118] Optionally, in this embodiment, when scaling the local model of the target 3D model corresponding to the first target region is not being scaled for the first time, the scaling information acquisition module 230 is used to acquire target scaling information again. The scaling information acquisition module 230 can acquire the target scaling information again by: acquiring a first vector obtained from the first scaling process; acquiring a second vector determined based on the current mouse movement on the plane where the first target region is located; and calculating the target scaling information required for this operation based on the newly acquired second vector and the first vector. The processing module 240 is further used to scale the 3D position information coordinates of each target 3D vertex again based on the re-acquired target scaling information.
[0119] Optionally, the above modules can be stored in the form of software or firmware. Figure 1 The memory 110 shown is either stored in or embedded in the operating system (OS) of the electronic device 100, and can be used by... Figure 1 The processor 120 executes the program. Meanwhile, the data and program code required to execute the above modules can be stored in the memory 110.
[0120] This application embodiment also provides a readable storage medium storing a computer program thereon, which, when executed by a processor, implements the local scaling processing method for the three-dimensional model.
[0121] In summary, this application provides a method, apparatus, electronic device, and readable storage medium for local scaling of a 3D model. When a first target region selected on a display screen as the area to be scaled is obtained, based on perspective projection transformation, in the world coordinate system, the 3D coordinates of the target 3D vertices are obtained according to the position of the virtual camera, the positions of each first target pixel in the first target region, and the target 3D model. These target 3D vertices are the vertices on the target 3D model that need to be scaled, determined based on the first target region. Finally, the 3D coordinates of each target 3D vertex are scaled according to the obtained target scaling information to complete the local scaling of the target 3D model. This allows for local scaling of the model, reducing the losses caused by model segmentation for detailed scaling and lowering costs.
[0122] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0123] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0124] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0125] The above description is merely an optional embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for local scaling of a three-dimensional model, characterized in that, The method includes: Obtain the first target area selected on the display screen, wherein the first target area is the zoom specified area; Based on perspective projection transformation, in the world coordinate system, according to the position of the virtual camera, the position of each first target pixel in the first target region and the target three-dimensional model, the three-dimensional coordinates of the target three-dimensional vertices are obtained, wherein the target three-dimensional vertices are the vertices on the target three-dimensional model that need to be scaled based on the first target region; Obtain target scaling information; The three-dimensional coordinates of each of the target three-dimensional vertices are scaled according to the target scaling information to complete the local scaling of the target three-dimensional model; The step of obtaining the 3D coordinates of the target's 3D vertices based on perspective projection transformation in the world coordinate system, according to the position of the virtual camera, the position of each first target pixel in the first target region, and the target's 3D model, includes: Based on perspective projection transformation, in the world coordinate system, according to the position of the virtual camera and the position of each first target pixel, the first information of the candidate three-dimensional vertex corresponding to each first target pixel is obtained. The projection point of the candidate three-dimensional vertex on the plane where the first target region is located is the corresponding first target pixel. The first information includes three-dimensional position information and color information. The candidate three-dimensional vertex is on the target three-dimensional model. Based on the first information of each candidate three-dimensional vertex, the second information of the target two-dimensional vertex is obtained, wherein the target two-dimensional vertex is the point on the plane where the candidate three-dimensional vertex is projected onto the target region, and the second information includes two-dimensional position information and the color information of the corresponding candidate three-dimensional vertex; Based on the second information of the target two-dimensional vertex, the two-dimensional coordinates of the two-dimensional edge vertices are determined from the obtained target two-dimensional vertex through edge detection; The vertices projected onto the target 3D model within the second target region corresponding to the determined 2D edge vertices are taken as the target 3D vertices.
2. The method according to claim 1, characterized in that, The process of obtaining target scaling information includes: Obtain the three-dimensional coordinates of the center point corresponding to the three-dimensional vertex of the target; The first vector is obtained based on the three-dimensional coordinates of any three-dimensional vertex of the target and the three-dimensional coordinates of the center point; Obtain a second vector based on the movement of the mouse on the plane containing the first target area; The target scaling information is determined based on the first vector and the second vector.
3. The method according to claim 2, characterized in that, Obtaining the three-dimensional coordinates of the center point corresponding to the target three-dimensional vertex includes: Obtain the two-dimensional coordinates of the two-dimensional edge vertices, wherein the two-dimensional edge vertices are the edge vertices in the target two-dimensional vertices, and the target two-dimensional vertices are the points on the plane where the first target pixel is first back-projected onto the target three-dimensional model and then projected onto the plane where the first target region is located. Based on the two-dimensional coordinates of the two-dimensional edge vertices, obtain the coordinates of the center of the second target region enclosed by the two-dimensional edge vertices; Based on the coordinates of the center, obtain the three-dimensional coordinates of the center point.
4. The method according to claim 3, characterized in that, The step of obtaining the coordinates of the center of the second target region enclosed by the two-dimensional edge vertices based on their two-dimensional coordinates includes: The coordinates of the center are obtained by calculating the center distance of the second target region based on the two-dimensional coordinates of the two-dimensional edge vertices.
5. The method according to claim 3, characterized in that, Obtaining the three-dimensional coordinates of the center point based on the coordinates of the center includes: Based on the two-dimensional coordinates of the two-dimensional edge vertices, the three-dimensional coordinates of the three-dimensional edge vertices are obtained, wherein the three-dimensional edge vertices are points projected back from the two-dimensional edge vertices onto the target three-dimensional model; Construct the target plane based on the three-dimensional coordinates of the three-dimensional edge vertices; Based on perspective projection transformation, the three-dimensional coordinates of the center point are obtained by projecting the center onto the target plane according to the two-dimensional coordinates of the center.
6. The method according to any one of claims 2-5, characterized in that, Determining the target scaling information based on the first vector and the second vector includes: When performing overall scaling, the first vector is projected onto the plane where the first target area is located to obtain a third vector. The target scaling information is calculated based on the projection length of the second vector onto the direction of the third vector. When scaling is performed individually for each axis, the first component of the first vector on each axis is projected onto the plane where the first target region is located to obtain the first projection component. The scaling ratio corresponding to the axis is calculated based on the projection length of the second vector in the direction of the first projection component. The target scaling information includes the scaling ratios corresponding to each of the three axes.
7. The method according to any one of claims 2-5, characterized in that, The method further includes: Determine whether this is the first time that a local model of the target 3D model corresponding to the first target region has been scaled; If so, proceed with the following steps: Obtain the first target area selected on the display screen; If not, the target scaling information is obtained again, and the three-dimensional position information coordinates of each of the target three-dimensional vertices are scaled again according to the target scaling information obtained again. The step of obtaining the target scaling information again includes: Obtain the first vector obtained from the first scaling process; Obtain the second vector determined based on the current mouse movement on the plane containing the first target area; Based on the newly obtained second vector and the first vector, the target scaling information required for this operation is calculated.
8. A local scaling processing device for a three-dimensional model, characterized in that, The device includes: The region determination module is used to obtain the first target region selected on the display screen, wherein the first target region is a zoom-specified region; The vertex determination module is used to obtain the three-dimensional coordinates of the target three-dimensional vertices in the world coordinate system based on perspective projection transformation, according to the position of the virtual camera, the first target region, and the target three-dimensional model. The target three-dimensional vertices are the vertices on the target three-dimensional model that need to be scaled based on the first target region. The vertex determination module is further configured to, based on perspective projection transformation, in the world coordinate system, obtain first information of candidate 3D vertices corresponding to each first target pixel according to the position of the virtual camera and the position of each first target pixel, wherein the projection point of the candidate 3D vertex on the plane where the first target region is located is the corresponding first target pixel, and the first information includes 3D position information and color information, and the candidate 3D vertex is on the target 3D model; and obtain second information of target 2D vertices according to the first information of each candidate 3D vertex, wherein the target 2D vertex is the point on the plane where the target region is located projected from the candidate 3D vertex, and the second information includes 2D position information and the color information of the corresponding candidate 3D vertex; and determine the 2D coordinates of 2D edge vertices from the obtained target 2D vertices through edge detection according to the second information of the target 2D vertices; and take the vertices projected onto the target 3D model in the second target region corresponding to the determined 2D edge vertices as the target 3D vertices; The scaling information acquisition module is used to obtain target scaling information; The processing module is used to scale the three-dimensional coordinates of each of the target three-dimensional vertices according to the target scaling information, so as to complete the local scaling processing of the target three-dimensional model.
9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the local scaling processing method for a three-dimensional model as described in any one of claims 1-7.
Citation Information
Patent Citations
Model scaling method and device in virtual space
CN114494653A