Data processing method and device, computer equipment and storage medium

By calculating the spatial boundary vertices of the visual device and the initial world coordinates of the model, the geometric center of the model can be quickly located, solving the problem of low computational efficiency when there are many models or complex structures in 3D visualization, and achieving smooth switching and safe movement of perspectives.

CN120765743APending Publication Date: 2025-10-10CHONGQING JINKANG NEW ENERGY VEHICLE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510893464.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

In 3D visualization applications, when there are many models or the structure is complex, the calculation efficiency of the model's geometric center is low, resulting in unsmooth perspective switching.

Method used

By obtaining the initial position parameters of the visual device, the coordinates of the space boundary vertices are calculated, and the geometric center of the model is calculated in combination with the initial world coordinates of the model to avoid traversing the model bounding box, and the view matrix is ​​used to realize perspective switching and collision detection.

Benefits of technology

The calculation efficiency of the model's geometric center is significantly improved, and fast positioning and smooth switching of viewing angles are achieved, ensuring the safe movement of visual equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120765743A_ABST
    Figure CN120765743A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method and device, computer equipment and a storage medium, relates to the technical field of three-dimensional scene application, and is used for solving the problem of low calculation efficiency of a model geometric center when the number of models in a scene is large or the model structure is complex. The method comprises the following steps: acquiring an initial position parameter of visual equipment in a scene, and calculating a space boundary vertex coordinate corresponding to the visual equipment according to the initial position parameter; initial world coordinates of the model in the scene are obtained, and the geometric center of the model is calculated based on the initial world coordinates and the space boundary vertex coordinates.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of three-dimensional scene application technology, and in particular to a data processing method, device, computer equipment and storage medium. Background Art

[0002] In 3D visualization applications, camera perspective control directly impacts the user experience, especially in projects that require dynamic model loading or scene perspective switching. For example, in scenarios such as virtual reality, building information modeling, digital twins, or game development, users often need to quickly focus on the center of different models to achieve smooth perspective switching.

[0003] In related technologies, the calculation method of the model's geometric center usually relies on the calculation of the model's bounding box. However, this method is inefficient when there are many models in the scene or the model structure is complex. Summary of the Invention

[0004] Based on this, a data processing method, apparatus, computer device and storage medium are provided to solve the problem in related technologies of low efficiency in calculating the geometric center of a model when there are a large number of models in a scene or the model structure is complex.

[0005] In a first aspect, the present invention provides a data processing method, comprising:

[0006] Obtaining initial position parameters of a visual device in the scene, and calculating the coordinates of a space boundary vertex corresponding to the visual device based on the initial position parameters;

[0007] The initial world coordinates of the model in the scene are obtained, and the geometric center of the model is calculated based on the initial world coordinates and the coordinates of the space boundary vertices.

[0008] In one embodiment, calculating the space boundary vertex corresponding to the visual device according to the initial position parameter includes:

[0009] Calculating the coordinates of the center point of the near clipping plane according to the first world coordinate, the orientation, and the near clipping plane distance in the initial position parameters, and calculating the coordinates of the center point of the far clipping plane according to the first world coordinate, the orientation, and the far clipping plane distance in the initial position parameters;

[0010] Calculating the near clipping plane size according to the vertical field angle, the aspect ratio and the near clipping plane distance in the initial position parameters, and calculating the far clipping plane size according to the vertical field angle, the aspect ratio and the far clipping plane distance;

[0011] Calculating the coordinates of a first boundary vertex of the near clipping plane according to the coordinates of the center point of the near clipping plane and the size of the near clipping plane, and calculating the coordinates of a second boundary vertex of the far clipping plane according to the coordinates of the center point of the far clipping plane and the size of the far clipping plane;

[0012] The first boundary vertex coordinates and the second boundary vertex coordinates are determined as the space boundary vertex coordinates.

[0013] In one embodiment, the calculating the model geometric center based on the initial world coordinates and the space boundary vertex coordinates includes:

[0014] The initial world coordinates and the space boundary vertex coordinates are averaged to obtain the model geometric center.

[0015] In one embodiment, after calculating the geometric center of the model, the method further includes:

[0016] Obtaining a perspective identifier, determining a current perspective according to the perspective identifier, and loading a second world coordinate of the visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective;

[0017] In response to receiving the target point coordinates corresponding to the current viewing angle, a view matrix of the visual device under the current viewing angle is generated based on the target point coordinates and the second world coordinates.

[0018] In one embodiment, generating a view matrix of the visual device at the current viewing angle based on the target point coordinates and the second world coordinates includes:

[0019] Calculating a direction vector between the target point coordinates and the second world coordinates;

[0020] Calculating a yaw angle and a pitch angle of the visual device based on the direction vector;

[0021] The view matrix is ​​generated based on the yaw angle and the pitch angle.

[0022] In one embodiment, after calculating the geometric center of the model, the method further includes:

[0023] In response to controlling the visual device to move according to a preset displacement vector, determining a movement target point based on the preset displacement vector;

[0024] Based on the moving target point and the preset viewpoint function, it is detected whether the visual device has a collision risk.

[0025] In one embodiment, detecting whether there is a collision risk with the visual device based on the moving target point and a preset viewpoint function includes:

[0026] Obtaining the current world coordinates of the visual device, and calculating a target direction vector between the moving target point and the current world coordinates;

