Automatic way-finding method in scene based on ThreeJS framework

By performing passability detection in the ThreeJS framework and combining the PathFinding library to generate the best path, the problem of lack of automatic pathfinding function in the ThreeJS framework is solved, and the effect of accurately calculating feasible paths and free movement in complex scenarios is achieved.

CN119540501APending Publication Date: 2025-02-28HEFEI SHIER INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411679884.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The existing ThreeJS framework lacks automatic pathfinding in the scene, fails to identify obstacles and calculate the optimal movement path, resulting in limitations.

Method used

By pre-acquisitioning the size of the floor object in the scene, setting the block grid cells, performing passability detection, including solid barrier detection, gap detection and octree barrier detection, obtaining two-dimensional Vector3 array type data, and combining the PathFinding library to generate the best path between two points.

Benefits of technology

The automatic pathfinding function in the ThreeJS framework is realized, and the feasible paths in complex terrain can be accurately calculated based on the scene's geometry and object distribution, so that characters can move freely in diverse terrains, ensuring the accuracy and effectiveness of pathfinding.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540501A_ABST
    Figure CN119540501A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic way-finding method in a scene based on a ThreeJS framework, and relates to the technical field of webpage 3D application programs, and the method comprises the following steps: obtaining the size of a floor object in the scene on a three-dimensional coordinate system XOZ plane in advance, setting the unit length of a block grid unit to form a grid set, and setting the unit length of the block grid unit to form a three-dimensional coordinate system XOZ; the starting coordinate of the upper left corner of the grid set in the three-dimensional coordinate system, the coordinate of the center point of the first block grid unit and the column number and the row number of the grid set are calculated; according to the method, the optimal moving path between the two points is obtained in the scene based on the ThreeJS framework, the automatic path finding strategy in the 3D scene built by the ThreeJS is completed, the scene adaptability is high, the feasible path in the complex terrain can be accurately calculated according to the geometrical shape and object distribution of the scene, the role can freely move in the diversified terrain, and the effect of automatic path finding is achieved. According to the method, the path-finding accuracy and effectiveness are ensured, the method can be quickly integrated into a ThreeJS project, the automatic path-finding function is realized, and the development time and energy are saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of web 3D application programs, and in particular to an automatic path-finding method in a scene based on a ThreeJS framework. Background Art

[0002] With the rapid development of network technology, people's lives are inseparable from the Internet, and the demand for Web technology is also increasing. In order to improve the user's visual experience, Web-based visualization technology is becoming more and more widely used. While Web technology is developing rapidly, many traditional client software are also gradually expanding their applications to Web ports, providing users with a more convenient and quick way to use.

[0003] Most fluid grid display functions are implemented based on client software. Usually, the display function of fluid grids is often embedded in computing software. As the online working mode of multi-person collaboration becomes more and more popular, the functional requirements of online work gradually become prominent, and the technical development work based on the Web is increasingly valued. The mainstream Web view technologies mainly include ThreeJS, a-fram, Babylon.js, etc. Among them, ThreeJS is a 3D engine based on native WebGL encapsulation and operation. Among all WebGL engines, it is the 3D engine with the most documents and the most widely used in China. ThreeJS provides a scene object, which is a container for all 3D elements. Developers can add objects, light sources, cameras and other elements to the scene to build a complete 3D scene. For example, when creating an indoor scene, you can add objects such as walls, furniture, and lights to the scene to provide an environmental basis for automatic pathfinding.

[0004] However, ThreeJS is currently a common framework for implementing web 3D applications. When developing a Metaverse-type project based on a web page, it is necessary to click on the target point, and the character automatically moves from the starting point to the target point, and the moving path is automatically generated by the program. This framework does not provide obstacle recognition and calculation of the best moving path, resulting in certain limitations.

[0005] Currently, no effective solution has been proposed for the problems in the related technologies. Summary of the invention

[0006] In view of the problems in the related art, the present invention proposes an automatic pathfinding method in a scene based on the ThreeJS framework to overcome the above-mentioned technical problems existing in the existing related art.

