@lagless/pixi-react 0.0.46 → 0.0.50

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/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './lib/virtual-joystick/virtual-joystick';
2
2
  export * from './lib/neutrino-particles/use-vfx-container';
3
3
  export * from './lib/filter-views/filter-views';
4
+ export { DebugPhysics2dRenderer } from './lib/debug-physics-2d/debug-physics-2d-renderer';
5
+ export type { DebugRenderData, DebugPhysics2dRendererProps } from './lib/debug-physics-2d/debug-physics-2d-renderer';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,YAAY,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './lib/virtual-joystick/virtual-joystick';
2
2
  export * from './lib/neutrino-particles/use-vfx-container';
3
3
  export * from './lib/filter-views/filter-views';
4
+ export { DebugPhysics2dRenderer } from './lib/debug-physics-2d/debug-physics-2d-renderer';
@@ -0,0 +1,13 @@
1
+ import { FC } from 'react';
2
+ import { Container } from 'pixi.js';
3
+ export interface DebugRenderData {
4
+ vertices: Float32Array;
5
+ colors: Float32Array;
6
+ }
7
+ export interface DebugPhysics2dRendererProps {
8
+ getBuffers: () => DebugRenderData;
9
+ strokeWidth?: number;
10
+ parent: Container;
11
+ }
12
+ export declare const DebugPhysics2dRenderer: FC<DebugPhysics2dRendererProps>;
13
+ //# sourceMappingURL=debug-physics-2d-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-physics-2d-renderer.d.ts","sourceRoot":"","sources":["../../../src/lib/debug-physics-2d/debug-physics-2d-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAqB,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAY,MAAM,SAAS,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,eAAe,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAqDlE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { useTick } from '@pixi/react';
3
+ import { Graphics } from 'pixi.js';
4
+ export const DebugPhysics2dRenderer = ({ getBuffers, strokeWidth = 0.5, parent }) => {
5
+ const graphicsRef = useRef(null);
6
+ useEffect(() => {
7
+ const g = new Graphics();
8
+ g.zIndex = 999999;
9
+ parent.sortableChildren = true;
10
+ graphicsRef.current = g;
11
+ parent.addChild(g);
12
+ return () => {
13
+ parent.removeChild(g);
14
+ g.destroy();
15
+ graphicsRef.current = null;
16
+ };
17
+ }, [parent]);
18
+ useTick(() => {
19
+ const g = graphicsRef.current;
20
+ if (!g)
21
+ return;
22
+ const buffers = getBuffers();
23
+ g.clear();
24
+ const vtx = buffers.vertices;
25
+ const cls = buffers.colors;
26
+ const segmentCount = vtx.length / 4;
27
+ if (segmentCount === 0)
28
+ return;
29
+ let batchColor = segmentColor(cls, 0);
30
+ let batchAlpha = cls[3];
31
+ g.moveTo(vtx[0], vtx[1]);
32
+ g.lineTo(vtx[2], vtx[3]);
33
+ for (let i = 1; i < segmentCount; i++) {
34
+ const color = segmentColor(cls, i);
35
+ const alpha = cls[i * 8 + 3];
36
+ if (color !== batchColor || alpha !== batchAlpha) {
37
+ g.stroke({ width: strokeWidth, color: batchColor, alpha: batchAlpha });
38
+ batchColor = color;
39
+ batchAlpha = alpha;
40
+ }
41
+ g.moveTo(vtx[i * 4], vtx[i * 4 + 1]);
42
+ g.lineTo(vtx[i * 4 + 2], vtx[i * 4 + 3]);
43
+ }
44
+ g.stroke({ width: strokeWidth, color: batchColor, alpha: batchAlpha });
45
+ });
46
+ return null;
47
+ };
48
+ function segmentColor(cls, i) {
49
+ return ((cls[i * 8] * 255) << 16) | ((cls[i * 8 + 1] * 255) << 8) | (cls[i * 8 + 2] * 255);
50
+ }