This is a part of Node3D project.
npm install @node-3d/coreThis package uses pre-compiled Node.js addons. There is no compilation during
npm install. The addons are compiled for: Win64, Linux64, Linux ARM64, MacOS ARM64.
- WebGL/OpenGL on Node.js with support for web libs, such as three.js.
- Multi-window apps, low-level window control with @node-3d/glfw.
- Modern OpenGL functions also available, see @node-3d/webgl.
- Image loading/saving in popular formats with @node-3d/image.
Initializes Node3D, creates the first Document, wires browser-like globals, and returns:
doc- the createdDocument, also assigned toglobalThis.documentandglobalThis.window.loop- shortcut fordoc.loop.raf- shortcut fordoc.requestAnimationFrame.
init() is cached. Repeated calls return the first result and do not create another document.
Options are mostly @node-3d/glfw Document options, plus:
isGles3- request an OpenGL ES 3 style context and shader behavior, closest to WebGL.isWebGL2- expose the context as WebGL2 to browser-style libraries.isVisible- passfalseto create an initially hidden window.
Patches a Three.js module instance for Node3D:
- Makes
three.FileLoader.load()read files through Node.js. - Adds
three.Texture.fromId(id)so Three.js textures can wrap existing GL texture IDs.
Call this once before creating Three.js loaders/materials that depend on those behaviors.
@node-3d/core re-exports the common pieces needed by apps:
Screen,Surface,Points,Lines,Tris,Rect,BrushColor,Vec2,Vec3,Vec4Document,Window,Imageglfrom@node-3d/webglglfwfrom@node-3d/glfw, withglfw.Documentandglfw.Windowattached
Screen is the high-level Three.js helper. It creates or accepts a camera, scene, and renderer,
binds them to the Node3D document, forwards input events, and recreates the renderer when the
window mode changes.
Important members:
renderer,scene,camera,document,canvas,contextwidth,height,w,h,sizetitle,icon,fov,modedraw()- rendersscenewithcamerasnapshot(name?)- saves the current framebuffer
The lightweight drawable classes are useful when you need simple geometry without writing Three.js setup code each time:
Points- point cloud drawable backed by GL buffers.Lines- line, segment, or loop drawable.Tris- triangle drawable.Rect- 2D rectangle helper.Brush- mouse/paint-style helper built on rectangles.Surface- nested render surface.
They are intentionally small wrappers around Three.js objects and raw GL resources.
(As in crate-lean.ts):
import * as THREE from 'three';
import { Screen, addThreeHelpers, init } from '@node-3d/core';
const { loop } = init({
isGles3: true, vsync: true, autoEsc: true, autoFullscreen: true, title: 'Crate',
});
addThreeHelpers(THREE);
const screen = new Screen({ three: THREE, fov: 70, z: 2 });
const texture = new THREE.TextureLoader().load('three/textures/crate.gif');
texture.colorSpace = THREE.SRGBColorSpace;
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ map: texture });
const mesh = new THREE.Mesh(geometry, material);
screen.scene.add(mesh);
loop((now) => {
mesh.rotation.x = now * 0.0005;
mesh.rotation.y = now * 0.001;
screen.draw();
});Example Notes:
- You can run TypeScript examples directly with Node.js 24.
loopis a convenience method, you can userequestAnimationFrametoo.autoFullscreenoption enables "CTRL+F", "CTRL+SHIFT+F", "CTRL+ALT+F" to switch window modes.Screenhelps with three.js-oriented resource management, but is not required.- three.js uses VAO, so if not using
Screen, handling the window mode changes (which creates a separate OpenGL context) is up to you. Basically,doc.on('mode', () => {...})- here you should re-createTHREE.WebGLRenderer. See the current Screen implementation.
- This is real native OpenGL, and you have direct access to GL resource IDs. This may be useful for resource sharing and compute interop:
- The flag
isGles3lets you use a GL ES 3 preset, which is closest to "real" WebGL. If set tofalse, WebGL stuff (such as three.js) will still work, but now with some hacks. However, if you are planning to use non-WebGL features (e.g. OpenGL 4.5 features), you might want it off, and then select a specific context version manually. - The flag
isWebGL2impacts how web libraries recognize the WebGL version. But it doesn't really change the capabilities of the engine. - Offscreen rendering is possible on Windows and Linux, as demonstrated by the tests running in GitHub Actions. There are test cases that generate and compare screenshots.
- OpenGL context sharing is enabled. You can obtain
HDC, HWND, CTXfor Windows and whatever those are called on Linux and MacOS. See @node-3d/glfw.
You get this for free. Have fun!
Some of the components have their separate licenses, but all of them may be used commercially, without royalty.
