Giter Site home page Giter Site logo

physijs's People

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

physijs's Issues

how to add physijs to js model ?

hi guys
i need add physijs to my game
this is my code
loader.load( "models/kaf.js", function(geometry) {
var part1 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial() );
mesh = new THREE.Object3D();
mesh.add( part1 );
//var mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0,80.10012515644638,0);
mesh.rotation.set(0,0,0);
mesh.scale.set(1,1,1);
scene.add( mesh );
});

terrain demo on top of cubicvr

[12:26am] ccliffe: heightfield demo with the latest ammo.js is up here now: http://cjcliffe.github.com/CubicVR.js/cubicvr/samples/physics/physics_heightfield.html
[12:26am] jetienne: ccliffe: nice how to handle the terrain in ammo.js ?
[12:26am] ccliffe: can add ?# to the URL as usual where # is the amount of objects to spawn for stress testing
[12:27am] ccliffe: jetienne: yup, btHeightfieldTerrainShape does the work
[12:28am] ccliffe: jetienne: this code starting here does the setup, works like any other collision shape: https://github.com/cjcliffe/CubicVR.js/blob/master/source/CubicVR.ScenePhysics.js#L193

Scaling objects doesnt scale their physijs size

var box = new Physijs.BoxMesh(new THREE.CubeGeometry(10, 10, 10));
box.scale.set(1000, 1000, 1000);

produces a 1000 by 1000 by 1000 box which acts like its 10 by 10 by 10 when collided with

Physijs.PlaneMesh seems to only support a flat mesh or I am an idiot

Hi,

Thanks again for this wicked API!

I'm progressing ever further in my helicopter game but I've hit a problem with my terrain physics.

I'm creating a THREE.PlaneGeometry and then setting the raw y position of its vertices in my createLandscape() function like so:

this.terrainGeometry = new THREE.PlaneGeometry(lightboxWidth /2,lightboxWidth /2, this.groundMeshSegments, this.groundMeshSegments);

    this.createLandscape();

    this.terrainGeometry.dynamic = true;
    this.terrainGeometry.__dirtyVertices = true;
    this.terrainGeometry.computeCentroids();

    // now wrap in a physics object after we've sculpted the mesh..
    this.terrain = new Physijs.PlaneMesh(
            this.terrainGeometry,
            ground_material, 0);

My Helicopter drops through the rendered terrain and hits what is y=0 on the x/z plane.

Is this a bug or am I doing something stupid?

p.s. I will publish the game soon, so will drop you a link - wouldnt be possible without you, Mr Doob and the bullet engine guy who's name escapes me.

Thanks

Custom mesh shapes

Custom geometries should use btBvhTriangleMeshShape for non-convex meshes and btConvexHullShape for convex meshes.

INVALID_STATE_ERR: DOM Exception 11

With Chrome 24.0.1312.14 beta I get the following error (Firefox 17 is fine, as is Chromium 20) from the Vehicle System example:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 /Physijs/physijs_worker.js:987
And the same one from a different line from the Constraints, Car example:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 /Physijs/physijs_worker.js:1018

They come from reportVehicles and reportConstraints transferableMessage call. Looking at the code a bit, it appears those functions do not have the SUPPORT_TRANSFERABLE code path that initializes the buffer - this seems like a good candidate for the culprit. Should be trivial to fix, but I leave it for you as I don't know the reporting system well and could introduce subtle bugs.

CCD support?

Looking at some of the demos, you don't seem to be using continuous collision detection (sweep-tests and the like), as moving a block quickly in the Jenga demo would cause it to pass through other blocks. Is this something you're planning on adding?

Exception when using PointConstraint

Adding a PointConstraint toe scene results in the following exception in physijs_worker.js:1006

Uncaught TypeError: Object #<F$> has no method 'getFrameOffsetA'

Not sure how to debug this.

using setAngularFactor

