@qy_better_lib/hooks 0.2.13 → 0.2.15
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/lib/use-three/index.mjs +100 -78
- package/lib/use-three/interface.d.ts +18 -4
- package/lib/use-three/modules/loader.d.ts +11 -12
- package/package.json +1 -1
package/lib/use-three/index.mjs
CHANGED
|
@@ -731,82 +731,15 @@ function use_loader(current_three) {
|
|
|
731
731
|
model: null
|
|
732
732
|
};
|
|
733
733
|
use_draco_loader(loader);
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
(gltf) => {
|
|
737
|
-
loadingState.loaded = true;
|
|
738
|
-
loadingState.progress = 1;
|
|
739
|
-
loadingState.model = gltf.scene;
|
|
740
|
-
current_three.scene?.add(gltf.scene);
|
|
741
|
-
},
|
|
742
|
-
(xhr) => {
|
|
743
|
-
if (xhr.total) {
|
|
744
|
-
loadingState.progress = xhr.loaded / xhr.total;
|
|
745
|
-
options?.onProgress?.(loadingState.progress);
|
|
746
|
-
}
|
|
747
|
-
},
|
|
748
|
-
(error) => {
|
|
749
|
-
loadingState.error = error;
|
|
750
|
-
options?.onError?.(error);
|
|
751
|
-
}
|
|
752
|
-
);
|
|
753
|
-
return loadingState;
|
|
754
|
-
}
|
|
755
|
-
function load_obj_model(url, mtlUrl, options) {
|
|
756
|
-
const loadingState = {
|
|
757
|
-
progress: 0,
|
|
758
|
-
loaded: false,
|
|
759
|
-
error: null,
|
|
760
|
-
model: null
|
|
761
|
-
};
|
|
762
|
-
if (mtlUrl) {
|
|
763
|
-
const mtlLoader = new MTLLoader();
|
|
764
|
-
mtlLoader.load(
|
|
765
|
-
mtlUrl,
|
|
766
|
-
(materials) => {
|
|
767
|
-
materials.preload();
|
|
768
|
-
const objLoader = new OBJLoader();
|
|
769
|
-
objLoader.setMaterials(materials);
|
|
770
|
-
objLoader.load(
|
|
771
|
-
url,
|
|
772
|
-
(object) => {
|
|
773
|
-
loadingState.loaded = true;
|
|
774
|
-
loadingState.progress = 1;
|
|
775
|
-
loadingState.model = object;
|
|
776
|
-
current_three.scene?.add(object);
|
|
777
|
-
},
|
|
778
|
-
(xhr) => {
|
|
779
|
-
if (xhr.total) {
|
|
780
|
-
loadingState.progress = xhr.loaded / xhr.total;
|
|
781
|
-
options?.onProgress?.(loadingState.progress);
|
|
782
|
-
}
|
|
783
|
-
},
|
|
784
|
-
(error) => {
|
|
785
|
-
loadingState.error = error;
|
|
786
|
-
options?.onError?.(error);
|
|
787
|
-
}
|
|
788
|
-
);
|
|
789
|
-
},
|
|
790
|
-
(xhr) => {
|
|
791
|
-
if (xhr.total) {
|
|
792
|
-
loadingState.progress = xhr.loaded / xhr.total * 0.5;
|
|
793
|
-
options?.onProgress?.(loadingState.progress);
|
|
794
|
-
}
|
|
795
|
-
},
|
|
796
|
-
(error) => {
|
|
797
|
-
loadingState.error = error;
|
|
798
|
-
options?.onError?.(error);
|
|
799
|
-
}
|
|
800
|
-
);
|
|
801
|
-
} else {
|
|
802
|
-
const objLoader = new OBJLoader();
|
|
803
|
-
objLoader.load(
|
|
734
|
+
return new Promise((resolve, reject) => {
|
|
735
|
+
loader.load(
|
|
804
736
|
url,
|
|
805
|
-
(
|
|
737
|
+
(gltf) => {
|
|
806
738
|
loadingState.loaded = true;
|
|
807
739
|
loadingState.progress = 1;
|
|
808
|
-
loadingState.model =
|
|
809
|
-
current_three.scene?.add(
|
|
740
|
+
loadingState.model = gltf.scene;
|
|
741
|
+
current_three.scene?.add(gltf.scene);
|
|
742
|
+
resolve(loadingState);
|
|
810
743
|
},
|
|
811
744
|
(xhr) => {
|
|
812
745
|
if (xhr.total) {
|
|
@@ -817,15 +750,103 @@ function use_loader(current_three) {
|
|
|
817
750
|
(error) => {
|
|
818
751
|
loadingState.error = error;
|
|
819
752
|
options?.onError?.(error);
|
|
753
|
+
resolve(loadingState);
|
|
820
754
|
}
|
|
821
755
|
);
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function load_obj_model(url, mtlUrl, options) {
|
|
759
|
+
const loadingState = {
|
|
760
|
+
progress: 0,
|
|
761
|
+
loaded: false,
|
|
762
|
+
error: null,
|
|
763
|
+
model: null
|
|
764
|
+
};
|
|
765
|
+
return new Promise((resolve, reject) => {
|
|
766
|
+
if (mtlUrl) {
|
|
767
|
+
const mtlLoader = new MTLLoader();
|
|
768
|
+
mtlLoader.load(
|
|
769
|
+
mtlUrl,
|
|
770
|
+
(materials) => {
|
|
771
|
+
materials.preload();
|
|
772
|
+
const objLoader = new OBJLoader();
|
|
773
|
+
objLoader.setMaterials(materials);
|
|
774
|
+
objLoader.load(
|
|
775
|
+
url,
|
|
776
|
+
(object) => {
|
|
777
|
+
loadingState.loaded = true;
|
|
778
|
+
loadingState.progress = 1;
|
|
779
|
+
loadingState.model = object;
|
|
780
|
+
current_three.scene?.add(object);
|
|
781
|
+
resolve(loadingState);
|
|
782
|
+
},
|
|
783
|
+
(xhr) => {
|
|
784
|
+
if (xhr.total) {
|
|
785
|
+
loadingState.progress = xhr.loaded / xhr.total;
|
|
786
|
+
options?.onProgress?.(loadingState.progress);
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
(error) => {
|
|
790
|
+
loadingState.error = error;
|
|
791
|
+
options?.onError?.(error);
|
|
792
|
+
resolve(loadingState);
|
|
793
|
+
}
|
|
794
|
+
);
|
|
795
|
+
},
|
|
796
|
+
(xhr) => {
|
|
797
|
+
if (xhr.total) {
|
|
798
|
+
loadingState.progress = xhr.loaded / xhr.total * 0.5;
|
|
799
|
+
options?.onProgress?.(loadingState.progress);
|
|
800
|
+
}
|
|
801
|
+
},
|
|
802
|
+
(error) => {
|
|
803
|
+
loadingState.error = error;
|
|
804
|
+
options?.onError?.(error);
|
|
805
|
+
reject(error);
|
|
806
|
+
}
|
|
807
|
+
);
|
|
808
|
+
} else {
|
|
809
|
+
const objLoader = new OBJLoader();
|
|
810
|
+
objLoader.load(
|
|
811
|
+
url,
|
|
812
|
+
(object) => {
|
|
813
|
+
loadingState.loaded = true;
|
|
814
|
+
loadingState.progress = 1;
|
|
815
|
+
loadingState.model = object;
|
|
816
|
+
current_three.scene?.add(object);
|
|
817
|
+
resolve(loadingState);
|
|
818
|
+
},
|
|
819
|
+
(xhr) => {
|
|
820
|
+
if (xhr.total) {
|
|
821
|
+
loadingState.progress = xhr.loaded / xhr.total;
|
|
822
|
+
options?.onProgress?.(loadingState.progress);
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
(error) => {
|
|
826
|
+
loadingState.error = error;
|
|
827
|
+
options?.onError?.(error);
|
|
828
|
+
resolve(loadingState);
|
|
829
|
+
}
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
function load_models(models) {
|
|
835
|
+
const promises = [];
|
|
836
|
+
for (const model of models) {
|
|
837
|
+
if (model.type === "gltf") {
|
|
838
|
+
promises.push(load_gltf_model(model.url, model.options));
|
|
839
|
+
} else if (model.type === "obj") {
|
|
840
|
+
promises.push(load_obj_model(model.url, model.mtlUrl, model.options));
|
|
841
|
+
}
|
|
822
842
|
}
|
|
823
|
-
return
|
|
843
|
+
return Promise.all(promises);
|
|
824
844
|
}
|
|
825
845
|
return {
|
|
826
846
|
use_draco_loader,
|
|
827
847
|
load_gltf_model,
|
|
828
|
-
load_obj_model
|
|
848
|
+
load_obj_model,
|
|
849
|
+
load_models
|
|
829
850
|
};
|
|
830
851
|
}
|
|
831
852
|
function use_resources(current_three) {
|
|
@@ -1037,10 +1058,10 @@ function use_effect_composer(current_three) {
|
|
|
1037
1058
|
}
|
|
1038
1059
|
});
|
|
1039
1060
|
if (options.visible_edge_color) {
|
|
1040
|
-
outline_pass.visibleEdgeColor
|
|
1061
|
+
outline_pass.visibleEdgeColor = options.visible_edge_color;
|
|
1041
1062
|
}
|
|
1042
1063
|
if (options.hidden_edge_color) {
|
|
1043
|
-
outline_pass.hiddenEdgeColor
|
|
1064
|
+
outline_pass.hiddenEdgeColor = options.hidden_edge_color;
|
|
1044
1065
|
}
|
|
1045
1066
|
outline_pass.selectedObjects = objects;
|
|
1046
1067
|
}
|
|
@@ -1128,7 +1149,7 @@ function use_three(options) {
|
|
|
1128
1149
|
const { add_default_lighting, add_ambient_light, add_directional_light, add_point_light, add_spot_light, enable_shadow } = use_lighting(current_three);
|
|
1129
1150
|
const { init_renderer, init_css2_renderer, set_rendering_status, set_target_fps, render, resize, set_container } = use_renderer(current_three);
|
|
1130
1151
|
const { get_select_object, enable_object_drag, disable_object_drag, enable_touch_support } = use_interaction(current_three);
|
|
1131
|
-
const { load_gltf_model, load_obj_model, use_draco_loader } = use_loader(current_three);
|
|
1152
|
+
const { load_gltf_model, load_obj_model, load_models, use_draco_loader } = use_loader(current_three);
|
|
1132
1153
|
const { clear_resources } = use_resources(current_three);
|
|
1133
1154
|
const { enable_effect, enable_fxaa, enable_unreal_bloom, enable_outline, set_out_line } = use_effect_composer(current_three);
|
|
1134
1155
|
function create_box_helper(color = "#00ffff") {
|
|
@@ -1203,6 +1224,7 @@ function use_three(options) {
|
|
|
1203
1224
|
set_target_fps,
|
|
1204
1225
|
load_gltf_model,
|
|
1205
1226
|
load_obj_model,
|
|
1227
|
+
load_models,
|
|
1206
1228
|
enable_object_drag,
|
|
1207
1229
|
disable_object_drag,
|
|
1208
1230
|
enable_touch_support,
|
|
@@ -70,23 +70,23 @@ export interface UseThree {
|
|
|
70
70
|
* 加载GLTF模型
|
|
71
71
|
* @param url 模型URL
|
|
72
72
|
* @param options 加载选项
|
|
73
|
-
* @returns
|
|
73
|
+
* @returns Promise<any> 加载完成的Promise,解析为加载状态对象
|
|
74
74
|
*/
|
|
75
75
|
load_gltf_model: (url: string, options?: {
|
|
76
76
|
onProgress?: (progress: number) => void;
|
|
77
77
|
onError?: (error: any) => void;
|
|
78
|
-
}) => any
|
|
78
|
+
}) => Promise<any>;
|
|
79
79
|
/**
|
|
80
80
|
* 加载OBJ模型
|
|
81
81
|
* @param url 模型URL
|
|
82
82
|
* @param mtlUrl 材质URL
|
|
83
83
|
* @param options 加载选项
|
|
84
|
-
* @returns
|
|
84
|
+
* @returns Promise<any> 加载完成的Promise,解析为加载状态对象
|
|
85
85
|
*/
|
|
86
86
|
load_obj_model: (url: string, mtlUrl?: string, options?: {
|
|
87
87
|
onProgress?: (progress: number) => void;
|
|
88
88
|
onError?: (error: any) => void;
|
|
89
|
-
}) => any
|
|
89
|
+
}) => Promise<any>;
|
|
90
90
|
/**
|
|
91
91
|
* 启用对象拖拽
|
|
92
92
|
* @param object 要拖拽的对象
|
|
@@ -201,4 +201,18 @@ export interface UseThree {
|
|
|
201
201
|
* @param out_line_options 配置
|
|
202
202
|
*/
|
|
203
203
|
set_out_line: (outline_pass: OutlinePass, objects: Object3D[], out_line_options?: OutLineOptions) => void;
|
|
204
|
+
/**
|
|
205
|
+
* 批量加载模型
|
|
206
|
+
* @param models 模型加载配置数组
|
|
207
|
+
* @returns Promise<any[]> 全部加载完成的Promise,解析为加载状态对象数组
|
|
208
|
+
*/
|
|
209
|
+
load_models: (models: Array<{
|
|
210
|
+
type: 'gltf' | 'obj';
|
|
211
|
+
url: string;
|
|
212
|
+
mtlUrl?: string;
|
|
213
|
+
options?: {
|
|
214
|
+
onProgress?: (progress: number) => void;
|
|
215
|
+
onError?: (error: any) => void;
|
|
216
|
+
};
|
|
217
|
+
}>) => Promise<any[]>;
|
|
204
218
|
}
|
|
@@ -10,19 +10,18 @@ export declare function use_loader(current_three: ThreeTarget): {
|
|
|
10
10
|
load_gltf_model: (url: string, options?: {
|
|
11
11
|
onProgress?: (progress: number) => void;
|
|
12
12
|
onError?: (error: any) => void;
|
|
13
|
-
}) =>
|
|
14
|
-
progress: number;
|
|
15
|
-
loaded: boolean;
|
|
16
|
-
error: null;
|
|
17
|
-
model: any;
|
|
18
|
-
};
|
|
13
|
+
}) => Promise<any>;
|
|
19
14
|
load_obj_model: (url: string, mtlUrl?: string, options?: {
|
|
20
15
|
onProgress?: (progress: number) => void;
|
|
21
16
|
onError?: (error: any) => void;
|
|
22
|
-
}) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
}) => Promise<any>;
|
|
18
|
+
load_models: (models: Array<{
|
|
19
|
+
type: "gltf" | "obj";
|
|
20
|
+
url: string;
|
|
21
|
+
mtlUrl?: string;
|
|
22
|
+
options?: {
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
onError?: (error: any) => void;
|
|
25
|
+
};
|
|
26
|
+
}>) => Promise<any[]>;
|
|
28
27
|
};
|