Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a6b25cb
Add OrbitControls and use Y up coordinate system
marcofugaro Jun 17, 2020
7ad737d
Update some examples to ES6
marcofugaro Jun 17, 2020
97ea5f0
More ES6 conversion, updated 30% of examples
marcofugaro Jun 18, 2020
e58daea
Conovert some more examples to es6
marcofugaro Jun 22, 2020
6afcb58
Clean ragdoll and raycastVehicle examples
marcofugaro Jul 3, 2020
2564340
Rotate vehicle
marcofugaro Jul 3, 2020
36d3951
Clean up rigidVehicle
marcofugaro Jul 3, 2020
c42e4fd
Rotate rigidVehicle
marcofugaro Jul 5, 2020
adbf468
Auto-generate index.html examples and add source button
marcofugaro Jul 5, 2020
1e52840
🧹 Clean more examples
marcofugaro Jul 19, 2020
0170057
Clean trimesh and tween examples
marcofugaro Jul 20, 2020
58e63c6
Clean up two more examples
marcofugaro Aug 1, 2020
02ecf69
Clean up threejs_fps
marcofugaro Aug 21, 2020
ea37b5f
🧹 Clean up threejs_mousepick
marcofugaro Sep 2, 2020
d562ef7
Clean up threejs_voxel_fps
marcofugaro Sep 2, 2020
7de68d3
🧹 Cleanup worker.html
marcofugaro Sep 28, 2020
60a24a0
Clean up Demo.js
marcofugaro Nov 10, 2020
b2e0435
Clean up titles
marcofugaro Nov 10, 2020
51c30c7
Introduce three-conversion-utils.js
marcofugaro Nov 11, 2020
6d925a2
Fix syntax
marcofugaro Nov 11, 2020
df6563e
Clean up canvas_interpolation
marcofugaro Nov 13, 2020
ef282f5
Upgrade three.js version
marcofugaro Nov 13, 2020
1e0ac59
📖 Better comments and descriptions in examples
marcofugaro Nov 15, 2020
c25d13c
Use BufferGemetries in some examples
marcofugaro Nov 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions dist/cannon-es.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6723,9 +6723,9 @@ class RaycastVehicle {
this.wheelInfos = [];
this.sliding = false;
this.world = null;
this.indexRightAxis = typeof options.indexRightAxis !== 'undefined' ? options.indexRightAxis : 1;
this.indexRightAxis = typeof options.indexRightAxis !== 'undefined' ? options.indexRightAxis : 2;
this.indexForwardAxis = typeof options.indexForwardAxis !== 'undefined' ? options.indexForwardAxis : 0;
this.indexUpAxis = typeof options.indexUpAxis !== 'undefined' ? options.indexUpAxis : 2;
this.indexUpAxis = typeof options.indexUpAxis !== 'undefined' ? options.indexUpAxis : 1;
this.constraints = [];

this.preStepCallback = () => {};
Expand Down Expand Up @@ -7366,7 +7366,7 @@ class RigidVehicle {
// No chassis body given. Create it!
this.chassisBody = new Body({
mass: 1,
shape: new Box(new Vec3(5, 2, 0.5))
shape: new Box(new Vec3(5, 0.5, 2))
});
}

Expand Down Expand Up @@ -7407,7 +7407,7 @@ class RigidVehicle {
this.chassisBody.pointToWorldFrame(position, worldPosition);
wheelBody.position.set(worldPosition.x, worldPosition.y, worldPosition.z); // Constrain wheel

const axis = typeof options.axis !== 'undefined' ? options.axis.clone() : new Vec3(0, 1, 0);
const axis = typeof options.axis !== 'undefined' ? options.axis.clone() : new Vec3(0, 0, 1);
this.wheelAxes.push(axis);
const hingeConstraint = new HingeConstraint(this.chassisBody, wheelBody, {
pivotA: position,
Expand All @@ -7434,8 +7434,8 @@ class RigidVehicle {
const c = Math.cos(value);
const s = Math.sin(value);
const x = axis.x;
const y = axis.y;
this.constraints[wheelIndex].axisA.set(c * x - s * y, s * x + c * y, 0);
const z = axis.z;
this.constraints[wheelIndex].axisA.set(-c * x + s * z, 0, s * x + c * z);
}
/**
* Set the target rotational speed of the hinge constraint.
Expand Down Expand Up @@ -9127,7 +9127,7 @@ class Trimesh extends Shape {
const n = this.vertices.length / 3,
verts = this.vertices;
const minx,miny,minz,maxx,maxy,maxz;
const v = tempWorldVertex;
const v = tempWorldVertex;
for(let i=0; i<n; i++){
this.getVertex(i, v);
quat.vmult(v, v);
Expand All @@ -9137,12 +9137,12 @@ class Trimesh extends Shape {
} else if(v.x > maxx || maxx===undefined){
maxx = v.x;
}
if (v.y < miny || miny===undefined){
if (v.y < miny || miny===undefined){
miny = v.y;
} else if(v.y > maxy || maxy===undefined){
maxy = v.y;
}
if (v.z < minz || minz===undefined){
if (v.z < minz || minz===undefined){
minz = v.z;
} else if(v.z > maxz || maxz===undefined){
maxz = v.z;
Expand Down
18 changes: 9 additions & 9 deletions dist/cannon-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -6719,9 +6719,9 @@ class RaycastVehicle {
this.wheelInfos = [];
this.sliding = false;
this.world = null;
this.indexRightAxis = typeof options.indexRightAxis !== 'undefined' ? options.indexRightAxis : 1;
this.indexRightAxis = typeof options.indexRightAxis !== 'undefined' ? options.indexRightAxis : 2;
this.indexForwardAxis = typeof options.indexForwardAxis !== 'undefined' ? options.indexForwardAxis : 0;
this.indexUpAxis = typeof options.indexUpAxis !== 'undefined' ? options.indexUpAxis : 2;
this.indexUpAxis = typeof options.indexUpAxis !== 'undefined' ? options.indexUpAxis : 1;
this.constraints = [];

this.preStepCallback = () => {};
Expand Down Expand Up @@ -7362,7 +7362,7 @@ class RigidVehicle {
// No chassis body given. Create it!
this.chassisBody = new Body({
mass: 1,
shape: new Box(new Vec3(5, 2, 0.5))
shape: new Box(new Vec3(5, 0.5, 2))
});
}

Expand Down Expand Up @@ -7403,7 +7403,7 @@ class RigidVehicle {
this.chassisBody.pointToWorldFrame(position, worldPosition);
wheelBody.position.set(worldPosition.x, worldPosition.y, worldPosition.z); // Constrain wheel

const axis = typeof options.axis !== 'undefined' ? options.axis.clone() : new Vec3(0, 1, 0);
const axis = typeof options.axis !== 'undefined' ? options.axis.clone() : new Vec3(0, 0, 1);
this.wheelAxes.push(axis);
const hingeConstraint = new HingeConstraint(this.chassisBody, wheelBody, {
pivotA: position,
Expand All @@ -7430,8 +7430,8 @@ class RigidVehicle {
const c = Math.cos(value);
const s = Math.sin(value);
const x = axis.x;
const y = axis.y;
this.constraints[wheelIndex].axisA.set(c * x - s * y, s * x + c * y, 0);
const z = axis.z;
this.constraints[wheelIndex].axisA.set(-c * x + s * z, 0, s * x + c * z);
}
/**
* Set the target rotational speed of the hinge constraint.
Expand Down Expand Up @@ -9123,7 +9123,7 @@ class Trimesh extends Shape {
const n = this.vertices.length / 3,
verts = this.vertices;
const minx,miny,minz,maxx,maxy,maxz;
const v = tempWorldVertex;
const v = tempWorldVertex;
for(let i=0; i<n; i++){
this.getVertex(i, v);
quat.vmult(v, v);
Expand All @@ -9133,12 +9133,12 @@ class Trimesh extends Shape {
} else if(v.x > maxx || maxx===undefined){
maxx = v.x;
}
if (v.y < miny || miny===undefined){
if (v.y < miny || miny===undefined){
miny = v.y;
} else if(v.y > maxy || maxy===undefined){
maxy = v.y;
}
if (v.z < minz || minz===undefined){
if (v.z < minz || minz===undefined){
minz = v.z;
} else if(v.z > maxz || maxz===undefined){
maxz = v.z;
Expand Down
85 changes: 0 additions & 85 deletions examples/bodyTypes.html

This file was deleted.

85 changes: 85 additions & 0 deletions examples/body_types.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>cannon.js - body types demo</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
</head>
<body>
<script type="module">
import * as CANNON from '../dist/cannon-es.js'
import { Demo } from './js/Demo.js'

/**
* Demos of the Body.type types.
*/

const demo = new Demo()

demo.addScene('Moving box', () => {
const world = setupWorld(demo)

const size = 2

// Kinematic Box
// Does only collide with dynamic bodies, but does not respond to any force.
// Its movement can be controlled by setting its velocity.
const boxShape = new CANNON.Box(new CANNON.Vec3(size, size, size))
const boxBody = new CANNON.Body({
mass: 0,
type: CANNON.Body.KINEMATIC,
position: new CANNON.Vec3(0, size * 0.5, 0),
})
boxBody.addShape(boxShape)
world.addBody(boxBody)
demo.addVisual(boxBody)

// To control the box movement we must set its velocity
boxBody.velocity.set(0, 5, 0)
setInterval(() => {
if (boxBody.velocity.y < 0) {
boxBody.velocity.set(0, 5, 0)
} else {
boxBody.velocity.set(0, -5, 0)
}
}, 1000)

// Dynamic Sphere
// Dynamic bodies can collide with bodies of all other types.
const sphereShape = new CANNON.Sphere(size)
const sphereBody = new CANNON.Body({
mass: 5,
position: new CANNON.Vec3(0, size * 3, 0),
})
sphereBody.addShape(sphereShape)
world.addBody(sphereBody)
demo.addVisual(sphereBody)
})

demo.start()

function setupWorld(demo) {
const world = demo.getWorld()
world.gravity.set(0, -40, 0)

// Tweak contact properties.
// Contact stiffness - use to make softer/harder contacts
world.defaultContactMaterial.contactEquationStiffness = 1e8

// Stabilization time in number of timesteps
world.defaultContactMaterial.contactEquationRelaxation = 10

// Static ground plane
const groundShape = new CANNON.Plane()
const groundBody = new CANNON.Body({ mass: 0 })
groundBody.addShape(groundShape)
groundBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0)
world.addBody(groundBody)
demo.addVisual(groundBody)

return world
}
</script>
</body>
</html>
Loading