retiam 1.0.0 → 1.0.2

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.
@@ -1,6 +1,6 @@
1
1
  import { Color } from '../math/Color';
2
2
  import { SubTexture } from '../loader/SubTexture';
3
- import { ShadingStyle } from '../render/RenderConfig';
3
+ import { Shading, ShadingStyle } from '../material/shading';
4
4
  export type TextureSource = string | ImageBitmap | HTMLCanvasElement | OffscreenCanvas | HTMLImageElement | HTMLVideoElement | HTMLElement | SubTexture;
5
5
  /**
6
6
  * Bitmask flags to track which material properties were explicitly set by the user.
@@ -21,8 +21,7 @@ export declare enum MaterialFlags {
21
21
  ALBEDO_IDX = 2048,
22
22
  NORMAL_IDX = 4096,
23
23
  NORMAL_SCALE = 8192,
24
- SHADING_STYLE = 16384,
25
- STYLE_PARAMS = 32768
24
+ SHADING_STYLE = 16384
26
25
  }
27
26
  /**
28
27
  * Manages rendering material parameters (reflectance, roughness, metallic, normal scaling) for an [[Entity]],
@@ -52,6 +51,7 @@ export declare class Material {
52
51
  readonly _emColor: Float32Array;
53
52
  private _albedoMap?;
54
53
  private _normalMap?;
54
+ private _shading;
55
55
  /**
56
56
  * Creates a new Material instance.
57
57
  *
@@ -151,22 +151,17 @@ export declare class Material {
151
151
  setSpecular(v: number): Material;
152
152
  /** Sets the normal map scale strength. */
153
153
  setNormalScale(v: number): Material;
154
- /** Shading style override for this material (-1: inherit from RenderConfig, 0: PBR, 1: Gooch, 2: Cel, 3: Clay). */
154
+ /** Surface lighting override. Null inherits the parent material or scene default. */
155
+ get shading(): Shading | null;
156
+ set shading(value: Shading | null);
157
+ /** Selects a shading model using its name, or -1 to inherit. */
155
158
  get shadingStyle(): ShadingStyle | number;
156
- set shadingStyle(v: ShadingStyle | number);
157
- get goochWarm(): number;
158
- set goochWarm(v: number);
159
- get goochCool(): number;
160
- set goochCool(v: number);
161
- get celBands(): number;
162
- set celBands(v: number);
163
- get rimStrength(): number;
164
- set rimStrength(v: number);
165
- get rimPower(): number;
166
- set rimPower(v: number);
167
- setShadingStyle(v: ShadingStyle | number): Material;
168
- setGooch(warm?: number, cool?: number): Material;
169
- setCel(bands?: number, rimStrength?: number): Material;
159
+ set shadingStyle(value: ShadingStyle | number);
160
+ setShadingStyle(value: ShadingStyle | number): this;
161
+ setGooch(warm?: number, cool?: number): this;
162
+ setCel(bands?: number, rimStrength?: number, rimPower?: number): this;
163
+ /** Numeric settings interpolate within a model; model changes happen at the endpoint. */
164
+ interpolateShading(start: Material, target: Material, t: number): void;
170
165
  /** Clones this material instance. */
171
166
  copy(): Material;
172
167
  clone(): Material;
@@ -11,6 +11,7 @@ import { Entity } from './Entity';
11
11
  import { Compute, ComputeCommand } from '../compute/Compute';
12
12
  import { RenderCommand } from './SceneInterface';
13
13
  import { RenderConfig } from '../render/RenderConfig';
14
+ import { Shading } from '../material/shading';
14
15
  import { Pass } from '../render/frame_graph/Pass';
15
16
  import { GroupAnimator } from '../animation/GroupAnimator';
16
17
  import { SnapshotManager } from './SnapshotManager';
