@things-factory/scene-visualizer 6.0.1 → 6.0.5

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/src/path.js DELETED
@@ -1,167 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import * as THREE from 'three'
5
- import Object3D from './object3d'
6
-
7
- const STATUS_COLORS = ['#6666ff', '#ccccff', '#ffcccc', '#cc3300']
8
-
9
- export default class Path extends Object3D {
10
- constructor(model, canvasSize, container) {
11
- super(model)
12
-
13
- this._container = container
14
-
15
- this.createObject(canvasSize)
16
- }
17
-
18
- async createObject(canvasSize) {
19
- var { x1, y1, x2, y2, lineWidth = 5, location } = this.model
20
-
21
- x1 = x1 - canvasSize.width / 2
22
- y1 = y1 - canvasSize.height / 2
23
- x2 = x2 - canvasSize.width / 2
24
- y2 = y2 - canvasSize.height / 2
25
- let z = 0
26
-
27
- this.type = 'path'
28
-
29
- if (location) this.name = location
30
-
31
- let material = new THREE.LineBasicMaterial({
32
- color: 0x333333,
33
- linewidth: lineWidth
34
- })
35
-
36
- let geometry = new THREE.BufferGeometry()
37
-
38
- geometry.vertices.push(new THREE.Vector3(x1, z, y1))
39
- geometry.vertices.push(new THREE.Vector3(x2, z, y2))
40
-
41
- let line = new THREE.Line(geometry, material)
42
-
43
- this.add(line)
44
-
45
- //
46
- // for(var i=0; i<3; i++ ){
47
- // let mesh = this.createSensor(model.rx * (1 + 0.5*i), model.ry * (1 + 0.5*i), model.depth * (1 + 0.5*i), i)
48
- // mesh.material.opacity = 0.5 - (i * 0.15)
49
- // }
50
- //
51
- // this.position.set(cx, cz, cy)
52
- // this.rotation.y = model.rotation || 0
53
- //
54
- // this._container._heatmap.addData({
55
- // x: Math.floor(model.cx),
56
- // y: Math.floor(model.cy),
57
- // value: this.userData.temperature
58
- // })
59
- //
60
- // this._container.updateHeatmapTexture()
61
-
62
- // var self = this
63
- //
64
- // setInterval(function(){
65
- //
66
- // var data = self._container._heatmap._store._data
67
- //
68
- // // var value = self._container._heatmap.getValueAt({x:model.cx, y: model.cy})
69
- // var value = data[model.cx][model.cy]
70
- //
71
- // self._container._heatmap.addData({
72
- // x: model.cx,
73
- // y: model.cy,
74
- // // min: -100,
75
- // // value: -1
76
- // value: (Math.random() * 40 - 10) - value
77
- // })
78
- // self._container._heatmap.repaint()
79
- //
80
- // self._container.render_threed()
81
- // }, 1000)
82
- }
83
-
84
- createSensor(w, h, d, i) {
85
- var isFirst = i === 0
86
-
87
- let geometry = new THREE.SphereBufferGeometry(w, 32, 32)
88
- // let geometry = new THREE.SphereGeometry(w, d, h);
89
- var material
90
- if (isFirst) {
91
- // var texture = new THREE.TextureLoader().load('./images/drop-34055_1280.png')
92
- // texture.repeat.set(1,1)
93
- // // texture.premultiplyAlpha = true
94
- material = new THREE.MeshStandardMaterial({ color: '#cc3300', side: THREE.FrontSide })
95
- // material = new THREE.MeshStandardMaterial( { color : '#74e98a', side: THREE.FrontSide} );
96
- } else {
97
- material = new THREE.MeshStandardMaterial({
98
- color: '#cc3300',
99
- side: THREE.FrontSide,
100
- wireframe: true,
101
- wireframeLinewidth: 1
102
- })
103
- // material = new THREE.MeshStandardMaterial( { color : '#74e98a', side: THREE.FrontSide, wireframe: true, wireframeLinewidth : 1} );
104
- }
105
-
106
- // let material = new THREE.MeshStandardMaterial( { color : '#ff3300', side: THREE.DoubleSide, wireframe: true, wireframeLinewidth : 1} );
107
-
108
- var mesh = new THREE.Mesh(geometry, material)
109
- mesh.material.transparent = true
110
-
111
- this.add(mesh)
112
-
113
- return mesh
114
- }
115
-
116
- onUserDataChanged() {
117
- super.onUserDataChanged()
118
-
119
- var { cx, cy } = this._model
120
- cx = Math.floor(cx)
121
- cy = Math.floor(cy)
122
-
123
- var temperature = this.userData.temperature
124
-
125
- for (let sphere of this.children) {
126
- var colorIndex = 0
127
- if (temperature < 0) {
128
- colorIndex = 0
129
- } else if (temperature < 10) {
130
- colorIndex = 1
131
- } else if (temperature < 20) {
132
- colorIndex = 2
133
- } else {
134
- colorIndex = 3
135
- }
136
-
137
- sphere.material.color.set(STATUS_COLORS[colorIndex])
138
- }
139
-
140
- var data = this._container._heatmap._store._data
141
-
142
- // var value = self._container._heatmap.getValueAt({x:model.cx, y: model.cy})
143
- var value = data[cx][cy]
144
-
145
- this._container._heatmap.addData({
146
- x: cx,
147
- y: cy,
148
- // min: -100,
149
- // value: -1
150
- value: temperature - value
151
- })
152
- this._container._heatmap.repaint()
153
-
154
- // this._container.render_threed()
155
- this._container.updateHeatmapTexture()
156
- }
157
- }
158
-
159
- var { Component, Line } = scene
160
-
161
- export class LinePath extends Line {
162
- is3dish() {
163
- return true
164
- }
165
- }
166
-
167
- Component.register('path', LinePath)
@@ -1,460 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Component, RectPath } from '@hatiolab/things-scene'
5
- import * as THREE from 'three'
6
-
7
- const NATURE = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'string',
14
- label: 'src',
15
- name: 'src',
16
- property: 'src'
17
- },
18
- {
19
- type: 'checkbox',
20
- label: 'autoplay',
21
- name: 'autoplay',
22
- property: 'autoplay'
23
- }
24
- ]
25
- }
26
-
27
- export default class VideoPlayer360 extends RectPath(Component) {
28
- get nature() {
29
- return NATURE
30
- }
31
-
32
- init_scene(width, height) {
33
- var { mute, loop, autoplay, src, fov, clickAndDrag, wheelEnabled } = this.model
34
-
35
- this._dragStart = {}
36
- this._lon = 0
37
- this._lat = 0
38
- this._clickAndDrag = clickAndDrag
39
- this._isPlaying = false
40
- this._wheelEnabled = wheelEnabled
41
-
42
- this._fov = fov || 35
43
- this._fovMin = 3
44
- this._fovMax = 100
45
-
46
- this._time = new Date().getTime()
47
-
48
- // create a local THREE.js scene
49
- this._scene = new THREE.Scene()
50
-
51
- // create ThreeJS camera
52
- this._camera = new THREE.PerspectiveCamera(fov, width / height, 0.1, 1000)
53
- this._camera.setFocalLength(fov)
54
-
55
- // create ThreeJS renderer and append it to our object
56
- this._renderer = new THREE.WebGLRenderer()
57
- this._renderer.setSize(width, height)
58
- this._renderer.autoClear = false
59
- this._renderer.setClearColor(0x333333, 1)
60
-
61
- // create off-dom video player
62
- this._video = document.createElement('video')
63
- this._video.setAttribute('crossorigin', 'anonymous')
64
- this._video.loop = loop
65
- this._video.muted = mute
66
- this._texture = new THREE.Texture(this._video)
67
-
68
- // make a self reference we can pass to our callbacks
69
- var self = this
70
-
71
- // attach video player event listeners
72
- this._video.addEventListener('ended', function () {
73
- this._isPlaying = false
74
- })
75
-
76
- // Progress Meter
77
- this._video.addEventListener('progress', function () {
78
- var percent = null
79
- if (
80
- self._video &&
81
- self._video.buffered &&
82
- self._video.buffered.length > 0 &&
83
- self._video.buffered.end &&
84
- self._video.duration
85
- ) {
86
- percent = self._video.buffered.end(0) / self._video.duration
87
- }
88
- // Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
89
- // to be anything other than 0. If the byte count is available we use this instead.
90
- // Browsers that support the else if do not seem to have the bufferedBytes value and
91
- // should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
92
- else if (
93
- self._video &&
94
- self._video.bytesTotal !== undefined &&
95
- self._video.bytesTotal > 0 &&
96
- self._video.bufferedBytes !== undefined
97
- ) {
98
- percent = self._video.bufferedBytes / self._video.bytesTotal
99
- }
100
-
101
- // Someday we can have a loading animation for videos
102
- var cpct = Math.round(percent * 100)
103
- if (cpct === 100) {
104
- // do something now that we are done
105
- } else {
106
- // do something with this percentage info (cpct)
107
- }
108
- })
109
-
110
- // Video Play Listener, fires after video loads
111
- // this._video.addEventListener("canplaythrough", function() {
112
- this._video.addEventListener('canplay', function () {
113
- if (autoplay === true) {
114
- self.play()
115
- self._videoReady = true
116
- }
117
- })
118
-
119
- // set the video src and begin loading
120
- this._video.src = this.app.url(src)
121
-
122
- this._texture.generateMipmaps = false
123
- this._texture.minFilter = THREE.LinearFilter
124
- this._texture.magFilter = THREE.LinearFilter
125
- this._texture.format = THREE.RGBFormat
126
-
127
- // create ThreeJS mesh sphere onto which our texture will be drawn
128
- this._mesh = new THREE.Mesh(
129
- new THREE.SphereBufferGeometry(500, 80, 50),
130
- new THREE.MeshStandardMaterial({ map: this._texture })
131
- )
132
- this._mesh.scale.x = -1 // mirror the texture, since we're looking from the inside out
133
- this._scene.add(this._mesh)
134
-
135
- // this.createControls()
136
-
137
- this.animate()
138
- }
139
-
140
- destroy_scene() {
141
- cancelAnimationFrame(this._requestAnimationId)
142
- this._requestAnimationId = undefined
143
- this._texture.dispose()
144
- this._scene.remove(this._mesh)
145
- this.unloadVideo()
146
-
147
- this._renderer = undefined
148
- this._camera = undefined
149
- this._keyboard = undefined
150
- this._controls = undefined
151
- this._projector = undefined
152
- this._load_manager = undefined
153
-
154
- this._scene = undefined
155
- this._video = undefined
156
- }
157
-
158
- loadVideo(videoFile) {
159
- this._video.src = videoFile
160
- }
161
-
162
- unloadVideo() {
163
- // overkill unloading to avoid dreaded video 'pending' bug in Chrome. See https://code.google.com/p/chromium/issues/detail?id=234779
164
- this.pause()
165
- this._video.src = ''
166
- this._video.removeAttribute('src')
167
- }
168
-
169
- play() {
170
- this._isPlaying = true
171
- this._video.play()
172
- }
173
-
174
- pause() {
175
- this._isPlaying = false
176
- this._video.pause()
177
- }
178
-
179
- resize(w, h) {
180
- if (!this._renderer) return
181
- this._renderer.setSize(w, h)
182
- this._camera.aspect = w / h
183
- this._camera.updateProjectionMatrix()
184
- }
185
-
186
- animate() {
187
- this._requestAnimationId = requestAnimationFrame(this.animate.bind(this))
188
-
189
- if (this._video.readyState === this._video.HAVE_ENOUGH_DATA) {
190
- if (typeof this._texture !== 'undefined') {
191
- var ct = new Date().getTime()
192
- if (ct - this._time >= 30) {
193
- this._texture.needsUpdate = true
194
- this._time = ct
195
- }
196
- }
197
- }
198
-
199
- this.render()
200
- this.invalidate()
201
- }
202
-
203
- render() {
204
- this._lat = Math.max(-85, Math.min(85, this._lat || 0))
205
- this._phi = ((90 - this._lat) * Math.PI) / 180
206
- this._theta = ((this._lon || 0) * Math.PI) / 180
207
-
208
- var cx = 500 * Math.sin(this._phi) * Math.cos(this._theta)
209
- var cy = 500 * Math.cos(this._phi)
210
- var cz = 500 * Math.sin(this._phi) * Math.sin(this._theta)
211
-
212
- this._camera.lookAt(new THREE.Vector3(cx, cy, cz))
213
-
214
- // distortion
215
- if (this.model.flatProjection) {
216
- this._camera.position.x = 0
217
- this._camera.position.y = 0
218
- this._camera.position.z = 0
219
- } else {
220
- this._camera.position.x = -cx
221
- this._camera.position.y = -cy
222
- this._camera.position.z = -cz
223
- }
224
-
225
- this._renderer.clear()
226
- this._renderer.render(this._scene, this._camera)
227
- }
228
-
229
- // creates div and buttons for onscreen video controls
230
- createControls() {
231
- var muteControl = this.options.muted ? 'fa-volume-off' : 'fa-volume-up'
232
- var playPauseControl = this.options.autoplay ? 'fa-pause' : 'fa-play'
233
-
234
- var controlsHTML =
235
- ' \
236
- <div class="controls"> \
237
- <a href="#" class="playButton button fa ' +
238
- playPauseControl +
239
- '"></a> \
240
- <a href="#" class="muteButton button fa ' +
241
- muteControl +
242
- '"></a> \
243
- <a href="#" class="fullscreenButton button fa fa-expand"></a> \
244
- </div> \
245
- '
246
-
247
- $(this.element).append(controlsHTML, true)
248
-
249
- // hide controls if option is set
250
- if (this.options.hideControls) {
251
- $(this.element).find('.controls').hide()
252
- }
253
-
254
- // wire up controller events to dom elements
255
- // this.attachControlEvents();
256
- }
257
-
258
- attachControlEvents() {
259
- // create a self var to pass to our controller functions
260
- var self = this
261
-
262
- this.element.addEventListener('mousemove', this.onMouseMove.bind(this), false)
263
- this.element.addEventListener('touchmove', this.onMouseMove.bind(this), false)
264
- this.element.addEventListener('mousewheel', this.onMouseWheel.bind(this), false)
265
- this.element.addEventListener('DOMMouseScroll', this.onMouseWheel.bind(this), false)
266
- this.element.addEventListener('mousedown', this.onMouseDown.bind(this), false)
267
- this.element.addEventListener('touchstart', this.onMouseDown.bind(this), false)
268
- this.element.addEventListener('mouseup', this.onMouseUp.bind(this), false)
269
- this.element.addEventListener('touchend', this.onMouseUp.bind(this), false)
270
-
271
- $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange', this.fullscreen.bind(this))
272
-
273
- $(window).resize(function () {
274
- self.resizeGL($(self.element).width(), $(self.element).height())
275
- })
276
-
277
- // Player Controls
278
- $(this.element)
279
- .find('.playButton')
280
- .click(function (e) {
281
- e.preventDefault()
282
- if ($(this).hasClass('fa-pause')) {
283
- $(this).removeClass('fa-pause').addClass('fa-play')
284
- self.pause()
285
- } else {
286
- $(this).removeClass('fa-play').addClass('fa-pause')
287
- self.play()
288
- }
289
- })
290
-
291
- $(this.element)
292
- .find('.fullscreenButton')
293
- .click(function (e) {
294
- e.preventDefault()
295
- var elem = $(self.element)[0]
296
- if ($(this).hasClass('fa-expand')) {
297
- if (elem.requestFullscreen) {
298
- elem.requestFullscreen()
299
- } else if (elem.msRequestFullscreen) {
300
- elem.msRequestFullscreen()
301
- } else if (elem.mozRequestFullScreen) {
302
- elem.mozRequestFullScreen()
303
- } else if (elem.webkitRequestFullscreen) {
304
- elem.webkitRequestFullscreen()
305
- }
306
- } else {
307
- if (elem.requestFullscreen) {
308
- document.exitFullscreen()
309
- } else if (elem.msRequestFullscreen) {
310
- document.msExitFullscreen()
311
- } else if (elem.mozRequestFullScreen) {
312
- document.mozCancelFullScreen()
313
- } else if (elem.webkitRequestFullscreen) {
314
- document.webkitExitFullscreen()
315
- }
316
- }
317
- })
318
-
319
- $(this.element)
320
- .find('.muteButton')
321
- .click(function (e) {
322
- e.preventDefault()
323
- if ($(this).hasClass('fa-volume-off')) {
324
- $(this).removeClass('fa-volume-off').addClass('fa-volume-up')
325
- self._video.muted = false
326
- } else {
327
- $(this).removeClass('fa-volume-up').addClass('fa-volume-off')
328
- self._video.muted = true
329
- }
330
- })
331
- }
332
-
333
- /* Component Overides .. */
334
-
335
- _draw(ctx) {
336
- var { left, top, width, height, src } = this.model
337
-
338
- ctx.beginPath()
339
- ctx.rect(left, top, width, height)
340
- }
341
-
342
- _post_draw(ctx) {
343
- var { left, top, width, height, src } = this.model
344
-
345
- if (src) {
346
- if (!this._scene) {
347
- this.init_scene(width, height)
348
- this.render()
349
- }
350
-
351
- this.drawImage(ctx, this._renderer.domElement, 0, 0, width, height, left, top, width, height)
352
- } else {
353
- this.drawFill(ctx)
354
- }
355
-
356
- this.drawStroke(ctx)
357
- }
358
-
359
- onchange(after, before) {
360
- if (after.hasOwnProperty('width') || after.hasOwnProperty('height')) {
361
- this.resize(this.model.width, this.model.height)
362
- }
363
-
364
- if (after.hasOwnProperty('src') || after.hasOwnProperty('autoplay')) {
365
- this.destroy_scene()
366
- }
367
-
368
- this.invalidate()
369
- }
370
-
371
- ondblclick(e) {
372
- if (this._isPlaying) this.pause()
373
- else this.play()
374
-
375
- e.stopPropagation()
376
- }
377
-
378
- onmousedown(e) {}
379
-
380
- onmousemove(e) {
381
- if (this._clickAndDrag === false) {
382
- var x, y
383
-
384
- this._onPointerDownPointerX = e.offsetX
385
- this._onPointerDownPointerY = -e.offsetY
386
-
387
- this._onPointerDownLon = this._lon
388
- this._onPointerDownLat = this._lat
389
-
390
- x = e.offsetX - this._renderer.getContext().canvas.offsetLeft
391
- y = e.offsetY - this._renderer.getContext().canvas.offsetTop
392
- this._lon = (x / this._renderer.getContext().canvas.width) * 430 - 225
393
- this._lat = (y / this._renderer.getContext().canvas.height) * -180 + 90
394
- }
395
- }
396
-
397
- onwheel(e) {
398
- if (this._wheelEnabled === false) return
399
-
400
- var wheelSpeed = 0.01
401
-
402
- this._fov -= e.deltaY * wheelSpeed
403
-
404
- if (this._fov < this._fovMin) {
405
- this._fov = this._fovMin
406
- } else if (this._fov > this._fovMax) {
407
- this._fov = this._fovMax
408
- }
409
-
410
- this._camera.setFocalLength(this._fov)
411
- this._camera.updateProjectionMatrix()
412
- e.stopPropagation()
413
- }
414
-
415
- ondragstart(e) {
416
- // this._dragStart.x = e.pageX;
417
- // this._dragStart.y = e.pageY;
418
- this._dragStart.x = e.offsetX
419
- this._dragStart.y = e.offsetY
420
- }
421
-
422
- ondragmove(e) {
423
- if (this._isPlaying === false) {
424
- return
425
- }
426
-
427
- if (this._clickAndDrag !== false) {
428
- // this._onPointerDownPointerX = e.clientX;
429
- // this._onPointerDownPointerY = -e.clientY;
430
- this._onPointerDownPointerX = e.offsetX
431
- this._onPointerDownPointerY = -e.offsetY
432
-
433
- this._onPointerDownLon = this._lon
434
- this._onPointerDownLat = this._lat
435
-
436
- var x, y
437
-
438
- x = e.offsetX - this._dragStart.x
439
- y = e.offsetY - this._dragStart.y
440
- this._dragStart.x = e.offsetX
441
- this._dragStart.y = e.offsetY
442
- this._lon += x
443
- this._lat -= y
444
- }
445
-
446
- e.stopPropagation()
447
- }
448
-
449
- ondragend(e) {}
450
-
451
- ontouchstart(e) {}
452
-
453
- ontouchmove(e) {}
454
-
455
- ontouchend(e) {}
456
-
457
- onkeydown(e) {}
458
- }
459
-
460
- Component.register('video-player-360', VideoPlayer360)