three-edit-cores 0.0.2 → 0.0.9

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.
Files changed (3) hide show
  1. package/README.md +144 -0
  2. package/dist/index.js +7888 -11734
  3. package/package.json +43 -43
package/README.md CHANGED
@@ -0,0 +1,144 @@
1
+ - 文档主页 https://z2586300277.github.io/editor-docs/
2
+
3
+ - 案例 https://z2586300277.github.io/three-editor/dist/#/example
4
+
5
+ - author https://z2586300277.github.io/
6
+
7
+ - Copyright (c) threehub.cn email:2586300277@qq.com All rights reserved.
8
+
9
+ ### 基础使用
10
+
11
+ ```js
12
+ import { ThreeEditor } from 'three-edit-cores'
13
+
14
+ ThreeEditor.dracoPath = '/draco/' // draco解码器路径
15
+
16
+ ThreeEditor.__DESIGNS__ // 自定义组件列表
17
+
18
+ ThreeEditor.__EFFECTS__ // 后期处理列表
19
+
20
+ const options = {
21
+
22
+ fps: null,
23
+
24
+ pixelRatio: window.devicePixelRatio * 1,
25
+
26
+ webglRenderParams: { antialias: true, alpha: true, logarithmicDepthBuffer: true },
27
+
28
+ sceneParams: json // 场景参数
29
+
30
+ } // 内部参数皆为可选
31
+
32
+ const threeEditor = new ThreeEditor(DOM, options)
33
+
34
+ // 添加点击事件
35
+ DOM.addEventListener('dblclick', (e) => threeEditor.getSceneEvent(e, (info) => {}))
36
+
37
+ window.addEventListener('resize', () => threeEditor.renderSceneResize()) // 窗口自适应
38
+
39
+ ```
40
+
41
+ ### 编辑器Api
42
+
43
+ ```js
44
+
45
+ const json = threeEditor.saveSceneEdit() // 获取编辑器保存的json 初始化可加载
46
+
47
+ threeEditor.renderSceneResize() // 渲染器自适应窗口大小
48
+
49
+ threeEditor.resetEditorStorage(json) // 重置编辑器 场景1 => 场景2
50
+
51
+ threeEditor.destroySceneRender() // 销毁场景
52
+
53
+ threeEditor.openControlPanel() // 打开内置的 gui 控制面板
54
+
55
+ ```
56
+
57
+ ### 常用方法
58
+
59
+ ```js
60
+
61
+ // 截图
62
+ const base64 = threeEditor.getSceneEditorImage()
63
+ const link = document.createElement('a');
64
+ link.href = base64;
65
+ link.download = 'myImage.png';
66
+ link.click()
67
+
68
+ threeEditor.setOutlinePass([mesh1, mesh2]) // 选中物体添加轮廓
69
+
70
+ // 设置css2d css3d 标签
71
+ threeEditor.setCss2dDOM(div, position)
72
+ threeEditor.setCss3dDOM(div, position)
73
+
74
+ const { scene } = threeEditor
75
+
76
+ scene.setSceneBackground(urls) // 设置场景背景 天空盒六张图 urls = []
77
+ scene.background = null // 清空天空
78
+
79
+ scene.setEnvBackground(urls) // 设置环境贴图 天空盒六张图 urls = []
80
+ scene.environmentEnabled = true // 开启环境贴图
81
+ scene.envBackground = null // 清空环境贴图
82
+ ```
83
+
84
+ ### 自定义3D 组件
85
+
86
+ ```js
87
+ /**
88
+ * component 自定义组件 结构
89
+ * {
90
+
91
+ name: String, // 名称
92
+
93
+ label: '组件名字', // 标签
94
+
95
+ initPanel?: (initFolder, args, cores) => void,
96
+
97
+ createPanel?: (mesh, folder, args) => void,
98
+
99
+ getStorage: (mesh, args, cores) => storage,
100
+
101
+ setStorage: (mesh, storage, args, cores) => void,
102
+
103
+ create: (storage, args, cores) => mesh
104
+ }
105
+ */
106
+ ThreeEditor.__DESIGNS__.push(component)
107
+ ```
108
+
109
+ ### 自定义后期处理
110
+
111
+ ```js
112
+
113
+ const install = ({ DOM, renderer }) => {
114
+ const afterimagePass = new AfterimagePass();
115
+ afterimagePass.enabled = false
116
+ afterimagePass.uniforms["damp"].value = 0.96
117
+ return afterimagePass
118
+ }
119
+
120
+ const getStorage = (afterimagePass) => {
121
+ return {
122
+ damp: afterimagePass.uniforms["damp"].value,
123
+ enabled: afterimagePass.enabled
124
+ }
125
+ }
126
+
127
+ const setStorage = (afterimagePass, storage) => {
128
+ if (storage.damp !== undefined) afterimagePass.uniforms["damp"].value = storage.damp;
129
+ }
130
+
131
+ const createPanel = (afterimagePass, folder) => folder.add(afterimagePass, 'enabled').name('启用残影效果')
132
+
133
+ const customEffect = {
134
+ name: 'afterimagePass',
135
+ label: '残影效果',
136
+ order: 80, // 排序
137
+ install, // 安装
138
+ getStorage, // 存储
139
+ setStorage, // 还原
140
+ createPanel // 控制板
141
+ }
142
+
143
+ ThreeEditor.__EFFECTS__.push(customEffect)
144
+ ```