@vctrl/hooks 0.7.7 → 0.8.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.7",
2
+ "version": "0.8.0",
3
3
  "name": "@vctrl/hooks",
4
4
  "description": "vctrl/hooks is a React hooks package designed to simplify 3D model loading and management within React applications. It's part of the vectreal-core ecosystem and is primarily used in the vctrl/viewer React component and the official website application.",
5
5
  "bugs": {
@@ -46,12 +46,12 @@
46
46
  "react": "18.3.1"
47
47
  },
48
48
  "dependencies": {
49
- "jszip": "^3.10.1",
50
- "file-saver": "^2.0.5",
51
- "three": "^0.168.0",
52
49
  "@gltf-transform/core": "^4.0.8",
53
- "@gltf-transform/functions": "^4.0.8",
54
50
  "@gltf-transform/extensions": "^4.0.10",
55
- "meshoptimizer": "^0.21.0"
51
+ "@gltf-transform/functions": "^4.0.8",
52
+ "file-saver": "^2.0.5",
53
+ "jszip": "^3.10.1",
54
+ "meshoptimizer": "^0.21.0",
55
+ "three": "^0.168.0"
56
56
  }
57
57
  }
@@ -8,28 +8,30 @@ declare const ModelContext: import('react').Context<{
8
8
  load: (filesOrDirectories: import('./types').InputFileOrDirectory) => Promise<void>;
9
9
  reset: () => void;
10
10
  optimize: {
11
+ simplifyOptimization: () => void;
12
+ dedupOptimization: () => void;
13
+ quantizeOptimization: () => void;
14
+ normalsOptimization: () => void;
15
+ texturesCompressOptimization: () => void;
16
+ getSize: () => void;
17
+ reset: () => void;
18
+ report: null;
19
+ error: null;
20
+ loading: boolean;
21
+ } | {
11
22
  simplifyOptimization: (options?: {
12
23
  ratio?: number;
13
24
  error?: number;
14
25
  } | undefined) => Promise<void>;
15
26
  dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
16
27
  quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
28
+ normalsOptimization: (options?: import('@gltf-transform/functions').NormalsOptions | undefined) => Promise<void>;
17
29
  texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
18
30
  getSize: () => import('../use-optimize-model/types').ModelSize | null;
19
31
  reset: () => void;
20
32
  report: import('@gltf-transform/functions').InspectReport | null;
21
33
  error: Error | null;
22
34
  loading: boolean;
23
- } | {
24
- simplifyOptimization: () => void;
25
- dedupOptimization: () => void;
26
- quantizeOptimization: () => void;
27
- texturesCompressOptimization: () => void;
28
- getSize: () => void;
29
- reset: () => void;
30
- report: null;
31
- error: null;
32
- loading: boolean;
33
35
  };
34
36
  file: import('./types').ModelFile | null;
35
37
  isFileLoading: boolean;
@@ -43,28 +45,30 @@ declare const useModelContext: () => {
43
45
  load: (filesOrDirectories: import('./types').InputFileOrDirectory) => Promise<void>;
44
46
  reset: () => void;
45
47
  optimize: {
48
+ simplifyOptimization: () => void;
49
+ dedupOptimization: () => void;
50
+ quantizeOptimization: () => void;
51
+ normalsOptimization: () => void;
52
+ texturesCompressOptimization: () => void;
53
+ getSize: () => void;
54
+ reset: () => void;
55
+ report: null;
56
+ error: null;
57
+ loading: boolean;
58
+ } | {
46
59
  simplifyOptimization: (options?: {
47
60
  ratio?: number;
48
61
  error?: number;
49
62
  } | undefined) => Promise<void>;
50
63
  dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
51
64
  quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
65
+ normalsOptimization: (options?: import('@gltf-transform/functions').NormalsOptions | undefined) => Promise<void>;
52
66
  texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
53
67
  getSize: () => import('../use-optimize-model/types').ModelSize | null;
54
68
  reset: () => void;
55
69
  report: import('@gltf-transform/functions').InspectReport | null;
56
70
  error: Error | null;
57
71
  loading: boolean;
58
- } | {
59
- simplifyOptimization: () => void;
60
- dedupOptimization: () => void;
61
- quantizeOptimization: () => void;
62
- texturesCompressOptimization: () => void;
63
- getSize: () => void;
64
- reset: () => void;
65
- report: null;
66
- error: null;
67
- loading: boolean;
68
72
  };
69
73
  file: import('./types').ModelFile | null;
70
74
  isFileLoading: boolean;
@@ -41,28 +41,30 @@ declare function useLoadModel(optimizer?: ReturnType<typeof useOptimizeModel>):
41
41
  * - `loading`: The loading state of the optimizer.
42
42
  */
43
43
  optimize: {
44
+ simplifyOptimization: () => void;
45
+ dedupOptimization: () => void;
46
+ quantizeOptimization: () => void;
47
+ normalsOptimization: () => void;
48
+ texturesCompressOptimization: () => void;
49
+ getSize: () => void;
50
+ reset: () => void;
51
+ report: null;
52
+ error: null;
53
+ loading: boolean;
54
+ } | {
44
55
  simplifyOptimization: (options?: {
45
56
  ratio?: number;
46
57
  error?: number;
47
58
  } | undefined) => Promise<void>;
48
59
  dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
49
60
  quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
61
+ normalsOptimization: (options?: import('@gltf-transform/functions').NormalsOptions | undefined) => Promise<void>;
50
62
  texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
51
63
  getSize: () => import('../use-optimize-model/types').ModelSize | null;
52
64
  reset: () => void;
53
65
  report: import('@gltf-transform/functions').InspectReport | null;
54
66
  error: Error | null;
55
67
  loading: boolean;
56
- } | {
57
- simplifyOptimization: () => void;
58
- dedupOptimization: () => void;
59
- quantizeOptimization: () => void;
60
- texturesCompressOptimization: () => void;
61
- getSize: () => void;
62
- reset: () => void;
63
- report: null;
64
- error: null;
65
- loading: boolean;
66
68
  };
67
69
  file: ModelFile | null;
68
70
  isFileLoading: boolean;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-DLPGvQ8f.cjs");exports.ModelContext=e.ModelContext;exports.ModelFileTypes=e.ModelFileTypes;exports.ModelProvider=e.ModelProvider;exports.useLoadModel=e.useLoadModel;exports.useModelContext=e.useModelContext;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-Du5WQddA.cjs");exports.ModelContext=e.ModelContext;exports.ModelFileTypes=e.ModelFileTypes;exports.ModelProvider=e.ModelProvider;exports.useLoadModel=e.useLoadModel;exports.useModelContext=e.useModelContext;
@@ -1,4 +1,4 @@
1
- import { a as s, M as a, b as d, u as l, c as M } from "./model-context-hgFMs-nK.js";
1
+ import { a as s, M as a, b as d, u as l, c as M } from "./model-context-fEKN9ymq.js";
2
2
  export {
3
3
  s as ModelContext,
4
4
  a as ModelFileTypes,
@@ -1,5 +1,5 @@
1
1
  import { Object3D } from 'three';
2
- import { dedup, quantize, textureCompress } from '@gltf-transform/functions';
2
+ import { dedup, quantize, normals, textureCompress } from '@gltf-transform/functions';
3
3
  import { ModelSize } from './types';
4
4
  /**
5
5
  * Custom React hook for optimizing Three.js models using glTF-Transform.
@@ -20,6 +20,7 @@ declare const useOptimizeModel: () => {
20
20
  }) => Promise<void>;
21
21
  dedupOptimization: (options?: Parameters<typeof dedup>[0]) => Promise<void>;
22
22
  quantizeOptimization: (options?: Parameters<typeof quantize>[0]) => Promise<void>;
23
+ normalsOptimization: (options?: Parameters<typeof normals>[0]) => Promise<void>;
23
24
  texturesOptimization: (options?: Parameters<typeof textureCompress>[0]) => Promise<void>;
24
25
  reset: () => void;
25
26
  error: Error | null;
@@ -1,15 +1,15 @@
1
- import { useReducer as L, useRef as d, useCallback as o } from "react";
2
- import { G as M } from "./GLTFExporter-Q5UJ5eb1.js";
3
- import { WebIO as _ } from "@gltf-transform/core";
4
- import { inspect as y, weld as b, simplify as B, dedup as U, quantize as F, textureCompress as H } from "@gltf-transform/functions";
5
- import { KHRMeshQuantization as K, KHRMaterialsVolume as q, KHRMaterialsTransmission as G } from "@gltf-transform/extensions";
6
- import { MeshoptSimplifier as k } from "meshoptimizer";
1
+ import { useReducer as M, useRef as d, useCallback as n } from "react";
2
+ import { G as _ } from "./GLTFExporter-Q5UJ5eb1.js";
3
+ import { WebIO as b } from "@gltf-transform/core";
4
+ import { inspect as y, weld as B, simplify as U, dedup as F, quantize as H, normals as K, textureCompress as q } from "@gltf-transform/functions";
5
+ import { KHRMeshQuantization as G, KHRMaterialsVolume as k, KHRMaterialsTransmission as I } from "@gltf-transform/extensions";
6
+ import { MeshoptSimplifier as Q } from "meshoptimizer";
7
7
  const f = {
8
8
  modelDoc: null,
9
9
  modelReport: null,
10
10
  error: null,
11
11
  loading: !1
12
- }, I = (i, t) => {
12
+ }, V = (i, t) => {
13
13
  switch (t.type) {
14
14
  case "LOAD_START":
15
15
  return { ...i, loading: !0, error: null };
@@ -27,14 +27,14 @@ const f = {
27
27
  default:
28
28
  return i;
29
29
  }
30
- }, J = () => {
31
- const [i, t] = L(I, f), { modelDoc: n, modelReport: a, error: R, loading: S } = i, O = d(new M()), u = d(
32
- new _().registerExtensions([
33
- K,
34
- q,
35
- G
30
+ }, P = () => {
31
+ const [i, t] = M(V, f), { modelDoc: s, modelReport: a, error: R, loading: S } = i, O = d(new _()), u = d(
32
+ new b().registerExtensions([
33
+ G,
34
+ k,
35
+ I
36
36
  ])
37
- ), z = o(async (r) => {
37
+ ), z = n(async (r) => {
38
38
  t({ type: "LOAD_START" });
39
39
  try {
40
40
  const e = { binary: !0 }, l = await O.current.parseAsync(r, e), c = new Uint8Array(l), p = await u.current.readBinary(c), m = y(p);
@@ -45,77 +45,83 @@ const f = {
45
45
  } catch (e) {
46
46
  t({ type: "LOAD_ERROR", payload: e }), console.error("Error loading model:", e);
47
47
  }
48
- }, []), s = o(
48
+ }, []), o = n(
49
49
  async (r) => {
50
- if (n)
50
+ if (s)
51
51
  try {
52
- await n.transform(...r);
53
- const e = y(n);
52
+ await s.transform(...r);
53
+ const e = y(s);
54
54
  t({
55
55
  type: "LOAD_SUCCESS",
56
- payload: { modelDoc: n, modelReport: e }
56
+ payload: { modelDoc: s, modelReport: e }
57
57
  });
58
58
  } catch (e) {
59
59
  console.error("Error applying transforms:", e);
60
60
  }
61
61
  },
62
- [n]
63
- ), E = o(
62
+ [s]
63
+ ), w = n(
64
64
  async (r) => {
65
65
  const { ratio: e = 0.5, error: l = 1e-3 } = r || {};
66
- await s([
67
- b(),
68
- B({
69
- simplifier: k,
66
+ await o([
67
+ B(),
68
+ U({
69
+ simplifier: Q,
70
70
  ratio: e,
71
71
  error: l
72
72
  })
73
73
  ]);
74
74
  },
75
- [s]
76
- ), w = o(
75
+ [o]
76
+ ), E = n(
77
77
  async (r) => {
78
- await s([U(r)]);
78
+ await o([F(r)]);
79
79
  },
80
- [s]
81
- ), g = o(
80
+ [o]
81
+ ), g = n(
82
82
  async (r) => {
83
- await s([F(r)]);
83
+ await o([H(r)]);
84
84
  },
85
- [s]
86
- ), D = o(
85
+ [o]
86
+ ), D = n(
87
87
  async (r) => {
88
- r && await s([H(r)]);
88
+ await o([K(r)]);
89
89
  },
90
- [s]
91
- ), A = o(async () => {
92
- if (!n) return null;
90
+ [o]
91
+ ), A = n(
92
+ async (r) => {
93
+ r && await o([q(r)]);
94
+ },
95
+ [o]
96
+ ), h = n(async () => {
97
+ if (!s) return null;
93
98
  try {
94
- return await u.current.writeBinary(n);
99
+ return await u.current.writeBinary(s);
95
100
  } catch (r) {
96
101
  return console.error("Error getting model binary:", r), null;
97
102
  }
98
- }, [n]), h = o(() => {
103
+ }, [s]), x = n(() => {
99
104
  if (!a) return null;
100
- const r = (m) => m.reduce((T, C) => T + C.size, 0), e = r(a.meshes.properties), l = r(a.textures.properties), c = e + l, p = `${(c / (1024 * 1024)).toFixed(2)} MB`;
105
+ const r = (m) => m.reduce((C, L) => C + L.size, 0), e = r(a.meshes.properties), l = r(a.textures.properties), c = e + l, p = `${(c / (1024 * 1024)).toFixed(2)} MB`;
101
106
  return { fileSize: c, displayFileSize: p };
102
- }, [a]), x = o(() => {
107
+ }, [a]), T = n(() => {
103
108
  t({ type: "RESET" });
104
109
  }, []);
105
110
  return {
106
111
  load: z,
107
- getModel: A,
108
- getSize: h,
112
+ getModel: h,
113
+ getSize: x,
109
114
  report: a,
110
- simplifyOptimization: E,
111
- dedupOptimization: w,
115
+ simplifyOptimization: w,
116
+ dedupOptimization: E,
112
117
  quantizeOptimization: g,
113
- texturesOptimization: D,
114
- reset: x,
118
+ normalsOptimization: D,
119
+ texturesOptimization: A,
120
+ reset: T,
115
121
  error: R,
116
122
  loading: S
117
123
  };
118
124
  };
119
125
  export {
120
- J as u
126
+ P as u
121
127
  };
@@ -0,0 +1 @@
1
+ "use strict";const r=require("react"),T=require("./GLTFExporter-ltc8rmzz.cjs"),L=require("@gltf-transform/core"),a=require("@gltf-transform/functions"),m=require("@gltf-transform/extensions"),q=require("meshoptimizer"),R={modelDoc:null,modelReport:null,error:null,loading:!1},M=(i,o)=>{switch(o.type){case"LOAD_START":return{...i,loading:!0,error:null};case"LOAD_SUCCESS":return{...i,loading:!1,modelDoc:o.payload.modelDoc,modelReport:o.payload.modelReport};case"LOAD_ERROR":return{...i,loading:!1,error:o.payload};case"RESET":return{...R};default:return i}},_=()=>{const[i,o]=r.useReducer(M,R),{modelDoc:n,modelReport:l,error:f,loading:S}=i,z=r.useRef(new T.GLTFExporter),y=r.useRef(new L.WebIO().registerExtensions([m.KHRMeshQuantization,m.KHRMaterialsVolume,m.KHRMaterialsTransmission])),O=r.useCallback(async e=>{o({type:"LOAD_START"});try{const t={binary:!0},c=await z.current.parseAsync(e,t),u=new Uint8Array(c),p=await y.current.readBinary(u),d=a.inspect(p);o({type:"LOAD_SUCCESS",payload:{modelDoc:p,modelReport:d}})}catch(t){o({type:"LOAD_ERROR",payload:t}),console.error("Error loading model:",t)}},[]),s=r.useCallback(async e=>{if(n)try{await n.transform(...e);const t=a.inspect(n);o({type:"LOAD_SUCCESS",payload:{modelDoc:n,modelReport:t}})}catch(t){console.error("Error applying transforms:",t)}},[n]),C=r.useCallback(async e=>{const{ratio:t=.5,error:c=.001}=e||{};await s([a.weld(),a.simplify({simplifier:q.MeshoptSimplifier,ratio:t,error:c})])},[s]),E=r.useCallback(async e=>{await s([a.dedup(e)])},[s]),w=r.useCallback(async e=>{await s([a.quantize(e)])},[s]),b=r.useCallback(async e=>{await s([a.normals(e)])},[s]),g=r.useCallback(async e=>{e&&await s([a.textureCompress(e)])},[s]),D=r.useCallback(async()=>{if(!n)return null;try{return await y.current.writeBinary(n)}catch(e){return console.error("Error getting model binary:",e),null}},[n]),A=r.useCallback(()=>{if(!l)return null;const e=d=>d.reduce((k,x)=>k+x.size,0),t=e(l.meshes.properties),c=e(l.textures.properties),u=t+c,p=`${(u/(1024*1024)).toFixed(2)} MB`;return{fileSize:u,displayFileSize:p}},[l]),h=r.useCallback(()=>{o({type:"RESET"})},[]);return{load:O,getModel:D,getSize:A,report:l,simplifyOptimization:C,dedupOptimization:E,quantizeOptimization:w,normalsOptimization:b,texturesOptimization:g,reset:h,error:f,loading:S}};exports.useOptimizeModel=_;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./use-optimize-model-BcDBGz71.cjs");exports.useOptimizeModel=e.useOptimizeModel;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./use-optimize-model-EEn8K4nu.cjs");exports.useOptimizeModel=e.useOptimizeModel;
@@ -1,4 +1,4 @@
1
- import { u as i } from "./use-optimize-model-CgEMWTEN.js";
1
+ import { u as i } from "./use-optimize-model-BXWR9d6e.js";
2
2
  export {
3
3
  i as useOptimizeModel
4
4
  };
@@ -1 +0,0 @@
1
- "use strict";const t=require("react"),T=require("./GLTFExporter-ltc8rmzz.cjs"),k=require("@gltf-transform/core"),a=require("@gltf-transform/functions"),m=require("@gltf-transform/extensions"),L=require("meshoptimizer"),R={modelDoc:null,modelReport:null,error:null,loading:!1},q=(i,o)=>{switch(o.type){case"LOAD_START":return{...i,loading:!0,error:null};case"LOAD_SUCCESS":return{...i,loading:!1,modelDoc:o.payload.modelDoc,modelReport:o.payload.modelReport};case"LOAD_ERROR":return{...i,loading:!1,error:o.payload};case"RESET":return{...R};default:return i}},M=()=>{const[i,o]=t.useReducer(q,R),{modelDoc:s,modelReport:l,error:f,loading:S}=i,z=t.useRef(new T.GLTFExporter),y=t.useRef(new k.WebIO().registerExtensions([m.KHRMeshQuantization,m.KHRMaterialsVolume,m.KHRMaterialsTransmission])),O=t.useCallback(async e=>{o({type:"LOAD_START"});try{const r={binary:!0},c=await z.current.parseAsync(e,r),u=new Uint8Array(c),p=await y.current.readBinary(u),d=a.inspect(p);o({type:"LOAD_SUCCESS",payload:{modelDoc:p,modelReport:d}})}catch(r){o({type:"LOAD_ERROR",payload:r}),console.error("Error loading model:",r)}},[]),n=t.useCallback(async e=>{if(s)try{await s.transform(...e);const r=a.inspect(s);o({type:"LOAD_SUCCESS",payload:{modelDoc:s,modelReport:r}})}catch(r){console.error("Error applying transforms:",r)}},[s]),C=t.useCallback(async e=>{const{ratio:r=.5,error:c=.001}=e||{};await n([a.weld(),a.simplify({simplifier:L.MeshoptSimplifier,ratio:r,error:c})])},[n]),E=t.useCallback(async e=>{await n([a.dedup(e)])},[n]),w=t.useCallback(async e=>{await n([a.quantize(e)])},[n]),b=t.useCallback(async e=>{e&&await n([a.textureCompress(e)])},[n]),g=t.useCallback(async()=>{if(!s)return null;try{return await y.current.writeBinary(s)}catch(e){return console.error("Error getting model binary:",e),null}},[s]),D=t.useCallback(()=>{if(!l)return null;const e=d=>d.reduce((h,x)=>h+x.size,0),r=e(l.meshes.properties),c=e(l.textures.properties),u=r+c,p=`${(u/(1024*1024)).toFixed(2)} MB`;return{fileSize:u,displayFileSize:p}},[l]),A=t.useCallback(()=>{o({type:"RESET"})},[]);return{load:O,getModel:g,getSize:D,report:l,simplifyOptimization:C,dedupOptimization:E,quantizeOptimization:w,texturesOptimization:b,reset:A,error:f,loading:S}};exports.useOptimizeModel=M;