to lock down angular rotation, does setAngularFactor(new THREE.Vector3(0, 0, 0)) have to be called at every single frame? something tells me thats not right

Possible to attach a physics volume to a 'controllable' mesh?

Ok first off, great work.

I am trying out your work via tQuery from jeromeetienne.

I have the basic falling cubes demo working and I have combined it with a very simple car driving simulator (VERY SIMPLE).

How would I go about "attaching" a physics volume to the car in order to collide with the cubes that it touches? I am not talking about realistic car physics, just collisions with world objects.

Is this simple enough or am I missing the point entirely and it's impossible?

Excuse the newbie question but I love the idea of 3D in browser and if I can get simple collisions detected and reacted I can create the game for a client I have always wanted to do!

PlaneMesh Collisions

This may be expected behavior, but seemed worth a mention. If a BoxMesh face shares a plane with a PlaneMesh, then collisions are registered โ€” even if the two object do not overlap.

An example is available at http://eee-c.github.com/threejs-my/collision_test.html. In the JavaScript console, You can see that, even though no cube is touching the green plane at the start of the animation, a collision event with the plane is registered.

More details (way too many really) are available at: http://japhr.blogspot.com/2012/08/collision-events-in-physijs.html

Trouble with objects imported from Blender

Hi Chandler,
Big thanks to you for making Physijs and making it and the examples available to everyone!

I've been wrestling with trying to build objects in Blender and use them with Physijs.

I've exported and loaded into my scene one of the objects that I've built in blender. It's just a blue horizontal thin BoxMesh.

I've also created a green ground using a Physijs.BoxMesh and 2 red balls using Physijs.SphereMesh.

I've set the scene so that one ball should fall onto the loaded Blender object and one should fall onto the ground. I've added some positive z gravity to make the balls roll across the ground and fall off the edge.

What I'm seeing is that the ground looks to be behaving just fine. Once the balls hit it, they roll across it to the edge and fall off.

But, the ball that should hit the blue loaded Blender object passes right through it and hits the ground. The ball that should fall directly to the ground hits something invisible at the same height as the Blender object rolls off and then onto the ground.

I have __dirtyPosition and __dirtyRotation set to true for all objects just before adding them to the scene.

I change the rotation.y and position of the Blender object before setting __dirtyPosition and __dirtyRotation to true. I had a .scale.set(14,14,14); for the blender object before. But after reading the Wiki section "Why can't I scale objects?" I scaled the object in Blender and exported it so I could remove the scale.set line. (It does make working with the objects in Blender a bit of a pain, if there is a different approach that you know of, that would be great.)

Here's the link to the example I put together. Am I doing something obvious that is causing the issue?

http://bittyb.atwebpages.com/

And the link to the exported Blender object

http://bittyb.atwebpages.com/js/rightdesktops14.js

The basic shapes wiki page contains misleading information

It says "There is one additional parameter you can pass to the add method: a callback. This callback function will be called when your mesh has been added to the physics simulation." It is wrong, as it doesn't work as intended.

The proper way I've discovered in samples is to addEventListener('ready') to the mesh before adding it to scene.

Detecting collisions

Need to have code for detecting collisions.
I have something like this:

function findCollision() {
var dp = dynamicsWorld.getDispatcher();
var num = dp.getNumManifolds()
for (var i = 0; i < num; i++) {
var man = dp.getManifoldByIndexInternal(i);
if (man.getNumContacts() == 0) continue;
if (bodies[0].a == man.getBody0() || bodies[0].a == man.getBody1()) {
// bodies[0] has collision
}
}
}

applyImpulse relative to object

First, awesome job on this library, very easy to use.

And second, a question/feature request: I have been playing around with applying an impulse on an object with applyCentralImpulse(). I am applying a positive impulse on the Y axis like rocket.applyCentralImpulse(new THREE.Vector3(0, 1e3, 0)). This is the rocket taking off. But then I rotate my rocket on the Z axis, and I want to apply the same impulse, but now propel my rocket in the direction it is facing (instead of just up on the Y world axis). In other words, I want to propel my rocket on it's own Y axis.

