API: Three (r2)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Three (r2) Yes Three.js No 36 Worlds Starter Worlds


This API is for Three.js Worlds. It has no Ancient Brain framework. Anything written in Three.js should run using this API without change.

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:


3D for Kids Worl...
179 runs ♦ 0 likes
By Starter user  
Created: 1 Sep 2018
Modified: 17 Sep 2023
Example of plain Three.js API. Porting a World unchanged. From "3D Game Programming for Kids"
Plain Three.js World
103 runs ♦ 0 likes
By Starter user  
Created: 1 Sep 2018
Modified: 17 Sep 2023
Example of plain Three.js API. Porting a World unchanged. From github.com/mrdoob