@gradio/model3d 0.10.11 → 0.11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @gradio/model3d
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Features
6
+
7
+ - [#8687](https://github.com/gradio-app/gradio/pull/8687) [`bc1d45d`](https://github.com/gradio-app/gradio/commit/bc1d45d8745a677bbe2a32f8d7553fe0d4ef3fd7) - Model3D point cloud and wireframe display modes. Thanks @dawoodkhan82!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/atoms@0.7.6
12
+ - @gradio/utils@0.5.1
13
+ - @gradio/statustracker@0.7.1
14
+ - @gradio/client@1.3.0
15
+ - @gradio/upload@0.11.5
16
+ - @gradio/icons@0.6.0
17
+
18
+ ## 0.10.12
19
+
20
+ ### Dependency updates
21
+
22
+ - @gradio/upload@0.11.4
23
+ - @gradio/client@1.2.1
24
+
3
25
  ## 0.10.11
4
26
 
5
27
  ### Dependency updates
package/Index.svelte CHANGED
@@ -20,6 +20,7 @@
20
20
  export let visible = true;
21
21
  export let value: null | FileData = null;
22
22
  export let root: string;
23
+ export let display_mode: "solid" | "point_cloud" | "wireframe" = "solid";
23
24
  export let clear_color: [number, number, number, number];
24
25
  export let loading_status: LoadingStatus;
25
26
  export let label: string;
@@ -66,6 +67,7 @@
66
67
  <Model3D
67
68
  {value}
68
69
  i18n={gradio.i18n}
70
+ {display_mode}
69
71
  {clear_color}
70
72
  {label}
71
73
  {show_label}
@@ -105,6 +107,7 @@
105
107
  {label}
106
108
  {show_label}
107
109
  {root}
110
+ {display_mode}
108
111
  {clear_color}
109
112
  {value}
110
113
  {camera_position}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/model3d",
3
- "version": "0.10.11",
3
+ "version": "0.11.0",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -12,16 +12,16 @@
12
12
  "babylonjs-loaders": "^4.2.1",
13
13
  "dequal": "^2.0.2",
14
14
  "gsplat": "^1.0.5",
15
- "@gradio/atoms": "^0.7.5",
16
- "@gradio/client": "^1.2.0",
17
- "@gradio/icons": "^0.5.0",
18
- "@gradio/statustracker": "^0.7.0",
19
- "@gradio/upload": "^0.11.3",
20
- "@gradio/utils": "^0.5.0",
15
+ "@gradio/client": "^1.3.0",
16
+ "@gradio/atoms": "^0.7.6",
17
+ "@gradio/icons": "^0.6.0",
18
+ "@gradio/upload": "^0.11.5",
19
+ "@gradio/utils": "^0.5.1",
20
+ "@gradio/statustracker": "^0.7.1",
21
21
  "@gradio/wasm": "^0.11.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@gradio/preview": "^0.10.0"
24
+ "@gradio/preview": "^0.10.1"
25
25
  },
26
26
  "main_changeset": true,
27
27
  "main": "./Index.svelte",
@@ -15,6 +15,7 @@
15
15
  }
16
16
 
17
17
  export let value: FileData;
18
+ export let display_mode: "solid" | "point_cloud" | "wireframe";
18
19
  export let clear_color: [number, number, number, number];
19
20
  export let camera_position: [number | null, number | null, number | null];
20
21
  export let zoom_speed: number;
@@ -53,6 +54,7 @@
53
54
  let canvas: HTMLCanvasElement;
54
55
  let scene: BABYLON.Scene;
55
56
  let engine: BABYLON.Engine;
57
+ let point_cloud_system: BABYLON.PointsCloudSystem | null = null;
56
58
  let mounted = false;
57
59
 
58
60
  onMount(() => {
@@ -91,6 +93,11 @@
91
93
  mesh.dispose();
92
94
  });
93
95
 
96
+ if (point_cloud_system) {
97
+ point_cloud_system.dispose();
98
+ point_cloud_system = null;
99
+ }
100
+
94
101
  // Load the new model
