A-Frame scene optimization for mobile devices - aframe

I have created a grocery store project built on A-Frame with 63 products and 3 shelves.
Screenshot: https://i.stack.imgur.com/A1x5u.jpg
On the laptop, after the grocery store is loaded, it holds 60 fps.
But it won't load on mobile devices - it's just crash the browser (tried on iPhone 13, Safari/Chrome and Samsung Galaxy S10, Chrome).
What guidelines should I follow to optimize the A-Frame scene for mobile devices?

I'd recommend looking at the Best Practices - Performance docs.
In my experience the most common culprit is making too many draw calls. If you have identical objects it would be best to use Instanced Meshes.
Diarmid McKenzie made a cool component if you don't want to dive into the THREE.js API
Use the stats component as often as possible, to keep track of the complexity of the scene (draw calls, geometries, lights).

Related

QML, code once, deploy twice

I am creating an application in QML. Initially it was for desktop use only, but I decided to cover Android devices too.
The problem I'm struggling with is how to handle different platforms. For now, I have a separate class that provides informations about screen ratio, platform(mobile, desktop) orientation etc.
What is the best approach to provide UX closest to native, for each platform?
How to handle situations like this?
Mobile
StackView with 2 pages
ListView taking entire screen space
Clicking on object in the ListView navigates to the second page with
additional info
Desktop
No StackView
ListView taking only 300 pixels
Additional info about currently selected element on the list should
be visible in TextArea next to ListView
Designing scalable UI, based on calculated screen ratio or pixel density for a given device is one solution. But, this kind of mobile-ish interface looks pretty bad on desktop. Can you imagine Android Gmail app running on PC?
The solution I see is to place as much logic as possible into C++ and create lightweight layouts for both mobile and desktop platforms in QML.
What is, in your opinion best way to target multiple devices. Should I create scalable UI for mobile and use it on desktop and just 'deal with it' or should I sacrifice more time and create UI for each platform so that it will be user friendly everywhere?
Should I create scalable UI for mobile and use it on desktop and just 'deal with it' or should I sacrifice more time and create UI for each platform so that it will be user friendly everywhere?
This question is quite subjective, and we haven't seen the UI in question, but in my opinion, you should sacrifice more time and create a decent UI for desktop and mobile. This is assuming that the desktop version of your application has enough content and/or features to warrant it.
The solution I see is to place as much logic as possible into C++ and create lightweight layouts for both mobile and desktop platforms in QML.
This is the right approach. QML is super easy to write, and super easy to maintain as long as you keep it simple. Qt Quick Controls learned this the hard way, and this is why Qt Quick Controls 2 are being created: to use as much C++ and as little JavaScript, expensive bindings, Loaders etc. as possible.

Why people write Flash video players in Flex not in Flash?

One common hebavior I observed in my slow Internet connection is that most sites on the Web embedding Flash Video, their player is always written in Flex. I can tell by the extremely long loading scroll bar that Flex defaultly provides. From my experience Flash loads faster, Why do people stop writing stuff in Flash anymore?
Are there any fast loading yet rich feature Flash video players>
My experience is that the components provided by default in the Flex framework are more stable than the ones provided in the Flash IDE. So I'd prefer to use the Flex components simply because it means less time debugging problems in the actual component code. It is however true that players based on the Flex framework tend to be heavier in terms of download size. But since video is bandwidth heavy and people who watch video over the net tend to have good bandwidth these days, I guess the conclusions most developers come to is that the extra download size is an acceptable tradeoff for less time spent in coding boilerplate.
Personally, if the requirements state that the player has to load fast and be light weight then I always roll my own in pure AS3 and just implement exactly as much as is needed. But if there is no such requirement, then I'll use the Flex-components as a base and do customization from there.
As for the second part of your question, sorry can't think of any open source fast loading feature rich flash video players right now.
Flex produces a flash movie (swf), so the end result is still flash.
As for the reason behind it, not everybody has or wants Adobe Flash (Studio) or any of the other timeline based studios.
Flex enables anybody to create a flash based application or widget using XML and the free Flex SDK.
There may also aesthetic reasons such as standardised controls.
Try Flowplayer, JW FLV Media Player and the last contender, but not the least from Adobe - Strobe Media Playback http://www.osmf.org/strobe_mediaplayback.html
From my experience Flash loads faster, Why do people stop writing stuff in Flash anymore?
When done correctly, there's no difference in how they work - in fact, I'd argue that stuff done in Flex (specifically, using the Flex SDK) give you more freedom to control how loading is done.
But to answer the question, people stopped using Flash just because there's much better stuff out there. Flex Builder, FlashDevelop, FDT - they're all much better tools for any serious coding and debugging. I used to love the IDE, but now I can't fathom how would anyone do anything serious on it, even when using external code editors.
Flash still works when you need vectors, or to create a library with some embeddable assets, but that's pretty much all it's useful for nowadays.
I am a flex developer, see flex is somewhere flash, here flex has two frames, preloader stage(first frame) and creationComplete stage(second frame), the same frame concept as flash has, but flash has more than two frames and layer concept is also there
Major differneces comnes in the ease of using the components in flex, in flash, altho flash is one of powerful tools that has changes the web,
but flex gives the freedom, i m using flex, so i know that i can give more time on business login development, rather than concentrating on design aspects,
but it's also true, i have to see the design aspects as well in flex,
so happy flexing

