API: Physics (r2)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Physics (r2) Yes Three.js, Ammo No 5 Worlds Starter Worlds

This API is for Three.js Worlds with physics using ammo.js. It has no Ancient Brain framework. Anything written for Three.js with ammo.js should be easily ported to this API.

This API has the following features:



This API defines a global variable called "ABWorld" with not much in it:

 ABWorld;                 // instance of class ABWorldClass  

 ABWorld.canvas;          // a variable to point to the canvas   		
 // When making a screenshot, Ancient Brain will search for the canvas.
 // If it cannot find the canvas, set this variable to point to it.
 ABWorld.fullwidth();     // return full width of window on desktop / screen on mobile 
 ABWorld.fullheight();    // return full height of window on desktop / screen on mobile

Custom renderer: preserveDrawingBuffer

In this API you make your own renderer.
Here is an important note to make sure your World can generate screenshots.

We need to allow runs to generate a World image screenshot from the canvas.
To allow this, the API sets the THREE.WebGLRenderer property "preserveDrawingBuffer" to true by default. The API takes care of this for you.
When you make your own renderer, you need to consider "preserveDrawingBuffer". If you create the renderer like the following, then your World cannot have a screenshot:

renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer: false } );
To solve this, you can make preserveDrawingBuffer always true, or make it true only on screenshot runs:

if ( AB.isScreenshotRun() )
	renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer : true } );
	renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer : false } );


Examples of Worlds that use this API:

Ammo physics mod...
95 runs ♦ 0 likes
By Starter user  
Created: 19 Apr 2021
Modified: 17 Sep 2023
Highly modified version of "ammo / instancing" from Three.js examples
Ammo physics demo
120 runs ♦ 0 likes
By Starter user  
Created: 19 Apr 2021
Modified: 17 Sep 2023
Port of "ammo / instancing" from Three.js examples