[0027] Based on the target direction vector and the preset viewpoint function, emitting a ray from the current world coordinate toward the moving target point, and obtaining an array of intersection points between the ray and the object;

[0028] If the intersection array is empty, it is detected that there is no collision risk for the visual device;

[0029] If the intersection array is not empty, it is detected that there is a collision risk for the visual device.

[0030] In a second aspect, the present invention provides a data processing device, comprising:

[0031] An acquisition module, configured to acquire initial position parameters of a visual device in a scene, and calculate the coordinates of a space boundary vertex corresponding to the visual device based on the initial position parameters;

[0032] A calculation module is used to obtain the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

[0033] In a third aspect, the present invention provides a computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the data processing method of the first aspect when executing the computer program.

[0034] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the data processing method of the first aspect when executed by a processor.

[0035] The above-mentioned data processing method, device, computer equipment and storage medium, after calculating the spatial boundary vertex coordinates corresponding to the visual device through the initial position parameters of the visual device in the scene, only need to combine the spatial boundary vertex coordinates with the initial world coordinates of the model in the scene to calculate the geometric center of the model, without traversing the bounding boxes of all models, significantly improving the calculation efficiency of the model geometric center and realizing the rapid positioning of the model geometric center. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 1 is a flow chart of a data processing method in one embodiment;

[0037] Figure 2 is a schematic diagram of a scene world coordinate system in one embodiment;

[0038] Figure 3 A schematic diagram of boundary vertices of a visual device in one embodiment;

[0039] Figure 4 is a structural block diagram of a data processing device in one embodiment;

[0040] Figure 5 is a structural block diagram of a data processing device in another embodiment;

[0041] Figure 6 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail with reference to the accompanying drawings. The specific operating methods in the method embodiments can also be applied to device embodiments or system embodiments. It should be noted that in the description of the present invention, "multiple" is understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist, and B exists alone. A is connected to B, which can represent: A is directly connected to B and A is connected to B through C. In addition, in the description of the present invention, words such as "first" and "second" are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.

[0043] In order to facilitate understanding by those skilled in the art, the technical terms involved in the present invention are first explained.

[0044] (1) The 3D graphics engine library (Three JavaScript, Three.js) runs in the browser, allowing developers to create and display complex 3D graphics and animations on web pages without requiring users to install any additional plug-ins or software. In Three.js, the scene is a container for the 3D world, and all objects must be added to the scene before they can be displayed. The visual device in Three.js determines where and how the scene is viewed.

[0045] (2) The LookAt function is a very important function in computer graphics. It can calculate the rotation angle of an object relative to the observer in three-dimensional space. The LookAt function requires three parameters: the visual device position, the target point position, and the up vector. Among them, the visual device position and the target point position are vectors expressed in the scene world coordinate system, and the up vector is a vector perpendicular to the visual device orientation, which is used to determine the up and down direction of the visual device. Through these three parameters, the LookAt function can calculate the vector of the visual device orientation and convert it into a rotation matrix. Then, this rotation matrix is ​​applied to the model in the scene to rotate it to the correct perspective. In this way, the perspective transformation can be achieved by changing the visual device position, the target point position, and the up vector, so as to observe different angles in the three-dimensional scene.

[0046] (3) Three.Object3D in Three.js is the base class in Three.js. It is the foundation of all three-dimensional space. It is an abstract concept that represents an object that can be freely moved, rotated, and scaled in three-dimensional space, and can be controlled to be displayed and hidden.

[0047] In the technical solution of the present invention, the acquisition, transmission, storage, and use of data are in compliance with the requirements of relevant national laws and regulations.

[0048] Before introducing the data processing method provided by the present invention, for ease of understanding, the technical background of the present invention is introduced in detail below.

[0049] In related technologies, the calculation method of the model's geometric center usually relies on the calculation of the model's bounding box. For example, by traversing the coordinates of all vertices of the model's bounding box to determine the minimum and maximum coordinates, the coordinates of the center point of the model's bounding box are calculated based on the minimum and maximum coordinates = (minimum coordinate + maximum coordinate) / 2, which is the model's geometric center and is used as the camera's target point. However, this method is inefficient in calculating the model's geometric center when there are many models in the scene or the model structure is complex.

[0050] In view of this, the present invention provides a data processing method, apparatus, computer device and storage medium to solve the problem in related technologies of low efficiency in calculating the geometric center of a model when there are a large number of models in a scene or the model structure is complex.

[0051] The technical solution provided by the present invention is described in detail below with reference to the accompanying drawings and specific implementation methods.

[0052] Figure 1FIG1 is a flow chart of a data processing method in one embodiment. The flow chart can be executed by a data processing device. The device can be implemented by software, hardware, or a combination of software and hardware. Figure 2 As shown, the process includes the following steps:

[0053] S101, obtaining initial position parameters of a visual device in a scene, and calculating the coordinates of a space boundary vertex corresponding to the visual device according to the initial position parameters;

[0054] S102: Obtain the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

[0055] The scene can be a three-dimensional scene in Three.js; the visual device can be a three-dimensional scene camera in Three.js, such as a perspective camera, an orthographic camera, etc.; the spatial boundary corresponding to the visual device represents the visible range of the visual device in the scene, which can be represented by a viewing frustum. The viewing frustum is composed of two rectangles, a near clipping plane and a far clipping plane, and the two rectangles are connected by four edges. The coordinates of the spatial boundary vertices are the coordinates of the eight vertices of the viewing frustum.

