Model processing method and device, equipment and storage medium
By obtaining the model information of the target model, creating a bounding box and adjusting the virtual camera according to the relative distance, the problems of low model processing efficiency and scaling deformation in the existing technology are solved, and the complete display of the model on the screen and efficient modeling are achieved.
Patent Information
- Application Number
- CN202311122023.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-01
- Publication Date
- 2024-08-30
AI Technical Summary
Existing model processing methods take a long time to develop, have low modeling efficiency, and are prone to deformation problems during model scaling.
By obtaining the model information of the target model, a bounding box is created to represent its bounding box, the relative distance between the virtual camera and the model is determined based on the width and height of the bounding box and the screen size, and processing is performed to achieve adaptive adjustment and avoid scaling deformation.
It improves the complete display of the model on the screen, avoids scaling and deformation problems, and improves modeling efficiency.
Smart Images

Figure CN118570351A
Abstract
Description
Technical Field
[0001] The present application belongs to the field of three-dimensional scene application technology, and specifically relates to a model processing method, device, equipment and storage medium. Background Art
[0002] Computer graphics is a science that uses mathematical algorithms to convert two-dimensional or three-dimensional graphics into a raster form for a computer display. With the development of computer graphics, users can use three-dimensional engines such as Three.js that run in the browser to draw various three-dimensional scenes in the browser. To meet the needs of users, Three.js provides users with an entry to upload models so that Three.js can achieve better visual effects by loading external models. Since the sizes of models uploaded by users vary, the use of a fixed-size display method often results in poor display of the model in the display area, thus affecting the user experience.
[0003] In order to solve the defects such as poor display effect caused by the fixed-size display of models of different sizes when using Three.js to load external models, the prior art proposes a method for scaling the model size, specifically by modifying the size of the model in the 3D software or in the Three.js code, so that external models of different sizes can be fully displayed in the display area.
[0004] However, existing model processing methods require the establishment of specifications with professional 3D technicians when modifying the model size, resulting in long development time and low modeling efficiency. At the same time, in the process of controlling the scaling of the model, there may be scaling deformation problems caused by different model midpoints. Summary of the invention
[0005] The present application provides a model processing method, device, equipment and storage medium to solve the problems of long development time, low modeling efficiency and easy scaling and deformation of existing model processing methods.
[0006] In a first aspect, the present application provides a model processing method, the method comprising:
[0007] Acquire model information of the target model, and create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene;
[0008] Obtaining the width and height of the bounding box, and determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height;
[0009] The target model is processed according to the relative distance.
[0010] Optionally, creating a bounding box corresponding to the target model according to the model information includes:
[0011] Performing grouping processing on the target model according to the model information to obtain a plurality of group objects in a hierarchical structure corresponding to the target model;
[0012] A bounding box corresponding to the target model is created according to a target group object of the target model, wherein the target group object is a group object with the highest hierarchical structure among the multiple group objects.
[0013] Optionally, determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height includes:
[0014] taking a ratio of the screen width to the width as a first ratio;
[0015] taking the ratio of the screen height to the height as a second ratio;
[0016] Determining a target parameter of the bounding box according to the first ratio and the second ratio, the target parameter being the width or the height;
[0017] The relative distance between the virtual camera and the target model is determined according to the target parameters and the field of view of the virtual camera.
[0018] Optionally, determining the relative distance between the virtual camera and the target model according to the target parameter and the field of view of the virtual camera includes:
[0019] The relative distance is determined using the following formula:
[0020] Among them, Zoom is the relative distance, length is the target parameter, and camera.fov is the field of view of the virtual camera.
[0021] Optionally, processing the target model according to the relative distance includes:
[0022] Determine a far cross section of the virtual camera according to the relative distance;
[0023] According to the relative distance, the far section and the preset near section, the virtual camera is assigned a value, and a matrix operation is performed on the virtual camera;
[0024] The target model is rendered based on the virtual camera after the value assignment process.
[0025] Optionally, if the target model includes a plurality of sub-models, determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height includes:
[0026] Determine a candidate relative distance between the virtual camera and each sub-model according to the width and height of the bounding box corresponding to each sub-model, as well as the screen width and the screen height;
[0027] The candidate relative distance with the largest distance among the multiple candidate relative distances is used as the relative distance between the virtual camera and the target model.
[0028] Optionally, after taking the candidate relative distance with the largest distance among the multiple candidate relative distances as the relative distance between the virtual camera and the target model, the method further includes:
[0029] determining a scaling parameter of each sub-model according to the plurality of candidate relative distances and the relative distance;
[0030] According to the scaling parameters, the corresponding sub-model is modified.
[0031] In a second aspect, the present application provides a model processing device, the device comprising:
[0032] An acquisition module, used to acquire model information of a target model;
[0033] A processing module, used to create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene;
[0034] The acquisition module is further used to acquire the width and height of the bounding box;
[0035] The processing module is further used to determine the relative distance between the virtual camera and the target model according to the width, the height, the screen width and the screen height;
[0036] The processing module is further used to process the target model according to the relative distance.
[0037] Optionally, the processing module is further used to perform grouping processing on the target model according to the model information to obtain a plurality of group objects in the hierarchical structure corresponding to the target model;
[0038] The processing module is further used to create a bounding box corresponding to the target model according to a target group object of the target model, wherein the target group object is the group object with the highest hierarchical structure among the multiple group objects.
[0039] Optionally, the device further includes: a determination module;
[0040] The processing module is further used to use the ratio of the screen width to the width as a first ratio, and use the ratio of the screen height to the height as a second ratio;
[0041] The determining module is used to determine a target parameter of the bounding box according to the first ratio and the second ratio, wherein the target parameter is the width or the height;
[0042] The determination module is further used to determine the relative distance between the virtual camera and the target model according to the target parameters and the field of view of the virtual camera.
[0043] Optionally, the processing module is further configured to determine the relative distance using the following formula:
[0044] Among them, Zoom is the relative distance, length is the target parameter, and camera.fov is the field of view of the virtual camera.
[0045] Optionally, the determination module is further used to determine a far cross section of the virtual camera according to the relative distance;
[0046] The processing module is further used to perform value assignment processing on the virtual camera according to the relative distance, the far section and the preset near section, and perform matrix operation on the virtual camera;
[0047] The processing module is further used to render the target model based on the virtual camera after the assignment processing.
[0048] Optionally, the processing module is further used to determine a candidate relative distance between the virtual camera and each sub-model according to the width and height of the bounding box corresponding to each sub-model, and the screen width and the screen height;
[0049] The processing module is further configured to use the candidate relative distance with the largest distance among the multiple candidate relative distances as the relative distance between the virtual camera and the target model.
[0050] Optionally, the processing module is further used to determine a scaling parameter of each sub-model according to the multiple candidate relative distances and the relative distance;
[0051] The processing module is further used to perform correction processing on the corresponding sub-model according to the scaling parameter.
[0052] In a third aspect, the present application provides a model processing device, comprising:
[0053] Memory;
[0054] processor;
[0055] Wherein, the memory stores computer-executable instructions;
[0056] The processor executes the computer-executable instructions stored in the memory to implement the model processing method as described in the first aspect and various possible implementations of the first aspect.
[0057] In a fourth aspect, the present application provides a computer storage medium having computer execution instructions stored thereon, wherein the computer execution instructions are executed by a processor to implement the model processing method as described in the first aspect and various possible implementations of the first aspect.
[0058] The model processing method provided by the present application obtains model information of a target model, and creates a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in a three-dimensional scene, obtains the width and height of the bounding box, and determines the relative distance between a virtual camera and the target model according to the width, the height, the screen width, and the screen height, and processes the target model according to the relative distance. The method controls the relative distance between the virtual camera and the target model so that the target model can be fully displayed on the screen, thereby avoiding the scaling deformation problem caused by modifying the size of the target model and improving the modeling efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0060] Figure 1 This is the process of the model processing method provided by this application Figure 1 ;
[0061] Figure 2 This is the process of the model processing method provided by this application Figure 2 ;
[0062] Figure 3 This is a diagram showing the relative distance between the virtual camera and the target model provided in this application. Figure 1 ;
[0063] Figure 4 This is a diagram showing the relative distance between the virtual camera and the target model provided in this application. Figure 2 ;
[0064] Figure 5 is a schematic diagram of the visible area of the virtual camera provided by the present application;
[0065] Figure 6 It is a structural schematic diagram of the model processing device provided by the present application;
[0066] Figure 7 It is a structural schematic diagram of the model processing device provided in this application.
[0067] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0068] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0069] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in sequences other than those illustrated or described herein.
[0070] In the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0071] Computer graphics is a science that uses mathematical algorithms to convert two-dimensional or three-dimensional graphics into a raster form for a computer display. It mainly studies how to represent graphics in a computer, and the relevant principles and algorithms for using computers to calculate, process and display graphics. With the development of computer graphics, users can use three-dimensional engines such as Three.js that run in browsers to draw various three-dimensional scenes in the browser. To meet the needs of users, Three.js provides users with an entry to upload models so that Three.js can achieve better visual effects by loading external models. Since the sizes of models uploaded by users are different, the use of fixed-size display methods often results in poor display effects of models in the display area, thus affecting the user experience.
[0072] In order to solve the defects such as poor display effect caused by the fixed-size display of models of different sizes when using Three.js to load external models, the prior art proposes a method for scaling the model size, specifically by modifying the size of the model in the 3D software or in the Three.js code, so that external models of different sizes can be fully displayed in the display area.
[0073] At present, there are mainly three solutions used in existing model processing methods to solve the problem of external model size:
[0074] 1. Manually resize the model and then re-import it into the Three.js scene.
[0075] Among them, the manual resizing method consumes a lot of manpower and time, and requires professional 3D software and 3D technicians.
[0076] 2. Enlarge or reduce the model according to its size.
[0077] Among them, scaling the model according to the model size can solve the problem of adaptive size of the model in most scenes. However, the model needs to be exported and imported according to certain specifications. When encountering an irregular model where the center point is not at the center of the model, the model scaling will deviate from the camera's field of view. In this case, professional 3D technicians are also required to make secondary modifications to the model.
[0078] 3. Establish a model specification in advance and require 3D personnel to model according to the specification.
[0079] Among them, formulating model specifications is only suitable for the internal work process of the team. When external users are required to model according to the specifications, the communication cost is increased.
[0080] In summary, the common point of the above solutions when processing external models is that the model is modified in the 3D software or Three.js code, which leads to a long development time and low modeling efficiency. At the same time, in the process of controlling the scaling of the model, there may be scaling deformation problems caused by different midpoints of the model.
[0081] In view of this, an embodiment of the present application provides a model processing method, by obtaining model information of a target model, and creating a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in a three-dimensional scene; obtaining the width and height of the bounding box, and determining the relative distance between a virtual camera and the target model according to the width, the height, the screen width, and the screen height; processing the target model according to the relative distance, so as to realize that the virtual camera in the scene in Three.js adaptively adjusts the distance from the target model according to the size of the target model, thereby ensuring that the target model can be fully displayed on the screen, solving the deformation problem of the model during scaling, and at the same time, improving the modeling efficiency.
[0082] The following specific embodiments are used to describe in detail the technical solution of the present application and how the technical solution of the present application solves the above technical problems. The following specific embodiments can be implemented independently or in combination with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0083] First, the pre-process of the model processing method provided in the embodiment of the present application is described. It should be noted that the pre-process is only an example of an application scenario to which the model processing method of the present application can be applied, so as to help technical personnel in this field understand the technical content of the present application, but it does not mean that the embodiment of the present application cannot be used in other devices, systems, environments or scenarios.
[0084] 1. Model resources: Model resources are generally provided by 3D modelers. Since there are no standard restrictions, modelers do not need to put the model into the scene in place, that is, the scene model axis coordinates (x, y, z) = (0, 0, 0); and the model's scaling attributes do not need to be (1, 1, 1). Model formats can be, for example, obj+mtl, fbx, glb, gltf, stl, etc.
[0085] 2. Initialize the Three.js scene:
[0086] 1) Create a new 3D scene in the Three.js engine.
[0087] 2) Create a virtual camera based on the field of view angle, screen aspect ratio, far section and near section.
[0088] 3) Create a WebGL renderer to render the target model.
[0089] 4) Add common lights, including parallel light or ambient light, according to the needs of the new 3D scene.
[0090] 3. Model loading: Using the Application Programming Interface (API) provided by Three.js, encapsulate the API into a function modelLoader(data), where the parameter data is {modelUrl, modelName, callBack}. modelUrl is the link returned by the model uploaded by the user. modelName is the name of the model, and callback is the callback function for model loading, where the model processing method provided in the embodiment of the present application can be called.
[0091] Figure 1 The process of the model processing method provided in the embodiment of the present application Figure 1 The execution subject of this embodiment may be, for example, a processor of the terminal where Three.js is located. Figure 1 As shown, the model processing method provided in this embodiment includes:
[0092] S101. Acquire model information of a target model, and create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in a three-dimensional scene.
[0093] The target model is an external model uploaded by the user, which is displayed on the screen after being processed in Three.js. The model information is the information of each hierarchical object in the hierarchical structure corresponding to the target model in Three.js. The model information can be, for example, a group object or a sub-object in the hierarchical structure corresponding to the target model. The bounding box refers to an external geometric body that is set according to the size of the target model in a three-dimensional scene and can completely surround the target model.
[0094] It can be understood that after the user imports the target model to be displayed through the user terminal, the target model returns the model information corresponding to the target model through the API interface provided by Three.js, and the model information is used to create a bounding box corresponding to the target model. Among them, when the type of the target model uploaded by the user terminal is a single model, that is, the number of target models is one, then a single bounding box corresponding to the single model can be obtained according to the model information of the single model; when the type of the target model uploaded by the user terminal is a multiple model, that is, the number of target models is multiple, then multiple bounding boxes corresponding to multiple sub-models in the multiple models can be obtained according to the model information of the multiple models.
[0095] In this step, the model information includes the group object and child objects of the target model. The target model can be organized through the group object of Three.js so that the target model forms a hierarchical structure. In the hierarchical structure of the target model, the group object is a parent object, corresponding to multiple child objects, such as point models, line models, and grid models, so that the target model forms a tree structure, that is, the group object includes the various child objects that constitute the target model. Therefore, a bounding box corresponding to the target model can be created according to the model information of the target model.
[0096] Since the shape of the target model is usually complex, the bounding box can be used to assist in calculating the center position and size of the target model it encloses in the three-dimensional scene. Therefore, it is necessary to create a bounding box corresponding to the target model based on the model information of the target model, so as to judge the relationship between the target model and points, surfaces and other objects in the three-dimensional space.
[0097] Exemplarily, a specific implementation method for creating a bounding box corresponding to the target model based on the model information is provided here: when the type of the model is a single model type, a hierarchical structure relationship between multiple group objects is obtained based on multiple group objects of the model; based on the hierarchical structure relationship, a target group object is determined, and the target group object is a group object whose position in the hierarchical structure of the model is higher than other group objects; based on the target group object, a bounding box corresponding to the target model is created so that the bounding box wraps the model within the bounding box.
[0098] When the type of the model is a multi-model type, the multiple sub-models corresponding to the multiple target models are classified and processed to obtain multiple group objects corresponding to the multiple sub-models; according to the positions of the multiple group objects in the hierarchical structure of the corresponding sub-models, the multiple target group objects corresponding to the multiple sub-models are determined, and the target group objects are the group objects with the highest position in the hierarchical structure of the corresponding sub-models; according to the multiple target group objects, multiple bounding boxes corresponding to the multiple sub-models in the multiple target models are respectively created, so that the multiple bounding boxes respectively wrap the corresponding target models in the bounding boxes. This application does not impose any special restrictions on the specific implementation method of creating a bounding box corresponding to the target model according to the model information.
[0099] S102: Obtain the width and height of the bounding box, and determine the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height.
[0100] Among them, the virtual camera is used to capture the image of the target model in the Three.js scene. The virtual camera is equivalent to the position and orientation of the human eye in the three-dimensional scene. Therefore, the objects within the visible range of the virtual camera are the content visible on the user side. Objects beyond the visible range of the virtual camera will not be rendered by the renderer, that is, they cannot be displayed on the screen.
[0101] It can be understood that the shape of the target model is usually an irregular and complex shape, and the bounding box is a regular geometric body circumscribed to the target model. Moreover, the bounding box refers to a geometric body that is set according to the size of the target model in a three-dimensional scene and can completely wrap the target model. Therefore, using the bounding box to replace the target model itself for calculation, thereby obtaining the width and height of the bounding box, is more efficient and simpler than directly using the target model itself for calculation.
[0102] By moving the virtual camera and changing the relative distance between the virtual camera and the target model, the position and size of the target model in the three-dimensional scene can be controlled so that the target model can be better displayed on the screen and meet the user's demand for visual effects. The display effect of the target model on the screen is associated with the width and height of the bounding box corresponding to the target model, and the width and height of the screen. Therefore, the relative distance between the virtual camera and the target model can be determined based on the width and height of the bounding box and the width and height of the screen, so that the target model can be fully displayed on the screen, improving the display effect.
[0103] For example, the width and height of the bounding box and the width and height of the screen can be used to determine the value of the width and height of the bounding box that is more different from the width and height of the screen, that is, the smaller value of the width and height of the bounding box, and the side length corresponding to the value is used as the target side length. Then, based on the correlation between the target side length and the field of view of the virtual camera, the relative distance between the virtual camera and the target model is calculated so that the target model can be within the visible range of the virtual camera.
[0104] Optionally, if the target model includes multiple sub-models, the candidate relative distance between the virtual camera and each sub-model can be determined based on the width and height of the bounding box corresponding to each sub-model, as well as the screen width and the screen height; the largest candidate relative distance among the multiple candidate relative distances is used as the relative distance between the virtual camera and the target model, so that the multiple sub-models in the target model can be projected onto the screen by the virtual camera and displayed.
[0105] Optionally, after determining the relative distance between the virtual camera and the target model, the scaling parameter of each sub-model can also be determined based on the multiple candidate relative distances and the relative distance. For example, the ratio of the multiple candidate relative distances to the relative distance can be used as the scaling parameter; according to the scaling parameter, the corresponding sub-model is corrected to adjust the proportion of each sub-model, so that the proportion of each sub-model in the target model remains uniform and balanced, thereby improving the display effect of the model.
[0106] S103: Process the target model according to the relative distance.
[0107] Among them, after determining the relative distance between the virtual camera and the target model, other parameters of the virtual camera can be determined according to the relative distance, and the virtual camera can be assigned value processing, matrix operation and other settings, so that the virtual camera can adaptively adjust the relative distance with the target model to ensure that the target model is within the visible range of the virtual camera, that is, the target model can be fully displayed on the screen.
[0108] It can be understood that, according to the relative distance between the virtual camera and the target model, after completing the setting of the virtual camera, the target model can be added to the three-dimensional scene of Three.js, so that the renderer draws the target model on the screen.
[0109] The model processing method provided in the present embodiment obtains model information of the target model, and creates a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene, obtains the width and height of the bounding box, and determines the relative distance between the virtual camera and the target model according to the width, the height, the screen width and the screen height, and processes the target model according to the relative distance. The method controls the relative distance between the virtual camera and the target model so that the target model can be fully displayed on the screen, thereby avoiding the scaling deformation problem caused by modifying the size of the target model and improving the modeling efficiency.
[0110] Figure 2 The process of the model processing method provided in the embodiment of the present application Figure 2 This embodiment is in Figure 1 Based on the embodiment, the model processing method is described in detail. Figure 2 As shown, the model processing method provided in this embodiment includes:
[0111] S201: Acquire model information of a target model, and group the target model according to the model information to obtain a plurality of group objects in a hierarchical structure corresponding to the target model.
[0112] The model information includes the group object and child objects of the target model. The target model can be organized through the group object of Three.js so that the target model forms a hierarchical structure. In the hierarchical structure of the target model, the group object is a parent object, corresponding to multiple child objects, such as point models, line models, and grid models.
[0113] It can be understood that by grouping and summarizing multiple sub-objects in the target model to obtain multiple group objects, this is done to establish a hierarchical structure for the target model, making the target model a hierarchical model to facilitate subsequent operations on the target model.
[0114] For example, when the target model is a robot model, the various elements in the robot's body are grouped and processed. The robot's eyes are the child objects of the robot's head, and the robot's head is the group object corresponding to the eyes; the robot's fingers are the child objects of the hands, and the hands can be the group objects of the fingers. Because the hands are the child objects of the arms, the arms can be the group objects of the hands. In this way, the various elements of the robot model can be grouped to make the robot model form a hierarchical structure, that is, a tree structure.
[0115] S202: Create a bounding box corresponding to the target model according to a target group object of the target model, wherein the target group object is a group object with the highest hierarchical structure among the multiple group objects.
[0116] The target group object is a group object that is higher than other group objects in the hierarchical structure corresponding to the target model, and the target group object is used to represent the overall hierarchical structure of the target model.
[0117] It can be understood that the child objects are located at the bottom layer in the hierarchical structure corresponding to the target model, and the group objects, as the middle layer in the hierarchical structure, connect the multi-layer structures. Multiple group objects are connected to form a tree structure of the target model. Only the parent object can be rotated, scaled, translated, etc., so that all child objects corresponding to the parent object can be transformed at the same time, thereby realizing the operation of the entire target model. Because the highest group object in the hierarchical structure corresponding to the target model is the parent object of other group objects, it includes each group object in all levels of the model and the child objects in the group object. Therefore, when the target group object is used to represent the overall hierarchical structure of the target model, the target group object is the group object with the highest hierarchical structure among the multiple group objects.
[0118] The purpose of this step is to completely wrap the target model by creating a bounding box corresponding to the target model, thereby simplifying the calculation process of the target model and improving the calculation efficiency.
[0119] In this step, the specific implementation method of creating a bounding box corresponding to the target model according to the target group object of the target model is similar to the above step S101, which will not be repeated here.
[0120] S203 , obtaining the width and height of the bounding box, taking the ratio of the screen width to the width as a first ratio, and taking the ratio of the screen height to the height as a second ratio.
[0121] Among them, the screen width is the internal width of the window of the display screen, and the screen height is the internal height of the window of the display screen. Three-dimensional space is usually represented by three coordinate axes, namely the x-axis, y-axis, and z-axis. Since the coordinate axis arrangement method adopted by Three.js is the right-handed coordinate system, the width of the bounding box in the right-handed coordinate system is the side length of the bounding box in the x-axis direction, and the height of the bounding box in the right-handed coordinate system is the side length of the bounding box in the y-axis direction.
[0122] S204: Determine a target parameter of the bounding box according to the first ratio and the second ratio, where the target parameter is the width or the height.
[0123] Among them, the target parameter is the width or height of the bounding box, and the target parameter is used to indicate the shape characteristics of the target model. When the target parameter is the width of the bounding box, it indicates that the side of the bounding box in the x-axis direction is a shorter side, that is, the target model is a tall model, that is, a narrow model, such as a high-rise building model; when the target parameter is the height of the bounding box, it indicates that the side of the bounding box in the y-axis direction is a shorter side, that is, the target model is a wide model, that is, a flat model, such as a keyboard model.
[0124] It can be understood that since the first ratio is the ratio of the screen width to the width of the bounding box, and the second ratio is the ratio of the screen height to the height of the bounding box, the width and height of the bounding box with the lowest ratio to the width and height of the screen, that is, the shortest side length of the bounding box in the coordinate system, can be determined based on the first ratio and the second ratio.
[0125] For example, the numerical values of the first ratio and the second ratio may be compared, and the side length of the bounding box corresponding to the ratio with a larger numerical value may be taken as the target parameter, where the target parameter is the width or height of the bounding box.
[0126] S205: Determine a relative distance between the virtual camera and the target model according to the target parameters and the field of view of the virtual camera.
[0127] The field of view refers to the direction and angle of the virtual camera used to observe the target model in the three-dimensional scene.
[0128] It can be understood that during the operation of Three.js, the size of the target model in the three-dimensional scene can be controlled by changing the relative distance between the virtual camera and the target model, and the target model is surrounded by a bounding box. Therefore, the relative distance between the virtual camera and the bounding box can be determined according to the target parameters and the field of view of the virtual camera, and the relative distance between the virtual camera and the target model can be determined, thereby realizing the adaptive adjustment of the distance between the virtual camera and the target model according to the size of the target model, so that the target model can be fully captured by the virtual camera without modifying the size of the model.
[0129] The relative distance between the virtual camera and the target model can be obtained by, for example, the following formula:
[0130] Among them, Zoom is the relative distance, length is the target parameter, and camera.fov is the field of view of the virtual camera.
[0131] The following example takes the target parameter as the width of the bounding box:
[0132] Figure 3 Schematic diagram of the relative distance between the virtual camera and the target model provided in the embodiment of the present application Figure 1 ,like Figure 3 As shown, when the target parameter is the width of the bounding box, it proves that the target model is a high model, and the relative distance between the virtual camera and the target model is the ratio of the tangent value of half the width of the bounding box to half the field of view of the virtual camera.
[0133] The following example takes the target parameter as the height of the bounding box:
[0134] Figure 4 Schematic diagram of the relative distance between the virtual camera and the target model provided in the embodiment of the present application Figure 2 ,like Figure 4 As shown, when the target parameter is the height of the bounding box, it proves that the target model is a wide model, and the relative distance between the virtual camera and the target model is the ratio of the tangent value of half the height of the bounding box to half the field of view of the virtual camera.
[0135] S206: Determine a far cross section of the virtual camera according to the relative distance.
[0136] The far section of the virtual camera refers to the section at the farthest distance in the visible area of the virtual camera in the three-dimensional scene. The purpose of setting the far section is to prevent the target model from being too far away from the virtual camera and being invisible.
[0137] For example, Figure 5 A schematic diagram of the visible area of the virtual camera provided in this embodiment, such as Figure 5 As shown, when the target model needs to be projected by the virtual camera, the relative distance between the virtual camera and the target model must be smaller than the relative distance from the far section of the virtual camera to the virtual camera, that is, the target model cannot exceed the far section. Therefore, the position of the far section of the virtual camera can be determined based on the association between the relative distance and the far section.
[0138] For example, a cross section at a distance 10 times greater than the relative distance between the virtual camera and the target model may be used as the far cross section of the virtual camera.
[0139] S207 . Performing value assignment processing on the virtual camera according to the relative distance, the far section, and the preset near section, and performing matrix operation on the virtual camera.
[0140] The preset near cross section refers to the cross section at the closest distance in the visible area of the virtual camera in the three-dimensional scene. The purpose of setting the near cross section is to avoid the target model being too close to the virtual camera and causing the target model to be invisible. The preset near cross section can be a cross section set based on experience. The relative distance between the specific near cross section and the virtual camera is not specifically limited. The relative distance between the preset near cross section and the virtual camera can be, for example, 0.1.
[0141] Continue to refer to Figure 5 ,like Figure 5 As shown in the figure, when the virtual camera processes the target model, it must meet the following conditions: the target model can only be projected by the virtual camera when the distance between the virtual camera and the target model is greater than the preset near section, less than the far section, and within the field of view of the virtual camera. In addition, the relative distance between the virtual camera and the target model is a necessary condition to ensure that the target model is within the visible range of the virtual camera. Therefore, it is necessary to assign values to the virtual camera according to the relative distance, the far section, and the preset near section so that the virtual camera can adjust the distance between itself and the target model.
[0142] In this step, after the virtual camera is assigned, matrix operations can be performed on the virtual camera to improve processing efficiency. Due to the characteristics of the virtual camera in Three.js, matrix operations are required for the translation and x-axis rotation of the virtual camera.
[0143] For example, the following formula can be used to calculate the translation of the virtual camera:
[0144] Wherein Zoom is the relative distance between the virtual camera and the target model.
[0145] For example, the x-axis rotation of the virtual camera can be calculated using the following formula:
[0146] Among them, α is the angle of rotation of the virtual camera around the x-axis.
[0147] S208: Rendering the target model based on the virtual camera after the value assignment.
[0148] Among them, after completing the assignment processing of the virtual camera, the renderer can be controlled to update the matrix of the virtual camera, and the target model in the three-dimensional scene can be projected into a digital image according to the set environment, lighting, material and rendering parameters, so as to realize the drawing of the target model in the three-dimensional scene onto the screen.
[0149] The model processing method provided in the embodiment of the present application obtains model information of the target model, groups the target model according to the model information, obtains multiple group objects in a hierarchical structure corresponding to the target model, takes the group object with the highest hierarchical structure among the multiple group objects as the target group object, creates a bounding box corresponding to the target model according to the target group object, obtains the width and height of the bounding box, takes the ratio of the screen width to the width as the first ratio, takes the ratio of the screen height to the height as the second ratio, determines the target parameters of the bounding box according to the first ratio and the second ratio, and The target parameters and the field of view of the virtual camera are used to determine the relative distance between the virtual camera and the target model, and the far section of the virtual camera is determined according to the relative distance. The virtual camera is assigned a value according to the relative distance, the far section and a preset near section, and a matrix operation is performed on the virtual camera. The target model is rendered based on the virtual camera after the assignment. This method enables the target model to be fully displayed on the screen by controlling the relative distance between the virtual camera and the target model, thereby avoiding the scaling deformation problem caused by modifying the size of the target model and improving the modeling efficiency.
[0150] Figure 6 The structure diagram of the model processing device provided in this application Figure 1 , applied to the server. Figure 3 As shown, the model processing device 300 provided in this embodiment includes:
[0151] An acquisition module 301 is used to acquire model information of a target model;
[0152] A processing module 302 is used to create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene;
[0153] The acquisition module 301 is further used to acquire the width and height of the bounding box;
[0154] The processing module 302 is further used to determine the relative distance between the virtual camera and the target model according to the width, the height, the screen width and the screen height;
[0155] The processing module 302 is further configured to process the target model according to the relative distance.
[0156] Optionally, the processing module 302 is further configured to perform grouping processing on the target model according to the model information to obtain a plurality of group objects in a hierarchical structure corresponding to the target model;
[0157] The processing module 302 is further configured to create a bounding box corresponding to the target model according to a target group object of the target model, wherein the target group object is a group object with the highest hierarchical structure among the multiple group objects.
[0158] Optionally, the device further includes: a determination module 303;
[0159] The processing module 302 is further configured to use a ratio of the screen width to the width as a first ratio, and a ratio of the screen height to the height as a second ratio;
[0160] The determination module 303 is used to determine a target parameter of the bounding box according to the first ratio and the second ratio, wherein the target parameter is the width or the height;
[0161] The determination module 303 is further configured to determine a relative distance between the virtual camera and the target model according to the target parameters and the field of view of the virtual camera.
[0162] Optionally, the processing module 302 is further configured to determine the relative distance using the following formula:
[0163] Among them, Zoom is the relative distance, length is the target parameter, and camera.fov is the field of view of the virtual camera.
[0164] Optionally, the determination module 303 is further configured to determine a far cross section of the virtual camera according to the relative distance;
[0165] The processing module 302 is further used to perform value assignment processing on the virtual camera according to the relative distance, the far section and the preset near section, and perform matrix operation on the virtual camera;
[0166] The processing module 302 is further used to render the target model based on the virtual camera after the assignment processing.
[0167] Optionally, the processing module 302 is further used to determine a candidate relative distance between the virtual camera and each sub-model according to the width and height of the bounding box corresponding to each sub-model, and the screen width and the screen height;
[0168] The processing module 302 is further configured to use the largest candidate relative distance among the plurality of candidate relative distances as the relative distance between the virtual camera and the target model.
[0169] Optionally, the processing module 302 is further configured to determine a scaling parameter of each sub-model according to the multiple candidate relative distances and the relative distance;
[0170] The processing module 302 is further used to perform correction processing on the corresponding sub-model according to the scaling parameter.
[0171] Figure 4 This is a schematic diagram of the structure of the model processing device provided in this application. Figure 4 As shown, the present application provides a model processing device, and the model processing device 400 includes: a receiver 401, a transmitter 402, a processor 403 and a memory 404.
[0172] Receiver 401, used for receiving instructions and data;
[0173] A transmitter 402, used for sending instructions and data;
[0174] Memory 404, for storing computer-executable instructions;
[0175] The processor 403 is used to execute the computer-executable instructions stored in the memory 404 to implement the various steps performed by the model processing method in the above embodiment. For details, please refer to the relevant description in the above embodiment of the model processing method.
[0176] Optionally, the memory 404 may be independent or integrated with the processor 403 .
[0177] When the memory 404 is independently provided, the electronic device further includes a bus for connecting the memory 404 and the processor 403 .
[0178] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the model processing method executed by the above-mentioned model processing device is implemented.
[0179] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0180] So far, the technical solution of the present application has been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific embodiments, and the above embodiments are only used to illustrate the technical solution of the present application rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A model processing method, characterized in that: The method comprises: Acquire model information of the target model, and create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene; Obtaining the width and height of the bounding box, and determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height; The target model is processed according to the relative distance.
2. The method according to claim 1, characterized in that: The step of creating a bounding box corresponding to the target model according to the model information includes: Performing grouping processing on the target model according to the model information to obtain a plurality of group objects in a hierarchical structure corresponding to the target model; A bounding box corresponding to the target model is created according to a target group object of the target model, wherein the target group object is a group object with the highest hierarchical structure among the multiple group objects.
3. The method according to claim 1, characterized in that Determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height includes: taking a ratio of the screen width to the width as a first ratio; taking the ratio of the screen height to the height as a second ratio; Determining a target parameter of the bounding box according to the first ratio and the second ratio, the target parameter being the width or the height; The relative distance between the virtual camera and the target model is determined according to the target parameters and the field of view of the virtual camera.
4. The method according to claim 3, characterized in that Determining the relative distance between the virtual camera and the target model according to the target parameter and the field of view of the virtual camera includes: The relative distance is determined using the following formula: Among them, Zoom is the relative distance, length is the target parameter, and camera.fov is the field of view of the virtual camera.
5. The method according to claim 1, characterized in that The processing of the target model according to the relative distance includes: Determine a far cross section of the virtual camera according to the relative distance; According to the relative distance, the far section and the preset near section, the virtual camera is assigned a value, and a matrix operation is performed on the virtual camera; The target model is rendered based on the virtual camera after the value assignment process.
6. The method according to claim 1, characterized in that If the target model includes a plurality of sub-models, determining the relative distance between the virtual camera and the target model according to the width, the height, the screen width, and the screen height includes: Determine a candidate relative distance between the virtual camera and each sub-model according to the width and height of the bounding box corresponding to each sub-model, as well as the screen width and the screen height; The candidate relative distance with the largest distance among the multiple candidate relative distances is used as the relative distance between the virtual camera and the target model.
7. The method according to claim 6, characterized in that After taking the candidate relative distance with the largest distance among the multiple candidate relative distances as the relative distance between the virtual camera and the target model, the method further includes: determining a scaling parameter of each sub-model according to the plurality of candidate relative distances and the relative distance; According to the scaling parameters, the corresponding sub-model is modified.
8. A model processing device, characterized in that: The device comprises: An acquisition module, used to acquire model information of a target model; A processing module, used to create a bounding box corresponding to the target model according to the model information, wherein the bounding box is used to indicate a bounding box corresponding to the target model in the three-dimensional scene; The acquisition module is further used to acquire the width and height of the bounding box; The processing module is further used to determine the relative distance between the virtual camera and the target model according to the width, the height, the screen width and the screen height; The processing module is further used to process the target model according to the relative distance.
9. A model processing device, characterized in that: include: Memory; processor; Wherein, the memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the model processing method according to any one of claims 1 to 7.
10. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, which are used to implement the model processing method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Cited By
Method, device, equipment and medium for managing three-dimensional model
CN115690365A
Method, apparatus, device, and medium for managing three-dimensional models
CN115690365B
Virtual object comparison display method and device
CN118864791A
