@vctrl/hooks 0.7.3 → 0.7.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.
- package/index.cjs.js +1 -1
- package/index.es.js +1 -1
- package/package.json +1 -1
- package/use-optimize-model-BcDBGz71.cjs +1 -0
- package/{use-optimize-model-CVcoeFrO.js → use-optimize-model-CgEMWTEN.js} +20 -16
- package/use-optimize-model.cjs.js +1 -1
- package/use-optimize-model.es.js +1 -1
- package/use-optimize-model-7wjiNiSZ.cjs +0 -1
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-DLPGvQ8f.cjs"),o=require("./use-optimize-model-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-DLPGvQ8f.cjs"),o=require("./use-optimize-model-BcDBGz71.cjs"),t=require("./use-export-model-BfzYIkcD.cjs");exports.ModelContext=e.ModelContext;exports.ModelFileTypes=e.ModelFileTypes;exports.ModelProvider=e.ModelProvider;exports.useLoadModel=e.useLoadModel;exports.useModelContext=e.useModelContext;exports.useOptimizeModel=o.useOptimizeModel;exports.useExportModel=t.useExportModel;
|
package/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as s, M as a, b as d, u as r, c as t } from "./model-context-hgFMs-nK.js";
|
|
2
|
-
import { u as M } from "./use-optimize-model-
|
|
2
|
+
import { u as M } from "./use-optimize-model-CgEMWTEN.js";
|
|
3
3
|
import { u as p } from "./use-export-model-ccF7tK6m.js";
|
|
4
4
|
export {
|
|
5
5
|
s as ModelContext,
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.7.
|
|
2
|
+
"version": "0.7.4",
|
|
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": {
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useReducer as
|
|
2
|
-
import { G as
|
|
3
|
-
import { WebIO as
|
|
4
|
-
import { inspect as y, weld as
|
|
5
|
-
import { KHRMeshQuantization as G } from "@gltf-transform/extensions";
|
|
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
6
|
import { MeshoptSimplifier as k } from "meshoptimizer";
|
|
7
7
|
const f = {
|
|
8
8
|
modelDoc: null,
|
|
9
9
|
modelReport: null,
|
|
10
10
|
error: null,
|
|
11
11
|
loading: !1
|
|
12
|
-
},
|
|
12
|
+
}, I = (i, t) => {
|
|
13
13
|
switch (t.type) {
|
|
14
14
|
case "LOAD_START":
|
|
15
15
|
return { ...i, loading: !0, error: null };
|
|
@@ -27,16 +27,20 @@ const f = {
|
|
|
27
27
|
default:
|
|
28
28
|
return i;
|
|
29
29
|
}
|
|
30
|
-
},
|
|
31
|
-
const [i, t] =
|
|
32
|
-
new
|
|
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
|
|
36
|
+
])
|
|
33
37
|
), z = o(async (r) => {
|
|
34
38
|
t({ type: "LOAD_START" });
|
|
35
39
|
try {
|
|
36
|
-
const e = { binary: !0 }, l = await O.current.parseAsync(r, e), c = new Uint8Array(l), p = await
|
|
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);
|
|
37
41
|
t({
|
|
38
42
|
type: "LOAD_SUCCESS",
|
|
39
|
-
payload: { modelDoc: p, modelReport:
|
|
43
|
+
payload: { modelDoc: p, modelReport: m }
|
|
40
44
|
});
|
|
41
45
|
} catch (e) {
|
|
42
46
|
t({ type: "LOAD_ERROR", payload: e }), console.error("Error loading model:", e);
|
|
@@ -60,7 +64,7 @@ const f = {
|
|
|
60
64
|
async (r) => {
|
|
61
65
|
const { ratio: e = 0.5, error: l = 1e-3 } = r || {};
|
|
62
66
|
await s([
|
|
63
|
-
|
|
67
|
+
b(),
|
|
64
68
|
B({
|
|
65
69
|
simplifier: k,
|
|
66
70
|
ratio: e,
|
|
@@ -81,19 +85,19 @@ const f = {
|
|
|
81
85
|
[s]
|
|
82
86
|
), D = o(
|
|
83
87
|
async (r) => {
|
|
84
|
-
r && await s([
|
|
88
|
+
r && await s([H(r)]);
|
|
85
89
|
},
|
|
86
90
|
[s]
|
|
87
91
|
), A = o(async () => {
|
|
88
92
|
if (!n) return null;
|
|
89
93
|
try {
|
|
90
|
-
return await
|
|
94
|
+
return await u.current.writeBinary(n);
|
|
91
95
|
} catch (r) {
|
|
92
96
|
return console.error("Error getting model binary:", r), null;
|
|
93
97
|
}
|
|
94
98
|
}, [n]), h = o(() => {
|
|
95
99
|
if (!a) return null;
|
|
96
|
-
const r = (
|
|
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`;
|
|
97
101
|
return { fileSize: c, displayFileSize: p };
|
|
98
102
|
}, [a]), x = o(() => {
|
|
99
103
|
t({ type: "RESET" });
|
|
@@ -113,5 +117,5 @@ const f = {
|
|
|
113
117
|
};
|
|
114
118
|
};
|
|
115
119
|
export {
|
|
116
|
-
|
|
120
|
+
J as u
|
|
117
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./use-optimize-model-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./use-optimize-model-BcDBGz71.cjs");exports.useOptimizeModel=e.useOptimizeModel;
|
package/use-optimize-model.es.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const t=require("react"),x=require("./GLTFExporter-ltc8rmzz.cjs"),k=require("@gltf-transform/core"),a=require("@gltf-transform/functions"),L=require("@gltf-transform/extensions"),T=require("meshoptimizer"),y={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{...y};default:return i}},_=()=>{const[i,o]=t.useReducer(q,y),{modelDoc:s,modelReport:c,error:f,loading:R}=i,S=t.useRef(new x.GLTFExporter),m=t.useRef(new k.WebIO().registerExtensions([L.KHRMeshQuantization])),z=t.useCallback(async e=>{o({type:"LOAD_START"});try{const r={binary:!0},l=await S.current.parseAsync(e,r),u=new Uint8Array(l),p=await m.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]),O=t.useCallback(async e=>{const{ratio:r=.5,error:l=.001}=e||{};await n([a.weld(),a.simplify({simplifier:T.MeshoptSimplifier,ratio:r,error:l})])},[n]),C=t.useCallback(async e=>{await n([a.dedup(e)])},[n]),E=t.useCallback(async e=>{await n([a.quantize(e)])},[n]),w=t.useCallback(async e=>{e&&await n([a.textureCompress(e)])},[n]),b=t.useCallback(async()=>{if(!s)return null;try{return await m.current.writeBinary(s)}catch(e){return console.error("Error getting model binary:",e),null}},[s]),g=t.useCallback(()=>{if(!c)return null;const e=d=>d.reduce((A,h)=>A+h.size,0),r=e(c.meshes.properties),l=e(c.textures.properties),u=r+l,p=`${(u/(1024*1024)).toFixed(2)} MB`;return{fileSize:u,displayFileSize:p}},[c]),D=t.useCallback(()=>{o({type:"RESET"})},[]);return{load:z,getModel:b,getSize:g,report:c,simplifyOptimization:O,dedupOptimization:C,quantizeOptimization:E,texturesOptimization:w,reset:D,error:f,loading:R}};exports.useOptimizeModel=_;
|