[0056] For example, Three.js uses a right-handed coordinate system, that is, the three fingers of the right hand are stretched out, pointing in the direction of the X, Y and Z axes respectively. The direction pointed by the thumb is the X axis, the direction pointed by the index finger is the Y axis, and the direction pointed by the middle finger is the Z axis. In Three.js, the coordinate system is divided into the scene world coordinate system and the local coordinate system, which are used to describe the position of objects (such as models, visual devices, etc.) in the global scene and the transformation of objects relative to themselves. The scene world coordinate system is the global coordinate system of the entire Three.js scene, which is used to uniformly describe the position, rotation and scale of all objects in the scene. The origin of the scene world coordinate system (0, 0, 0) is the reference point of the entire scene. No matter how the object moves, rotates or scales, the scene world coordinate system remains unchanged.

[0057] like Figure 1 , which is a schematic diagram of the scene world coordinate system in one embodiment, wherein the X-axis represents the horizontal direction, with the positive direction pointing to the right; the Y-axis represents the vertical direction, with the positive direction pointing upward; and the Z-axis represents the depth direction, with the positive direction pointing outside the observer and the negative direction pointing inside the observer.

[0058] The local coordinate system is the object's own coordinate system. Each object has its own local coordinate system, which is used to describe its internal coordinate reference. The origin of the local coordinate system is usually located at the center of the object (unless the model itself defines a different origin). The origin of the object's local coordinate system always follows the object's position and rotation. Transformations in the local coordinate system are relative to the object itself, not the scene's world coordinate system.

[0059] Based on this, the initial position parameters of the visual device in the scene include but are not limited to: first world coordinates; orientation: the pointing direction of the visual device, usually the position of a target point; up direction: the direction in which the visual device "points", which is the Y axis in the scene's world coordinate system; vertical field of view (FOV): the viewing angle range of the visual device in the vertical direction (unit: angle); aspect ratio: the ratio of the width to the height of the visual device's viewport; near clipping plane distance: the closest distance that the visual device can see, and models smaller than this closest distance are clipped; far clipping plane distance: the farthest distance that the visual device can see, and models beyond this farthest distance are clipped.

[0060] In the above data processing method, after calculating the spatial boundary vertex coordinates corresponding to the visual device through the initial position parameters of the visual device in the scene, it is only necessary to combine the spatial boundary vertex coordinates with the initial world coordinates of the model in the scene to calculate the model geometric center. There is no need to traverse all the vertex coordinates of the model bounding box, which significantly improves the calculation efficiency of the model geometric center and realizes the rapid positioning of the model geometric center.

[0061] In one embodiment, for example, calculating the coordinates of the space boundary vertices corresponding to the visual device according to the initial position parameters in S101 includes but is not limited to:

[0062] First, calculate the coordinates C of the center point of the near clipping plane based on the first world coordinates, orientation, and near clipping plane distance in the initial position parameters. near = first world coordinate + direction * distance to the nearest clipping plane, and calculate the coordinates of the center point of the far clipping plane C through the first world coordinate, direction and distance to the far clipping plane far = first world coordinate + direction * far clipping plane distance.

[0063] For example, the first world coordinate = (0, 0, 0), the orientation = (0, 0, -1), the near clipping plane distance = 1, the far clipping plane distance = 10, then C near =(0,0,0)+1*(0,0,-1)=(0,0,-1);C far =(0,0,0)+10*(0,0,-1)=(0,0,-10).

[0064] The near clipping plane size is calculated based on the vertical FOV, aspect ratio and near clipping plane distance in the initial position parameters, and the far clipping plane size is calculated based on the vertical FOV, aspect ratio and far clipping plane distance, where the size includes height and width, and the near clipping plane height h near =2*near clipping plane distance*tan(vertical FOV / 2), near clipping plane width w near =h near * aspect ratio; far clipping plane height h far =2*far clipping plane distance*tan(vertical FOV / 2), far clipping plane width w far =h far *Aspect ratio.

[0065] Then, according to C near and the size of the near clipping plane, calculate the coordinates of the first boundary vertex of the near clipping plane, and according to C far And the far clipping plane size, calculate the coordinates of the second boundary vertex of the far clipping plane.

[0066] like Figure 3 FIG. 1 is a schematic diagram of the boundary vertices of a visual device in one embodiment, wherein the boundary vertex coordinates of the visual device include the first boundary vertex coordinates of the near clipping surface: V n1 、V n2 、V n3 、V n4 And the coordinates of the second boundary vertex of the far clipping plane: V f1 、V f2 、V f3 、V f4 , and V n1 -V n3 or V n2 -V n4 h near , V n1 -V n2 or V n3 -V n4 w near ; V f1 -V f3 or V f2 -V f4 h far , V f1 -V f2 or V f3 -V f4 w far .

[0067] By normalizing the orientation in the initial position parameters, a unit vector is obtained, and based on the unit vector and the upward direction in the initial position parameters, the right direction of the visual device r = unit vector × upward direction is calculated, and the upward direction is corrected based on r and the unit vector to obtain the corrected upward direction u = unit vector × r.

