@casmo/tree.js 0.3.0 → 0.4.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.
- package/README.md +186 -1
- package/dist/effects/effects.d.ts +51 -6
- package/dist/effects/effects.d.ts.map +1 -1
- package/dist/effects/glow.d.ts +5 -0
- package/dist/effects/glow.d.ts.map +1 -1
- package/dist/effects/grade.d.ts +3 -0
- package/dist/effects/grade.d.ts.map +1 -1
- package/dist/effects/highlight.d.ts +35 -0
- package/dist/effects/highlight.d.ts.map +1 -0
- package/dist/effects/index.d.ts +5 -1
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/effects/inner-lines.d.ts +39 -0
- package/dist/effects/inner-lines.d.ts.map +1 -0
- package/dist/effects/live.d.ts +12 -0
- package/dist/effects/live.d.ts.map +1 -0
- package/dist/effects/mask.d.ts +23 -11
- package/dist/effects/mask.d.ts.map +1 -1
- package/dist/effects/outline.d.ts +12 -0
- package/dist/effects/outline.d.ts.map +1 -1
- package/dist/effects/pass.d.ts +27 -0
- package/dist/effects/pass.d.ts.map +1 -0
- package/dist/effects/screen.d.ts +31 -0
- package/dist/effects/screen.d.ts.map +1 -0
- package/dist/effects/suggested.d.ts +5 -0
- package/dist/effects/suggested.d.ts.map +1 -1
- package/dist/effects/tree-id.d.ts +50 -0
- package/dist/effects/tree-id.d.ts.map +1 -0
- package/dist/effects.js +772 -57
- package/dist/effects.js.map +1 -1
- package/dist/forest/Forest.d.ts +2 -0
- package/dist/forest/Forest.d.ts.map +1 -1
- package/dist/{forest-ChEaWJrf.js → forest-lg61rhKM.js} +5 -1
- package/dist/{forest-ChEaWJrf.js.map → forest-lg61rhKM.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Camera, Node, TextureNode } from 'three/webgpu';
|
|
2
|
+
/** Eight sample directions around a pixel, unit length: the four axes and the four diagonals. */
|
|
3
|
+
export declare const EIGHT_DIRECTIONS: readonly (readonly [number, number])[];
|
|
4
|
+
/** Four sample directions around a pixel: the axes. */
|
|
5
|
+
export declare const FOUR_DIRECTIONS: readonly (readonly [number, number])[];
|
|
6
|
+
/** The size of a texture in pixels, as a `vec2`. */
|
|
7
|
+
export declare function sizeOf(texture: TextureNode): Node<'vec2'>;
|
|
8
|
+
/**
|
|
9
|
+
* The texel `offset` px from the pixel being shaded, clamped to the texture, for exact texel loads
|
|
10
|
+
* (`texture.load(texelAt(texture, offset))`) of unfiltered targets such as the Tree ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare function texelAt(texture: TextureNode, offset: Node<'vec2'>): Node<'ivec2'>;
|
|
13
|
+
/** The Tree ID at a texel (see {@link texelAt}): 0 where no tree is drawn. */
|
|
14
|
+
export declare function treeIdAt(treeId: TextureNode, texel: Node<'ivec2'>): Node<'uint'>;
|
|
15
|
+
/** An optional input an effect needs, or an error naming the effect, the input and where to get it. */
|
|
16
|
+
export declare function requireInput<T>(effect: string, value: T | undefined, name: string, hint: string): T;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the scene depth `depth` is further from the camera than `than` (both raw values of the
|
|
19
|
+
* scene pass's depth texture). Decided per renderer when the shader is built: a reversed depth
|
|
20
|
+
* buffer (`reversedDepthBuffer`) stores 1 at the near plane and 0 at the far plane, a standard or
|
|
21
|
+
* logarithmic one the other way around.
|
|
22
|
+
*/
|
|
23
|
+
export declare const isFurther: (depth: Node<"float">, than: Node<"float">) => Node<"bool">;
|
|
24
|
+
/**
|
|
25
|
+
* A function turning a raw value of the scene pass's depth texture into view Z (negative, in world
|
|
26
|
+
* units) for `camera` (its near and far are read every render). It follows the renderer's depth
|
|
27
|
+
* buffer: standard, reversed (`reversedDepthBuffer`) or logarithmic (`logarithmicDepthBuffer`,
|
|
28
|
+
* which three only applies to perspective cameras).
|
|
29
|
+
*/
|
|
30
|
+
export declare function viewZFromDepth(camera: Camera): (depth: Node<'float'>) => Node<'float'>;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AK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,CAkBtF"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { StyleName } from '../styles/registry';
|
|
2
2
|
import type { TreeColorGradeOptions } from './grade';
|
|
3
3
|
import type { LeafGlowOptions } from './glow';
|
|
4
|
+
import type { TreeHighlightOptions } from './highlight';
|
|
4
5
|
import type { TreeOutlineOptions } from './outline';
|
|
6
|
+
import type { InnerLinesOptions } from './inner-lines';
|
|
5
7
|
/** A combination of Tree Effects; leave an effect out to skip it. `{}` = no effects. */
|
|
6
8
|
export interface TreeEffectsSettings {
|
|
7
9
|
grade?: TreeColorGradeOptions;
|
|
8
10
|
glow?: LeafGlowOptions;
|
|
9
11
|
outline?: TreeOutlineOptions;
|
|
12
|
+
innerLines?: InnerLinesOptions;
|
|
13
|
+
/** Marks the TreeEffects' `highlighted` trees; never in a suggestion. */
|
|
14
|
+
highlight?: TreeHighlightOptions;
|
|
10
15
|
}
|
|
11
16
|
/** The suggested combination of Tree Effects for each built-in Style. */
|
|
12
17
|
export declare const SUGGESTED_TREE_EFFECTS: Record<StyleName, TreeEffectsSettings>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggested.d.ts","sourceRoot":"","sources":["../../src/effects/suggested.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"suggested.d.ts","sourceRoot":"","sources":["../../src/effects/suggested.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAED,yEAAyE;AACzE,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAqBzE,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type MRTNode, type PassNode, type Renderer, type Texture } from 'three/webgpu';
|
|
2
|
+
import type { ForestTree } from '../forest';
|
|
3
|
+
import type { Tree } from '../tree';
|
|
4
|
+
/** Name of the Tree ID output in a pass's MRT (`scenePass.getTextureNode(TREE_ID)`), see {@link treeIdMRT}. */
|
|
5
|
+
export declare const TREE_ID = "treeId";
|
|
6
|
+
/**
|
|
7
|
+
* The current Tree ID of a Tree or a Forest tree, or `undefined` for a Forest tree that was removed.
|
|
8
|
+
* IDs are handed out lazily, on first use: by this function or by the first draw with the Tree ID
|
|
9
|
+
* channel, whichever comes first. So asking for a Tree's ID before it is drawn reserves it then
|
|
10
|
+
* (and for a Forest tree the block of its Variant's current meshes). A Forest tree's ID is
|
|
11
|
+
* frame-relative (see {@link treeFromId}).
|
|
12
|
+
*/
|
|
13
|
+
export declare function treeIdOf(tree: Tree | ForestTree): number | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The Tree or Forest tree with this Tree ID, resolved against the current trees, or `undefined`
|
|
16
|
+
* for 0 (not a tree), an unknown ID or a tree that is gone.
|
|
17
|
+
*/
|
|
18
|
+
export declare function treeFromId(id: number): Tree | ForestTree | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The MRT output that renders each tree's Tree ID ({@link createTreeId}) next to the colour, opt-in
|
|
21
|
+
* next to {@link treeMaskMRT}. Merge it into the MRT of your own scene pass and always call
|
|
22
|
+
* {@link treeIdTexture} on that pass afterwards:
|
|
23
|
+
* `scenePass.setMRT(mrt({ output }).merge(treeMaskMRT()).merge(treeIdMRT())); treeIdTexture(scenePass);`.
|
|
24
|
+
* Note that this turns MSAA off on that scene pass (an integer target cannot be multisampled, see
|
|
25
|
+
* {@link treeIdTexture}). Read IDs back with {@link readTreeId}, or in a shader with exact texel
|
|
26
|
+
* loads (never filtered).
|
|
27
|
+
*/
|
|
28
|
+
export declare function treeIdMRT(): MRTNode;
|
|
29
|
+
/**
|
|
30
|
+
* Makes the Tree ID target of a scene pass ({@link treeIdMRT} merged into its MRT) one 32-bit
|
|
31
|
+
* unsigned integer per pixel (`r32uint`, read without filtering) and returns its texture. Call it
|
|
32
|
+
* once after `setMRT`, before the first render.
|
|
33
|
+
*
|
|
34
|
+
* **MSAA is turned off on this scene pass**: an integer target cannot be multisampled, and all the
|
|
35
|
+
* targets of a pass share one sample count, so this sets `scenePass.options.samples = 0`, also with
|
|
36
|
+
* an `antialias: true` renderer (the colour then has aliased edges unless you add FXAA/SMAA after
|
|
37
|
+
* the pass). That is a hard constraint of WebGPU and WebGL2, not a choice of tree.js.
|
|
38
|
+
*
|
|
39
|
+
* On the WebGL2 fallback it also makes the pass clear the Tree ID target to 0 right before every
|
|
40
|
+
* render (three cannot clear integer targets there), so a pixel where nothing is drawn reads 0.
|
|
41
|
+
*/
|
|
42
|
+
export declare function treeIdTexture(scenePass: PassNode): Texture;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the Tree ID under a point of the canvas from the last render of `scenePass` (with
|
|
45
|
+
* {@link treeIdMRT} in its MRT): `x`, `y` in CSS pixels from the canvas's top left corner, as in
|
|
46
|
+
* `event.offsetX/offsetY`. Resolves to 0 off the canvas or where no tree is drawn. Resolve the ID
|
|
47
|
+
* with {@link treeFromId} right away: IDs are frame-relative.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readTreeId(renderer: Renderer, scenePass: PassNode, x: number, y: number): Promise<number>;
|
|
50
|
+
//# sourceMappingURL=tree-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-id.d.ts","sourceRoot":"","sources":["../../src/effects/tree-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiG,KAAK,OAAO,EAA4B,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjN,OAAO,KAAK,EAAU,UAAU,EAAiB,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAGpC,+GAA+G;AAC/G,eAAO,MAAM,OAAO,WAAW,CAAC;AA0EhC;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAKpE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAQpE;AAiHD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAInC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAU1D;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa/G"}
|