@forgeax/engine-debug-draw 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +256 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/errors.test-d.d.ts +2 -0
  5. package/dist/__tests__/errors.test-d.d.ts.map +1 -0
  6. package/dist/constants.d.ts +7 -0
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/debug-draw.d.ts +65 -0
  9. package/dist/debug-draw.d.ts.map +1 -0
  10. package/dist/errors.d.ts +65 -0
  11. package/dist/errors.d.ts.map +1 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.mjs +835 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/shapes/aabb.d.ts +4 -0
  17. package/dist/shapes/aabb.d.ts.map +1 -0
  18. package/dist/shapes/arrow.d.ts +11 -0
  19. package/dist/shapes/arrow.d.ts.map +1 -0
  20. package/dist/shapes/axes.d.ts +18 -0
  21. package/dist/shapes/axes.d.ts.map +1 -0
  22. package/dist/shapes/frustum.d.ts +7 -0
  23. package/dist/shapes/frustum.d.ts.map +1 -0
  24. package/dist/shapes/line.d.ts +4 -0
  25. package/dist/shapes/line.d.ts.map +1 -0
  26. package/dist/shapes/sphere.d.ts +7 -0
  27. package/dist/shapes/sphere.d.ts.map +1 -0
  28. package/dist/types.d.ts +136 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/package.json +61 -0
  31. package/src/__tests__/errors.test-d.ts +89 -0
  32. package/src/constants.ts +13 -0
  33. package/src/debug-draw.ts +713 -0
  34. package/src/errors.ts +142 -0
  35. package/src/index.ts +14 -0
  36. package/src/shapes/aabb.ts +57 -0
  37. package/src/shapes/arrow.ts +75 -0
  38. package/src/shapes/axes.ts +60 -0
  39. package/src/shapes/frustum.ts +182 -0
  40. package/src/shapes/line.ts +14 -0
  41. package/src/shapes/sphere.ts +74 -0
  42. package/src/types.ts +176 -0
