Git Product home page Git Product logo

newton's Introduction

Newton

A playful, particle-based physics engine designed from the ground up for JavaScript.

Build Status

Read the docs

Roadmap

  • Getting started guide
  • ☑ Feature completeness with getting started guide demos
  • ◻ 90% Test coverage
  • ◻ API docs
  • ◻ Performance benchmarks
  • ◻ Shape Constraint (rigid bodies)
  • ◻ Registration Points (for custom rendering)
  • ◻ Web Workers (offloading from the main CPU)

Contributing quick start

Contributions welcome! Check out the roadmap. Constraints are always handy. Force and Body libraries too.

make build && open examples/guide_movement.html

  • make watch: builds into build/newton.js and watches for changes
  • make test: runs unit tests
  • make dist: builds a minified distribution version

newton's People

Contributors

deepak1556 avatar floatdrop avatar hunterloftis avatar spenserj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newton's Issues

API docs?

Is there any complete api doc available? I mean complete list of available classes/methods/properties?

Object has no method 'Layer'

I've built the master version and when I've tried using it I got this error:

Uncaught TypeError: Object #<Object> has no method 'Layer' newton.js:363

Destroying constraints

There seems to be no way to do this except destroying one of the particles used by the constraint.

Support removal of bodies and components

Please forgive me if there's an obvious reason why I shouldn't be doing this, but I'd like to remove things from my simulation periodically beyond just particles. For instance, if I create a body that has associated edges, particles and constraints, I'd like to be able to remove the entire thing from the simulation at a certain point.

I was able to accomplish this for my purposes by adding an isDestroyed to Edge and adding a cull pass into the simulator for the edge list. I can submit a PR with that change if that's valuable.

In general, I'd just like to start a discussion as to the right approach for removal of complex bodies from the simulator.

Using newton.js

I want to use newton.js in a large project, but I have a couple questions: are there any docs besides the guide? Even a list of classes to explore? Secondly, how do I render bodies without using a builtin renderer (to use textures, etc.)?

Physics for the lazy demo slow in Firefox.

Apologies if this is the wrong place - it's the closest I could find to a project related to your post "Physics for the lazy".

The line:
ctx.globalCompositeOperation='overlay';
...makes the demo insanely slow in FF.

The Firebug profiler shows that, with this line, the line:
ctx.stroke();
...uses about 99.99% of the cpu time.

The demo runs at a normal speed without the 'overlay' setting.

System: FF29.0.1, Win 7, Nvidia GeForce GT 650M

Strange box collision with lattice (see pics)

Code from this tutorial: https://github.com/hunterloftis/newton/blob/master/examples/bodies/index.html

The bug is visible in the first image where the 2 boxes are 45º degree and are sliding on the lattice, obviously not very realistic. In the second image you can see that one box is sliding correctly.

bug1a

bug1b

bug1c

bug1c

Code

        var canvas = $('<canvas id="display" width="1280" height="450"></canvas>')
        this.$el.append(canvas)
        var renderer = Newton.GLRenderer(canvas[0]),
              sim = Newton.Simulator(undefined, renderer.callback, 60, 10),
              gravity = Newton.LinearGravity(0, 0.002, 0),
              container = Newton.BoxConstraint(0, 0, 1280, 450),
              squishy = Newton.Squishy(525, 250, 70, 16),
              boxes = createBoxes(20, 20, 25, 10),
              fabric = Newton.Fabric(700, 0, 1250, 50, 40, 22),
              lattice = Newton.Lattice(0, 200, 50, 10, true, true),
              anchor = squishy.particles[0];

          anchor.pin(525, 0);

          sim
            .add(gravity)
            // .add(squishy, 'squishy')
            .add(boxes, 'boxes')
            // .add(fabric, 'fabric')
            .add(lattice, 'boxes')
            .add(container)
            // .link('squishy', 'boxes fabric')
            // .link('boxes', 'boxes squishy fabric')
            // .link('fabric', 'boxes squishy')
            .start();

          $('#display').on('mousemove', function(e) {
            var offset = $(this).offset();
            var x = e.pageX - offset.left;
            var y = e.pageY - offset.top;

            anchor.pin(x, y);
          });


          function createBoxes(x, y, size, amount) {
            var boxes = [];
            while (amount--) {
              boxes.push(Newton.Box(x + amount * size * 3, y, size));
            }
            return boxes;
          }

Node.js package

I think supporting node require will vastly increase audience of newton (aka simple multiplayer game examples).

benchmarking in node

It would be nice to be able to measure performance before/after changes semi-objectively (eg, without noise from browser implementations and render steps). A suite of node tests with timers could help here.

WebGL Renderer

The examples tend to be render-limited rather than simulation-limited.

Their overall speed could be improved by converting the default renderer to WebGL from Canvas.

inertia effect on particle

How would one add an effect of inertia on a particle ?

let's say i would like to improve the example from the guide (copy/pasted here)

var mousePin = null;

renderer.on('pointerdown', function(point) {
    var particle = sim.findNearest(point, 30);
    if (particle) mousePin = sim.add(Newton.PinConstraint(particle, point));
});

renderer.on('pointerup', function(point) {
   if (!mousePin) return;
   sim.remove(mousePin);
   mousePin = null;
});

And i would like the particle to continue its movement upon mouse release, and slowly stop until its completely static.

Since forces are applied globally on all particles, the way to go would be to make an inertia constraint to target a specific particle.
Am i right ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.