0.2.5 • Published 2 months ago

t3d v0.2.5

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 months ago

ThingJS 3D Engine

NPM Package npm-size Issues DeepScan grade Discord

ThingJS 3D Engine (t3d) is a lightweight, web-first, and extendable 3D rendering library. It is used by ThingJS for web3d rendering, but can also be used as a standalone library.

Examples Docs Discord

Import

Use t3d.js or t3d.min.js in your page:

<script src="t3d.min.js"></script>

or import as es6 module:

import * as t3d from 't3d.module.js';

Npm

t3d is published on npm. To install, use:

npm install t3d --save

This will allow you to import t3d entirely using:

import * as t3d from 't3d';

or individual classes using:

import { Scene, Renderer } from 't3d';

Since v0.2.0, the JavaScript files in examples/jsm can be imported like this:

import { OrbitControls } from 't3d/addons/controls/OrbitControls.js';

CDN

Usage

Draw a simple cube:

const width = window.innerWidth || 2;
const height = window.innerHeight || 2;

const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);

const gl = canvas.getContext('webgl2', {
  antialias: true,
  alpha: false
});
const renderer = new t3d.WebGLRenderer(gl);
renderer.setClearColor(0.1, 0.1, 0.1, 1);
const backRenderTarget = new t3d.RenderTargetBack(canvas);

const scene = new t3d.Scene();

const geometry = new t3d.BoxGeometry(8, 8, 8);
const material = new t3d.PBRMaterial();
const mesh = new t3d.Mesh(geometry, material);
scene.add(mesh);

const ambientLight = new t3d.AmbientLight(0xffffff);
scene.add(ambientLight);

const directionalLight = new t3d.DirectionalLight(0xffffff);
directionalLight.position.set(-5, 5, 5);
directionalLight.lookAt(new t3d.Vector3(), new t3d.Vector3(0, 1, 0));
scene.add(directionalLight);

const camera = new t3d.Camera();
camera.position.set(0, 10, 30);
camera.lookAt(new t3d.Vector3(0, 0, 0), new t3d.Vector3(0, 1, 0));
camera.setPerspective(45 / 180 * Math.PI, width / height, 1, 1000);
scene.add(camera);

function loop(count) {
  requestAnimationFrame(loop);

  mesh.euler.y = count / 1000 * .5; // rotate cube

  scene.updateMatrix();
  scene.updateRenderStates(camera);
  scene.updateRenderQueue(camera);

  renderer.setRenderTarget(backRenderTarget);
  renderer.clear(true, true, false);
  renderer.renderScene(scene, camera);
}
requestAnimationFrame(loop);

Extensions

Contributing

Please make sure to read the Contributing Guide before making a pull request.

0.2.5

2 months ago

0.2.4

3 months ago

0.2.3

5 months ago

0.2.2

6 months ago

0.2.1

7 months ago

0.2.0-beta.0

9 months ago

0.2.0

9 months ago

0.1.6

10 months ago

0.1.5

11 months ago

0.1.4

12 months ago

0.1.3

1 year ago

0.1.3-beta.2

1 year ago

0.1.3-beta.1

1 year ago

0.1.3-beta.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago