react-native-wgpu 0.1.2 → 0.1.4

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 (83) hide show
  1. package/android/cpp/AndroidPlatformContext.h +108 -2
  2. package/android/cpp/cpp-adapter.cpp +5 -2
  3. package/android/src/main/java/com/webgpu/WebGPUModule.java +8 -2
  4. package/cpp/rnwgpu/PlatformContext.h +14 -1
  5. package/cpp/rnwgpu/RNWebGPUManager.cpp +6 -9
  6. package/cpp/rnwgpu/RNWebGPUManager.h +0 -3
  7. package/cpp/rnwgpu/api/GPU.cpp +33 -52
  8. package/cpp/rnwgpu/api/GPUAdapter.cpp +92 -92
  9. package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
  10. package/cpp/rnwgpu/api/GPUQueue.cpp +45 -2
  11. package/cpp/rnwgpu/api/ImageBitmap.h +34 -0
  12. package/cpp/rnwgpu/api/RNWebGPU.h +100 -0
  13. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +14 -4
  14. package/ios/IOSPlatformContext.h +3 -0
  15. package/ios/IOSPlatformContext.mm +50 -0
  16. package/ios/SurfaceUtils.mm +0 -1
  17. package/lib/commonjs/Canvas.js +1 -3
  18. package/lib/commonjs/Canvas.js.map +1 -1
  19. package/lib/commonjs/index.js +25 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/utils.js +39 -0
  22. package/lib/commonjs/utils.js.map +1 -0
  23. package/lib/module/Canvas.js +1 -3
  24. package/lib/module/Canvas.js.map +1 -1
  25. package/lib/module/index.js +14 -0
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/utils.js +31 -0
  28. package/lib/module/utils.js.map +1 -0
  29. package/lib/typescript/lib/commonjs/utils.d.ts +5 -0
  30. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
  31. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  32. package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts +0 -1
  33. package/lib/typescript/lib/module/index.d.ts +1 -0
  34. package/lib/typescript/lib/module/utils.d.ts +3 -0
  35. package/lib/typescript/lib/module/utils.d.ts.map +1 -0
  36. package/lib/typescript/src/Canvas.d.ts +6 -1
  37. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  38. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +0 -1
  39. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  40. package/lib/typescript/src/index.d.ts +1 -0
  41. package/lib/typescript/src/index.d.ts.map +1 -1
  42. package/lib/typescript/src/utils.d.ts +6 -0
  43. package/lib/typescript/src/utils.d.ts.map +1 -0
  44. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  45. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  46. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  47. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  48. package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  49. package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  50. package/libs/ios/arm64_xros/libwebgpu_dawn.a +0 -0
  51. package/libs/ios/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  52. package/libs/ios/libwebgpu_dawn.a +0 -0
  53. package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +36 -5
  54. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  55. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  56. package/libs/ios/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  57. package/libs/ios/libwebgpu_dawn.xcframework/xros-arm64_x86_64-simulator/libwebgpu_dawn_visionos.a +0 -0
  58. package/libs/ios/libwebgpu_dawn_visionos.a +0 -0
  59. package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  60. package/libs/ios/x86_64_xrsimulator/libwebgpu_dawn.a +0 -0
  61. package/package.json +3 -20
  62. package/react-native-wgpu.podspec +1 -1
  63. package/src/Canvas.tsx +8 -3
  64. package/src/index.tsx +19 -0
  65. package/src/utils.ts +40 -0
  66. package/cpp/rnwgpu/api/ImageData.h +0 -50
  67. package/cpp/rnwgpu/api/Navigator.h +0 -46
  68. package/lib/typescript/example/src/Triangle/triangle.d.ts +0 -3
  69. package/lib/typescript/example/src/Triangle/triangle.d.ts.map +0 -1
  70. package/lib/typescript/example/src/Wireframe/Shaders.d.ts +0 -3
  71. package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +0 -1
  72. package/lib/typescript/example/src/Wireframe/models.d.ts +0 -29
  73. package/lib/typescript/example/src/Wireframe/models.d.ts.map +0 -1
  74. package/lib/typescript/example/src/components/DrawingContext.d.ts +0 -13
  75. package/lib/typescript/example/src/components/DrawingContext.d.ts.map +0 -1
  76. package/lib/typescript/example/src/components/cube.d.ts +0 -7
  77. package/lib/typescript/example/src/components/cube.d.ts.map +0 -1
  78. package/lib/typescript/example/src/components/meshes/sphere.d.ts +0 -12
  79. package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +0 -1
  80. package/lib/typescript/example/src/components/meshes/teapot.d.ts +0 -6
  81. package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +0 -1
  82. package/lib/typescript/example/src/components/meshes/utils.d.ts +0 -10
  83. package/lib/typescript/example/src/components/meshes/utils.d.ts.map +0 -1
@@ -8,33 +8,64 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>libwebgpu_dawn.a</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64</string>
11
+ <string>ios-arm64_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>libwebgpu_dawn.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
+ <string>x86_64</string>
17
18
  </array>
18
19
  <key>SupportedPlatform</key>
19
20
  <string>ios</string>
21
+ <key>SupportedPlatformVariant</key>
22
+ <string>simulator</string>
20
23
  </dict>
21
24
  <dict>
22
25
  <key>BinaryPath</key>
23
- <string>libwebgpu_dawn.a</string>
26
+ <string>libwebgpu_dawn_visionos.a</string>
24
27
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_x86_64-simulator</string>
28
+ <string>xros-arm64_x86_64-simulator</string>
26
29
  <key>LibraryPath</key>
27
- <string>libwebgpu_dawn.a</string>
30
+ <string>libwebgpu_dawn_visionos.a</string>
28
31
  <key>SupportedArchitectures</key>
29
32
  <array>
30
33
  <string>arm64</string>
31
34
  <string>x86_64</string>
32
35
  </array>
33
36
  <key>SupportedPlatform</key>
34
- <string>ios</string>
37
+ <string>xros</string>
35
38
  <key>SupportedPlatformVariant</key>
36
39
  <string>simulator</string>
37
40
  </dict>
41
+ <dict>
42
+ <key>BinaryPath</key>
43
+ <string>libwebgpu_dawn.a</string>
44
+ <key>LibraryIdentifier</key>
45
+ <string>ios-arm64</string>
46
+ <key>LibraryPath</key>
47
+ <string>libwebgpu_dawn.a</string>
48
+ <key>SupportedArchitectures</key>
49
+ <array>
50
+ <string>arm64</string>
51
+ </array>
52
+ <key>SupportedPlatform</key>
53
+ <string>ios</string>
54
+ </dict>
55
+ <dict>
56
+ <key>BinaryPath</key>
57
+ <string>libwebgpu_dawn.a</string>
58
+ <key>LibraryIdentifier</key>
59
+ <string>xros-arm64</string>
60
+ <key>LibraryPath</key>
61
+ <string>libwebgpu_dawn.a</string>
62
+ <key>SupportedArchitectures</key>
63
+ <array>
64
+ <string>arm64</string>
65
+ </array>
66
+ <key>SupportedPlatform</key>
67
+ <string>xros</string>
68
+ </dict>
38
69
  </array>
39
70
  <key>CFBundlePackageType</key>
40
71
  <string>XFWK</string>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wgpu",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -28,12 +28,10 @@
28
28
  "!**/.*"
29
29
  ],
30
30
  "scripts": {
31
- "example": "yarn workspace react-native-webgpu-example",
32
31
  "test": "jest -i",
33
32
  "test:ref": "REFERENCE=true yarn test -i",
34
33
  "tsc": "tsc --noEmit",
35
- "lint": "eslint \"**/*.{ts,tsx}\"",
36
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
34
+ "lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
37
35
  "prepare": "bob build",
38
36
  "build-dawn": "ts-node scripts/build/dawn.ts",
39
37
  "clean-dawn": "rimraf ./libs && rimraf ../externals/dawn/out",
@@ -64,7 +62,6 @@
64
62
  "registry": "https://registry.npmjs.org/"
65
63
  },
