Flash Stage3D is a perfect solution for displaying the problem of the model on the 2D UI interface

Source: Internet
Author: User

A lot of stage3d developers have been having headaches with 3D models showing up on 2DUI. Stage3D is always under the stage2d. In order to achieve the 3D model on the 2DUI display usually there are several implementations, the following is the implementation of these methods.

Implementation Mode 1:

Dig a hole in the 2DUI to show the three layers. The drawback of this approach is that if two UI interfaces are turned on at the same time, the UI error level is displayed as an aberration. In order to solve this problem many programmers choose to hide the other interface when the hole is displayed in the UI, the user experience is very poor.

Implementation Mode 2:

Use Context3d's Drawtobitmapdata API to plot the price of the 3D layer to bitmapdata in real time. And then add it to the 2DUI. The disadvantage of this approach is that each drawtobitmapdata function. Each time you draw from the graphics card and then return it, the overhead is very high, causing the frame rate to drop. And each draw graph generates a lot of memory. Some people might say that I draw at a time interval to draw, reducing part of the overhead. In fact, all the same picture is not smooth.

Implementation Mode 3:

Renders the 3D model as a sequence frame bitmap. Then implement a bitmap player to display on 2DUI. This way, the amount of bitmaps needed to load is very large, and the memory size can be imagined.

Well, all of these are our common practice. Really disgusting, many programmers will choose to use the 3rd party to provide 3DUI such as Starling, etc. to achieve. Yes, that's the final solution, but the problem with the headaches is that coordinate transformation is a troublesome problem. Another is that Starling for AS3 programmers is not always so handy. What to do.... What to do.... Painful tangle of needles in the tie.

Friends if you are still in for these problems headache, tangle, needle stick in the following I recommend to you the next one can almost solve the above you worry about any problem. Let's go first.

What about it? Does it feel great?

One day in the morning meeting, my colleague and I said he thought of a way to solve the problem of UI mutex. Holding a doubtful heart I saw his way of realization. Let me just say it.

In fact, the principle is still mentioned in the implementation of the way 1 is only in this practice to do some optimization. We all know that the Graphics in AS3 draw a rectangle in the same place and draw a hole two times. First check to see if the UI panel with the 3D model overlaps with the other UI. If overlap keeps the topmost UI, the lower UI is empty. This will solve the problem. But here's the problem. A UI with a 3D model and a normal 2DUI display are no problem. Then the two UI with the 3D model stacks together to see the model on another UI running to the UI. The reason is that the model is rendered on the same context3d once the drawing is empty, it is all displayed. To solve this problem we have to change the rendering of the 3D engine. First, the 3D elements to be displayed on the UI are made into a standard room to distinguish the rendering from the bottom of the engine.

Call the next Context3d to clear the depth when the tag is checked

Context.clear (0, 0, 0, 1, 1, 0, context3dclearmask.depth);

Okay, let's get down to the rendering order of the 3D objects we render on the 2D interface:

Light-to-grid (as background backplane)---> 3D models

Well, the sequence is clear, and now the rendering begins.

The light was ignored. As long as you adjust the coordinates to the model you can do without special treatment. The point is, when we render the background backplane, we call again context.clear (0, 0, 0, 1, 1, 0, context3dclearmask.depth) and render again.

Cleaning depth This is mainly used to control the 3D objects in the lower layer due to the depth of the problem to the front. All right, the backplane is already rendered OK. Now let's repeat the rendering of the backplane once again to render the model again. Okay, now it looks good, everything's okay. Create a few more overlays now try

OK, everything's fine. Finally, the statement that if the conditional friend or suggest that you write 3DUI to do. It doesn't matter. You can consider using Starling or some 3rd-party class libraries to implement.

Flash Stage3D is a perfect solution for displaying the problem of the model on the 2D UI interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.