How can I get a smooth text crawl using Flex?

I'm working on a standalone Flash application (written using Flex 3/ActionScript 3) that features a text crawl, like what you might see at the bottom of your TV when watching a cable news channel; it's a long narrow box that text moves across from right to left.
I've implemented it by creating a Label element, populating it with text, and then moving it using a mx:Move object with a Linear.easeNone easing function. It works, but it has ample room for improvement. It looks a bit jerky, and tends to have a fair amount of "tearing" (the top and bottom halves of the text sometimes fall out of sync).
I tried throwing math at the problem to get the crawl's movement rate synced with the monitor's refresh rate, but that was a bust. I found out the hard way that the app's frame rate jumps around too much; the "optimized" crawl varied between looking silky smooth and like it had epilepsy.
Is there anything else folks would recommend I try to smooth this thing out? Is there some alternate design you'd recommend I try?
Edit: Some context: the crawl is part of a digital signage application (played from a standalone Flash projector -- no web browser) that does stuff elsewhere on the screen, including video playback and rendering text and images. It definitely gets choppier during video playback, but it's never as smooth as I'd like it to be.
There are two potential solutions to this problem, but both have caveats, the first because of your use of Flex and a standalone projector, the second because it is a mitigator, not a complete solution.
Hardware Acceleration
When publishing your file, you can attempt to have Flash utilize hardware acceleration to alleviate the vertical refresh issue you are running into that is causing tearing. Sadly, Flex Builder 3 is incapable of enabling this setting at the SWF (projector) level (Link to bug). This has yet to be resolved and has been pushed from 4.0 to 4.1 to 4.x... If and when it is resolved, it will likely be a compiler argument in the project settings of Flash Builder 4.
You may be able to determine if this solution works for you by outputting your projector as a standard SWF and embedding it on an HTML document with the wmode set to "direct" or "gpu". Sadly, if it does (it should), you can't use it right now anyway. If you have Flash Builder 4, certain projects are capable of making round trips between FB4 and Flash Professional CS5, though I am not sure what the criteria for that is (my current AIR project has all the project modification menu options grayed out). If you do manage to get your project into Flash, you can enable hardware acceleration in the Publish Settings of the project (File->Publish Settings->Flash tab->Hardware Acceleration option in CS5).
This method is almost a certain solution for your problem, though it has two issues, one already highlighted above, and (for people publishing for the web) that by utilizing direct or GPU rendering on a webpage, you are unable to layer any DOM elements on top of flash.
direct: This mode tries to use the fastest path to screen, or direct path if you will. In most cases it will ignore whatever the browser would want to do to have things like overlapping HTML menus or such work. A typical use case for this mode is video playback. On Windows this mode is using DirectDraw or Direct3D on Vista, on OSX and Linux we are using OpenGL. Fidelity should not be affected when you use this mode.
gpu: This is fully fledged compositing (+some extras) using some functionality of the graphics card. Think of it being similar to what OSX and Vista do for their desktop managers, the content of windows (in flash language that means movie clips) is still rendered using software, but the result is composited using hardware. When possible we also scale video natively in the card. More and more parts of our software rasterizer might move to the GPU over the next few Flash Player versions, this is just a start. On Windows this mode uses Direct3D, on OSX and Linux we are using OpenGL.
**Source*
Direct is the ideal option for this situation, as you can actually have performance degredation with "gpu" as well as visual differences from graphics card to graphics card.
Lower your framerate
The Flash player will continue to play video at its native refresh rate independent of the rest of your project as long as you keep the framerate at or above approximately 2FPS (though I suggest 5FPS minimum). You won't want to run that low for this example, but you are able to lower the framerate of the entire scene without impacting video performance. The closer your framerate is to the screen refresh rate, the more apt you are to actually create the tearing effect unless you are able to absolutely sync with the monitor's refresh rate, which you probably cannot do without the above... Hardware Acceleration.
This problem has existed in the Flash Player for as long as it has been able to move objects horizontally. What happens is that Flash updates a buffered snapshot of the running animation at the same time that the screen is refreshing. If the buffered snapshot changes partway through a screen refresh, you get a tear. This is why lowering the framerate actually reduces the amount of tearing, you are refreshing the buffer less frequently.
As #Tegeril mentioned, using Flex is one of the reasons. Flex is a pretty heavy framework and it does a lot of things behind the scenes. If you're familiar with the life cycle of a component(especially invalidating properties, invalidating the display list, etc.).
As a few minor things that might improve performance:
try to keep a simple display list. If you know the app will always be displayed at one size, then flex won't waste time traversing the display list/tree up to the top and back for measurements. Also, try to use a Canvas. I know, it's not very clean, but since it uses absolute values and doesn't check with the 'parents' much, it should be faster than other containers(like HBox,VBox, etc.)
try to display the video at it's full size(make sure the encoded video dimensions are right so there be any CPU cycles on resizing video
Ok, this was Flex stuff.
It might be very handy to read sencular's article on Asynchronous ActionScript Execution which explains how Flash Player handles updates and renders.
(source: senocular.com)
Frames both execute ActionScript and render the screen
(source: senocular.com)
ActionScript taking a long time to complete delays rendering
I imagine the jerkiness is related to this. Also, I'm guessing you might
get moments of smooth movement then sudden halts, every now and then, when
Flash Player catches it's breath(Garbage Collector cleans up)
Victor Drâmbă article on “Multithreading” in Actionscript might also
be useful.
Soo, to recap:
use Profiler or something and see if the Flex framework is slowing you down, or where the 'bottleneck' is
improve as much as you can on that side then check if it's how Flash Player handles all the actionscript('elastic' frames)
If the bottleneck comes from the Flex framework, worst case, you
can try to minimise the number of components that traverse the display list,
and use pure actionscript for the other things(as #PatrickS suggested, use TweenLite, etc.)
If it helps, try to preload data(fetch rss feed and all that) at the start, and when you've got most of the important bits that don't require 'refreshes'/loads frequently, display the app. You will use more memory, but will have more cpu cycles to spare for other tasks.
Also, if it's display objects that are the 'bottleneck' and there's plenty of them, check if you can reuse them using Object Pools.
HTH
TweenMax or even TweenLite ( http://www.greensock.com )handles this sort of job pretty well. What else is your app doing while the text is scrolling though? Is it possible that some other processes are interfering?
This may not be helpful, but have you considered putting the crawling text into the html DOM and using CSS transitions to crawl the text. Obviously there's the IE problem, but it should be supported in IE9 and you could use javascript as a fallback.
This may seem silly, but CSS transitions are getting hardware acceleration and separate processes for plugins meaning on a multicore machine you could get parallel threads.
One thing you might consider is to move your label incrementally using a Timer instead of an easing function. That way you can take advantage of the updateAfterEvent method to get smoother rendering. Here's a link to an article/video from Chet Haase (Adobe's Flex graphics dude) that explains usage along with an example app with code:
http://graphics-geek.blogspot.com/2010/04/video-event-performance-in-flex.html
Hope that helps.

Any ideas on how to prepare for the future of Flash/Flex/HTML5 Development?

I've chosen Flex 4 as the most appropriate technology to develop a graphically-rich web application (its not a simple content-driven site), but worried about how the recent negative press (i.e. security issues) may effect end-user's trust and ultimately whether the user-base may drop promptly in response. (I don't care if my app works on iphones or ipads for now)
I think Flash Builder 4 is an great development environment and has minimized development time for me/my team. After some basic testing of graphical animations similar to that used in my app - HTML5 didn't perform as fast, is inconsistent with browsers, and some animations are jagged (I expect browser performance and graphic libraries to improve over time). I also 'personally' dislike programming Javascript as I am very fond of strong-typing to uncover mistakes quickly.
If you develop Rich Internet Apps, how are you responding?
Are you preparing to potentially migrate to HTML5/Javascript? Java? No action?
BTW - I don't want pro/anti-flash arguments - just curious to see how the community is responding.
At the end of the day, Flash/Flex aren't going anywhere. If Flex 4 meets your current needs and you're aware of the limitations (ie can't deploy to iOS devices) then I say go for it. Yes it's true that the topic has become mildly politicized - but if you're offering something your clients need then they'd be silly to refuse to use it on the grounds that they support "HTML 5" - when HTML 5 clearly doesn't offer you the tools you need.
Plenty of awesome stuff is coming down the pipe in Flash, much of which simply can't be done any other way - google UJam for an example. I wouldn't let Steve Jobs scare you away from using the technology that works for your needs.
My company plans to continue with Flash, using FlashBuilder 4 and Java back end. We went with Flex/Flash several years ago to get out of the business of supporting all the different browsers and into the business of being productive and giving our users a rich client-side experience.
HTML5/Javascript have potential, but are nowhere near as robust, powerful, fast, or efficient. The class hierarchy, data typing, and event model alone put ActionScript 3 miles beyond any Javascript. So what if Steve Jobs gives Flash the thumbs down? Time-Warner and other big media companies have said they're going to continue with Flash, so it's only a matter of time before Steve Jobs either relegates Apple to permanent niche status or caves and allows Flash on Apple products. (My guess is for the immediate future he will prefer niche status to admitting he is wrong—look how long he maintained a mouse only needed a single button?—but that's just my opinion.) In any case, Flash will soon be available on a multitude of smart phones, including the Droid, so I am not worried.
Adobe will provide tools to convert to HTML5, but they are already following the HTML5 Path with some introductory tools. Just keep watch on adobe. They know what is going on. They just killed mobile flash so even though they argued with apple over it they finally did the right thing instead of stupidly holding on to it just because... hope that helps
I'm a Flex developer, but I think HTML5 is going to be huge. The full features of HTML5 are years away, and I don't think it's totally going to kill Flash. Flex will hold on to some part of the RIA market because it has a lot more going for than just a de facto standard client plugin -- LCDS/BlazeDS, plays nicely with ColdFusion and Java.
I like Flex for the long run. It'll lose some ground to HTML5, but there are areas where Flex will hold its advantage.
Disclaimer: I am author of Web Atoms JS
Flex/Flash is dead already, as usage of non PC devices is increasing everyday. Except old IE (IE<10) almost all features of Flash are already offered by browsers. File API, AJAX upload with progress bar,Canvas API, Indexed DB, Cross Domain message API & Web Sockets. And CSS3, WebGL with 3D can give flash like graphics.
Regarding Component Library & Binding, HTML5+JS lacks component driven development that flash offers. To bridge this gap, we created framework that gives similar functionality with all components to that of flex. Look at following image & see this blog which outlines similarities between Flex & Web Atoms JS.
http://akashkava.com/blog/439/migrating-from-flex-to-html5-with-web-atoms-js/
Here is link to documentation.
http://webatomsjs.neurospeech.com/docs

How can I do Flash 3d animation, Flash only supports 2d animation?

I am a beginner Flash developer. I saw some site like [http://www.3dfreeair.com]1 and another site also. On this site some 3d Flash animation there. How can I do like those animations? Because Flash only supports 2d animation. If you know, send me any reference url for studying 3d animation in Flash only.
Flash CS4 only supports very basic 3D animations and movement. If you want more advanced 3D in flash you need to use one of the various non Adobe 3D libraries. The list includes:
http://blog.papervision3d.org/
http://away3d.com/
http://www.flashsandy.org/
http://blog.alternativaplatform.com/en/
http://www.yogurt3d.com/en/
http://www.ambiera.com/coppercube/index.html
Be aware that no 3D libraries in flash are hardware accelerated so you'll never get the same performance or features that you get with proper 3D graphics programs. If you do need high end hardware accelerated 3D graphics in the browser you may want to take a look at unity3D
http://unity3d.com/
J
Flash CS4 / Flash Player 10 supports basic 3d Animation of flat planes. Check this out. A quick search gave me lot of flash 3d tutorials.
PaperVision3D is the most widely-used library and is excellent.
BTW,
Papervision3D is evolving to PapervisionX, and Alternativa3D 5.5 is evolving to version 7, both with specific support for player 10's anisotropic texture mapping capabilities, which should improve scene complexity and frame-rates considerably.
Also worth a peek is ND3D and Glen Rhode's Flash Ray Engine

Resources