CN111950053B - Building model roaming function optimization method and related device based on Threejs - Google Patents

Building model roaming function optimization method and related device based on Threejs Download PDF

Info

Publication number
CN111950053B
CN111950053B CN202010750130.2A CN202010750130A CN111950053B CN 111950053 B CN111950053 B CN 111950053B CN 202010750130 A CN202010750130 A CN 202010750130A CN 111950053 B CN111950053 B CN 111950053B
Authority
CN
China
Prior art keywords
camera
engine
pitch angle
angle value
threejs
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010750130.2A
Other languages
Chinese (zh)
Other versions
CN111950053A (en
Inventor
马骁
许君君
郝方位
陶海波
叶宇飞
廖灿灿
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCTEG Chongqing Engineering Group Co Ltd
Original Assignee
CCTEG Chongqing Engineering Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CCTEG Chongqing Engineering Group Co Ltd filed Critical CCTEG Chongqing Engineering Group Co Ltd
Priority to CN202010750130.2A priority Critical patent/CN111950053B/en
Publication of CN111950053A publication Critical patent/CN111950053A/en
Application granted granted Critical
Publication of CN111950053B publication Critical patent/CN111950053B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/10Geometric CAD
    • G06F30/13Architectural design, e.g. computer-aided architectural design [CAAD] related to design of buildings, bridges, landscapes, production plants or roads
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T19/00Manipulating 3D models or images for computer graphics
    • G06T19/006Mixed reality
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/69Control of means for changing angle of the field of view, e.g. optical zoom objectives or electronic zooming
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/698Control of cameras or camera modules for achieving an enlarged field of view, e.g. panoramic image capture

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Geometry (AREA)
  • Computer Hardware Design (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • General Engineering & Computer Science (AREA)
  • Architecture (AREA)
  • Software Systems (AREA)
  • Civil Engineering (AREA)
  • Computer Graphics (AREA)
  • Structural Engineering (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Processing Or Creating Images (AREA)

Abstract

The application provides an optimization method and a related device for a building model roaming function based on Threejs, which can enable a visual angle of a camera to freely rotate 360 degrees in the vertical direction and improve user operation experience. The method comprises the following steps: the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller; when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera; when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.

Description

Building model roaming function optimization method and related device based on Threejs
Technical Field
The embodiment of the application relates to the technical field of three-dimensional graphics, in particular to an optimization method and a related device for a building model roaming function based on Threejs.
Background
In the building and related fields, the three-dimensional building model can intuitively display the design content, and along with the continuous progress of the technology, people are increasingly widely applied to the building model, and the building model not only plays a role in the design stage, but also covers the whole life cycle of the whole building engineering. After the wide application of building models, the industry has set higher requirements on them: lighter, faster, more convenient, i.e., lighter construction models are being sought.
The key technology for realizing the lightweight rendering of the building model in China is Threejs, the roaming function of the model is realized by a camera and a controller provided by the Threejs official, the camera and the controller are combined to determine the position, the direction and the angle of the model observation, and the content seen by the camera is rendered in a scene by a renderer, namely the content finally presented on a screen.
In the prior art, when a camera and a controller provided by a threjs authority are used for realizing a roaming function, due to the limitation of an algorithm, the visual angle of the camera in the vertical direction can only reach 180 degrees of rotation and cannot rotate 360 degrees, so that the operation experience of a user is influenced.
Disclosure of Invention
The application provides an optimization method and a related device for a building model roaming function based on Threejs, which can enable a visual angle of a camera to freely rotate 360 degrees in the vertical direction and improve user operation experience.
The first aspect of the present application provides a method for optimizing roaming function of building model based on threjs, which comprises:
the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.
Optionally, the Threejs further comprises: a rendering module;
the method further comprises the steps of:
the camera has a first matrix stored therein, the camera controller has a second matrix stored therein, the engine updates the second matrix according to a moving path of the camera when the camera controller moves the camera, the first matrix represents the position information before the camera moves, and the second matrix represents the position information after the camera moves;
the engine judges whether the first matrix is identical to the second matrix;
and the engine controls whether the rendering module executes the rendering operation or not according to the judging result.
Optionally, the engine controlling whether the rendering module performs the rendering operation according to the result of the determination includes:
when the judging result is the same, the engine controls the rendering module not to execute rendering operation in the camera controller frame circulation callback function;
and when the judging result is different, the engine updates the first matrix according to the second matrix and controls the rendering module to execute rendering operation according to the updated first matrix.
Optionally, the method further comprises:
and the engine calls a movement function and binds the camera controller with a preset keyboard key instruction through the movement function so that the movement of the camera can be controlled by the keyboard.
Optionally, the method further comprises:
and the engine calls a visual angle switching function and binds the camera controller with a mouse instruction through the visual angle switching function so that the visual angle of the camera can be changed along with the movement of the mouse.
Optionally, the method further comprises:
and the engine calls a gravity function, the gravity function is used for controlling the opening and closing of the gravity effect of the camera, and when the gravity effect is opened, the visual angle of the camera falls down according to a preset speed.
Optionally, the method further comprises:
and the engine calls a collision function, the collision function is used for controlling the opening and closing of the collision effect of the camera, when the collision effect is opened, the camera detects whether a barrier exists at the current view angle, and when the barrier exists, the camera stops moving in the direction opposite to the barrier.
A second aspect of the present application provides an engine comprising:
the first calling unit is used for calling Threejs, and the Threejs comprises a camera and a camera controller;
a determining unit configured to determine that the camera controller moves the camera;
a first judging unit configured to judge whether a pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001 when the determining unit determines that the camera controller moves the camera;
a first assignment unit configured to assign the pitch angle value to 89.9 when the first determination unit determines that the pitch angle value is greater than or equal to 89.9999 and less than 90.0001;
a second judging unit configured to judge whether a pitch angle value of the camera is greater than or equal to-90.0001 and less than-89.9999 when the determining unit determines that the camera controller moves the camera;
and the second assignment unit is used for assigning the pitch angle value to be-89.9 when the second judgment unit judges that the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999.
Optionally, the engine further comprises:
a first storage unit for storing a first matrix in the camera;
a second storage unit for storing a second matrix in the camera controller;
an updating unit configured to update the second matrix according to a movement path of the camera when the determining unit determines that the camera controller moves the camera;
a third judging unit configured to judge whether the first matrix is the same as the second matrix;
and the control unit is used for controlling whether the rendering module executes the rendering operation according to the judgment result of the third judgment unit, controlling the rendering module not to execute the rendering operation in the camera controller frame circulation callback function when the judgment result of the third judgment unit is the same, updating the first matrix according to the second matrix when the judgment result of the third judgment unit is different, and controlling the rendering module to execute the rendering operation according to the updated first matrix.
Optionally, the engine further comprises:
and the second calling unit is used for calling a moving function and binding the camera controller with a preset keyboard key instruction through the moving function so that the movement of the camera can be controlled by a keyboard.
Optionally, the engine further comprises:
and the third calling unit is used for calling a visual angle switching function and binding the camera controller with a mouse instruction through the visual angle switching function so that the visual angle of the camera can be changed along with the movement of a mouse.
Optionally, the engine further comprises:
and the fourth calling unit is used for calling a gravity function, the gravity function is used for controlling the opening and closing of the gravity effect of the camera, and when the gravity effect is opened, the visual angle of the camera falls down according to the preset speed.
Optionally, the engine further comprises:
and the fifth calling unit is used for calling a collision function, the collision function is used for controlling the opening and closing of the collision effect of the camera, when the collision effect is opened, the camera detects whether a barrier exists at the current view angle, and when the barrier exists, the camera stops moving in the direction opposite to the barrier.
A third aspect of the present application provides an engine comprising:
the device comprises a processor, a memory, an input/output unit and a bus;
the processor is connected with the memory, the input/output unit and the bus;
the processor specifically performs the following operations:
the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.
A fourth aspect of the present application provides a computer readable storage medium having a program stored thereon, which when executed on a computer performs the method according to any of the first aspects.
From the above technical solutions, the embodiments of the present application have the following advantages:
when the user controls the camera visual angle to switch, the Threejs carries out corresponding operation according to the Euler angle and sphere formula as the basic algorithm, but when the pitch angle is 90 degrees or-90 degrees, the situation that the dividend is 0 in the algorithm is involved, so that the calculation cannot be carried out. According to the method, whether the pitch angle value falls in the target range is judged through the algorithm (the pitch angle value > = 89.9999, the pitch angle value is less than 90.0001 or the pitch angle value > = -90.0001, and the pitch angle value is less than-89.9999), when the pitch angle value falls in the target range, the pitch angle is assigned again, so that the algorithm can normally run, the camera view angle can rotate 360 degrees in the vertical direction, and the operation experience of a user is improved.
Drawings
FIG. 1 is a flow chart of an embodiment of a method for optimizing roaming functions of a building model based on Threejs;
FIG. 2 is a flow chart of another embodiment of a method for optimizing roaming functions of a building model based on Threejs in the present application;
FIG. 3 is a schematic diagram of an embodiment of an engine of the present application;
FIG. 4 is a schematic view of another embodiment of an engine according to the present application;
FIG. 5 is a schematic diagram of another embodiment of an engine according to the present application.
Detailed Description
The application provides an optimization method and a related device for a building model roaming function based on Threejs, which can enable a visual angle of a camera to rotate 360 degrees in the vertical direction and improve user operation experience.
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
Threejs is a WebGL framework which is packaged on the basis of an api interface of a Web graphic library (WebGL, web Graphics Library), encapsulates common objects in 3D graphic programming in a simple and visual form, and is a completely open-source framework. The method and the device have the advantages that secondary development is carried out on the basis of the camera and the controller provided by the Threejs official, JS files which are more suitable for model roaming operation are generated, and related functions of model roaming in Threejs are optimized. The roaming function in threjs refers to moving the camera from the first person's viewing angle, and browsing the model from various angles, so as to achieve the effect of being in the scene.
Referring to fig. 1, an embodiment of a method for optimizing roaming functions of a building model based on threjs in the present application includes:
101. the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
in rendering models using threjs, the cameras and camera controllers in threjs need to be defined. The camera controller is used for controlling the translation of the camera and the switching of the view angles of the camera, and the content finally seen by the camera is the content presented on the page.
When invoking a camera in threjs, related parameters of the camera are initialized first, where the related parameters of the camera include: the yaw angle, pitch angle, roll angle, initial position coordinates of the camera and the like are needed to be described, wherein the yaw angle, pitch angle and roll angle refer to the yaw angle, pitch angle and roll angle respectively. The pitch angle is the angle at which the model "pitches" in the right hand coordinate system relative to the XOY plane, and is positive when the x-axis of the model is above the XOY plane, and negative otherwise.
102. When the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, step 103 is executed, and the pitch angle value changes along with the movement of the camera;
103. assigning the pitch angle value to be 89.9;
when the camera controller is called to move the camera, the engine captures the position coordinates of the camera, the rolling point and the moving speed of the camera, calculates the positions of all points of the model according to Euler angles and a sphere formula, and updates the position information of the camera. When the camera switches the view angle in the vertical direction, the pitch angle changes, but when the camera rotates to 90 degrees or 90 degrees below zero, namely the pitch angle is 90 degrees or 90 degrees below zero, the situation that the divisor is 0 in the algorithm is involved, calculation cannot be performed, namely the camera can only switch the view angle of 180 degrees in the vertical direction.
It is therefore necessary to add the determination step 102 to determine whether the pitch angle value is greater than or equal to 89.9999 and less than 90.0001, and when the pitch angle value is greater than or equal to 89.9999 and less than 90.0001, an incapacitation may occur, and when the pitch angle is assigned to 89.9, the algorithm may continue to calculate normally, so that the operation of controlling the rotation of the viewing angle may run normally, and the rotation continues when the camera pitch angle is positive, breaking through the limit of 90 °.
104. When the engine determines that the camera controller moves the camera, the engine determines whether the pitch angle value is greater than or equal to-90.0001 and less than-89.9999, and if so, performs step 105;
105. assigning the pitch angle value to be-89.9.
It should be noted that, there is no timing relationship between the step 102 and the step 104, and the engine may execute 102 first and then execute 104, or may execute 104 first and then execute 102, which is not limited herein. When the engine judges that the pitch angle value of the camera is in the range interval of 89.9999 and-89.9999, the algorithm can normally run, and corresponding calculation can be directly carried out without executing assignment operation.
The engine determines the movement of the camera by determining if the pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001, or greater than or equal to-90.0001 and less than-89.9999, and reassigning the pitch angle when the pitch angle value falls within the target range: the pitch angle value is assigned to 89.9 when the camera moves to the positive target range or the pitch angle value is assigned to-89.9 when the camera moves to the negative target range, so that the divisor in the algorithm is not equal to 0, and the problem that the algorithm cannot calculate when the camera moves to the pitch angle of 90 degrees or 90 degrees below zero, and the camera cannot continue rotating is solved. Therefore, the camera view angle can freely rotate 360 degrees in the vertical direction, and the operation experience of a user is improved.
Referring to fig. 2, another embodiment of the method for optimizing roaming function of building model based on threjs in the present application includes:
201. the engine calls a Threejs, wherein the Threejs comprises a camera, a camera controller and a rendering module;
when the Threejs is used for rendering the model, the engine also needs to call the rendering module to execute rendering operation besides calling the camera and the camera controller to determine the position, the direction and the angle observed by the model, so that the model can be finally displayed on the page.
202. When the engine determines that the camera controller moves the camera, assigning the pitch angle value to be 89.9 when the engine determines that the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, wherein the pitch angle value changes along with the movement of the camera;
203. assigning the pitch angle value to be-89.9 when the engine determines that the pitch angle value is greater than or equal to-90.0001 and less than-89.999 when the engine determines that the camera controller moves the camera;
steps 202 to 203 in this embodiment are similar to steps 102 to 105 in the previous embodiment, and will not be repeated here.
204. The camera has a first matrix stored therein, the camera controller has a second matrix stored therein, the engine updates the second matrix according to a moving path of the camera when the camera controller moves the camera, the first matrix represents the position information before the camera moves, and the second matrix represents the position information after the camera moves;
in Threejs, a three-dimensional projection algorithm is adopted to calculate the position of a three-dimensional object on a camera view plane, the position and direction of the camera, the type of the camera, the position and deformation of the object are converted into matrixes, the matrixes represent the information such as the position of the camera and the like, and a rendering module calculates and renders according to the information.
The engine stores two matrixes in the camera and the camera controller respectively, and when the camera controller moves the camera, the engine only updates the matrixes in the camera controller according to the moving path of the camera and the final position of the camera, and does not update the matrixes stored in the camera, so that whether the camera moves can be determined by judging whether the matrixes stored in the camera and the camera controller are identical.
205. The engine judges whether the first matrix is identical to the second matrix;
in the prior art, no matter whether the camera moves or not, corresponding calculation needs to be performed every time the rendering operation is performed, and when the camera does not move, the rendering operation is performed, so that the same scene and model are repeatedly rendered, and the rendering performance is delayed and reduced. In the method, whether the camera is moved is judged by judging whether the matrix stored in the camera is the same as the matrix stored in the camera controller.
206. The engine controls whether the rendering module executes rendering operation or not according to the judging result;
when the engine determines that the camera moves, namely that the first matrix is different from the second matrix, the engine updates the first matrix according to the second matrix and calculates according to the updated first matrix, and performs rendering operation, otherwise, the engine does not perform rendering operation in the camera controller frame loop callback function. Therefore, the engine can calculate and update the data required by the camera only when the camera controller operates, and the performance waste caused by continuous calculation is reduced.
207. The engine calls a moving function and binds the camera controller with a preset keyboard key instruction through the moving function so that the movement of the camera can be controlled by a keyboard;
it should be noted that, step 207 is an optional step, and the camera controller and the preset keyboard instruction are combined through this step, so that the user can control the movement of the camera through the keyboard, and in this embodiment, the specific preset keyboard instruction is not limited, and the preset keyboard instruction can correspond to any key on the keyboard.
Optionally, the function of the threjs for controlling the camera to translate in the front, back, left and right directions is bound with the W, A, S, D keys of the keyboard, so that a user can realize the movement of the camera in the corresponding direction only by operating the four keys on the keyboard.
208. The engine calls a visual angle switching function and binds the camera controller with a mouse instruction through the visual angle switching function so that the visual angle of the camera can be changed along with the movement of a mouse;
it should be noted that, step 208 is an optional step, and the camera controller and the mouse command are combined through this step, so that the user can control the switching of the camera view angle through the mouse. Specifically, a function in the threjs for controlling the view angle direction of the camera is bound with the mouse, so that the effect that the view angle is changed along with the movement of the mouse is achieved.
Specifically, step 207 and step 208 are combined, so that the user can switch the view angles of the characters and forward the translation in the directions of the view angles like a CS shooting game, the roaming function is simpler and more convenient to operate, and meanwhile, the offset, the displacement and the state of the camera are monitored according to seconds, so that the smoothness of model roaming is improved, and meanwhile, the occupation of resources is reduced.
209. The method comprises the steps that an engine calls a gravity function, the gravity function is used for controlling the opening and closing of the gravity effect of the camera, and when the gravity effect is opened, the visual angle of the camera falls down according to a preset speed;
it should be noted that, step 209 is an optional step, and this step controls the on and off of the gravity effect of the camera by setting a switch of the gravity effect. Specifically, every time the camera is started, the gravity switch attribute is set to false by default, i.e., the gravity effect is turned off. When the switch attribute is changed to true, the gravity effect of the camera is started, namely the view angle of the camera gradually falls down according to the default speed, so that the sense of gravity is achieved, and the use scene in the roaming function is enriched.
Optionally, when the gravity effect of the camera is started, it is firstly determined whether the vertical area of the camera has a component, and when the component is not present, the gravity effect of the camera is executed. In an actual application scene, if a component is blocked, the camera still falls, so that the conditions of mold penetration, perspective and the like can occur, and the gravity effect is not realistic.
210. And the engine calls a collision function, the collision function is used for controlling the opening and closing of the collision effect of the camera, when the collision effect is opened, the camera detects whether a barrier exists at the current view angle, and when the barrier exists, the camera stops moving in the direction opposite to the barrier.
It should be noted that, step 210 is an optional step, and this step controls the on and off of the collision effect of the camera by setting a switch of the collision effect. Specifically, the collision switch attribute is set to false by default every time the camera is started, and when the switch attribute is changed to true, the collision effect of the camera is started.
When the camera starts the collision effect, whether a blocking object, such as a wall body, a column, a beam and other components of the model, appears in the moving path of the camera is detected, and when the blocking object appears, the visual angle cannot pass through, so that the effect of colliding with the object is given to a user, and the roaming function of the model is more real.
It should be noted that, in this embodiment, the functions mentioned in all steps may be encapsulated in the same JS file using JS language, and when the user uses threjs to perform roaming of the model, the JS file may be called from outside, so that the roaming function of the model is more intuitive, simpler and easier to get on hand, and user experience is improved.
The above describes the method for optimizing the roaming function of the building model based on Threejs in the present application, and the following describes the engine in the present application:
referring to fig. 3, one embodiment of the engine of the present application includes:
a first calling unit 301, configured to call Threejs, where Threejs includes a camera and a camera controller;
a determining unit 302 for determining that the camera controller moves the camera;
a first judging unit 303 for judging whether a pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001 when the determining unit determines that the camera controller moves the camera;
a first assignment unit 304, configured to assign the pitch angle value to 89.9 when the first determination unit determines that the pitch angle value is greater than or equal to 89.9999 and less than 90.0001;
a second judging unit 305 for judging whether a pitch angle value of the camera is greater than or equal to-90.0001 and less than-89.9999 when the determining unit determines that the camera controller moves the camera;
and a second assignment unit 306, configured to assign the pitch angle value to be-89.9 when the second determination unit determines that the pitch angle value is greater than or equal to-90.0001 and less than-89.9999.
In this embodiment, after the invoking unit 301 invokes threjs, the determining unit 302 determines, when determining that the camera moves, whether the pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001, the second determining unit 305 determines whether the pitch angle value is greater than or equal to-90.0001 and less than-89.9999, and when the pitch angle value is greater than or equal to 89.9999 and less than 90.0001, the first assigning unit 304 assigns the pitch angle value to 89.9, and when greater than or equal to-90.0001 and less than-89.9999, the second assigning unit 306 assigns the pitch angle value to-89.9, so that the dividend in the algorithm does not appear to be equal to 0, and the problem that the camera cannot be calculated when moving to the pitch angle of 90 ° or-90 ° and cannot continue moving is solved. Therefore, the camera view angle can rotate 360 degrees in the vertical direction, and the operation experience of a user is improved.
Referring to fig. 4, another embodiment of the engine of the present application includes:
a calling unit 401, configured to call Threejs, where Threejs includes a camera and a camera controller;
a determining unit 402 configured to determine that the camera controller moves the camera;
a first judging unit 403 for judging whether a pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001 when the determining unit determines that the camera controller moves the camera;
a first assignment unit 404, configured to assign the pitch angle value to 89.9 when the first determination unit determines that the pitch angle value is greater than or equal to 89.9999 and less than 90.0001;
a second judging unit 405 for judging whether a pitch angle value of the camera is greater than or equal to-90.0001 and less than-89.9999 when the determining unit determines that the camera controller moves the camera;
and a second assignment unit 406, configured to assign the pitch angle value to be-89.9 when the second determination unit determines that the pitch angle value is greater than or equal to-90.0001 and less than-89.9999.
In this embodiment, the engine may further include:
a first storage unit 407 for storing a first matrix in the camera;
a second storage unit 408 for storing a second matrix in the camera controller;
an updating unit 409 for updating the second matrix according to a movement path of the camera when the determining unit 402 determines that the camera controller moves the camera;
a third judging unit 410, configured to judge whether the first matrix is the same as the second matrix;
and a control unit 411, configured to control whether the rendering module performs a rendering operation according to a result determined by the third determining unit 410, and when the result determined by the third determining unit 410 is the same, control the rendering module not to perform the rendering operation in the camera controller frame loop callback function, and when the result determined by the third determining unit 410 is different, update the first matrix according to the second matrix, and control the rendering module to perform the rendering operation according to the updated first matrix.
Optionally, the engine further comprises:
and the second calling unit 412 is configured to call a movement function, and bind the camera controller with a preset keyboard key instruction through the movement function, so that movement of the camera can be controlled by the keyboard.
Optionally, the engine further comprises:
and a third calling unit 413, where the third calling unit 413 is configured to call a view angle switching function, and bind the camera controller with a mouse instruction through the view angle switching function, so that the view angle of the camera can be transformed along with movement of the mouse.
Optionally, the engine further comprises:
and a fourth calling unit 414, where the fourth calling unit 414 is configured to call a gravity function, where the gravity function is used to control opening and closing of a gravity effect of the camera, and when the gravity effect is opened, a viewing angle of the camera falls according to a preset speed.
Optionally, the engine further comprises:
and a fifth calling unit 415 for calling a collision function for controlling on and off of a collision effect of the camera, when the collision effect is on, the camera detecting whether a barrier exists at a current viewing angle, and when the barrier exists, stopping movement of the camera in a direction opposite to the barrier.
In this embodiment, the functions of each unit and module correspond to the steps in the embodiment shown in fig. 2, and are not described herein.
Referring to fig. 5, another embodiment of the engine in the present application includes:
a processor 501, a memory 502, an input/output unit 503, and a bus 504;
the processor 501 is connected to the memory 502, the input/output unit 503, and the bus 504;
the processor 501 specifically performs the following operations:
the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.
In this embodiment, the functions of the processor 501 correspond to the steps in the embodiments shown in fig. 1 to 2, and are not described herein.
In the embodiments provided in the present application, it may be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the system, apparatus and unit described above may refer to the corresponding process in the foregoing method embodiment, which is not repeated herein.
In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a random access memory (RAM, random access memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.

Claims (10)

1. The method for optimizing the roaming function of the building model based on the threjs is characterized by comprising the following steps of:
the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.
2. The method according to claim 1, wherein said Threejs further comprises: a rendering module;
the method further comprises the steps of:
the camera has a first matrix stored therein, the camera controller has a second matrix stored therein, the engine updates the second matrix according to a moving path of the camera when the camera controller moves the camera, the first matrix represents the position information before the camera moves, and the second matrix represents the position information after the camera moves;
the engine judges whether the first matrix is identical to the second matrix;
and the engine controls whether the rendering module executes the rendering operation or not according to the judging result.
3. The method of claim 2, wherein the engine controlling whether the rendering module performs a rendering operation according to the result of the determination comprises:
when the judging result is the same, the engine controls the rendering module not to execute rendering operation;
and when the judging result is different, the engine updates the first matrix according to the second matrix and controls the rendering module to execute rendering operation according to the updated first matrix.
4. A method according to any one of claims 1 to 3, further comprising:
and the engine calls a movement function and binds the camera controller with a preset keyboard key instruction through the movement function so that the movement of the camera can be controlled by the keyboard.
5. A method according to any one of claims 1 to 3, further comprising:
and the engine calls a visual angle switching function and binds the camera controller with a mouse instruction through the visual angle switching function so that the visual angle of the camera can be changed along with the movement of the mouse.
6. A method according to any one of claims 1 to 3, further comprising:
and the engine calls a gravity function, the gravity function is used for controlling the opening and closing of the gravity effect of the camera, and when the gravity effect is opened, the visual angle of the camera falls down according to a preset speed.
7. A method according to any one of claims 1 to 3, further comprising:
and the engine calls a collision function, the collision function is used for controlling the opening and closing of the collision effect of the camera, when the collision effect is opened, the camera detects whether a barrier exists at the current view angle, and when the barrier exists, the camera stops moving in the direction opposite to the barrier.
8. An optimizing device for building model roaming function based on threjs, which is characterized by comprising:
the calling unit is used for calling Threejs, and the Threejs comprises a camera and a camera controller;
a determining unit configured to determine that the camera controller moves the camera;
a first judging unit configured to judge whether a pitch angle value of the camera is greater than or equal to 89.9999 and less than 90.0001 when the determining unit determines that the camera controller moves the camera;
a first assignment unit configured to assign the pitch angle value to 89.9 when the first determination unit determines that the pitch angle value is greater than or equal to 89.9999 and less than 90.0001;
a second judging unit configured to judge whether a pitch angle value of the camera is greater than or equal to-90.0001 and less than-89.9999 when the determining unit determines that the camera controller moves the camera;
and the second assignment unit is used for assigning the pitch angle value to be-89.9 when the second judgment unit judges that the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999.
9. An engine system, comprising:
the device comprises a processor, a memory, an input/output unit and a bus;
the processor is connected with the memory, the input/output unit and the bus;
the processor specifically performs the following operations:
the engine calls a Threejs, wherein the Threejs comprises a camera and a camera controller;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value of the camera is larger than or equal to 89.9999 and smaller than 90.0001, if so, the pitch angle value is assigned to be 89.9, and the pitch angle value changes along with the movement of the camera;
when the engine determines that the camera controller moves the camera, the engine judges whether the pitch angle value is larger than or equal to-90.0001 and smaller than-89.9999, and if yes, the pitch angle value is assigned to be-89.9.
10. A computer readable storage medium having a program stored thereon, which when executed on a computer performs the method of any of claims 1 to 7.
CN202010750130.2A 2020-07-30 2020-07-30 Building model roaming function optimization method and related device based on Threejs Active CN111950053B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010750130.2A CN111950053B (en) 2020-07-30 2020-07-30 Building model roaming function optimization method and related device based on Threejs

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010750130.2A CN111950053B (en) 2020-07-30 2020-07-30 Building model roaming function optimization method and related device based on Threejs

Publications (2)

Publication Number Publication Date
CN111950053A CN111950053A (en) 2020-11-17
CN111950053B true CN111950053B (en) 2023-05-26

Family

ID=73338186

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010750130.2A Active CN111950053B (en) 2020-07-30 2020-07-30 Building model roaming function optimization method and related device based on Threejs

Country Status (1)

Country Link
CN (1) CN111950053B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018210847A1 (en) * 2017-05-16 2018-11-22 Twnkls B.V. Method of determining absolute horizontal orientation of a moving and operating camera device
CN110427724A (en) * 2019-08-12 2019-11-08 深圳市艾伯信息科技有限公司 Based on WebGL three-dimensional fire architecture model visualization method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3350649B1 (en) * 2015-09-17 2024-05-08 Fathom Optics Inc. Multi-view displays and associated systems and methods

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018210847A1 (en) * 2017-05-16 2018-11-22 Twnkls B.V. Method of determining absolute horizontal orientation of a moving and operating camera device
CN110427724A (en) * 2019-08-12 2019-11-08 深圳市艾伯信息科技有限公司 Based on WebGL three-dimensional fire architecture model visualization method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Wang shunli等.A 3D reconstruction and visualization APP using monocular vision service.《2018 26th international conference on Geoinfomatics》.2018,1-5. *
刘冬冬.制造系统设备设施三维可视化研究与应用.《中国优秀硕士学位论文全文数据库 (经济与管理科学辑)》.2018,(第undefined期),J150-191. *

Also Published As

Publication number Publication date
CN111950053A (en) 2020-11-17

Similar Documents

Publication Publication Date Title
US11883743B2 (en) Information processing method and apparatus, storage medium, and electronic device
KR102625233B1 (en) Method for controlling virtual objects, and related devices
CN107219916B (en) Multi-platform based experience generation
EP4070865A1 (en) Method and apparatus for displaying virtual scene, and device and storage medium
JP7238143B2 (en) MOVEMENT CONTROL METHOD AND APPARATUS THEREOF, TERMINAL AND COMPUTER PROGRAM FOR VIRTUAL OBJECT
EP3970819B1 (en) Interface display method and apparatus, and terminal and storage medium
KR20170137913A (en) Information processing method, terminal and computer storage medium
US20150067603A1 (en) Display control device
JP6972135B2 (en) Devices and methods for generating dynamic virtual content in mixed reality
JP6800464B2 (en) Programs and information processing equipment
CN112156467A (en) Control method and system of virtual camera, storage medium and terminal equipment
WO2021218460A1 (en) Virtual object control method and device, terminal, and storage medium
KR20220130257A (en) Adaptive display method and apparatus for virtual scene, electronic device, storage medium and computer program product
CN109758760B (en) Shooting control method and device in football game, computer equipment and storage medium
US11024257B2 (en) Android platform based display device and image display method thereof
CN111950053B (en) Building model roaming function optimization method and related device based on Threejs
CN113680065A (en) Map processing method and device in game
CN111766989B (en) Interface switching method and device
CN112190930A (en) Control method and device for game role
CN114053693B (en) Object control method and device in virtual scene and terminal equipment
CN111311760B (en) Three-dimensional building display method, system, device and storage medium
CN114385061A (en) Operation method, device, electronic equipment and computer readable storage medium
CN110930488B (en) Fish behavior simulation method, device, equipment and storage medium
CN113827974A (en) AI role control method and device in game
JPH1166351A (en) Method and device for controlling object operation inside three-dimensional virtual space and recording medium recording object operation control program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant