Giter VIP home page Giter VIP logo

oimo.js's People

Contributors

akiyah avatar davidlyons avatar lo-th avatar oakes avatar positlabs avatar raananw avatar sebavan avatar sufuf3 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  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

oimo.js's Issues

Friction isn't properly handled?

The coefficients of friction on objects don't seem to be affecting very much. Ideally a coefficient of zero would mean objects could slide freely over one another (like on ice), but it seems there is still a very considerable damping/frictional effect going on which prevents that kind of sliding behavior. Any ideas how i can go about fixing this?

EDIT: actually i found the problem, setting the coefficient of friction/restitution/etc to 0 means the checks when you create a new OIMO.Body() are seeing it as a falsey value and replacing it with the default of 0.4 in the case of friction.

should be replaced with (obj.config[1] === undefined ? 0.4 : obj.config[1]) etc. so 0 is a legal input, but the method of setting a default if a parameter is left out is preserved

Future Plans?

First off, i have to say after looking around on the web, oimo.js looks like the fastest .js physics engine out there right now. Obviously this speed is a result of it being lightweight, but it is lacking some important features which would be nice to have. I'm hunting around for physics engines to use in my project, and oimo is really my number one pick right now, but i'm a bit discouraged by its lack of support for collisions against triangle meshes / terrain / convex shapes / basic shapes (terrain being the most important) having support for cones / ramp wedges / pyramids, and other basic geometries would also be awesome. Ammo.js and cannon.js are the only real alternatives out there, and they perform very poorly imo compared to oimo.js, nonetheless they have support for triangle meshes / other shapes. In any case I'm considering using oimo.js anyways and possibly extending it to have these features. It's just too good to ignore.

Really it'd be nice to know this project is still alive, but i really just want to know whats in store (or not) for the future, so I (and probably many others in my position) can plan accordingly.

Events?

Hi there, lo-th.
Thanks for this great work, Oimo.js is fantastic!

I'm building my own little engine for some WebGL apps, mostly games, thinking on a client-server context. Three.js is my tool of choice for client-side rendering, and i was developing my own server using node.js.
Did a few steps on that direction, but given that i'm a newbie on physics it was a kinda rough path. That's how i discovered Oimo, looking for some help in the physics field.

I've already adapted Oimo's basic demo to work with node.js for experiments, and then adapted some of my own project's classes to work with Oimo's classes (mostly inheriting). It seems to work fine.

Thing is, now i need to communicate Oimo's classes with my own. My classes use an EventEmmiter pattern, with ".on()" and ".trigger()" kinda stuff for easy high-level configuration and for avoiding tight coupling. I was expecting to handle Oimo's inner events somehow (like collisions, for example), but still haven't found a way looking at Oimo's source.

So, the question is: does Oimo's classes implement some event model i can hook on?

If the answer is "no", do you have any plan on implementing an event model on it?

Oimo dosent work on iOS safari

it shows the error in oimo.js:814

SyntaxError: Attempted to redefine property 'multiplyScalar'.

then ReferenceError: Can't find variable: OIMO

setting body mass

Sorry in advance if my question is rather primitive, but I cannot see how to set the mass of an OIMO.Body. Background: I'm trying to use OIMO and one moving object keeps getting NaN position and rotation, I suspect it is because its mass is 0.

and before all: salute for the lean and fast engine!

toggle a fixed body

Hi,

From time to time I want a fixed body blocking a goal and other times note. I need to toggle the "activeness" of the body. I would like to avoid removing the body and re-adding it as there is a lot of state added to the body that would need to be rebuilt.

Is there a "deactivate" ?

Thank you!

Relative rotation in REV is busted (caused by bad matrix mult)

There's a line in Sync-shapes which multiplies the shapes relative rotation 3x3 Matrix with the rigid body matrix, but the multiply order should be reversed, or else the relative rotation ends up creating a strange effect where objects with any relative rotation rotate inverted to the rigid body.

basically
the line should be:
shape.rotation.mul(this.rotation,shape.relativeRotation);
not the current:
shape.rotation.mul(shape.relativeRotation,this.rotation);

Collision and Trigger Events/Callbacks?

How do I determine when 2 bodies collide, is there a callback? Also, another part to that, is there way to detect when 2 bodies to be behave like triggers, is there a way to get a callback event but not have the bodies collide?