66
64
  "devDependencies": {
67
- "@react-native/eslint-config": "^0.74.84",
68
65
  "@types/jest": "^29.5.12",
69
66
  "@types/lodash": "^4.17.5",
70
67
  "@types/node": "^20.14.7",
@@ -73,14 +70,9 @@
73
70
  "@types/react": "^18.2.44",
74
71
  "@types/seedrandom": "^3.0.8",
75
72
  "@types/ws": "^8.5.10",
76
- "@typescript-eslint/eslint-plugin": "^7.13.1",
77
- "@webgpu/types": "^0.1.42",
73
+ "@webgpu/types": "^0.1.44",
78
74
  "clang-format": "^1.8.0",
79
75
  "del-cli": "^5.1.0",
80
- "eslint": "8",
81
- "eslint-config-react-native-wcandillon": "^3.10.2",
82
- "eslint-plugin-import": "^2.29.1",
83
- "eslint-plugin-prettier": "^5.1.3",
84
76
  "jest": "^29.7.0",
85
77
  "lodash": "^4.17.21",
86
78
  "pixelmatch": "5.3.0",
@@ -96,22 +88,13 @@
96
88
  "ts-morph": "^22.0.0",
97
89
  "ts-node": "^10.9.2",
98
90
  "turbo": "^1.10.7",
99
- "typescript": "^5.2.2",
100
91
  "wgpu-matrix": "^3.0.2",
101
92
  "ws": "^8.18.0"
102
93
  },
103
- "resolutions": {
104
- "@types/react": "^18.2.44",
105
- "@webgpu/types": "^0.1.42"
106
- },
107
94
  "peerDependencies": {
108
95
  "react": "*",
109
96
  "react-native": "*"
110
97
  },