[0068] Then the coordinates of the first boundary vertex: V n1 =C near -(w near / 2)r+(h near / 2)u、V n2 =C near +(w near / 2)r+(h near / 2)u、V n3 =C near -(w near / 2)r-(h near / 2)u、V n4 =C near +(w near / 2)r-(h near / 2)u; coordinates of the second boundary vertex: V f1 =C far -(w far / 2)r+(h far / 2)u、V f2 =C far +(w far / 2)r+(h far / 2)u、V f3 =C far -(w far / 2)r-(h far / 2)u、V f4 =C far +(w far / 2)r-(h far / 2)u.

[0069] Finally, the first boundary vertex coordinates and the second boundary vertex coordinates are determined to be the spatial boundary vertex coordinates of the visual device and are stored. Therefore, when controlling the movement of the visual device, there is no need to recalculate the corresponding spatial boundary vertex coordinates based on the initial position parameters of the visual device. Instead, the spatial boundary vertex coordinates only need to be updated according to the movement amount of the visual device.

[0070] Through the above method, based on the first world coordinates, orientation, near / far clipping plane distance, vertical field of view angle and aspect ratio of the visual device, the spatial boundary vertices corresponding to the visual device can be accurately calculated, thereby providing an accurate geometric basis for the calculation of the model's geometric center.

[0071] In one embodiment, it is exemplarily illustrated that the calculation of the model geometric center based on the initial world coordinates of the model and the spatial boundary vertex coordinates in S102 includes but is not limited to:

[0072] The initial world coordinates of the model and the spatial boundary vertex coordinates are calculated by the average value to obtain the model geometric center, and the model geometric center is set as the orientation of the visual device.

[0073] For example, the initial world coordinates of the model are (x1, y1, z1), and the spatial boundary vertex coordinates include: (x 21 , y 21 , z 21 ), (x 22 , y 22 , z 22 ), (x 23 , y 23 , z 23 ), (x 24 , y 24 , z 24 ), (x 31 , y 31 , z 31 ), (x 32 , y 32 , z 32 ), (x 33 , y 33 , z 33 ), (x 34 , y 34 , z 34 ).

[0074] The initial world coordinates of the model and the spatial boundary vertex coordinates are calculated by the average value to obtain the model geometric center C = [(x1+x 21 +x 22 +x 23 +x 24 +x 31 +x 32 +x 33 +x 34 ) / 9, (y1+y 21 +y 22 +y 23 +y 24 +y 31 +y 32 +y 33 +y 34 ) / 9, (z1+z 21 +z 22 +z 23 +z 24 +z 31 +z 32 +z 33+z 34 ) / 9].

[0075] Through the above method, based on the average value of the model's initial world coordinates and the coordinates of the space boundary vertices, the model's geometric center can be quickly solved, thereby enabling the visual device to quickly locate the model's geometric center.

[0076] In one embodiment, for example, after calculating the geometric center of the model in S102, the method further includes:

[0077] Obtain a perspective identifier, determine the current perspective based on the perspective identifier, and load the second world coordinates of the visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective.

[0078] For example, when the perspective identifier is "0", the current perspective is determined to be a first-person perspective; when the perspective identifier is "1", the current perspective is determined to be a third-person perspective. The specific identifier depends on the situation and is not limited here.

[0079] In the present invention, the initial parameters of the visual device under different personal perspectives can be pre-defined, where the initial parameters include but are not limited to Euler angles (yaw angle: rotation around the Y axis, pitch angle: rotation around the X axis, roll angle: rotation around the Z axis), second world coordinates, orientation, and upward direction. The specific values ​​of the initial parameters depend on the situation and are not limited here.

[0080] For example, define the first initial yaw angle m_yaw = 0.0, the first initial pitch angle m_pitch = 0.0, and the first initial roll angle m_roll = 0.0 of the visual device under the first-person perspective, the second world coordinate P_m = (x_m: 3000.0, y_m: 3000.0, z_m: 3000.0), the first direction LookAt_m = (x_m: 0.0, y_m: 0.0, z_m: 0.0), and the first upward direction Up_m = (x_m: 0.0, y_m: 1.0, z_m: 0.0).

[0081] Define the second initial yaw angle t_yaw = -45.0, the second initial pitch angle t_pitch = 27.0, and the second initial roll angle t_roll = 0.0 of the visual device under the third-person perspective, the second world coordinate P_t = (x_t: 0.0, y_t: 0.0, z_t: 0.0), the second direction LookAt_t = (x_t: 0.0, y_t: 0.0, z_t: 0.0), and the second upward direction Up_t = (x_t: 0.0, y_t: 1.0, z_t: 0.0).

[0082] In response to receiving the target point coordinates corresponding to the current viewing angle, a view matrix of the visual device under the current viewing angle is generated based on the target point coordinates and the second world coordinates. The target point coordinates can be the geometric center of the model, depending on the specific situation and is not limited here.

[0083] Through the above method, the first-person perspective and the third-person perspective are dynamically switched based on the perspective identifier, and when the corresponding target point coordinates are received, the view matrix of the visual device under the current perspective is generated based on the target point coordinates and the second world coordinates of the visual device, thereby achieving low-latency perspective switching control.

[0084] In one embodiment, the view matrix of the visual device at the current viewing angle is generated based on the target point coordinates and the second world coordinates, including but not limited to:

