-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
174 lines (141 loc) · 5.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MR.js whiteboard</title>
<meta name="description" content="MR.js whiteboard">
<script src="https://cdn.jsdelivr.net/gh/volumetrics-io/mrjs@latest/dist/build.js"></script>
<link rel="stylesheet" type="text/css" href="./style.css" />
<style>
html {
overflow: hidden;
overscroll-behavior: none;
-webkit-user-select: none; /* Safari */
-ms-user-select: none; /* IE 10 and IE 11 */
user-select: none; /* Standard syntax */
}
</style>
</head>
<body >
<mr-app camera="camera: orthographic">
<mr-surface>
<mr-container>
<mr-column>
<mr-whiteboard id="board"></mr-whiteboard>
<!--markers-->
<mr-row height ="0.2" width="3">
<mr-button color="black"></mr-button>
<mr-button color="red"></mr-button>
<mr-button color="blue"></mr-button>
<mr-button color="green"></mr-button>
<mr-button color="yellow"></mr-button>
<mr-button color="purple"></mr-button>
<mr-button color="brown"></mr-button>
<mr-button color="orange"></mr-button>
<mr-button color="magenta"></mr-button>
<mr-button color="darkred"></mr-button>
<mr-button id="eraser" color="white"></mr-button>
</mr-row>
</mr-column>
</mr-container>
</mr-surface>
</mr-app>
</body>
<footer>
<script>
let color = '#000000'
let strokeWidth = 5
let buttons = document.querySelectorAll('mr-button')
for(const button of buttons) {
button.addEventListener('click', (event) => {
if(event.target.id == 'eraser') {
color = "#ffffff"
strokeWidth = 50
} else {
color = event.target.color
strokeWidth = 5
}
})
}
class Whiteboard extends Panel {
set absoluteHeight(value) {
super.absoluteHeight = value
this.resizeCanvas()
}
get absoluteHeight() {
return super.absoluteHeight
}
set absoluteWidth(value) {
super.absoluteWidth = value
this.resizeCanvas()
}
get absoluteWidth() {
return super.absoluteWidth
}
constructor(){
super()
this.resolution = 1080
this.canvas = document.createElement('canvas')
document.querySelector('mr-app').appendChild(this.canvas)
this.canvas.width = this.width * this.resolution
this.canvas.height = this.height * this.resolution
this.context = this.canvas.getContext('2d')
this.canvasScale = new THREE.Vector3(this.canvas.width, this.canvas.height, 1)
this.drawPosition = new THREE.Vector3()
this.drawStartPosition = new THREE.Vector3();
this.context.fillStyle = '#FFFFFF';
this.context.lineWidth = 5;
this.context.lineCap = 'round'
this.context.lineJoin = 'round'
this.context.fillRect( 0, 0, this.canvas.width, this.canvas.height );
this.canvasTexture = new THREE.CanvasTexture(this.canvas)
this.object3D.material.map = this.canvasTexture
this.zOffeset = 0.005
this.addEventListener('touch-start', (event) => {
this.context.beginPath();
this.drawStartPosition.copy(event.detail.position)
this.getCanvasPosition(this.drawStartPosition)
})
this.addEventListener('touch', (event) => {
console.log('touch');
this.drawPosition.copy(event.detail.position)
this.getCanvasPosition(this.drawPosition)
this.draw()
})
}
resizeCanvas() {
this.canvas.width = this.absoluteWidth * this.resolution
this.canvas.height = this.absoluteHeight * this.resolution
console.log('width', this.canvas.width);
console.log('height', this.canvas.height);
this.context.fillStyle = '#FFFFFF';
this.context.lineWidth = 5;
this.context.lineCap = 'round'
this.context.lineJoin = 'round'
this.context.fillRect( 0, 0, this.canvas.width, this.canvas.height );
this.canvasTexture = new THREE.CanvasTexture(this.canvas)
this.object3D.material.map = this.canvasTexture
this.canvasScale.setX(this.canvas.width)
this.canvasScale.setY(this.canvas.height)
}
getCanvasPosition(position) {
position.setX(position.x + (this.absoluteWidth / 2))
position.setY((this.absoluteHeight / 2) - position.y)
position.multiplyScalar(this.resolution)
}
draw() {
this.context.moveTo( this.drawStartPosition.x , this.drawStartPosition.y);
this.context.strokeStyle = color;
this.context.lineWidth = strokeWidth;
this.context.lineTo( this.drawPosition.x, this.drawPosition.y );
this.context.stroke();
// reset drawing start position to current position.
this.drawStartPosition.set( this.drawPosition );
// need to flag the map as needing updating.
this.object3D.material.map.needsUpdate = true;
}
}
customElements.get('mr-whiteboard') || customElements.define('mr-whiteboard', Whiteboard)
</script>
</footer>
</html>