[0007] The technical solution of the present invention is achieved in this way:

[0008] A method for automatically finding a path in a scene based on the ThreeJS framework includes the following steps:

[0009] Get the size of the floor object in the scene in the XOZ plane of the three-dimensional coordinate system in advance, set the unit length of the block grid unit to form a grid set, and calculate the starting coordinates of the upper left corner of the grid set in the three-dimensional coordinate system, the coordinates of the center point of the first block grid unit, and the number of columns and rows of the grid set;

[0010] The number of rows of the grid set is used as the number of outer loops, and the number of columns is used as the number of inner loops. In the inner loop, a passability check is performed, which includes: performing solid obstacle detection of the floor object to detect whether the block grid unit exists in the floor object and excluding the block grid unit where the solid object is located, performing gap detection to detect whether the center point of the current block grid unit is located in the middle of the gap to determine whether the current block grid unit is passable, and performing octree obstacle detection to detect whether the coordinate point on the current block grid unit is in the wall or the gap to determine whether the current block grid unit is passable;

[0011] According to the passability detection, obtain two-dimensional Vector3 array type data, including: block row and column coordinate data pathPosMatrix and block row and column passability data mapGrid, where: block row and column coordinate data pathPosMatrix is ​​used to indicate the row and column number and center point coordinates of each block grid unit in the grid set; block row and column passability data mapGrid is used to indicate whether the block grid unit in each row and column is in a passable state;

[0012] Combine the two-dimensional Vector3 array type data with the PathFinding library to generate the best path between two points, and operate the character to move on the path to complete the automatic pathfinding process.

[0013] Further, the solid obstacle detection of the floor object comprises the following steps:

[0014] Pre-calculate the center point coordinates of the current loop block grid unit;

[0015] Instantiate a Raycaster class ray provided by ThreeJS, set the coordinates of the ray's starting point to (centerPos.x, character height, centerPos.z), set the ray's direction to directly below, and use the intersectObject method of Raycaster to obtain a collection of object information in all scenes that the ray touches;

[0016] If there is a floor object in the object set, the grid unit of the block is recorded as impassable and the inner loop ends; otherwise, it is impassable and proceeds to the next step of gap detection.

[0017] Furthermore, the gap detection comprises the following steps:

[0018] Instantiate a Raycaster class ray provided by ThreeJS, the starting coordinates of the ray are (centerPos.x, character height, centerPos.z), and perform multi-directional detection;

[0019] If an obstacle-type object is detected in any two directions, it means that the block grid unit is located in the gap of the scene, and it is marked as impassable and the inner loop ends. Otherwise, it is impassable and enters the next step of octree obstacle detection.

[0020] Furthermore, the octree obstacle detection comprises the following steps:

[0021] The character is marked as a capsule, and the octree data constructed by the scene is combined with the character capsule to calculate whether the capsule has an intersection with the obstacles in the scene;

[0022] If there is an intersection, the map block grid unit is recorded as impassable, otherwise it is marked as passable and the memory loop ends.

[0023] Further, generating the optimal path includes the following steps:

[0024] Take the grid unit of the block where the character is currently located as the starting point;

[0025] Mark any place in the scene as the target end point. First, use the grid set to determine whether the coordinates of the target end point belong to the block grid unit. If not, exit the path finding process. Otherwise, obtain the row and column numbers of the block grid unit of the target end point.

[0026] After obtaining the row and column numbers of the target destination block grid unit, determine whether the target destination block grid unit is surrounded by inaccessible block grid units. If so, obtain the accessible block grid unit closest to the target destination block grid unit as the new target destination and proceed to the next step. Otherwise, proceed directly to the next step.

[0027] According to the two-dimensional Vector3 array type data combined with the findPath method of the PathFinding library, the block order set of the best path from the starting block grid unit to the target end block grid unit is obtained, and the corresponding coordinate point set is obtained according to the block order set as the best path coordinate point set.

[0028] Beneficial effects of the present invention:

[0029] The present invention is based on the automatic pathfinding method in the scene of the ThreeJS framework, pre-acquires the size of the floor object in the scene on the XOZ plane of the three-dimensional coordinate system, sets the unit length of the block grid unit to form a grid set, and calculates the starting coordinates of the upper left corner of the grid set in the three-dimensional coordinate system, the coordinates of the center point of the first block grid unit and the number of columns and rows of the grid set, takes the number of rows of the grid set as the number of outer loops, and the number of columns as the number of inner loops, performs a passability test in the inner loop, obtains two-dimensional Vector3 array type data according to the passability test, combines the two-dimensional Vector3 array type data with the PathFinding library, generates the best path between two points, and operates the character to move on the path, completes the automatic pathfinding process, realizes obtaining the best moving path between two points in the scene based on the ThreeJS framework, and completes the automatic pathfinding strategy in the 3D scene built by ThreeJS, not only has strong scene adaptability, but also can accurately calculate the feasible path in the complex terrain according to the geometric shape and object distribution of the scene, so that the character can move freely in the diverse terrain, ensures the accuracy and effectiveness of the pathfinding, and can be quickly integrated into the ThreeJS In the project, the automatic pathfinding function is implemented, which saves development time and energy. At the same time, the automatic pathfinding strategy based on ThreeJS has high reusability and scalability. Developers can encapsulate the pathfinding function into an independent module and reuse it in different 3D scene projects, and can expand and optimize the scene according to specific needs. In addition, the user experience is enhanced. When users browse the 3D scene built by ThreeJS, the automatic pathfinding function can make the character or perspective move automatically along a reasonable path without manual operation by the user, allowing users to focus more on the scene content, as if they were in it, enhancing the sense of immersion. At the same time, for complex 3D scenes, it may be difficult to manually control the pathfinding of the character. The automatic pathfinding function provides users with a convenient navigation method. They only need to specify the starting point and the end point to automatically find a feasible path, which reduces the difficulty of user operation and improves the efficiency of interaction. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0031] Figure 1 It is a flowchart of an automatic path finding method in a scene based on the ThreeJS framework according to an embodiment of the present invention;

[0032] Figure 2is a schematic diagram of the size of a floor object according to an automatic pathfinding method in a scene based on a ThreeJS framework according to an embodiment of the present invention;

[0033] Figure 3 It is a schematic diagram of a grid set of an automatic path finding method in a scene based on a ThreeJS framework according to an embodiment of the present invention;

[0034] Figure 4 It is a schematic diagram of a feasibility detection process of an automatic path finding method in a scene based on a ThreeJS framework according to an embodiment of the present invention;

[0035] Figure 5 is a schematic diagram of solid obstacle detection in a scene based on an automatic pathfinding method of a ThreeJS framework according to an embodiment of the present invention, wherein (a) indicates that the detection ray is not located in a wall or obstacle and has an intersection with a floor object, (b) indicates that the detection ray is not located in a wall or obstacle and has no intersection with a floor object, and (c) indicates that the detection ray is located in a wall or obstacle and has an intersection with a floor object;

[0036] Figure 6 1 is a schematic diagram of gap detection of an automatic pathfinding method in a scene based on a ThreeJS framework according to an embodiment of the present invention; (a) in the figure is emitting rays in the positive direction of the Z axis, (b) is emitting rays in the positive direction of the X axis, (c) is emitting rays in the negative direction of the Z axis, and (d) is emitting rays in the negative direction of the X axis;

[0037] Figure 7 : is a schematic diagram of an octree obstacle detection method based on a ThreeJS framework in a scene according to an embodiment of the present invention; FIG. (a) is a schematic diagram of an obstacle detection method. Figure 1 , Figure (b) shows obstacle detection Figure 2 ;

[0038] Figure 8 The present invention discloses a schematic diagram of an optimal path generation method based on a ThreeJS framework for automatic path finding in a scene according to an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of the present invention.

[0040] According to an embodiment of the present invention, a method for automatic path finding in a scene based on a ThreeJS framework is provided.

[0041] like Figure 1-Figure 8 As shown, the automatic path finding method in a scene based on the ThreeJS framework according to an embodiment of the present invention includes the following steps:

[0042] like Figure 2-Figure 3 As shown, the size of the floor object in the scene on the XOZ plane of the three-dimensional coordinate system is obtained in advance, the unit length of the block grid unit is set to form a grid set, and the starting coordinates of the upper left corner of the grid set in the three-dimensional coordinate system, the coordinates of the center point of the first block grid unit, and the number of columns and rows of the grid set are calculated;

[0043] like Figure 4 As shown, the number of rows of the grid set is used as the number of outer loops, and the number of columns is used as the number of inner loops. The feasibility test is performed in the inner loop, including the following steps:

[0044] Among them, Figure 5 As shown, solid obstacle detection of floor objects is performed to detect whether block grid units exist in floor objects and exclude block grid units where solid objects are located. When the detection point is located in a solid object, the floor object cannot be detected and is marked as impassable. Non-solid walls need to be excluded using the gap detection in the next step. Specifically, the following steps are included:

[0045] Pre-calculate the center point coordinates of the current loop block grid unit;

[0046] Instantiate a Raycaster class ray provided by ThreeJS, set the coordinates of the ray's starting point to (centerPos.x, character height, centerPos.z), set the ray's direction to directly below, and use the intersectObject method of Raycaster to obtain a collection of object information in all scenes that the ray touches;

[0047] If there is a floor object in the object set, the grid cell in this block is recorded as impassable and the inner loop ends; otherwise, it is impassable and proceeds to the next step of gap detection;

[0048] Among them, Figure 6 As shown, gap detection is performed. If the center point of the current block grid unit is located in the middle of a very small gap, the solid obstacle detection of the floor object in the previous step will mark the block as passable. However, since the diameter of the character is larger than the size of the gap, the block is actually impassable, so gap detection is required to further determine whether the current block grid unit is passable. The specific steps include:

[0049] Instantiate a Raycaster class ray provided by ThreeJS. The starting coordinates of the ray are (centerPos.x, character height, centerPos.z). At this time, detection is required in four different directions, namely the east, west, south and north directions of the point. If an obstacle type object is detected in any two directions, it means that the block grid unit is located in the gap of the scene, and it is marked as impassable and the inner loop ends. Otherwise, it is passable and enters the next step of octree obstacle detection;

[0050] Among them, Figure 8 As shown, octree obstacle detection can exclude the situation where the coordinate point (centerPos.x, character height, centerPos.z) on the current block grid unit is inside a wall or a gap. However, the character has volume, and will be further detected by the octree obstacle detection algorithm provided by the ThreeJS framework. The algorithm regards the character as a capsule. The algorithm internally combines the octree data constructed by the scene with the character capsule to calculate whether the capsule has an intersection with the obstacle in the scene. If so, the map block grid unit is recorded as impassable, otherwise it is marked as passable, ending the memory loop.

[0051] According to the passability detection, obtain the two-dimensional Vector3 array type data, including: block row and column coordinate data pathPosMatrix and block row and column passability data mapGrid, where;

[0052] The block row and column coordinate data pathPosMatrix is ​​used to represent the row and column number and center point coordinates of each block grid unit in the grid set;

[0053] The block row and column passability data mapGrid is used to indicate whether the block grid unit in each row and column is passable;

[0054] Combine the two-dimensional Vector3 array type data with the PathFinding library to generate the best path between two points, and operate the character to move on the path to complete the automatic pathfinding process.

[0055] The generation of the best path includes the following steps:

[0056] Take the grid unit of the block where the character is currently located as the starting point;

[0057] Mark any place in the scene as the target end point. First, use the grid set to determine whether the coordinates of the target end point belong to the block grid unit. If not, exit the path finding process. Otherwise, obtain the row and column numbers of the block grid unit of the target end point.

[0058] After obtaining the row and column numbers of the target destination block grid unit, determine whether the target destination block grid unit is surrounded by inaccessible block grid units. If so, obtain the accessible block grid unit closest to the target destination block grid unit as the new target destination and proceed to the next step. Otherwise, proceed directly to the next step.

