trid3d 0.3.0 → 0.3.1
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.
- package/README.md +30 -11
- package/package.json +1 -1
- package/trid/index.d.ts +2 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
Trid gives you a scene, a camera, shapes, model loading and mouse/keyboard tools, all in plain ES modules you can drop next to your page.
|
|
12
12
|
|
|
13
|
-
> **Status:** early.
|
|
13
|
+
> **Status:** early (0.x): the API can still change between minor versions. See [Upgrading](#upgrading).
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ Trid gives you a scene, a camera, shapes, model loading and mouse/keyboard tools
|
|
|
26
26
|
- **Export** — `scene.screenshot()` and `scene.record()` save images and videos of the canvas; `exportOBJ` / `exportModel` write meshes, objects or whole scenes as OBJ files with their MTL materials and textures.
|
|
27
27
|
- **Camera** — position, yaw, pitch and field of view, with near-plane clipping.
|
|
28
28
|
- **Tools** — orbit and fly cameras, object dragging, hover highlight, a move / rotate / scale gizmo, a view axes gizmo, an FPS meter and an OBJ uploader, one line each. Exact picking by triangles. Writing your own is a plain object with a few methods.
|
|
29
|
-
- **Pure math** — every transform and projection step is exported, so you can use the pipeline piece by piece.
|
|
29
|
+
- **Pure math** — every transform and projection step is exported, plus 4×4 matrices and rotations, so you can use the pipeline piece by piece.
|
|
30
30
|
|
|
31
31
|
## Install
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ No bundler? Use the CDN with an import map, or copy the `trid/` folder next to y
|
|
|
38
38
|
|
|
39
39
|
```html
|
|
40
40
|
<script type="importmap">
|
|
41
|
-
{ "imports": { "trid3d": "https://cdn.jsdelivr.net/npm/trid3d@0.
|
|
41
|
+
{ "imports": { "trid3d": "https://cdn.jsdelivr.net/npm/trid3d@0.3/trid/index.js" } }
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -69,8 +69,8 @@ Without a bundler, serve the folder (`python3 -m http.server`) instead of openin
|
|
|
69
69
|
```js
|
|
70
70
|
import { loadOBJ } from "trid3d";
|
|
71
71
|
|
|
72
|
-
const mesh = await loadOBJ("models/teapot.obj", { fit: 1 }); // centered, 1 unit wide
|
|
73
|
-
scene.add({ mesh });
|
|
72
|
+
const mesh = await loadOBJ("models/teapot.obj", { fit: 1, materials: true }); // centered, 1 unit wide
|
|
73
|
+
scene.add({ mesh, material: mesh.materials }); // colors and textures from its .mtl file
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
Or let users load their own: `scene.use(new ObjUploader())` accepts dropped `.obj` files, and `uploader.open()` shows a file dialog.
|
|
@@ -81,12 +81,14 @@ Or let users load their own: `scene.use(new ObjUploader())` accepts dropped `.ob
|
|
|
81
81
|
| --- | --- |
|
|
82
82
|
| `trid/index.js` | Entry file: exports everything (`"trid3d"`) |
|
|
83
83
|
| `trid/scene.js` | The `Scene` class |
|
|
84
|
-
| `trid/
|
|
85
|
-
| `trid/
|
|
86
|
-
| `trid/
|
|
87
|
-
| `trid/
|
|
88
|
-
| `trid/
|
|
84
|
+
| `trid/sceneGraph.js` | Groups: `children`, world matrices |
|
|
85
|
+
| `trid/math/` | Transforms, camera directions, projection, matrices, rotations, random numbers and noise |
|
|
86
|
+
| `trid/render/` | Renderers (Canvas 2D, WebGL), effects, shapes, mesh helpers, procedural textures, drawing, frame loop |
|
|
87
|
+
| `trid/loaders/` | OBJ, MTL and texture loading |
|
|
88
|
+
| `trid/export/` | Screenshots, video recording, OBJ and MTL export |
|
|
89
|
+
| `trid/tools/` | Camera, object, gizmo and overlay tools |
|
|
89
90
|
| `docs/` | Documentation site with live demos |
|
|
91
|
+
| `test/` | Tests (`npm test`) |
|
|
90
92
|
|
|
91
93
|
## Documentation
|
|
92
94
|
|
|
@@ -101,6 +103,23 @@ npm run docs:dev
|
|
|
101
103
|
|
|
102
104
|
See [`docs/README.md`](https://github.com/ZachR622/Trid/blob/master/docs/README.md) for building and editing the docs.
|
|
103
105
|
|
|
106
|
+
## Tests
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npm test
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Uses Node's built-in test runner (Node 21+), so there's nothing to install. The tests cover shapes, mesh helpers, noise, textures, OBJ / MTL, picking, tools, groups and matrices, and the WebGL renderer's GPU memory on a fake WebGL context.
|
|
113
|
+
|
|
114
|
+
## Upgrading
|
|
115
|
+
|
|
116
|
+
### From 0.2 to 0.3
|
|
117
|
+
|
|
118
|
+
- **Canvas textures are read once.** A canvas used as a `texture` is now uploaded once (faster, and sharper with mipmaps). If you draw on it again, call `updateTexture(canvas)` after drawing, or give its material `liveTexture: true` to read it every frame. Videos still play on their own. See [Changing a canvas](https://zachr622.github.io/Trid/textures#changing-a-canvas).
|
|
119
|
+
- **The WebGL renderer frees unused GPU memory**: meshes and textures not drawn for 300 frames are freed (and sent again if they come back). Set `new WebGLRenderer({ releaseAfter: Infinity })` to keep the old behavior.
|
|
120
|
+
- **Objects can have `children`**, and `mesh` is optional for a group. Code that walks `scene.objects` only sees the top level; use `worldObjects(scene)` to include children.
|
|
121
|
+
- `parseOBJ` now sets `materialNames` / `faceMaterials` for a file with a single material too.
|
|
122
|
+
|
|
104
123
|
## Roadmap
|
|
105
124
|
|
|
106
125
|
Roughly in order:
|
|
@@ -108,4 +127,4 @@ Roughly in order:
|
|
|
108
127
|
- **More import and export formats** — STL; basic glTF later
|
|
109
128
|
- **More tools** — a selection outline, a grid helper
|
|
110
129
|
- **Post effects** (WebGL) — bloom, vignette, outlines, antialiasing and color grading over the whole image
|
|
111
|
-
- **More tests** —
|
|
130
|
+
- **More tests** — the canvas renderer's drawing and the remaining math functions
|
package/package.json
CHANGED
package/trid/index.d.ts
CHANGED
|
@@ -91,6 +91,8 @@ export type TextureSource = CanvasImageSource;
|
|
|
91
91
|
|
|
92
92
|
/** How an object's faces look. Objects without one are drawn as wireframes. */
|
|
93
93
|
export interface Material {
|
|
94
|
+
/** A name: `exportOBJ` / `exportMTL` write it as the material's name (`usemtl` / `newmtl`) */
|
|
95
|
+
name?: string;
|
|
94
96
|
/** Face color, any CSS color (default: the scene's color, or white with a texture) */
|
|
95
97
|
fill?: string;
|
|
96
98
|
/** Darken faces that turn away from the light (default true) */
|