Skip to content

Commit

Permalink
update to latest ammo.js, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Gräfenstein committed Jul 5, 2020
1 parent 7237ff0 commit 467397a
Show file tree
Hide file tree
Showing 9 changed files with 1,149 additions and 694 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ interface btVector4: btVector3 {
3. sequence types are not allowed for attribute fields. The following lines are currently ignored

- `attribute float[] m_plane;`
- `attribute Node[] m_n;`

# Manual IDL adjustments

Expand Down
32 changes: 25 additions & 7 deletions ammo/ambient/ammo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ declare module Ammo {
class btConeShape extends btCollisionShape {
constructor(radius: number, height: number);
}
class btConeShapeX extends btConeShape {
constructor(radius: number, height: number);
}
class btConeShapeZ extends btConeShape {
constructor(radius: number, height: number);
}
class btIntArray {
size(): number;
at(n: number): number;
Expand Down Expand Up @@ -345,12 +351,6 @@ declare module Ammo {
numVertices(): number;
getVertexPointer(): btVector3;
}
class btConeShapeX extends btConeShape {
constructor(radius: number, height: number);
}
class btConeShapeZ extends btConeShape {
constructor(radius: number, height: number);
}
class btCompoundShape extends btCollisionShape {
constructor(enableDynamicAabbTree?: boolean);
addChildShape(localTransform: btTransform, shape: btCollisionShape): void;
Expand Down Expand Up @@ -390,6 +390,9 @@ declare module Ammo {
}
class btConcaveShape extends btCollisionShape {
}
class btEmptyShape extends btConcaveShape {
constructor();
}
class btStaticPlaneShape extends btConcaveShape {
constructor(planeNormal: btVector3, planeConstant: number);
}
Expand Down Expand Up @@ -437,7 +440,7 @@ declare module Ammo {
}
class btCollisionConfiguration {
}
class btDbvtBroadphase extends btBroadphaseInterface {
class btDbvtBroadphase {
constructor();
}
class btBroadphaseProxy {
Expand Down Expand Up @@ -507,6 +510,7 @@ declare module Ammo {
getGravity(): btVector3;
setGravity(acceleration: btVector3): void;
getBroadphaseProxy(): btBroadphaseProxy;
clearForces(): void;
}
class btConstraintSetting {
constructor();
Expand Down Expand Up @@ -647,10 +651,12 @@ declare module Ammo {
get_m_numIterations(): number;
set_m_numIterations(m_numIterations: number): void;
}
type btInternalTickCallback = (world: btDynamicsWorld, timeStep: number) => void;
class btDynamicsWorld extends btCollisionWorld {
addAction(action: btActionInterface): void;
removeAction(action: btActionInterface): void;
getSolverInfo(): btContactSolverInfo;
setInternalTickCallback(cb: btInternalTickCallback, worldUserInfo?: any, isPreTick?: boolean): void;
}
class btDiscreteDynamicsWorld extends btDynamicsWorld {
constructor(dispatcher: btDispatcher, pairCache: btBroadphaseInterface, constraintSolver: btConstraintSolver, collisionConfiguration: btCollisionConfiguration);
Expand Down Expand Up @@ -878,6 +884,16 @@ declare module Ammo {
get_m_gravity(): btVector3;
set_m_gravity(m_gravity: btVector3): void;
}
class Face {
get_m_normal(): btVector3;
set_m_normal(m_normal: btVector3): void;
get_m_ra(): number;
set_m_ra(m_ra: number): void;
}
class tFaceArray {
size(): number;
at(n: number): Face;
}
class Node {
get_m_x(): btVector3;
set_m_x(m_x: btVector3): void;
Expand Down Expand Up @@ -993,6 +1009,8 @@ declare module Ammo {
set_m_cfg(m_cfg: Config): void;
get_m_nodes(): tNodeArray;
set_m_nodes(m_nodes: tNodeArray): void;
get_m_faces(): tFaceArray;
set_m_faces(m_faces: tFaceArray): void;
get_m_materials(): tMaterialArray;
set_m_materials(m_materials: tMaterialArray): void;
get_m_anchors(): tAnchorArray;
Expand Down
32 changes: 25 additions & 7 deletions ammo/ammo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ export declare module Ammo {
class btConeShape extends btCollisionShape {
constructor(radius: number, height: number);
}
class btConeShapeX extends btConeShape {
constructor(radius: number, height: number);
}
class btConeShapeZ extends btConeShape {
constructor(radius: number, height: number);
}
class btIntArray {
size(): number;
at(n: number): number;
Expand Down Expand Up @@ -346,12 +352,6 @@ export declare module Ammo {
numVertices(): number;
getVertexPointer(): btVector3;
}
class btConeShapeX extends btConeShape {
constructor(radius: number, height: number);
}
class btConeShapeZ extends btConeShape {
constructor(radius: number, height: number);
}
class btCompoundShape extends btCollisionShape {
constructor(enableDynamicAabbTree?: boolean);
addChildShape(localTransform: btTransform, shape: btCollisionShape): void;
Expand Down Expand Up @@ -391,6 +391,9 @@ export declare module Ammo {
}
class btConcaveShape extends btCollisionShape {
}
class btEmptyShape extends btConcaveShape {
constructor();
}
class btStaticPlaneShape extends btConcaveShape {
constructor(planeNormal: btVector3, planeConstant: number);
}
Expand Down Expand Up @@ -438,7 +441,7 @@ export declare module Ammo {
}
class btCollisionConfiguration {
}
class btDbvtBroadphase extends btBroadphaseInterface {
class btDbvtBroadphase {
constructor();
}
class btBroadphaseProxy {
Expand Down Expand Up @@ -508,6 +511,7 @@ export declare module Ammo {
getGravity(): btVector3;
setGravity(acceleration: btVector3): void;
getBroadphaseProxy(): btBroadphaseProxy;
clearForces(): void;
}
class btConstraintSetting {
constructor();
Expand Down Expand Up @@ -648,10 +652,12 @@ export declare module Ammo {
get_m_numIterations(): number;
set_m_numIterations(m_numIterations: number): void;
}
type btInternalTickCallback = (world: btDynamicsWorld, timeStep: number) => void;
class btDynamicsWorld extends btCollisionWorld {
addAction(action: btActionInterface): void;
removeAction(action: btActionInterface): void;
getSolverInfo(): btContactSolverInfo;
setInternalTickCallback(cb: btInternalTickCallback, worldUserInfo?: any, isPreTick?: boolean): void;
}
class btDiscreteDynamicsWorld extends btDynamicsWorld {
constructor(dispatcher: btDispatcher, pairCache: btBroadphaseInterface, constraintSolver: btConstraintSolver, collisionConfiguration: btCollisionConfiguration);
Expand Down Expand Up @@ -879,6 +885,16 @@ export declare module Ammo {
get_m_gravity(): btVector3;
set_m_gravity(m_gravity: btVector3): void;
}
class Face {
get_m_normal(): btVector3;
set_m_normal(m_normal: btVector3): void;
get_m_ra(): number;
set_m_ra(m_ra: number): void;
}
class tFaceArray {
size(): number;
at(n: number): Face;
}
class Node {
get_m_x(): btVector3;
set_m_x(m_x: btVector3): void;
Expand Down Expand Up @@ -994,6 +1010,8 @@ export declare module Ammo {
set_m_cfg(m_cfg: Config): void;
get_m_nodes(): tNodeArray;
set_m_nodes(m_nodes: tNodeArray): void;
get_m_faces(): tFaceArray;
set_m_faces(m_faces: tFaceArray): void;
get_m_materials(): tMaterialArray;
set_m_materials(m_materials: tMaterialArray): void;
get_m_anchors(): tAnchorArray;
Expand Down
45 changes: 34 additions & 11 deletions ammo/ammo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ interface btConeShape {
};
btConeShape implements btCollisionShape;

interface btConeShapeX {
void btConeShapeX(float radius, float height);
};
btConeShapeX implements btConeShape;

interface btConeShapeZ {
void btConeShapeZ(float radius, float height);
};
btConeShapeZ implements btConeShape;

interface btIntArray {
long size();
long at(long n);
Expand Down Expand Up @@ -392,16 +402,6 @@ interface btShapeHull {
[Const] btVector3 getVertexPointer();
};

interface btConeShapeX {
void btConeShapeX(float radius, float height);
};
btConeShapeX implements btConeShape;

interface btConeShapeZ {
void btConeShapeZ(float radius, float height);
};
btConeShapeZ implements btConeShape;

interface btCompoundShape {
void btCompoundShape(optional boolean enableDynamicAabbTree);
void addChildShape([Const, Ref] btTransform localTransform, btCollisionShape shape);
Expand Down Expand Up @@ -450,6 +450,11 @@ interface btConcaveShape {
};
btConcaveShape implements btCollisionShape;

interface btEmptyShape {
void btEmptyShape();
};
btEmptyShape implements btConcaveShape;

interface btStaticPlaneShape {
void btStaticPlaneShape([Const, Ref] btVector3 planeNormal, float planeConstant);
};
Expand Down Expand Up @@ -516,7 +521,7 @@ interface btBroadphaseInterface {
interface btCollisionConfiguration {
};

interface btDbvtBroadphase: btBroadphaseInterface {
interface btDbvtBroadphase {
void btDbvtBroadphase();
};

Expand Down Expand Up @@ -580,6 +585,7 @@ interface btRigidBody {
[Const, Ref] btVector3 getGravity();
void setGravity([Const, Ref] btVector3 acceleration);
[Const] btBroadphaseProxy getBroadphaseProxy();
void clearForces();
};
btRigidBody implements btCollisionObject;

Expand Down Expand Up @@ -732,10 +738,13 @@ interface btContactSolverInfo {
attribute long m_numIterations;
};

callback btInternalTickCallback = void (btDynamicsWorld world, float timeStep);

interface btDynamicsWorld {
void addAction(btActionInterface action);
void removeAction(btActionInterface action);
[Ref] btContactSolverInfo getSolverInfo();
void setInternalTickCallback(btInternalTickCallback cb, optional VoidPtr worldUserInfo, optional boolean isPreTick);
};
btDynamicsWorld implements btCollisionWorld;

Expand Down Expand Up @@ -939,6 +948,19 @@ interface btSoftBodyWorldInfo {
[Value] attribute btVector3 m_gravity;
};

[Prefix="btSoftBody::"]
interface Face {
attribute Node[] m_n;
[Value] attribute btVector3 m_normal;
attribute float m_ra;
};

[Prefix="btSoftBody::"]
interface tFaceArray {
[Const] long size();
[Const, Ref] Face at(long n);
};

[Prefix="btSoftBody::"]
interface Node {
[Value] attribute btVector3 m_x;
Expand Down Expand Up @@ -1024,6 +1046,7 @@ interface btSoftBody {

[Value] attribute Config m_cfg;
[Value] attribute tNodeArray m_nodes;
[Value] attribute tFaceArray m_faces;
[Value] attribute tMaterialArray m_materials;
[Value] attribute tAnchorArray m_anchors;

Expand Down
1,633 changes: 968 additions & 665 deletions ammo/ammo.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions lib/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export function convertIDL(rootTypes: webidl2.IDLRootType[]): ts.Statement[] {
nodes.push(convertInterface(rootType))
} else if (rootType.type === 'enum') {
nodes.push(convertEnum(rootType))
} else if (rootType.type === 'callback') {
nodes.push(convertCallback(rootType))
} else {
console.log('unknown IDL type', rootType.type)
}
Expand Down Expand Up @@ -189,3 +191,17 @@ function convertEnum(idl: webidl2.EnumType) {
const members = idl.values.map(it => ts.createEnumMember(it.value, null))
return ts.createEnumDeclaration([], [], idl.name, members)
}

function convertCallback(idl: webidl2.CallbackType) {
return ts.createTypeAliasDeclaration(
undefined,
undefined,
ts.createIdentifier(idl.name),
undefined,
ts.createFunctionTypeNode(
undefined,
idl.arguments.map(convertArgument),
convertType(idl.idlType),
)
)
}
4 changes: 4 additions & 0 deletions lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export function parseIDL(path: string) {
console.warn('ignored line:', line)
return `// ${line}`
})
.replace(/attribute Node\[\].*;/gi, line => {
console.warn('ignored line:', line)
return `// ${line}`
})
.replace(/float\[\]/gi, 'sequence<float>')
.replace(/long\[\]/gi, 'sequence<long>')

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ammojs-typed",
"version": "1.0.2",
"version": "1.0.3",
"description": "Ammo.js with type definitions",
"main": "ammo/ammo.js",
"types": "ammo/ammo.d.ts",
Expand All @@ -27,8 +27,8 @@
"devDependencies": {
"@types/node": "^12.7.5",
"@types/webidl2": "^23.8.0",
"ts-node": "^8.4.1",
"typescript": "^3.6.3",
"webidl2": "^23.8.2"
"ts-node": "^8.10.2",
"typescript": "^3.9.6",
"webidl2": "^23.12.1"
}
}
Loading

0 comments on commit 467397a

Please sign in to comment.