Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions dist/cannon-es-debugger.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ function cannonDebugger(scene, bodies, options = {}) {

const _planeGeometry = new three.PlaneGeometry(10, 10, 10, 10);

const _cylinderGeometry = new three.CylinderGeometry(0.5, 0.5, 1, 32);

function createConvexPolyhedronGeometry(shape) {
const geometry = new three.Geometry();
shape.vertices.forEach(({
Expand Down Expand Up @@ -128,7 +126,9 @@ function cannonDebugger(scene, bodies, options = {}) {

case CYLINDER:
{
mesh = new three.Mesh(_cylinderGeometry, _material);
const geometry = new three.CylinderGeometry(shape.radiusTop, shape.radiusBottom, shape.height, shape.numSegments);
mesh = new three.Mesh(geometry, _material);
shape.geometryId = geometry.id;
break;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ function cannonDebugger(scene, bodies, options = {}) {
const {
geometry
} = mesh;
return geometry instanceof three.SphereGeometry && shape.type === cannonEs.Shape.types.SPHERE || geometry instanceof three.BoxGeometry && shape.type === cannonEs.Shape.types.BOX || geometry instanceof three.PlaneGeometry && shape.type === cannonEs.Shape.types.PLANE || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.CONVEXPOLYHEDRON || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.TRIMESH || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.HEIGHTFIELD;
return geometry instanceof three.SphereGeometry && shape.type === cannonEs.Shape.types.SPHERE || geometry instanceof three.BoxGeometry && shape.type === cannonEs.Shape.types.BOX || geometry instanceof three.PlaneGeometry && shape.type === cannonEs.Shape.types.PLANE || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.CYLINDER || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.CONVEXPOLYHEDRON || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.TRIMESH || geometry.id === shape.geometryId && shape.type === cannonEs.Shape.types.HEIGHTFIELD;
}

function updateMesh(index, shape) {
Expand Down Expand Up @@ -261,9 +261,12 @@ function cannonDebugger(scene, bodies, options = {}) {
const mesh = meshes[meshIndex];

if (mesh) {
// Get world position
body.quaternion.vmult(body.shapeOffsets[i], shapeWorldPosition);
body.position.vadd(shapeWorldPosition, shapeWorldPosition);
body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion);
body.position.vadd(shapeWorldPosition, shapeWorldPosition); // Get world quaternion

body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion); // Copy to meshes

mesh.position.copy(shapeWorldPosition);
mesh.quaternion.copy(shapeWorldQuaternion);

Expand Down
17 changes: 10 additions & 7 deletions dist/cannon-es-debugger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vec3, Quaternion, Shape } from 'cannon-es';
import { MeshBasicMaterial, SphereGeometry, BoxGeometry, PlaneGeometry, CylinderGeometry, Mesh, Geometry, Vector3, Face3 } from 'three';
import { MeshBasicMaterial, SphereGeometry, BoxGeometry, PlaneGeometry, Mesh, CylinderGeometry, Geometry, Vector3, Face3 } from 'three';

function cannonDebugger(scene, bodies, options = {}) {
var _options$color;
Expand All @@ -25,8 +25,6 @@ function cannonDebugger(scene, bodies, options = {}) {

const _planeGeometry = new PlaneGeometry(10, 10, 10, 10);

const _cylinderGeometry = new CylinderGeometry(0.5, 0.5, 1, 32);

function createConvexPolyhedronGeometry(shape) {
const geometry = new Geometry();
shape.vertices.forEach(({
Expand Down Expand Up @@ -126,7 +124,9 @@ function cannonDebugger(scene, bodies, options = {}) {

case CYLINDER:
{
mesh = new Mesh(_cylinderGeometry, _material);
const geometry = new CylinderGeometry(shape.radiusTop, shape.radiusBottom, shape.height, shape.numSegments);
mesh = new Mesh(geometry, _material);
shape.geometryId = geometry.id;
break;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ function cannonDebugger(scene, bodies, options = {}) {
const {
geometry
} = mesh;
return geometry instanceof SphereGeometry && shape.type === Shape.types.SPHERE || geometry instanceof BoxGeometry && shape.type === Shape.types.BOX || geometry instanceof PlaneGeometry && shape.type === Shape.types.PLANE || geometry.id === shape.geometryId && shape.type === Shape.types.CONVEXPOLYHEDRON || geometry.id === shape.geometryId && shape.type === Shape.types.TRIMESH || geometry.id === shape.geometryId && shape.type === Shape.types.HEIGHTFIELD;
return geometry instanceof SphereGeometry && shape.type === Shape.types.SPHERE || geometry instanceof BoxGeometry && shape.type === Shape.types.BOX || geometry instanceof PlaneGeometry && shape.type === Shape.types.PLANE || geometry.id === shape.geometryId && shape.type === Shape.types.CYLINDER || geometry.id === shape.geometryId && shape.type === Shape.types.CONVEXPOLYHEDRON || geometry.id === shape.geometryId && shape.type === Shape.types.TRIMESH || geometry.id === shape.geometryId && shape.type === Shape.types.HEIGHTFIELD;
}

function updateMesh(index, shape) {
Expand Down Expand Up @@ -259,9 +259,12 @@ function cannonDebugger(scene, bodies, options = {}) {
const mesh = meshes[meshIndex];

if (mesh) {
// Get world position
body.quaternion.vmult(body.shapeOffsets[i], shapeWorldPosition);
body.position.vadd(shapeWorldPosition, shapeWorldPosition);
body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion);
body.position.vadd(shapeWorldPosition, shapeWorldPosition); // Get world quaternion

body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion); // Copy to meshes

mesh.position.copy(shapeWorldPosition);
mesh.quaternion.copy(shapeWorldQuaternion);

Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"typegen": "tsc --outFile dist/cannon-es-debugger.d.ts"
},
"peerDependencies": {
"cannon-es": "^0.15.1",
"three": "^0.118.3",
"cannon-es": "0.x.x",
"three": "<=0.124.0",
"typescript": ">=3.8"
},
"peerDependenciesMeta": {
Expand All @@ -37,17 +37,17 @@
}
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/preset-typescript": "^7.10.4",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-node-resolve": "^9.0.0",
"cannon-es": "^0.15.1",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-typescript": "^7.12.7",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-node-resolve": "^11.1.0",
"cannon-es": "^0.16.0",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.28.1",
"three": "^0.118.3",
"typescript": "^3.9.6"
"rollup": "^2.36.1",
"three": "^0.124.0",
"typescript": "^4.1.3"
}
}
17 changes: 15 additions & 2 deletions src/cannon-es-debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Heightfield,
Shape,
Quaternion as CannonQuaternion,
Cylinder,
} from 'cannon-es'
import {
MeshBasicMaterial,
Expand Down Expand Up @@ -41,7 +42,6 @@ export default function cannonDebugger(scene: Scene, bodies: Body[], options: De
const _sphereGeometry = new SphereGeometry(1)
const _boxGeometry = new BoxGeometry(1, 1, 1)
const _planeGeometry = new PlaneGeometry(10, 10, 10, 10)
const _cylinderGeometry = new CylinderGeometry(0.5, 0.5, 1, 32)

function createConvexPolyhedronGeometry(shape: ConvexPolyhedron): Geometry {
const geometry = new Geometry()
Expand Down Expand Up @@ -134,7 +134,14 @@ export default function cannonDebugger(scene: Scene, bodies: Body[], options: De
}

case CYLINDER: {
mesh = new Mesh(_cylinderGeometry, _material)
const geometry = new CylinderGeometry(
(shape as Cylinder).radiusTop,
(shape as Cylinder).radiusBottom,
(shape as Cylinder).height,
(shape as Cylinder).numSegments
)
mesh = new Mesh(geometry, _material)
;(shape as ComplexShape).geometryId = geometry.id
break
}

Expand Down Expand Up @@ -217,6 +224,7 @@ export default function cannonDebugger(scene: Scene, bodies: Body[], options: De
(geometry instanceof SphereGeometry && shape.type === Shape.types.SPHERE) ||
(geometry instanceof BoxGeometry && shape.type === Shape.types.BOX) ||
(geometry instanceof PlaneGeometry && shape.type === Shape.types.PLANE) ||
(geometry.id === (shape as ComplexShape).geometryId && shape.type === Shape.types.CYLINDER) ||
(geometry.id === (shape as ComplexShape).geometryId && shape.type === Shape.types.CONVEXPOLYHEDRON) ||
(geometry.id === (shape as ComplexShape).geometryId && shape.type === Shape.types.TRIMESH) ||
(geometry.id === (shape as ComplexShape).geometryId && shape.type === Shape.types.HEIGHTFIELD)
Expand Down Expand Up @@ -254,9 +262,14 @@ export default function cannonDebugger(scene: Scene, bodies: Body[], options: De
const mesh = meshes[meshIndex]

if (mesh) {
// Get world position
body.quaternion.vmult(body.shapeOffsets[i], shapeWorldPosition)
body.position.vadd(shapeWorldPosition, shapeWorldPosition)

// Get world quaternion
body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion)

// Copy to meshes
mesh.position.copy((shapeWorldPosition as unknown) as ThreeVector3)
mesh.quaternion.copy((shapeWorldQuaternion as unknown) as ThreeQuaternion)

Expand Down
Loading