preface

3D panoramis are nothing new, but the 3D panoramis we see on the Web used to be done in Flash. If we can properly use the relevant knowledge of CSS3 Transform, we can also achieve a similar effect. In other words, 3D panorama is actually one of the application scenes of CSS3 3D.

To prepare

Before implementing CSS3 3D panorama, we will first sort out some CSS3 Transform properties:

Here’s a closer look at some of the points above:

implementation

Here’s how to implement a CSS Transform 3D panorama:

Imagine standing in the middle of an intersection, holding your body still and rotating your head 360 degrees, creating a panorama centered around you. In fact, when the focal length is constant, we are standing at the center of a cylinder.

But the biggest difference between the virtual world and the real world is that nothing is continuous, that is, everything is discrete. For example, you can’t display a perfect circle on the screen. You can only represent a circle as a regular polygon: the more sides, the more “perfect” the circle is.

Similarly, in three dimensions, each 3D model is equivalent to a polyhedron (i.e., a 3D model can only be composed of uncurved planes). This is not surprising when we are talking about a model that is itself a polyhedron, such as a cube, but we need to keep this principle in mind when we want to show other models, such as spheres.



The taobao Creation Festival event page is a great CSS 3D panorama page, which divides the panorama into 20 equal sections with 18° (360-20) difference between adjacent elements. Note that we want to make sure that the face of each element points toward the center of the cylinder, so we need to calculate the rotation Angle of each equal portion. And then you move the element outward (in the z-direction) by R px. For a cube r is side length over 2, but for other more complicated regular polyhedra?

Example: For a regular nhedron, the width of each element is210pxAnd the corresponding Angle is40 °, namely, as shown below:

Images from:Desandro. Making. IO / 3 dtransform…



Top view of the regular nenhedron







The calculation process

This gives us a common function that simply passes in an object containing the width and number of elements to get the value r:

function calTranslateZ(opts) { return Math.round(opts.width / (2 * Math.tan(Math.PI / opts.number))) } calTranlateZ({ width: 210, number: 9 }); / / 288Copy the code



Animation of elements moving out as seen from overhead

In addition, to make the following easier to understand, we have agreed on the HTML structure:

#view(perspective:1000px) #stage(transform-style:preserve-3d) #cube(transform-style:preserve-3d). Div (width:600px; Height: 600 px) /* The elements that make up the cube */Copy the code

Once the regular polyhedron is constructed, we need to place our “eyes” inside the regular polyhedron. Since elements after the “eye” are not rendered by the browser (and.div elements whether to set backface-visibility:hidden; ), and we made sure that the front faces of the.div elements point towards the center of the regular polyhedron, creating a 360° surround effect. Where exactly is the “eye” placed? A: Make the z-coordinate of the invisible.div element larger than the perspective value by setting the translateZ value of the #stage element. Such as: RotateY (-180deg) translateZ(-300px), meaning that the front element is shifted 300px to the direction of the “eyeball”. If the #view perspective is 1000px, then the #stage translateZ value should be more than 700px and less than 1300px, depending on the effect you want to render.

Based on the above knowledge, I roughly mimicked the effect of the Creation Festival: jdc.jd.com/lab/zaowu/i…

In fact, it only takes six images to achieve a common panorama without dead angles. I tested myself again: jdc.jd.com/lab/zaowu/i…

It can be seen from the following figure that a panorama is formed by combining the four horizontal pictures:



With that in mind, you can create an interactive panorama by setting the appropriate CSS3 Transform attribute values for the elements. Of course, interactive effects can be drag, gravity sensing and so on.

As mentioned above: “Nothing is continuous, that is, everything is discrete…” . Combining the horizontal images from the Festival of Creation and the subsequent panorama, we find that the more images, the lower the requirements of the image. What do you think?



Panorama of the Festival of Creation



Panorama material production

Panorama making is divided into design and real scene:

Design class

To create a panoramic page similar to Taobao Maker Festival, the design draft needs to have the following requirements.

Note: The specific data mentioned below are based on the Creation Section, and can be adjusted according to their own requirements (if found lacking, welcome to supplement).

The overall background design is as follows (2580*1170px, divided into 20 equal parts) :



Basic requirements:

  1. It needs to be end to end horizontally;
  2. Because the effect drawing eventually needs to be cut into N equal parts, the width of the design drawing should be divisible by N as much as possible.
  3. Image size takes into account not only the size of the front view, but also the fact that elements can still cover the field of view when rotated (optional).

Of course, the above picture is just the background picture, and you can also add some small object materials (parallax can be formed by the difference of motion speed to enhance the stereo effect), such as:





Small object elements (dotted lines are for reference, there are 21 small objects in the Festival)





As shown in the figure above, each picture is equally divided into M equal parts. Of course, M depends on where the object is in the background and how big it is. In addition, the width of M is the same as the width of N. Although some objects (M>1) have a smaller proportion of the pattern on both sides, it is recommended to keep the same width.

Note: if the small object has special deformation effect, the specific deformation parameters should be noted.

There are no special requirements for top and bottom images.

Live class

If you want to create a live panorama, take a look at Google Street View:

Google street viewRecommended devices are:





The most affordable option is the last one, the Google Street View APP, which offers a panoramic camera in-house, but as the photo blurb says, it’s a bit of practice, so it’s a bit more demanding.

Addendum: Last Saturday (August 20, 2016) TGDC sharing session, guests shared their approach to panorama:

  1. Use professional equipment such as RICOH THETA S to take panoramas
  2. Exporting a still image
  3. Use the APP or krPAMo Tools, Pano2VR, Glsky Box and other tools specially provided by the device to turn the static image into 6 images
  4. Use Web technology to create interactive panoramas

Web technology has the following three options (and, of course, others) :

  • CSS3 (the method mentioned in this article)
  • Three.js
  • Krpano (for panorama, fall back to Flash for lower level browsers), check out the tutorial

At that time, guests quickly produced the scene of the conference panorama.

It can be seen that the emergence of excellent hardware equipment greatly reduces the time of post-processing, and the Web provides a good display platform.

The last

As the software and hardware of terminal devices continue to improve and improve, the Web is not far behind in the FIELD of 3D, if you are tired of playing with 2D H5 or want to provide users with a more innovative and excellent experience, panorama may be a choice.

Finally, if there is anything unclear or unclear, please contact me and I will try my best to solve it. Thank you thank you ~