@needle-tools/gltf-progressive 1.0.0-alpha.9 → 1.1.0-alpha.1

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,2 +1,2 @@
1
1
  export { patchModelViewer } from "./modelviewer.js";
2
- export { registerPlugin, type NEEDLE_progressive_plugin } from "./plugin.js";
2
+ export { type NEEDLE_progressive_plugin } from "./plugin.js";
@@ -1,2 +1 @@
1
1
  export { patchModelViewer } from "./modelviewer.js";
2
- export { registerPlugin } from "./plugin.js";
@@ -23,8 +23,8 @@ export function patchModelViewer(modelviewer) {
23
23
  }
24
24
  if (renderer) {
25
25
  console.log("Adding Needle LODs to modelviewer");
26
- const lod = new LODsManager(renderer);
27
- lod.plugins.push(new RegisterModelviewerDataPlugin(modelviewer));
26
+ const lod = LODsManager.get(renderer);
27
+ LODsManager.addPlugin(new RegisterModelviewerDataPlugin(modelviewer));
28
28
  lod.enable();
29
29
  if (scene) {
30
30
  const camera = scene["camera"] || scene.traverse((o) => o.type == "PerspectiveCamera")[0];
@@ -104,7 +104,11 @@ class RegisterModelviewerDataPlugin {
104
104
  if (value?.isTexture === true) {
105
105
  const textureIndex = value.userData?.associations?.textures;
106
106
  const textureData = currentGLTF.parser.json.textures[textureIndex];
107
- if (textureData.extensions?.[EXTENSION_NAME]) {
107
+ if (!textureData) {
108
+ console.warn("Texture data not found for texture index " + textureIndex);
109
+ continue;
110
+ }
111
+ if (textureData?.extensions?.[EXTENSION_NAME]) {
108
112
  const ext = textureData.extensions[EXTENSION_NAME];
109
113
  if (ext && url) {
110
114
  NEEDLE_progressive.registerTexture(url, value, ext.lods.length, ext);
@@ -7,7 +7,10 @@ export interface NEEDLE_progressive_plugin {
7
7
  /** Called before the LOD level will be requested/updated for a object */
8
8
  onBeforeUpdateLOD?(renderer: WebGLRenderer, scene: Scene, camera: Camera, object: Mesh): void;
9
9
  /** Called after the LOD level has been requested */
10
- onAfterUpdatedLOD?(renderer: WebGLRenderer, scene: Scene, camera: Camera, object: Mesh, level: number): void;
10
+ onAfterUpdatedLOD?(renderer: WebGLRenderer, scene: Scene, camera: Camera, object: Mesh, level: {
11
+ mesh_lod: number;
12
+ texture_lod: number;
13
+ }): void;
11
14
  /** Called when a new mesh is registered */
12
15
  onRegisteredNewMesh?(mesh: Mesh, ext: NEEDLE_progressive_mesh_model): void;
13
16
  /** Called before the LOD mesh is fetched */
@@ -18,7 +21,3 @@ export interface NEEDLE_progressive_plugin {
18
21
  * @internal
19
22
  */
20
23
  export declare const plugins: NEEDLE_progressive_plugin[];
21
- /**
22
- * Register a plugin for the progressive extension. The plugin callbacks will be called at different stages of the progressive extension.
23
- */
24
- export declare function registerPlugin(plugin: NEEDLE_progressive_plugin): void;
@@ -3,9 +3,3 @@
3
3
  * @internal
4
4
  */
5
5
  export const plugins = new Array();
6
- /**
7
- * Register a plugin for the progressive extension. The plugin callbacks will be called at different stages of the progressive extension.
8
- */
9
- export function registerPlugin(plugin) {
10
- plugins.push(plugin);
11
- }
package/lib/utils.d.ts CHANGED
@@ -1,2 +1,15 @@
1
+ import { BufferGeometry, Object3D } from "three";
1
2
  export declare function getParam(name: string): boolean | string;
2
3
  export declare function resolveUrl(source: string | undefined, uri: string): string;
4
+ /**
5
+ * The raycast mesh is a low poly version of the mesh used for raycasting. It is set when a mesh that has LOD level with more vertices is discovered for the first time
6
+ * @param obj the object to get the raycast mesh from
7
+ * @returns the raycast mesh or null if not set
8
+ */
9
+ export declare function getRaycastMesh(obj: Object3D): BufferGeometry<any> | null;
10
+ /**
11
+ * Set the raycast mesh for an object. The raycast mesh is a low poly version of the mesh used for raycasting. It is set when a mesh that has LOD level with more vertices is discovered for the first time
12
+ * @param obj the object to set the raycast mesh for
13
+ * @param geom the raycast mesh
14
+ */
15
+ export declare function setRaycastMesh(obj: Object3D, geom: BufferGeometry): void;
package/lib/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { BufferGeometry } from "three";
1
2
  export function getParam(name) {
2
3
  const url = new URL(window.location.href);
3
4
  const param = url.searchParams.get(name);
@@ -34,3 +35,26 @@ export function resolveUrl(source, uri) {
34
35
  }
35
36
  return uri;
36
37
  }
38
+ /**
39
+ * The raycast mesh is a low poly version of the mesh used for raycasting. It is set when a mesh that has LOD level with more vertices is discovered for the first time
40
+ * @param obj the object to get the raycast mesh from
41
+ * @returns the raycast mesh or null if not set
42
+ */
43
+ export function getRaycastMesh(obj) {
44
+ if (obj.userData?.["needle:raycast-mesh"] instanceof BufferGeometry) {
45
+ return obj.userData["needle:raycast-mesh"];
46
+ }
47
+ return null;
48
+ }
49
+ /**
50
+ * Set the raycast mesh for an object. The raycast mesh is a low poly version of the mesh used for raycasting. It is set when a mesh that has LOD level with more vertices is discovered for the first time
51
+ * @param obj the object to set the raycast mesh for
52
+ * @param geom the raycast mesh
53
+ */
54
+ export function setRaycastMesh(obj, geom) {
55
+ if (obj.type === "Mesh" || obj.type === "SkinnedMesh") {
56
+ if (!obj.userData)
57
+ obj.userData = {};
58
+ obj.userData["needle:raycast-mesh"] = geom;
59
+ }
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.1.0-alpha.1",
4
4
  "description": "three.js support for loading glTF or GLB files that contain progressive loading data",
5
5
  "homepage": "https://needle.tools",
6
6
  "author": {