I'm new to matrices and physics in general, but I have some idea that I need to take my force vector and somehow convert that into my objects direction vector (maybe the cross product of my direction and force vectors?). It doesn't appear there is a ready-made function to apply an impulse to an object relative to it's own XYZ, but maybe you could point me in the right direction as to how one would accomplish this?

setGravity doesn't work

I have the following code setting up my scene:

var scene = new Physijs.Scene();
scene.setGravity(0, 0, -10);

Yet all of my objects still fall along the Y axis. What am I doing wrong?

Physijs with TextGeometry elements

Hello,

first of all, thank you for this amazing plugin !

I'm doing a job for school where I would need to animate Typography in 3D. I tried to animate a TextGeometry element with threejs + physijs and the results are quite unexpected.

You can look at it here: http://minguely.ch/three/

Have I done something wrong, or the plugin, in its state, just can't manager Text element?

Thanks in advance !

Julien

Make the physics objects more like promises

Currently, if you call setAngularFactor before adding the object to the scene it will have no effect. This should be changed so that all of the calls will be applied as soon as the object is added.

collision event on Physijs children

lets say you have a physijs cube made out of 6 physijs planes and a physijs sphere inside the cube. if you shake the cube, every time the sphere hits the inside face of the cube, a collision callback happens, but only if the sphere doesnt touch the cube again between collisions. so if the sphere rolls into a corner, no collision callback happens, as it never lost contact with the surface it was rolling on.

this could be fixed if the collision callback reset were dependent on a physijs child as opposed to the physijs object itself

mesh passing through other meshes

Hi, here is a bug I've seen on the game I'm currently working on:

http://www.youtube.com/watch?v=cAASoY_G1ZI&t=3m20s
http://www.youtube.com/watch?v=cAASoY_G1ZI&t=5m15s
http://www.youtube.com/watch?v=cAASoY_G1ZI&t=6m7s

Sometime (don't really know when), the marble will stop colliding with nails.

Here is the game repo:

https://github.com/yazgoo/nails_n_wood

If you wan't to try it, there's an instance (I used map s1 for my tests):

http://naw1-yazgoo.rhcloud.com/

Here is where the marble is initialized (yes, I use a BoxMesh since I didn't manage to have the SphereMesh work (but that's another problem)):

https://github.com/yazgoo/nails_n_wood/blob/master/js/game.js#L105

I initialized the nails here:

https://github.com/yazgoo/nails_n_wood/blob/master/js/game.js#L144

I'm using a Physi.js from september the 15th I think, please tell me if you think I should use another
version.

Oh, worth noticing: since I only need 2D simulation, I force z to 10 in render loops:

https://github.com/yazgoo/nails_n_wood/blob/master/js/game.js#L204

applyForce()

The short version: I am accelerating an object using applyImpulse() and then trying to slow it down by turning the object around and accelerating again, but it just makes it go faster in whichever direction it was going. I'm wondering if something like applyForce() would be more appropriate and not result in strange behavior like this and if applyForce() could be put into Physijs.

The code:

// applying the impulse for forward acceleration
ship.applyCentralImpulse(ship.matrix.multiplyVector3(new THREE.Vector3(0, 10, 0)));

// rotate the ship clockwise
ship.applyImpulse(
                ship.matrix.multiplyVector3(new THREE.Vector3(10, 0, 0)),
                ship.matrix.multiplyVector3(new THREE.Vector3(0, 1, 0))
);
ship.applyImpulse(
                ship.matrix.multiplyVector3(new THREE.Vector3(-10, 0, 0)),
                ship.matrix.multiplyVector3(new THREE.Vector3(0, -1, 0))
);