[0059] According to the two-dimensional Vector3 array type data combined with the findPath method of the PathFinding library, the block order set of the best path from the starting block grid unit to the target end block grid unit is obtained, and the corresponding coordinate point set is obtained according to the block order set as the best path coordinate point set.

[0060] In addition, in the embodiment, the following steps are specifically included:

[0061] Load the sample building model in the scene in advance and obtain the model data buildingData;

[0062] Determine the name attribute of the floor object of the building model, traverse the model data buildingData, and find the floor object through the name attribute;

[0063] Through the Box3 class provided by ThreeJS, the size information of the floor object on the XOZ plane of the three-dimensional coordinate system is obtained, that is, the size in the X-axis direction is 6, and the size in the Z-axis direction is 13.51. The coordinates of the upper left corner of the grid set on the XOZ plane are calculated to be (-3, -6.255), which is represented by the variable mapStatePos. At the same time, the starting Y coordinate zeroY of the landmark is obtained, and the value is 0.15.

[0064] Create the Octree class object worldOctree in the ThreeJS library, and use the worldOctree.fromGraphNode(buildingData) method to generate the scene octree data structure;

[0065] Create a Capsule class object collider representing the character, represented as a character capsule, create a character height variable characterHeight, and set the value to 1.7;

[0066] Create a unit length variable cellUnitLength value of 0.3 for the block grid unit, and calculate the grid set to have 46 rows and 20 columns based on the floor object size of 6x13.51;

[0067] Use the grid set obtained in the previous step to initialize a block row and column passability data mapGrid, which indicates whether the block grid unit in each row and column is passable, and is used by the PathFinding library to find the best path;

[0068] Create a block row and column coordinate data pathPosMatrix to store the coordinate data of each block;

[0069] Set 46 as the number of outer loops, the loop factor is row, and 20 as the number of inner loops, the loop factor is col. Create a nested loop. In each inner loop, process the block grid cell in row row and column col. The specific processing process is as follows:

[0070] Create a variable walkable with an initial value of true, which is used to record whether the block grid unit currently being processed is passable. A value of true indicates that it is passable, and a value of false indicates that it is not passable.

[0071] The center coordinates of the current block grid cell cellCenterPos are calculated to be (-3+col*0.3,0.15,-6.255+row*.0.3), expressed as:

[0072] (mapStartPos.x+col*cellUnitLength,zeroY,mapStartPos.y+row*cellUnitLength);

[0073] Save the center coordinates cellCenterPos of the current block grid cell to pathPosMatrix;

[0074] Set the emission point coordinates of the obstacleRay ray to:

[0075] (cellCenterPos.x,zeroY+characterHeight,cellCenterPos.z),

[0076] The emission direction is set to the negative direction of the Y axis of the three-dimensional coordinate system, that is, (0, -1, 0). The obstacaleRay.intersectObject method is used to obtain the set of objects that the ray touches in the scene. The set is traversed. If there is no floor object in the set, the walkable variable is assigned to false.

[0077] If the value of the walkable variable is true, gap detection is performed, including: calibrating the starting point coordinates of the detection ray to:

[0078] (cellCenterPos.x,zeroY+characterHeight,cellCenterPos.z);

[0079] The positive direction of the X axis, the negative direction of the X axis, the positive direction of the Z axis, and the negative direction of the Z axis in the three-dimensional rectangular coordinate system are used as the emission directions of the detection ray. If an obstacle object in the scene is detected in any two directions and the distance from the emission point is less than or equal to the character radius, it means that the block is a gap and the walkable variable is assigned to false;

[0080] Among them, if the value of the walkable variable is true, the octree obstacle detection is performed, including: setting the coordinates of the character capsule to the center point coordinates of the block grid unit cellCenterPos, calling the worldOctree.capsuleInterset method to perform obstacle detection, if the character capsule detects an obstacle in the block grid unit, the method will return the collision data, otherwise it will return a null value, when an obstacle is detected, the walkable variable is assigned to false;

[0081] According to the value of the walkable variable, the accessibility of the grid is set through the mapGrid.walkableAt method;