[0085] Calculate the direction vector D between the target point coordinate T and the second world coordinate P, and calculate the yaw angle and pitch angle of the visual device based on D.

[0086] For example, T = (T x , T y , T z ), P=(x, y, z), then the difference between T and P is calculated to get D=(T x -x,T y -y,T z -z)=(D x , D y , D z ).

[0087] Define an angle calculation function this.computIncludedAngle, which calculates the angle between the second world coordinate and the target point coordinate on the XZ plane, that is, yaw. Substitute the x, z in P and T in T x 、T z Input this.computIncludedAngle to get the yaw of the vision device.

[0088] At the same time, get the horizontal distance between T and P and actual distance If D y >0, based on drx and dr, calculate the visual device If D y1 ≤0, then based on drx and dr, the visual device is calculated

[0089] Then, based on yaw and pitch, the view matrix of the visual device is generated. The specific generation method depends on the situation and is not limited here.

[0090] For example, the forward vector F of the visual device is calculated based on yaw and pitch = (F x , F y , F z ), F x =sin(yaw)*cos(pitch), F y =sin(pitch), F z = cos(yaw)*cos(pitch). And generate the view matrix through the LookAt function, then the visual device position in the LookAt function is P, and the target point position is P+F=(x+F x , y+F y , z+F z ), the up vector is the up direction in the initial parameters of the visual device under the current viewing angle.

[0091] Through the above method, the yaw angle and pitch angle of the visual device are determined based on the direction vector between the target point coordinates and the second world coordinates of the visual device, and an accurate view matrix is ​​generated based on the yaw angle and pitch angle, thereby realizing automatic alignment and smooth control of the perspective in three-dimensional space, thereby realizing dynamic perspective switching.

[0092] Optionally, in the present invention, the second world coordinates under different viewing angles are different, and therefore, based on the direction vector between T and P, the yaw and pitch of the visual device calculated are also different. For example:

[0093] If the current perspective is a first-person perspective, the first yaw angle m_yaw1 and the first pitch angle m_pitch1 of the visual device are calculated based on the direction vector between T and P_m, and m_yaw1 is controlled within a first angle range, and m_pitch1 is controlled within a second angle range.

[0094] The first angle range can be [0, 360] degrees. If m_yaw1 < 0 degrees, m_yaw1 is set to 0 degrees; if m_yaw1 > 360 degrees, m_yaw1 is set to 360 degrees. The second angle range can be [-89.9, 89.9] degrees. If m_pitch1 < -89.9 degrees, m_pitch1 is set to -89.9 degrees; if m_pitch1 > 89.9 degrees, m_pitch1 is set to 89.9 degrees. The specific range values ​​of the first and second angle ranges vary depending on the situation and are not limited here.

[0095] If the current perspective is a third-person perspective, the second yaw angle t_yaw1 and the second pitch angle t_pitch1 of the visual device are calculated based on the direction vector between T and P_t, and t_yaw1 is controlled within the third angle range, and t_pitch1 is controlled within the fourth angle range.

[0096] The third angle range may be [-360, 360] degrees. If t_yaw1 < -360 degrees, t_yaw1 is set to -360 degrees. If t_yaw1 > 360 degrees, t_yaw1 is set to 360 degrees. The fourth angle range may be (90, 270) degrees and (-270, -90) degrees. If t_pitch1 is between [89.9, 90] degrees or [-90, -89.9] degrees, processing is terminated immediately. If t_pitch1 < -270 degrees, t_pitch1 is set to -270 degrees. If t_pitch1 > 270 degrees, t_pitch1 is set to 270 degrees. The specific range values ​​of the third and fourth angle ranges depend on the circumstances and are not limited here.

[0097] Through the above method, by constraining the angle range of m_yaw1, m_pitch1, t_yaw1 and t_pitch1 in the third-person perspective and in the third-person perspective respectively, the rationality of the perspective of the visual device can be ensured, and the perspective control without gimbal deadlock can be achieved.

[0098] In one embodiment, for example, after calculating the geometric center of the model in S102, the method further includes:

[0099] In response to controlling the movement of the visual device according to the preset displacement vector, a moving target point R=(R x , R y , R z ) (such as controlling the visual device to move forward, backward, left and right through the "W", "A", "S", and "D" keys on the keyboard. The specific control method depends on the situation and is not limited here), wherein the preset displacement vector at least includes a preset moving distance r1.

[0100] For example, if the current world coordinates of the visual device are (x1, y1, z1), then R x =x1+r1*cos[radians(pitch1)]*cos[radians(yaw1)], R y =y1+r1*sin[radians(pitch1)], R x= z1 + r1 * cos[radians(pitch1)] * sin[radians(yaw1)], where the radians function is used to convert the angle value to radians. Radians = angle value × (360 / 2π). The specific calculation method depends on the situation and is not limited here.

[0101] Then, based on R and a preset viewpoint function, it is detected whether the visual device has a collision risk. The preset viewpoint function can be a ray viewpoint function computeRaycasterPoint. The specific viewpoint function depends on the situation and is not limited here.

[0102] For example, a ray casting instance Raycaster(origin: Vector3, direction: Vector3, near: Float, far: Float) is defined, where origin represents the starting point of the ray; direction represents the direction vector (normalized) that provides the direction for the ray; near represents that all returned results are farther than near, and near cannot be a negative value, and its default value is 0 (the specific value depends on the situation and is not limited here); far represents that all returned results are closer than far, and far is greater than near, and its default value is positive infinity (the specific value depends on the situation and is not limited here).