@@ -386,6 +387,8 @@ export declare class Scene {
386
387
  */
387
388
  onAfterReset(): void;
388
389
  enableFrameFeedback(): FrameFeedbackFeature;
390
+ /** Default surface lighting for this scene; individual materials can override it. */
391
+ shading: Shading;
389
392
  _renderConfig: RenderConfig;
390
393
  get renderConfig(): RenderConfig;
391
394
  addCompute(...compute_commands: ComputeCommand[]): void;
@@ -1,8 +1,10 @@
1
1
  import { Scene } from './Scene';
2
+ import { Shading } from '../material/shading';
2
3
  export interface EntitySnapshot {
3
4
  id: number;
4
5
  visibility: boolean;
5
6
  stateData: Float32Array;
7
+ shading?: Shading | null;
6
8
  }
7
9
  export interface AnimationSnapshot {
8
10
  type: string;
@@ -30,6 +32,7 @@ export interface SceneSnapshot {
30
32
  entities: EntitySnapshot[];
31
33
  animations: AnimationSnapshot[];
32
34
  isPaused: boolean;
35
+ shading?: Shading;
33
36
  }
34
37
  /**
35
38
  * Manages deterministic scene state checkpoints and snapshots.
@@ -6,13 +6,8 @@ export declare class ModelFragment extends FragmentComponent {
6
6
  private _lastShadowState;
7
7
  private _lastShadowMethod;
8
8
  private _lastLightSize;
9
- private _lastShadingStyle;
9
+ private _shading;
10
10
  private _lastIsTransparent;
11
- private _lastGoochWarm;
12
- private _lastGoochCool;
13
- private _lastCelBands;
14
- private _lastCelRimStrength;
15
- private _lastCelRimPower;
16
11
  prepare(scene: Scene, state?: State): void;
17
12
  setup(builder: ShaderBuilder, passName: string): void;
18
13
  isPassActive(passName: string, state: State): boolean;
@@ -0,0 +1,16 @@
1
+ import { Shading } from './Shading';
2
+ export interface CelShadingOptions {
3
+ bands?: number;
4
+ rimStrength?: number;
5
+ rimPower?: number;
6
+ }
7
+ /** Cartoon lighting bands with an optional silhouette highlight. */
8
+ export declare class CelShading extends Shading {
9
+ bands: number;
10
+ rimStrength: number;
11
+ rimPower: number;
12
+ constructor({ bands, rimStrength, rimPower }?: CelShadingOptions);
13
+ writeParameters(target: Float32Array, offset: number): void;
14
+ interpolate(start: CelShading, target: CelShading, t: number): void;
15
+ clone(): CelShading;
16
+ }
@@ -0,0 +1,6 @@
1
+ import { Shading } from './Shading';
2
+ /** Matte studio lighting for inspecting shapes. */
3
+ export declare class ClayShading extends Shading {
4
+ constructor();
5
+ clone(): ClayShading;
6
+ }
@@ -0,0 +1,14 @@
1
+ import { Shading } from './Shading';
2
+ export interface GoochShadingOptions {
3
+ warm?: number;
4
+ cool?: number;
5
+ }
6
+ /** Warm/cool lighting for technical illustrations. */
7
+ export declare class GoochShading extends Shading {
8
+ warm: number;
9
+ cool: number;
10
+ constructor({ warm, cool }?: GoochShadingOptions);
11
+ writeParameters(target: Float32Array, offset: number): void;
12
+ interpolate(start: GoochShading, target: GoochShading, t: number): void;
13
+ clone(): GoochShading;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { Shading } from './Shading';
2
+ /** Physically based surface lighting using the material's roughness and metallic values. */
3
+ export declare class PBRShading extends Shading {
4
+ constructor();
5
+ clone(): PBRShading;
6
+ }
@@ -0,0 +1,17 @@
1
+ export declare enum ShadingStyle {
2
+ PBR = "pbr",
3
+ GOOCH = "gooch",
4
+ CEL = "cel",
5
+ CLAY = "clay"
6
+ }
7
+ /** A surface lighting model. Numeric parameters are written to the material GPU buffer. */
8
+ export declare abstract class Shading {
9
+ readonly style: ShadingStyle;
10
+ readonly chunk: string;
11
+ readonly fragment: string;
12
+ protected constructor(style: ShadingStyle, chunk: string, fragment: string);
13
+ writeParameters(target: Float32Array, offset: number): void;
14
+ /** Interpolate numeric settings between two instances of this lighting model. */
15
+ interpolate(start: Shading, target: Shading, t: number): void;
16
+ abstract clone(): Shading;
17
+ }
@@ -0,0 +1,5 @@
1
+ export { Shading, ShadingStyle } from './Shading';
2
+ export { PBRShading } from './PBRShading';
3
+ export { CelShading, type CelShadingOptions } from './CelShading';
4
+ export { GoochShading, type GoochShadingOptions } from './GoochShading';
5
+ export { ClayShading } from './ClayShading';
@@ -17,12 +17,7 @@ export declare enum DenoiserType {
17
17
  OIDN = "oidn",
18
18
  NATIVE = "native"
19
19
  }
20
- export declare enum ShadingStyle {
21
- PBR = "pbr",
22
- GOOCH = "gooch",
23
- CEL = "cel",
24
- CLAY = "clay"
25
- }
20
+ export { ShadingStyle } from '../material/shading/Shading';
26
21
  export declare enum ShadowMethod {
27
22
  PCF = "pcf",
28
23
  PCSS = "pcss"
@@ -37,12 +32,6 @@ export declare class RenderConfig {
37
32
  shadowMethod: ShadowMethod;
38
33
  lightSize: number;
39
34
  frustumCulling: boolean;
40
- shadingStyle: ShadingStyle;
41
- celBands: number;
42
- celRimStrength: number;
43
- celRimPower: number;
44
- goochWarm: number;
45
- goochCool: number;
46
35
  raytraceEnabled: boolean;
47
36
  rtSamples: number;
48
37
  rtMaxAccumulation: number;
@@ -51,15 +40,4 @@ export declare class RenderConfig {
51
40
  bounce_count: number;
52
41
  denoiser: DenoiserType;
53
42
  oidnModel: string;
54
- /** Apply Cel/Toon shading with optional parameters. Chainable. */
55
- setCel(options?: {
56
- bands?: number;
57
- rimStrength?: number;
58
- rimPower?: number;
59
- }): this;
60
- /** Apply Gooch technical illustration shading. Chainable. */
61
- setGooch(options?: {
62
- warm?: number;
63
- cool?: number;
64
- }): this;
65
43
  }
@@ -436,3 +436,4 @@ export * from './engine/utils/SubdivisionEngine';
436
436
  export * from './engine/utils/Utility';
437
437
  export * from './engine/utils/gpu_utils';
438
438
  export * from './plugins/OutlinePlugin';
439
+ export * from './engine/material/shading';
package/package.json CHANGED
@@ -1,117 +1,108 @@
1
- {
2
- "name": "retiam",
3
- "version": "1.0.0",
4
- "description": "WebGPU powered animation engine",
5
- "type": "module",
6
- "main": "./dist/retiam.es.js",
7
- "module": "./dist/retiam.es.js",
8
- "types": "./dist/src/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/src/index.d.ts",
12
- "import": "./dist/retiam.es.js"
13
- },
14
- "./dist/assets/*": "./dist/assets/*",
15
- "./*": {
16
- "types": "./dist/libs/*/index.d.ts",
17
- "import": "./dist/libs/*/index.js"
18
- }
19
- },
20
- "bin": {
21
- "retiam": "./bin/cli.js"
22
- },
23
- "files": [
24
- "dist/*.js",
25
- "dist/assets/**",
26
- "dist/libs/**/*.js",
27
- "dist/libs/**/*.d.ts",
28
- "dist/src/**/*.d.ts",
29
- "bin"
30
- ],
31
- "scripts": {
32
- "dev": "vite",
33
- "build": "tsc && vite build",
34
- "prepack": "npm run build",
35
- "build:watch": "vite build --watch",
36
- "export": "node ./bin/cli.js export",
37
- "render": "node ./bin/cli.js render",
38
- "lint:scene": "node ./bin/cli.js lint",
39
- "snapshot": "node ./bin/cli.js snapshot",
40
- "init": "node ./bin/cli.js init",
41
- "create": "node ./bin/cli.js create",
42
- "cdn": "vite preview",
43
- "start": "npm run dev",
1
+ {
2
+ "name": "retiam",
3
+ "version": "1.0.2",
4
+ "description": "WebGPU powered animation engine",
5
+ "type": "module",
6
+ "main": "./dist/retiam.es.js",
7
+ "module": "./dist/retiam.es.js",
8
+ "types": "./dist/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/src/index.d.ts",
12
+ "import": "./dist/retiam.es.js"
13
+ },
14
+ "./dist/assets/*": "./dist/assets/*",
15
+ "./*": {
16
+ "types": "./dist/libs/*/index.d.ts",
17
+ "import": "./dist/libs/*/index.js"
18
+ }
19
+ },
20
+ "bin": {
21
+ "retiam": "./bin/cli.js"
22
+ },
23
+ "files": [
24
+ "dist/*.js",
25
+ "dist/assets/**",
26
+ "dist/libs/**/*.js",
27
+ "dist/libs/**/*.d.ts",
28
+ "dist/src/**/*.d.ts",
29
+ "bin"
30
+ ],
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "build": "tsc && vite build",
34
+ "prepack": "npm run build",
35
+ "build:watch": "vite build --watch",
36
+ "export": "node ./bin/cli.js export",
37
+ "render": "node ./bin/cli.js render",
38
+ "lint:scene": "node ./bin/cli.js lint",
39
+ "snapshot": "node ./bin/cli.js snapshot",
40
+ "init": "node ./bin/cli.js init",
41
+ "create": "node ./bin/cli.js create",
42
+ "cdn": "vite preview",
43
+ "start": "npm run dev",
44
44
  "resolve": "npm i",
45
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
46
- "test:distribution": "node --import tsx --test test/library_portability_test.ts test/package_contents_test.mjs",
47
- "unit-test": "ts-node-esm test/test.ts",
48
- "gen-context": "ts-node tools/context_gen/context_generator.ts ./src",
49
- "gen-index": "node ./tools/index_generator/generate-index.cjs"
50
- },
51
- "author": "Abhilas Biswas",
52
- "license": "ISC",
53
- "devDependencies": {
54
- "@lightningjs/msdf-generator": "^1.1.1",
55
- "@types/earcut": "^3.0.0",
56
- "@types/events": "^3.0.3",
57
- "@types/integer": "^4.0.3",
58
- "@types/jest": "^29.5.12",
59
- "@types/matter-js": "^0.20.2",
60
- "@types/node": "^22.2.0",
61
- "@webgpu/types": "^0.1.31",
62
- "jest": "^29.7.0",
63
- "msdf-atlas-gen": "^1.0.0",
64
- "msdf-bmfont-xml": "^2.7.0",
65
- "puppeteer": "^21.11.0",
66
- "roughjs": "^4.6.6",
67
- "ts-jest": "^29.1.2",
68
- "ts-node": "^10.9.2",
69
- "tsx": "^4.22.4",
70
- "vite-plugin-dts": "^5.0.1",
71
- "vite-plugin-mkcert": "^2.0.0"
72
- },
73
- "peerDependencies": {
74
- "roughjs": "^4.6.6",
75
- "puppeteer": ">=21"
76
- },
77
- "peerDependenciesMeta": {
78
- "roughjs": {
79
- "optional": true
80
- },
81
- "puppeteer": {
82
- "optional": true
83
- }
84
- },
85
- "dependencies": {
86
- "@dimforge/rapier2d-compat": "^0.20.0",
87
- "@dimforge/rapier3d-compat": "^0.20.0",
88
- "@types/libtess": "^1.2.0",
89
- "@types/prismjs": "^1.26.6",
90
- "@zappar/msdf-generator": "^1.2.4",
91
- "box3d-wasm": "^0.2.0",
92
- "cli-progress": "^3.12.0",
93
- "earcut": "^3.0.2",
94
- "events": "^3.3.0",
95
- "extrude-polyline": "^1.0.6",
96
- "jolt-physics": "^1.1.0",
97
- "libtess": "^1.2.2",
98
- "mathjax-full": "^3.2.2",
99
- "matter-js": "^0.20.0",
100
- "mp4-muxer": "^5.2.2",
101
- "msedge-tts": "^2.0.8",
102
- "oidn-web": "^0.3.5",
103
- "opentype.js": "^1.3.4",
104
- "path-data-parser": "^0.1.0",
105
- "planck": "^1.5.0",
106
- "polygon-clipping": "^0.15.7",
107
- "prismjs": "^1.30.0",
108
- "svg-parser": "^2.0.4",
109
- "svg-pathdata": "^7.0.0",
110
- "typescript": "^5.4.5",
111
- "vite": "^6.1.1",
112
- "webm-muxer": "^5.1.4",
113
- "wgsl_reflect": "^1.2.3",
114
- "woff2-encoder": "^2.0.0",
115
- "ws": "^8.16.0"
116
- }
117
- }
45
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
46
+ "test:distribution": "node --import tsx --test test/library_portability_test.ts test/package_contents_test.mjs test/render_config_test.mjs",
47
+ "test:create": "node --test test/create_retiam_test.mjs",
48
+ "test:shading": "npm run build && node --test test/shading_test.mjs test/shading_browser.test.mjs",
49
+ "test:studio-layout": "node --test test/studio_layout.test.mjs",
50
+ "unit-test": "ts-node-esm test/test.ts",
51
+ "gen-context": "ts-node tools/context_gen/context_generator.ts ./src",
52
+ "gen-index": "node ./tools/index_generator/generate-index.cjs"
53
+ },
54
+ "author": "Abhilas Biswas",
55
+ "license": "ISC",
56
+ "devDependencies": {
57
+ "@lightningjs/msdf-generator": "^1.1.1",
58
+ "@types/earcut": "^3.0.0",
59
+ "@types/events": "^3.0.3",
60
+ "@types/integer": "^4.0.3",
61
+ "@types/jest": "^29.5.12",
62
+ "@types/matter-js": "^0.20.2",
63
+ "@types/node": "^22.2.0",
64
+ "@webgpu/types": "^0.1.31",
65
+ "jest": "^29.7.0",
66
+ "msdf-atlas-gen": "^1.0.0",
67
+ "msdf-bmfont-xml": "^2.7.0",
68
+ "ts-jest": "^29.1.2",
69
+ "ts-node": "^10.9.2",
70
+ "tsx": "^4.22.4",
71
+ "vite-plugin-dts": "^5.0.1",
72
+ "vite-plugin-mkcert": "^2.0.0"
73
+ },
74
+ "dependencies": {
75
+ "@dimforge/rapier2d-compat": "^0.20.0",
76
+ "@dimforge/rapier3d-compat": "^0.20.0",
77
+ "@types/libtess": "^1.2.0",
78
+ "@types/prismjs": "^1.26.6",
79
+ "@zappar/msdf-generator": "^1.2.4",
80
+ "box3d-wasm": "^0.2.0",
81
+ "cli-progress": "^3.12.0",
82
+ "earcut": "^3.0.2",
83
+ "events": "^3.3.0",
84
+ "extrude-polyline": "^1.0.6",
85
+ "jolt-physics": "^1.1.0",
86
+ "libtess": "^1.2.2",
87
+ "mathjax-full": "^3.2.2",
88
+ "matter-js": "^0.20.0",
89
+ "mp4-muxer": "^5.2.2",
90
+ "msedge-tts": "^2.0.8",
91
+ "oidn-web": "^0.3.5",
92
+ "opentype.js": "^1.3.4",
93
+ "path-data-parser": "^0.1.0",
94
+ "planck": "^1.5.0",
95
+ "polygon-clipping": "^0.15.7",
96
+ "prismjs": "^1.30.0",
97
+ "puppeteer": "^21.11.0",
98
+ "roughjs": "^4.6.6",
99
+ "svg-parser": "^2.0.4",
100
+ "svg-pathdata": "^7.0.0",
101
+ "typescript": "^5.4.5",
102
+ "vite": "^6.1.1",
103
+ "webm-muxer": "^5.1.4",
104
+ "wgsl_reflect": "^1.2.3",
105
+ "woff2-encoder": "^2.0.0",
106
+ "ws": "^8.16.0"
107
+ }
108
+ }