@vctrl/hooks 0.9.4 → 0.11.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +202 -383
  3. package/package.json +66 -55
  4. package/project.json +55 -0
  5. package/src/index.ts +38 -0
  6. package/src/use-export-model/use-export-model.ts +113 -0
  7. package/src/use-load-model/event-system.ts +46 -0
  8. package/src/use-load-model/index.ts +15 -0
  9. package/src/use-load-model/model-context.tsx +174 -0
  10. package/src/use-load-model/state.ts +75 -0
  11. package/src/use-load-model/types.ts +284 -0
  12. package/src/use-load-model/use-load-model.ts +682 -0
  13. package/src/use-load-model/utils/calculate-referenced-bytes.ts +123 -0
  14. package/src/use-load-model/utils/index.ts +7 -0
  15. package/src/use-load-model/utils/read-directory.ts +35 -0
  16. package/src/use-load-model/utils/reconstruct-files.ts +85 -0
  17. package/src/use-load-model/utils/resolve-scene-payload.ts +151 -0
  18. package/{use-optimize-model/index.d.ts → src/use-optimize-model/index.ts} +2 -1
  19. package/src/use-optimize-model/state.ts +40 -0
  20. package/src/use-optimize-model/types.ts +37 -0
  21. package/src/use-optimize-model/use-calc-optimization-info.ts +97 -0
  22. package/src/use-optimize-model/use-optimize-model.ts +467 -0
  23. package/src/use-optimize-model/utils/index.ts +29 -0
  24. package/src/use-optimize-model/utils/texture-optimization.ts +292 -0
  25. package/src/use-optimize-model/utils/validation.ts +62 -0
  26. package/src/utils/server-communication.ts +351 -0
  27. package/tsconfig.json +21 -0
  28. package/tsconfig.lib.json +16 -0
  29. package/vite.config.ts +77 -0
  30. package/GLTFExporter-Q5UJ5eb1.js +0 -1265
  31. package/GLTFExporter-ltc8rmzz.cjs +0 -18
  32. package/index.cjs.js +0 -1
  33. package/index.d.ts +0 -3
  34. package/index.es.js +0 -12
  35. package/model-context-Du5WQddA.cjs +0 -9
  36. package/model-context-fEKN9ymq.js +0 -3443
  37. package/use-export-model/types.d.ts +0 -19
  38. package/use-export-model/use-export-model.d.ts +0 -14
  39. package/use-export-model/utils/data-uri-to-blob.d.ts +0 -9
  40. package/use-export-model/utils/export-handlers.d.ts +0 -23
  41. package/use-export-model/utils/file-helpers.d.ts +0 -17
  42. package/use-export-model/utils/index.d.ts +0 -3
  43. package/use-export-model-BfzYIkcD.cjs +0 -1
  44. package/use-export-model-ccF7tK6m.js +0 -76
  45. package/use-export-model.cjs.js +0 -1
  46. package/use-export-model.es.js +0 -4
  47. package/use-load-model/event-system.d.ts +0 -7
  48. package/use-load-model/file-type-hooks/index.d.ts +0 -2
  49. package/use-load-model/file-type-hooks/use-load-binary.d.ts +0 -11
  50. package/use-load-model/file-type-hooks/use-load-gltf.d.ts +0 -5
  51. package/use-load-model/index.d.ts +0 -3
  52. package/use-load-model/loaders/create-gltf-loader.d.ts +0 -3
  53. package/use-load-model/loaders/create-usdz-loader.d.ts +0 -3
  54. package/use-load-model/loaders/index.d.ts +0 -2
  55. package/use-load-model/model-context.d.ts +0 -78
  56. package/use-load-model/state.d.ts +0 -19
  57. package/use-load-model/types.d.ts +0 -51
  58. package/use-load-model/use-load-model.d.ts +0 -74
  59. package/use-load-model/utils/array-buffer-to-base64.d.ts +0 -2
  60. package/use-load-model/utils/index.d.ts +0 -2
  61. package/use-load-model/utils/read-directory.d.ts +0 -8
  62. package/use-load-model.cjs.js +0 -1
  63. package/use-load-model.es.js +0 -8
  64. package/use-optimize-model/state.d.ts +0 -13
  65. package/use-optimize-model/types.d.ts +0 -37
  66. package/use-optimize-model/use-optimize-model.d.ts +0 -29
  67. package/use-optimize-model-BXWR9d6e.js +0 -127
  68. package/use-optimize-model-EEn8K4nu.cjs +0 -1
  69. package/use-optimize-model.cjs.js +0 -1
  70. package/use-optimize-model.es.js +0 -4
  71. /package/{use-export-model/index.d.ts → src/use-export-model/index.ts} +0 -0
@@ -1,127 +0,0 @@
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
- const f = {
8
- modelDoc: null,
9
- modelReport: null,
10
- error: null,
11
- loading: !1
12
- }, V = (i, t) => {
13
- switch (t.type) {
14
- case "LOAD_START":
15
- return { ...i, loading: !0, error: null };
16
- case "LOAD_SUCCESS":
17
- return {
18
- ...i,
19
- loading: !1,
20
- modelDoc: t.payload.modelDoc,
21
- modelReport: t.payload.modelReport
22
- };
23
- case "LOAD_ERROR":
24
- return { ...i, loading: !1, error: t.payload };
25
- case "RESET":
26
- return { ...f };
27
- default:
28
- return i;
29
- }
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
- ])
37
- ), z = n(async (r) => {
38
- t({ type: "LOAD_START" });
39
- try {
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);
41
- t({
42
- type: "LOAD_SUCCESS",
43
- payload: { modelDoc: p, modelReport: m }
44
- });
45
- } catch (e) {
46
- t({ type: "LOAD_ERROR", payload: e }), console.error("Error loading model:", e);
47
- }
48
- }, []), o = n(
49
- async (r) => {
50
- if (s)
51
- try {
52
- await s.transform(...r);
53
- const e = y(s);
54
- t({
55
- type: "LOAD_SUCCESS",
56
- payload: { modelDoc: s, modelReport: e }
57
- });
58
- } catch (e) {
59
- console.error("Error applying transforms:", e);
60
- }
61
- },
62
- [s]
63
- ), w = n(
64
- async (r) => {
65
- const { ratio: e = 0.5, error: l = 1e-3 } = r || {};
66
- await o([
67
- B(),
68
- U({
69
- simplifier: Q,
70
- ratio: e,
71
- error: l
72
- })
73
- ]);
74
- },
75
- [o]
76
- ), E = n(
77
- async (r) => {
78
- await o([F(r)]);
79
- },
80
- [o]
81
- ), g = n(
82
- async (r) => {
83
- await o([H(r)]);
84
- },
85
- [o]
86
- ), D = n(
87
- async (r) => {
88
- await o([K(r)]);
89
- },
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;
98
- try {
99
- return await u.current.writeBinary(s);
100
- } catch (r) {
101
- return console.error("Error getting model binary:", r), null;
102
- }
103
- }, [s]), x = n(() => {
104
- if (!a) return null;
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`;
106
- return { fileSize: c, displayFileSize: p };
107
- }, [a]), T = n(() => {
108
- t({ type: "RESET" });
109
- }, []);
110
- return {
111
- load: z,
112
- getModel: h,
113
- getSize: x,
114
- report: a,
115
- simplifyOptimization: w,
116
- dedupOptimization: E,
117
- quantizeOptimization: g,
118
- normalsOptimization: D,
119
- texturesOptimization: A,
120
- reset: T,
121
- error: R,
122
- loading: S
123
- };
124
- };
125
- export {
126
- P as u
127
- };
@@ -1 +0,0 @@
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 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./use-optimize-model-EEn8K4nu.cjs");exports.useOptimizeModel=e.useOptimizeModel;
@@ -1,4 +0,0 @@
1
- import { u as i } from "./use-optimize-model-BXWR9d6e.js";
2
- export {
3
- i as useOptimizeModel
4
- };