[0103] Define ComputRaycasterPoint(origin, direction) to calculate the objects that intersect with the ray emitted from origin toward direction in the current scene, and return an array of intersection points between the ray and the object.

[0104] Through the above method, R is determined based on the preset displacement vector, and combined with the preset viewpoint function, it is detected in real time whether there is a collision risk of the visual device, thereby realizing precise mobile control and dynamic obstacle avoidance based on the visual device.

[0105] In one embodiment, after predefining the above-mentioned instances and functions, detecting whether there is a collision risk of the visual device based on R and the preset viewpoint function includes but is not limited to:

[0106] Get the current world coordinates of the vision device and calculate the target direction vector between R and the current world coordinates. For example, calculate the difference between R and the current world coordinates to obtain the target direction vector.

[0107] Then, based on the target direction vector and the preset viewpoint function, a ray is emitted from the current world coordinate toward R, and an array of intersection points between the ray and the object is obtained. For example, the current world coordinates of the visual device and the target direction vector are input into ComputRaycasterPoint(origin, direction) to obtain an array of intersection points between the ray and the object.

[0108] Alternatively, if the current world coordinates of the visual device are directly used as the origin, objects near the visual device (such as part of the character model itself) may be detected, leading to misjudgment. Therefore, the current world coordinates can be shifted down by a preset value, and the current world coordinates after the shift can be used as the launch starting point to avoid its own interference. For example, if the current world coordinates are (x1, y1, z1) and the preset value is 1300, then the launch starting point is determined to be (x1, y1-1300, z1). The specific value of the preset value depends on the situation and is not limited here.

[0109] If the intersection array is empty, it is detected that there is no collision risk for the visual device; if the intersection array is not empty, it is detected that there is a collision risk for the visual device.

[0110] Optionally, if the intersection array is not empty, and the intersection array contains various object sets, each of which contains at least the object hit by the ray (Three.Object3D), the distance from the emission starting point to the object, and the world coordinates of the object, then any object in the intersection array is obtained, and the parent object corresponding to any object is determined (because complex models may be nested, the actual collision body may be a subcomponent of a door, such as a door handle, so the parent object two levels above can be obtained. The specific level depends on the situation and is not limited here). If the object type of any object or the parent object corresponding to any object is "door", then any object is removed from the intersection array and ignored, thereby avoiding misjudging interactive objects as obstacles.

[0111] In addition, the moving speed of the visual device can be customized according to the target moving point, and the moving distance of the visual device can be calculated in real time based on the moving speed. When the difference between the distance from the launch starting point to the object and the device moving distance is less than the preset distance (the specific value of the preset distance depends on the situation and is not limited here), stop moving the visual device to avoid penetration or numerical jitter.

[0112] Through the above method, based on the target direction vector between the moving target point and the current world position of the visual device, rays are emitted for collision detection, and an array of intersection points between the rays and the object is obtained. This can achieve efficient and accurate motion path obstacle detection and ensure the safety of the visual device movement.

[0113] Optionally, before detecting whether the visual device is at risk of collision based on the moving target point and the preset viewpoint function, it may be further determined whether collision detection is currently enabled. For example, a collision detection switch flag may be obtained. If the collision detection switch flag is a true value of "true," collision detection is enabled; if the collision detection switch flag is a false value of "false," collision detection is not enabled, and movement of the visual device is permitted by default. The specific determination method may vary depending on the circumstances and is not limited herein.

[0114] Through the above method, flexible control of collision detection can be achieved. When collision detection is not needed (such as playing a cutscene animation, etc.), turning off collision detection can reduce the computational burden.

[0115] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0116] In one embodiment, Figure 4 As shown, a data processing device is provided, including: an acquisition module 401 and a calculation module 402, wherein:

[0117] An acquisition module 401 is used to acquire initial position parameters of a visual device in a scene and calculate the coordinates of a space boundary vertex corresponding to the visual device based on the initial position parameters;

[0118] The calculation module 402 is used to obtain the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

[0119] In one embodiment, the acquisition module 401 is used to:

[0120] Calculate the coordinates of the center point of the near clipping plane according to the first world coordinate, orientation and near clipping plane distance in the initial position parameters, and calculate the coordinates of the center point of the far clipping plane according to the first world coordinate, orientation and far clipping plane distance in the initial position parameters;

[0121] Calculate the near clipping plane size based on the vertical field of view angle, aspect ratio and near clipping plane distance in the initial position parameters, and calculate the far clipping plane size based on the vertical field of view angle, aspect ratio and far clipping plane distance;

[0122] Calculate the coordinates of the first boundary vertex of the near clipping plane according to the coordinates of the center point of the near clipping plane and the size of the near clipping plane, and calculate the coordinates of the second boundary vertex of the far clipping plane according to the coordinates of the center point of the far clipping plane and the size of the far clipping plane;

[0123] The first boundary vertex coordinates and the second boundary vertex coordinates are determined as space boundary vertex coordinates.

[0124] In one embodiment, the calculation module 402 is configured to:

[0125] The geometric center of the model is obtained by averaging the initial world coordinates and the coordinates of the space boundary vertices.

