@operato/scene-visualizer 8.0.0-beta.0 → 8.0.0-beta.2
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/package.json +5 -5
- package/CHANGELOG.md +0 -640
- package/attachments/0d91a37d-c2d7-4c6d-88dc-a29e5bbea361.png +0 -0
- package/attachments/1b07c8d3-07d5-4007-b02e-031ee1755539.glb +0 -0
- package/attachments/226c6c23-c4fd-46c8-93e3-3d3d9c4bb8a9.glb +0 -0
- package/attachments/4425ca46-cf1d-476d-9185-dcb881ecad1f.glb +0 -0
- package/attachments/51e7c45d-6eae-4baf-a4e2-ba979b7e77cd.glb +0 -0
- package/attachments/54427925-c109-4499-875c-fb14207b95c5.glb +0 -0
- package/attachments/8cc70a65-e20f-4187-83c8-64deb3faf3d9.glb +0 -0
- package/attachments/964d004d-1fe7-4224-89a6-2b6e86db233c.glb +0 -0
- package/attachments/ff47fd63-6f1c-4a69-b965-9bb03797a415.png +0 -0
- package/db.sqlite +0 -0
- package/demo/index-modeller.html +0 -112
- package/demo/index.html +0 -109
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -25
- package/logs/.5e5d741d8b7784a2fbad65eedc0fd46946aaf6f2-audit.json +0 -25
- package/logs/application-2025-01-07-10.log +0 -106
- package/logs/application-2025-01-07-14.log +0 -4
- package/logs/application-2025-01-07-15.log +0 -4
- package/logs/connections-2025-01-07-10.log +0 -106
- package/logs/connections-2025-01-07-14.log +0 -53
- package/logs/connections-2025-01-07-15.log +0 -53
- package/schema.graphql +0 -4552
- package/src/banner.ts +0 -88
- package/src/camera.ts +0 -132
- package/src/component.d.ts +0 -10
- package/src/cube.ts +0 -39
- package/src/cylinder.ts +0 -39
- package/src/desk.ts +0 -135
- package/src/editors/index.ts +0 -13
- package/src/editors/property-editor-gltf-info.ts +0 -135
- package/src/editors/property-editor-location-increase-pattern.ts +0 -260
- package/src/effects/outline.ts +0 -54
- package/src/ellipse.ts +0 -37
- package/src/gltf-object.ts +0 -117
- package/src/html-overlay-element.ts +0 -13
- package/src/index.ts +0 -29
- package/src/light.ts +0 -155
- package/src/polygon.ts +0 -88
- package/src/rack-table-cell.ts +0 -386
- package/src/rack-table.ts +0 -1296
- package/src/rack.ts +0 -232
- package/src/rect.ts +0 -39
- package/src/scene/component.ts +0 -38
- package/src/sphere.ts +0 -39
- package/src/sprite.ts +0 -30
- package/src/stock.ts +0 -262
- package/src/templates/3d-container.ts +0 -21
- package/src/templates/banner.ts +0 -21
- package/src/templates/camera.ts +0 -25
- package/src/templates/cube.ts +0 -20
- package/src/templates/cylinder.ts +0 -20
- package/src/templates/desk.ts +0 -20
- package/src/templates/gltf-object.ts +0 -20
- package/src/templates/index.ts +0 -29
- package/src/templates/light.ts +0 -23
- package/src/templates/pallet.ts +0 -20
- package/src/templates/rack-table.ts +0 -21
- package/src/templates/sphere.ts +0 -20
- package/src/templates/sprite.ts +0 -21
- package/src/templates/visualizer.ts +0 -21
- package/src/templates/wall.ts +0 -20
- package/src/text.ts +0 -10
- package/src/three-container-editor.ts +0 -187
- package/src/three-container.ts +0 -724
- package/src/three-controls.ts +0 -778
- package/src/three-layout.ts +0 -25
- package/src/three-space.ts +0 -732
- package/src/threed/common.ts +0 -21
- package/src/threed/floor/floor.ts +0 -62
- package/src/threed/html/elements.ts +0 -27
- package/src/threed/index.ts +0 -15
- package/src/threed/real-object-camera-meshed.ts +0 -67
- package/src/threed/real-object-camera.ts +0 -41
- package/src/threed/real-object-dom-element.ts +0 -55
- package/src/threed/real-object-dummy.ts +0 -13
- package/src/threed/real-object-extrude.ts +0 -210
- package/src/threed/real-object-gltf.ts +0 -136
- package/src/threed/real-object-group.ts +0 -35
- package/src/threed/real-object-mesh.ts +0 -74
- package/src/threed/real-object-plane.ts +0 -27
- package/src/threed/real-object-scene.ts +0 -84
- package/src/threed/real-object-sprite-2d.ts +0 -54
- package/src/threed/real-object-sprite.ts +0 -64
- package/src/threed/real-object-text.ts +0 -86
- package/src/threed/real-object.ts +0 -326
- package/src/threed/texture/canvas-texture.ts +0 -67
- package/src/threed/texture/text-texture.ts +0 -100
- package/src/threed/three-dimensional-container.ts +0 -9
- package/src/threed/utils/bound-uv-generator.ts +0 -80
- package/src/visualizer.ts +0 -319
- package/src/wall.ts +0 -50
- package/tsconfig.json +0 -24
- package/tsconfig.tsbuildinfo +0 -1
- package/web-dev-server.config.mjs +0 -27
package/src/three-container.ts
DELETED
|
@@ -1,724 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Component, ComponentNature, Container, error, FPS, Layout, Properties } from '@hatiolab/things-scene'
|
|
6
|
-
import * as THREE from 'three'
|
|
7
|
-
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js'
|
|
8
|
-
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js'
|
|
9
|
-
|
|
10
|
-
import ThreeControls from './three-controls'
|
|
11
|
-
import './three-layout'
|
|
12
|
-
import { RealObject } from './threed/real-object'
|
|
13
|
-
import { ThreeDimensionalContainer } from './threed/three-dimensional-container'
|
|
14
|
-
import { CSS3DRenderer } from 'three/examples/jsm/renderers/CSS3DRenderer'
|
|
15
|
-
import { createFloor } from './threed/floor/floor'
|
|
16
|
-
import { RealObjectDomElement } from './threed'
|
|
17
|
-
|
|
18
|
-
const NATURE: ComponentNature = {
|
|
19
|
-
mutable: false,
|
|
20
|
-
resizable: true,
|
|
21
|
-
rotatable: true,
|
|
22
|
-
properties: [
|
|
23
|
-
{
|
|
24
|
-
type: 'select',
|
|
25
|
-
label: 'precision',
|
|
26
|
-
name: 'precision',
|
|
27
|
-
property: {
|
|
28
|
-
options: [
|
|
29
|
-
{
|
|
30
|
-
display: 'High',
|
|
31
|
-
value: 'highp'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
display: 'Medium',
|
|
35
|
-
value: 'mediump'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
display: 'Low',
|
|
39
|
-
value: 'lowp'
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
type: 'checkbox',
|
|
46
|
-
label: 'anti-alias',
|
|
47
|
-
name: 'antialias',
|
|
48
|
-
property: 'antialias'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
type: 'checkbox',
|
|
52
|
-
label: '3dmode',
|
|
53
|
-
name: 'threed',
|
|
54
|
-
property: 'threed'
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'checkbox',
|
|
58
|
-
label: 'auto-rotate',
|
|
59
|
-
name: 'autoRotate',
|
|
60
|
-
property: 'autoRotate'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
type: 'checkbox',
|
|
64
|
-
label: 'debug',
|
|
65
|
-
name: 'debug',
|
|
66
|
-
property: 'debug'
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
help: 'scene/component/three-container'
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const WEBGL_NO_SUPPORT_TEXT = 'WebGL no support'
|
|
73
|
-
|
|
74
|
-
export class ThreeContainer extends Container implements ThreeDimensionalContainer {
|
|
75
|
-
_scene3d?: THREE.Scene
|
|
76
|
-
_initalizeComplete?: Promise<void>
|
|
77
|
-
|
|
78
|
-
_mixer?: THREE.AnimationMixer
|
|
79
|
-
|
|
80
|
-
_camera?: THREE.PerspectiveCamera
|
|
81
|
-
_renderer3d?: THREE.WebGLRenderer
|
|
82
|
-
|
|
83
|
-
_mouse?: THREE.Vector2
|
|
84
|
-
|
|
85
|
-
_clock?: THREE.Clock
|
|
86
|
-
|
|
87
|
-
_controls?: any
|
|
88
|
-
_onFocus?: (e: FocusEvent) => void
|
|
89
|
-
_onResize?: (e: Event) => void
|
|
90
|
-
_noSupportWebgl: boolean = false
|
|
91
|
-
|
|
92
|
-
_raycaster = new THREE.Raycaster()
|
|
93
|
-
|
|
94
|
-
_lastFocused?: RealObject
|
|
95
|
-
_lastHovered?: RealObject
|
|
96
|
-
|
|
97
|
-
private _css3DScene?: THREE.Scene
|
|
98
|
-
private _css3DRenderer?: CSS3DRenderer
|
|
99
|
-
|
|
100
|
-
composer?: EffectComposer
|
|
101
|
-
|
|
102
|
-
containable(component: Component) {
|
|
103
|
-
return component.is3dish()
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
is3dContainer() {
|
|
107
|
-
return true
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* THREE Object related .. */
|
|
111
|
-
|
|
112
|
-
createObjects(components: Component[]) {
|
|
113
|
-
for (let component of components) {
|
|
114
|
-
try {
|
|
115
|
-
var item = component.realObject
|
|
116
|
-
|
|
117
|
-
if (item) {
|
|
118
|
-
if (component.isHTMLElement()) {
|
|
119
|
-
this.css3DScene.add((item as RealObjectDomElement).object3d)
|
|
120
|
-
} else {
|
|
121
|
-
this._scene3d!.add(item.object3d)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
error(err)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
destroy_scene3d() {
|
|
131
|
-
this.stop()
|
|
132
|
-
|
|
133
|
-
window.removeEventListener('focus', this._onFocus!)
|
|
134
|
-
window.removeEventListener('resize', this._onResize!)
|
|
135
|
-
|
|
136
|
-
if (this._renderer3d) this._renderer3d.clear()
|
|
137
|
-
|
|
138
|
-
if (this._controls?.autoRotate) {
|
|
139
|
-
this._controls.doAutoRotate(false)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
delete this._renderer3d
|
|
143
|
-
delete this._camera
|
|
144
|
-
delete this._controls
|
|
145
|
-
|
|
146
|
-
if (this._scene3d) {
|
|
147
|
-
let children = this._scene3d.children.slice()
|
|
148
|
-
for (let i in children) {
|
|
149
|
-
let child = children[i] as any
|
|
150
|
-
if (child.dispose) child.dispose()
|
|
151
|
-
if (child.geometry && child.geometry.dispose) child.geometry.dispose()
|
|
152
|
-
if (child.material && child.material.dispose) child.material.dispose()
|
|
153
|
-
if (child.texture && child.texture.dispose) child.texture.dispose()
|
|
154
|
-
this._scene3d.remove(child)
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
delete this._scene3d
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
update() {
|
|
162
|
-
var { width, height } = this.bounds
|
|
163
|
-
|
|
164
|
-
var {
|
|
165
|
-
fov = 45,
|
|
166
|
-
near = 0.1,
|
|
167
|
-
far = 20000,
|
|
168
|
-
antialias = true,
|
|
169
|
-
precision = 'highp',
|
|
170
|
-
cameraX,
|
|
171
|
-
cameraY,
|
|
172
|
-
cameraZ,
|
|
173
|
-
exposure = 2.5
|
|
174
|
-
} = this.state
|
|
175
|
-
|
|
176
|
-
var components = this.components || []
|
|
177
|
-
|
|
178
|
-
// SCENE
|
|
179
|
-
this._scene3d = new THREE.Scene()
|
|
180
|
-
|
|
181
|
-
// CAMERA
|
|
182
|
-
var aspect = width / height
|
|
183
|
-
|
|
184
|
-
this._camera = new THREE.PerspectiveCamera(fov, aspect, near, far)
|
|
185
|
-
|
|
186
|
-
var cameraXPos = height * 0.8,
|
|
187
|
-
cameraYPos = width * 0.8,
|
|
188
|
-
cameraZPos = Math.min(500, Math.floor(Math.min(width, height)))
|
|
189
|
-
// cameraZPos = Math.floor(Math.min(width, height))
|
|
190
|
-
|
|
191
|
-
if (cameraX != undefined) cameraXPos = cameraX * width
|
|
192
|
-
if (cameraY != undefined) cameraYPos = cameraY * height
|
|
193
|
-
if (cameraZ != undefined) cameraZPos = cameraZ * Math.floor(Math.min(width, height))
|
|
194
|
-
|
|
195
|
-
this._camera.position.set(cameraXPos, cameraZPos, cameraYPos)
|
|
196
|
-
|
|
197
|
-
this._scene3d.add(this._camera)
|
|
198
|
-
this._camera.lookAt(this._scene3d.position)
|
|
199
|
-
this._camera.zoom = this.getState('zoom') * 0.01
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
const canvas = document.createElement('canvas')
|
|
203
|
-
let context = canvas!.getContext('webgl2')!
|
|
204
|
-
|
|
205
|
-
var renderer3d = new THREE.WebGLRenderer({
|
|
206
|
-
canvas,
|
|
207
|
-
context,
|
|
208
|
-
precision,
|
|
209
|
-
alpha: true,
|
|
210
|
-
antialias
|
|
211
|
-
})
|
|
212
|
-
} catch (e) {
|
|
213
|
-
this._noSupportWebgl = true
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this._renderer3d = renderer3d
|
|
218
|
-
|
|
219
|
-
renderer3d!.autoClear = true
|
|
220
|
-
// @ts-ignore for three@0.150.1
|
|
221
|
-
renderer3d!.outputColorSpace = THREE.SRGBColorSpace
|
|
222
|
-
renderer3d!.useLegacyLights = false
|
|
223
|
-
renderer3d!.toneMappingExposure = Math.pow(exposure, 5.0)
|
|
224
|
-
renderer3d!.toneMapping = THREE.LinearToneMapping
|
|
225
|
-
renderer3d!.shadowMap.enabled = true
|
|
226
|
-
renderer3d!.setClearColor(0xffffff, 0) // transparent
|
|
227
|
-
renderer3d!.setSize(width, height)
|
|
228
|
-
|
|
229
|
-
// CONTROLS
|
|
230
|
-
this._controls = new (ThreeControls as any)(this._camera, this)
|
|
231
|
-
this._controls.cameraChanged = true
|
|
232
|
-
|
|
233
|
-
// Lights
|
|
234
|
-
var _hemiLight = new THREE.HemisphereLight(0xdddddd, 0x333333, 0.035)
|
|
235
|
-
|
|
236
|
-
this.scene3d!.add(_hemiLight)
|
|
237
|
-
|
|
238
|
-
this._mouse = new THREE.Vector2()
|
|
239
|
-
|
|
240
|
-
this._clock = new THREE.Clock(true)
|
|
241
|
-
this._mixer = new THREE.AnimationMixer(this.scene3d!)
|
|
242
|
-
|
|
243
|
-
this.createObjects(components)
|
|
244
|
-
|
|
245
|
-
this._camera.updateProjectionMatrix()
|
|
246
|
-
|
|
247
|
-
const floor = createFloor(this)
|
|
248
|
-
|
|
249
|
-
if (floor) {
|
|
250
|
-
this._scene3d.add(floor)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// postprocessing
|
|
254
|
-
|
|
255
|
-
var composer = (this.composer = new EffectComposer(renderer3d!))
|
|
256
|
-
composer.setSize(width, height)
|
|
257
|
-
|
|
258
|
-
const renderPass = new RenderPass(this._scene3d, this._camera)
|
|
259
|
-
composer.addPass(renderPass)
|
|
260
|
-
|
|
261
|
-
this._onFocus = (e: FocusEvent) => {
|
|
262
|
-
this.render_threed()
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
this._onResize = (e: Event) => {
|
|
266
|
-
this.resize()
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
window.addEventListener('resize', this._onResize)
|
|
270
|
-
window.addEventListener('focus', this._onFocus)
|
|
271
|
-
|
|
272
|
-
this.buildOverlays()
|
|
273
|
-
this.resize()
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
resize() {
|
|
277
|
-
const { width, height } = this.bounds
|
|
278
|
-
|
|
279
|
-
this._camera!.aspect = width / height
|
|
280
|
-
|
|
281
|
-
this.renderer3d!.setSize(width, height)
|
|
282
|
-
this.css3DRenderer.setSize(width, height)
|
|
283
|
-
|
|
284
|
-
this.composer?.setSize(width, height)
|
|
285
|
-
this._camera!.updateProjectionMatrix()
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
init_scene3d() {
|
|
289
|
-
this.root.on('redraw', this.onredraw, this)
|
|
290
|
-
|
|
291
|
-
if (this._scene3d) {
|
|
292
|
-
this.destroy_scene3d()
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
this.update()
|
|
296
|
-
|
|
297
|
-
this.onchangeData && this.onchangeData(this.data, this.data)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
threed_animate() {
|
|
301
|
-
if (!this._controls) {
|
|
302
|
-
return
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (this._mixer) {
|
|
306
|
-
this._mixer.update(this._clock!.getDelta())
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
this._controls.update()
|
|
310
|
-
|
|
311
|
-
if (this.state.autoRotate) {
|
|
312
|
-
this.invalidate()
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
this.render_threed()
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
stop() {}
|
|
319
|
-
|
|
320
|
-
get scene3d() {
|
|
321
|
-
if (!this._scene3d) {
|
|
322
|
-
this.init_scene3d()
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return this._scene3d
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
get renderer3d() {
|
|
329
|
-
return this._renderer3d
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
get mixer() {
|
|
333
|
-
return this._mixer
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
get zoom() {
|
|
337
|
-
return this._camera?.zoom
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* CSS3DRenderer용 THREE.Scene을 제공
|
|
342
|
-
*/
|
|
343
|
-
get css3DScene() {
|
|
344
|
-
if (!this._css3DScene) {
|
|
345
|
-
this._css3DScene = this.buildCSS3DScene()
|
|
346
|
-
}
|
|
347
|
-
return this._css3DScene
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
protected buildCSS3DScene() {
|
|
351
|
-
return new THREE.Scene()
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
protected disposeCSS3DScene() {
|
|
355
|
-
var children = [...this.css3DScene.children]
|
|
356
|
-
children.forEach(child => this.css3DScene.remove(child))
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/* css3d-renderer */
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* css3d-renderer getter
|
|
363
|
-
*/
|
|
364
|
-
get css3DRenderer() {
|
|
365
|
-
if (!this._css3DRenderer) {
|
|
366
|
-
this._css3DRenderer = this.createCSS3DRenderer()
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return this._css3DRenderer
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
protected createCSS3DRenderer() {
|
|
373
|
-
var renderer = new CSS3DRenderer()
|
|
374
|
-
var div = renderer.domElement
|
|
375
|
-
div.style.position = 'absolute'
|
|
376
|
-
div.style.top = '0'
|
|
377
|
-
div.style.pointerEvents = 'none'
|
|
378
|
-
div.setAttribute('scene', 'three-container:css3d-renderer')
|
|
379
|
-
|
|
380
|
-
if (this.app.isViewMode) {
|
|
381
|
-
// disableAllUserEvents(div)
|
|
382
|
-
} else {
|
|
383
|
-
div.style.pointerEvents = 'none'
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return renderer
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
protected disposeCSS3DRenderer() {
|
|
390
|
-
// Nothing to do
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* element내부에 필요한 overlay들을 생성
|
|
395
|
-
* ViewRenderer에서는 CSS3DRenderer와 GLRendering을 위한 canvas를 오버레이로 만든다.
|
|
396
|
-
* Warn: this.element는 아직 만들어지지 않은 상태에 buildOverlays가 호출됨.
|
|
397
|
-
* @param into
|
|
398
|
-
*/
|
|
399
|
-
buildOverlays() {
|
|
400
|
-
this.element.appendChild(this.css3DRenderer.domElement)
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
render_threed() {
|
|
404
|
-
if (this.composer) {
|
|
405
|
-
this.composer.render()
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/* Container Overides .. */
|
|
410
|
-
render(ctx: CanvasRenderingContext2D) {
|
|
411
|
-
if (this.app.isViewMode) {
|
|
412
|
-
this.setState('threed', true)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
if (this.state.threed && !this._noSupportWebgl && this._camera) {
|
|
416
|
-
this.css3DRenderer.render(this.css3DScene, this._camera!)
|
|
417
|
-
return
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
super.render(ctx)
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
postrender(ctx: CanvasRenderingContext2D) {
|
|
424
|
-
var { left, top, debug, threed } = this.state
|
|
425
|
-
|
|
426
|
-
var { width, height } = this.bounds
|
|
427
|
-
|
|
428
|
-
// ios에서 width, height에 소수점이 있으면 3d를 표현하지 못하는 문제가 있어 정수화
|
|
429
|
-
width = Math.floor(width)
|
|
430
|
-
height = Math.floor(height)
|
|
431
|
-
|
|
432
|
-
if (threed) {
|
|
433
|
-
if (!this._scene3d) {
|
|
434
|
-
this.init_scene3d()
|
|
435
|
-
this.render_threed()
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (this._noSupportWebgl) {
|
|
439
|
-
this._showWebglNoSupportText(ctx)
|
|
440
|
-
return
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (!this._renderer3d) {
|
|
444
|
-
return
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
var { width: rendererWidth, height: rendererHeight } = this._renderer3d.getSize(new THREE.Vector2())
|
|
448
|
-
|
|
449
|
-
ctx.drawImage(this._renderer3d.domElement, 0, 0, rendererWidth, rendererHeight, left, top, width, height)
|
|
450
|
-
|
|
451
|
-
if (debug) {
|
|
452
|
-
ctx.font = 100 + 'px Arial'
|
|
453
|
-
ctx.textAlign = 'center'
|
|
454
|
-
ctx.fillStyle = 'black'
|
|
455
|
-
ctx.globalAlpha = 0.5
|
|
456
|
-
ctx.fillText(String(FPS()), 100, 100)
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
super.postrender(ctx)
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
dispose() {
|
|
464
|
-
this.root.off('redraw', this.onredraw, this)
|
|
465
|
-
|
|
466
|
-
this.disposeCSS3DScene()
|
|
467
|
-
|
|
468
|
-
this.composer?.dispose()
|
|
469
|
-
this.destroy_scene3d()
|
|
470
|
-
|
|
471
|
-
super.dispose()
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
get layout() {
|
|
475
|
-
return Layout.get('three')
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
get nature(): ComponentNature {
|
|
479
|
-
return NATURE
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
getObjectByRaycast(): THREE.Object3D | undefined {
|
|
483
|
-
var intersects = this.getObjectsByRaycast()
|
|
484
|
-
|
|
485
|
-
if (intersects && intersects.length > 0) {
|
|
486
|
-
var object: THREE.Object3D | null = intersects[0].object
|
|
487
|
-
while (object) {
|
|
488
|
-
if (object.userData.context) {
|
|
489
|
-
return object
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
object = object.parent
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
getObjectsByRaycast() {
|
|
498
|
-
var vector = this._mouse
|
|
499
|
-
if (!this._camera) {
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
this._raycaster.setFromCamera(vector!, this._camera)
|
|
504
|
-
|
|
505
|
-
var intersects = this._raycaster.intersectObjects(this._scene3d!.children, true)
|
|
506
|
-
|
|
507
|
-
return intersects
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
_showWebglNoSupportText(context: CanvasRenderingContext2D) {
|
|
511
|
-
context.save()
|
|
512
|
-
|
|
513
|
-
var { width, height } = this.state
|
|
514
|
-
|
|
515
|
-
context.font = width / 20 + 'px Arial'
|
|
516
|
-
context.textAlign = 'center'
|
|
517
|
-
context.fillText(WEBGL_NO_SUPPORT_TEXT, width / 2 - width / 40, height / 2)
|
|
518
|
-
|
|
519
|
-
context.restore()
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/* Event Handlers */
|
|
523
|
-
|
|
524
|
-
onchange(after: Properties, before: Properties) {
|
|
525
|
-
if (after.hasOwnProperty('width') || after.hasOwnProperty('height') || after.hasOwnProperty('threed'))
|
|
526
|
-
this.destroy_scene3d()
|
|
527
|
-
|
|
528
|
-
if (after.hasOwnProperty('autoRotate')) {
|
|
529
|
-
if (this._controls) {
|
|
530
|
-
this._controls.doAutoRotate(after.autoRotate)
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
if (
|
|
535
|
-
after.hasOwnProperty('fov') ||
|
|
536
|
-
after.hasOwnProperty('near') ||
|
|
537
|
-
after.hasOwnProperty('far') ||
|
|
538
|
-
after.hasOwnProperty('zoom')
|
|
539
|
-
) {
|
|
540
|
-
if (this._camera) {
|
|
541
|
-
const { near, far, zoom, fov } = this.state
|
|
542
|
-
|
|
543
|
-
this._camera.near = near
|
|
544
|
-
this._camera.far = far
|
|
545
|
-
this._camera.zoom = zoom * 0.01
|
|
546
|
-
this._camera.fov = fov
|
|
547
|
-
this._camera.updateProjectionMatrix()
|
|
548
|
-
|
|
549
|
-
this._controls.cameraChanged = true
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
onmousedown(e: MouseEvent) {
|
|
555
|
-
if (this._controls) {
|
|
556
|
-
this._controls.onMouseDown(e)
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
onmouseup(e: MouseEvent) {
|
|
561
|
-
if (this._controls) {
|
|
562
|
-
if (this._lastFocused) {
|
|
563
|
-
;(this._lastFocused as any)._focused = false
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
const { left, top, width, height } = this.state
|
|
567
|
-
|
|
568
|
-
var pointer = this.transcoordC2S(e.offsetX, e.offsetY)
|
|
569
|
-
|
|
570
|
-
this._mouse!.x = ((pointer.x - left) / width) * 2 - 1
|
|
571
|
-
this._mouse!.y = -((pointer.y - top) / height) * 2 + 1
|
|
572
|
-
|
|
573
|
-
var object = this.getObjectByRaycast()
|
|
574
|
-
var realObject = object?.userData.context as RealObject
|
|
575
|
-
|
|
576
|
-
if (realObject) {
|
|
577
|
-
;(realObject as any)._focused = true
|
|
578
|
-
;(realObject as any)._focusedAt = performance.now()
|
|
579
|
-
this._lastFocused = realObject
|
|
580
|
-
realObject.component?.trigger('click', e)
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
e.stopPropagation()
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
onmousemove(e: MouseEvent) {
|
|
588
|
-
if (this._controls) {
|
|
589
|
-
const { left, top, width, height } = this.state
|
|
590
|
-
|
|
591
|
-
var pointer = this.transcoordC2S(e.offsetX, e.offsetY)
|
|
592
|
-
|
|
593
|
-
this._mouse!.x = ((pointer.x - left) / width) * 2 - 1
|
|
594
|
-
this._mouse!.y = -((pointer.y - top) / height) * 2 + 1
|
|
595
|
-
|
|
596
|
-
var object = this.getObjectByRaycast()
|
|
597
|
-
var realObject = object?.userData.context as RealObject
|
|
598
|
-
|
|
599
|
-
if (realObject !== this._lastHovered) {
|
|
600
|
-
if (this._lastHovered) {
|
|
601
|
-
this._lastHovered.component?.trigger('mouseleave', e)
|
|
602
|
-
delete this._lastHovered
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
if (realObject) {
|
|
606
|
-
this._lastHovered = realObject
|
|
607
|
-
this._lastHovered.component?.trigger('mouseenter', e)
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
this._controls.onMouseMove(e)
|
|
612
|
-
|
|
613
|
-
e.stopPropagation()
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
onmouseleave(e: MouseEvent) {}
|
|
618
|
-
|
|
619
|
-
onwheel(e: WheelEvent) {
|
|
620
|
-
if (this._controls) {
|
|
621
|
-
this.handleMouseWheel(e)
|
|
622
|
-
e.stopPropagation()
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
ondblclick(e: MouseEvent) {
|
|
627
|
-
if (this._controls) {
|
|
628
|
-
this.setState('zoom', this.getState('zoom'))
|
|
629
|
-
this._controls.reset()
|
|
630
|
-
e.stopPropagation()
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
ondragstart(e: DragEvent) {
|
|
635
|
-
if (this._controls) {
|
|
636
|
-
var pointer = this.transcoordC2S(e.offsetX, e.offsetY)
|
|
637
|
-
var { left, top, width, height } = this.bounds
|
|
638
|
-
|
|
639
|
-
this._mouse!.x = ((pointer.x - left) / width) * 2 - 1
|
|
640
|
-
this._mouse!.y = -((pointer.y - top) / height) * 2 + 1
|
|
641
|
-
|
|
642
|
-
this._controls.onDragStart(e)
|
|
643
|
-
e.stopPropagation()
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
ondragmove(e: DragEvent) {
|
|
648
|
-
if (this._controls) {
|
|
649
|
-
this._controls.cameraChanged = true
|
|
650
|
-
this._controls.onDragMove(e)
|
|
651
|
-
e.stopPropagation()
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
ondragend(e: DragEvent) {
|
|
656
|
-
if (this._controls) {
|
|
657
|
-
this._controls.cameraChanged = true
|
|
658
|
-
this._controls.onDragEnd(e)
|
|
659
|
-
e.stopPropagation()
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
ontouchstart(e: TouchEvent) {
|
|
664
|
-
if (this._controls) {
|
|
665
|
-
this._controls.onTouchStart(e)
|
|
666
|
-
e.stopPropagation()
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
onpan(e: TouchEvent) {
|
|
671
|
-
if (this._controls) {
|
|
672
|
-
this._controls.cameraChanged = true
|
|
673
|
-
this._controls.onTouchMove(e)
|
|
674
|
-
e.stopPropagation()
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
ontouchend(e: TouchEvent) {
|
|
678
|
-
if (this._controls) {
|
|
679
|
-
this._controls.onTouchEnd(e)
|
|
680
|
-
e.stopPropagation()
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
onkeydown(e: KeyboardEvent) {
|
|
685
|
-
if (this._controls) {
|
|
686
|
-
this._controls.onKeyDown(e)
|
|
687
|
-
e.stopPropagation()
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
onpinch(e: TouchEvent) {
|
|
692
|
-
if (this._controls) {
|
|
693
|
-
var zoom = this.getState('zoom')
|
|
694
|
-
//@ts-ignore
|
|
695
|
-
zoom *= e.scale
|
|
696
|
-
|
|
697
|
-
if (zoom < 100) zoom = 100
|
|
698
|
-
|
|
699
|
-
this.setState('zoom', zoom)
|
|
700
|
-
e.stopPropagation()
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
ondoubletap() {
|
|
705
|
-
this._controls.reset()
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
handleMouseWheel(event: WheelEvent) {
|
|
709
|
-
var delta = 0
|
|
710
|
-
var zoom = this.getState('zoom')
|
|
711
|
-
|
|
712
|
-
delta = -event.deltaY
|
|
713
|
-
zoom += delta * 0.1
|
|
714
|
-
if (zoom < 100) zoom = 100
|
|
715
|
-
|
|
716
|
-
this.setState('zoom', zoom)
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
onredraw() {
|
|
720
|
-
this.threed_animate()
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
Component.register('3d-container', ThreeContainer)
|