headless-three 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +5 -2
  2. package/index.js +9 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # headless-three
2
2
 
3
- Headless Three.js rendering for Node.js, made simple.
3
+ Headless [Three.js](https://www.npmjs.com/package/three) rendering for Node.js, made simple.
4
4
  Render 3D scenes to images on the server with no browser required.
5
5
  Runs Three.js r162 (the last version with WebGL 1 support) without polluting the global scope.
6
6
 
@@ -11,7 +11,7 @@ Runs Three.js r162 (the last version with WebGL 1 support) without polluting the
11
11
 
12
12
  * Three.js r162 running in an isolated VM context
13
13
  * No global scope pollution
14
- * Works with any canvas library ([skia-canvas](https://www.npmjs.com/package/skia-canvas), [canvas](https://www.npmjs.com/package/canvas), [@napi-rs/canvas](https://www.npmjs.com/package/@napi-rs/canvas))
14
+ * Works with any canvas library ([skia-canvas](https://www.npmjs.com/package/skia-canvas), [@napi-rs/canvas](https://www.npmjs.com/package/@napi-rs/canvas), [canvas](https://www.npmjs.com/package/canvas))
15
15
  * Headless WebGL rendering via [gl](https://www.npmjs.com/package/gl)
16
16
  * Built-in render function with multi-format output (PNG, JPEG, WebP, etc.) via [sharp](https://www.npmjs.com/package/sharp)
17
17
  * Texture loading utility
@@ -108,6 +108,9 @@ Renders a scene to an image buffer or file. When saving to a file, the format is
108
108
  | `height` | `1024` | Output height in pixels |
109
109
  | `path` | | If provided, saves to this file path. Format is inferred from the extension |
110
110
  | `format` | | Output format (`"png"`, `"jpeg"`, `"webp"`, `"avif"`, `"tiff"`, etc.). Overrides extension inference |
111
+ | `colorSpace` | `THREE.SRGBColorSpace` | Renderer output color space |
112
+ | `clearColor` | `0x000000` | Background clear color |
113
+ | `clearAlpha` | `0` | Background clear alpha (0 = transparent) |
111
114
 
112
115
  ```js
113
116
  // Save to file (format inferred from extension)
package/index.js CHANGED
@@ -69,6 +69,8 @@ export default async function({ Canvas, Image, ImageData }) {
69
69
  window,
70
70
  self: window,
71
71
  OffscreenCanvas: Canvas,
72
+ HTMLCanvasElement: Canvas,
73
+ HTMLImageElement: Image,
72
74
  Image,
73
75
  ImageData,
74
76
  Blob: Blob,
@@ -139,10 +141,16 @@ export default async function({ Canvas, Image, ImageData }) {
139
141
  return tex
140
142
  },
141
143
 
142
- async render({ scene, camera, width = 1024, height = 1024, path, format }) {
144
+ async render({ scene, camera, width = 1024, height = 1024, path, format, colorSpace, clearColor, clearAlpha }) {
143
145
  const glCtx = createContext(width, height)
144
146
  const renderer = new THREE.WebGLRenderer({ context: glCtx })
145
147
  renderer.setSize(width, height)
148
+ if (colorSpace) {
149
+ renderer.outputColorSpace = colorSpace
150
+ }
151
+ if (clearColor !== undefined || clearAlpha !== undefined) {
152
+ renderer.setClearColor(clearColor ?? 0x000000, clearAlpha ?? 0)
153
+ }
146
154
  camera.projectionMatrix.elements[5] *= -1
147
155
  const gl = renderer.getContext()
148
156
  const currentFrontFace = gl.getParameter(gl.FRONT_FACE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "headless-three",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Headless Three.js rendering for Node.js, made simple.",
5
5
  "author": "Ewan Howell <ewanhowell5195> & CCCode",
6
6
  "license": "MIT",