@navaramap/three-default-plugin 0.0.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/LICENSE +8 -0
- package/README.md +91 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +25 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +41 -0
- package/src/index.ts +272 -0
- package/src/vite-env.d.ts +6 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @navaramap/three-default-plugin
|
|
2
|
+
|
|
3
|
+
The default plugin for `@navaramap/three`. It registers all built-in mesh, light, and effect descriptors from `@navaramap/three-default-descs` (boxes, GLTF models, sky, stars, sun, ambient light, SSAO, bloom, tone mapping, and so on) under their standard keys, so they can be used through `view.addMesh()`, `view.addLight()`, and `view.addEffect()`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Add the plugin before `view.init()`, and parameterize the view with `DefaultDescriptions` so descriptor keys are typed:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import ThreeView, {
|
|
11
|
+
degreeToRadian,
|
|
12
|
+
geodeticToVector3,
|
|
13
|
+
northUpEastToFixedFrame,
|
|
14
|
+
} from "@navaramap/three";
|
|
15
|
+
import {
|
|
16
|
+
DefaultPlugin,
|
|
17
|
+
type DefaultDescriptions,
|
|
18
|
+
} from "@navaramap/three-default-plugin";
|
|
19
|
+
|
|
20
|
+
const view = new ThreeView<DefaultDescriptions>();
|
|
21
|
+
const defaultPlugin = new DefaultPlugin();
|
|
22
|
+
view.addPlugin(defaultPlugin); // must happen before init()
|
|
23
|
+
await view.init();
|
|
24
|
+
|
|
25
|
+
// Place the mesh on the globe via a local tangent frame at the target lng/lat.
|
|
26
|
+
const origin = geodeticToVector3({
|
|
27
|
+
lng: degreeToRadian(139.77),
|
|
28
|
+
lat: degreeToRadian(35.68),
|
|
29
|
+
height: 0,
|
|
30
|
+
});
|
|
31
|
+
view.addMesh({
|
|
32
|
+
box: { width: 100, height: 100, depth: 100 },
|
|
33
|
+
matrixWorld: northUpEastToFixedFrame(origin),
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
After `init()`, `addDefaultPhotorealScene()` sets up a photorealistic base scene in one call — sky, stars, sun, sky light probe, aerial perspective, lens flare, tone mapping, and antialiasing — and returns the handles so each piece can be updated or removed later. Combine it with terrain and satellite imagery (credited through the view's built-in attribution UI) for a realistic globe:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const scene = defaultPlugin.addDefaultPhotorealScene();
|
|
41
|
+
|
|
42
|
+
// Terrain first (layer render order = add order), then imagery draped over it.
|
|
43
|
+
const terrain = view.addSource({
|
|
44
|
+
type: "quantized-mesh",
|
|
45
|
+
url: "https://terrain.reearth.land/cesium-mesh/ellipsoid/{z}/{x}/{y}.terrain",
|
|
46
|
+
maxZoom: 18,
|
|
47
|
+
requestVertexNormals: true,
|
|
48
|
+
requestWaterMask: true,
|
|
49
|
+
});
|
|
50
|
+
view.addLayer({
|
|
51
|
+
type: "terrain",
|
|
52
|
+
source: terrain,
|
|
53
|
+
terrain: { castShadow: true, receiveShadow: true },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const imagery = view.addSource({
|
|
57
|
+
type: "raster-tile",
|
|
58
|
+
url:
|
|
59
|
+
"https://tiles.maps.eox.at/wmts?layer=s2cloudless-2020_3857&style=default" +
|
|
60
|
+
"&tilematrixset=g&Service=WMTS&Request=GetTile" +
|
|
61
|
+
"&Version=1.0.0&Format=image%2Fjpeg" +
|
|
62
|
+
"&TileMatrix={z}&TileCol={x}&TileRow={y}",
|
|
63
|
+
maxZoom: 15,
|
|
64
|
+
});
|
|
65
|
+
view.addLayer({ type: "raster", source: imagery });
|
|
66
|
+
|
|
67
|
+
// Credit the data through the built-in attribution UI.
|
|
68
|
+
view.attribution?.add([
|
|
69
|
+
{
|
|
70
|
+
attribution: "© Re:Earth Terrain",
|
|
71
|
+
attributionUrl: "https://terrain.reearth.land/",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
attributionHtml:
|
|
75
|
+
'<a href="https://s2maps.eu">Sentinel-2 cloudless 2020</a> by <a href="https://eox.at">EOX IT Services GmbH</a> (contains modified Copernicus Sentinel data 2020)',
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
// Tweak individual pieces via the returned handles.
|
|
80
|
+
scene.sun.update({ sun: { castShadow: true } });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The package also re-exports every descriptor class and config type from `@navaramap/three-default-descs`, so typed `addMesh<T>` / `addEffect<T>` / `addLight<T>` calls need only this one import.
|
|
84
|
+
|
|
85
|
+
## Documentation
|
|
86
|
+
|
|
87
|
+
See https://navara-docs.netlify.app/ for the full list of built-in descriptors and their options.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT OR Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AerialPerspectiveConfig } from '@navaramap/three-default-descs';
|
|
2
|
+
import { AerialPerspectiveEffectDesc } from '@navaramap/three-default-descs';
|
|
3
|
+
import { AmbientLightConfig } from '@navaramap/three-default-descs';
|
|
4
|
+
import { ArclineMeshConfig } from '@navaramap/three-default-descs';
|
|
5
|
+
import { ArrowHelperConfig } from '@navaramap/three-default-descs';
|
|
6
|
+
import { AxesHelperConfig } from '@navaramap/three-default-descs';
|
|
7
|
+
import { BoxMeshConfig } from '@navaramap/three-default-descs';
|
|
8
|
+
import { CloudsConfig } from '@navaramap/three-default-descs';
|
|
9
|
+
import { ColorGradingLUTConfig } from '@navaramap/three-default-descs';
|
|
10
|
+
import { CylinderMeshConfig } from '@navaramap/three-default-descs';
|
|
11
|
+
import { default as default_2 } from '@navaramap/three';
|
|
12
|
+
import { DepthOfFieldConfig } from '@navaramap/three-default-descs';
|
|
13
|
+
import { EffectHandle } from '@navaramap/three';
|
|
14
|
+
import { FogLightConfig } from '@navaramap/three-default-descs';
|
|
15
|
+
import { FXAAConfig } from '@navaramap/three-default-descs';
|
|
16
|
+
import { FXAAEffectDesc } from '@navaramap/three-default-descs';
|
|
17
|
+
import { GlowGlobeMeshConfig } from '@navaramap/three-default-descs';
|
|
18
|
+
import { GLTFModelConfig } from '@navaramap/three-default-descs';
|
|
19
|
+
import { InstancedBoxMeshConfig } from '@navaramap/three-default-descs';
|
|
20
|
+
import { InstancedCylinderMeshConfig } from '@navaramap/three-default-descs';
|
|
21
|
+
import { InstancedGltfModelMeshConfig } from '@navaramap/three-default-descs';
|
|
22
|
+
import { InstancedPlaneMeshConfig } from '@navaramap/three-default-descs';
|
|
23
|
+
import { InstancedSphereMeshConfig } from '@navaramap/three-default-descs';
|
|
24
|
+
import { LensFlareConfig } from '@navaramap/three-default-descs';
|
|
25
|
+
import { LensFlareEffectDesc } from '@navaramap/three-default-descs';
|
|
26
|
+
import { LightHandle } from '@navaramap/three';
|
|
27
|
+
import { LightProbeConfig } from '@navaramap/three-default-descs';
|
|
28
|
+
import { MeshHandle } from '@navaramap/three';
|
|
29
|
+
import { PlaneMeshConfig } from '@navaramap/three-default-descs';
|
|
30
|
+
import { Plugin as Plugin_2 } from '@navaramap/three';
|
|
31
|
+
import { RainDropConfig } from '@navaramap/three-default-descs';
|
|
32
|
+
import { RainMeshConfig } from '@navaramap/three-default-descs';
|
|
33
|
+
import { SelectiveBloomEffectConfig } from '@navaramap/three-default-descs';
|
|
34
|
+
import { SelectiveOutlineEffectConfig } from '@navaramap/three-default-descs';
|
|
35
|
+
import { SkyBoxMeshConfig } from '@navaramap/three-default-descs';
|
|
36
|
+
import { SkyLightProbeConfig } from '@navaramap/three-default-descs';
|
|
37
|
+
import { SkyLightProbeDesc } from '@navaramap/three-default-descs';
|
|
38
|
+
import { SkyMeshConfig } from '@navaramap/three-default-descs';
|
|
39
|
+
import { SkyMeshDesc } from '@navaramap/three-default-descs';
|
|
40
|
+
import { SMAAConfig } from '@navaramap/three-default-descs';
|
|
41
|
+
import { SMAAEffectDesc } from '@navaramap/three-default-descs';
|
|
42
|
+
import { SmoothLineMeshConfig } from '@navaramap/three-default-descs';
|
|
43
|
+
import { SnowMeshConfig } from '@navaramap/three-default-descs';
|
|
44
|
+
import { SphereMeshConfig } from '@navaramap/three-default-descs';
|
|
45
|
+
import { SplatMeshConfig } from '@navaramap/three-default-descs';
|
|
46
|
+
import { SSAOConfig } from '@navaramap/three-default-descs';
|
|
47
|
+
import { SSRConfig } from '@navaramap/three-default-descs';
|
|
48
|
+
import { StarsConfig } from '@navaramap/three-default-descs';
|
|
49
|
+
import { StarsDesc } from '@navaramap/three-default-descs';
|
|
50
|
+
import { SunLightConfig } from '@navaramap/three-default-descs';
|
|
51
|
+
import { SunLightDesc } from '@navaramap/three-default-descs';
|
|
52
|
+
import { ToneMappingConfig } from '@navaramap/three-default-descs';
|
|
53
|
+
import { ToneMappingEffectDesc } from '@navaramap/three-default-descs';
|
|
54
|
+
import { TubeMeshConfig } from '@navaramap/three-default-descs';
|
|
55
|
+
import { ViewContext } from '@navaramap/three';
|
|
56
|
+
|
|
57
|
+
export declare type DefaultDescriptions = {
|
|
58
|
+
mesh: DefaultMeshDescription;
|
|
59
|
+
light: DefaultLightDescription;
|
|
60
|
+
effect: DefaultEffectDescription;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export declare type DefaultEffectDescription = AerialPerspectiveConfig | CloudsConfig | ColorGradingLUTConfig | DepthOfFieldConfig | FogLightConfig | FXAAConfig | LensFlareConfig | RainDropConfig | SelectiveBloomEffectConfig | SelectiveOutlineEffectConfig | SMAAConfig | SSAOConfig | SSRConfig | ToneMappingConfig;
|
|
64
|
+
|
|
65
|
+
export declare type DefaultLightDescription = SunLightConfig | SkyLightProbeConfig | AmbientLightConfig | LightProbeConfig;
|
|
66
|
+
|
|
67
|
+
export declare type DefaultMeshDescription = RainMeshConfig | SnowMeshConfig | SkyMeshConfig | SkyBoxMeshConfig | StarsConfig | BoxMeshConfig | SphereMeshConfig | GlowGlobeMeshConfig | CylinderMeshConfig | TubeMeshConfig | PlaneMeshConfig | GLTFModelConfig | SplatMeshConfig | AxesHelperConfig | ArrowHelperConfig | ArclineMeshConfig | SmoothLineMeshConfig | InstancedBoxMeshConfig | InstancedSphereMeshConfig | InstancedPlaneMeshConfig | InstancedCylinderMeshConfig | InstancedGltfModelMeshConfig;
|
|
68
|
+
|
|
69
|
+
export declare class DefaultPlugin extends Plugin_2<default_2<DefaultDescriptions>, ViewContext> {
|
|
70
|
+
private view?;
|
|
71
|
+
init(view: default_2<DefaultDescriptions>, _ctx: ViewContext): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Add default descriptors automatically to make the photorealistic scene.
|
|
74
|
+
* This method must be invoked after `view.init()`.
|
|
75
|
+
*/
|
|
76
|
+
addDefaultPhotorealScene(): {
|
|
77
|
+
sky: MeshHandle<SkyMeshDesc>;
|
|
78
|
+
stars: MeshHandle<StarsDesc>;
|
|
79
|
+
skyLightProbe: LightHandle<SkyLightProbeDesc>;
|
|
80
|
+
sun: LightHandle<SunLightDesc>;
|
|
81
|
+
aerialPerspective: EffectHandle<AerialPerspectiveEffectDesc>;
|
|
82
|
+
lensFlare: EffectHandle<LensFlareEffectDesc> | undefined;
|
|
83
|
+
toneMapping: EffectHandle<ToneMappingEffectDesc>;
|
|
84
|
+
antialiasing: EffectHandle<SMAAEffectDesc> | EffectHandle<FXAAEffectDesc>;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin as e } from "@navaramap/three";
|
|
2
|
+
import { AerialPerspectiveEffectDesc as t, AmbientLightDesc as n, ArclineMeshDesc as r, ArrowHelperDesc as i, AxesHelperDesc as a, BoxMeshDesc as o, CloudsEffectDesc as s, ColorGradingLUTEffectDesc as c, CylinderMeshDesc as l, DepthOfFieldEffectDesc as u, FXAAEffectDesc as d, FogLightEffectDesc as f, GLTFModelDesc as p, GlowGlobeMeshDesc as m, InstancedBoxMeshDesc as h, InstancedCylinderMeshDesc as g, InstancedGltfModelMeshDesc as _, InstancedPlaneMeshDesc as v, InstancedSphereMeshDesc as y, LensFlareEffectDesc as b, LightProbeDesc as x, PlaneMeshDesc as S, RainDropEffectDesc as C, RainMeshDesc as w, SMAAEffectDesc as T, SSAOEffectDesc as E, SSREffectDesc as D, SelectiveBloomEffectDesc as O, SelectiveOutlineEffectDesc as k, SkyBoxMeshDesc as A, SkyLightProbeDesc as j, SkyMeshDesc as M, SmoothLineMeshDesc as N, SnowMeshDesc as P, SphereMeshDesc as F, SplatMeshDesc as I, StarsDesc as L, SunLightDesc as R, ToneMappingEffectDesc as z, TubeMeshDesc as B } from "@navaramap/three-default-descs";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
var V = class extends e {
|
|
5
|
+
view;
|
|
6
|
+
async init(e, V) {
|
|
7
|
+
this.view = e, e.registerMesh("rain", w), e.registerMesh("snow", P), e.registerMesh("sky", M), e.registerMesh("skyBox", A), e.registerMesh("stars", L), e.registerMesh("box", o), e.registerMesh("sphere", F), e.registerMesh("glowGlobe", m), e.registerMesh("cylinder", l), e.registerMesh("tube", B), e.registerMesh("plane", S), e.registerMesh("gltfModel", p), e.registerMesh("splat", I), e.registerMesh("axesHelper", a), e.registerMesh("arrowHelper", i), e.registerMesh("arcLines", r), e.registerMesh("smoothLines", N), e.registerMesh("boxes", h), e.registerMesh("spheres", y), e.registerMesh("planes", v), e.registerMesh("cylinders", g), e.registerMesh("gltfModels", _), e.registerLight("sun", R), e.registerLight("ambient", n), e.registerLight("skyLightProbe", j), e.registerLight("lightProbe", x), e.registerEffect("aerialPerspective", t), e.registerEffect("rainDrop", C), e.registerEffect("selectiveBloom", O), e.registerEffect("selectiveOutline", k), e.registerEffect("clouds", s), e.registerEffect("fogLight", f), e.registerEffect("lensFlare", b), e.registerEffect("ssao", E), e.registerEffect("ssr", D), e.registerEffect("depthOfField", u), e.registerEffect("colorGradingLUT", c), e.registerEffect("toneMapping", z), e.registerEffect("smaa", T), e.registerEffect("fxaa", d);
|
|
8
|
+
}
|
|
9
|
+
addDefaultPhotorealScene() {
|
|
10
|
+
if (!this.view) throw Error("DefaultPlugin is not initialized. Call view.addPlugin() and view.init() first.");
|
|
11
|
+
let e = this.view, t = e.isMobileOptimized();
|
|
12
|
+
return {
|
|
13
|
+
sky: e.addMesh({ sky: {} }),
|
|
14
|
+
stars: e.addMesh({ stars: {} }),
|
|
15
|
+
skyLightProbe: e.addLight({ skyLightProbe: {} }),
|
|
16
|
+
sun: e.addLight({ sun: {} }),
|
|
17
|
+
aerialPerspective: e.addEffect({ aerialPerspective: {} }),
|
|
18
|
+
lensFlare: t ? void 0 : e.addEffect({ lensFlare: {} }),
|
|
19
|
+
toneMapping: e.addEffect({ toneMapping: {} }),
|
|
20
|
+
antialiasing: t ? e.addEffect({ fxaa: {} }) : e.addEffect({ smaa: {} })
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { V as DefaultPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@navaramap/three"),require("@navaramap/three-default-descs")):typeof define==`function`&&define.amd?define([`exports`,`@navaramap/three`,`@navaramap/three-default-descs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.NavaraDefaultPlugin={},e._navaramap_three,e._navaramap_three_default_descs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.DefaultPlugin=class extends t.Plugin{view;async init(e,t){this.view=e,e.registerMesh(`rain`,n.RainMeshDesc),e.registerMesh(`snow`,n.SnowMeshDesc),e.registerMesh(`sky`,n.SkyMeshDesc),e.registerMesh(`skyBox`,n.SkyBoxMeshDesc),e.registerMesh(`stars`,n.StarsDesc),e.registerMesh(`box`,n.BoxMeshDesc),e.registerMesh(`sphere`,n.SphereMeshDesc),e.registerMesh(`glowGlobe`,n.GlowGlobeMeshDesc),e.registerMesh(`cylinder`,n.CylinderMeshDesc),e.registerMesh(`tube`,n.TubeMeshDesc),e.registerMesh(`plane`,n.PlaneMeshDesc),e.registerMesh(`gltfModel`,n.GLTFModelDesc),e.registerMesh(`splat`,n.SplatMeshDesc),e.registerMesh(`axesHelper`,n.AxesHelperDesc),e.registerMesh(`arrowHelper`,n.ArrowHelperDesc),e.registerMesh(`arcLines`,n.ArclineMeshDesc),e.registerMesh(`smoothLines`,n.SmoothLineMeshDesc),e.registerMesh(`boxes`,n.InstancedBoxMeshDesc),e.registerMesh(`spheres`,n.InstancedSphereMeshDesc),e.registerMesh(`planes`,n.InstancedPlaneMeshDesc),e.registerMesh(`cylinders`,n.InstancedCylinderMeshDesc),e.registerMesh(`gltfModels`,n.InstancedGltfModelMeshDesc),e.registerLight(`sun`,n.SunLightDesc),e.registerLight(`ambient`,n.AmbientLightDesc),e.registerLight(`skyLightProbe`,n.SkyLightProbeDesc),e.registerLight(`lightProbe`,n.LightProbeDesc),e.registerEffect(`aerialPerspective`,n.AerialPerspectiveEffectDesc),e.registerEffect(`rainDrop`,n.RainDropEffectDesc),e.registerEffect(`selectiveBloom`,n.SelectiveBloomEffectDesc),e.registerEffect(`selectiveOutline`,n.SelectiveOutlineEffectDesc),e.registerEffect(`clouds`,n.CloudsEffectDesc),e.registerEffect(`fogLight`,n.FogLightEffectDesc),e.registerEffect(`lensFlare`,n.LensFlareEffectDesc),e.registerEffect(`ssao`,n.SSAOEffectDesc),e.registerEffect(`ssr`,n.SSREffectDesc),e.registerEffect(`depthOfField`,n.DepthOfFieldEffectDesc),e.registerEffect(`colorGradingLUT`,n.ColorGradingLUTEffectDesc),e.registerEffect(`toneMapping`,n.ToneMappingEffectDesc),e.registerEffect(`smaa`,n.SMAAEffectDesc),e.registerEffect(`fxaa`,n.FXAAEffectDesc)}addDefaultPhotorealScene(){if(!this.view)throw Error(`DefaultPlugin is not initialized. Call view.addPlugin() and view.init() first.`);let e=this.view,t=e.isMobileOptimized();return{sky:e.addMesh({sky:{}}),stars:e.addMesh({stars:{}}),skyLightProbe:e.addLight({skyLightProbe:{}}),sun:e.addLight({sun:{}}),aerialPerspective:e.addEffect({aerialPerspective:{}}),lensFlare:t?void 0:e.addEffect({lensFlare:{}}),toneMapping:e.addEffect({toneMapping:{}}),antialiasing:t?e.addEffect({fxaa:{}}):e.addEffect({smaa:{}})}}}});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@navaramap/three-default-plugin",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"main": "dist/index.umd.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT OR Apache-2.0",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/reearth/navara.git",
|
|
16
|
+
"directory": "web/navara_three_default_plugin"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@navaramap/three": "0.0.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@navaramap/three-default-descs": "0.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@navaramap/three": "0.0.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"type-check": "tsc && tsc -p tsconfig.node.json",
|
|
32
|
+
"build": "pnpm type-check && vite build --watch=false",
|
|
33
|
+
"build:dev": "vite build --mode development",
|
|
34
|
+
"build:dev:watch": "pnpm build:dev --watch",
|
|
35
|
+
"test": "vitest --passWithNoTests --watch=false",
|
|
36
|
+
"lint": "eslint . --fix",
|
|
37
|
+
"lint:check": "eslint .",
|
|
38
|
+
"format": "prettier --write --ignore-path ../../.gitignore .",
|
|
39
|
+
"format:check": "prettier --check --ignore-path ../../.gitignore ."
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type ThreeView from "@navaramap/three";
|
|
2
|
+
import {
|
|
3
|
+
Plugin,
|
|
4
|
+
type MeshHandle,
|
|
5
|
+
type LightHandle,
|
|
6
|
+
type EffectHandle,
|
|
7
|
+
type ViewContext,
|
|
8
|
+
} from "@navaramap/three";
|
|
9
|
+
import {
|
|
10
|
+
RainMeshDesc,
|
|
11
|
+
SnowMeshDesc,
|
|
12
|
+
SkyMeshDesc,
|
|
13
|
+
SkyBoxMeshDesc,
|
|
14
|
+
StarsDesc,
|
|
15
|
+
BoxMeshDesc,
|
|
16
|
+
SphereMeshDesc,
|
|
17
|
+
GlowGlobeMeshDesc,
|
|
18
|
+
CylinderMeshDesc,
|
|
19
|
+
TubeMeshDesc,
|
|
20
|
+
PlaneMeshDesc,
|
|
21
|
+
GLTFModelDesc,
|
|
22
|
+
SplatMeshDesc,
|
|
23
|
+
AxesHelperDesc,
|
|
24
|
+
ArrowHelperDesc,
|
|
25
|
+
ArclineMeshDesc,
|
|
26
|
+
SmoothLineMeshDesc,
|
|
27
|
+
type RainMeshConfig,
|
|
28
|
+
type SnowMeshConfig,
|
|
29
|
+
type SkyMeshConfig,
|
|
30
|
+
type SkyBoxMeshConfig,
|
|
31
|
+
type StarsConfig,
|
|
32
|
+
type BoxMeshConfig,
|
|
33
|
+
type SphereMeshConfig,
|
|
34
|
+
type GlowGlobeMeshConfig,
|
|
35
|
+
type CylinderMeshConfig,
|
|
36
|
+
type TubeMeshConfig,
|
|
37
|
+
type PlaneMeshConfig,
|
|
38
|
+
type GLTFModelConfig,
|
|
39
|
+
type SplatMeshConfig,
|
|
40
|
+
type AxesHelperConfig,
|
|
41
|
+
type ArrowHelperConfig,
|
|
42
|
+
type ArclineMeshConfig,
|
|
43
|
+
type SmoothLineMeshConfig,
|
|
44
|
+
InstancedBoxMeshDesc,
|
|
45
|
+
type InstancedBoxMeshConfig,
|
|
46
|
+
InstancedSphereMeshDesc,
|
|
47
|
+
type InstancedSphereMeshConfig,
|
|
48
|
+
InstancedPlaneMeshDesc,
|
|
49
|
+
type InstancedPlaneMeshConfig,
|
|
50
|
+
InstancedCylinderMeshDesc,
|
|
51
|
+
type InstancedCylinderMeshConfig,
|
|
52
|
+
InstancedGltfModelMeshDesc,
|
|
53
|
+
type InstancedGltfModelMeshConfig,
|
|
54
|
+
AerialPerspectiveEffectDesc,
|
|
55
|
+
CloudsEffectDesc,
|
|
56
|
+
ColorGradingLUTEffectDesc,
|
|
57
|
+
DepthOfFieldEffectDesc,
|
|
58
|
+
FogLightEffectDesc,
|
|
59
|
+
FXAAEffectDesc,
|
|
60
|
+
LensFlareEffectDesc,
|
|
61
|
+
RainDropEffectDesc,
|
|
62
|
+
SelectiveBloomEffectDesc,
|
|
63
|
+
SelectiveOutlineEffectDesc,
|
|
64
|
+
SMAAEffectDesc,
|
|
65
|
+
SSAOEffectDesc,
|
|
66
|
+
SSREffectDesc,
|
|
67
|
+
ToneMappingEffectDesc,
|
|
68
|
+
type AerialPerspectiveConfig,
|
|
69
|
+
type CloudsConfig,
|
|
70
|
+
type ColorGradingLUTConfig,
|
|
71
|
+
type DepthOfFieldConfig,
|
|
72
|
+
type FogLightConfig,
|
|
73
|
+
type FXAAConfig,
|
|
74
|
+
type LensFlareConfig,
|
|
75
|
+
type RainDropConfig,
|
|
76
|
+
type SelectiveBloomEffectConfig,
|
|
77
|
+
type SelectiveOutlineEffectConfig,
|
|
78
|
+
type SMAAConfig,
|
|
79
|
+
type SSAOConfig,
|
|
80
|
+
type SSRConfig,
|
|
81
|
+
type ToneMappingConfig,
|
|
82
|
+
SunLightDesc,
|
|
83
|
+
AmbientLightDesc,
|
|
84
|
+
SkyLightProbeDesc,
|
|
85
|
+
LightProbeDesc,
|
|
86
|
+
type SunLightConfig,
|
|
87
|
+
type AmbientLightConfig,
|
|
88
|
+
type SkyLightProbeConfig,
|
|
89
|
+
type LightProbeConfig,
|
|
90
|
+
} from "@navaramap/three-default-descs";
|
|
91
|
+
|
|
92
|
+
export class DefaultPlugin extends Plugin<
|
|
93
|
+
ThreeView<DefaultDescriptions>,
|
|
94
|
+
ViewContext
|
|
95
|
+
> {
|
|
96
|
+
private view?: ThreeView<DefaultDescriptions>;
|
|
97
|
+
|
|
98
|
+
async init(view: ThreeView<DefaultDescriptions>, _ctx: ViewContext) {
|
|
99
|
+
this.view = view;
|
|
100
|
+
|
|
101
|
+
// Register meshes
|
|
102
|
+
view.registerMesh("rain", RainMeshDesc);
|
|
103
|
+
view.registerMesh("snow", SnowMeshDesc);
|
|
104
|
+
view.registerMesh("sky", SkyMeshDesc);
|
|
105
|
+
view.registerMesh("skyBox", SkyBoxMeshDesc);
|
|
106
|
+
view.registerMesh("stars", StarsDesc);
|
|
107
|
+
view.registerMesh("box", BoxMeshDesc);
|
|
108
|
+
view.registerMesh("sphere", SphereMeshDesc);
|
|
109
|
+
view.registerMesh("glowGlobe", GlowGlobeMeshDesc);
|
|
110
|
+
view.registerMesh("cylinder", CylinderMeshDesc);
|
|
111
|
+
view.registerMesh("tube", TubeMeshDesc);
|
|
112
|
+
view.registerMesh("plane", PlaneMeshDesc);
|
|
113
|
+
view.registerMesh("gltfModel", GLTFModelDesc);
|
|
114
|
+
view.registerMesh("splat", SplatMeshDesc);
|
|
115
|
+
view.registerMesh("axesHelper", AxesHelperDesc);
|
|
116
|
+
view.registerMesh("arrowHelper", ArrowHelperDesc);
|
|
117
|
+
view.registerMesh("arcLines", ArclineMeshDesc);
|
|
118
|
+
view.registerMesh("smoothLines", SmoothLineMeshDesc);
|
|
119
|
+
view.registerMesh("boxes", InstancedBoxMeshDesc);
|
|
120
|
+
view.registerMesh("spheres", InstancedSphereMeshDesc);
|
|
121
|
+
view.registerMesh("planes", InstancedPlaneMeshDesc);
|
|
122
|
+
view.registerMesh("cylinders", InstancedCylinderMeshDesc);
|
|
123
|
+
view.registerMesh("gltfModels", InstancedGltfModelMeshDesc);
|
|
124
|
+
|
|
125
|
+
// Register lights
|
|
126
|
+
view.registerLight("sun", SunLightDesc);
|
|
127
|
+
view.registerLight("ambient", AmbientLightDesc);
|
|
128
|
+
view.registerLight("skyLightProbe", SkyLightProbeDesc);
|
|
129
|
+
view.registerLight("lightProbe", LightProbeDesc);
|
|
130
|
+
|
|
131
|
+
// Register effects
|
|
132
|
+
view.registerEffect("aerialPerspective", AerialPerspectiveEffectDesc);
|
|
133
|
+
view.registerEffect("rainDrop", RainDropEffectDesc);
|
|
134
|
+
view.registerEffect("selectiveBloom", SelectiveBloomEffectDesc);
|
|
135
|
+
view.registerEffect("selectiveOutline", SelectiveOutlineEffectDesc);
|
|
136
|
+
view.registerEffect("clouds", CloudsEffectDesc);
|
|
137
|
+
view.registerEffect("fogLight", FogLightEffectDesc);
|
|
138
|
+
view.registerEffect("lensFlare", LensFlareEffectDesc);
|
|
139
|
+
view.registerEffect("ssao", SSAOEffectDesc);
|
|
140
|
+
view.registerEffect("ssr", SSREffectDesc);
|
|
141
|
+
view.registerEffect("depthOfField", DepthOfFieldEffectDesc);
|
|
142
|
+
view.registerEffect("colorGradingLUT", ColorGradingLUTEffectDesc);
|
|
143
|
+
view.registerEffect("toneMapping", ToneMappingEffectDesc);
|
|
144
|
+
view.registerEffect("smaa", SMAAEffectDesc);
|
|
145
|
+
view.registerEffect("fxaa", FXAAEffectDesc);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Add default descriptors automatically to make the photorealistic scene.
|
|
150
|
+
* This method must be invoked after `view.init()`.
|
|
151
|
+
*/
|
|
152
|
+
addDefaultPhotorealScene(): {
|
|
153
|
+
sky: MeshHandle<SkyMeshDesc>;
|
|
154
|
+
stars: MeshHandle<StarsDesc>;
|
|
155
|
+
skyLightProbe: LightHandle<SkyLightProbeDesc>;
|
|
156
|
+
sun: LightHandle<SunLightDesc>;
|
|
157
|
+
aerialPerspective: EffectHandle<AerialPerspectiveEffectDesc>;
|
|
158
|
+
lensFlare: EffectHandle<LensFlareEffectDesc> | undefined;
|
|
159
|
+
toneMapping: EffectHandle<ToneMappingEffectDesc>;
|
|
160
|
+
antialiasing: EffectHandle<SMAAEffectDesc> | EffectHandle<FXAAEffectDesc>;
|
|
161
|
+
} {
|
|
162
|
+
if (!this.view) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
"DefaultPlugin is not initialized. Call view.addPlugin() and view.init() first.",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const view = this.view;
|
|
169
|
+
const mobile = view.isMobileOptimized();
|
|
170
|
+
|
|
171
|
+
// Meshes
|
|
172
|
+
const sky = view.addMesh<SkyMeshDesc>({
|
|
173
|
+
sky: {},
|
|
174
|
+
});
|
|
175
|
+
const stars = view.addMesh<StarsDesc>({
|
|
176
|
+
stars: {},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Lights
|
|
180
|
+
const skyLightProbe = view.addLight<SkyLightProbeDesc>({
|
|
181
|
+
skyLightProbe: {},
|
|
182
|
+
});
|
|
183
|
+
const sun = view.addLight<SunLightDesc>({
|
|
184
|
+
sun: {},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Effects
|
|
188
|
+
const aerialPerspective = view.addEffect<AerialPerspectiveEffectDesc>({
|
|
189
|
+
aerialPerspective: {},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Skip lens flare on mobile - expensive effect with limited benefit
|
|
193
|
+
const lensFlare = mobile
|
|
194
|
+
? undefined
|
|
195
|
+
: view.addEffect<LensFlareEffectDesc>({
|
|
196
|
+
lensFlare: {},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const toneMapping = view.addEffect<ToneMappingEffectDesc>({
|
|
200
|
+
toneMapping: {},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Use FXAA on mobile (faster), SMAA on desktop (higher quality)
|
|
204
|
+
const antialiasing = mobile
|
|
205
|
+
? view.addEffect<FXAAEffectDesc>({
|
|
206
|
+
fxaa: {},
|
|
207
|
+
})
|
|
208
|
+
: view.addEffect<SMAAEffectDesc>({
|
|
209
|
+
smaa: {},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
sky,
|
|
214
|
+
stars,
|
|
215
|
+
skyLightProbe,
|
|
216
|
+
sun,
|
|
217
|
+
aerialPerspective,
|
|
218
|
+
lensFlare,
|
|
219
|
+
toneMapping,
|
|
220
|
+
antialiasing,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export type DefaultDescriptions = {
|
|
226
|
+
mesh: DefaultMeshDescription;
|
|
227
|
+
light: DefaultLightDescription;
|
|
228
|
+
effect: DefaultEffectDescription;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export type DefaultLightDescription =
|
|
232
|
+
SunLightConfig | SkyLightProbeConfig | AmbientLightConfig | LightProbeConfig;
|
|
233
|
+
|
|
234
|
+
export type DefaultEffectDescription =
|
|
235
|
+
| AerialPerspectiveConfig
|
|
236
|
+
| CloudsConfig
|
|
237
|
+
| ColorGradingLUTConfig
|
|
238
|
+
| DepthOfFieldConfig
|
|
239
|
+
| FogLightConfig
|
|
240
|
+
| FXAAConfig
|
|
241
|
+
| LensFlareConfig
|
|
242
|
+
| RainDropConfig
|
|
243
|
+
| SelectiveBloomEffectConfig
|
|
244
|
+
| SelectiveOutlineEffectConfig
|
|
245
|
+
| SMAAConfig
|
|
246
|
+
| SSAOConfig
|
|
247
|
+
| SSRConfig
|
|
248
|
+
| ToneMappingConfig;
|
|
249
|
+
|
|
250
|
+
export type DefaultMeshDescription =
|
|
251
|
+
| RainMeshConfig
|
|
252
|
+
| SnowMeshConfig
|
|
253
|
+
| SkyMeshConfig
|
|
254
|
+
| SkyBoxMeshConfig
|
|
255
|
+
| StarsConfig
|
|
256
|
+
| BoxMeshConfig
|
|
257
|
+
| SphereMeshConfig
|
|
258
|
+
| GlowGlobeMeshConfig
|
|
259
|
+
| CylinderMeshConfig
|
|
260
|
+
| TubeMeshConfig
|
|
261
|
+
| PlaneMeshConfig
|
|
262
|
+
| GLTFModelConfig
|
|
263
|
+
| SplatMeshConfig
|
|
264
|
+
| AxesHelperConfig
|
|
265
|
+
| ArrowHelperConfig
|
|
266
|
+
| ArclineMeshConfig
|
|
267
|
+
| SmoothLineMeshConfig
|
|
268
|
+
| InstancedBoxMeshConfig
|
|
269
|
+
| InstancedSphereMeshConfig
|
|
270
|
+
| InstancedPlaneMeshConfig
|
|
271
|
+
| InstancedCylinderMeshConfig
|
|
272
|
+
| InstancedGltfModelMeshConfig;
|