@qy_better_lib/hooks 0.2.8 → 0.2.10

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.
@@ -0,0 +1,155 @@
1
+ import { ThreeTarget } from '../shared/type';
2
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
3
+ import { BoxHelper, Object3D } from 'three';
4
+ import { ObjectToolTip, ToolTipOptions } from './toolTip';
5
+ export interface UseThree {
6
+ /**three 实例*/
7
+ instance: ThreeTarget;
8
+ /**
9
+ * 初始化
10
+ */
11
+ init_three: () => void;
12
+ /**
13
+ * 设置渲染容器
14
+ * @param container 渲染容器元素
15
+ */
16
+ set_container: (container: HTMLElement) => void;
17
+ /**
18
+ * 创建透视相机
19
+ */
20
+ create_perspective_camera: () => void;
21
+ /**
22
+ * 创建正交相机
23
+ * @param options 正交相机配置
24
+ */
25
+ create_orthographic_camera: (options?: any) => void;
26
+ /**
27
+ * 设置相机预设
28
+ * @param preset 预设名称
29
+ */
30
+ set_camera_preset: (preset: 'front' | 'back' | 'top' | 'bottom' | 'left' | 'right') => void;
31
+ /**
32
+ * 添加默认光照
33
+ */
34
+ add_default_lighting: () => void;
35
+ /**
36
+ * 添加环境光
37
+ * @param options 光源配置
38
+ */
39
+ add_ambient_light: (options?: any) => void;
40
+ /**
41
+ * 添加平行光
42
+ * @param options 光源配置
43
+ */
44
+ add_directional_light: (options?: any) => void;
45
+ /**
46
+ * 添加点光源
47
+ * @param options 光源配置
48
+ */
49
+ add_point_light: (options?: any) => void;
50
+ /**
51
+ * 添加聚光灯
52
+ * @param options 光源配置
53
+ */
54
+ add_spot_light: (options?: any) => void;
55
+ /**
56
+ * 设置渲染状态
57
+ * @param status 渲染状态
58
+ */
59
+ set_rendering_status: (status: boolean) => void;
60
+ /**
61
+ * 设置目标帧率
62
+ * @param fps 帧率
63
+ */
64
+ set_target_fps: (fps: number) => void;
65
+ /**
66
+ * 加载GLTF模型
67
+ * @param url 模型URL
68
+ * @param options 加载选项
69
+ * @returns 加载状态对象
70
+ */
71
+ load_gltf_model: (url: string, options?: {
72
+ onProgress?: (progress: number) => void;
73
+ onError?: (error: any) => void;
74
+ }) => any;
75
+ /**
76
+ * 加载OBJ模型
77
+ * @param url 模型URL
78
+ * @param mtlUrl 材质URL
79
+ * @param options 加载选项
80
+ * @returns 加载状态对象
81
+ */
82
+ load_obj_model: (url: string, mtlUrl?: string, options?: {
83
+ onProgress?: (progress: number) => void;
84
+ onError?: (error: any) => void;
85
+ }) => any;
86
+ /**
87
+ * 启用对象拖拽
88
+ * @param object 要拖拽的对象
89
+ * @param options 拖拽选项
90
+ */
91
+ enable_object_drag: (object: Object3D, options?: {
92
+ onDragStart?: () => void;
93
+ onDragEnd?: () => void;
94
+ onDrag?: (position: {
95
+ x: number;
96
+ y: number;
97
+ z: number;
98
+ }) => void;
99
+ }) => void;
100
+ /**
101
+ * 禁用对象拖拽
102
+ */
103
+ disable_object_drag: () => void;
104
+ /**
105
+ * 启用触摸设备支持
106
+ */
107
+ enable_touch_support: () => void;
108
+ /**
109
+ * 工具函数集合
110
+ */
111
+ utils: any;
112
+ /**
113
+ * three渲染
114
+ * @param renderer 渲染器
115
+ * @param scene 场景
116
+ * @param camera 相机
117
+ * @param renderAction 渲染行为
118
+ */
119
+ render: (renderAction?: Function) => void;
120
+ /**
121
+ * 获取模型点击的对象
122
+ */
123
+ get_select_object: (e: any) => any;
124
+ /**开启VR */
125
+ enabled_vr: () => void;
126
+ /**禁用VR */
127
+ disabled_vr: () => void;
128
+ /**使用模型解压缩,适用于使用DRAC算法压缩的模型 */
129
+ use_draco_loader: (gltf_loader: GLTFLoader) => void;
130
+ /**释放 */
131
+ dispose_three: () => void;
132
+ /**复位 */
133
+ reset: () => void;
134
+ /**容器大小变更 */
135
+ resize: () => void;
136
+ /**开启阴影 */
137
+ enable_shadow: () => void;
138
+ /**
139
+ * 创建3D对象工具提示
140
+ * @param obj 3D对象
141
+ * @param options 配置选项
142
+ * @returns ObjectToolTip实例
143
+ */
144
+ create_tool_tip: (obj: Object3D, options?: ToolTipOptions) => ObjectToolTip;
145
+ /**
146
+ * 创建ObjectToolTip实例
147
+ * @returns ObjectToolTip实例
148
+ */
149
+ create_tool_tip_instance: () => ObjectToolTip;
150
+ /**
151
+ * 创建边界框辅助
152
+ * @param color 边界框颜色
153
+ */
154
+ create_box_helper: (color?: string) => BoxHelper;
155
+ }
@@ -0,0 +1,15 @@
1
+ import { BoxHelper, Object3D, Scene } from 'three';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 边界框辅助 Hook
5
+ * @param current_three Three.js实例
6
+ * @param color 边界框颜色
7
+ * @returns 边界框相关方法
8
+ */
9
+ export declare function use_box_helper(current_three: ThreeTarget, color?: string): {
10
+ helper: BoxHelper;
11
+ add_to_scene: (scene: Scene) => void;
12
+ set_box_frame: (obj: Object3D) => void;
13
+ set_visible: (visible: boolean) => void;
14
+ destroy: () => void;
15
+ };
@@ -0,0 +1,15 @@
1
+ import { ThreeOption } from '../type';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 相机系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 相机相关方法
7
+ */
8
+ export declare function use_camera(current_three: ThreeTarget): {
9
+ create_perspective_camera: (options: ThreeOption) => void;
10
+ create_orthographic_camera: (options?: any) => void;
11
+ set_camera_preset: (preset: "front" | "back" | "top" | "bottom" | "left" | "right") => void;
12
+ orbit_controls: () => void;
13
+ axes_helper: (size?: number) => void;
14
+ reset_camera: (options: ThreeOption) => void;
15
+ };
@@ -0,0 +1,45 @@
1
+ import { ThreeTarget } from '../../shared/type';
2
+ import { Object3D } from 'three';
3
+ import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
4
+ import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass.js';
5
+ import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
6
+ import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
7
+ import { FilmPass } from 'three/examples/jsm/postprocessing/FilmPass.js';
8
+ import { OutLineOptions } from '../type';
9
+ /**
10
+ * SSAO 配置选项
11
+ */
12
+ interface SSAOOptions {
13
+ /** 内核半径 */
14
+ kernel_radius?: number;
15
+ /** 最小距离 */
16
+ min_distance?: number;
17
+ /** 最大距离 */
18
+ max_distance?: number;
19
+ }
20
+ /**
21
+ * 电影效果配置选项
22
+ */
23
+ interface FilmOptions {
24
+ /** 颗粒强度 */
25
+ noise_intensity?: number;
26
+ /** 灰度模式 */
27
+ grayscale?: boolean;
28
+ }
29
+ /**
30
+ * 后期处理 Hook
31
+ * @param current_three Three.js实例
32
+ * @returns 后期处理相关方法
33
+ */
34
+ export declare function use_effect_composer(current_three: ThreeTarget): {
35
+ enable_effect: (use_ssao?: boolean, ssao_options?: SSAOOptions) => EffectComposer;
36
+ enable_fxaa: (composer: EffectComposer) => void;
37
+ enable_unreal_bloom: (composer: EffectComposer, strength?: number, radius?: number, threshold?: number) => UnrealBloomPass | null;
38
+ enable_outline: (composer: EffectComposer) => OutlinePass | null;
39
+ set_out_line: (outline_pass: OutlinePass, objects: Object3D[], out_line_options?: OutLineOptions) => void;
40
+ enable_film_effect: (composer: EffectComposer, options?: FilmOptions) => FilmPass | null;
41
+ enable_grayscale: (composer: EffectComposer) => ShaderPass | null;
42
+ update_all_composers_size: () => void;
43
+ clear_composers: () => void;
44
+ };
45
+ export {};
@@ -0,0 +1,21 @@
1
+ import { Object3D, Object3DEventMap } from 'three';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 交互系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 交互相关方法
7
+ */
8
+ export declare function use_interaction(current_three: ThreeTarget): {
9
+ get_select_object: (e: any) => Object3D< Object3DEventMap> | null;
10
+ enable_object_drag: (object: Object3D, options?: {
11
+ onDragStart?: () => void;
12
+ onDragEnd?: () => void;
13
+ onDrag?: (position: {
14
+ x: number;
15
+ y: number;
16
+ z: number;
17
+ }) => void;
18
+ }) => void;
19
+ disable_object_drag: () => void;
20
+ enable_touch_support: () => void;
21
+ };
@@ -0,0 +1,15 @@
1
+ import { AmbientLight, DirectionalLight, PointLight, SpotLight } from 'three';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 光照系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 光照相关方法
7
+ */
8
+ export declare function use_lighting(current_three: ThreeTarget): {
9
+ add_default_lighting: () => void;
10
+ add_ambient_light: (options?: any) => AmbientLight;
11
+ add_directional_light: (options?: any) => DirectionalLight;
12
+ add_point_light: (options?: any) => PointLight;
13
+ add_spot_light: (options?: any) => SpotLight;
14
+ enable_shadow: () => void;
15
+ };
@@ -0,0 +1,28 @@
1
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 模型加载系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 模型加载相关方法
7
+ */
8
+ export declare function use_loader(current_three: ThreeTarget): {
9
+ use_draco_loader: (gltfLoader: GLTFLoader) => void;
10
+ load_gltf_model: (url: string, options?: {
11
+ onProgress?: (progress: number) => void;
12
+ onError?: (error: any) => void;
13
+ }) => {
14
+ progress: number;
15
+ loaded: boolean;
16
+ error: null;
17
+ model: any;
18
+ };
19
+ load_obj_model: (url: string, mtlUrl?: string, options?: {
20
+ onProgress?: (progress: number) => void;
21
+ onError?: (error: any) => void;
22
+ }) => {
23
+ progress: number;
24
+ loaded: boolean;
25
+ error: null;
26
+ model: any;
27
+ };
28
+ };
@@ -0,0 +1,18 @@
1
+ import { ThreeTarget } from '../../shared/type';
2
+ import { ThreeOption } from '../type';
3
+ /**
4
+ * 渲染系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 渲染相关方法
7
+ */
8
+ export declare function use_renderer(current_three: ThreeTarget): {
9
+ init_renderer: (options: ThreeOption) => void;
10
+ init_css2_renderer: () => void;
11
+ set_rendering_status: (status: boolean) => void;
12
+ set_target_fps: (fps: number) => void;
13
+ render: (render_action?: Function) => void;
14
+ resize: () => void;
15
+ set_container: (container: HTMLElement) => void;
16
+ cancel_animation: () => void;
17
+ get_rendering_status: () => boolean;
18
+ };
@@ -0,0 +1,12 @@
1
+ import { Object3D } from 'three';
2
+ import { ThreeTarget } from '../../shared/type';
3
+ /**
4
+ * 资源管理系统 Hook
5
+ * @param current_three Three.js实例
6
+ * @returns 资源管理相关方法
7
+ */
8
+ export declare function use_resources(current_three: ThreeTarget): {
9
+ clear_resources: () => void;
10
+ clear_renderer: () => void;
11
+ remove_object: (object: Object3D) => void;
12
+ };
@@ -0,0 +1,133 @@
1
+ import { Object3D, Vector3, Box3 } from 'three';
2
+ /**
3
+ * 安全执行函数
4
+ * @param fn 要执行的函数
5
+ * @param default_value 默认返回值
6
+ * @returns 函数执行结果或默认值
7
+ */
8
+ export declare function safe_execute<T>(fn: () => T, default_value?: T): T | undefined;
9
+ /**
10
+ * 工具函数集合
11
+ */
12
+ export declare const three_utils: {
13
+ /**
14
+ * 计算对象边界盒
15
+ * @param object 3D对象
16
+ * @returns 边界盒对象
17
+ */
18
+ compute_bounding_box: (object: Object3D) => Box3 | null | undefined;
19
+ /**
20
+ * 计算对象中心点
21
+ * @param object 3D对象
22
+ * @returns 中心点坐标
23
+ */
24
+ compute_center: (object: Object3D) => Vector3 | undefined;
25
+ /**
26
+ * 生成网格辅助线
27
+ * @param size 网格大小
28
+ * @param divisions 网格细分
29
+ * @returns 网格辅助线对象
30
+ */
31
+ create_grid_helper: (size?: number, divisions?: number) => any;
32
+ /**
33
+ * 创建坐标轴辅助器
34
+ * @param size 坐标轴大小
35
+ * @returns 坐标轴辅助器对象
36
+ */
37
+ create_axes_helper: (size?: number) => any;
38
+ /**
39
+ * 创建立方体
40
+ * @param size 立方体大小
41
+ * @param material 材质
42
+ * @returns 立方体对象
43
+ */
44
+ create_box: (size?: number, material?: any) => any;
45
+ /**
46
+ * 创建球体
47
+ * @param radius 球体半径
48
+ * @param material 材质
49
+ * @returns 球体对象
50
+ */
51
+ create_sphere: (radius?: number, material?: any) => any;
52
+ /**
53
+ * 创建圆柱体
54
+ * @param radius_top 顶部半径
55
+ * @param radius_bottom 底部半径
56
+ * @param height 高度
57
+ * @param material 材质
58
+ * @returns 圆柱体对象
59
+ */
60
+ create_cylinder: (radius_top?: number, radius_bottom?: number, height?: number, material?: any) => any;
61
+ /**
62
+ * 屏幕坐标转世界坐标
63
+ * @param x 屏幕X坐标
64
+ * @param y 屏幕Y坐标
65
+ * @param camera 相机
66
+ * @returns 世界坐标
67
+ */
68
+ screen_to_world: (x: number, y: number, camera: any) => any;
69
+ /**
70
+ * 世界坐标转屏幕坐标
71
+ * @param position 世界坐标
72
+ * @param camera 相机
73
+ * @returns 屏幕坐标
74
+ */
75
+ world_to_screen: (position: Vector3, camera: any) => {
76
+ x: number;
77
+ y: number;
78
+ } | undefined;
79
+ /**
80
+ * 平滑动画函数
81
+ * @param start 起始值
82
+ * @param end 结束值
83
+ * @param duration 动画时长
84
+ * @param callback 每帧回调
85
+ * @param ease 缓动函数
86
+ */
87
+ animate: (start: number, end: number, duration: number, callback: (value: number) => void, ease?: (t: number) => number) => void;
88
+ /**
89
+ * 缓动函数集合
90
+ */
91
+ easing: {
92
+ linear: (t: number) => number;
93
+ ease_in_quad: (t: number) => number;
94
+ ease_out_quad: (t: number) => number;
95
+ ease_in_out_quad: (t: number) => number;
96
+ ease_in_cubic: (t: number) => number;
97
+ ease_out_cubic: (t: number) => number;
98
+ ease_in_out_cubic: (t: number) => number;
99
+ };
100
+ };
101
+ /**相机预设位置 */
102
+ export declare const camera_presets: {
103
+ front: {
104
+ x: number;
105
+ y: number;
106
+ z: number;
107
+ };
108
+ back: {
109
+ x: number;
110
+ y: number;
111
+ z: number;
112
+ };
113
+ top: {
114
+ x: number;
115
+ y: number;
116
+ z: number;
117
+ };
118
+ bottom: {
119
+ x: number;
120
+ y: number;
121
+ z: number;
122
+ };
123
+ left: {
124
+ x: number;
125
+ y: number;
126
+ z: number;
127
+ };
128
+ right: {
129
+ x: number;
130
+ y: number;
131
+ z: number;
132
+ };
133
+ };
@@ -0,0 +1,101 @@
1
+ import { Object3D, Vector3 } from 'three';
2
+ /**
3
+ * 3D对象工具提示配置选项
4
+ */
5
+ export interface ToolTipOptions {
6
+ /**
7
+ * 关闭回调函数
8
+ */
9
+ onClose?: () => void;
10
+ /**
11
+ * 提示框内容
12
+ */
13
+ content?: string;
14
+ /**
15
+ * 提示框样式类名
16
+ */
17
+ className?: string;
18
+ /**
19
+ * 提示框位置偏移
20
+ */
21
+ offset?: Vector3;
22
+ }
23
+ /**
24
+ * 3D对象工具提示类
25
+ * 用于在3D场景中为对象添加交互式工具提示
26
+ */
27
+ export declare class ObjectToolTip {
28
+ /**
29
+ * 关联的3D对象
30
+ */
31
+ obj: Object3D | undefined;
32
+ /**
33
+ * 工具提示元素
34
+ */
35
+ container: HTMLElement | null;
36
+ /**
37
+ * CSS2D对象,用于在3D场景中渲染HTML元素
38
+ */
39
+ private css2Object;
40
+ /**
41
+ * 事件回调
42
+ */
43
+ private events;
44
+ /**
45
+ * 是否显示
46
+ */
47
+ private isVisible;
48
+ /**
49
+ * 提示框内容
50
+ */
51
+ private content;
52
+ /**
53
+ * 创建3D对象工具提示
54
+ * @param obj 3D对象
55
+ * @param options 配置选项
56
+ */
57
+ create(obj: Object3D, options?: ToolTipOptions): void;
58
+ /**
59
+ * 更新提示框内容
60
+ * @param content 新的内容
61
+ */
62
+ updateContent(content: string): void;
63
+ /**
64
+ * 更新提示框位置
65
+ * @param position 新的位置
66
+ */
67
+ updatePosition(position: Vector3): void;
68
+ /**
69
+ * 显示提示框
70
+ */
71
+ show(): void;
72
+ /**
73
+ * 隐藏提示框
74
+ */
75
+ hide(): void;
76
+ /**
77
+ * 移除提示框
78
+ */
79
+ remove(): void;
80
+ /**
81
+ * 清理资源
82
+ */
83
+ private clear;
84
+ /**
85
+ * 检查提示框是否可见
86
+ * @returns 是否可见
87
+ */
88
+ isShowing(): boolean;
89
+ /**
90
+ * 获取提示框内容
91
+ * @returns 提示框内容
92
+ */
93
+ getContent(): string;
94
+ }
95
+ /**
96
+ * 创建3D对象工具提示的工厂函数
97
+ * @param obj 3D对象
98
+ * @param options 配置选项
99
+ * @returns ObjectToolTip实例
100
+ */
101
+ export declare function createObjectToolTip(obj: Object3D, options?: ToolTipOptions): ObjectToolTip;
@@ -0,0 +1,82 @@
1
+ import { Point3D } from '../shared/type';
2
+ import { Texture } from 'three';
3
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
4
+ export type ThreeOption = {
5
+ /**背景色 */
6
+ scenebgcolor?: string;
7
+ /**环境贴图 */
8
+ scenebg?: Texture;
9
+ /**相机配置 */
10
+ camera_option?: CameraOption;
11
+ /**相机类型,默认为透视相机 */
12
+ camera_type?: 'perspective' | 'orthographic';
13
+ /**是否包含控制器 */
14
+ controls?: boolean;
15
+ /**坐标辅助器 */
16
+ axes_helper?: boolean;
17
+ /**2d html渲染-展示html元素 */
18
+ css2_render?: boolean;
19
+ /**开启GPU加速 */
20
+ gpu?: boolean;
21
+ /**默认光照设置 */
22
+ default_lighting?: boolean;
23
+ };
24
+ /**光源配置 */
25
+ export type LightOption = {
26
+ /**光源颜色 */
27
+ color?: string | number;
28
+ /**光源强度 */
29
+ intensity?: number;
30
+ /**光源位置 */
31
+ position?: Point3D;
32
+ };
33
+ /**正交相机配置 */
34
+ export type OrthographicCameraOption = {
35
+ /**相机位置 */
36
+ position: Point3D;
37
+ /**左边界 */
38
+ left: number;
39
+ /**右边界 */
40
+ right: number;
41
+ /**上边界 */
42
+ top: number;
43
+ /**下边界 */
44
+ bottom: number;
45
+ /**近截面 */
46
+ near: number;
47
+ /**远截面 */
48
+ far: number;
49
+ };
50
+ /**相机配置 */
51
+ export type CameraOption = {
52
+ /**相机位置 */
53
+ position: Point3D;
54
+ /**摄像机视锥体垂直视野角度,从视图的底部到顶部,以角度来表示。默认值是50 */
55
+ fov: number;
56
+ /**摄像机视锥体长宽比 */
57
+ aspect?: number;
58
+ /**近距离面 */
59
+ near: number;
60
+ /**远局里面 */
61
+ far: number;
62
+ };
63
+ /**模型加载器 */
64
+ export type ModelLoader = {
65
+ gltf_loader: GLTFLoader;
66
+ };
67
+ export type OutLineOptions = {
68
+ /**律动值,数值越大,律动越慢 */
69
+ pulse_period?: number;
70
+ /**高光颜色 */
71
+ visible_edge_color?: string | number;
72
+ /**阴影颜色 */
73
+ hidden_edge_color?: string | number;
74
+ /**是否使用纹理覆盖 */
75
+ use_pattern_texture?: boolean;
76
+ /**高光边缘强度 */
77
+ edge_strength?: number;
78
+ /**边缘微光强度 */
79
+ edge_glow?: number;
80
+ /**高光厚度 */
81
+ edge_thickness?: number;
82
+ };
@@ -0,0 +1,11 @@
1
+ import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
2
+ import { ModelLoader } from './type';
3
+ /**
4
+ * 加载GLTF模型
5
+ * @param url 模型路径
6
+ * @param loaders 加载器
7
+ * @param cache 是否缓存
8
+ * @param store indexedDB仓库
9
+ * @returns
10
+ */
11
+ export declare function GLTFloadAsync(path: string, loaders: ModelLoader, cache: boolean, store?: any): Promise<GLTF>;