npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tomaisthorpe/ammojs-typed

v1.0.7

Published

Ammo.js with type definitions

Downloads

1

Readme

Ammo.js Typed

This project provides the Ammo.js modules with typescript definitions.

Installation

Use npm or yarn to install this version of ammojs from npm

$ npm install ammojs-typed

or from github

$ npm install github:giniedp/ammojs-typed

Usage

Ammo as window global

Configure your tsconfig.json to lookup the ambient types

  "typeRoots": ["node_modules/ammojs-typed/ammo/ambient"]

Then at some point require ammo.js (depends on your build chain)

require('ammojs-typed')

or reference the script

<script src="./ammo.js">

And use the global Ammo object

Ammo().then(() => {
  new Ammo.btVector3(1, 2, 3)
})

Ammo as es6 module import

You probably need to set the following compilerOptions in tsconfig.json

  "allowSyntheticDefaultImports": true,
  "esModuleInterop": true

Then import ammo like this

import Ammo from 'ammojs-typed'

This works but be cautious here. The default import gives you the bootstrap function. After bootstrapping the api is not available through the Ammo symbol by default.

Ammo().then(api => {
  const v1 = new api.btVector3(1, 2, 3)
  const v2 = new Ammo.btVector3(1, 2, 3) // <-- runtime error here
})

You can work around that by booting like this

Ammo(Ammo).then(() => {
  const v2 = new Ammo.btVector3(1, 2, 3) // <-- works
})

Ammo as dynamic import

Enable same compilerOptions as above

import('./ammo.js')                        // use dynamic import
  .then((Module) => Module.default())      // bootstrap ammo.js
  .then((ammo) => {
    const v1 = new ammo.btVector3(1, 2, 3) // use ammo here
  })

Since typescript 3.8 you can use type only imports. So with dynamic imports you can safely import ammo.js types, without including them in you bundle like this

import type Ammo from './ammo.js'

import('./ammo.js')                        // use dynamic import
  .then((Module) => Module.default())      // bootstrap ammo.js
  .then((ammo) => {
    let v1: Ammo.btVector3 = null
    // ...
    v1 = v
  })

Generate .d.ts files

Clone this repository and install node dependencies

git clone [email protected]:giniedp/ammojs-typed.git
cd ammojs-typed
npm install

Place the ammo.idl and ammo.js into the ./ammo folder. To download the latest version from the ammo.js repository run

$ npm run download

Make your adjustments to the IDL file if needed (see below) and run

$ npm run generate

This will parse the ./ammo/ammo.idl and generate a ./ammo/ammo.d.ts as well as ./ammo/ambient/ammo.d.ts

Manual IDL adjustments

The btVector4 implements the shape of btVector3 which causes a signature mismatch of the setValue method which typescript complains about. Add the following to the btVector4

+void setValue(float x, float y, float z);

The btDbvtBroadphase should derive from btBroadphaseInterface

-interface btDbvtBroadphase {
+interface btDbvtBroadphase: btBroadphaseInterface {

References

  • https://github.com/kripken/ammo.js/issues/233
  • https://github.com/microsoft/TSJS-lib-generator
  • https://github.com/osman-turan/ammo.js-typings
  • https://ts-ast-viewer.com