[0126] In another embodiment, in addition to the above Figure 4 In addition to the modules shown in FIG. , it may further include a perspective switching module and a collision detection module, such as Figure 5 FIG. 4 is a block diagram of a data processing device in another embodiment, wherein the device comprises an acquisition module 401 , a calculation module 402 , a view switching module 501 and a collision detection module 502 .

[0127] The perspective switching module 501 is used to obtain a perspective identifier, determine the current perspective based on the perspective identifier, and load the second world coordinates of the visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective; in response to receiving the target point coordinates corresponding to the current perspective, generate a view matrix of the visual device under the current perspective based on the target point coordinates and the second world coordinates.

[0128] The collision detection module 502 is used to control the movement of the visual device in response to the preset displacement vector, determine the moving target point based on the preset displacement vector; and detect whether there is a collision risk of the visual device based on the moving target point and the preset viewpoint function.

[0129] In one embodiment, the perspective switching module 501 is used to:

[0130] Calculate the direction vector between the target point coordinates and the second world coordinates;

[0131] Calculate the yaw and pitch angles of the visual device based on the direction vector;

[0132] Based on the yaw and pitch angles, a view matrix is ​​generated.

[0133] In one embodiment, the collision detection module 502 is configured to:

[0134] Get the current world coordinates of the visual device and calculate the target direction vector between the moving target point and the current world coordinates;

[0135] Based on the target direction vector and the preset viewpoint function, a ray is emitted from the current world coordinate toward the moving target point, and an array of intersection points between the ray and the object is obtained;

[0136] If the intersection array is empty, there is no collision risk for the detection vision device;

[0137] If the intersection array is not empty, there is a collision risk in the detection vision device.

[0138] For the specific definition of the data processing device, please refer to the definition of the data processing method above and will not be repeated here. Each module in the above-mentioned data processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software so that the processor can call and execute the operations corresponding to each of the above modules.

[0139] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data processing data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a data processing method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0140] Those skilled in the art will understand that Figure 6 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present invention and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0141] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are performed:

[0142] Obtain the initial position parameters of the visual device in the scene, and calculate the coordinates of the spatial boundary vertex corresponding to the visual device based on the initial position parameters;

[0143] Get the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

[0144] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0145] Calculate the coordinates of the center point of the near clipping plane according to the first world coordinate, orientation and near clipping plane distance in the initial position parameters, and calculate the coordinates of the center point of the far clipping plane according to the first world coordinate, orientation and far clipping plane distance in the initial position parameters;

[0146] Calculate the near clipping plane size based on the vertical field of view angle, aspect ratio and near clipping plane distance in the initial position parameters, and calculate the far clipping plane size based on the vertical field of view angle, aspect ratio and far clipping plane distance;

[0147] Calculate the coordinates of the first boundary vertex of the near clipping plane according to the coordinates of the center point of the near clipping plane and the size of the near clipping plane, and calculate the coordinates of the second boundary vertex of the far clipping plane according to the coordinates of the center point of the far clipping plane and the size of the far clipping plane;

[0148] The first boundary vertex coordinates and the second boundary vertex coordinates are determined as space boundary vertex coordinates.

[0149] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0150] The geometric center of the model is obtained by averaging the initial world coordinates and the coordinates of the space boundary vertices.

[0151] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0152] Obtaining a perspective identifier, determining a current perspective based on the perspective identifier, and loading a second world coordinate of a visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective;

[0153] In response to receiving the target point coordinates corresponding to the current viewing angle, a view matrix of the visual device under the current viewing angle is generated based on the target point coordinates and the second world coordinates.

[0154] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0155] Calculate the direction vector between the target point coordinates and the second world coordinates;

[0156] Calculate the yaw and pitch angles of the visual device based on the direction vector;

[0157] Based on the yaw and pitch angles, a view matrix is ​​generated.

[0158] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0159] In response to controlling the visual device to move according to the preset displacement vector, determining a movement target point based on the preset displacement vector;

[0160] Based on the moving target point and the preset viewpoint function, the visual device is detected to see if there is a collision risk.

[0161] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0162] Get the current world coordinates of the visual device and calculate the target direction vector between the moving target point and the current world coordinates;

[0163] Based on the target direction vector and the preset viewpoint function, a ray is emitted from the current world coordinate toward the moving target point, and an array of intersection points between the ray and the object is obtained;

[0164] If the intersection array is empty, there is no collision risk for the detection vision device;

[0165] If the intersection array is not empty, there is a collision risk in the detection vision device.

[0166] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0167] Obtain the initial position parameters of the visual device in the scene, and calculate the coordinates of the spatial boundary vertex corresponding to the visual device based on the initial position parameters;

[0168] Get the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

[0169] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0170] Calculate the coordinates of the center point of the near clipping plane according to the first world coordinate, orientation and near clipping plane distance in the initial position parameters, and calculate the coordinates of the center point of the far clipping plane according to the first world coordinate, orientation and far clipping plane distance in the initial position parameters;

[0171] Calculate the near clipping plane size based on the vertical field of view angle, aspect ratio and near clipping plane distance in the initial position parameters, and calculate the far clipping plane size based on the vertical field of view angle, aspect ratio and far clipping plane distance;

[0172] Calculate the coordinates of the first boundary vertex of the near clipping plane according to the coordinates of the center point of the near clipping plane and the size of the near clipping plane, and calculate the coordinates of the second boundary vertex of the far clipping plane according to the coordinates of the center point of the far clipping plane and the size of the far clipping plane;

