Drag the background!

API: Three (Module) (r1)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
Three (Module) (r1) Yes Three.js No 121 Worlds None


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

This API has the following features:

  • Includes Three.js release 127.

  • Includes the following libraries for loading 3D models:

  • It loads your JS using <script type="module">
  • This means you cannot use document.write

  • 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 );  

You can load Three.js using something like this:

  
  	import * as THREE from '/api/threemodule/libs/three.module.js'; 


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



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.