@@ -0,0 +1,65 @@
1
+ import type { ColorLike, Mat4, Vec3 } from '@forgeax/engine-math';
2
+ import type { BindGroup, Buffer, RenderPipeline, RhiCommandEncoder, RhiDevice, RhiRenderPassEncoder, TextureView } from '@forgeax/engine-rhi';
3
+ import type { Result } from '@forgeax/engine-types';
4
+ import type { DebugDrawError } from './errors';
5
+ import type { DebugDraw as DebugDrawInterface, DebugDrawOptions } from './types';
6
+ export declare class DebugDraw implements DebugDrawInterface {
7
+ private stagingArr;
8
+ private stagingLen;
9
+ private lastFlushedVertexCount;
10
+ private capVal;
11
+ private gpuVbo;
12
+ private gpuPipeline;
13
+ private gpuUniformBuffer;
14
+ private gpuBindGroup;
15
+ private maxCapVal;
16
+ private readonly rhiDevice;
17
+ private isDestroyed;
18
+ private destroyedWarnedOnce;
19
+ private truncationWarned;
20
+ /**
21
+ * Depth texture view for less-equal depth mode.
22
+ * Set via {@link _setDepthView} before flush() when depthMode is 'less-equal'.
23
+ * The runtime auto-attach path receives depth from the render-graph context;
24
+ * low-path callers (test harnesses, smoke runners) set this explicitly.
25
+ */
26
+ private depthView;
27
+ constructor(device: RhiDevice, pipeline: RenderPipeline, vbo: Buffer, uniformBuffer: Buffer, bindGroup: BindGroup, initialCapacity: number, maxCapacity: number);
28
+ /** @internal CPU staging vertex count (exposed for unit tests). */
29
+ get _stagingVertexCount(): number;
30
+ hasPendingWork(): boolean;
31
+ /** @internal Vertex count passed to the most recent non-empty draw call. */
32
+ get _lastFlushVertexCount(): number;
33
+ /** @internal Current GPU vertex buffer capacity in vertex count. */
34
+ get _capacity(): number;
35
+ /** @internal Whether destroy() has been called. */
36
+ get _destroyed(): boolean;
37
+ /**
38
+ * @internal Set the depth texture view for less-equal depth mode.
39
+ * Required before flush() when depthMode is 'less-equal'.
40
+ * Used by test harnesses and smoke runners that don't have a scene
41
+ * depth buffer; the runtime auto-attach path receives depth from
42
+ * the render-graph context.
43
+ */
44
+ _setDepthView(view: TextureView): void;
45
+ /** @internal Read position of vertex at `index` in CPU staging (for unit tests). */
46
+ _getVertexPosition(index: number): [number, number, number];
47
+ /** @internal Read color of vertex at `index` as packed u32 (for unit tests). */
48
+ _getVertexPackedColor(index: number): number;
49
+ private postDestroyWarnOnce;
50
+ private pushVertex;
51
+ private warnTruncationOnce;
52
+ private ensureCapacity;
53
+ private colorToRGBA;
54
+ line(a: Vec3, b: Vec3, color: ColorLike): void;
55
+ aabb(min: Vec3, max: Vec3, color: ColorLike): void;
56
+ sphere(center: Vec3, radius: number, color: ColorLike, segments?: number): void;
57
+ frustum(viewProj: Mat4, color: ColorLike): void;
58
+ arrow(start: Vec3, end: Vec3, color: ColorLike, tipLength?: number): void;
59
+ axes(worldMat: Mat4, length: number): void;
60
+ flush(encoder: RhiCommandEncoder, view: TextureView, viewProj: Mat4): Result<void, DebugDrawError>;
61
+ encode(pass: RhiRenderPassEncoder, viewProj: Mat4): Result<void, DebugDrawError>;
62
+ destroy(): void;
63
+ }
64
+ export declare function createDebugDraw(opts: DebugDrawOptions): Promise<Result<DebugDraw, DebugDrawError>>;
65
+ //# sourceMappingURL=debug-draw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-draw.d.ts","sourceRoot":"","sources":["../src/debug-draw.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAa/C,OAAO,KAAK,EAAE,SAAS,IAAI,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;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IAS1B,OAAO,CAAC,cAAc;IA+CtB,OAAO,CAAC,WAAW;IAUnB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAY9C,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAalD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,SAAK,GAAG,IAAI;IAa3E,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAmB/C,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAazE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAkB1C,KAAK,CACH,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,IAAI,GACb,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC;IAyC/B,MAAM,CAAC,IAAI,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC;IAwChF,OAAO,IAAI,IAAI;CAoBhB;AAMD,wBAAsB,eAAe,CACnC,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAgL5C"}
@@ -0,0 +1,65 @@
1
+ import { type Result } from '@forgeax/engine-types';
2
+ /** {@link pipeline-create-failed} payload: carries the RHI-level error detail. */
3
+ export interface PipelineCreateFailedDetail {
4
+ readonly code: 'pipeline-create-failed';
5
+ readonly rhiError: string;
6
+ }
7
+ /** {@link buffer-allocation-failed} payload: carries the RHI-level error detail. */
8
+ export interface BufferAllocationFailedDetail {
9
+ readonly code: 'buffer-allocation-failed';
10
+ readonly rhiError: string;
11
+ }
12
+ /** {@link flushed-after-destroy} payload: carries the instance identifier. */
13
+ export interface FlushedAfterDestroyDetail {
14
+ readonly code: 'flushed-after-destroy';
15
+ }
16
+ /** {@link viewProj-required} payload: carries the missing parameter name. */
17
+ export interface ViewProjRequiredDetail {
18
+ readonly code: 'viewProj-required';
19
+ }
20
+ interface DebugDrawErrorDetailByCode {
21
+ 'pipeline-create-failed': PipelineCreateFailedDetail;
22
+ 'buffer-allocation-failed': BufferAllocationFailedDetail;
23
+ 'flushed-after-destroy': FlushedAfterDestroyDetail;
24
+ 'viewProj-required': ViewProjRequiredDetail;
25
+ }
26
+ /**
27
+ * Closed {@link DebugDrawErrorCode} union.
28
+ * Exhaustive `switch (err.code)` needs no default fallback.
29
+ *
30
+ * | code | trigger |
31
+ * |:--|:--|
32
+ * | `'pipeline-create-failed'` | `device.createRenderPipeline(...)` rejected or threw |
33
+ * | `'buffer-allocation-failed'` | `device.createBuffer(...)` for GPU vbo allocation failed |
34
+ * | `'flushed-after-destroy'` | `flush()` called on an already-destroyed DebugDraw instance |
35
+ * | `'viewProj-required'` | `flush()` called with `undefined` or missing `viewProj` |
36
+ */
37
+ export type DebugDrawErrorCode = keyof DebugDrawErrorDetailByCode;
38
+ /**
39
+ * Discriminated detail union for {@link DebugDrawError}, narrowed per
40
+ * `DebugDrawError.code`. AI users obtain the concrete shape via
41
+ * `switch (err.code)` without a fallback `as` cast.
42
+ */
43
+ export type DebugDrawErrorDetail = DebugDrawErrorDetailByCode[DebugDrawErrorCode];
44
+ /**
45
+ * Structured debug-draw error -- four-field surface
46
+ * (`.code` / `.expected` / `.hint` / `.detail`).
47
+ *
48
+ * AI users consume the structured triple by fields, not by parsing `.message`.
49
+ */
50
+ type DebugDrawErrorVariant<C extends DebugDrawErrorCode> = {
51
+ readonly code: C;
52
+ readonly expected: string;
53
+ readonly hint: string;
54
+ readonly detail: DebugDrawErrorDetailByCode[C];
55
+ };
56
+ export type DebugDrawError = {
57
+ [C in DebugDrawErrorCode]: DebugDrawErrorVariant<C>;
58
+ }[DebugDrawErrorCode];
59
+ /** Result-returning helpers consuming engine-types `Result<T, E>` + `err()`. */
60
+ export declare function pipelineCreateFailed(rhiError: string): Result<never, DebugDrawError>;
61
+ export declare function bufferAllocationFailed(rhiError: string): Result<never, DebugDrawError>;
62
+ export declare function flushedAfterDestroy(): Result<never, DebugDrawError>;
63
+ export declare function viewProjRequired(): Result<never, DebugDrawError>;
64
+ export {};
65
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAWA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEzD,kFAAkF;AAClF,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,oFAAoF;AACpF,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,8EAA8E;AAC9E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;CACxC;AAED,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;CACpC;AAED,UAAU,0BAA0B;IAClC,wBAAwB,EAAE,0BAA0B,CAAC;IACrD,0BAA0B,EAAE,4BAA4B,CAAC;IACzD,uBAAuB,EAAE,yBAAyB,CAAC;IACnD,mBAAmB,EAAE,sBAAsB,CAAC;CAC7C;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,0BAA0B,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;AAElF;;;;;GAKG;AACH,KAAK,qBAAqB,CAAC,CAAC,SAAS,kBAAkB,IAAI;IACzD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;KAC1B,CAAC,IAAI,kBAAkB,GAAG,qBAAqB,CAAC,CAAC,CAAC;CACpD,CAAC,kBAAkB,CAAC,CAAC;AAoBtB,gFAAgF;AAEhF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CASpF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAStF;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CASnE;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAShE"}
@@ -0,0 +1,5 @@
1
+ export { INITIAL_VERTEX_CAPACITY, MAX_VERTEX_CAPACITY, VERTEX_STRIDE_BYTES } from './constants';
2
+ export { createDebugDraw, DebugDraw } from './debug-draw';
3
+ export type { DebugDrawError, DebugDrawErrorCode, DebugDrawErrorDetail, } from './errors';
4
+ export type { CreateShaderModule, DebugDrawOptions, DepthMode } from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}