What are the available callbacks for this?

Extending Oimo shapes from outside

Hi:

I'm trying to adapt Oimo to my special needs for my application, that requires some new collision shapes. The problem is that Oimo do not allow to extend it easily without modifying the lib itself, because any collision detector must inherit from CollisionDetector but that class is not public so I cannot extend it without editing the lib, which will cause problems in future updates.

Also the world.add function allows to pass the shape as an string, but the possible values are hardcoded in a switch. I suggest to have a container to associate shape names with the class representing it.

I will make the changes myself but I dont feel confident enough yet.

Cheers

modularize, publish to npm

In the main example there are 17 script tags:
https://github.com/lo-th/Oimo.js/blob/master/index.html#L16-L32

That's not a great way for third parties to consume this library. It's common practice to generate a umd build so that people using module systems such as commonjs or AMD can require() this module and people not using any module system will still have their window globals as usual, but with only a single <script> tag to include.

Once the code has been modularized, you can generate a package.json file with npm, which ships by node.js by default. Just do:

npm init

And the command will walk you through filling out the right fields. You should point the "main" field at the singular entry point for this package, which could be a dist build since the internals aren't modularized yet. A really simple way to do this with what you've already got is just to cat together all the files necessary and then append some exports.FOO=... statements, at least for commonjs. Once the build works, just publish to npm with:

npm publish

You can test the build with a tool like browserify.

No air friction?

Hi:

All my spherical RigidBodies slide through the ground plane infinitely no matter what friction I put in the ground plane or the bodies. Is there a way to ensure they will stop? or to set up some kind of air friction.

Thanks

how to change ```move``` in a body

I created a body with { move: false } as parameter (so it isnt move by the physics)

later i would like to change this and start to make it move. how can i change that ?

Friction doesn't seem to work?

I have a plane and a sphere, both with a friction of 0.8. If I have the sphere be tossed on the plane, it will roll infinitely.

The friction doesn't appear to be slowing down the bodies even in the examples. Why is this ignored?

[dev] SliderJoint undefined property

Hey,

I'm using the dev version (1.1.0a), and noticed that when trying to use a SliderJoint, this property throws an error (since this.joint is undefined).

A fix for it would be to set this line to read:
this.type = this.JOINT_SLIDER;

I know the dev version is being worked on, so apologies if this is a pointless issue!

Cheers.

Terrain support?

Hi @lo-th
First, thank you for putting in the effort to port this awesome physics engine! I will definitely be using this as my go-to physics engine for Three.js games.

I have some ideas for games that require terrain-shape support. I would like to put in a feature request to add a terrain class. Do you know this engine well enough to add it yourself, or, if not, do you think the original author would be able to add it?

I guess what would be needed is a simple 2-d array of vertex points that form a grid in the x-z plane. The number of width (x) and depth (z) would be supplied by the developer. Then, for each point a height value (y) is given by the developer. This is where my knowledge gets thin. I'm supposing a series of triangles would have to be made, storing a normal for each triangle. Then, somehow every triangle would have to be tested against all spheres and/or boxes in the scene (using the existing sphere-plane and box-plane routines?) Then the intersection point would have to be tested to be inside the triangle. Finally, an impulse is added to the sphere/box like it would be for a plane, or floor (which is already a part of this engine).

Please let me know what you are willing/able to do with this request. I could try to do one myself, but I don't see any point-in-triangle routines in the library as of yet.

Again, thanks for this wonderful project! :)
-Erich

body.setRotation(mtx) don't work

setRotation:function(x,y,z){
var r = OIMO.EulerToAxis(x* OIMO.TO_RAD, y* OIMO.TO_RAD, z* OIMO.TO_RAD);
var rad = r[0];
var len = r[1]r[1]+r[2]r[2]+r[3]r[3];
if(len>0){
len=1/Math.sqrt(len);
r[1]
=len;
r[2]
=len;
r[3]
=len;
}
var sin=Math.sin(rad_0.5);
var cos=Math.cos(rad_0.5);

    //this.body.rotation = new OIMO.Quat(cos,sin*r[1],sin*r[2],sin*r[3]);
    this.orientation = new OIMO.Quat(cos,sin*r[1],sin*r[2],sin*r[3]);
    //this.orientation = new OIMO.Quat(r[0], r[1], r[2], r[3]);     
}