Some background:
I'm working on a scene where I have a space ship. I'm using applyCentralImpulse() currently to apply a force to this ship every 100 milleseconds when the spacebar is pressed to simulate a rocket engine propelling the space ship forward. I have set gravity to Vector3(0, 0, 0), and I have made controls to turn the space ship using two applyImpulse() commands with a small offset to rotate the ship. This is all in the x, y, and I'm not worrying about z (other than setting the ships z position to always be 0).

Everything works as expected until the ship get's going too fast (in my case about 1000 in the Y direction). When I try to turn the ship around and applyCentralImpulse() now in the -Y direction, it just accelerates more in the Y direction. If the ship is going slow enough I can turn it in any direction and get it to slow down.

Reading through the documentation for ammo.js and specifically the Bullet physics engine, it seems like what I should be doing is an applyForce(). I'm wondering if applyImpulse is actually the wrong thing for me to do in this scenario and because of something about that function that I don't understand, I'm seeing really strange results.

(I also notice that when I rotate the ship while going fast, the rotation actually makes the ship go even faster while also rotating it.)

Could applyForce() be implemented in Physijs? It seemed a little bit different than applyImpulse, which is a one-time thing, and that with applyForce you had to be more connected with the time-cycle of the physics simulation, and give a time over which to apply the force--so maybe that makes it more difficult to easily port to be used within Three.js.

Anyway.... I'd really like to find a solution to this and can't seem to do so with the current tools and my understanding.

(Btw--I've also tried just multiplying the the ship's position vector by a scalar to simulate acceleration, but that has funny results as well.)

Quick way to add multiple of the same exact mesh?

I have a scene where I am trying to simulate dice rolling. The dice are custom models using the ConvexMeshes using the FaceMaterial. They are fairly complicated, with around 2,000 vertices. Loading them into THREE.js and adding them to the scene goes quickly (I can add 10 in around 100ms). However, there is a long delay between when they are added to the scene and when the "ready" event is triggered on the shape by Physijs. During that time I can see them on the screen, but they are simply static. It takes around 200ms or so for each mesh (so doing 1 mesh is reasonable, doing 10 or 15 is not). I assume this is the setup time it takes to perform calculations on the complicated mesh.

Since these are exactly the same model/mesh/material, is there an easy way to let Physijs only do that work once and then re-use it?

If that's not possible, what's the best way to see some gain in speed for the initial setup? Reduce the number of vertices?

improved collision callback

can lines 275 and 278 of physi.js be changed to

_temp1 = _temp_vector3_1.clone();
_temp2 = _temp_vector3_1.clone();

from

_temp1 = _temp_vector3_1.length();
_temp2 = _temp_vector3_1.length();

this adds a lot more flexibility and control to the collision event callback

REQUEST: Feature ideas for forthcoming vehicle physics system...

Hey @chandlerprall

You may have already thought of these before but as someone who is very interested in the possibility of your proposed vehicle physics and a casual game developer I thought I'd share some suggestions with you based on the questions I've asked of other physics systems (as I am not up to coding one myself):

Articulation - for simple lorry/trailer action
More than 4 wheels - say a six wheeled ATV or a lorry
Rear-wheel turn - forklift trucks etc.
Different sized wheels - like on a tractor

As I mentioned earlier I would be happy to help test and provide models and 'situations' to help develop this system what you've created so far appears very simple to use - this could be a good one!

p.s. hope development is going well

obsolete code in Physijs.ConvexMesh ?

in both case the code seems to be the same, no ?

            if ( THREE_REVISION >= 49 ) {
                points.push({
                    x: geometry.vertices[i].x,
                    y: geometry.vertices[i].y,
                    z: geometry.vertices[i].z,
                });
            } else {
                points.push({
                    x: geometry.vertices[i].x,
                    y: geometry.vertices[i].y,
                    z: geometry.vertices[i].z,
                });

            }

Setting relative angular velocity

