A method for realizing multi-view display of Web 3D maps based on camera switching
By adopting the camera switching method in WebGIS technology, the camera is only switched during off-screen drawing, which solves the problem of browser memory and efficiency when displaying multi-view maps, and achieves efficient multi-view synchronous display.
Patent Information
- Application Number
- CN202111281743.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-01
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-11-01
AI Technical Summary
In the field of WebGIS technology, existing methods need to create multiple map instance objects when implementing multi-view map display, resulting in a significant increase in browser memory and GPU resource consumption, which reduces map operation efficiency.
Using a method based on camera switching, the 3D context object used in split-view rendering is consistent with the main view. The camera is only switched during off-screen drawing to avoid repeated calculations. Only the canvas, camera and frame buffer related to the split-view are created. Achieve multi-view synchronous display.
It greatly reduces browser memory consumption, improves map operation efficiency, avoids repeated calculations, and achieves efficient multi-view display.
Smart Images

Figure CN114003840B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of WebGIS, and in particular relates to a method for realizing multi-view display of Web three-dimensional maps based on camera switching. Background Art
[0002] Currently in the field of WebGIS technology, it is often necessary to implement a multi-view display function for maps, so as to achieve the effect of synchronous display of the same scene in different viewing angles. The usual implementation method is to create multiple map instance objects and graphic objects. This method not only greatly increases the browser memory when the map is running, but also increases GPU resource consumption, greatly reducing the efficiency of the browser when the map is running. Summary of the invention
[0003] Purpose of the invention: The purpose of the present invention is to provide a method for implementing three-dimensional multi-view on the Web based on camera switching, and to provide an efficient multi-view display and synchronization method, specifically: the 3D context object used for rendering the sub-view is consistent with the main view, and the rendered scene content is consistent with the main view, and only the sub-view camera is switched to the current camera to change the observation position, and then the scene content is re-drawn off-screen. This method reduces the browser memory for map operation and improves the browser efficiency for map operation. (In addition to creating the canvas related to the sub-view, this method only needs to create the corresponding camera and frame buffer, thereby greatly reducing the browser memory when the map is running; when this method performs off-screen drawing, it only needs to switch the camera of the sub-view, and the scene content does not change, avoiding repeated calculations, thereby greatly improving the browser efficiency when the map is running).
[0004] The present invention comprises the following steps:
[0005] Step 1, create the webpage div elements, canvas and objects required for the main view and each sub-view;
[0006] Step 2: After entering the frame loop, modify the drawing function and add off-screen drawing of the sub-view in the frame loop:
[0007] Step 3, read the drawing content from the frame buffer object and save it as a picture, obtain the 2D drawing context of the sub-view canvas, draw the saved picture into the 2D drawing context, and realize the sub-view display;
[0008] Step 4, perform steps 2 and 3 on each sub-view until all time-sharing views are displayed.
[0009] Step 1 includes:
[0010] Step 1-1, create the webpage div elements and canvases required for the main view and each sub-view, mount the canvases on the div elements, and set the height, width, and offset of the main view and sub-view div elements;
[0011] Step 1-2, create instance objects required for the main view and sub-view, the instance objects include: camera, screen control event, frame buffer, pixel storage and mouse control camera object.
[0012] Step 2 includes:
[0013] Step 2-1, switching the current camera object to a sub-view camera object, and switching the current frame buffer to a sub-view buffer object;
[0014] Step 2-2, obtain the screen coordinates (x1, y1) of the mouse start point and the screen coordinates (x2, y2) of the end point by monitoring the sub-view mouse events, calculate the Cartesian world coordinates P1 (X1, Y1, Z1) of the start point and the Cartesian world coordinates P2 (X2, Y2, Z2) of the end point through the screen coordinate to world coordinate function, obtain the direction vector D of the camera change according to the formula D=P2-P1, and obtain the number N of camera changes by calculating the length of the direction vector; pass the direction vector D and the number N parameters of the camera change into the camera object translation, rotation, and zoom change functions, calculate the position position, forward vector direction, upward vector up, and right vector right of the camera object, and then calculate the view matrix view matrix through the matrix computeView function, set it as the view matrix currently used in the WebGL shader, execute the WebGL system off-screen drawing, and save the result in the frame buffer object.
[0015] In step 2-2, the calculation method of the matrix computeView function is as follows: the parameters of the matrix computeView function include the camera's position vector position, forward vector direction, upward vector up, and right vector right; the calculated view matrix array indexes 0, 4, and 8 are respectively equal to the world coordinate values (x, y, z) of the right vector right, the view matrix array indexes 1, 5, and 9 are respectively equal to the world coordinate values (x, y, z) of the upward vector up, the view matrix array indexes 2, 6, and 10 are respectively equal to the negative of the world coordinate values (x, y, z) of the forward vector direction, the view matrix array index 12 is equal to the negative dot product of the right vector right and the position vector position, the view matrix array index 13 is equal to the negative dot product of the upward vector up and the position vector position, and the view matrix array index 12 is equal to the dot product of the forward vector direction and the position vector position.
[0016] In step 2-2, the execution of off-screen drawing by the WebGL system refers to the process of drawing in the frame buffer, specifically including: by default, WebGL draws in the color buffer, the resulting image is stored in the color buffer, and the color buffer content is directly displayed on the browser; the frame buffer can be used to replace the color buffer, and the resulting image drawn in the frame buffer will be saved in the frame buffer and will not be directly displayed on the browser.
[0017] Step 3 includes:
[0018] Step 3-1, obtain the 3D drawing context through the getContext method of the main view canvas (pass in the "3d" parameter), create a Uint8Array object of size width multiplied by height according to the width width (pixel value) and height height (pixel value) of the main view canvas, pass the Uint8Array object as a parameter to the read pixel method (readPixels) of the 3D drawing context, execute the read pixel method to read the contents of the frame buffer and save it in the Uint8Array object, finally create a picture (ImageData object) with the Uint8Array object as a parameter, and save the contents of the Uint8Array object as a picture (ImageData object);
[0019] Step 3-2, obtain the 2D drawing context through the getContext method of the sub-view canvas (pass in the "2d" parameter), pass the image (ImageData object) as a parameter to the drawing image method (putImageData) of the 2D drawing context, execute the drawing image method to draw the image content and display it on the sub-view.
[0020] Beneficial effect: For the scenario of multi-view display of Web three-dimensional maps, the present invention is different from the traditional technical route of creating multiple independent and complete three-dimensional views. It only creates a complete three-dimensional main view and canvas elements, cameras, and frame buffers related to the sub-views, which greatly reduces the browser memory when the Web map is running. At the same time, when off-screen drawing is performed, only the camera needs to be switched, and the scene content does not change, which avoids repeated calculations and greatly improves the operating efficiency of the Web map. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0022] Figure 1 It is a schematic flow diagram of the method of the present invention.
[0023] Figure 2 This is a schematic diagram of the main view WebGL color buffer drawing process.
[0024] Figure 3 It is a schematic diagram of the off-screen drawing process of the sub-view.
[0025] Figure 4 Is a diagram of the frame buffer object structure. DETAILED DESCRIPTION
[0026] The following is a process for realizing multi-view display of Web 3D maps based on the Cesium 3D map engine according to the present invention, including the following steps (see Figure 1 ):
[0027] Step 1 creates the canvas elements, camera objects, and frame buffer objects related to the main view and sub-view. The specific implementation is as follows:
[0028] Step 1-1 creates web page div elements and canvases for drawing the main view and sub-views respectively, and sets CSS styles such as width and height to achieve the layout effect of each view.
[0029] Steps 1-2 create a split-view camera (Cesium.Camera), a screen space event handler (Cesium.ScreenSpaceEventHandler) based on the split-view canvas, a screen space camera controller (Cesium.ScreenSpaceCameraController) based on the split-view camera, and a frame buffer (Cesium.FrameBuffer).
[0030] Step 2 obtains the WEBGL drawing context of the main view canvas, switches the current camera to the main view camera, switches the drawing target to the color buffer, draws the scene content and displays it to the main view. The specific implementation is as follows:
[0031] Step 2-1 Based on the canvas of the main view, create a Cesium 3D map instance (Cesium.Viewer) and execute its render function to draw and render the main view WebGL color buffer (see Figure 2 ) to display the scene content on the main view.
[0032] Step 3 switches the current camera to a split-view camera, switches the drawing target to a split-view frame buffer object, and performs off-screen drawing of the scene content. The specific implementation method is as follows:
[0033] Step 3-1 adds the sub-view rendering process to the rendering loop (render function) of the Cesium 3D map instance, as follows:
[0034] (1) Switch the current camera object to a split-view camera object, and switch the current frame buffer to a split-view frame buffer object; (2) Obtain the screen coordinates (x1, y1) of the mouse start point and the screen coordinates (x2, y2) of the end point by monitoring the split-view mouse events, and calculate the Cartesian world coordinates P1 (X1, Y1, Z1) of the start point and P2 (X2, Y2, Z2) of the end point through the screen coordinate conversion function; obtain the direction vector (D) of the camera change according to the formula D = P2-P1, and obtain the number of camera changes (N) by calculating the length of the direction vector; pass the direction vector (D) and number (N) of the camera change parameters into the camera object translation, rotation, zoom and other change functions, calculate the position (position), forward vector (direction), upward vector (up), and right vector (right) of the camera object, and calculate the view matrix (view matrix) according to the above parameters of the camera object through the matrix computeView function, set it as the view matrix currently used in the WebGL shader, and execute the WebGL system off-screen drawing (see Figure 3 ), saving the result in a frame buffer object (see Figure 4 )middle;
[0035] (3) Calculation method of the matrix computeView function: The parameters of the matrix computeView function include the camera's position vector position, forward vector direction, upward vector up, and right vector right; the calculated values of the view matrix array indexes 0, 4, and 8 are respectively equal to the world coordinate values (x, y, z) of the right vector right, the values of the view matrix array indexes 1, 5, and 9 are respectively equal to the world coordinate values (x, y, z) of the upward vector up, the values of the view matrix array indexes 2, 6, and 10 are respectively equal to the negative of the world coordinate values (x, y, z) of the forward vector direction, the value of the view matrix array index 12 is equal to the negative of the dot product of the right vector right and the position vector position, the value of the view matrix array index 13 is equal to the negative of the dot product of the upward vector up and the position vector position, and the value of the view matrix array index 12 is equal to the dot product of the forward vector direction and the position vector position.
[0036] (4) WebGL system off-screen rendering (see Figure 3 ), refers to the process of drawing in the frame buffer, including: by default, WebGL draws in the color buffer, the resulting image is stored in the color buffer, and the color buffer content is directly displayed on the browser; frame buffer object (see Figure 4 ) can be used instead of the color buffer. The resulting image drawn in the frame buffer will be saved in the frame buffer and will not be directly displayed on the browser.
[0037] Step 4 reads the content from the frame buffer object and saves it as an ImageData object, and draws the ImageData object to the sub-view through the 2D drawing context of the sub-view canvas. The specific implementation method is as follows:
[0038] Step 4-1 Modify the function (resolveFramebuffers function) in the scene that processes the frame buffer and renders it to the screen: Get the 3D drawing context through the getContext method of the main view canvas (pass in the "3d" parameter), create a Uint8Array object of size width multiplied by height according to the width width (pixel value) and height height (pixel value) of the main view canvas, pass the Uint8Array object as a parameter to the read pixel method (readPixels) of the 3D drawing context, execute the read pixel method to read the content of the frame buffer and save it in the Uint8Array object, and finally create a picture (ImageData object) with the Uint8Array object as a parameter, and save the content of the Uint8Array object as a picture (ImageData object); get the 2D drawing context through the getContext method of the sub-view canvas (pass in the "2d" parameter), pass the picture (ImageData object) as a parameter to the draw picture method (putImageData) of the 2D drawing context, execute the draw picture method to draw and display the picture content on the sub-view, and achieve the display effect of the same scene content under the sub-view camera.
[0039] The present invention provides a method for realizing multi-view display of a Web three-dimensional map based on camera switching. There are many methods and ways to realize the technical solution. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the protection scope of the present invention. All components not specified in this embodiment can be realized by existing technologies.
Claims
1. A method for realizing multi-view display of a Web three-dimensional map based on camera switching, comprising the following steps: Step 1, create the webpage div elements, canvas and objects required for the main view and each sub-view; Step 2: After entering the frame loop, modify the drawing function and add off-screen drawing of sub-views in the frame loop; Step 3, read the drawing content from the frame buffer object and save it as a picture, obtain the 2D drawing context of the sub-view canvas, draw the saved picture into the 2D drawing context, and realize the sub-view display; Step 4, performing the operations of steps 2 and 3 on each sub-view until all sub-views are displayed; Step 1 includes: Step 1-1, create the webpage div elements and canvases required for the main view and each sub-view, mount the canvases on the div elements, and set the height, width, and offset of the main view and sub-view div elements; Step 1-2, creating instance objects required for the main view and sub-view, the instance objects include: camera, screen control event, frame buffer, pixel storage and mouse control camera object; Step 2 includes: Step 2-1, switching the current camera object to a sub-view camera object, and switching the current frame buffer to a sub-view buffer object; Step 2-2, obtain the screen coordinates (x1, y1) of the mouse start point and the screen coordinates (x2, y2) of the end point by monitoring the sub-view mouse events, calculate the Cartesian world coordinates P1 (X1, Y1, Z1) of the start point and P2 (X2, Y2, Z2) of the end point through the screen coordinate to world coordinate function, get the direction vector D of the camera change according to the formula D = P2 - P1, and get the number N of camera changes by finding the length of the direction vector; pass the direction vector D and the number N parameters of the camera change into the camera object translation, rotation, and zoom change functions, calculate the position, forward vector direction, upward vector up, and right vector right of the camera object, and then calculate the view matrix view matrix through the matrix computeView function, set it as the view matrix currently used in the WebGL shader, execute the WebGL system off-screen drawing, and save the result in the frame buffer object; Step 3 includes: Step 3-1, obtain the 3D drawing context through the getContext method of the main view canvas, create a Uint8Array object of size width multiplied by height according to the pixel value of width and height of the main view canvas, pass the Uint8Array object as a parameter to the readPixels method of the 3D drawing context, execute the readPixels method to read the contents of the frame buffer and save them into the Uint8Array object, finally create an ImageData object with the Uint8Array object as a parameter, and save the contents of the Uint8Array object into the ImageData object; Step 3-2, obtain the 2D drawing context through the getContext method of the sub-view canvas, pass the image ImageData object as a parameter to the putImageData method of the 2D drawing context, execute the image drawing method to draw the image content and display it on the sub-view.
2. The method according to claim 1, characterized in that In step 2-2, the calculation method of the matrix computeView function: the parameters of the matrix computeView function include the camera's position vector position, forward vector direction, upward vector up, and right vector right; The calculated values of view matrix array indexes 0, 4, and 8 are equal to the world coordinate values of the right vector right, the values of view matrix array indexes 1, 5, and 9 are equal to the world coordinate values of the upward vector up, the values of view matrix array indexes 2, 6, and 10 are equal to the negative world coordinate values of the forward vector direction, the value of view matrix array index 12 is equal to the negative dot product of the right vector right and the position vector position, the value of view matrix array index 13 is equal to the negative dot product of the upward vector up and the position vector position, and the value of view matrix array index 12 is equal to the dot product of the forward vector direction and the position vector position.
3. The method according to claim 2, characterized in that In step 2-2, the execution of off-screen drawing by the WebGL system refers to the process of drawing in the frame buffer, specifically including: by default, WebGL draws in the color buffer, the resulting image is stored in the color buffer, and the color buffer content is directly displayed on the browser; the frame buffer can be used to replace the color buffer, and the resulting image drawn in the frame buffer will be saved in the frame buffer and will not be directly displayed on the browser.
