Skip to content

Commit

Permalink
Remove legacy Geometry support
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Jan 3, 2024
1 parent 7de764a commit f62a58e
Show file tree
Hide file tree
Showing 5 changed files with 731 additions and 462 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [18.x, 20.x]

env:
CI: true
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"scripts": {
"dist": "microbundle --format cjs,esm,modern,umd --no-compress --globals three=THREE --external three",
"watch": "microbundle watch --format cjs,esm,modern,umd --no-compress --globals three=THREE --external three",
"test": "ava test/*.test.ts",
"coverage": "c8 --reporter=lcov --reporter=text ava test/*.ts --tap",
"test": "ava --no-worker-threads test/*.test.ts",
"coverage": "c8 --reporter=lcov --reporter=text ava --no-worker-threads test/*.ts --tap",
"coverage:report": "c8 report --reporter=text-lcov > coverage/coverage.lcov",
"preversion": "rimraf dist/* && npm run dist && npm test",
"postversion": "git push && git push --tags && npm publish && yarn coverage:report",
Expand Down Expand Up @@ -45,20 +45,20 @@
"three": ">=0.125.x"
},
"dependencies": {
"@types/three": ">=0.142.0"
"@types/three": ">=0.160.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"ava": "5.3.1",
"@typescript-eslint/eslint-plugin": "6.17.0",
"@typescript-eslint/parser": "6.17.0",
"ava": "6.0.1",
"c8": "8.0.1",
"cannon-es": "0.20.0",
"eslint": "8.54.0",
"eslint": "8.56.0",
"microbundle": "0.15.1",
"rimraf": "5.0.5",
"three": "0.140.0",
"ts-node": "10.9.1",
"typescript": "5.3.2"
"three": "0.160.0",
"tsx": "^4.7.0",
"typescript": "5.3.3"
},
"files": [
"dist/",
Expand All @@ -79,7 +79,7 @@
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
"--import=tsx"
]
}
}
10 changes: 2 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BufferAttribute, BufferGeometry, Mesh, Object3D, Quaternion, Vector3 } from 'three';
import type { Geometry } from 'three/examples/jsm/deprecated/Geometry';

const _v1 = new Vector3();
const _v2 = new Vector3();
Expand Down Expand Up @@ -30,13 +29,8 @@ export function getGeometry (object: Object3D): BufferGeometry | null {
}

function normalizeGeometry (mesh: Mesh): BufferGeometry {
let geometry: BufferGeometry = mesh.geometry;
if ((geometry as unknown as Geometry).toBufferGeometry) {
geometry = (geometry as unknown as Geometry).toBufferGeometry();
} else {
// Preserve original type, e.g. CylinderBufferGeometry.
geometry = geometry.clone();
}
// Preserve original type, e.g. CylinderBufferGeometry.
const geometry: BufferGeometry = mesh.geometry.clone();

mesh.updateMatrixWorld();
mesh.matrixWorld.decompose(_v1, _q1, _v2);
Expand Down
24 changes: 3 additions & 21 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Box, ConvexPolyhedron, Cylinder, Shape, Sphere, Trimesh } from 'cannon-es';
import test from 'ava';
import { BoxBufferGeometry, BufferGeometry, Group, Matrix4, Mesh, Vector3 } from 'three';
import { Geometry } from 'three/examples/jsm/deprecated/Geometry.js';
import { BoxGeometry, Group, Matrix4, Mesh } from 'three';
import { getShapeParameters, ShapeParameters, ShapeResult, ShapeType, threeToCannon } from 'three-to-cannon';

const object = new Mesh(new BoxBufferGeometry(10, 10, 10));
const object = new Mesh(new BoxGeometry(10, 10, 10));

function equalsApprox (a: number, b: number) {
return Math.abs( a - b ) < 0.0001;
Expand Down Expand Up @@ -116,7 +115,7 @@ test('threeToCannon - shape - mesh', function (t) {

test('threeToCannon - transform - position', function (t) {
const group = new Group();
const object = new Mesh(new BoxBufferGeometry(10, 10, 10));
const object = new Mesh(new BoxGeometry(10, 10, 10));
const matrix = new Matrix4().makeTranslation(0, 50, 0);
object.geometry.applyMatrix4(matrix);
group.position.set(100, 0, 0);
Expand All @@ -137,20 +136,3 @@ test('threeToCannon - transform - position', function (t) {
t.is( offset?.z, 0, 'box.offset.z' );
t.is( orientation, undefined, 'box.orientation' );
});

test('threeToCannon - legacy geometry', function (t) {
const geometry = new Geometry();
geometry.vertices.push(
new Vector3(2, 2, 2),
new Vector3(0, 0, 0),
new Vector3(-2, -2, -2),
);
const mesh = new Mesh(geometry as unknown as BufferGeometry);

const {shape: box} = threeToCannon(mesh, {type: ShapeType.BOX}) as ShapeResult<Box>;

t.is( box.type, Shape.types.BOX, 'box.type' );
t.is( box.halfExtents.x, 2, 'box.halfExtents.x' );
t.is( box.halfExtents.y, 2, 'box.halfExtents.y' );
t.is( box.halfExtents.z, 2, 'box.halfExtents.z' );
});
Loading

0 comments on commit f62a58e

Please sign in to comment.