@vyr/three-remote 0.0.33 → 0.0.36
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 +1 -1
- package/src/Cache.ts +17 -21
- package/src/ChangeScriptable.ts +16 -12
- package/src/RemoteExecutor.ts +57 -73
- package/src/index.ts +1 -2
- package/src/locale/Language.ts +1 -5
- package/src/locale/LanguageProvider.ts +2 -7
- package/src/utils/flyto.ts +21 -19
- package/src/utils/index.ts +16 -30
- package/src/utils/update.ts +22 -24
package/package.json
CHANGED
package/src/Cache.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Camera, Asset } from "@vyr/engine"
|
|
2
2
|
import { Collection } from "@vyr/remote"
|
|
3
|
-
import {
|
|
3
|
+
import { AmbientLight, BoxGeometry, DirectionalLight, Light, MeshBasicMaterial, PerspectiveCamera, PlaneGeometry, SphereGeometry } from "@vyr/three"
|
|
4
4
|
|
|
5
|
-
class Cache {
|
|
6
|
-
private _camera:
|
|
5
|
+
export class Cache {
|
|
6
|
+
private _camera: Camera | null = null
|
|
7
7
|
get camera() {
|
|
8
8
|
if (this._camera === null) {
|
|
9
|
-
this._camera = new
|
|
9
|
+
this._camera = new PerspectiveCamera()
|
|
10
10
|
}
|
|
11
11
|
return this._camera
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
private _light:
|
|
14
|
+
private _light: Light | null = null
|
|
15
15
|
get light() {
|
|
16
16
|
if (this._light === null) {
|
|
17
|
-
this._light = new
|
|
18
|
-
this._light.add(new
|
|
17
|
+
this._light = new AmbientLight({ color: '#2d2d2d' })
|
|
18
|
+
this._light.add(new DirectionalLight({ position: { x: -100, y: 100, z: 0 } }))
|
|
19
19
|
}
|
|
20
20
|
return this._light
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
readonly materialUrl = Asset.createVirtualUrl('remote/asset/material/basic.material.json')
|
|
24
|
-
private _material:
|
|
24
|
+
private _material: MeshBasicMaterial | null = null
|
|
25
25
|
get material() {
|
|
26
26
|
if (this._material === null) {
|
|
27
|
-
this._material = new
|
|
27
|
+
this._material = new MeshBasicMaterial()
|
|
28
28
|
}
|
|
29
29
|
return this._material
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
readonly boxUrl = Asset.createVirtualUrl('remote/asset/material/box.geometry.json')
|
|
33
|
-
private _box:
|
|
33
|
+
private _box: BoxGeometry | null = null
|
|
34
34
|
get box() {
|
|
35
35
|
if (this._box === null) {
|
|
36
|
-
this._box = new
|
|
36
|
+
this._box = new BoxGeometry()
|
|
37
37
|
}
|
|
38
38
|
return this._box
|
|
39
39
|
}
|
|
40
40
|
readonly sphereUrl = Asset.createVirtualUrl('remote/asset/material/sphere.geometry.json')
|
|
41
|
-
private _sphere:
|
|
41
|
+
private _sphere: SphereGeometry | null = null
|
|
42
42
|
get sphere() {
|
|
43
43
|
if (this._sphere === null) {
|
|
44
|
-
this._sphere = new
|
|
44
|
+
this._sphere = new SphereGeometry()
|
|
45
45
|
}
|
|
46
46
|
return this._sphere
|
|
47
47
|
}
|
|
48
48
|
readonly planeUrl = Asset.createVirtualUrl('remote/asset/material/plane.geometry.json')
|
|
49
|
-
private _plane:
|
|
49
|
+
private _plane: PlaneGeometry | null = null
|
|
50
50
|
get plane() {
|
|
51
51
|
if (this._plane === null) {
|
|
52
|
-
this._plane = new
|
|
52
|
+
this._plane = new PlaneGeometry()
|
|
53
53
|
}
|
|
54
54
|
return this._plane
|
|
55
55
|
}
|
|
@@ -58,8 +58,4 @@ class Cache {
|
|
|
58
58
|
transformCollection = new Collection()
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const cache = new Cache()
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
cache
|
|
65
|
-
}
|
|
61
|
+
export const cache = new Cache()
|
package/src/ChangeScriptable.ts
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { Descriptor, Graphics, Scriptable, traceService } from "@vyr/engine";
|
|
3
3
|
import { RemoteProcess, Job } from '@vyr/remote'
|
|
4
4
|
import { cache } from "./Cache"
|
|
5
|
+
import { getTransformEvent } from "./utils";
|
|
5
6
|
|
|
6
|
-
class ChangeScriptable extends Scriptable {
|
|
7
|
-
|
|
7
|
+
export class ChangeScriptable extends Scriptable {
|
|
8
|
+
static id = getTransformEvent()
|
|
9
|
+
static inputSchame = z.object({
|
|
10
|
+
type: z.enum(['mousedown', 'mouseup', 'change']),
|
|
11
|
+
target: z.string(),
|
|
12
|
+
})
|
|
13
|
+
execute(graphics: Graphics, trigger: string, input: z.infer<ChangeScriptable['inputSchame']>) {
|
|
8
14
|
const process = RemoteProcess.get(graphics.engine)
|
|
9
15
|
if (process === null) return
|
|
10
16
|
|
|
11
|
-
const target = Descriptor.get(
|
|
12
|
-
const service =
|
|
17
|
+
const target = Descriptor.get(input.target) as Descriptor
|
|
18
|
+
const service = traceService(target)
|
|
13
19
|
if (service) {
|
|
14
20
|
const orbit = cache.orbitCollection.get(service)
|
|
15
21
|
if (orbit) {
|
|
16
|
-
if (
|
|
22
|
+
if (input.type === 'mousedown') {
|
|
17
23
|
orbit.enabled = false
|
|
18
|
-
} else if (
|
|
24
|
+
} else if (input.type === 'mouseup') {
|
|
19
25
|
orbit.enabled = true
|
|
20
26
|
}
|
|
21
27
|
orbit.setNeedsUpdate()
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
const params = { eventType:
|
|
31
|
+
const params = { eventType: input.type, target: input.target, descriptor: target.clone(false) }
|
|
26
32
|
process.bridge.send(new Job.invoke.transform.Response(params))
|
|
27
33
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default ChangeScriptable
|
|
34
|
+
}
|
package/src/RemoteExecutor.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { Asset, Descriptor, DeserializationObject,
|
|
2
|
-
import {
|
|
1
|
+
import { Asset, Descriptor, DeserializationObject, Node, Service, Scene, Unit, Vector3 as _V3, traceService, isHTML, Scriptable } from '@vyr/engine'
|
|
2
|
+
import { Mesh, NodeActor, OrbitControllerActor, OrbitController, Particle, PerspectiveCamera, Points, PointsMaterial, Scene3DService, Sprite, SpriteMaterial, Texture, TransformController, THREE, geometry, material } from '@vyr/three'
|
|
3
3
|
import { RemoteExecutor as _RemoteExecutor, Job, RemoteProcess } from '@vyr/remote'
|
|
4
|
-
import { checkParentValidity, flyTo, getControllerByService, getGraphics, getTransformEvent, lookAt, resize,
|
|
4
|
+
import { checkParentValidity, flyTo, getControllerByService, getGraphics, getTransformEvent, lookAt, resize, updateModelByScene, updateOtherUpdateJob } from './utils'
|
|
5
5
|
import { cache } from './Cache'
|
|
6
6
|
|
|
7
|
-
class RemoteExecutor extends _RemoteExecutor {
|
|
7
|
+
export class RemoteExecutor extends _RemoteExecutor {
|
|
8
8
|
async loadByAsset(task: InstanceType<typeof Job['asset']['load']['Task']>) {
|
|
9
9
|
await super.loadByAsset(task)
|
|
10
10
|
if (this.process.config.invoke) {
|
|
11
|
-
flyTo(this.process.
|
|
12
|
-
|
|
11
|
+
flyTo(this.process.scene.uuid, this.process)
|
|
12
|
+
updateModelByScene(this.process.scene, this.process)
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
async loadByScene(task: InstanceType<(typeof Job)['scene']['load']['Task']>) {
|
|
16
|
-
await super.loadByScene(task)
|
|
17
|
-
flyTo(this.process.scheduler.uuid, this.process)
|
|
18
|
-
updateModelByScheduler(this.process.scheduler, this.process)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
15
|
async transformByInvoke(task: InstanceType<(typeof Job)['invoke']['transform']['Task']>) {
|
|
22
16
|
const transforms = cache.transformCollection.values()
|
|
23
17
|
for (const item of transforms) {
|
|
@@ -28,19 +22,19 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
const target = Descriptor.get<Descriptor>(task.params.target)
|
|
31
|
-
let service =
|
|
25
|
+
let service = traceService(target)
|
|
32
26
|
if (service === null) return
|
|
33
27
|
|
|
34
|
-
if (target
|
|
35
|
-
if (service instanceof
|
|
28
|
+
if (isHTML(target) && checkParentValidity(target)) {
|
|
29
|
+
if (service instanceof Scene3DService) {
|
|
36
30
|
const ancestor = service.traceAncestor(false)
|
|
37
|
-
service =
|
|
31
|
+
service = traceService(ancestor.parent)
|
|
38
32
|
}
|
|
39
33
|
super.transformByInvoke(task, service)
|
|
40
34
|
} else {
|
|
41
35
|
super.clearHTMLTransform()
|
|
42
36
|
|
|
43
|
-
const transform = cache.transformCollection.get<
|
|
37
|
+
const transform = cache.transformCollection.get<TransformController>(service)
|
|
44
38
|
if (transform === null) return
|
|
45
39
|
|
|
46
40
|
const enabled = ['translate', 'rotate', 'scale'].includes(task.params.mode)
|
|
@@ -50,7 +44,7 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
50
44
|
transform.enabled = true
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
if (target instanceof
|
|
47
|
+
if (target instanceof Node) lookAt(target, this.process)
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
async orbitByInvoke(task: InstanceType<(typeof Job)['invoke']['orbit']['Task']>) {
|
|
@@ -95,7 +89,7 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
const target = Descriptor.get<Descriptor>(targetUuid)
|
|
98
|
-
if (descriptor instanceof
|
|
92
|
+
if (descriptor instanceof Node && target instanceof Node) {
|
|
99
93
|
target.position.x = descriptor.position.x
|
|
100
94
|
target.position.y = descriptor.position.y
|
|
101
95
|
target.position.z = descriptor.position.z
|
|
@@ -108,7 +102,7 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
108
102
|
target.setNeedsUpdate()
|
|
109
103
|
}
|
|
110
104
|
|
|
111
|
-
if (descriptor instanceof
|
|
105
|
+
if (descriptor instanceof PerspectiveCamera) {
|
|
112
106
|
const controller = getControllerByService(descriptor)
|
|
113
107
|
if (controller === null || controller.orbit === null) return
|
|
114
108
|
const interpreter = graphics.getInterpreter(descriptor)
|
|
@@ -138,17 +132,17 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
resetTransformByRemoveJob(target: Descriptor) {
|
|
141
|
-
let service =
|
|
135
|
+
let service = traceService(target)
|
|
142
136
|
if (service === null) return
|
|
143
137
|
|
|
144
|
-
if (target
|
|
145
|
-
if (service instanceof
|
|
138
|
+
if (isHTML(target)) {
|
|
139
|
+
if (service instanceof Scene3DService) {
|
|
146
140
|
const ancestor = service.traceAncestor(false)
|
|
147
|
-
service =
|
|
141
|
+
service = traceService(ancestor.parent)
|
|
148
142
|
}
|
|
149
143
|
super.resetTransformByRemoveJob(target, service)
|
|
150
144
|
} else {
|
|
151
|
-
const transform = cache.transformCollection.get<
|
|
145
|
+
const transform = cache.transformCollection.get<TransformController>(service)
|
|
152
146
|
if (transform === null) return
|
|
153
147
|
|
|
154
148
|
if (transform.target === target.uuid) {
|
|
@@ -159,12 +153,12 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
159
153
|
}
|
|
160
154
|
}
|
|
161
155
|
updateOtherUpdateJob(target: Descriptor, deserialization: DeserializationObject<Descriptor>) {
|
|
162
|
-
let service =
|
|
156
|
+
let service = traceService(target)
|
|
163
157
|
|
|
164
|
-
if (target
|
|
165
|
-
if (service instanceof
|
|
158
|
+
if (isHTML(target)) {
|
|
159
|
+
if (service instanceof Scene3DService) {
|
|
166
160
|
const ancestor = service.traceAncestor(false)
|
|
167
|
-
service =
|
|
161
|
+
service = traceService(ancestor.parent)
|
|
168
162
|
}
|
|
169
163
|
super.updateOtherUpdateJob(target, deserialization, service)
|
|
170
164
|
} else {
|
|
@@ -174,15 +168,15 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
174
168
|
|
|
175
169
|
protected getRenderObject(url: string, descriptor: Descriptor) {
|
|
176
170
|
cache.material.map = ''
|
|
177
|
-
const mesh = new
|
|
178
|
-
if (descriptor
|
|
179
|
-
let target: (
|
|
180
|
-
if (descriptor instanceof
|
|
181
|
-
target = new
|
|
171
|
+
const mesh = new Mesh()
|
|
172
|
+
if (material.isMaterial(descriptor)) {
|
|
173
|
+
let target: (Mesh | Sprite | Points | Particle) = mesh
|
|
174
|
+
if (descriptor instanceof PointsMaterial) {
|
|
175
|
+
target = new Points()
|
|
182
176
|
target.geometry = cache.sphereUrl
|
|
183
177
|
Asset.set(cache.sphereUrl, cache.sphere)
|
|
184
|
-
} else if (descriptor instanceof
|
|
185
|
-
target = new
|
|
178
|
+
} else if (descriptor instanceof SpriteMaterial) {
|
|
179
|
+
target = new Sprite()
|
|
186
180
|
} else {
|
|
187
181
|
target.geometry = cache.boxUrl
|
|
188
182
|
Asset.set(cache.boxUrl, cache.box)
|
|
@@ -190,11 +184,11 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
190
184
|
|
|
191
185
|
target.material = url
|
|
192
186
|
return target
|
|
193
|
-
} else if (descriptor
|
|
187
|
+
} else if (geometry.isGeometry(descriptor)) {
|
|
194
188
|
mesh.material = cache.materialUrl
|
|
195
189
|
mesh.geometry = url
|
|
196
190
|
Asset.set(cache.materialUrl, cache.material)
|
|
197
|
-
} else if (descriptor instanceof
|
|
191
|
+
} else if (descriptor instanceof Texture) {
|
|
198
192
|
cache.material.map = url
|
|
199
193
|
mesh.material = cache.materialUrl
|
|
200
194
|
mesh.geometry = cache.planeUrl
|
|
@@ -203,94 +197,84 @@ class RemoteExecutor extends _RemoteExecutor {
|
|
|
203
197
|
}
|
|
204
198
|
return mesh
|
|
205
199
|
}
|
|
206
|
-
onLoadAsset(url: string, descriptor: Descriptor,
|
|
207
|
-
super.onLoadAsset(url, descriptor,
|
|
208
|
-
if (descriptor
|
|
200
|
+
onLoadAsset(url: string, descriptor: Descriptor, scene: Scene) {
|
|
201
|
+
super.onLoadAsset(url, descriptor, scene)
|
|
202
|
+
if (isHTML(descriptor)) {
|
|
209
203
|
return
|
|
210
|
-
} else if (descriptor instanceof
|
|
211
|
-
const service = new
|
|
204
|
+
} else if (descriptor instanceof Node) {
|
|
205
|
+
const service = new Scene3DService()
|
|
212
206
|
service.add(descriptor)
|
|
213
207
|
service.add(cache.light)
|
|
214
|
-
|
|
215
|
-
} else if (descriptor instanceof PrefabeDescriptor && descriptor.category === 'scene') {
|
|
216
|
-
const service = new SceneServiceDescriptor()
|
|
217
|
-
service.add(descriptor)
|
|
218
|
-
service.add(cache.light)
|
|
219
|
-
scheduler.add(service)
|
|
208
|
+
scene.add(service)
|
|
220
209
|
} else {
|
|
221
|
-
const service = new
|
|
210
|
+
const service = new Scene3DService()
|
|
222
211
|
service.add(this.getRenderObject(url, descriptor))
|
|
223
212
|
service.add(cache.light)
|
|
224
|
-
|
|
213
|
+
scene.add(service)
|
|
225
214
|
}
|
|
226
215
|
}
|
|
227
|
-
onAddService(service:
|
|
216
|
+
onAddService(service: Service) {
|
|
228
217
|
super.onAddService(service)
|
|
229
|
-
if (service instanceof
|
|
218
|
+
if (service instanceof Scene3DService) {
|
|
230
219
|
let transform = cache.transformCollection.get(service)
|
|
231
220
|
if (transform == null) {
|
|
232
|
-
transform = new
|
|
221
|
+
transform = new TransformController({ enabled: false, selectable: false })
|
|
233
222
|
cache.transformCollection.set(service, transform)
|
|
234
223
|
transform.camera = cache.camera.uuid
|
|
235
224
|
transform.event = getTransformEvent()
|
|
236
225
|
}
|
|
237
|
-
service.add(transform as
|
|
226
|
+
service.add(transform as TransformController)
|
|
238
227
|
|
|
239
228
|
let orbit = cache.orbitCollection.get(service)
|
|
240
229
|
if (orbit === null) {
|
|
241
|
-
orbit = new
|
|
230
|
+
orbit = new OrbitController({ enabled: true, selectable: false, draggingSmoothTime: 0, smoothTime: 0, restThreshold: 0, dollyToCursor: false })
|
|
242
231
|
cache.orbitCollection.set(service, orbit)
|
|
243
232
|
orbit.camera = cache.camera.uuid
|
|
244
233
|
}
|
|
245
|
-
service.add(orbit as
|
|
234
|
+
service.add(orbit as OrbitController)
|
|
246
235
|
}
|
|
247
236
|
}
|
|
248
|
-
onRemoveService(service:
|
|
237
|
+
onRemoveService(service: Service) {
|
|
249
238
|
super.onRemoveService(service)
|
|
250
|
-
if (service instanceof
|
|
251
|
-
const transform = cache.transformCollection.get<
|
|
239
|
+
if (service instanceof Scene3DService) {
|
|
240
|
+
const transform = cache.transformCollection.get<TransformController>(service)
|
|
252
241
|
if (transform !== null) {
|
|
253
242
|
cache.transformCollection.delete(service)
|
|
254
243
|
service.remove(transform)
|
|
255
244
|
}
|
|
256
245
|
|
|
257
|
-
const orbit = cache.orbitCollection.get<
|
|
246
|
+
const orbit = cache.orbitCollection.get<OrbitController>(service)
|
|
258
247
|
if (orbit !== null) {
|
|
259
248
|
cache.orbitCollection.delete(service)
|
|
260
249
|
service.remove(orbit)
|
|
261
250
|
}
|
|
262
251
|
}
|
|
263
252
|
}
|
|
264
|
-
|
|
253
|
+
onUpdateScene(unit: Unit) {
|
|
265
254
|
const descriptor = Descriptor.get<Descriptor>(unit.uuid)
|
|
266
|
-
const service = cache.transformCollection.getByMap<
|
|
267
|
-
?? cache.orbitCollection.getByMap<
|
|
255
|
+
const service = cache.transformCollection.getByMap<TransformController>(descriptor)
|
|
256
|
+
?? cache.orbitCollection.getByMap<OrbitController>(descriptor)
|
|
268
257
|
|
|
269
258
|
if (service !== null) {
|
|
270
259
|
//@ts-ignore
|
|
271
260
|
window['__VYR_RUNTIME.DISABLED_INPUT'] = false
|
|
272
261
|
}
|
|
273
262
|
|
|
274
|
-
super.
|
|
263
|
+
super.onUpdateScene(unit)
|
|
275
264
|
}
|
|
276
265
|
|
|
277
266
|
enhance(process: RemoteProcess) {
|
|
278
267
|
super.enhance(process, (graphics) => {
|
|
279
|
-
Object.defineProperty(graphics.
|
|
268
|
+
Object.defineProperty(graphics.scene, 'camera', { get() { return cache.camera.uuid }, set() { } })
|
|
280
269
|
})
|
|
281
270
|
}
|
|
282
271
|
|
|
283
272
|
async listen() {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
Asset.load(transformEvent)
|
|
273
|
+
const { ChangeScriptable } = await import('./ChangeScriptable')
|
|
274
|
+
Scriptable.register(ChangeScriptable)
|
|
287
275
|
|
|
288
276
|
window.addEventListener('resize', resize(this.process))
|
|
289
277
|
|
|
290
278
|
await super.listen()
|
|
291
279
|
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export {
|
|
295
|
-
RemoteExecutor
|
|
296
280
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RemoteProcess } from '@vyr/remote'
|
|
2
2
|
import { RemoteExecutor } from './RemoteExecutor'
|
|
3
3
|
|
|
4
|
-
const setup = (process: RemoteProcess) => {
|
|
4
|
+
export const setup = (process: RemoteProcess) => {
|
|
5
5
|
process.setExecutor(new RemoteExecutor(process))
|
|
6
6
|
}
|
|
7
7
|
RemoteProcess.register(setup)
|
|
8
8
|
|
|
9
|
-
export { setup }
|
|
10
9
|
export * from './locale'
|
package/src/locale/Language.ts
CHANGED
|
@@ -3,8 +3,4 @@ import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
|
|
|
3
3
|
|
|
4
4
|
Locale.register(zhCnLanguageProvider)
|
|
5
5
|
|
|
6
|
-
const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
language
|
|
10
|
-
}
|
|
6
|
+
export const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { LanguageProvider } from '@vyr/locale'
|
|
2
2
|
|
|
3
|
-
interface ZhCNLanguageProvider extends LanguageProvider {
|
|
3
|
+
export interface ZhCNLanguageProvider extends LanguageProvider {
|
|
4
4
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
7
|
+
export const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
8
8
|
id: 'zh_CN',
|
|
9
9
|
name: '@vyr/three-remote',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
ZhCNLanguageProvider,
|
|
14
|
-
zhCnLanguageProvider,
|
|
15
10
|
}
|
package/src/utils/flyto.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NodeActor, OrbitControllerActor,
|
|
1
|
+
import { Camera, Graphics, Descriptor, Node, Scene, isService, traceService, Vector3 as _V3 } from "@vyr/engine"
|
|
2
|
+
import { NodeActor, OrbitControllerActor, OrbitController, TransformController, THREE } from "@vyr/three"
|
|
3
3
|
import { RemoteProcess } from "@vyr/remote"
|
|
4
4
|
import { cache } from "../Cache"
|
|
5
5
|
|
|
6
6
|
const rawVector3 = new THREE.Vector3(0, 0, 0)
|
|
7
7
|
const emptyBox = new THREE.Box3()
|
|
8
|
-
const getBox3 = (descriptor: Descriptor, graphics: Graphics) => {
|
|
8
|
+
export const getBox3 = (descriptor: Descriptor, graphics: Graphics) => {
|
|
9
9
|
const box3 = new THREE.Box3()
|
|
10
10
|
// const ignore: Descriptor[] = []
|
|
11
11
|
// if (instance) ignore.push(instance.orbit, instance.transform)
|
|
@@ -19,16 +19,18 @@ const getBox3 = (descriptor: Descriptor, graphics: Graphics) => {
|
|
|
19
19
|
}, true)
|
|
20
20
|
return box3
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
22
|
+
|
|
23
|
+
export const getControllerByService = (target: Descriptor) => {
|
|
24
|
+
const service = traceService(target)
|
|
25
|
+
if (isService(service)) {
|
|
26
|
+
const orbit = cache.orbitCollection.get<OrbitController>(service)
|
|
27
|
+
const transform = cache.transformCollection.get<TransformController>(service)
|
|
27
28
|
return { transform, orbit }
|
|
28
29
|
}
|
|
29
30
|
return null
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
|
|
33
|
+
export const getFlyInfo = (descriptor: Descriptor, graphics: Graphics) => {
|
|
32
34
|
const box3 = getBox3(descriptor, graphics)
|
|
33
35
|
|
|
34
36
|
if (box3.equals(emptyBox)) return null
|
|
@@ -53,7 +55,8 @@ const getFlyInfo = (descriptor: Descriptor, graphics: Graphics) => {
|
|
|
53
55
|
lookAt: sphere.center
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
export const flyToTarget = (descriptor: Descriptor, graphics: Graphics, orbit: OrbitController | null) => {
|
|
57
60
|
const flyInfo = getFlyInfo(descriptor, graphics)
|
|
58
61
|
if (flyInfo === null) return
|
|
59
62
|
|
|
@@ -71,20 +74,21 @@ const flyToTarget = (descriptor: Descriptor, graphics: Graphics, orbit: OrbitCon
|
|
|
71
74
|
flyInfo.lookAt.z,
|
|
72
75
|
)
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
|
|
78
|
+
export const flyTo = (uuid: string, process: RemoteProcess) => {
|
|
79
|
+
const descriptor = Descriptor.get<Node>(uuid)
|
|
76
80
|
if (descriptor === null) return
|
|
77
|
-
const cameraDescriptor = Descriptor.get<
|
|
81
|
+
const cameraDescriptor = Descriptor.get<Camera>(process.scene.camera)
|
|
78
82
|
if (cameraDescriptor === null) return
|
|
79
83
|
|
|
80
84
|
const services: Descriptor[] = []
|
|
81
|
-
if (descriptor instanceof
|
|
85
|
+
if (descriptor instanceof Scene) {
|
|
82
86
|
RemoteProcess.getServices(descriptor, services)
|
|
83
|
-
} else if (descriptor
|
|
87
|
+
} else if (isService(descriptor)) {
|
|
84
88
|
services.push(descriptor)
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
const graphics = process.engine.getGraphics(process.
|
|
91
|
+
const graphics = process.engine.getGraphics(process.scene)
|
|
88
92
|
|
|
89
93
|
if (services.length === 0) {
|
|
90
94
|
const controller = getControllerByService(descriptor)
|
|
@@ -97,6 +101,4 @@ const flyTo = (uuid: string, process: RemoteProcess) => {
|
|
|
97
101
|
flyToTarget(descriptor, graphics, controller.orbit)
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { getControllerByService, getFlyInfo, flyToTarget, flyTo }
|
|
104
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Descriptor,
|
|
1
|
+
import { Descriptor, Generate, HTML, isHTML, Node, Scene } from "@vyr/engine"
|
|
2
2
|
import { RemoteProcess } from "@vyr/remote"
|
|
3
|
-
import {
|
|
3
|
+
import { HTMLConvert, NodeActor, OrbitControllerActor, THREE } from "@vyr/three"
|
|
4
4
|
import { cache } from "../Cache"
|
|
5
5
|
import { getControllerByService, getFlyInfo } from './flyto'
|
|
6
6
|
|
|
7
7
|
let transformEvent = ''
|
|
8
|
-
const getTransformEvent = () => {
|
|
8
|
+
export const getTransformEvent = () => {
|
|
9
9
|
if (transformEvent === '') {
|
|
10
10
|
transformEvent = `TransformController/event/${Generate.uuid()}.ts`
|
|
11
11
|
}
|
|
@@ -17,45 +17,38 @@ const getParent = (descriptor: Descriptor): Descriptor | boolean | null => {
|
|
|
17
17
|
const ancestor = descriptor.traceAncestor(false)
|
|
18
18
|
if (ancestor.parent === null) {
|
|
19
19
|
return null
|
|
20
|
-
} else if (ancestor.parent
|
|
20
|
+
} else if (isHTML(ancestor.parent)) {
|
|
21
21
|
return ancestor.parent
|
|
22
|
-
} else if (ancestor.parent instanceof
|
|
23
|
-
return getParent(ancestor.parent)
|
|
24
|
-
} else if (ancestor.parent instanceof PrefabeDescriptor) {
|
|
25
|
-
const nextParent = getParent(ancestor.parent)
|
|
26
|
-
return nextParent === null ? true : nextParent
|
|
27
|
-
} else if (ancestor.parent instanceof PrefabInstanceDescriptor) {
|
|
28
|
-
return getParent(ancestor.parent)
|
|
29
|
-
} else if (ancestor.parent instanceof HTMLConvertDescriptor) {
|
|
22
|
+
} else if (ancestor.parent instanceof HTMLConvert) {
|
|
30
23
|
return null
|
|
31
|
-
} else if (ancestor.parent instanceof
|
|
24
|
+
} else if (ancestor.parent instanceof Node) {
|
|
32
25
|
return ancestor.parent
|
|
33
26
|
} else {
|
|
34
27
|
return null
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
|
-
const checkParentValidity = (html:
|
|
30
|
+
export const checkParentValidity = (html: HTML) => {
|
|
38
31
|
const parent = getParent(html)
|
|
39
32
|
if (parent === null) {
|
|
40
33
|
return false
|
|
41
|
-
} else if (parent
|
|
34
|
+
} else if (isHTML(parent)) {
|
|
42
35
|
return true
|
|
43
|
-
} else if (parent instanceof
|
|
36
|
+
} else if (parent instanceof Node) {
|
|
44
37
|
return false
|
|
45
38
|
} else {
|
|
46
39
|
return true
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
const getGraphics = (descriptor: Descriptor, process: RemoteProcess) => {
|
|
43
|
+
export const getGraphics = (descriptor: Descriptor, process: RemoteProcess) => {
|
|
51
44
|
const ancestor = descriptor.traceAncestor(true)
|
|
52
|
-
const
|
|
53
|
-
return
|
|
45
|
+
const scene = ancestor.collection[ancestor.collection.length - 1] as Scene
|
|
46
|
+
return scene instanceof Scene ? process.engine.getGraphics(scene) : null
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
const resize = (process: RemoteProcess) => {
|
|
49
|
+
export const resize = (process: RemoteProcess) => {
|
|
57
50
|
return () => {
|
|
58
|
-
const graphics = process.engine.getGraphics(process.
|
|
51
|
+
const graphics = process.engine.getGraphics(process.scene)
|
|
59
52
|
if (graphics == null) return
|
|
60
53
|
const interpreter = graphics.getInterpreter(cache.camera)
|
|
61
54
|
const actor = interpreter.getActor<NodeActor<THREE.PerspectiveCamera>>(cache.camera)
|
|
@@ -64,10 +57,10 @@ const resize = (process: RemoteProcess) => {
|
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
59
|
|
|
67
|
-
const lookAt = (target: Descriptor, process: RemoteProcess) => {
|
|
60
|
+
export const lookAt = (target: Descriptor, process: RemoteProcess) => {
|
|
68
61
|
const controller = getControllerByService(target)
|
|
69
62
|
if (controller === null) return
|
|
70
|
-
const graphics = process.engine.getGraphics(process.
|
|
63
|
+
const graphics = process.engine.getGraphics(process.scene)
|
|
71
64
|
const flyInfo = getFlyInfo(target, graphics)
|
|
72
65
|
if (flyInfo === null) return
|
|
73
66
|
if (!controller.orbit) return
|
|
@@ -80,12 +73,5 @@ const lookAt = (target: Descriptor, process: RemoteProcess) => {
|
|
|
80
73
|
)
|
|
81
74
|
}
|
|
82
75
|
|
|
83
|
-
export {
|
|
84
|
-
getTransformEvent,
|
|
85
|
-
checkParentValidity,
|
|
86
|
-
getGraphics,
|
|
87
|
-
resize,
|
|
88
|
-
lookAt,
|
|
89
|
-
}
|
|
90
76
|
export * from './update'
|
|
91
77
|
export * from './flyto'
|
package/src/utils/update.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Asset, Descriptor, DeserializationObject, observer,
|
|
2
|
-
import {
|
|
1
|
+
import { Asset, Descriptor, DeserializationObject, observer, Service, Scene } from "@vyr/engine"
|
|
2
|
+
import { Texture, TransformController, Model, AnimationAction, Scene3DService, Scene3DServiceActor, THREE } from "@vyr/three"
|
|
3
3
|
import { Job, RemoteProcess } from "@vyr/remote"
|
|
4
4
|
import { cache } from "../Cache"
|
|
5
5
|
|
|
6
|
-
const updateAnimationAction = async (uuid: string, url: string, process: RemoteProcess) => {
|
|
6
|
+
export const updateAnimationAction = async (uuid: string, url: string, process: RemoteProcess) => {
|
|
7
7
|
const animations: string[] = []
|
|
8
8
|
if (url) {
|
|
9
9
|
const currentUrl = `${url}?${uuid}`
|
|
@@ -17,10 +17,10 @@ const updateAnimationAction = async (uuid: string, url: string, process: RemoteP
|
|
|
17
17
|
process.bridge.send(new Job.invoke.animation.Response({ type: 'action', uuid: uuid, animations }))
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const updateSceneService = (target:
|
|
20
|
+
export const updateSceneService = (target: Scene3DService, deserialization: DeserializationObject<Scene3DService>, process: RemoteProcess) => {
|
|
21
21
|
if (target.shadowMapType === deserialization.shadowMapType) return
|
|
22
|
-
const graphics = process.engine.getGraphics(process.
|
|
23
|
-
const actor = graphics.getActor<
|
|
22
|
+
const graphics = process.engine.getGraphics(process.scene)
|
|
23
|
+
const actor = graphics.getActor<Scene3DServiceActor>(target)
|
|
24
24
|
if (actor === null) return
|
|
25
25
|
actor.pipeline.resetState()
|
|
26
26
|
actor.scene.traverse(sub => {
|
|
@@ -36,7 +36,7 @@ const updateSceneService = (target: SceneServiceDescriptor, deserialization: Des
|
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const updateModel = async (target:
|
|
39
|
+
export const updateModel = async (target: Model, deserialization: DeserializationObject<Model>, process: RemoteProcess) => {
|
|
40
40
|
if (target.url === deserialization.url) return
|
|
41
41
|
updateAnimationAction(target.uuid, deserialization.url, process)
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ const updateModel = async (target: ModelDescriptor, deserialization: Deserializa
|
|
|
45
45
|
await Asset.readly()
|
|
46
46
|
process.engine.listen('afterRender', () => {
|
|
47
47
|
for (const actionDescriptor of target.children) {
|
|
48
|
-
if (actionDescriptor instanceof
|
|
48
|
+
if (actionDescriptor instanceof AnimationAction) {
|
|
49
49
|
actionDescriptor.setNeedsUpdate()
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -53,17 +53,17 @@ const updateModel = async (target: ModelDescriptor, deserialization: Deserializa
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
if (sub instanceof
|
|
56
|
+
export const updateModelByScene = (scene: Scene, process: RemoteProcess) => {
|
|
57
|
+
scene.traverse(sub => {
|
|
58
|
+
if (sub instanceof Model) {
|
|
59
59
|
updateAnimationAction(sub.uuid, sub.url, process)
|
|
60
60
|
}
|
|
61
61
|
})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const updateTexture = (target:
|
|
64
|
+
export const updateTexture = (target: Texture, deserialization: DeserializationObject<Texture>, process: RemoteProcess) => {
|
|
65
65
|
if (target.url === deserialization.url) return
|
|
66
|
-
const graphics = process.engine.getGraphics(process.
|
|
66
|
+
const graphics = process.engine.getGraphics(process.scene)
|
|
67
67
|
const unit = graphics.getUnit(target.uuid)
|
|
68
68
|
if (unit === null) return
|
|
69
69
|
graphics.doFree(unit)
|
|
@@ -71,20 +71,18 @@ const updateTexture = (target: TextureDescriptor, deserialization: Deserializati
|
|
|
71
71
|
observer.trigger('updateDeps', { self: target.uuid })
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const updateOtherUpdateJob = (target: Descriptor, deserialization: DeserializationObject<Descriptor>, service:
|
|
75
|
-
if (target instanceof
|
|
76
|
-
updateTexture(target, deserialization as
|
|
77
|
-
} else if (target instanceof
|
|
78
|
-
updateModel(target, deserialization as
|
|
79
|
-
} else if (target instanceof
|
|
80
|
-
updateSceneService(target, deserialization as
|
|
74
|
+
export const updateOtherUpdateJob = (target: Descriptor, deserialization: DeserializationObject<Descriptor>, service: Service | null, process: RemoteProcess) => {
|
|
75
|
+
if (target instanceof Texture) {
|
|
76
|
+
updateTexture(target, deserialization as Texture, process)
|
|
77
|
+
} else if (target instanceof Model) {
|
|
78
|
+
updateModel(target, deserialization as Model, process)
|
|
79
|
+
} else if (target instanceof Scene3DService) {
|
|
80
|
+
updateSceneService(target, deserialization as Scene3DService, process)
|
|
81
81
|
}
|
|
82
82
|
if (service === null) return
|
|
83
|
-
const transform = cache.transformCollection.get<
|
|
83
|
+
const transform = cache.transformCollection.get<TransformController>(service)
|
|
84
84
|
if (transform === null) return
|
|
85
85
|
if (transform.target === target.uuid) {
|
|
86
86
|
process.engine.listen('afterRender', () => transform.setNeedsUpdate(), { once: true })
|
|
87
87
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { updateModelByScheduler, updateOtherUpdateJob }
|
|
88
|
+
}
|