@qy_better_lib/hooks 0.2.10 → 0.2.11

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/DOCUMENTATION.md CHANGED
@@ -256,7 +256,7 @@ close();
256
256
 
257
257
  ### 5. use-mqtt - MQTT功能
258
258
 
259
- > 注意:MQTT功能现在是可选依赖,需要单独导入
259
+ > 注意:MQTT功能是可选依赖,需要单独导入
260
260
 
261
261
  #### 功能描述
262
262
  适用于需要MQTT通信的场景,支持连接管理、消息订阅和发布。
@@ -391,7 +391,7 @@ close(() => {
391
391
 
392
392
  ### 7. use-chart - 图表管理
393
393
 
394
- > 注意:图表管理功能现在是可选依赖,需要单独导入
394
+ > 注意:图表管理功能是可选依赖,需要单独导入
395
395
 
396
396
  #### 功能描述
397
397
  适用于需要在前端使用ECharts的场景,支持图表渲染、主题切换、响应式设计等功能。
@@ -487,7 +487,7 @@ close(() => {
487
487
 
488
488
  ### 8. use-layout-flow - 流程图布局
489
489
 
490
- > 注意:流程图布局功能现在是可选依赖,需要单独导入
490
+ > 注意:流程图布局功能是可选依赖,需要单独导入
491
491
 
492
492
  #### 功能描述
493
493
  适用于需要自动布局的流程图场景,支持多种布局方向和自定义元素。
@@ -623,12 +623,108 @@ emitter.on('test', (data) => {
623
623
  emitter.off('test', listener);
624
624
  ```
625
625
 
626
+ ### 10. use-three - Three.js 3D渲染
626
627
 
628
+ > 注意:Three.js 3D渲染功能是可选依赖,需要单独导入
629
+
630
+ #### 功能描述
631
+ 适用于需要在前端实现3D渲染的场景,基于Three.js库,支持场景管理、相机控制、光照系统、模型加载、交互系统等功能。
632
+
633
+ #### 安装依赖
634
+ ```bash
635
+ npm install three
636
+ ```
637
+
638
+ #### 参数
639
+ - `options: ThreeOption` - Three.js配置选项
640
+
641
+ #### 返回值
642
+ - **instance**: `ThreeTarget` - Three.js实例对象
643
+ - **init_three**: `() => void` - 初始化Three.js场景
644
+ - **set_container**: `(container: HTMLElement | string) => void` - 设置渲染容器
645
+ - **create_perspective_camera**: `() => PerspectiveCamera` - 创建透视相机
646
+ - **create_orthographic_camera**: `() => OrthographicCamera` - 创建正交相机
647
+ - **set_camera_preset**: `(preset: string) => void` - 设置相机预设
648
+ - **add_default_lighting**: `() => void` - 添加默认光照
649
+ - **add_ambient_light**: `(options?: AmbientLightOptions) => AmbientLight` - 添加环境光
650
+ - **add_directional_light**: `(options?: DirectionalLightOptions) => DirectionalLight` - 添加平行光
651
+ - **add_point_light**: `(options?: PointLightOptions) => PointLight` - 添加点光源
652
+ - **add_spot_light**: `(options?: SpotLightOptions) => SpotLight` - 添加聚光灯
653
+ - **set_rendering_status**: `(status: boolean) => void` - 设置渲染状态
654
+ - **set_target_fps**: `(fps: number) => void` - 设置目标帧率
655
+ - **load_gltf_model**: `(url: string, options?: LoadModelOptions) => Promise<{ model: Object3D; animations: AnimationClip[]; }>` - 加载GLTF模型
656
+ - **load_obj_model**: `(url: string, options?: LoadModelOptions) => Promise<Object3D>` - 加载OBJ模型
657
+ - **enable_object_drag**: `(obj: Object3D, options?: DragOptions) => void` - 启用对象拖拽
658
+ - **disable_object_drag**: `(obj: Object3D) => void` - 禁用对象拖拽
659
+ - **enable_touch_support**: `() => void` - 启用触摸支持
660
+ - **utils**: `ThreeUtils` - Three.js工具函数
661
+ - **dispose_three**: `() => void` - 释放Three.js资源
662
+ - **render**: `() => void` - 手动渲染
663
+ - **get_select_object**: `(x: number, y: number) => Object3D | null` - 获取选中的对象
664
+ - **enabled_vr**: `() => void` - 启用VR模式
665
+ - **disabled_vr**: `() => void` - 禁用VR模式
666
+ - **use_draco_loader**: `(path?: string) => void` - 使用DRACO压缩加载器
667
+ - **reset**: `() => void` - 重置相机位置和控制器状态
668
+ - **resize**: `() => void` - 调整渲染大小
669
+ - **enable_shadow**: `() => void` - 启用阴影
670
+ - **create_tool_tip**: `(obj: Object3D, options?: ToolTipOptions) => ObjectToolTip` - 创建3D对象工具提示
671
+ - **create_tool_tip_instance**: `() => ObjectToolTip` - 创建ObjectToolTip实例
672
+ - **create_box_helper**: `(color?: string) => BoxHelper` - 创建边界框辅助
673
+ - **enable_effect**: `() => EffectComposer` - 启用后期处理
674
+ - **enable_fxaa**: `() => ShaderPass` - 启用FXAA抗锯齿
675
+ - **enable_unreal_bloom**: `(options?: BloomOptions) => UnrealBloomPass` - 启用UnrealBloom效果
676
+ - **enable_outline**: `(options?: OutlineOptions) => OutlinePass` - 启用轮廓效果
677
+ - **set_out_line**: `(obj: Object3D, visible: boolean) => void` - 设置对象轮廓
678
+
679
+ #### 示例
680
+ ```typescript
681
+ import { use_three } from '@qy_better_lib/hooks/use-three';
682
+
683
+ // 初始化use-three
684
+ const three = use_three({
685
+ scenebgcolor: '#f0f0f0',
686
+ camera_option: {
687
+ position: { x: 10, y: 10, z: 10 },
688
+ fov: 60
689
+ },
690
+ controls: true,
691
+ axes_helper: true,
692
+ default_lighting: true
693
+ });
694
+
695
+ // 设置容器
696
+ three.set_container('#three-container');
697
+
698
+ // 初始化场景
699
+ three.init_three();
700
+
701
+ // 添加模型
702
+ await three.load_gltf_model('/models/model.glb', {
703
+ on_progress: (progress) => {
704
+ console.log('加载进度:', progress);
705
+ }
706
+ });
707
+
708
+ // 启用对象拖拽
709
+ three.enable_object_drag(model);
710
+
711
+ // 启用后期处理效果
712
+ three.enable_effect();
713
+ three.enable_unreal_bloom({
714
+ strength: 0.5,
715
+ radius: 1,
716
+ threshold: 0.1
717
+ });
718
+
719
+ // 释放资源
720
+ // three.dispose_three();
721
+ ```
627
722
 
628
723
  ## 注意事项
629
724
 
630
- 1. **use-chart** 现在是可选依赖,需要单独导入:`import { use_chart } from '@qy_better_lib/hooks/use-chart'`,并需要安装 ECharts 依赖:`npm install echarts`
631
- 2. **use-layout-flow** 现在是可选依赖,需要单独导入:`import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow'`,并需要安装 @antv/x6 和 dagre 依赖:`npm install @antv/x6 dagre`
632
- 3. **use-mqtt** 现在是可选依赖,需要单独导入:`import { use_mqtt } from '@qy_better_lib/hooks/use-mqtt'`,并需要安装 mqtt 依赖:`npm install mqtt`
633
- 4. **use-websocket** 需要确保服务器端支持 WebSocket 协议
634
- 5. **use-print** 在某些浏览器中可能存在兼容性问题,建议在现代浏览器中使用
725
+ 1. **use-chart** 是可选依赖,需要单独导入:`import { use_chart } from '@qy_better_lib/hooks/use-chart'`,并需要安装 ECharts 依赖:`npm install echarts`
726
+ 2. **use-layout-flow** 是可选依赖,需要单独导入:`import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow'`,并需要安装 @antv/x6 和 dagre 依赖:`npm install @antv/x6 dagre`
727
+ 3. **use-mqtt** 是可选依赖,需要单独导入:`import { use_mqtt } from '@qy_better_lib/hooks/use-mqtt'`,并需要安装 mqtt 依赖:`npm install mqtt`
728
+ 4. **use-three** 是可选依赖,需要单独导入:`import { use_three } from '@qy_better_lib/hooks/use-three'`,并需要安装 Three.js 依赖:`npm install three`
729
+ 5. **use-websocket** 需要确保服务器端支持 WebSocket 协议
730
+ 6. **use-print** 在某些浏览器中可能存在兼容性问题,建议在现代浏览器中使用
@@ -1,7 +1,11 @@
1
1
  import { ThreeTarget } from '../shared/type';
2
2
  import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
3
+ import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
4
+ import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass.js';
5
+ import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
3
6
  import { BoxHelper, Object3D } from 'three';
4
7
  import { ObjectToolTip, ToolTipOptions } from './toolTip';
8
+ import { OutLineOptions } from './type';
5
9
  export interface UseThree {
6
10
  /**three 实例*/
7
11
  instance: ThreeTarget;
@@ -148,8 +152,53 @@ export interface UseThree {
148
152
  */
149
153
  create_tool_tip_instance: () => ObjectToolTip;
150
154
  /**
151
- * 创建边界框辅助
152
- * @param color 边界框颜色
153
- */
154
- create_box_helper: (color?: string) => BoxHelper;
155
+ * 创建边界框辅助
156
+ * @param color 边界框颜色
157
+ * @returns 边界框辅助对象
158
+ */
159
+ create_box_helper: (color?: string) => {
160
+ helper: BoxHelper;
161
+ add_to_scene: (scene: any) => void;
162
+ set_box_frame: (obj: Object3D) => void;
163
+ set_visible: (visible: boolean) => void;
164
+ destroy: () => void;
165
+ };
166
+ /**
167
+ * 开启后期处理
168
+ * @param use_ssao 是否使用SSAO效果
169
+ * @param ssao_options SSAO配置选项
170
+ * @returns EffectComposer实例
171
+ */
172
+ enable_effect: (use_ssao?: boolean, ssao_options?: {
173
+ kernel_radius?: number;
174
+ min_distance?: number;
175
+ max_distance?: number;
176
+ }) => EffectComposer | null;
177
+ /**
178
+ * 开启FXAA抗锯齿
179
+ * @param composer 后期处理composer
180
+ */
181
+ enable_fxaa: (composer: EffectComposer) => void;
182
+ /**
183
+ * 开启辉光光晕效果
184
+ * @param composer 后期处理composer
185
+ * @param strength 强度
186
+ * @param radius 半径
187
+ * @param threshold 阈值
188
+ * @returns UnrealBloomPass实例
189
+ */
190
+ enable_unreal_bloom: (composer: EffectComposer, strength?: number, radius?: number, threshold?: number) => UnrealBloomPass | null;
191
+ /**
192
+ * 开启轮廓高亮
193
+ * @param composer 后期处理composer
194
+ * @returns OutlinePass实例
195
+ */
196
+ enable_outline: (composer: EffectComposer) => OutlinePass | null;
197
+ /**
198
+ * 设置模型高光
199
+ * @param outline_pass OutlinePass实例
200
+ * @param objects 需要高光的模型
201
+ * @param out_line_options 配置
202
+ */
203
+ set_out_line: (outline_pass: OutlinePass, objects: Object3D[], out_line_options?: OutLineOptions) => void;
155
204
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qy_better_lib/hooks",
3
3
  "private": false,
4
- "version": "0.2.10",
4
+ "version": "0.2.11",
5
5
  "description": "qy better lib hooks",
6
6
  "author": "luhuiming",
7
7
  "license": "MIT",