@null3d/engine 0.0.0 → 0.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 (311) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +19 -6
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +19 -6
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +23 -67
  8. package/docs/api/assets.md +42 -26
  9. package/docs/api/cameras.md +8 -6
  10. package/docs/api/controls.md +46 -44
  11. package/docs/api/debug.md +13 -8
  12. package/docs/api/engine.md +17 -11
  13. package/docs/api/feature-draws.md +3 -3
  14. package/docs/api/feature-effects.md +3 -3
  15. package/docs/api/feature-instances.md +2 -2
  16. package/docs/api/features.md +14 -15
  17. package/docs/api/geometry.md +56 -75
  18. package/docs/api/grass.md +1 -1
  19. package/docs/api/impostors.md +120 -9
  20. package/docs/api/input.md +4 -11
  21. package/docs/api/lights.md +14 -38
  22. package/docs/api/lines.md +8 -25
  23. package/docs/api/materials.md +69 -70
  24. package/docs/api/math.md +6 -7
  25. package/docs/api/objects.md +13 -13
  26. package/docs/api/particles.md +2 -14
  27. package/docs/api/points.md +3 -25
  28. package/docs/api/post.md +22 -23
  29. package/docs/api/quality.md +11 -6
  30. package/docs/api/raycast.md +13 -32
  31. package/docs/api/reference/animation.md +9 -9
  32. package/docs/api/reference/assets.md +18 -18
  33. package/docs/api/reference/cameras.md +5 -2
  34. package/docs/api/reference/controls.md +75 -23
  35. package/docs/api/reference/debug.md +23 -8
  36. package/docs/api/reference/engine.md +22 -10
  37. package/docs/api/reference/geometry.md +161 -82
  38. package/docs/api/reference/grass.md +1 -1
  39. package/docs/api/reference/impostors.md +92 -1
  40. package/docs/api/reference/input.md +3 -3
  41. package/docs/api/reference/lights.md +9 -9
  42. package/docs/api/reference/lines.md +7 -7
  43. package/docs/api/reference/materials.md +48 -48
  44. package/docs/api/reference/math.md +22 -22
  45. package/docs/api/reference/objects.md +9 -9
  46. package/docs/api/reference/points.md +4 -4
  47. package/docs/api/reference/post.md +18 -18
  48. package/docs/api/reference/quality.md +7 -3
  49. package/docs/api/reference/raycast.md +6 -6
  50. package/docs/api/reference/render.md +2 -2
  51. package/docs/api/reference/scene.md +29 -26
  52. package/docs/api/reference/sketch.md +4 -0
  53. package/docs/api/reference/sound.md +203 -0
  54. package/docs/api/reference/sprites.md +5 -5
  55. package/docs/api/reference/terrain.md +2 -1
  56. package/docs/api/reference/textures.md +4 -4
  57. package/docs/api/reference/ui.md +3 -3
  58. package/docs/api/reference/vertex-draws.md +3 -3
  59. package/docs/api/reference/water.md +77 -6
  60. package/docs/api/reference/wind.md +2 -2
  61. package/docs/api/render.md +12 -10
  62. package/docs/api/scene.md +40 -29
  63. package/docs/api/sketch.md +64 -3
  64. package/docs/api/sound.md +169 -0
  65. package/docs/api/splats.md +7 -0
  66. package/docs/api/sprites.md +4 -20
  67. package/docs/api/tasks.md +2 -2
  68. package/docs/api/terrain.md +2 -14
  69. package/docs/api/textures.md +9 -9
  70. package/docs/api/ui.md +3 -15
  71. package/docs/api/water.md +198 -15
  72. package/docs/api/wind.md +5 -5
  73. package/docs/cli/null3d.md +93 -18
  74. package/docs/concepts/architecture.md +10 -10
  75. package/docs/concepts/assets.md +2 -19
  76. package/docs/concepts/backends.md +7 -5
  77. package/docs/concepts/color-management.md +15 -26
  78. package/docs/concepts/culling.md +1 -1
  79. package/docs/concepts/instances.md +5 -5
  80. package/docs/concepts/large-worlds.md +1 -1
  81. package/docs/concepts/lighting.md +50 -55
  82. package/docs/concepts/lod.md +2 -15
  83. package/docs/concepts/materials.md +16 -16
  84. package/docs/concepts/post-processing.md +7 -29
  85. package/docs/concepts/quality-preset-tables.md +53 -50
  86. package/docs/concepts/quality-presets.md +56 -27
  87. package/docs/concepts/render-graph.md +19 -14
  88. package/docs/concepts/render-layers.md +3 -17
  89. package/docs/concepts/shadows.md +10 -28
  90. package/docs/concepts/static-dynamic.md +2 -2
  91. package/docs/cookbook/index.md +1 -1
  92. package/docs/data/threejs-mapping.json +136 -102
  93. package/docs/errors/E1214.md +3 -3
  94. package/docs/errors/E1307.md +23 -0
  95. package/docs/errors/E1420.md +3 -3
  96. package/docs/errors/index.md +3 -2
  97. package/docs/getting-started/cdn.md +17 -1
  98. package/docs/getting-started/first-scene.md +1 -1
  99. package/docs/getting-started/hosting.md +50 -9
  100. package/docs/getting-started/install.md +8 -7
  101. package/docs/getting-started/network-use.md +10 -2
  102. package/docs/getting-started/project-structure.md +15 -6
  103. package/docs/getting-started/third-party-notices.md +8 -6
  104. package/docs/guides/accessibility.md +1 -1
  105. package/docs/guides/add-ons.md +3 -2
  106. package/docs/guides/agents.md +16 -5
  107. package/docs/guides/assets-pipeline.md +13 -12
  108. package/docs/guides/audio.md +109 -124
  109. package/docs/guides/car-paint.md +1 -1
  110. package/docs/guides/content-pages.md +10 -6
  111. package/docs/guides/custom-passes.md +9 -8
  112. package/docs/guides/custom-shaders.md +6 -3
  113. package/docs/guides/debugging.md +78 -4
  114. package/docs/guides/deploying.md +105 -5
  115. package/docs/guides/deterministic-simulation.md +1 -1
  116. package/docs/guides/first-use-shaders.md +4 -4
  117. package/docs/guides/loading-screens.md +78 -33
  118. package/docs/guides/multiple-views.md +41 -2
  119. package/docs/guides/performance.md +6 -3
  120. package/docs/guides/phones.md +12 -1
  121. package/docs/guides/physics.md +1 -1
  122. package/docs/guides/screens.md +7 -5
  123. package/docs/guides/start-time.md +328 -0
  124. package/docs/guides/testing.md +23 -5
  125. package/docs/guides/ui-overlays.md +3 -3
  126. package/docs/index.md +12 -8
  127. package/docs/pages.md +26 -23
  128. package/docs/porting/react-three-fiber.md +228 -5
  129. package/docs/porting/threejs-loop-and-threads.md +220 -6
  130. package/docs/porting/threejs-mapping.md +86 -84
  131. package/docs/porting/threejs-materials.md +212 -5
  132. package/docs/porting/threejs-overview.md +218 -5
  133. package/docs/porting/threejs-postprocessing.md +2 -2
  134. package/docs/porting/threejs-shaders.md +298 -5
  135. package/docs/porting/threejs-unsupported.md +82 -6
  136. package/docs/porting/verification.md +181 -5
  137. package/docs/shaders/builtins.md +1 -1
  138. package/docs/shaders/library.md +63 -39
  139. package/docs/shaders/surface-functions.md +11 -10
  140. package/docs/shaders/wgsl-rules.md +1 -1
  141. package/lib/debug/channel.d.ts +103 -0
  142. package/lib/debug/channel.js +269 -0
  143. package/lib/debug/debug.d.ts +9 -7
  144. package/lib/debug/draw.d.ts +9 -0
  145. package/lib/debug/draw.js +49 -2
  146. package/lib/debug/inspector.d.ts +60 -0
  147. package/lib/debug/inspector.js +475 -0
  148. package/lib/debug/stats-panel.d.ts +1 -1
  149. package/lib/debug/stats.d.ts +2 -3
  150. package/lib/errors/codes.js +8 -2
  151. package/lib/errors/engine-error.js +25 -10
  152. package/lib/errors/fixes.d.ts +1 -0
  153. package/lib/errors/fixes.js +3 -2
  154. package/lib/generated/core.d.ts +1 -1
  155. package/lib/generated/core.js +1 -1
  156. package/lib/gpu/early-builds.d.ts +68 -0
  157. package/lib/gpu/early-builds.js +158 -0
  158. package/lib/gpu/pipeline-name.d.ts +6 -0
  159. package/lib/gpu/pipeline-name.js +23 -0
  160. package/lib/gpu/webgl2/backend.d.ts +63 -2
  161. package/lib/gpu/webgl2/backend.js +226 -8
  162. package/lib/gpu/webgl2/programs.d.ts +18 -0
  163. package/lib/gpu/webgl2/programs.js +4 -1
  164. package/lib/gpu/webgpu/backend.d.ts +89 -2
  165. package/lib/gpu/webgpu/backend.js +255 -8
  166. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  167. package/lib/gpu/webgpu/pipelines.js +15 -1
  168. package/lib/index.d.ts +6 -4
  169. package/lib/index.js +3 -2
  170. package/lib/math/color.d.ts +5 -5
  171. package/lib/math/color.js +5 -5
  172. package/lib/math/mat4.d.ts +6 -12
  173. package/lib/math/mat4.js +6 -12
  174. package/lib/math/namespaces/quat.d.ts +3 -3
  175. package/lib/math/namespaces/quat.js +3 -3
  176. package/lib/math/quat.d.ts +8 -12
  177. package/lib/math/quat.js +8 -12
  178. package/lib/math/random.d.ts +2 -3
  179. package/lib/math/random.js +2 -3
  180. package/lib/math/types.d.ts +4 -4
  181. package/lib/math/vec3.d.ts +3 -6
  182. package/lib/math/vec3.js +3 -6
  183. package/lib/page/capabilities.d.ts +7 -7
  184. package/lib/page/capabilities.js +39 -25
  185. package/lib/page/check-store.d.ts +14 -2
  186. package/lib/page/check-store.js +34 -11
  187. package/lib/page/engine.d.ts +103 -26
  188. package/lib/page/engine.js +420 -97
  189. package/lib/page/first-frame.d.ts +16 -0
  190. package/lib/page/first-frame.js +35 -0
  191. package/lib/page/frame-stats.d.ts +34 -1
  192. package/lib/page/frame-stats.js +15 -0
  193. package/lib/page/label-loop.d.ts +7 -3
  194. package/lib/page/label-loop.js +17 -10
  195. package/lib/page/labels.d.ts +3 -3
  196. package/lib/page/pipeline-store.d.ts +25 -0
  197. package/lib/page/pipeline-store.js +84 -0
  198. package/lib/page/start-marker.d.ts +4 -1
  199. package/lib/page/start-marker.js +5 -2
  200. package/lib/page/switches.d.ts +32 -2
  201. package/lib/page/switches.js +9 -1
  202. package/lib/quality/check.d.ts +24 -3
  203. package/lib/quality/check.js +21 -7
  204. package/lib/quality/chooser.d.ts +6 -0
  205. package/lib/quality/chooser.js +8 -0
  206. package/lib/quality/governor.d.ts +98 -6
  207. package/lib/quality/governor.js +250 -20
  208. package/lib/quality/preset-docs.d.ts +16 -1
  209. package/lib/quality/preset-docs.js +3 -0
  210. package/lib/quality/presets.d.ts +84 -7
  211. package/lib/quality/presets.js +94 -2
  212. package/lib/render/draw.d.ts +3 -2
  213. package/lib/render/draw.js +15 -5
  214. package/lib/render/load-draw.d.ts +7 -5
  215. package/lib/render/load-draw.js +7 -5
  216. package/lib/render/loss.d.ts +28 -10
  217. package/lib/render/loss.js +50 -22
  218. package/lib/render/recovery.d.ts +20 -0
  219. package/lib/render/recovery.js +44 -4
  220. package/lib/render/renderer.d.ts +85 -9
  221. package/lib/render/renderer.js +181 -42
  222. package/lib/render/scene-renderer.d.ts +19 -1
  223. package/lib/render/scene-renderer.js +25 -1
  224. package/lib/render/webgl2-renderers.js +8 -5
  225. package/lib/render/webgpu-renderers.js +5 -4
  226. package/lib/scene/animation.d.ts +28 -32
  227. package/lib/scene/animation.js +12 -15
  228. package/lib/scene/assets.d.ts +61 -86
  229. package/lib/scene/assets.js +103 -236
  230. package/lib/scene/background.d.ts +14 -18
  231. package/lib/scene/background.js +5 -2
  232. package/lib/scene/color.d.ts +3 -3
  233. package/lib/scene/downloads.d.ts +2 -0
  234. package/lib/scene/downloads.js +371 -0
  235. package/lib/scene/environment.d.ts +7 -7
  236. package/lib/scene/environment.js +1 -1
  237. package/lib/scene/fake-call-values.js +1 -1
  238. package/lib/scene/fog.d.ts +11 -4
  239. package/lib/scene/fog.js +8 -2
  240. package/lib/scene/frame-cameras.d.ts +19 -0
  241. package/lib/scene/frame-cameras.js +58 -0
  242. package/lib/scene/gltf.d.ts +32 -2
  243. package/lib/scene/gltf.js +78 -49
  244. package/lib/scene/grading.d.ts +2 -2
  245. package/lib/scene/grading.js +3 -3
  246. package/lib/scene/ktx2.d.ts +9 -1
  247. package/lib/scene/ktx2.js +3 -2
  248. package/lib/scene/level-rule.d.ts +120 -0
  249. package/lib/scene/level-rule.js +130 -0
  250. package/lib/scene/lines.d.ts +13 -17
  251. package/lib/scene/lines.js +3 -3
  252. package/lib/scene/lut.d.ts +1 -2
  253. package/lib/scene/lut.js +1 -2
  254. package/lib/scene/picks.d.ts +2 -2
  255. package/lib/scene/pointer-events.d.ts +4 -7
  256. package/lib/scene/post.d.ts +38 -43
  257. package/lib/scene/post.js +4 -1
  258. package/lib/scene/prefab.d.ts +7 -8
  259. package/lib/scene/prefab.js +7 -8
  260. package/lib/scene/property-animation.d.ts +1 -1
  261. package/lib/scene/property-animation.js +1 -1
  262. package/lib/scene/queries.d.ts +7 -13
  263. package/lib/scene/resources.d.ts +225 -254
  264. package/lib/scene/resources.js +179 -81
  265. package/lib/scene/scene.d.ts +149 -118
  266. package/lib/scene/scene.js +196 -98
  267. package/lib/scene/serial-loads.d.ts +29 -0
  268. package/lib/scene/serial-loads.js +68 -0
  269. package/lib/scene/shader-preloads.d.ts +34 -0
  270. package/lib/scene/shader-preloads.js +38 -0
  271. package/lib/scene/sprites.d.ts +14 -17
  272. package/lib/scene/sprites.js +5 -6
  273. package/lib/scene/textures.d.ts +11 -12
  274. package/lib/scene/textures.js +9 -10
  275. package/lib/scene/time-of-day.d.ts +3 -4
  276. package/lib/scene/time-of-day.js +2 -3
  277. package/lib/scene/vertex-draws.d.ts +5 -4
  278. package/lib/scene/vertex-draws.js +7 -5
  279. package/lib/shader-artifact.json +1 -0
  280. package/lib/shared/core.d.ts +5 -0
  281. package/lib/shared/core.js +1 -0
  282. package/lib/shared/import-once.d.ts +6 -0
  283. package/lib/shared/import-once.js +19 -0
  284. package/lib/shared/metrics.d.ts +38 -0
  285. package/lib/shared/metrics.js +62 -1
  286. package/lib/shared/run-task.js +7 -1
  287. package/lib/shared/task-pending.d.ts +12 -0
  288. package/lib/shared/task-pending.js +61 -1
  289. package/lib/shared/tasks.js +79 -32
  290. package/lib/shared/version.d.ts +17 -1
  291. package/lib/shared/version.js +19 -1
  292. package/lib/shared/wasm.d.ts +12 -4
  293. package/lib/shared/wasm.js +50 -27
  294. package/lib/shared/worker-start.d.ts +7 -0
  295. package/lib/shared/worker-start.js +27 -0
  296. package/lib/sketch/define-sketch.d.ts +35 -0
  297. package/lib/sketch/input.d.ts +2 -2
  298. package/lib/sketch/preset-check.d.ts +20 -6
  299. package/lib/sketch/preset-check.js +42 -17
  300. package/lib/sketch/quality.d.ts +69 -11
  301. package/lib/sketch/quality.js +54 -13
  302. package/lib/sketch/runner.d.ts +76 -9
  303. package/lib/sketch/runner.js +385 -52
  304. package/lib/sketch/ui.d.ts +5 -8
  305. package/lib/workers/probe-worker.d.ts +5 -0
  306. package/lib/workers/probe-worker.js +13 -4
  307. package/lib/workers/protocol.d.ts +61 -13
  308. package/lib/workers/protocol.js +4 -0
  309. package/lib/workers/render-worker.js +25 -4
  310. package/lib/workers/sketch-worker.js +104 -15
  311. package/package.json +2 -2
