Drag the background!

API: Physics (r2)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Physics (r2) Yes Three.js, Ammo No 6 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:

  • Includes Three.js release 127.

  • Includes the following libraries for loading 3D models:

  • Includes Physics support with the ammo.js library. Build of Apr 4, 2021 .

  • Includes jQuery 3.6.0.
  • Loads up minimal CSS that should not conflict with user CSS.

  • No Ancient Brain framework.
  • World has to do everything. It has to make its own canvas. It has to do its own camera control.
  • Run header on RHS. Many JS worlds use fixed small dimension canvas, which will go in top LHS. So this API puts run header on RHS.
  • If World uses Minds, World author must call the Mind themselves:
     AB.mind.getAction ( state );  

Optional: The "ABWorld" object

This API defines the following "ABWorld" global variable. World authors can ignore the existence of ABWorld entirely.
 

	ABWorld;                 // instance of class ABWorldClass  
 
// Data and methods of ABWorld:
 
	ABWorld.canvas;          // to point to the canvas  		
 
	// useful functions for creating/resizing canvas:

	ABWorld.fullwidth();     // return full width of window on desktop / screen on mobile 
	ABWorld.fullheight();    // return full height of window on desktop / screen on mobile

The AB system will find the canvas automatically (e.g. when it needs to do a screenshot). If the AB system fails to find the canvas, you can help it out by assigning the canvas to ABWorld.canvas.


Optional: Set preserveDrawingBuffer for better performance

This API uses an edited version of Three.js with the THREE.WebGLRenderer property "preserveDrawingBuffer" set to true. This is needed to allow the site generate a World image screenshot from the canvas. This may lead to lower performance, though.

If you are concerned about performance, you can set preserveDrawingBuffer to be false:

 
  renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer: false } );
But then your World cannot have a screenshot. So a better approach is to set it to true for "generate image" runs and false for normal runs, which can be done as follows:
 
 if ( AB.isScreenshotRun() ) renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer : true } );
 else                        renderer = new THREE.WebGLRenderer ( { preserveDrawingBuffer : false } );

Templates


Examples

Examples of Worlds that use this API:


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

The background is a program, showing the JavaScript graphics used on this site.
The globes light up when you log in.
 
Font:

Users retain ownership of user content.

Platforms      Stats      The name      Terms and conditions

Call for partners      Contact

Call for partners!
Ancient Brain is looking for partners. In particular, we seek a partner in writing a JavaScript coding book for schools, to be used worldwide. We will integrate your course into the Ancient Brain site. This is an opportunity for someone looking to develop a course and textbook to partner with a site to promote it. Read more.