API: Three

API Version Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Three 2.0 Yes Three.js No 24 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:

  • Includes Three.js release 96.
  • Includes the following libraries for loading 3D models:
  • Includes jQuery 3.3.1.

  • 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:


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

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

© Ancient Brain Ltd. 2018-19. All rights reserved.

Ancient Brain ™ is a trademark of Ancient Brain Ltd.

Platforms      Stats      The name      Terms and conditions

Bug bounty      Classes in Dublin      Contact

Call for partners
If you are interested in writing a programming course or textbook, Ancient Brain is looking for partners. We will work with you, and integrate your course into the site. This is an opportunity for someone looking to develop a course or textbook to partner with a site to support it and promote it.