[0173] The first boundary vertex coordinates and the second boundary vertex coordinates are determined as space boundary vertex coordinates.

[0174] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0175] The geometric center of the model is obtained by averaging the initial world coordinates and the coordinates of the space boundary vertices.

[0176] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0177] Obtaining a perspective identifier, determining a current perspective based on the perspective identifier, and loading a second world coordinate of a visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective;

[0178] In response to receiving the target point coordinates corresponding to the current viewing angle, a view matrix of the visual device under the current viewing angle is generated based on the target point coordinates and the second world coordinates.

[0179] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0180] Calculate the direction vector between the target point coordinates and the second world coordinates;

[0181] Calculate the yaw and pitch angles of the visual device based on the direction vector;

[0182] Based on the yaw and pitch angles, a view matrix is ​​generated.

[0183] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0184] In response to controlling the visual device to move according to the preset displacement vector, determining a movement target point based on the preset displacement vector;

[0185] Based on the moving target point and the preset viewpoint function, the visual device is detected to see if there is a collision risk.

[0186] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0187] Get the current world coordinates of the visual device and calculate the target direction vector between the moving target point and the current world coordinates;

[0188] Based on the target direction vector and the preset viewpoint function, a ray is emitted from the current world coordinate toward the moving target point, and an array of intersection points between the ray and the object is obtained;

[0189] If the intersection array is empty, there is no collision risk for the detection vision device;

[0190] If the intersection array is not empty, there is a collision risk in the detection vision device.

[0191] Those skilled in the art will appreciate that all or part of the processes in the above-described embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the above-described embodiments. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct RAM bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM).

[0192] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0193] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.

Claims

1. A data processing method, characterized in that: The method comprises: Obtaining initial position parameters of a visual device in the scene, and calculating the coordinates of a space boundary vertex corresponding to the visual device based on the initial position parameters; The initial world coordinates of the model in the scene are obtained, and the geometric center of the model is calculated based on the initial world coordinates and the coordinates of the space boundary vertices.

2. The method according to claim 1, characterized in that Calculating the space boundary vertex corresponding to the visual device according to the initial position parameter includes: Calculating the coordinates of the center point of the near clipping plane according to the first world coordinate, the orientation, and the near clipping plane distance in the initial position parameters, and calculating the coordinates of the center point of the far clipping plane according to the first world coordinate, the orientation, and the far clipping plane distance in the initial position parameters; Calculating the near clipping plane size according to the vertical field angle, the aspect ratio and the near clipping plane distance in the initial position parameters, and calculating the far clipping plane size according to the vertical field angle, the aspect ratio and the far clipping plane distance; Calculating the coordinates of a first boundary vertex of the near clipping plane according to the coordinates of the center point of the near clipping plane and the size of the near clipping plane, and calculating the coordinates of a second boundary vertex of the far clipping plane according to the coordinates of the center point of the far clipping plane and the size of the far clipping plane; The first boundary vertex coordinates and the second boundary vertex coordinates are determined as the space boundary vertex coordinates.

3. The method according to claim 1, characterized in that The step of calculating the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices includes: The initial world coordinates and the space boundary vertex coordinates are averaged to obtain the model geometric center.

4. The method according to claim 1, characterized in that After calculating the geometric center of the model, the method further includes: Obtaining a perspective identifier, determining a current perspective according to the perspective identifier, and loading a second world coordinate of the visual device under the current perspective, wherein the perspective includes at least a first-person perspective and a third-person perspective; In response to receiving the target point coordinates corresponding to the current viewing angle, a view matrix of the visual device under the current viewing angle is generated based on the target point coordinates and the second world coordinates.

5. The method according to claim 4, characterized in that The generating, based on the target point coordinates and the second world coordinates, a view matrix of the visual device at the current viewing angle includes: Calculating a direction vector between the target point coordinates and the second world coordinates; Calculating a yaw angle and a pitch angle of the visual device based on the direction vector; The view matrix is ​​generated based on the yaw angle and the pitch angle.

6. The method according to claim 1, characterized in that After calculating the geometric center of the model, the method further includes: In response to controlling the visual device to move according to a preset displacement vector, determining a movement target point based on the preset displacement vector; Based on the moving target point and the preset viewpoint function, it is detected whether the visual device has a collision risk.

7. The method according to claim 6, characterized in that The detecting whether the visual device has a collision risk based on the moving target point and a preset viewpoint function includes: Obtaining the current world coordinates of the visual device, and calculating a target direction vector between the moving target point and the current world coordinates; Based on the target direction vector and the preset viewpoint function, emitting a ray from the current world coordinate toward the moving target point, and obtaining an array of intersection points between the ray and the object; If the intersection array is empty, it is detected that there is no collision risk for the visual device; If the intersection array is not empty, it is detected that there is a collision risk for the visual device.

8. A data processing device, characterized in that: The device comprises: An acquisition module, configured to acquire initial position parameters of a visual device in a scene, and calculate the coordinates of a space boundary vertex corresponding to the visual device based on the initial position parameters; A calculation module is used to obtain the initial world coordinates of the model in the scene, and calculate the geometric center of the model based on the initial world coordinates and the coordinates of the space boundary vertices.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.