Step forward?

Hi @lo-th, is there a way to step forward?
I tried:
delay // milliseconds
var frames = Math.round(delay / 1000 * fps);
for(var i=0; i<frames; i++){
world.step();
}
updatePosition();

but doesn't seem to work. Any suggestion?
Thank you!

Setting a new position on a static body?

Hi, I've been scratching my head for a few hours trying various things and could not figure out why when I set a new position on a static (move:false) body, it wouldn't seem to take its place correctly.

I hacked through the OIMO source code and found a nifty little function that solved my issue, but it says in the comment there is no need to call from outside usually, so how is one supposed to set a new position on a static body without calling this and simulate for 1ms?

QUESTION #1 --> That's what I figured at the moment, am I doing it wrong? I'm doing this:

mybody.body.position.set(new_x, new_y, new_z);
mybody.body.updatePosition(1);

QUESTION #2 --> If I do that on many bodies, are the 1ms simulation happening on other bodies too? inb4 I test this myself thx :P

This is the function I found in the OIMO source code to make it work at the moment:

/** 
    * The time integration of the motion of a rigid body, you can update the information such as the shape. 
    * This method is invoked automatically when calling the step of the World, 
    * There is no need to call from outside usually. 
    * @param  timeStep time 
*/

updatePosition:function(timeStep){
    switch(this.type){
        case this.BODY_STATIC:
            this.linearVelocity.init();
            this.angularVelocity.init();
            // ONLY FOR TEST
            if(this.controlPos){
                this.position.copy(this.newPosition);
                this.controlPos = false;
            }
// --------------- ...ETC... --------------- 

Docs are broken

When viewing http://lo-th.github.io/Oimo.js/docs.html I get a console error:

Uncaught ReferenceError: isPlaying is not defined
    at Object.setPlay (editor.js:177)
    at Object.init (editor.js:171)
    at next (docs.js:72)
    at Object.load_next (view.js:569)
    at THREE.SEA3D.l.onComplete (view.js:588)
    at THREE.SEA3D.<anonymous> (sea3d.min.js:217)
    at SEA3D.File.dispatchComplete (sea3d.min.js:86)
    at SEA3D.File.readState (sea3d.min.js:85)

and no docs are displayed.

DEV vs REV

I can't find any mention in the docs of what the difference is. Can someone please share?

Is default scale 1 or 100?

The reason I ask is that Oimo.js has 100 as default scale, but the docs have 1. I can fix this and issue a pull request once I know what the default should be.

Collision Sounds?

Hi @lo-th and other contributors thank you for sharing this great physics engine, it seems to be very fast!. I have been enjoying playing around with the examples and wondered if there is any way to easily add sounds on collision of objects in Three.js scenes?

Changing the density of a shape doesn't work

Hi I'm trying to do a body wrapper for my WebGL engine but changing the density of the shape doesn't work but changing the restitution does. Can you guys help me please. Here is the class code.

EZ3.Body = function(world, type, position, size, rotation, move) {
  this._body = world.add({
    type: type,
    pos: position,
    size: size,
    rot: rotation,
    move: move,
    config: [
      40,
      1.9,
      0.2
    ]
  });

 this._body.shapes.density = 150;

  console.log(this._body.shapes.density); //150 but in the simulation still 40
};

Object.defineProperty(EZ3.Body.prototype, 'density', {
  get: function() {
    return this._body.shapes.density;
  },
  set: function(density) {
    this._body.shapes.density = density;
  }
});

Object.defineProperty(EZ3.Body.prototype, 'restitution', {
  get: function() {
    return this._body.shapes.restitution;
  },
  set: function(restitution) {
    this._body.shapes.restitution = restitution;
  }
});

Besides that, do you guys think that is necessary to support more than one shape per body ?. I saw Babylon.js code and I think it doesnt.

Greetings and thanks

getRotation?

i saw it mentioned in #10 that a getRotation() was being worked on for rigidbody, but don't see it in source anywhere....i want to use setRotation() to animate an object's rotation, but without getRotation() am not sure how to get the correct starting point. maybe there's another way to do that...?

anyways, been using oimo for a week and think this is great! thank you for all your work porting and maintaining :)

Triggers and Sensors?

Apologizes in advance for repeating myself, I'm just really looking forward to answer.

I'm continuing off of this issue here: #61

Thanks you for response. However, I fail to see how this answer my second part of my question: having the bodies behave like a trigger.

Is there a way, in that example, to have one of the spheres turn to the green material while passing through their box, respectively?

Imagine in a first person shooter the player walks through a doorway to go into a room full of monsters that spawn upon entering. In that door way as the player collided with a box trigger there was no actual collision but instead a callback/event for me to start spawning monsters. Make sense?

Is there a behavior like this available?

gravity

I'm playing around with some demos and see that there is a world gravity. I'm working on a project where different objects in the scene each require their own gravity - to either pull or push neighboring objects.

Is there a way to attract / repel rigid bodies based on gravity or will I have to calculate those forces outside of oimo?

Difference between .dev and .rev?

Hi again,
What are the basic differences between .dev and .rev? I noticed .rev had support for cylinder shapes where as .dev appears not to have the same support. I'm confused because isn't .dev supposed to be the latest (with ALL the features that are not found in older versions)?

Oimo.js is looking better and better each day! Keep up the great work!
Thanks,
-Erich

Elastic-like force to original position

I'm trying to reproduce something like this demo, applying a constant force in direction to original anchor position/rotation.

https://youtu.be/RLEEVGxu_k8?t=3m2s

It's more like the inverse of gravity, the larger the distance, larger the force, but have to slow down on the way back.

Do you have any idea how to achieve this? Working around to simulate it, like in the planet gravity demo?
Does Oimo.js have something like elastic force or constraint?

Error with world.step() function

Hi! I found a bug with the step() function in the oimo.world prototype.

Bodies which are asleep will not wake up if only their angular velocity has changed, because of what looks like a copying error near the top of the function. the offending chunk looks like this, and is easily fixed.

      if(tmpB.sleeping){
            var lv=tmpB.linearVelocity;
            var av=tmpB.linearVelocity; <------------------ this should be tmpB.angularVelocity
            var p=tmpB.position;
            var sp=tmpB.sleepPosition;
            var o=tmpB.orientation;
            var so=tmpB.sleepOrientation;
            if(
            lv.x!=0||lv.y!=0||lv.z!=0||
            av.x!=0||av.y!=0||av.z!=0||
            p.x!=sp.x||p.y!=sp.y||p.z!=sp.z||
            o.s!=so.s||o.x!=so.x||o.y!=so.y||o.z!=so.z
            ){
            tmpB.awake();
            continue;
            }

I have little experience with GitHub and pull-requests, but I aim to help build on this project, since it seems there are few if any contributors. If someone could help me get started with how to properly fork, get pull requests merged, etc. that'd be great! For starters i'm not sure if i'm supposed to fork the master or gh-pages branch, or if this even matters! I'm a noob with SVN stuff but I have a lot of experience with game engines and rigid body physics (i'm a mechanical engineering student, and have been programming for over a decade). I plan to possibly include support for more body shapes and possibly arbitrary meshes, as well as fix bugs and improve the overall quality of this physics engine, but i'd rather have my additions / fixes merged to the main project than keep them to myself so others could benefit. There really aren't any good js physics engines out there atm which aren't emscripten ports, and i feel i'd be helping a lot of people out by commiting things like this.

Reset the world without remove bodies?

Hi

I have setup a world with some bodies. I run this world and want to restart/reset the simulation without remove and recreate the world. Is this possible?

World properties

What do the different broadphase's mean, what does brute, sweep & prune, and volume tree do?

What does random do, what does adding a random number in the simulation mean?

An error in two or more shape

Hello.
An error comes out and I am troubled by the following codes.

When making rigidBody containing two or more shape(s), result becomes strange. if the angle of 90 degrees or more is specified.

Thank you

var pos = [0, 100, 0];
var rot = [90, 0, 0];//  <----- result becomes strange.
var bodyPos = getVec3(pos);
var bodyRot = getRotation(rot);
var body = new OIMO.RigidBody(
    bodyPos[0], bodyPos[1], bodyPos[2],
    bodyRot[0], bodyRot[1], bodyRot[2], bodyRot[3] 
);
world.addRigidBody(body);


function getVec3(vec){

    var pos = new OIMO.Vec3(vec[0], vec[1], vec[2]);
    pos.scale(pos, OIMO.INV_SCALE);
    return [pos.x, pos.y, pos.z];

}

function getRotation(rot){

    var rot = rot.map(function(x) { return x * OIMO.TO_RAD; });
    var tmp = OIMO.EulerToAxis(rot[0], rot[1], rot[2]);

    return tmp;
}



var shapes = [];

//create shape
var shape1 = getShape({
    type:'box',
    size:[100, 40, 400],
    position:[0, 0, 0],
    density:1
});
shapes.push(shape1);

//create shape
var shape2 = getShape({
    type:'box',
    size:[100, 100, 100],
    position:[0, 0, 100],
    rotation:[0, 45 * OIMO.TO_RAD, 0],
    density:1
});
shapes.push(shape2);

function getShape(){}//shape create func

var length = shapes.length;
for(var i = 0; i < length; i ++ ) body.addShape(shapes[i]);


body.setupMass(0x2, false);

test

adding a hollow cylinder as a body?

Hi

I have a bowl as a 3D model and try to add a hollow cylinder as a collision wall on the side. Is this possible? I don't want to add multiple boxes on the side of the bowl. Here are the sample:

image

How to apply force to a body?

for example, i want a ball move to right side,

and i have tried to use body.applyImpulse ({
x:0, y:0, z:100
}, 10);

unfortunately it dosen't work.

BTW: how to make a ball jump in this case?

oimo.module.js: OIMO is not defined

Hi,

I'm using the ES6 import from Oimo, and I'm getting an error that seems to be deep within the prebuilt oimo.module.js:

Uncaught ReferenceError: OIMO is not defined
    at eval (eval at evaluate (:117:21), <anonymous>:1:1)
    at BoxShape.updateProxy (http://192.168.128.125:8888/js/main.js:50564:13)
    at RigidBody.syncShapes (http://192.168.128.125:8888/js/main.js:54910:19)
    at RigidBody.setupMass (http://192.168.128.125:8888/js/main.js:54703:14)
    at World.add (http://192.168.128.125:8888/js/main.js:55873:22)
    ...

So my code clearly sees OIMO, and it's been included using Rollup+NodeResolve+CommonJS. But the Oimo code apparently is assuming an OIMO global variable, which doesn't exist.

A bit of grepping finds only one more place that an OIMO global is expected in oimo.module.js here:

if(r[n2+0]) {
	var q = new Quat().setFromAxis( r[n2], r[n2+1], r[n2+2], r[n2+3] );
	//var q = body.rotationAxisToQuad( r[0], r[1], r[2], r[3] );
	shapes[i].relativeRotation = new OIMO.Mat33().setQuat(q);
}

Looks like relatively simple fixes? For now I'm patching window.OIMO to point to OIMO.

Semantics / meaning of "kinematic"

Very nice work - I am using oimo.js for teaching my students in a graphics class.

Can you tell me the meaning and effect of marking a body as kinematic? So far I have not seen a difference between this and setting move == false.

Thank you.

Why are collision groups removed from "REV" version?

Collision groups don't seem to be present in REV version, in fact im quite confused what the difference between the REV and regular Oimo versions is. REV seems to have cylinder support but dev seems to have been modified most recently. What is the most up to date version of Oimo.js? why are there two different builds ??? And why are the features different between the builds, with some big things having been removed / not present in one file to the next?

Rotation funky when using low negative numbers

Hello

I have found some slightly odd behaviour with rotation of bodies, If you have a look at the link below you will see that when rotating the platform by -4 degrees the behaviour is as expected, but when rotating the platform by -3 to -1 degrees the platform rotates the opposite direction to what is expected.

http://www.pigloo.co.uk/oimo

var ground0 = world.add({size:[190, 40, 400], pos:[100,-20,0], rot:[-4,0,0], world:world});

// A look at 'ground0.rotation.elements' shows [1, -0, 0, 0, 0.9975640773773193, 0.06975647062063217, -0, -0.06975647062063217, 0.9975640773773193]

var ground1 = world.add({size:[190, 40, 400], pos:[-100,-20,0], rot:[-3,0,0], world:world});

// A look at 'ground1.rotation.elements' shows [1, 0, 0, 0, 0.9986295104026794, -0.0523359552025795, 0, 0.0523359552025795, 0.9986295104026794]

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.