@vctrl/hooks 0.4.0 → 0.6.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/README.md +15 -8
- package/index.cjs.js +1 -1
- package/index.d.ts +1 -0
- package/index.es.js +6 -4
- package/{model-context-BmfXsk0j.cjs → model-context-DLPGvQ8f.cjs} +5 -5
- package/{model-context-qjRd1gfd.js → model-context-hgFMs-nK.js} +460 -388
- package/package.json +1 -1
- package/use-export-model-BBfXwJbA.cjs +12 -0
- package/use-export-model-CUUL3YCH.js +2465 -0
- package/use-export-model.cjs.js +1 -12
- package/use-export-model.es.js +2 -2463
- package/use-load-model/model-context.d.ts +38 -0
- package/use-load-model/state.d.ts +8 -0
- package/use-load-model/types.d.ts +2 -1
- package/use-load-model/use-load-model.d.ts +54 -0
- package/use-load-model.cjs.js +1 -1
- package/use-load-model.es.js +1 -1
- package/use-optimize-model/state.d.ts +13 -0
- package/use-optimize-model/types.d.ts +37 -0
- package/use-optimize-model/use-optimize-model.d.ts +23 -4
- package/use-optimize-model-7wjiNiSZ.cjs +1 -0
- package/use-optimize-model-CVcoeFrO.js +117 -0
- package/use-optimize-model.cjs.js +1 -1
- package/use-optimize-model.es.js +1 -1
- package/use-optimize-model-CXJnsRYK.cjs +0 -1
- package/use-optimize-model-CsddjnWO.js +0 -51
|
@@ -8,9 +8,28 @@ declare const ModelContext: import('react').Context<{
|
|
|
8
8
|
load: (filesOrDirectories: import('./types').InputFileOrDirectory) => Promise<void>;
|
|
9
9
|
reset: () => void;
|
|
10
10
|
optimize: {
|
|
11
|
+
simplifyOptimization: (options?: {
|
|
12
|
+
ratio?: number;
|
|
13
|
+
error?: number;
|
|
14
|
+
} | undefined) => Promise<void>;
|
|
15
|
+
dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
|
|
16
|
+
quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
|
|
17
|
+
texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
|
|
18
|
+
getSize: () => import('../use-optimize-model/types').ModelSize | null;
|
|
19
|
+
reset: () => void;
|
|
20
|
+
report: import('@gltf-transform/functions').InspectReport | null;
|
|
21
|
+
error: Error | null;
|
|
22
|
+
loading: boolean;
|
|
23
|
+
} | {
|
|
11
24
|
simplifyOptimization: () => void;
|
|
12
25
|
dedupOptimization: () => void;
|
|
13
26
|
quantizeOptimization: () => void;
|
|
27
|
+
texturesCompressOptimization: () => void;
|
|
28
|
+
getSize: () => void;
|
|
29
|
+
reset: () => void;
|
|
30
|
+
report: null;
|
|
31
|
+
error: null;
|
|
32
|
+
loading: boolean;
|
|
14
33
|
};
|
|
15
34
|
file: import('./types').ModelFile | null;
|
|
16
35
|
isFileLoading: boolean;
|
|
@@ -24,9 +43,28 @@ declare const useModelContext: () => {
|
|
|
24
43
|
load: (filesOrDirectories: import('./types').InputFileOrDirectory) => Promise<void>;
|
|
25
44
|
reset: () => void;
|
|
26
45
|
optimize: {
|
|
46
|
+
simplifyOptimization: (options?: {
|
|
47
|
+
ratio?: number;
|
|
48
|
+
error?: number;
|
|
49
|
+
} | undefined) => Promise<void>;
|
|
50
|
+
dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
|
|
51
|
+
quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
|
|
52
|
+
texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
|
|
53
|
+
getSize: () => import('../use-optimize-model/types').ModelSize | null;
|
|
54
|
+
reset: () => void;
|
|
55
|
+
report: import('@gltf-transform/functions').InspectReport | null;
|
|
56
|
+
error: Error | null;
|
|
57
|
+
loading: boolean;
|
|
58
|
+
} | {
|
|
27
59
|
simplifyOptimization: () => void;
|
|
28
60
|
dedupOptimization: () => void;
|
|
29
61
|
quantizeOptimization: () => void;
|
|
62
|
+
texturesCompressOptimization: () => void;
|
|
63
|
+
getSize: () => void;
|
|
64
|
+
reset: () => void;
|
|
65
|
+
report: null;
|
|
66
|
+
error: null;
|
|
67
|
+
loading: boolean;
|
|
30
68
|
};
|
|
31
69
|
file: import('./types').ModelFile | null;
|
|
32
70
|
isFileLoading: boolean;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { Action, State } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Initial state for the useReadModelFiles hook
|
|
4
|
+
*
|
|
5
|
+
* @property file - Currently loaded file
|
|
6
|
+
* @property isFileLoading - Flag indicating if a file is currently being loaded
|
|
7
|
+
* @property progress - Current loading progress (0-100)
|
|
8
|
+
* @property supportedFileTypes - List of supported file types
|
|
9
|
+
*/
|
|
2
10
|
export declare const initialState: State;
|
|
3
11
|
/**
|
|
4
12
|
* Reducer function for the useReadModelFiles hook
|
|
@@ -38,10 +38,11 @@ export type Action = {
|
|
|
38
38
|
} | {
|
|
39
39
|
type: 'reset-state';
|
|
40
40
|
};
|
|
41
|
-
export type EventTypes = 'multiple-models' | 'not-loaded-files' | 'load-progress' | 'load-complete' | 'load-reset' | 'load-error';
|
|
41
|
+
export type EventTypes = 'multiple-models' | 'not-loaded-files' | 'load-start' | 'load-progress' | 'load-complete' | 'load-reset' | 'load-error';
|
|
42
42
|
export type EventData = {
|
|
43
43
|
'multiple-models': File[];
|
|
44
44
|
'not-loaded-files': File[];
|
|
45
|
+
'load-start': null;
|
|
45
46
|
'load-progress': number;
|
|
46
47
|
'load-complete': State['file'];
|
|
47
48
|
'load-reset': null;
|
|
@@ -1,14 +1,68 @@
|
|
|
1
1
|
import { useOptimizeModel } from '../use-optimize-model';
|
|
2
2
|
import { ModelFileTypes, InputFileOrDirectory, ModelFile } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to load and manage 3D models, integrating optimization functionalities.
|
|
5
|
+
*
|
|
6
|
+
* @param optimizer - Optional optimizer hook returned from useOptimizeModel.
|
|
7
|
+
* @returns An object containing the state, event handlers, and optimization functions.
|
|
8
|
+
*/
|
|
3
9
|
declare function useLoadModel(optimizer?: ReturnType<typeof useOptimizeModel>): {
|
|
10
|
+
/**
|
|
11
|
+
* Add an event listener to the event system.
|
|
12
|
+
*/
|
|
4
13
|
on: <T extends import('./types').EventTypes>(event: T, handler?: import('./types').EventHandler<T>) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Remove an event listener from the event system.
|
|
16
|
+
*/
|
|
5
17
|
off: <T extends import('./types').EventTypes>(event: T, handler?: import('./types').EventHandler<T>) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Load a model and integrate it with the optimizer if available.
|
|
20
|
+
* This also makes the model available in the use-model-context hook.
|
|
21
|
+
*/
|
|
6
22
|
load: (filesOrDirectories: InputFileOrDirectory) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Reset the model and optimizer state to the initial state.
|
|
25
|
+
*/
|
|
7
26
|
reset: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Integration of the optimizer
|
|
29
|
+
* An object containing functions to interact with the optimizer.
|
|
30
|
+
*
|
|
31
|
+
* It exposes the following functions:
|
|
32
|
+
*
|
|
33
|
+
* - `simplifyOptimization(options?: SimplifyOptions)`: Runs the simplification optimization with the given options.
|
|
34
|
+
* - `dedupOptimization(options?: DedupOptions)`: Runs the deduplication optimization with the given options.
|
|
35
|
+
* - `quantizeOptimization(options?: QuantizeOptions)`: Runs the quantization optimization with the given options.
|
|
36
|
+
* - `texturesCompressionOptimization(options?: TextureCompressionOptions)`: Runs the texture compression optimization with the given options.
|
|
37
|
+
* - `getSize()`: Returns the size of the optimized model.
|
|
38
|
+
* - `reset()`: Resets the optimizer.
|
|
39
|
+
* - `report`: The report state of the optimizer.
|
|
40
|
+
* - `error`: The error state of the optimizer.
|
|
41
|
+
* - `loading`: The loading state of the optimizer.
|
|
42
|
+
*/
|
|
8
43
|
optimize: {
|
|
44
|
+
simplifyOptimization: (options?: {
|
|
45
|
+
ratio?: number;
|
|
46
|
+
error?: number;
|
|
47
|
+
} | undefined) => Promise<void>;
|
|
48
|
+
dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
|
|
49
|
+
quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
|
|
50
|
+
texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
|
|
51
|
+
getSize: () => import('../use-optimize-model/types').ModelSize | null;
|
|
52
|
+
reset: () => void;
|
|
53
|
+
report: import('@gltf-transform/functions').InspectReport | null;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
} | {
|
|
9
57
|
simplifyOptimization: () => void;
|
|
10
58
|
dedupOptimization: () => void;
|
|
11
59
|
quantizeOptimization: () => void;
|
|
60
|
+
texturesCompressOptimization: () => void;
|
|
61
|
+
getSize: () => void;
|
|
62
|
+
reset: () => void;
|
|
63
|
+
report: null;
|
|
64
|
+
error: null;
|
|
65
|
+
loading: boolean;
|
|
12
66
|
};
|
|
13
67
|
file: ModelFile | null;
|
|
14
68
|
isFileLoading: boolean;
|
package/use-load-model.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-
|
|
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;
|
package/use-load-model.es.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Action, State } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Initial state for the reducer.
|
|
4
|
+
*/
|
|
5
|
+
export declare const initialState: State;
|
|
6
|
+
/**
|
|
7
|
+
* Reducer function to manage state transitions.
|
|
8
|
+
*
|
|
9
|
+
* @param state - Current state.
|
|
10
|
+
* @param action - Action to perform.
|
|
11
|
+
* @returns New state after applying the action.
|
|
12
|
+
*/
|
|
13
|
+
export declare const reducer: (state: State, action: Action) => State;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Document } from '@gltf-transform/core';
|
|
2
|
+
import { InspectReport } from '@gltf-transform/functions';
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing the size details of the model.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModelSize {
|
|
7
|
+
/** The file size in bytes. */
|
|
8
|
+
fileSize: number;
|
|
9
|
+
/** The file size formatted as a human-readable string. */
|
|
10
|
+
displayFileSize: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Interface representing the state of the model optimizer.
|
|
14
|
+
*/
|
|
15
|
+
export interface State {
|
|
16
|
+
modelDoc: Document | null;
|
|
17
|
+
modelReport: InspectReport | null;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Types of actions for the reducer.
|
|
23
|
+
*/
|
|
24
|
+
export type Action = {
|
|
25
|
+
type: 'LOAD_START';
|
|
26
|
+
} | {
|
|
27
|
+
type: 'LOAD_SUCCESS';
|
|
28
|
+
payload: {
|
|
29
|
+
modelDoc: Document;
|
|
30
|
+
modelReport: InspectReport;
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
type: 'LOAD_ERROR';
|
|
34
|
+
payload: Error;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'RESET';
|
|
37
|
+
};
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { Object3D } from 'three';
|
|
2
|
+
import { dedup, quantize, textureCompress } from '@gltf-transform/functions';
|
|
3
|
+
import { ModelSize } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Custom React hook for optimizing Three.js models using glTF-Transform.
|
|
6
|
+
*
|
|
7
|
+
* This hook provides functions to load, optimize, and retrieve Three.js models.
|
|
8
|
+
* Optimizations include deduplication, quantization, and simplification of model meshes and textures.
|
|
9
|
+
*
|
|
10
|
+
* @returns An object containing functions to interact with the model optimizer.
|
|
11
|
+
*/
|
|
2
12
|
declare const useOptimizeModel: () => {
|
|
3
13
|
load: (model: Object3D) => Promise<void>;
|
|
4
|
-
getModel: () => Promise<Uint8Array |
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
getModel: () => Promise<Uint8Array | null>;
|
|
15
|
+
getSize: () => ModelSize | null;
|
|
16
|
+
report: import('@gltf-transform/functions').InspectReport | null;
|
|
17
|
+
simplifyOptimization: (options?: {
|
|
18
|
+
ratio?: number;
|
|
19
|
+
error?: number;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
dedupOptimization: (options?: Parameters<typeof dedup>[0]) => Promise<void>;
|
|
22
|
+
quantizeOptimization: (options?: Parameters<typeof quantize>[0]) => Promise<void>;
|
|
23
|
+
texturesOptimization: (options?: Parameters<typeof textureCompress>[0]) => Promise<void>;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
error: Error | null;
|
|
26
|
+
loading: boolean;
|
|
8
27
|
};
|
|
9
28
|
export default useOptimizeModel;
|
|
@@ -0,0 +1 @@
|
|
|
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=_;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useReducer as T, useRef as m, useCallback as o } 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 M, simplify as B, dedup as U, quantize as F, textureCompress as q } from "@gltf-transform/functions";
|
|
5
|
+
import { KHRMeshQuantization as G } from "@gltf-transform/extensions";
|
|
6
|
+
import { MeshoptSimplifier as k } from "meshoptimizer";
|
|
7
|
+
const f = {
|
|
8
|
+
modelDoc: null,
|
|
9
|
+
modelReport: null,
|
|
10
|
+
error: null,
|
|
11
|
+
loading: !1
|
|
12
|
+
}, H = (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
|
+
}, v = () => {
|
|
31
|
+
const [i, t] = T(H, f), { modelDoc: n, modelReport: a, error: R, loading: S } = i, O = m(new _()), d = m(
|
|
32
|
+
new b().registerExtensions([G])
|
|
33
|
+
), z = o(async (r) => {
|
|
34
|
+
t({ type: "LOAD_START" });
|
|
35
|
+
try {
|
|
36
|
+
const e = { binary: !0 }, l = await O.current.parseAsync(r, e), c = new Uint8Array(l), p = await d.current.readBinary(c), u = y(p);
|
|
37
|
+
t({
|
|
38
|
+
type: "LOAD_SUCCESS",
|
|
39
|
+
payload: { modelDoc: p, modelReport: u }
|
|
40
|
+
});
|
|
41
|
+
} catch (e) {
|
|
42
|
+
t({ type: "LOAD_ERROR", payload: e }), console.error("Error loading model:", e);
|
|
43
|
+
}
|
|
44
|
+
}, []), s = o(
|
|
45
|
+
async (r) => {
|
|
46
|
+
if (n)
|
|
47
|
+
try {
|
|
48
|
+
await n.transform(...r);
|
|
49
|
+
const e = y(n);
|
|
50
|
+
t({
|
|
51
|
+
type: "LOAD_SUCCESS",
|
|
52
|
+
payload: { modelDoc: n, modelReport: e }
|
|
53
|
+
});
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error("Error applying transforms:", e);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
[n]
|
|
59
|
+
), E = o(
|
|
60
|
+
async (r) => {
|
|
61
|
+
const { ratio: e = 0.5, error: l = 1e-3 } = r || {};
|
|
62
|
+
await s([
|
|
63
|
+
M(),
|
|
64
|
+
B({
|
|
65
|
+
simplifier: k,
|
|
66
|
+
ratio: e,
|
|
67
|
+
error: l
|
|
68
|
+
})
|
|
69
|
+
]);
|
|
70
|
+
},
|
|
71
|
+
[s]
|
|
72
|
+
), w = o(
|
|
73
|
+
async (r) => {
|
|
74
|
+
await s([U(r)]);
|
|
75
|
+
},
|
|
76
|
+
[s]
|
|
77
|
+
), g = o(
|
|
78
|
+
async (r) => {
|
|
79
|
+
await s([F(r)]);
|
|
80
|
+
},
|
|
81
|
+
[s]
|
|
82
|
+
), D = o(
|
|
83
|
+
async (r) => {
|
|
84
|
+
r && await s([q(r)]);
|
|
85
|
+
},
|
|
86
|
+
[s]
|
|
87
|
+
), A = o(async () => {
|
|
88
|
+
if (!n) return null;
|
|
89
|
+
try {
|
|
90
|
+
return await d.current.writeBinary(n);
|
|
91
|
+
} catch (r) {
|
|
92
|
+
return console.error("Error getting model binary:", r), null;
|
|
93
|
+
}
|
|
94
|
+
}, [n]), h = o(() => {
|
|
95
|
+
if (!a) return null;
|
|
96
|
+
const r = (u) => u.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`;
|
|
97
|
+
return { fileSize: c, displayFileSize: p };
|
|
98
|
+
}, [a]), x = o(() => {
|
|
99
|
+
t({ type: "RESET" });
|
|
100
|
+
}, []);
|
|
101
|
+
return {
|
|
102
|
+
load: z,
|
|
103
|
+
getModel: A,
|
|
104
|
+
getSize: h,
|
|
105
|
+
report: a,
|
|
106
|
+
simplifyOptimization: E,
|
|
107
|
+
dedupOptimization: w,
|
|
108
|
+
quantizeOptimization: g,
|
|
109
|
+
texturesOptimization: D,
|
|
110
|
+
reset: x,
|
|
111
|
+
error: R,
|
|
112
|
+
loading: S
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
v as u
|
|
117
|
+
};
|
|
@@ -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-7wjiNiSZ.cjs");exports.useOptimizeModel=e.useOptimizeModel;
|
package/use-optimize-model.es.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const f=require("react"),m=require("./GLTFExporter-ltc8rmzz.cjs"),d=require("@gltf-transform/core"),t=require("@gltf-transform/functions"),l=require("@gltf-transform/extensions"),p=require("meshoptimizer"),y=new m.GLTFExporter,n=new d.WebIO;n.registerExtensions([l.KHRMeshQuantization]);const w=()=>{const r=f.useRef(null);async function i(e){const a=await y.parseAsync(e,{binary:!0});r.current=await n.readBinary(new Uint8Array(a))}async function o(){if(!r.current)return;const e=await r.current.transform(t.flatten(),t.quantize(),t.weld(),t.simplify({simplifier:p.MeshoptSimplifier,ratio:.1,error:1e-4}));r.current=e}async function s(){if(!r.current)return;const e=await r.current.transform(t.dedup({}));r.current=e}async function u(){if(!r.current)return;const e=await r.current.transform(t.quantize({}));r.current=e}async function c(){if(r.current)return await n.writeBinary(r.current)}return{load:i,getModel:c,simplifyOptimization:o,dedupOptimization:s,quantizeOptimization:u}};exports.useOptimizeModel=w;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useRef as f } from "react";
|
|
2
|
-
import { G as m } from "./GLTFExporter-Q5UJ5eb1.js";
|
|
3
|
-
import { WebIO as p } from "@gltf-transform/core";
|
|
4
|
-
import { flatten as d, quantize as e, weld as l, simplify as y, dedup as w } from "@gltf-transform/functions";
|
|
5
|
-
import { KHRMeshQuantization as z } from "@gltf-transform/extensions";
|
|
6
|
-
import { MeshoptSimplifier as M } from "meshoptimizer";
|
|
7
|
-
const O = new m(), n = new p();
|
|
8
|
-
n.registerExtensions([z]);
|
|
9
|
-
const A = () => {
|
|
10
|
-
const r = f(null);
|
|
11
|
-
async function i(t) {
|
|
12
|
-
const c = await O.parseAsync(t, {
|
|
13
|
-
binary: !0
|
|
14
|
-
});
|
|
15
|
-
r.current = await n.readBinary(new Uint8Array(c));
|
|
16
|
-
}
|
|
17
|
-
async function o() {
|
|
18
|
-
if (!r.current) return;
|
|
19
|
-
const t = await r.current.transform(
|
|
20
|
-
d(),
|
|
21
|
-
e(),
|
|
22
|
-
l(),
|
|
23
|
-
y({ simplifier: M, ratio: 0.1, error: 1e-4 })
|
|
24
|
-
);
|
|
25
|
-
r.current = t;
|
|
26
|
-
}
|
|
27
|
-
async function a() {
|
|
28
|
-
if (!r.current) return;
|
|
29
|
-
const t = await r.current.transform(w({}));
|
|
30
|
-
r.current = t;
|
|
31
|
-
}
|
|
32
|
-
async function u() {
|
|
33
|
-
if (!r.current) return;
|
|
34
|
-
const t = await r.current.transform(e({}));
|
|
35
|
-
r.current = t;
|
|
36
|
-
}
|
|
37
|
-
async function s() {
|
|
38
|
-
if (r.current)
|
|
39
|
-
return await n.writeBinary(r.current);
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
load: i,
|
|
43
|
-
getModel: s,
|
|
44
|
-
simplifyOptimization: o,
|
|
45
|
-
dedupOptimization: a,
|
|
46
|
-
quantizeOptimization: u
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
A as u
|
|
51
|
-
};
|