[0082] Assume that the current position of the character is the starting point of the pathfinding, and the coordinates are (-3.74, 0.15, -1.666). Through the two-dimensional array of grid coordinate data pathPosMatrix, we can get that the block row number of the starting point coordinate is 22 and the column number is 7;

[0083] The coordinates of the simulated user clicking on the map are (-1.35, 0.15, 2.24), which is the end point of this simulated pathfinding. Through the block coordinate data pathPosMatrix, we can get that the block row number of the end point is 35 and the column number is 15;

[0084] Through the PathFinding library, combined with the map accessibility data mapGrid, the row and column number array of the access path can be obtained as follows:

[0085] [{row:22,col:7},{row:23,col:8},{row:24,col:8},{row:25,col:8},{row:26,col:9},{row:27,col:10},{row:28,col:11},{r ow:29,col:11},{row:30,col:11},{row:31,col:12},{row:32,col:13},{row:33,col:14},{row:34,col:15},{row:35,col:15}],

[0086] Calculated through the block coordinate data pathPosMatrix, the path coordinate set array is:

[0087] [{x:-3.75:,y:0.15,z:-1.68},{x:-3.45,y:0.15,z:-1.38},{x:-3.45,y:0.15,z:-1.08},

[0088] {x:-3.45,y:0.15,z:-.078},{x:-3.15,y:0.15,z:-0.48},{x:-2.85,y:0.15,z:-0.18},

[0089] {x:-2.55,y:0.15,z:0.12},{x:-2.55,y:0.15,z:0.42},{x:-2.55,y:0.15,z:0.72},

[0090] {x:-2.55,y:0.15,z:1.02},{x:-1.95,y:0.15,z:1.32},{x:-1.65,y:0.15,z:1.62},

[0091] {x:-1.35,y:0.15,z:1.92},{x:-1.35,y:0.15,z:2.24}] is the optimal path data for this pathfinding test.

[0092] In summary, with the aid of the above technical solution of the present invention, the present invention is based on the ThreeJS framework in the scene automatic path finding method, pre-acquires the size of the floor object in the scene on the XOZ plane of the three-dimensional coordinate system, sets the unit length of the block grid unit to form a grid set, and calculates the starting coordinates of the upper left corner of the grid set in the three-dimensional coordinate system, the center point coordinates of the first block grid unit and the number of columns and rows of the grid set, takes the number of rows of the grid set as the number of outer loops, and the number of columns as the number of inner loops, performs a passability check in the inner loop, obtains two-dimensional Vector3 array type data according to the passability check, and converts the two-dimensional Vector3 Array type data is combined with the PathFinding library to generate the best path between two points, and operate the character to move on the path to complete the automatic pathfinding process, realize the best moving path between two points in the scene based on the ThreeJS framework, and complete the automatic pathfinding strategy in the 3D scene built by ThreeJS. It not only has strong scene adaptability, but can also accurately calculate the feasible path in complex terrain according to the geometric shape and object distribution of the scene, so that the character can move freely in a variety of terrains, ensuring the accuracy and effectiveness of pathfinding, but also can be quickly integrated into the ThreeJS project to realize the automatic pathfinding function, saving development time and effort. At the same time, the automatic pathfinding strategy based on ThreeJS has high reusability and scalability. Developers can encapsulate the pathfinding function into an independent module and reuse it in different 3D scene projects, and can expand and optimize the scene according to specific needs.

[0093] In addition, to enhance the user experience, when users browse the 3D scene built by ThreeJS, the automatic pathfinding function can make the character or perspective move automatically along a reasonable path without manual operation by the user, allowing users to focus more on the scene content, as if they were in it, enhancing the sense of immersion. At the same time, for complex 3D scenes, manual control of character pathfinding may be difficult. The automatic pathfinding function provides users with a convenient navigation method. They only need to specify the starting point and the end point to automatically find a feasible path, which reduces the difficulty of user operation and improves the interaction efficiency.

[0094] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. After considering the disclosure of the specification and the examples, those skilled in the art will easily think of other embodiments of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and the examples are only regarded as exemplary, and the true scope and spirit of the present disclosure are indicated by the claims.