@@ -1,15 +1,222 @@
1
1
  ---
2
2
  id: porting/threejs-materials
3
3
  title: Porting materials and textures
4
- status: planned
4
+ status: experimental
5
5
  since: "0.3"
6
6
  summary: "Parameter-by-parameter conversion; color spaces; approximations."
7
7
  ---
8
8
 
9
- <!-- null3d:placeholder -->
10
-
11
9
  # Porting materials and textures
12
10
 
13
- > Planned for roadmap step 0.3, first released in null3D 0.1.0. This page is a placeholder. No release has this feature yet, so the APIs it names do not exist. Coding agents must not use them.
11
+ > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
+
13
+ Most three.js materials map to `materials.standard`, which follows the same glTF metallic-roughness model and the same formulas. So the values of a `MeshStandardMaterial` or a `MeshPhysicalMaterial` carry over. Lambert, Phong and Toon materials have no direct equivalent, so they become a standard material with converted values, or a surface function.
14
+
15
+ This page goes through each three.js material, then the texture settings, then four recipes. [Materials](../api/materials.md) describes every option, and [Color management](../concepts/color-management.md) explains the color spaces.
16
+
17
+ ## MeshStandardMaterial
18
+
19
+ `MeshStandardMaterial` maps to `materials.standard`:
20
+
21
+ | three.js | null3D | Notes |
22
+ | --- | --- | --- |
23
+ | `color` | `color` | Hex values are sRGB in both engines. |
24
+ | `map` | `map` | Load it in the sRGB color space (`colorSpace: 'srgb'`). Its alpha multiplies `opacity`. |
25
+ | `roughness`, `metalness` | `roughness`, `metalness` | The same meaning and the same defaults. |
26
+ | `roughnessMap`, `metalnessMap` | `metalnessRoughnessMap` | One texture, with roughness in green and metalness in blue, as glTF packs them. Pack two textures into one with `bunx @null3d/cli assets pack-orm`. |
27
+ | `normalMap`, `normalScale` | `normalMap`, `normalScale: [x, y]` | Tangent space only. The frame comes from the mesh's tangents, or from the pixels around it, as in three.js. |
28
+ | `normalMapType: ObjectSpaceNormalMap` | No equivalent | Convert the map to tangent space offline. |
29
+ | `aoMap`, `aoMapIntensity` | `aoMap`, `aoMapIntensity` | Both engines read occlusion from the red channel. |
30
+ | `lightMap`, `lightMapIntensity` | `lightMap`, `lightMapIntensity` | Usually on the second texture coordinates: give the texture `uvSet: 1`. The texture's `offset` and `repeat` become `lightMapOffset` and `lightMapRepeat`. |
31
+ | `emissive`, `emissiveIntensity`, `emissiveMap` | The same names | `emissive` is an sRGB color, and `emissiveMap` is an sRGB texture. |
32
+ | `envMap`, `envMapIntensity` | `scene.setEnvironment(env)` and `envIntensity` | One scene environment lights every material. A material takes no environment map of its own. |
33
+ | `envMapRotation` | `scene.setEnvironment(env, { rotation })` | The scene's rotation, which every material shares. |
34
+ | `bumpMap`, `bumpScale` | The same names | three.js's formula, so the look is the same. Load the map in the linear color space. |
35
+ | `displacementMap`, `displacementScale`, `displacementBias` | The same names | Shadows, the depth prepass and the culling bounds follow the moved vertices. Without a normal or bump map, the engine also bends the normals by the map's slope. |
36
+ | `alphaMap` | Alpha in the alpha channel of `map`, or a surface function | three.js reads the alpha map's green channel. The recipe below samples it. |
37
+ | `transparent: true`, `opacity` | `alphaMode: 'blend'`, `opacity` | Blended objects draw after the opaque ones, farthest first. |
38
+ | `alphaTest` | `alphaMode: 'mask'`, `alphaCutoff` | Pass the `alphaTest` value as `alphaCutoff`. The cut edges are smooth by default. `alphaToCoverage: false` gives hard edges. |
39
+ | `alphaHash` | `alphaMode: 'hash'` | The alpha sets the share of the surface that draws. The noise pattern differs from three.js's. |
40
+ | `side: DoubleSide` | `doubleSided: true` | Fixed when you create the material. |
41
+ | `side: BackSide` | Flip the geometry | Reverse each triangle's indices and negate the normals in `geometry.fromArrays`. |
42
+ | `depthWrite`, `depthTest`, `colorWrite` | The same names | Fixed when you create the material. |
43
+ | `polygonOffset` and its factor and units | `depthBias: { constant, slopeScale }` | Keep the three.js values. The engine converts the signs for its reversed depth. |
44
+ | `blending` | `blending: 'normal'`, `'additive'` or `'multiply'`, with `alphaMode: 'blend'` | Subtractive and custom blending have no equivalent. |
45
+ | `vertexColors`, `flatShading`, `wireframe`, `fog` | The same names | Fixed when you create the material. `wireframeLinewidth` has no effect. |
46
+ | `toneMapped: false` | `toneMapped: false` | The material keeps its color as the display shows it. |
47
+ | `clippingPlanes` | A surface function with `alphaMode: 'mask'` | The recipe below cuts a mesh at a plane. Its shadow is cut at the plane too, as three.js does with `clipShadows: true`. three.js's default is `clipShadows: false`: for it, also declare `fn coverage(input: SurfaceInput) -> f32` and return `1.0`, so the whole shadow stays. |
48
+ | `dithering`, `precision`, `shadowSide` | Nothing | The final pass always dithers. |
49
+
50
+ The engine blends in linear color, as three.js's `WebGPURenderer` does. `WebGLRenderer` blends after tone mapping, so see-through surfaces look a little lighter in null3D.
51
+
52
+ ## MeshPhysicalMaterial
53
+
54
+ `materials.standard` takes the physical options with the same names and formulas. Give a layer's option when you create the material, even as 0, to change it later.
55
+
56
+ | three.js | null3D | Notes |
57
+ | --- | --- | --- |
58
+ | `ior`, `reflectivity` | `ior` | Convert `reflectivity` with `ior = (1 + 0.4 * r) / (1 - 0.4 * r)`, as three.js does. |
59
+ | `specularIntensity`, `specularColor` and their maps | The same names | The color map is sRGB, and the intensity map is linear. |
60
+ | `transmission`, `thickness`, `attenuationColor`, `attenuationDistance`, `dispersion` | The same names | Only opaque objects show through a transmissive surface. |
61
+ | `transmissionMap`, `thicknessMap` | The same names | Red multiplies the transmission, and green the thickness. |
62
+ | `clearcoat`, `clearcoatRoughness`, `clearcoatNormalScale` and their maps | The same names | `clearcoatMap` and `clearcoatRoughnessMap` must be one texture: the coat in red and its roughness in green. |
63
+ | `sheen`, `sheenColor`, `sheenRoughness` and their maps | `sheenColor` times `sheen`, and the other names | There is no `sheen` option, so multiply it into `sheenColor`. The two maps must be one texture. |
64
+ | `iridescence`, `iridescenceIOR`, `iridescenceThicknessRange` and their maps | `iridescence`, `iridescenceIor`, `iridescenceThicknessRange` | The same thin-film formulas. |
65
+ | `anisotropy`, `anisotropyRotation`, `anisotropyMap` | The same names | The same lobe, with the direction from the mesh's tangents. |
66
+
67
+ A material with a clear coat or a sheen takes no `lightMap`, `specularIntensityMap`, `specularColorMap` or `diffuseTransmission`. The layers' maps take their places. Bake the light map into the base color, or split the object across two materials.
68
+
69
+ glTF files with the matching `KHR_materials_*` extensions load into these options, as they do in three.js's `GLTFLoader`.
70
+
71
+ ## MeshBasicMaterial
72
+
73
+ `MeshBasicMaterial` maps to `materials.unlit`, which takes `color`, `opacity`, `map`, `uvTransform`, `vertexColors`, `doubleSided`, `fog`, the alpha modes, `blending` and the depth options. Its `envMap` and `reflectivity` have no equivalent. For a reflective look, use `materials.standard` with a high metalness and a low roughness.
74
+
75
+ ## MeshLambertMaterial and MeshPhongMaterial
76
+
77
+ Both become `materials.standard` with `metalness: 0`. The standard material keeps energy as `MeshStandardMaterial` does, so the look changes a little. Check the result with parity images, and tune.
78
+
79
+ - Lambert: give `roughness: 1`. The emissive values and the maps carry over.
80
+ - Phong: start from `roughness = (2 / (shininess + 2)) ** 0.25`. A shininess of 30 gives 0.5, and 100 gives about 0.37.
81
+ - A Phong `specular` color has no equivalent in the metalness model. Gray specular maps to roughness alone. Strongly colored specular needs a surface function.
82
+ - A Phong `specularMap` can become a roughness map, where bright specular means low roughness. Convert it offline.
83
+
84
+ ## MeshToonMaterial and MeshMatcapMaterial
85
+
86
+ Both become custom materials, as the recipes below show. A surface function cannot read the scene's lights, so the toon recipe takes the light's direction as a uniform. For a toon look that follows every light and its shadows, step the light in a lobe function instead. The engine calls `fn lobe(input: LobeInput) -> vec3f` for the main directional light and for each point and spot light. It gets the light's direction and its shadowed irradiance, and its color adds to that light's specular ([Surface functions](../shaders/surface-functions.md#a-materials-own-lobe)). The base lighting stays beside it, so set `s.baseColor` to black and `s.roughness` to 1, as the toon recipe does. The engine calls no lobe for the fill directional lights and the area lights, so the bands do not follow them. The matcap recipe looks up a texture by the normal in view space. It is an unlit function, so it ignores the scene's lights, as three.js's matcap does.
87
+
88
+ ## Other materials
89
+
90
+ | three.js | null3D |
91
+ | --- | --- |
92
+ | `MeshNormalMaterial` | `debug.view('normals')` while you debug, which shows world-space normals. A surface function can write the normal as a color. |
93
+ | `MeshDepthMaterial`, `MeshDistanceMaterial` | `debug.view('depth')` while you debug. Shadows need no custom depth material. |
94
+ | `ShadowMaterial` | `materials.shadowCatcher({ opacity })` |
95
+ | `PointsMaterial` | The options of `scene.createPoints`, such as `size`, `sizeAttenuation`, `map` and `colors` ([Points](../api/points.md)) |
96
+ | `LineBasicMaterial`, `LineDashedMaterial`, `LineMaterial` | The options of `scene.createLines`, such as `width`, `worldUnits` and `dashed` ([Lines](../api/lines.md)) |
97
+ | `SpriteMaterial` | The options of `scene.createSprites` ([Sprites](../api/sprites.md)) |
98
+ | `ShaderMaterial`, `RawShaderMaterial`, node materials | `materials.shader` in WGSL ([Porting shaders](threejs-shaders.md)) |
99
+ | `DecalGeometry` with a `polygonOffset` material | A box mesh with `materials.decal({ map, normalMap })`. The box's place, rotation and scale replace the decal's. |
100
+ | `Reflector`, `Water` | A reflection pass with `render.addPass({ kind: 'reflection' })`, and a custom material that reads it ([Materials](../api/materials.md#mirrors-polished-floors-and-water)) |
101
+
102
+ `scene.overrideMaterial = material` draws the whole main pass with one material, as in three.js. Sprites, points, lines and particles keep their own materials, and the shadow maps keep each object's material. Set it to `null` to draw each object's own material again.
103
+
104
+ ## Texture settings
105
+
106
+ `assets.loadTexture` takes the settings that a three.js texture keeps as properties:
107
+
108
+ | three.js | null3D |
109
+ | --- | --- |
110
+ | `colorSpace = SRGBColorSpace` | `colorSpace: 'srgb'` |
111
+ | No color space, for data textures | `colorSpace: 'linear'` |
112
+ | `flipY` | `flipY`. glTF textures always use `false`. |
113
+ | `wrapS`, `wrapT` | `wrap: 'repeat'`, `'clamp'` or `'mirror'`, or a pair `[u, v]` |
114
+ | `repeat`, `offset`, `rotation` | The material's `uvTransform: { repeat, offset, rotation }`, for every map. `mapUvTransforms` gives one map its own. |
115
+ | `center` | Bake it into `offset`. |
116
+ | `anisotropy` | `anisotropy`, from 1 to 16 |
117
+ | `magFilter`, `minFilter` with `NearestFilter` | `filter: 'nearest'` |
118
+ | `generateMipmaps` | `mipmaps` |
119
+ | `channel` | `uvSet` |
120
+ | `premultiplyAlpha` | `premultipliedAlpha` |
121
+ | `needsUpdate = true` after a change of pixels | `texture.update(bitmap)` |
122
+
123
+ `loadTexture` decodes PNG, JPEG, WebP and AVIF files, and KTX2 files in the device's compressed format. Convert large textures to KTX2 with `bunx @null3d/cli assets optimize`. Materials sample 2D textures and texture arrays, not cube maps. A cube map can be the scene's background, and the scene's environment lights every material.
124
+
125
+ ## Color spaces
126
+
127
+ The engine works in linear color and encodes sRGB once, in the final pass. Load color textures (`map`, `emissiveMap`, `specularColorMap`, `sheenColorMap`) as sRGB. Load data textures (normal, roughness, metalness, occlusion, bump and height maps) as linear. A wrong color space is the most common cause of a port that looks too dark or too washed out.
128
+
129
+ null3D tone maps with punchy AgX by default. A three.js app with `NoToneMapping` needs `post.set({ toneMapping: 'none' })` to match ([Color management](../concepts/color-management.md#exposure-and-tone-mapping)).
130
+
131
+ ## Recipes
132
+
133
+ Toon shading with three bands. The light's direction is a uniform, because a surface function cannot read the scene's lights:
134
+
135
+ ```ts
136
+ const toon = materials.shader({
137
+ uniforms: { bands: 3, shadowColor: '#303050', lightDirection: [-0.5, -1, -0.3] },
138
+ wgsl: /* wgsl */ `
139
+ struct Uniforms { bands: f32, shadowColor: vec3f, lightDirection: vec3f }
140
+
141
+ fn surface(input: SurfaceInput) -> Surface {
142
+ var s = defaultSurface(input);
143
+ let ndl = max(dot(input.normal, -normalize(material.lightDirection)), 0.0);
144
+ let band = floor(ndl * material.bands) / max(material.bands - 1.0, 1.0);
145
+ s.emissive = mix(material.shadowColor, s.baseColor, band);
146
+ s.baseColor = vec3f(0.0);
147
+ s.roughness = 1.0;
148
+ return s;
149
+ }`,
150
+ });
151
+ ```
152
+
153
+ Matcap, with the camera's view matrix:
154
+
155
+ ```ts
156
+ const matcap = materials.shader({
157
+ textures: { matcap: await assets.loadTexture('/tex/matcap-clay.ktx2', { colorSpace: 'srgb' }) },
158
+ wgsl: /* wgsl */ `
159
+ var matcap: texture_2d<f32>;
160
+
161
+ fn unlit(input: SurfaceInput) -> vec4f {
162
+ let n = normalize((camera.view * vec4f(input.normal, 0.0)).xyz);
163
+ let uv = n.xy * vec2f(0.5, -0.5) + 0.5;
164
+ return vec4f(textureSample(matcap, matcapSampler, uv).rgb, 1.0);
165
+ }`,
166
+ });
167
+ ```
168
+
169
+ A clipping plane, for section views. The plane is a normal and a constant, as in `THREE.Plane`:
170
+
171
+ ```ts
172
+ const clipped = materials.shader({
173
+ alphaMode: 'mask', alphaCutoff: 0.5,
174
+ uniforms: { plane: [0, -1, 0, 1.2] },
175
+ wgsl: /* wgsl */ `
176
+ struct Uniforms { plane: vec4f }
177
+
178
+ fn surface(input: SurfaceInput) -> Surface {
179
+ var s = defaultSurface(input);
180
+ let d = dot(material.plane.xyz, input.worldPosition) + material.plane.w;
181
+ s.alpha = select(1.0, 0.0, d < 0.0);
182
+ return s;
183
+ }`,
184
+ });
185
+ ```
186
+
187
+ An alpha map, read from the green channel as three.js reads it:
188
+
189
+ ```ts
190
+ const leaf = materials.shader({
191
+ alphaMode: 'mask', alphaCutoff: 0.5,
192
+ textures: { alphaTex: await assets.loadTexture('/tex/leaf-alpha.ktx2', { colorSpace: 'linear' }) },
193
+ wgsl: /* wgsl */ `
194
+ var alphaTex: texture_2d<f32>;
195
+
196
+ fn surface(input: SurfaceInput) -> Surface {
197
+ var s = defaultSurface(input);
198
+ s.alpha = s.alpha * textureSample(alphaTex, alphaTexSampler, input.uv).g;
199
+ return s;
200
+ }`,
201
+ });
202
+ ```
203
+
204
+ A custom material takes every standard option but the texture maps. It takes up to 6 textures of its own, which its WGSL samples.
205
+
206
+ ## Check the result
207
+
208
+ 1. Turn post-processing off, and match the tone mapping on both sides.
209
+ 2. Compare one material type at a time, on a sphere and a plane under the scene's lights.
210
+ 3. Read the diff image. A surface that is brighter or darker everywhere points to a color space, the exposure or the light units. A highlight of another size points to the roughness. Missing detail points to a missing map, or a map in the wrong color space.
211
+ 4. Expect two small differences. Highlights on small curved shapes are a little brighter and narrower, because the engine uses Filament's specular anti-aliasing. Grazing reflections on strong normal maps are darker, because the engine fades reflections that point below the surface.
212
+
213
+ [Verifying a port](verification.md) shows how to compare whole views with image tests.
214
+
215
+ ## Related pages
14
216
 
15
- This page will cover: Parameter-by-parameter conversion; color spaces; approximations.
217
+ - [Materials](../api/materials.md)
218
+ - [Textures](../api/textures.md)
219
+ - [Color management](../concepts/color-management.md)
220
+ - [Surface functions](../shaders/surface-functions.md)
221
+ - [Porting shaders](threejs-shaders.md)
222
+ - [The three.js to null3D mapping](threejs-mapping.md)
@@ -1,15 +1,228 @@
1
1
  ---
2
2
  id: porting/threejs-overview
3
3
  title: Porting from three.js
4
- status: planned
4
+ status: experimental
5
5
  since: "0.3"
6
6
  summary: "The porting workflow; what gets faster; what needs rewriting."
7
7
  ---
8
8
 
9
- <!-- null3d:placeholder -->
10
-
11
9
  # Porting from three.js
12
10
 
13
- > Planned for roadmap step 0.3, first released in null3D 0.1.0. This page is a placeholder. No release has this feature yet, so the APIs it names do not exist. Coding agents must not use them.
11
+ > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
+
13
+ ```mermaid
14
+ flowchart LR
15
+ inventory["1. Inventory:<br/>list the three.js<br/>features in use"] --> baseline["2. Baseline:<br/>images and timings<br/>of the original"]
16
+ baseline --> split["3. Split:<br/>page and sketch"]
17
+ split --> port["4. Port in order:<br/>loop, camera, models,<br/>materials, lights ..."]
18
+ port --> idiom["5. Make it idiomatic:<br/>batches, arrays,<br/>no allocations"]
19
+ idiom --> verify["6. Verify:<br/>images and timings<br/>on both GPU paths"]
20
+ ```
21
+
22
+ A good port looks like the original, runs faster, and reads like null3D code. A port that copies three.js line by line can match the look at best. Some three.js habits keep the original's speed problems, and some do not work at all, because sketch code runs in a worker. So port by intent: work out what each part of the original does, then write it the null3D way.
23
+
24
+ This page gives the workflow and the main differences. The [three.js to null3D mapping](threejs-mapping.md) gives the null3D equivalent of each three.js API.
25
+
26
+ ## What gets faster
27
+
28
+ null3D keeps scene data in flat arrays in WebAssembly memory, and job workers process the arrays in bulk. three.js keeps each object as a JavaScript object, and walks the scene graph one object at a time on the page's main thread. The gap grows with the object count.
29
+
30
+ The engine's benchmarks run the same scene code in both engines. They time the CPU work per frame on the busiest thread, against the faster of three.js's two renderers. These figures come from Chrome on a MacBook Pro, with null3D on WebGPU:
31
+
32
+ | Benchmark | null3D | three.js |
33
+ | --- | --- | --- |
34
+ | S2: a scene graph of 5,096 objects, 6 levels deep | 0.35 ms | 3.18 ms |
35
+ | S4: a town of 5,000 still objects and 200 cars, with shadows | 0.34 ms | 1.85 ms |
36
+ | S5: 500 animated characters with shadows | 1.32 ms | 44.83 ms |
37
+ | S1: 100,000 boxes that move every frame, the engine's own work | 0.22 ms | 0.44 ms |
38
+ | S1-static: the same 100,000 boxes, standing still | 0.20 ms | 0.07 ms |
39
+
40
+ A scene where nothing moves can cost more in null3D. Any WebGPU frame costs about 0.075 ms of CPU time in Chrome, even an empty one.
41
+
42
+ Most of the speed of a port comes from the fifth step of the workflow. Many similar objects become instance batches, per-object update methods become loops over arrays, and per-frame allocations go away. Measure before and after that step.
43
+
44
+ The main thread gains too. The scene, the loop and the drawing leave it, so the page's HTML stays responsive while the scene works.
45
+
46
+ ## What changes in the code
47
+
48
+ | three.js habit | null3D way | Why |
49
+ | --- | --- | --- |
50
+ | `renderer.render(scene, camera)` in `requestAnimationFrame` | The loop body goes in `onUpdate(dt)`, and the engine draws by itself | Frames run on the engine's own clock |
51
+ | `mesh.position.x += 1` | `mesh.setPosition(x, y, z)`, or a batch's typed arrays for many objects | Engine objects are handles, with no position properties |
52
+ | `scene.add(mesh)` | Objects exist as soon as they are created, and `setParent` builds a hierarchy | Creation is a batched command |
53
+ | `new THREE.Vector3()` in the loop | Scratch arrays made once | Allocations cause pauses for garbage collection |
54
+ | `document`, `window` and DOM events beside scene code | The page owns the DOM, input arrives in `ctx.input`, and messages carry data | Sketch code runs in a worker without a DOM |
55
+ | `obj.userData`, subclasses of `Mesh` | Your own maps or typed arrays, keyed by handle or row | Engine objects take no new properties |
56
+ | `onBeforeRender` and other per-draw callbacks | `onUpdate`, `onLateUpdate` or a declared pass | No sketch code runs while the engine draws |
57
+ | `InstancedMesh.setMatrixAt` with a dummy `Object3D` | Write the batch's `positions`, `rotations` and `scales` arrays | No matrix composition in JavaScript |
58
+ | `material.needsUpdate = true` to switch features | Make both materials while loading, then swap with `setMaterial` | A shader change needs a new pipeline |
59
+ | `mergeGeometries` to cut draw calls | Separate objects that share a mesh and a material | They already share one draw |
60
+ | Resize handlers and `setSize` | Nothing | The engine follows the canvas's CSS size |
61
+ | `EffectComposer` pass chains | `post.set` settings, and `post.addEffect` for each custom `ShaderPass` | The chain is built in |
62
+ | `renderer.compile` after loading | `await scene.warmUp()` in the sketch | The first frame waits for its pipelines |
63
+
64
+ [The render loop, threads and the DOM](threejs-loop-and-threads.md) shows how the loop and the DOM code move.
65
+
66
+ ## What needs rewriting by hand
67
+
68
+ These parts have no automatic route. Plan time for them before you start.
69
+
70
+ | three.js | null3D | Page |
71
+ | --- | --- | --- |
72
+ | GLSL in `ShaderMaterial` and `RawShaderMaterial` | WGSL in `materials.shader`, as a surface function, an unlit function or a full shader | [Porting shaders](threejs-shaders.md) |
73
+ | `onBeforeCompile` patches | A surface function or a vertex offset function | [Porting shaders](threejs-shaders.md) |
74
+ | TSL and node materials | A WGSL surface function | [Porting shaders](threejs-shaders.md) |
75
+ | `MeshToonMaterial` | A surface function that steps the light into bands | [Porting materials and textures](threejs-materials.md) |
76
+ | `ShaderPass` and other custom passes | `post.addEffect` or `render.addPass` | [Porting post-processing](threejs-postprocessing.md) |
77
+ | `material.alphaMap` | Alpha in the base color map, or a surface function | [Porting materials and textures](threejs-materials.md) |
78
+ | Clipping planes | A surface function with `alphaMode: 'mask'` | [Porting materials and textures](threejs-materials.md) |
79
+ | Skeletons built in code | A skeleton made in a modeling tool and exported as glTF | [Animation](../api/animation.md) |
80
+ | `object.userData` | Your own maps or arrays | [Handles and objects](../concepts/handles.md) |
81
+ | React Three Fiber scenes | A sketch, with React kept for the page UI | [Porting React Three Fiber](react-three-fiber.md) |
82
+
83
+ [Unsupported three.js features](threejs-unsupported.md) lists the features with no null3D equivalent, and the workaround for each.
84
+
85
+ ## What stays the same
86
+
87
+ - **Color management.** three.js r152 and later, like null3D, read hex colors as sRGB and light in linear space.
88
+ - **Light units.** null3D uses physical units, as three.js r155 and later do: candela for point and spot lights, and lux for the others.
89
+ - **Material options.** `materials.standard` keeps most of the names, ranges and formulas of `MeshStandardMaterial` and `MeshPhysicalMaterial`, such as the clear coat and the sheen.
90
+ - **Camera controls.** The controls in `@null3d/controls` keep the option names and defaults of three.js's `OrbitControls`, `MapControls`, `FlyControls` and `FirstPersonControls`.
91
+ - **Geometry generators.** `@null3d/geometry` returns the same vertices as three.js's extra geometry classes.
92
+ - **Models.** glTF files load as they are, with their materials, skins, morph targets and clips.
93
+
94
+ Some settings change the look, so check them first when a port looks different:
95
+
96
+ - **Tone mapping.** three.js uses none by default. null3D uses `'agx-punchy'`. Set `post.set({ toneMapping: 'none' })` to match an original without tone mapping.
97
+ - **Pixel ratio.** Many three.js apps draw at the full device pixel ratio. null3D's quality presets cap it. Fix it to 1 in both apps for image checks.
98
+ - **Shadows.** three.js shadow cameras are fitted by hand. null3D's cascades fit the view, so tune `mapSize`, `cascades` and the bias instead.
99
+ - **Light range.** A point or spot light needs a finite `range`. three.js's `distance: 0` means no end.
100
+
101
+ ## The workflow
102
+
103
+ 1. **Inventory.** List every three.js feature that the app uses. The porting skill's scanner does this: see [The porting skill](#the-porting-skill). Settle the hand rewrites and the unsupported features with the app's owner before you write code.
104
+ 2. **Baseline.** Capture images and timings of the running three.js app at fixed camera views, a fixed canvas size and a pixel ratio of 1. [Verifying a port](verification.md) says how.
105
+ 3. **Split the app.** Decide what stays on the page: the DOM, HTML UI, GUI panels, storage and video elements. The scene, the loop, input handling and controls move to the sketch.
106
+ 4. **Port in order.** Port the loop, then the camera and controls, then models and textures. Then port materials, lights and shadows, geometry and batches, interaction, animation, post-processing, custom shaders and other libraries. Check the images after each step.
107
+ 5. **Make it idiomatic.** Turn many similar objects into instance batches. Turn per-object `update()` methods into loops over arrays. Make scratch arrays once. Give objects that move every frame `dynamic: true`.
108
+ 6. **Verify.** Compare the images of every camera view on WebGPU and on WebGL2, with `?gpu=webgl2`. Compare the timings with the baseline on the same device and browser.
109
+
110
+ Convert FBX, OBJ, STL and PLY models to glTF with the command line tool, then optimize them:
111
+
112
+ ```sh
113
+ bunx @null3d/cli assets convert model.fbx model.glb
114
+ bunx @null3d/cli assets optimize model.glb model.opt.glb
115
+ ```
116
+
117
+ ### A large app in two steps
118
+
119
+ A large app often mixes DOM code and scene code everywhere. Move it in two steps:
120
+
121
+ 1. Port with `createEngine({ sketchThread: 'main' })`. Sketch code then runs on the page's main thread, so DOM calls keep working while you replace three.js calls. Reach parity there.
122
+ 2. Move the DOM code into the page module and messages. Then remove the option, so the sketch runs in its worker.
123
+
124
+ The render and job workers still run in the first step. But the sketch shares the main thread with the page, so layout work can delay frames. Treat the first step as a stage of the port.
125
+
126
+ ## A small example
127
+
128
+ Before, in three.js:
129
+
130
+ ```js
131
+ import * as THREE from 'three';
132
+ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
133
+
134
+ const renderer = new THREE.WebGLRenderer({ antialias: true });
135
+ renderer.setPixelRatio(devicePixelRatio);
136
+ renderer.setSize(innerWidth, innerHeight);
137
+ document.body.appendChild(renderer.domElement);
138
+ const scene = new THREE.Scene();
139
+ const camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 100);
140
+ camera.position.set(0, 1.5, 4);
141
+ const controls = new OrbitControls(camera, renderer.domElement);
142
+ scene.add(new THREE.AmbientLight(0xffffff, 0.4));
143
+ const sun = new THREE.DirectionalLight(0xffffff, 3);
144
+ sun.position.set(1, 2, 1);
145
+ scene.add(sun);
146
+ const cube = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshStandardMaterial({ color: 0x4a8cff }));
147
+ scene.add(cube);
148
+ addEventListener('resize', () => {
149
+ camera.aspect = innerWidth / innerHeight;
150
+ camera.updateProjectionMatrix();
151
+ renderer.setSize(innerWidth, innerHeight);
152
+ });
153
+ renderer.setAnimationLoop((t) => {
154
+ cube.rotation.y = t / 1000;
155
+ controls.update();
156
+ renderer.render(scene, camera);
157
+ });
158
+ ```
159
+
160
+ After, in null3D, the page module:
161
+
162
+ ```ts
163
+ // page.ts
164
+ import { createEngine } from '@null3d/engine';
165
+
166
+ await createEngine({
167
+ canvas: document.querySelector('canvas')!,
168
+ sketch: new URL('./sketch.ts', import.meta.url),
169
+ });
170
+ ```
171
+
172
+ And the sketch:
173
+
174
+ ```ts
175
+ // sketch.ts
176
+ import { defineSketch } from '@null3d/engine';
177
+ import { createOrbitControls } from '@null3d/controls';
178
+
179
+ export default defineSketch((ctx) => {
180
+ const { scene, geometry, materials, post, time } = ctx;
181
+ post.set({ toneMapping: 'none' }); // three.js's default, for parity
182
+
183
+ const camera = scene.createPerspectiveCamera({ fov: 60, near: 0.1, far: 100, position: [0, 1.5, 4] });
184
+ scene.setActiveCamera(camera);
185
+ const controls = createOrbitControls(ctx, camera);
186
+
187
+ scene.createAmbientLight({ intensity: 0.4 });
188
+ scene.createDirectionalLight({ direction: [-1, -2, -1], intensity: 3 });
189
+
190
+ const cube = scene.createMesh({
191
+ mesh: geometry.box(),
192
+ material: materials.standard({ color: 0x4a8cff }),
193
+ dynamic: true,
194
+ });
195
+
196
+ return {
197
+ onUpdate(dt) {
198
+ cube.setRotationEuler(0, time.now, 0);
199
+ controls.update(dt);
200
+ },
201
+ };
202
+ });
203
+ ```
204
+
205
+ The resize handler, the pixel ratio call, `scene.add` and the render call go away. A directional light takes the direction that its light travels, where three.js takes a position and a target. The canvas lives in `index.html`, and CSS sizes it.
206
+
207
+ ## The porting skill
208
+
209
+ The `null3d-port-threejs` agent skill walks a coding agent through a port. [Working with AI agents](../guides/agents.md) shows how to install it. Its scanner reads a three.js project and lists every three.js feature it finds, with file and line references and the null3D equivalent:
210
+
211
+ ```sh
212
+ bun <skill-folder>/scripts/analyze-threejs.mjs <three-project> --md PORTING-INVENTORY.md
213
+ ```
214
+
215
+ The scanner groups the features by their mapping status and warns about per-frame allocations, DOM access and GLSL. It gives a rough effort size too. It matches text patterns, so read the code to confirm each row.
216
+
217
+ ## Related pages
14
218
 
15
- This page will cover: The porting workflow; what gets faster; what needs rewriting.
219
+ - [three.js to null3D mapping](threejs-mapping.md)
220
+ - [The render loop, threads and the DOM](threejs-loop-and-threads.md)
221
+ - [Porting materials and textures](threejs-materials.md)
222
+ - [Porting shaders](threejs-shaders.md)
223
+ - [Porting post-processing](threejs-postprocessing.md)
224
+ - [Porting React Three Fiber](react-three-fiber.md)
225
+ - [Unsupported three.js features](threejs-unsupported.md)
226
+ - [Verifying a port](verification.md)
227
+ - [Performance guide](../guides/performance.md)
228
+ - [Deploying](../guides/deploying.md)
@@ -60,7 +60,7 @@ post.set({ toneMapping: 'aces', exposure: 1.2, vignette: { size: 1, intensity: 1
60
60
  | `SSAOPass`, `SAOPass`, N8AO | `ao` | Their settings mean other things. Start from the defaults and tune `radius` and `scale` by eye. |
61
61
  | `SSRPass`, the WebGPU `ssr()` node | `ssr` | `maxDistance` and `thickness` keep their names, and `opacity` becomes `intensity`. Smooth materials reflect, so `selects` and `blur` have no setting. The reflections take the place of the environment's, so give the scene one. `resolutionScale` becomes the quality setting `ssrScale`. |
62
62
  | `ReflectorForSSRPass` | A reflection pass | A flat floor mirrors through a reflection pass, which wins over `ssr` on its plane. |
63
- | `OutlinePass` | `outline` and `mesh.setOutlined(true)`, or the `@null3d/three-compat` outline | For the crisp line, `visibleEdgeColor` becomes `color`, `hiddenEdgeColor` becomes `hiddenColor`, and `width` is about twice `edgeThickness`. For the soft edge, the glow and the pulse, call `createOutlinePass(ctx, { color, hiddenColor, strength, thickness, glow, pulsePeriod })` from `@null3d/three-compat`: `edgeStrength`, `edgeThickness`, `edgeGlow` and `pulsePeriod` keep their names, and the visible and hidden colors become `color` and `hiddenColor`. |
63
+ | `OutlinePass` | `outline` and `mesh.setOutlined(true)`, or the `@null3d/three-compat` outline | For the crisp line, `visibleEdgeColor` becomes `color`, `hiddenEdgeColor` becomes `hiddenColor`, and `width` is about twice `edgeThickness`. For the soft edge, the glow and the pulse, call `createOutlinePass(ctx, { color, hiddenColor, strength, thickness, glow, pulsePeriod })` from `@null3d/three-compat`. `edgeStrength`, `edgeThickness` and `edgeGlow` keep their values as `strength`, `thickness` and `glow`, and `pulsePeriod` keeps its name. The visible and hidden colors become `color` and `hiddenColor`. |
64
64
  | `LUTPass` | `lut: await assets.loadLut(url)`, `lutIntensity` | Load the same `.cube` or `.3dl` file. A `Data3DTexture` that code fills becomes `await assets.lutFromData({ size, data })`, with floats from 0 to 1 in the same order. |
65
65
  | `ShaderPass(VignetteShader)` | `vignette: { size: offset, intensity: darkness }` under ACES; under AgX, `vignette: { size: offset, intensity: Math.min(darkness, 1), falloff: 3 }` | null3D darkens HDR color before the tone curve, so bright corners darken instead of turning gray. Under ACES the default falloff gives a close match. With a `darkness` below 1, three.js also lifts dark corners toward a gray, and null3D does not. |
66
66
  | `FXAAPass`, `ShaderPass(FXAAShader)` | `createEngine({ antialias: 'fxaa' })` on the page | FXAA runs in the final pass. |
@@ -86,7 +86,7 @@ pmndrs postprocessing maps the same way:
86
86
  | `ChromaticAberrationEffect`, `NoiseEffect`, `ScanlineEffect`, `PixelationEffect` | A custom effect for each |
87
87
  | `DepthOfFieldEffect` | `dof`. `worldFocusDistance` becomes `focusDistance`, and `bokehScale` becomes `maxBlur`, tuned by eye with `aperture`. A `target` to focus on becomes `focusPoint`. |
88
88
 
89
- Bloom's glow covers a share of the screen, and three.js's glow covers a number of pixels. So a bloom mapping matches at one canvas size. [The post-processing chain](../concepts/post-processing.md#porting-from-threejs) gives the details for bloom, ambient occlusion and outlines.
89
+ Bloom's glow covers a share of the screen, and three.js's glow covers a number of pixels. So a bloom mapping matches at one canvas size. [The three.js to null3D mapping](threejs-mapping.md#post-processing) gives the details for bloom, ambient occlusion and outlines.
90
90
 
91
91
  ## Port a ShaderPass to a custom effect
92
92