95
102
  if (url) {
96
103
  BABYLON.SceneLoader.ShowLoadingScreen = false;
@@ -98,7 +105,15 @@
98
105
  url,
99
106
  "",
100
107
  scene,
101
- () => create_camera(scene, camera_position, zoom_speed, pan_speed),
108
+ () => {
109
+ if (display_mode === "point_cloud") {
110
+ create_point_cloud(scene);
111
+ } else if (display_mode === "wireframe") {
112
+ create_wireframe(scene);
113
+ } else {
114
+ create_camera(scene, camera_position, zoom_speed, pan_speed);
115
+ }
116
+ },
102
117
  undefined,
103
118
  undefined,
104
119
  "." + value.path.split(".").pop()
@@ -145,6 +160,68 @@
145
160
  create_camera(scene, camera_position, zoom_speed, pan_speed);
146
161
  }
147
162
  }
163
+
164
+ function create_point_cloud(scene: BABYLON.Scene): void {
165
+ const meshes = scene.meshes;
166
+ const pointPositions: BABYLON.Vector3[] = [];
167
+
168
+ meshes.forEach((mesh) => {
169
+ if (mesh instanceof BABYLON.Mesh) {
170
+ const positions = mesh.getVerticesData(
171
+ BABYLON.VertexBuffer.PositionKind
172
+ );
173
+ if (positions) {
174
+ for (let i = 0; i < positions.length; i += 3) {
175
+ pointPositions.push(
176
+ new BABYLON.Vector3(
177
+ positions[i],
178
+ positions[i + 1],
179
+ positions[i + 2]
180
+ )
181
+ );
182
+ }
183
+ }
184
+ mesh.setEnabled(false);
185
+ }
186
+ });
187
+
188
+ point_cloud_system = new BABYLON.PointsCloudSystem(
189
+ "point_cloud_system",
190
+ 1,
191
+ scene
192
+ );
193
+
194
+ point_cloud_system.addPoints(
195
+ pointPositions.length,
196
+ (particle: BABYLON.CloudPoint, i: number) => {
197
+ particle.position = pointPositions[i];
198
+ particle.color = new BABYLON.Color4(
199
+ Math.random(),
200
+ Math.random(),
201
+ Math.random(),
202
+ 1.0
203
+ );
204
+ }
205
+ );
206
+
207
+ point_cloud_system.buildMeshAsync().then((mesh) => {
208
+ mesh.alwaysSelectAsActiveMesh = true;
209
+ create_camera(scene, camera_position, zoom_speed, pan_speed);
210
+ });
211
+ }
212
+
213
+ function create_wireframe(scene: BABYLON.Scene): void {
214
+ scene.meshes.forEach((mesh) => {
215
+ if (mesh instanceof BABYLON.Mesh) {
216
+ mesh.material = new BABYLON.StandardMaterial(
217
+ "wireframeMaterial",
218
+ scene
219
+ );
220
+ mesh.material.wireframe = true;
221
+ }
222
+ create_camera(scene, camera_position, zoom_speed, pan_speed);
223
+ });
224
+ }
148
225
  </script>
149
226
 
150
227
  <canvas bind:this={canvas}></canvas>
@@ -8,6 +8,7 @@
8
8
  import type Canvas3D from "./Canvas3D.svelte";
9
9
 
10
10
  export let value: FileData | null;
11
+ export let display_mode: "solid" | "point_cloud" | "wireframe" = "solid";
11
12
  export let clear_color: [number, number, number, number] = [0, 0, 0, 0];
12
13
  export let label = "";
13
14
  export let show_label: boolean;
@@ -101,6 +102,7 @@
101
102
  bind:this={canvas3d}
102
103
  bind:resolved_url
103
104
  {value}
105
+ {display_mode}
104
106
  {clear_color}
105
107
  {camera_position}
106
108
  {zoom_speed}
@@ -9,6 +9,7 @@
9
9
  import type Canvas3D from "./Canvas3D.svelte";
10
10
 
11
11
  export let value: null | FileData;
12
+ export let display_mode: "solid" | "point_cloud" | "wireframe" = "solid";
12
13
  export let clear_color: [number, number, number, number] = [0, 0, 0, 0];
13
14
  export let label = "";
14
15
  export let show_label: boolean;
@@ -121,6 +122,7 @@
121
122
  this={Canvas3DComponent}
122
123
  bind:this={canvas3d}
123
124
  {value}
125
+ {display_mode}
124
126
  {clear_color}
125
127
  {camera_position}
126
128
  {zoom_speed}