[0095] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for automatic pathfinding in a scene based on the ThreeJS framework, characterized in that: The following steps are involved: The size of the floor object in the scene on the XOZ plane of the three-dimensional coordinate system is obtained in advance, the unit length of the block grid unit is set to form a grid set, and the starting coordinates of the upper left corner of the grid set in the three-dimensional coordinate system, the coordinates of the center point of the first block grid unit, and the number of columns and rows of the grid set are calculated; The number of rows of the grid set is used as the number of outer loops, and the number of columns is used as the number of inner loops. In the inner loop, a passability check is performed, which includes: performing solid obstacle detection of the floor object to detect whether the block grid unit exists in the floor object and excluding the block grid unit where the solid object is located, performing gap detection to detect whether the center point of the current block grid unit is located in the middle of the gap to determine whether the current block grid unit is passable, and performing octree obstacle detection to detect whether the coordinate point on the current block grid unit is in the wall or the gap to determine whether the current block grid unit is passable; According to the passability detection, obtain two-dimensional Vector3 array type data, including: block row and column coordinate data pathPosMatrix and block row and column passability data mapGrid, where: block row and column coordinate data pathPosMatrix is ​​used to indicate the row and column number and center point coordinates of each block grid unit in the grid set; block row and column passability data mapGrid is used to indicate whether the block grid unit of each row and column is in a passable state; Combine the two-dimensional Vector3 array type data with the PathFinding library to generate the best path between two points, and operate the character to move on the path to complete the automatic pathfinding process.

2. The automatic path finding method in a scene based on the ThreeJS framework according to claim 1, characterized in that: The solid obstacle detection of the floor object comprises the following steps: Pre-calculate the center point coordinates of the current loop block grid unit; Instantiate a Raycaster class ray provided by ThreeJS, set the coordinates of the ray's starting point to (centerPos.x, character height, centerPos.z), set the ray's direction to directly below, and use the intersectObject method of Raycaster to obtain a collection of object information in all scenes that the ray contacts; If there is a floor object in the object set, the grid unit of the block is recorded as impassable and the inner loop ends; otherwise, it is impassable and proceeds to the next step of gap detection.

3. The automatic path finding method in a scene based on the ThreeJS framework according to claim 2, characterized in that: The gap detection comprises the following steps: Instantiate a Raycaster class ray provided by ThreeJS, the starting coordinates of the ray are (centerPos.x, character height, centerPos.z), and perform multi-directional detection; If an obstacle-type object is detected in any two directions, it means that the block grid unit is located in the gap of the scene, and it is marked as impassable and the inner loop ends. Otherwise, it is impassable and enters the next step of octree obstacle detection.

4. The automatic path finding method in a scene based on the ThreeJS framework according to claim 3, characterized in that: The octree obstacle detection comprises the following steps: The character is marked as a capsule, and the octree data constructed by the scene is combined with the character capsule to calculate whether the capsule has an intersection with the obstacles in the scene; Among them, if there is an intersection, the map block grid unit is recorded as impassable, otherwise it is marked as passable and the memory loop ends.

5. The automatic path finding method in a scene based on the ThreeJS framework according to claim 1 or 4, characterized in that: Generating the optimal path includes the following steps: Take the grid unit of the block where the character is currently located as the starting point; Mark any place in the scene as the target end point. First, use the grid set to determine whether the coordinates of the target end point belong to the block grid unit. If not, exit the path finding process. Otherwise, obtain the row and column numbers of the block grid unit of the target end point. After obtaining the row and column numbers of the target destination block grid unit, determine whether the target destination block grid unit is surrounded by inaccessible block grid units. If so, obtain the accessible block grid unit closest to the target destination block grid unit as the new target destination and proceed to the next step. Otherwise, proceed directly to the next step. According to the two-dimensional Vector3 array type data combined with the findPath method of the PathFinding library, the block order set of the best path from the starting block grid unit to the target end block grid unit is obtained, and the corresponding coordinate point set is obtained according to the block order set as the best path coordinate point set.