API: Physics (r1)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Physics (r1) Yes Three.js, Physijs No 9 Worlds Starter Worlds


This API is for Three.js Worlds with physics using the Physijs library. It has no Ancient Brain framework. Anything written in Three.js and Physijs should run using this API without change.

Note: The Physijs project is dormant since 2015.
Our newer physics APIs will use a different physics library.
We will not update this API. Worlds written for this API will continue to work.

This API has the following features:



Templates


ABWorld

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 } );
else                       
	renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer : false } );


Examples

Examples of Worlds that use this API:


Purple Fruit Monster
208 runs ♦ 1 like
By Starter user  
Created: 1 Sep 2018
Modified: 17 Sep 2023
Example of porting physics World unchanged to AB using plain physics API. From "3D Game Programm...