Comments (15)
I'm sure this is low on your priority list, but it would be cool to see. One reason DOM rendering would be compelling is there is a small but growing trend (especially in mobile) to use physics concepts to define the interactions of views (see UIDynamicAnimator which was added in iOS 7).
Right now I'm evaluating different engines for a similar feature in Ionic: http://github.com/driftyco/ionic. The lack of DOM output makes it harder to plug in (I'm using PhysicsJS right now which has it), but I feel like this library is more stable.
At any rate, awesome library and I look forward to playing with it more :)
from p2.js.
Thanks!
What would be a killer demo? I've been thinking of starting with simple draggable squares, or something similar.
Btw, I'm only making a small demo. A complete DOM renderer is not in the project scope.
from p2.js.
Is there still a need for this? I think I might be able to help with this. I have some knowledge of Dom sprites and would need some specifications on what the renderer/api would need to look like.
from p2.js.
IMHO combining Ionic and p2 could be a huge win, although a DOM renderer would probably be an effort to reckon with.
from p2.js.
@petarov I could easily combine this with react, transforms, proper transitions, and some react magic.
I'll work up a gist with 300 balls running at 60fps bouncing off of 3 planes tomorrow
from p2.js.
It turns out react is not designed for 60fps animation, and the dom shouldn't be used that way either :).
However, it is possible and I am working on it.
It's going to take some time.
-Josh
from p2.js.
Hm, would it be more smooth/performant if you ran the physics at, say, 30fps and let the DOM do linear interpolation using CSS animation?
from p2.js.
I'm pushing updates way too fast to React, and it ends up eating a lot of memory and doing garbage collection way too often. FPS doesn't matter.
Maintaining a set of dom nodes by giving them IDs in an index and pushing transforms and transitions to them is the fastest way and can be done at 60fps.
I'll get a working demo soon, I promise.
from p2.js.
Ok cool!
Another thing.. Should the animation data really go through React as state/props?
Here's a related post. Using jQuery, but I think it has some ideas that can be applied to using p2 too. http://stackoverflow.com/questions/25436445/using-jquery-plugins-that-transform-the-dom-in-react-components
from p2.js.
Yeah if I don't use react stuff it goes faster... so why use react at all ;-).
from p2.js.
Made a little fiddle around this... See http://jsfiddle.net/k98u8p0o/18/
The idea is to run physics at a slower rate than 60Hz and use CSS animations for the interpolation. Maybe you can use some parts of it. It seems to run OK on my phone as well :)
from p2.js.
Haha, having a bunch of fun with this
from p2.js.
I'm just having fun watching :)
To follow up to my comment, I did explore this a bit, using physicsjs though. If you want to see what I did, it's in this branch: https://github.com/driftyco/ionic/tree/wip-physics/contrib/physics.
Didn't find it was very useful or easy to use in practice, but fun as hell nonetheless 😛
from p2.js.
I highly suggest this:
elem.style.transition = 'transform 20ms';
elem.style.transform = 'translate(' + object.position[0] + ',' + object.position[1] + ') rotate(' + object.angle + ')';
You can go 60fps, just make the transition slightly longer than 20ms and the object will catch up.
Also, why set the transition more than once?
Simply use request animation frame and set transform: translate(x, y) rotate(rad) after physics once per frame.
from p2.js.
Yeah you're right. It feels like using CSS for interpolation is a bit unstable when updating so often, so I'm skipping it for now.
The DOM rendering demo has been added to the repo. Closing issue.
from p2.js.
Related Issues (20)
- npm finds 119 vulnerabilities on install HOT 5
- how to get constant speed of body?
- Unmount usage in React
- Particle Demo
- removeSpring event is not fired
- Shape position changed when added to a body
- p2.js Multiplayer Game issue HOT 3
- RotationalSpring damping is ignored
- CCD doesn't work with collisionGroups ? HOT 1
- Why is localAxis passed into projectOntoLocalAxis only to be overwritten by tmpVec1?
- How many pixels is a meter in p2.js? HOT 3
- How do I destroy an entity that has a body?
- Is there water or liquid simulation possibilities? HOT 3
- Is it possible to use the GPU for better performance?
- Collisions not working at all HOT 1
- Cannot read property 'overlaps' of undefined
- Help with resizing P2 Box?
- p2
- fatal: unable to access 'http://ikt.pm2.io/ikt.git/': Could not resolve host: ikt.pm2.io HOT 1
- Collision between circle and box can be missed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p2.js.