I can't seem to get setting angular velocity relative to current position and rotation to work. Below is some of the code that I have:

var zeroV = new THREE.Vector3(0,0,0);
var camVector = zeroV;

function projCalc(thetax, thetay, thetaz, cx, cy, cz, dx, dy, dz) {
    var M1 = $M([
        [1, 0, 0],
        [0, Math.cos(thetax), -1*Math.sin(thetax)],
        [0, Math.sin(thetax), Math.cos(thetax)]
    ]);
    var M2 = $M([
        [Math.cos(thetay), 0, Math.sin(thetay)],
        [0, 1, 0],
        [-1*Math.sin(thetay), 0, Math.cos(thetay)]
    ]);
    var M3 = $M([
        [Math.cos(thetaz), -1*Math.sin(thetaz), 0],
        [Math.sin(thetaz), Math.cos(thetaz), 0],
        [0, 0, 1]
    ]);
    var C = $M([
        [cx],
        [cy],
        [cz]
    ]);
    var D = $M([
        [dx],
        [dy],
        [dz]
    ])

    var M123 = M1.x(M2).x(M3);
    var M123inv = M123.inv();
    var result1 = M123.x(C).add(D);
    var result2 = M123inv.x(result1);
    return result2;
}

var otherEnd = projCalc(rotx, roty, rotz, camx, camy, camz, -1, 0, 0);
var unitVX = (otherEnd.elements[0][0] - camx);
var unitVY = (otherEnd.elements[1][0] - camy);
var unitVZ = (otherEnd.elements[2][0] - camz);
camVector.x = unitVX;
camVector.y = unitVY;
camVector.z = unitVZ;

camera.physics.setAngularVelocity(camVector);

camx, y, z is the position of the object that is going to be given the angular velocity

rotx, y, z is the current rotation of the object that is going to be given the angular velocity

and -1, 0, 0 is the relative axis of rotation

all projCalc() does is give the point that is (-1,0,0) in the relative space in the global coordinate plane (I used Sylvester to do the matrix math)

But whenever I try to set the angular velocity, it only works properly when the rotation is around 0 otherwise it is horribly wrong.

If there is an easier way to do this, that would be helpful! As a side note, it would be awesome if there could be a relative setAngularVelocity and getAngularVelocity in Physijs so that velocities could be changed relative to an objects current rotation.

Thanks

P.S. These are just code snippets above. My init and animate functions work just fine so that is not one of my issues.

Drag / air resistance possible?

Hi,

I'm using Physijs for my camera system. It is basically a camera attached to an invisible cube that collides with static objects. It is to prevent users from flying through geometry. The scene has no gravity. It all works fine but I want to apply air resistance to my object so that the camera slows down over time and eventually stops. The camera/cube currently just keeps flying. Is it possible to do this?

observed strange restitution

  • a sphere on a ground seems not to restitute all
  • even if the ground for a restitution of 1 and the sphere a resittution of 1 too

fps measurement in worker ?

  • currently when the worker is overloaded and cant produce one output per renderer frame
  • it is impossible to do
  • possibily provide a fps measure of that in a stat.js i dunno

Fixing the demo

I had to change the lines 19 and 20 in the html files of the demos to the following to make it work:

Physijs.scripts.worker = 'js/physijs_worker.js';
Physijs.scripts.ammo = 'ammo.js';

Did I miss anything?

Thanks,
Behzad

Compound Objects - Rotating Child Objects

Hi,

I don't think I'm doing anything wrong when building my compound objects.

If I offset the position of a child object and add to the parent, the physics engine runs smoothy.

However when I attempt to rotate a child object, the physics engine behaves as if the rotation had not happened but visually, the object is rendered with the expected rotation.

Is this possibly a bug?

Also, many thanks for this wonderful library - it has made building a browser based game very simple so far!

Disabling Gravity

Hello!
Nice plugin,
I have one simply question. How can i disable gravity?

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.