Skip to content

Commit f8e185b

Browse files
committed
update OffscreenCanvas
1 parent eacfa4a commit f8e185b

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

22 Three.js优化之OffscreenCanvas与WebWorker.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,5 +540,42 @@ if ( state !== STATE.NONE ) {
540540
541541
542542
543-
额~ 因为最近接了一个设计的活,本文先暂停更新几天。
543+
我们这里使用 Three.js 提供的 EventDispatcher。
544+
545+
> 原生 JS 中内置的 EventTarget 本质上也是一种内置的对象而已,和我们使用 Three.js 提供的 EventDispatcher 区别并不大。
546+
547+
548+
549+
接下来开始讲解具体如何实现 “虚拟DOM对象(真实 DOM 事件代理对象)”。
550+
551+
> 过程略微有点复杂,我尽量讲清楚。
552+
553+
554+
555+
#### 实现思路和代码片段
556+
557+
**第1步:先定义好我们准备 ‘复制(代理)’ 各种事件中的属性名**
558+
559+
```
560+
//鼠标事件,我们需要复制的属性名
561+
const mouseEventProperties = ['ctrlKey', 'metaKey', 'shiftKey', 'button', 'clientX', 'clientY', 'pageX', 'pageY']
562+
563+
//鼠标滚轴事件,我们需要复制的属性名
564+
const wheelEventProperties = ['deltaX','deltaY']
565+
566+
//键盘事件,我们需要复制的属性名
567+
const keyboardEventProperties = ['ctrlKey','metaKey','shiftKey','keyCode']
568+
```
569+
570+
571+
572+
**第2步:定义负责拷贝指定属性的函数**
573+
574+
```
575+
const copyProperties = (src: any, properties: string[], dst: any) => {
576+
properties.forEach((key) => {
577+
dst[key] = src[key]
578+
})
579+
}
580+
```
544581

0 commit comments

Comments
 (0)