111
- "workspaces": [
112
- "example"
113
- ],
114
- "packageManager": "yarn@3.6.1",
115
98
  "react-native-builder-bob": {
116
99
  "source": "src",
117
100
  "output": "lib",
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.license = package["license"]
12
12
  s.authors = package["author"]
13
13
 
14
- s.platforms = { :ios => min_ios_version_supported }
14
+ s.platforms = { :ios => min_ios_version_supported, :visionos => "1.0" }
15
15
  s.source = { :git => "https://github.com/wcandillon/react-native-webgpu.git", :tag => "#{s.version}" }
16
16
 
17
17
  s.source_files = [
package/src/Canvas.tsx CHANGED
@@ -12,6 +12,13 @@ function generateContextId() {
12
12
  declare global {
13
13
  // eslint-disable-next-line no-var
14
14
  var __WebGPUContextRegistry: Record<number, NativeCanvas>;
15
+ // eslint-disable-next-line no-var
16
+ var RNWebGPU: {
17
+ gpu: GPU;
18
+ MakeWebGPUCanvasContext: (nativeCanvas: NativeCanvas) => CanvasContext;
19
+ DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
20
+ createImageBitmap: typeof createImageBitmap;
21
+ };
15
22
  }
16
23
 
17
24
  export interface NativeCanvas {
@@ -51,9 +58,7 @@ export const Canvas = forwardRef<CanvasRef, ViewProps>((props, ref) => {
51
58
  if (!nativeSurface) {
52
59
  return null;
53
60
  }
54
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
- // @ts-expect-error
56
- const ctx = navigator.MakeWebGPUCanvasContext(nativeSurface);
61
+ const ctx = RNWebGPU.MakeWebGPUCanvasContext(nativeSurface);
57
62
  return ctx;
58
63
  },
59
64
  }));
package/src/index.tsx CHANGED
@@ -3,6 +3,7 @@ import WebGPUNativeModule from "./NativeWebGPUModule";
3
3
 
4
4
  export * from "./Canvas";
5
5
  export * from "./WebGPUViewNativeComponent";
6
+ export * from "./utils";
6
7
  export { default as WebGPUModule } from "./NativeWebGPUModule";
7
8
 
8
9
  const GPU: any = {};
@@ -175,3 +176,21 @@ global.GPUTexture = GPUTexture;
175
176
  global.GPUTextureView = GPUTextureView;
176
177
 
177
178
  WebGPUNativeModule.install();
179
+
180
+ if (!navigator) {
181
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
182
+ // @ts-expect-error
183
+ navigator = {};
184
+ }
185
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
186
+ // @ts-expect-error
187
+ navigator.gpu = RNWebGPU.gpu;
188
+
189
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
190
+ // @ts-ignore
191
+ navigator.userAgent = "react-native";
192
+
193
+ global.createImageBitmap =
194
+ global.createImageBitmap ??
195
+ ((...params: Parameters<typeof createImageBitmap>) =>
196
+ new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
package/src/utils.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ import type { CanvasRef } from "./Canvas";
4
+
5
+ type Unsubscribe = () => void;
6
+
7
+ export const warnIfNotHardwareAccelerated = (adapter: GPUAdapter) => {
8
+ if (adapter.info.architecture === "swiftshader") {
9
+ console.warn(
10
+ "GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.",
11
+ );
12
+ }
13
+ };
14
+
15
+ export const useCanvasEffect = (
16
+ effect: () => void | Unsubscribe | Promise<void | Unsubscribe>,
17
+ ) => {
18
+ const ref = useRef<CanvasRef>(null);
19
+ const unsubscribe = useRef<Unsubscribe>();
20
+ useEffect(() => {
21
+ requestAnimationFrame(async () => {
22
+ // const adapter = await navigator.gpu.requestAdapter();
23
+ // if (!adapter) {
24
+ // return;
25
+ // }
26
+ // const device = await adapter.requestDevice();
27
+ const unsub = await effect();
28
+ if (unsub) {
29
+ unsubscribe.current = unsub;
30
+ }
31
+ });
32
+ return () => {
33
+ if (unsubscribe.current) {
34
+ unsubscribe.current();
35
+ }
36
+ };
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, []);
39
+ return ref;
40
+ };
@@ -1,50 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
-
5
- #include "ArrayBuffer.h"
6
-
7
- namespace rnwgpu {
8
-
9
- struct ImageData {
10
- std::shared_ptr<ArrayBuffer> data;
11
- size_t width;
12
- size_t height;
13
- };
14
-
15
- } // namespace rnwgpu
16
-
17
- namespace margelo {
18
-
19
- using namespace rnwgpu; // NOLINT(build/namespaces)
20
-
21
- template <> struct JSIConverter<std::shared_ptr<rnwgpu::ImageData>> {
22
- static std::shared_ptr<rnwgpu::ImageData>
23
- fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
24
- auto result = std::make_unique<rnwgpu::ImageData>();
25
- if (!outOfBounds && arg.isObject()) {
26
- auto obj = arg.getObject(runtime);
27
- if (obj.hasProperty(runtime, "data")) {
28
- auto prop = obj.getProperty(runtime, "data");
29
- result->data = JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(
30
- runtime, prop, false);
31
- }
32
- if (obj.hasProperty(runtime, "width")) {
33
- auto prop = obj.getProperty(runtime, "width");
34
- result->width = prop.getNumber();
35
- }
36
- if (obj.hasProperty(runtime, "height")) {
37
- auto prop = obj.getProperty(runtime, "height");
38
- result->height = prop.getNumber();
39
- }
40
- }
41
-
42
- return result;
43
- }
44
- static jsi::Value toJSI(jsi::Runtime &runtime,
45
- std::shared_ptr<rnwgpu::ImageData> arg) {
46
- throw std::runtime_error("Invalid ImageData::toJSI()");
47
- }
48
- };
49
-
50
- } // namespace margelo
@@ -1,46 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
-
5
- #include "GPU.h"
6
- #include "GPUCanvasContext.h"
7
-
8
- namespace rnwgpu {
9
-
10
- namespace m = margelo;
11
-
12
- class Navigator : public m::HybridObject {
13
- public:
14
- explicit Navigator(std::shared_ptr<GPU> gpu,
15
- std::shared_ptr<PlatformContext> platformContext)
16
- : HybridObject("Navigator"), _gpu(gpu),
17
- _platformContext(platformContext) {}
18
-
19
- std::shared_ptr<GPU> getGPU() { return _gpu; }
20
-
21
- std::shared_ptr<GPUCanvasContext>
22
- MakeWebGPUCanvasContext(std::shared_ptr<Canvas> canvas) {
23
- auto nativeSurface = canvas->getSurface();
24
- auto width = canvas->getWidth();
25
- auto height = canvas->getHeight();
26
- auto surface = _platformContext->makeSurface(
27
- _gpu->get(), reinterpret_cast<void *>(nativeSurface), width, height);
28
- if (surface == nullptr) {
29
- throw std::runtime_error("null surface");
30
- }
31
- auto ctx = std::make_shared<GPUCanvasContext>(surface, canvas);
32
- return ctx;
33
- }
34
-
35
- void loadHybridMethods() override {
36
- registerHybridGetter("gpu", &Navigator::getGPU, this);
37
- registerHybridMethod("MakeWebGPUCanvasContext",
38
- &Navigator::MakeWebGPUCanvasContext, this);
39
- }
40
-
41
- private:
42
- std::shared_ptr<GPU> _gpu;
43
- std::shared_ptr<PlatformContext> _platformContext;
44
- };
45
-
46
- } // namespace rnwgpu
@@ -1,3 +0,0 @@
1
- export declare const triangleVertWGSL = "@vertex\nfn main(\n @builtin(vertex_index) VertexIndex : u32\n) -> @builtin(position) vec4f {\n var pos = array<vec2f, 3>(\n vec2(0.0, 0.5),\n vec2(-0.5, -0.5),\n vec2(0.5, -0.5)\n );\n\n return vec4f(pos[VertexIndex], 0.0, 1.0);\n}";
2
- export declare const redFragWGSL = "@fragment\nfn main() -> @location(0) vec4f {\n return vec4(1.0, 0.0, 0.0, 1.0);\n}";
3
- //# sourceMappingURL=triangle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"triangle.d.ts","sourceRoot":"","sources":["../../../../../example/src/Triangle/triangle.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,0PAW3B,CAAC;AAEH,eAAO,MAAM,WAAW,wFAGtB,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const solidColorLitWGSL = "struct Uniforms {\n worldViewProjectionMatrix: mat4x4f,\n worldMatrix: mat4x4f,\n color: vec4f,\n};\n\nstruct Vertex {\n @location(0) position: vec4f,\n @location(1) normal: vec3f,\n};\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n @location(0) normal: vec3f,\n};\n\n@group(0) @binding(0) var<uniform> uni: Uniforms;\n\n@vertex fn vs(vin: Vertex) -> VSOut {\n var vOut: VSOut;\n vOut.position = uni.worldViewProjectionMatrix * vin.position;\n vOut.normal = (uni.worldMatrix * vec4f(vin.normal, 0)).xyz;\n return vOut;\n}\n\n@fragment fn fs(vin: VSOut) -> @location(0) vec4f {\n let lightDirection = normalize(vec3f(4, 10, 6));\n let light = dot(normalize(vin.normal), lightDirection) * 0.5 + 0.5;\n return vec4f(uni.color.rgb * light, uni.color.a);\n}";
2
- export declare const wireframeWGSL = "struct Uniforms {\n worldViewProjectionMatrix: mat4x4f,\n worldMatrix: mat4x4f,\n color: vec4f,\n};\n\nstruct LineUniforms {\n stride: u32,\n thickness: f32,\n alphaThreshold: f32,\n};\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n};\n\n@group(0) @binding(0) var<uniform> uni: Uniforms;\n@group(0) @binding(1) var<storage, read> positions: array<f32>;\n@group(0) @binding(2) var<storage, read> indices: array<u32>;\n@group(0) @binding(3) var<uniform> line: LineUniforms;\n\n@vertex fn vsIndexedU32(@builtin(vertex_index) vNdx: u32) -> VSOut {\n // indices make a triangle so for every 3 indices we need to output\n // 6 values\n let triNdx = vNdx / 6;\n // 0 1 0 1 0 1 0 1 0 1 0 1 vNdx % 2\n // 0 0 1 1 2 2 3 3 4 4 5 5 vNdx / 2\n // 0 1 1 2 2 3 3 4 4 5 5 6 vNdx % 2 + vNdx / 2\n // 0 1 1 2 2 0 0 1 1 2 2 0 (vNdx % 2 + vNdx / 2) % 3\n let vertNdx = (vNdx % 2 + vNdx / 2) % 3;\n let index = indices[triNdx * 3 + vertNdx];\n\n // note:\n //\n // * if your indices are U16 you could use this\n //\n // let indexNdx = triNdx * 3 + vertNdx;\n // let twoIndices = indices[indexNdx / 2]; // indices is u32 but we want u16\n // let index = (twoIndices >> ((indexNdx & 1) * 16)) & 0xFFFF;\n //\n // * if you're not using indices you could use this\n //\n // let index = triNdx * 3 + vertNdx;\n\n let pNdx = index * line.stride;\n let position = vec4f(positions[pNdx], positions[pNdx + 1], positions[pNdx + 2], 1);\n\n var vOut: VSOut;\n vOut.position = uni.worldViewProjectionMatrix * position;\n return vOut;\n}\n\n@fragment fn fs() -> @location(0) vec4f {\n return uni.color + vec4f(0.5);\n}\n\nstruct BarycentricCoordinateBasedVSOutput {\n @builtin(position) position: vec4f,\n @location(0) barycenticCoord: vec3f,\n};\n\n@vertex fn vsIndexedU32BarycentricCoordinateBasedLines(\n @builtin(vertex_index) vNdx: u32\n) -> BarycentricCoordinateBasedVSOutput {\n let vertNdx = vNdx % 3;\n let index = indices[vNdx];\n\n // note:\n //\n // * if your indices are U16 you could use this\n //\n // let twoIndices = indices[vNdx / 2]; // indices is u32 but we want u16\n // let index = (twoIndices >> ((vNdx & 1) * 16)) & 0xFFFF;\n //\n // * if you're not using indices you could use this\n //\n // let index = vNdx;\n\n let pNdx = index * line.stride;\n let position = vec4f(positions[pNdx], positions[pNdx + 1], positions[pNdx + 2], 1);\n\n var vsOut: BarycentricCoordinateBasedVSOutput;\n vsOut.position = uni.worldViewProjectionMatrix * position;\n\n // emit a barycentric coordinate\n vsOut.barycenticCoord = vec3f(0);\n vsOut.barycenticCoord[vertNdx] = 1.0;\n return vsOut;\n}\n\nfn edgeFactor(bary: vec3f) -> f32 {\n let d = fwidth(bary);\n let a3 = smoothstep(vec3f(0.0), d * line.thickness, bary);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@fragment fn fsBarycentricCoordinateBasedLines(\n v: BarycentricCoordinateBasedVSOutput\n) -> @location(0) vec4f {\n let a = 1.0 - edgeFactor(v.barycenticCoord);\n if (a < line.alphaThreshold) {\n discard;\n }\n\n return vec4((uni.color.rgb + 0.5) * a, a);\n}\n";
3
- //# sourceMappingURL=Shaders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Shaders.d.ts","sourceRoot":"","sources":["../../../../../example/src/Wireframe/Shaders.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,6wBA6B5B,CAAC;AAEH,eAAO,MAAM,aAAa,oiGA0GzB,CAAC"}
@@ -1,29 +0,0 @@
1
- type Mesh = {
2
- positions: [number, number, number][];
3
- triangles: [number, number, number][];
4
- normals: [number, number, number][];
5
- };
6
- export declare function convertMeshToTypedArrays(mesh: Mesh, scale: number, offset?: number[]): {
7
- vertices: Float32Array;
8
- indices: Uint32Array;
9
- };
10
- export declare const modelData: {
11
- teapot: {
12
- vertices: Float32Array;
13
- indices: Uint32Array;
14
- };
15
- sphere: {
16
- vertices: Float32Array;
17
- indices: Uint32Array;
18
- };
19
- jewel: {
20
- vertices: Float32Array;
21
- indices: Uint32Array;
22
- };
23
- rock: {
24
- vertices: Float32Array;
25
- indices: Uint32Array;
26
- };
27
- };
28
- export {};
29
- //# sourceMappingURL=models.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../../example/src/Wireframe/models.ts"],"names":[],"mappings":"AAUA,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,EACb,MAAM,WAAY;;;EAoBnB;AAoED,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAKrB,CAAC"}
@@ -1,13 +0,0 @@
1
- /// <reference types="@webgpu/types" />
2
- export interface DrawingContext {
3
- width: number;
4
- height: number;
5
- getCurrentTexture(): GPUTexture;
6
- getImageData(): Promise<{
7
- data: number[];
8
- width: number;
9
- height: number;
10
- format: string;
11
- }>;
12
- }
13
- //# sourceMappingURL=DrawingContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DrawingContext.d.ts","sourceRoot":"","sources":["../../../../../example/src/components/DrawingContext.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,IAAI,UAAU,CAAC;IAChC,YAAY,IAAI,OAAO,CAAC;QACtB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ"}
@@ -1,7 +0,0 @@
1
- export declare const cubeVertexSize: number;
2
- export declare const cubePositionOffset = 0;
3
- export declare const cubeColorOffset: number;
4
- export declare const cubeUVOffset: number;
5
- export declare const cubeVertexCount = 36;
6
- export declare const cubeVertexArray: Float32Array;
7
- //# sourceMappingURL=cube.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cube.d.ts","sourceRoot":"","sources":["../../../../../example/src/components/cube.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAGlC,eAAO,MAAM,eAAe,cA2C1B,CAAC"}
@@ -1,12 +0,0 @@
1
- export interface SphereMesh {
2
- vertices: Float32Array;
3
- indices: Uint16Array;
4
- }
5
- export declare const SphereLayout: {
6
- vertexStride: number;
7
- positionsOffset: number;
8
- normalOffset: number;
9
- uvOffset: number;
10
- };
11
- export declare function createSphereMesh(radius: number, widthSegments?: number, heightSegments?: number, randomness?: number): SphereMesh;
12
- //# sourceMappingURL=sphere.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sphere.d.ts","sourceRoot":"","sources":["../../../../../../example/src/components/meshes/sphere.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,eAAO,MAAM,YAAY;;;;;CAKxB,CAAC;AAGF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,aAAa,SAAK,EAClB,cAAc,SAAK,EACnB,UAAU,SAAI,GACb,UAAU,CAkFZ"}
@@ -1,6 +0,0 @@
1
- export declare const mesh: {
2
- positions: [number, number, number][];
3
- triangles: [number, number, number][];
4
- normals: [number, number, number][];
5
- };
6
- //# sourceMappingURL=teapot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"teapot.d.ts","sourceRoot":"","sources":["../../../../../../example/src/components/meshes/teapot.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI;;;;CAIhB,CAAC"}
@@ -1,10 +0,0 @@
1
- export declare function computeSurfaceNormals(positions: [number, number, number][], triangles: [number, number, number][]): [number, number, number][];
2
- export declare function generateNormals(maxAngle: number, positions: [number, number, number][], triangles: [number, number, number][]): {
3
- positions: [number, number, number][];
4
- normals: [number, number, number][];
5
- triangles: [number, number, number][];
6
- };
7
- type ProjectedPlane = "xy" | "xz" | "yz";
8
- export declare function computeProjectedPlaneUVs(positions: [number, number, number][], projectedPlane?: ProjectedPlane): [number, number][];
9
- export {};
10
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../example/src/components/meshes/utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GACpC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CA4B5B;AAsBD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;;;;EA2ItC;AAED,KAAK,cAAc,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAQzC,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,cAAc,GAAE,cAAqB,GACpC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAuBpB"}