Rotation interaction control rendering method, computer equipment and readable storage medium
By obtaining the coordinate vectors of the screen camera and 3D model in the 3D printing slicing software, calculating the line of sight vector and dynamic transformation matrix, and updating the point data of the manipulating model to achieve dynamic rendering, it solves the operation inconvenience caused by static rotation of interactive controls, and improves the Speed and convenience of 3D model slice data preparation.
Patent Information
- Application Number
- CN202410985180.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-11-22
AI Technical Summary
The rotation interactive controls in the existing 3D printing slicing software are static, resulting in poor user experience in rotating 3D models, reducing the speed and convenience of slice data preparation.
By obtaining the coordinate vectors of the screen camera and 3D model in virtual three-dimensional space, calculating the line of sight vector and dynamic transformation matrix, updating the point data of the manipulation model to realize dynamic rendering of the manipulation model, making it follow the changes in the viewing angle of the screen camera and improving user rotation Speed and convenience of operation.
It improves the speed and convenience of users rotating 3D models, facilitates the preparation process of 3D model slice data, and enhances the operation experience.
Smart Images

Figure CN119006677A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of 3D printing, and in particular to a rendering method of a rotating interactive control, a computer device, and a readable storage medium. Background Art
[0002] The 3D printing slicing software will prepare the 3D model slicing data for preview. The workflow includes rotating the 3D model displayed on the computer device, so as to adjust the 3D model to a certain angle in the three-dimensional space according to the user's wishes, so as to facilitate the subsequent preview and slicing work.
[0003] In the process of rotating the 3D model, a virtual three-dimensional rotation interactive control is attached to the 3D model, and the user operates the 3D model through the control. In the related art, the rotation interactive controls of the 3D printing slice software are all static, resulting in a poor user experience of the 3D model operation, and reducing the speed and convenience of the user in preparing the 3D model slice data. Summary of the invention
[0004] In view of this, the present application provides a rendering method, a computer device and a readable storage medium for a rotating interactive control, which improves the speed and convenience of users preparing 3D model slice data.
[0005] In a first aspect, an embodiment of the present application provides a method for rendering a rotating interactive control, wherein the rotating interactive control is used to control the rotation of a 3D model in a virtual three-dimensional space, and the rotating interactive control includes a main control model and a manipulation model for manipulating the main control model, and the method includes:
[0006] Obtaining a first coordinate vector of a position of a screen camera in the virtual three-dimensional space and a second coordinate vector of a center point of a bounding box of the 3D model;
[0007] Calculate a sight line vector according to the first coordinate vector and the second coordinate vector;
[0008] Calculating, according to the sight line vector, a dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera;
[0009] The point data of the manipulation model is updated according to the dynamic transformation matrix, and the manipulation model is rendered after the update.
[0010] In a second aspect, an embodiment of the present application provides a computer device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be executed on the processor, and when the programs or instructions are executed by the processor, the steps of the method of the first aspect are implemented.
[0011] In a third aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method of the first aspect are implemented.
[0012] In an embodiment of the present application, the screen of the computer device is regarded as a camera, and a first coordinate vector of the position of the screen camera in the virtual three-dimensional space is obtained, and a second coordinate vector of the center point of the bounding box of the 3D model that the user wants to rotate is obtained. According to the first coordinate vector and the second coordinate vector, the sight line vector is calculated, and the dynamic transformation matrix of the manipulation model following the camera angle of view of the screen camera is calculated according to the sight line vector. The point data of the manipulation model is updated according to the dynamic transformation matrix, that is, the position of the manipulation model is updated according to the dynamic transformation matrix, and the manipulation model is rendered after the update. In an embodiment of the present application, by optimizing the rendering process of the manipulation model of the rotating interactive control, the position of the manipulation model can be dynamically updated and rendered in real time following the camera angle of view when the camera angle of the screen camera moves, thereby improving the speed and convenience of the user's rotation operation of the 3D model, and facilitating the user to prepare 3D model slice data.
[0013] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0015] Figure 1 A schematic diagram of the structure of a rotation interaction control in an embodiment of the present application is shown;
[0016] Figure 2 A schematic diagram showing a flow chart of a method for rendering a rotating interactive control according to an embodiment of the present application;
[0017] Figure 3 A schematic diagram showing a sight line vector of an embodiment of the present application is shown;
[0018] Figure 4 A structural block diagram of a computer device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0019] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0020] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0021] In conjunction with the accompanying drawings, the rendering method of the rotating interactive control, the computer device and the readable storage medium provided by the embodiments of the present application are described in detail through specific embodiments and their application scenarios. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0022] In three-dimensional graphics rendering, if the screen of a computer device is regarded as a camera, the rotation interactive controls of the 3D printing slicing software in the related art are static, and the rotation interactive controls will not be dynamically updated and rendered following the camera angle of the screen camera, which brings inconvenience to users in preparing 3D model slicing data.
[0023] In order to improve the speed and convenience of users rotating 3D models in the process of preparing 3D model slice data, the present application embodiment provides a rendering method of a rotating interactive control, which can optimize the rendering of the rotating interactive control to enable it to dynamically update and render in real time following the camera perspective when the camera perspective moves. The rotating interactive control is used to control the rotation of the 3D model in a virtual three-dimensional space, and the rotating interactive control includes a main control model and a manipulation model for manipulating the main control model.
[0024] In one embodiment of the present application, multiple main control models of the rotating interactive control are generated, and the multiple main control models respectively correspond to different planes of the virtual three-dimensional space; manipulation models corresponding to different main control models are generated or loaded; wherein, if the manipulation model is a regular shape, the manipulation model is generated; if the manipulation model is an irregular shape, the pre-generated manipulation model is loaded.
[0025] In this embodiment, the virtual three-dimensional space includes three planes, and multiple main control models are generated, corresponding to different planes of the virtual three-dimensional space, that is, the rotation of the 3D model in different directions is controlled respectively. The shape of the main control model can be a circular ring, an elliptical ring, a square ring, etc., which is not specifically limited in this application. For example, Figure 1 As shown, taking the XYZ axis of the Cartesian coordinate system as an example, corresponding main control models are generated in the YZ plane, XZ plane, and XY plane which are perpendicular to the X axis, Y axis, and Z axis respectively, including main control model 111, main control model 112, and main control model 113, and the main control model is an elliptical ring.
[0026] Generate or load multiple manipulation models of the rotation interactive control, one manipulation model corresponds to one main control model, and is used to manipulate the corresponding main control model. The shape of the manipulation model can be circular, elliptical, triangular, square, etc., which is not specifically limited in this application. For example, Figure 1 As shown, the main control model 111, the main control model 112 and the main control model 113 correspond to the manipulation model 121, the manipulation model 122 and the manipulation model 123 respectively, and the manipulation model is an ellipse.
[0027] It should be noted that if the manipulation model uses relatively regular geometric figures, it will not take up much time and computing resources, so the manipulation model can be generated directly; if the manipulation model uses complex irregular geometric figures, the manipulation model should be modeled in advance and loaded when the 3D printing slicing software is started to reduce time and reduce computing resources.
[0028] The embodiment of the present invention provides a rendering method for a rotating interactive control, such as Figure 2 As shown, the method includes:
[0029] S201, obtaining a first coordinate vector of the position of the screen camera in the virtual three-dimensional space and a second coordinate vector of the center point of the bounding box of the 3D model.
[0030] The rendering method of the rotating interactive control can be applied to slicing software. The slicing software can be run in a computer device, including but not limited to a personal terminal, such as a computer, or a cloud server.
[0031] In this step, the corresponding screen of the computer device is regarded as a camera, and the first coordinate vector of the position of the screen camera in the virtual three-dimensional space is obtained. The first coordinate vector is recorded as camera_position, and the data type of the first coordinate vector is a three-dimensional coordinate vector. Also, the 3D model that the user wants to rotate is determined, and the second coordinate vector of the center point of the bounding box of the 3D model is obtained. The second coordinate vector is recorded as model_center, and the data type of the second coordinate vector is a three-dimensional coordinate vector. The center point of the bounding box of the 3D model to be rotated is used as the origin of the coordinate system to render the rotation interactive control. It can be understood that if the rendering method of the rotation interactive control is run in the server, the screen corresponding to the cloud server can be the screen that the cloud server communicates with, such as the screen that the terminal that communicates with the cloud server needs to display information, such as a mobile phone, a computer, etc.
[0032] In one embodiment of the present application, obtaining a first coordinate vector of the position of a screen camera in a virtual three-dimensional space includes: when the slicing software is started, obtaining the initial position of the screen camera in the virtual three-dimensional space, and using the coordinate vector of the initial position as the first coordinate vector; or, after the camera viewing angle of the screen camera changes, obtaining the current position of the screen camera in the virtual three-dimensional space, and using the coordinate vector of the current position as the first coordinate vector.
[0033] In this embodiment, the timing for performing dynamic rendering of the rotating interactive control following the camera angle of the screen camera may be when the slicing software is started. When the slicing software is started, a default initial position of the screen camera in the virtual three-dimensional space is obtained, and the coordinate vector of the initial position is used as the first coordinate vector camera_position.
[0034] The timing for the rotation interactive control to follow the dynamic rendering of the camera angle of the screen camera can also be after each change of the camera angle of the screen camera. Each time the rotation control is rendered, that is, each time the camera angle of the screen camera changes, the current position of the screen camera in the three-dimensional space is obtained, and the coordinate vector of the current position is used as the first coordinate vector.
[0035] In an embodiment of the present application, when the slicing software is started and the camera angle of the screen camera changes, the position of the screen camera in the virtual three-dimensional space is determined, and the rotating interactive control is updated and rendered based on the position, so that the rotating interactive control changes dynamically with the camera angle of the screen camera, thereby improving the user's operation effect on the 3D model.
[0036] In one embodiment of the present application, obtaining a second coordinate vector of a center point of a bounding box of a 3D model in a virtual three-dimensional space includes: if there is one 3D model to be rotated, using the coordinate vector of the center point of the bounding box of the 3D model as the second coordinate vector; or, if there are multiple 3D models to be rotated, determining a common bounding box of the multiple 3D models, and using the coordinate vector of the center point of the common bounding box as the second coordinate vector.
[0037] In this embodiment, if the user needs to rotate only one 3D model, the coordinate vector of the center point of the bounding box of this 3D model is used as the second coordinate vector model_center; if the user needs to rotate multiple 3D models, the common bounding box of these 3D models is determined, and the coordinate vector of the center point of the common bounding box is used as the second coordinate vector model_center.
[0038] In one embodiment of the present application, rendering the manipulated model includes: using the center point of a bounding box of a 3D model or the center points of bounding boxes of multiple 3D models as the origin of a coordinate system to render the manipulated model. In this embodiment, the manipulated model is rendered using the center point of the bounding box of the 3D model or the center points of the bounding boxes of multiple 3D models to be operated as the origin of the coordinate system.
[0039] In the embodiment of the present application, a rotational interactive control is rendered by using the center point of the bounding box of a 3D model or multiple 3D models as the origin of the coordinate system, so that when a single model or multiple models are selected, the rotational interactive control changes dynamically with the camera perspective of the screen camera, thereby improving the user's operation effect on the 3D model.
[0040] S202, calculating a sight line vector according to the first coordinate vector and the second coordinate vector.
[0041] In this step, the sight line vector is calculated according to the first coordinate vector and the second coordinate vector, such as Figure 3 As shown, the sight vector represents the vector from the screen camera position to the center point of the bounding box of the 3D model.
[0042] In one embodiment of the present application, calculating the sight line vector according to the first coordinate vector and the second coordinate vector includes: calculating the difference between the second coordinate vector and the first coordinate vector to obtain the sight line vector.
[0043] In this embodiment, a view vector may be obtained from the first coordinate vector camera_position and the second coordinate vector model_center. The view vector is recorded as view_direction, where view_direction=model_center-camera_position.
[0044] S203, calculating a dynamic transformation matrix for manipulating the model to follow the camera viewing angle of the screen camera according to the sight line vector.
[0045] In this step, a dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera is calculated according to the sight line vector, so that the manipulation model can be updated and rendered according to the dynamic transformation matrix later.
[0046] It should be noted that each time the dynamic transformation matrix is calculated, it is only calculated based on the line of sight vector of the current frame, and has nothing to do with the line of sight vectors of other frames, that is, the amount of change of the line of sight vector is not taken into account.
[0047] S204, updating the point data of the manipulation model according to the dynamic transformation matrix, and rendering the manipulation model after the update.
[0048] In this step, the point data of the manipulation model is updated according to the dynamic transformation matrix obtained in step 203, that is, the position of the manipulation model is updated according to the dynamic transformation matrix, and the manipulation model is rendered after the update.
[0049] It should be noted that the point data here include vertex data and edge point data of the manipulation model, and updating the point data of the manipulation model refers to transforming the coordinates of the point data using a dynamic transformation matrix.
[0050] The rendering logic of the rotation interactive control is different from that of the 3D model. The rotation interactive control needs to follow the camera angle changes of the screen camera in real time, so it needs to be rendered separately from the 3D model. That is, before the formal rendering, update the point data of the manipulation model of the rotation interactive control so that it follows the camera angle changes of the screen camera, and then enter the formal rendering process.
[0051] An embodiment of the present application provides a solution for dynamically rendering the position of a manipulation model of a rotating interactive control in real time following the viewing angle of a screen camera. By optimizing the rendering process of the manipulation model of the rotating interactive control, the position of the manipulation model can be dynamically updated and rendered in real time following the viewing angle of the screen camera when the viewing angle of the screen camera moves, thereby improving the speed and convenience of the user's rotational operation of the 3D model and facilitating the user's preparation of 3D model slicing data.
[0052] In one embodiment of the present application, the manipulation model includes at least one of the following: a manipulation model corresponding to a first coordinate axis of the virtual three-dimensional space, a manipulation model corresponding to a second coordinate axis of the virtual three-dimensional space, and a manipulation model corresponding to a third coordinate axis of the virtual three-dimensional space.
[0053] In this embodiment, the manipulation model that is dynamically updated and rendered in real time following the camera viewing angle includes: a manipulation model corresponding to the first coordinate axis of the virtual three-dimensional space, a manipulation model corresponding to the second coordinate axis of the virtual three-dimensional space, and one or more of the manipulation models corresponding to the third coordinate axis of the virtual three-dimensional space. In the present application, the manipulation model of each coordinate axis can be rendered in sequence for each axis, or the manipulation models of the three axes can be rendered simultaneously. Specifically, if the manipulation model of each axis is rendered in sequence, the dynamic transformation matrix of one axis can be calculated first, and then the manipulation model can be rendered according to the dynamic transformation matrix, and then the manipulation models of the other axes can be rendered in sequence. If the manipulation models of the three axes are rendered at the same time, the dynamic transformation matrix of each axis can be calculated in sequence, or the dynamic transformation matrix of each axis can be calculated at the same time, and the manipulation models of all axes can be rendered according to the dynamic transformation matrix; or the point data of each axis can be calculated and updated in sequence, and then the manipulation models of all axes can be rendered at the same time according to the point data, that is, the present application does not limit how to render the manipulation models at the same time.
[0054] For example, Figure 1 As shown, the first coordinate axis is the X axis, the second coordinate axis is the Y axis, and the third coordinate axis is the Z axis. The manipulation model corresponding to the X axis is the manipulation model 121, the manipulation model corresponding to the Y axis is the manipulation model 122, and the manipulation model corresponding to the Z axis is the manipulation model 123. The one or more manipulation models may be dynamically updated and rendered in real time following the camera viewing angle, thereby improving the flexibility of update rendering.
[0055] In one embodiment of the present application, calculating the dynamic transformation matrix of the camera perspective of the manipulation model following the screen camera according to the sight line vector includes: calculating the dynamic transformation matrices of the camera perspectives of three manipulation models following the screen camera according to the sight line vector respectively;
[0056] Updating the point data of the manipulation model according to the dynamic transformation matrix includes: updating the point data of the three manipulation models respectively according to the dynamic transformation matrices corresponding to the three manipulation models.
[0057] In this embodiment, when the manipulation model includes manipulation models corresponding to the first coordinate axis, the second coordinate axis, and the third coordinate axis, respectively, the dynamic transformation matrices of different manipulation models following the camera perspective of the screen camera are calculated according to the line of sight vector, and then the update point data and rendering of different manipulation models are realized according to the corresponding dynamic transformation matrices.
[0058] Exemplarily, the manipulation model includes a manipulation model 121 corresponding to the X-axis, a manipulation model 122 corresponding to the Y-axis, and a manipulation model 123 corresponding to the Z-axis. Then, the dynamic transformation matrix A1 of the manipulation model 121, the dynamic transformation matrix A2 of the manipulation model 122, and the dynamic transformation matrix A3 of the manipulation model 123 are calculated respectively. Then, the point data of the manipulation model 121 is updated according to the dynamic transformation matrix A1, the point data of the manipulation model 122 is updated according to the dynamic transformation matrix A2, and the point data of the manipulation model 123 is updated according to the dynamic transformation matrix A3.
[0059] It should be noted that, due to the small amount of data, the CPU of the computer device can use the dynamic transformation matrix to update the point data of the manipulation model, and then the GPU uses the existing rendering logic for rendering. Of course, in some embodiments, the GPU can also use the dynamic transformation matrix to update the point data of the manipulation model, and then the GPU uses the existing rendering logic for rendering.
[0060] In the embodiment of the present application, the dynamic transformation matrix is calculated for each of the three manipulation models, thereby realizing the update rendering of the three manipulation models, so that the rotation interactive control can change dynamically with the change of the camera perspective, thereby improving the user operation experience. In addition, the dynamic transformation matrix is calculated for each of the three manipulation models, that is, different data of each axis is calculated independently, so that the rendering between the axes will not affect each other, thereby improving the rendering effect of the rotation interactive control.
[0061] In one embodiment of the present application, the dynamic transformation matrix of the camera viewing angle of the control model to follow the screen camera is calculated according to the sight vector, including:
[0062] According to the sight vector, calculate the movement matrix and rotation matrix of the manipulated model;
[0063] According to the preset scaling matrix, translation matrix and rotation matrix, the dynamic transformation matrix of the camera perspective of the manipulated model is calculated.
[0064] In this embodiment, for any manipulation model, according to the sight vector view_direction, the movement matrix (denoted as translate) and rotation matrix (denoted as rotation) of the manipulation model are calculated in real time. The movement matrix is used to describe the position change of the manipulation model in the virtual three-dimensional space, and the rotation matrix is used to describe the direction or posture change of the manipulation model in the virtual three-dimensional space. Further, a preset scaling matrix (denoted as scale) is obtained, and the preset scaling matrix is used to change the size of the manipulation model to achieve the expansion or reduction of the manipulation model in the X direction, Y direction or Z direction. Then, according to the preset scaling matrix, the movement matrix and the rotation matrix, the dynamic transformation matrix of the manipulation model is calculated. In this embodiment of the present application, precise control of the position, direction or posture and size of the manipulation model is achieved.
[0065] In one embodiment of the present application, the method further includes: obtaining a preset scaling matrix, where the preset scaling matrix is related to the screen pixel ratio of the manipulation model.
[0066] In this embodiment, in the embodiment of the present application, the preset zoom matrix can be determined according to the screen pixel ratio of the manipulation model. For example, taking a 24-inch 1080p standard screen as an example, there are 1920 pixels in the horizontal direction. If the size of the entire rotation interactive control is defined as a certain pixel ratio, such as 100 pixels, then the pixel ratio of the manipulation model can also be defined as a certain pixel amount, such as 20 pixels, and then the preset zoom matrix can be adjusted by the pixel ratio of the manipulation model, which can be 20 / 1920, or 20 / 100.
[0067] Determining the scaling matrix according to the screen pixel ratio of the manipulated model can ensure that the image of the manipulated model can obtain good display effects on different devices while maintaining the original proportion and clarity of the image.
[0068] In one embodiment of the present application, a dynamic transformation matrix of the camera perspective of the manipulation model to follow the screen camera is calculated based on a preset scaling matrix, a movement matrix, and a rotation matrix, including: calculating the product of the preset scaling matrix, the movement matrix, and the rotation matrix to obtain the dynamic transformation matrix of the camera perspective of the manipulation model to follow the screen camera.
[0069] In this embodiment, the product of the preset scaling matrix scale, the moving matrix translate and the rotation matrix rotation is calculated to obtain the dynamic transformation matrix matrix of the manipulation model following the camera angle of the screen camera, that is, matrix = scale × translate × rotation. That is, the scaling transformation is applied to change the size of the manipulation model, the rotation transformation is applied to change the direction of the manipulation model, and the moving transformation is applied to change the position of the manipulation model.
[0070] In one embodiment of the present application, the movement matrix and the rotation matrix of the manipulation model are calculated according to the sight vector, including:
[0071] Project the sight line vector onto the target plane to obtain a projection vector, where the target plane is a plane where the other two coordinate axes except the first target coordinate axis corresponding to the manipulation model are located;
[0072] Calculate the angle between the projection vector and the second target coordinate axis, where the second target coordinate axis is one of the other two coordinate axes;
[0073] Calculate the movement matrix of the manipulation model according to the included angle and the preset circle radius of the main control model;
[0074] The rotation matrix of the manipulated model is calculated based on the movement matrix and the first target coordinate axis.
[0075] In this embodiment, the movement matrix translate and the rotation matrix rotation of any manipulation model are calculated according to the view vector view_direction. The specific method is:
[0076] (1) Determine the target plane where the other two coordinate axes other than the first target coordinate axis corresponding to the manipulation model are located. For example, if the first target coordinate axis corresponding to the manipulation model is the X axis, then the target plane where the other two coordinate axes are located is the YZ plane; if the first target coordinate axis corresponding to the manipulation model is the Y axis, then the target plane where the other two coordinate axes are located is the XZ plane; if the first target coordinate axis corresponding to the manipulation model is the Z axis, then the target plane where the other two coordinate axes are located is the XY plane.
[0077] (2) Project the view vector view_direction onto the target plane to obtain the projection vector.
[0078] (3) Calculate the angle θ between the projection vector and the second target coordinate axis, where the second target coordinate axis is one of the other two coordinate axes. Take the first target coordinate axis as the X axis and the view vector view_direction projected onto the YZ plane as an example. The second target coordinate axis can be the Y axis or the Z axis. Then calculate the angle θ between the projection vector and the Y axis, or the angle θ between the projection vector and the Z axis. The cosine value can be obtained by multiplying the projection vector by the unit vector of the second target coordinate axis, and then perform the arc cosine calculation to obtain the angle θ.
[0079] (4) Calculate the movement matrix of the manipulation model based on the angle and the preset ring radius of the main control model. The movement matrix translate of the manipulation model is calculated using the angle θ and the preset ring radius r of the main control model, that is, converting the polar coordinates (r, θ) into Cartesian coordinates (x, y, z). The specific formula is: translate = Vec3 (r × cosf (θ), _r × sinf (θ), 0), where the Vec3 function contains three member variables (x, y, z), x = r × cosf (θ), that is, using the cosine function to calculate the x coordinate from the angle θ, y = r × sinf (θ), that is, using the sine function to calculate the y coordinate from the angle θ.
[0080] (5) Perform vector cross multiplication of the translation matrix and the first target coordinate axis (unit vector of the X axis) to obtain the tangent vector of the ring. The translation matrix can calibrate a point on the main control model (ring), and the tangent vector of the ring is the tangent through the translate point. Based on the tangent vector of the ring, the rotation matrix rotation of the manipulation model is obtained. For example, the vector from the center of the main control model (ring) to the translate point and the direction of the tangent vector of the ring are obtained. The two vectors are used to calculate the rotation axis and rotation angle, and then the rotation matrix is constructed.
[0081] Through the above calculation method, the movement matrix translate and rotation matrix rotation of the manipulation model corresponding to the YZ plane, the manipulation model corresponding to the XY plane, and the manipulation model corresponding to the XZ plane are calculated to prepare rendering data for the rotation interactive control.
[0082] In one embodiment of the present application, the method further includes: obtaining a preset ring radius of the main control model, wherein the preset ring radius is related to the size of the 3D model and / or the required display size of the main control model.
[0083] In this embodiment, the preset ring radius of the main control model can be set according to the size of the 3D model, or it can be set according to the required display size of the main control model, that is, the required visual effect, thereby ensuring a good display effect of the rotating interactive control.
[0084] The present application also provides a computer device, such as Figure 4 As shown, the computer device 400 includes a processor 401 and a memory 402. The memory 402 stores programs or instructions that can be executed on the processor 401. When the program or instruction is executed by the processor 401, the various steps of the above-mentioned rendering method of the rotating interactive control are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0085] The memory 402 can be used to store software programs and various data. The memory 402 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 402 may include a volatile memory or a non-volatile memory, or the memory 402 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 402 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0086] The processor 401 may include one or more processing units; optionally, the processor 401 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 401.
[0087] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned rendering method embodiment of the rotating interactive control is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0088] The present application also provides the following embodiments:
[0089] Reference numeral 1, a rendering method of a rotation interactive control, wherein the rotation interactive control is used to control the rotation of a 3D model in a virtual three-dimensional space, the rotation interactive control comprises a main control model and a manipulation model for manipulating the main control model, the method comprising:
[0090] Obtaining a first coordinate vector of a position of a screen camera in the virtual three-dimensional space and a second coordinate vector of a center point of a bounding box of the 3D model;
[0091] Calculate a sight line vector according to the first coordinate vector and the second coordinate vector;
[0092] Calculating, according to the sight line vector, a dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera;
[0093] The point data of the manipulation model is updated according to the dynamic transformation matrix, and the manipulation model is rendered after the update.
[0094] Reference number 2, based on reference number 1, the rendering method is applied to slicing software, and the step of obtaining a first coordinate vector of a position of a screen camera in the virtual three-dimensional space includes:
[0095] When the slicing software is started, the initial position of the screen camera in the virtual three-dimensional space is obtained, and the coordinate vector of the initial position is used as the first coordinate vector; or,
[0096] After the camera viewing angle of the screen camera changes, the current position of the screen camera in the virtual three-dimensional space is acquired, and the coordinate vector of the current position is used as the first coordinate vector.
[0097] Reference number 3, based on reference number 1, obtaining a second coordinate vector of the center point of the bounding box of the 3D model in the virtual three-dimensional space, including:
[0098] If the 3D model to be rotated includes one, the coordinate vector of the center point of the bounding box of the 3D model is used as the second coordinate vector; or,
[0099] If there are multiple 3D models to be rotated, a common bounding box of the multiple 3D models is determined, and a coordinate vector of a center point of the common bounding box is used as the second coordinate vector.
[0100] Reference number 4, based on reference number 3, rendering the manipulation model, including:
[0101] The manipulation model is rendered by taking a center point of a bounding box of the 3D model or a plurality of center points of the bounding boxes of the 3D models as an origin of a coordinate system.
[0102] Reference numeral 5, based on reference numeral 1, calculating the sight line vector according to the first coordinate vector and the second coordinate vector includes:
[0103] The difference between the second coordinate vector and the first coordinate vector is calculated to obtain the sight line vector.
[0104] Label 6, based on label 1, the manipulation model includes: a manipulation model corresponding to the first coordinate axis of the virtual three-dimensional space, a manipulation model corresponding to the second coordinate axis of the virtual three-dimensional space, and a manipulation model corresponding to the third coordinate axis of the virtual three-dimensional space.
[0105] Reference numeral 7, based on reference numeral 6, the step of calculating the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to the sight line vector includes:
[0106] According to the sight line vector, respectively calculating the dynamic transformation matrices of the three manipulation models following the camera viewing angles of the screen camera;
[0107] The step of updating the point data of the manipulation model according to the dynamic transformation matrix comprises:
[0108] The point data of the three manipulation models are updated respectively according to the dynamic transformation matrices corresponding to the three manipulation models.
[0109] Reference numeral 8, based on any one of reference numerals 1 to 7, calculating, according to the sight line vector, a dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera, comprising:
[0110] Calculating a movement matrix and a rotation matrix of the manipulation model according to the sight line vector;
[0111] The dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera is calculated according to a preset scaling matrix, the movement matrix and the rotation matrix.
[0112] Reference numeral 9, based on reference numeral 8, the step of calculating the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to the preset scaling matrix, the movement matrix and the rotation matrix comprises:
[0113] The product of the preset scaling matrix, the movement matrix and the rotation matrix is calculated to obtain the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera.
[0114] Reference number 10, based on reference number 9, the method further includes:
[0115] The preset scaling matrix is obtained, where the preset scaling matrix is related to the screen pixel ratio of the manipulation model.
[0116] Reference numeral 11, based on reference numeral 8, calculating the movement matrix and the rotation matrix of the manipulation model according to the sight vector, including:
[0117] Projecting the sight line vector onto a target plane to obtain a projection vector, wherein the target plane is a plane where two other coordinate axes except the first target coordinate axis corresponding to the manipulation model are located;
[0118] Calculating an angle between the projection vector and a second target coordinate axis, where the second target coordinate axis is one of the other two coordinate axes;
[0119] Calculating the movement matrix of the manipulation model according to the included angle and the preset circle radius of the main control model;
[0120] The rotation matrix of the manipulation model is calculated according to the movement matrix and the first target coordinate axis.
[0121] Reference number 12, based on reference number 11, the method further includes:
[0122] A preset circle radius of the main control model is obtained, where the preset circle radius is related to the size of the 3D model and / or the required display size of the main control model.
[0123] Reference number 13, based on any one of reference numbers 1 to 7, before obtaining the first coordinate vector of the position of the screen camera in the virtual three-dimensional space and the second coordinate vector of the center point of the bounding box of the 3D model, the method further includes:
[0124] Generate a plurality of main control models of the rotation interactive control, wherein the plurality of main control models correspond to different planes of the virtual three-dimensional space respectively;
[0125] Generate or load the manipulation models corresponding to the different main control models; if the manipulation model is a regular shape, generate the manipulation model; if the manipulation model is an irregular shape, load the pre-generated manipulation model.
[0126] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A method for rendering a rotating interactive control, characterized in that: The rotation interaction control is used to control the rotation of the 3D model in the virtual three-dimensional space. The rotation interaction control includes a main control model and a manipulation model for manipulating the main control model. The method includes: Obtaining a first coordinate vector of a position of a screen camera in the virtual three-dimensional space and a second coordinate vector of a center point of a bounding box of the 3D model; Calculate a sight line vector according to the first coordinate vector and the second coordinate vector; Calculating, according to the sight line vector, a dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera; The point data of the manipulation model is updated according to the dynamic transformation matrix, and the manipulation model is rendered after the update.
2. The method according to claim 1, characterized in that The rendering method is applied to the slicing software, and the obtaining of the first coordinate vector of the position of the screen camera in the virtual three-dimensional space includes: When the slicing software is started, the initial position of the screen camera in the virtual three-dimensional space is obtained, and the coordinate vector of the initial position is used as the first coordinate vector; or, After the camera viewing angle of the screen camera changes, the current position of the screen camera in the virtual three-dimensional space is acquired, and the coordinate vector of the current position is used as the first coordinate vector.
3. The method according to claim 1, characterized in that Obtaining a second coordinate vector of a center point of a bounding box of the 3D model in the virtual three-dimensional space includes: If the 3D model to be rotated includes one, the coordinate vector of the center point of the bounding box of the 3D model is used as the second coordinate vector; or, If there are multiple 3D models to be rotated, a common bounding box of the multiple 3D models is determined, and a coordinate vector of a center point of the common bounding box is used as the second coordinate vector.
4. The method according to claim 3, characterized in that Rendering the manipulation model includes: The manipulation model is rendered by taking a center point of a bounding box of the 3D model or a plurality of center points of the bounding boxes of the 3D models as an origin of a coordinate system.
5. The method according to claim 1, characterized in that The calculating the sight line vector according to the first coordinate vector and the second coordinate vector comprises: The difference between the second coordinate vector and the first coordinate vector is calculated to obtain the sight line vector.
6. The method according to claim 1, characterized in that The manipulation model includes: a manipulation model corresponding to a first coordinate axis of the virtual three-dimensional space, a manipulation model corresponding to a second coordinate axis of the virtual three-dimensional space, and a manipulation model corresponding to a third coordinate axis of the virtual three-dimensional space; The step of calculating the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to the sight line vector includes: According to the sight line vector, respectively calculating the dynamic transformation matrices of the three manipulation models following the camera viewing angles of the screen camera; The step of updating the point data of the manipulation model according to the dynamic transformation matrix comprises: The point data of the three manipulation models are updated respectively according to the dynamic transformation matrices corresponding to the three manipulation models.
7. The method according to any one of claims 1 to 6, characterized in that The step of calculating the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to the sight line vector includes: Calculating a movement matrix and a rotation matrix of the manipulation model according to the sight line vector; Calculate the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to a preset scaling matrix, the movement matrix and the rotation matrix; The step of calculating the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera according to the preset scaling matrix, the movement matrix and the rotation matrix comprises: Calculating the product of the preset scaling matrix, the movement matrix and the rotation matrix to obtain the dynamic transformation matrix of the manipulation model following the camera viewing angle of the screen camera; The method further comprises: Acquire the preset scaling matrix, where the preset scaling matrix is related to the screen pixel ratio of the manipulation model; The step of calculating the movement matrix and the rotation matrix of the manipulation model according to the sight line vector comprises: Projecting the sight line vector onto a target plane to obtain a projection vector, wherein the target plane is a plane where two other coordinate axes except the first target coordinate axis corresponding to the manipulation model are located; Calculating an angle between the projection vector and a second target coordinate axis, where the second target coordinate axis is one of the other two coordinate axes; Calculating the movement matrix of the manipulation model according to the included angle and the preset circle radius of the main control model; Calculating the rotation matrix of the manipulation model according to the movement matrix and the first target coordinate axis; The method further comprises: A preset circle radius of the main control model is obtained, where the preset circle radius is related to the size of the 3D model and / or the required display size of the main control model.
8. The method according to any one of claims 1 to 6, characterized in that Before obtaining the first coordinate vector of the position of the screen camera in the virtual three-dimensional space and the second coordinate vector of the center point of the bounding box of the 3D model, the method further includes: Generate a plurality of main control models of the rotation interactive control, wherein the plurality of main control models correspond to different planes of the virtual three-dimensional space respectively; Generate or load the manipulation models corresponding to the different main control models; if the manipulation model is a regular shape, generate the manipulation model; if the manipulation model is an irregular shape, load the pre-generated manipulation model.
9. A computer device, characterized in that: It comprises a processor and a memory, wherein the memory stores a program or instruction running on the processor, and when the program or instruction is executed by the processor, the steps of the method for rendering a rotating interactive control as described in any one of claims 1 to 8 are implemented.
10. A readable storage medium having a program or instruction stored thereon, characterized in that: When the program or instruction is executed by a processor, the steps of the method for rendering a rotating interactive control as described in any one of claims 1 to 8 are implemented.
