@vyr/three 0.0.1

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.
Files changed (127) hide show
  1. package/package.json +26 -0
  2. package/src/actor/ComposerServiceActor.ts +107 -0
  3. package/src/actor/GeometryActor.ts +13 -0
  4. package/src/actor/HTMLConvertActor.ts +55 -0
  5. package/src/actor/MaterialActor.ts +13 -0
  6. package/src/actor/NodeActor.ts +25 -0
  7. package/src/actor/OrbitControllerActor.ts +110 -0
  8. package/src/actor/PassActor.ts +24 -0
  9. package/src/actor/SceneServiceActor.ts +122 -0
  10. package/src/actor/TextureActor.ts +13 -0
  11. package/src/actor/TransformControllerActor.ts +23 -0
  12. package/src/actor/index.ts +10 -0
  13. package/src/asset/index.ts +187 -0
  14. package/src/controls/CameraControls.ts +2360 -0
  15. package/src/controls/TransformControls.ts +1747 -0
  16. package/src/controls/index.ts +2 -0
  17. package/src/descriptor/ComposerServiceDescriptor.ts +47 -0
  18. package/src/descriptor/GeoMapDescriptor.ts +24 -0
  19. package/src/descriptor/HTMLConvertDescriptor.ts +12 -0
  20. package/src/descriptor/InstancedMeshDescriptor.ts +21 -0
  21. package/src/descriptor/MeshDescriptor.ts +16 -0
  22. package/src/descriptor/ModelDescriptor.ts +15 -0
  23. package/src/descriptor/OrbitControllerDescriptor.ts +84 -0
  24. package/src/descriptor/OrthographicCameraDescriptor.ts +12 -0
  25. package/src/descriptor/ParticleDescriptor.ts +88 -0
  26. package/src/descriptor/PassDescriptor.ts +33 -0
  27. package/src/descriptor/PerspectiveCameraDescriptor.ts +15 -0
  28. package/src/descriptor/PointsDescriptor.ts +16 -0
  29. package/src/descriptor/SceneServiceDescriptor.ts +39 -0
  30. package/src/descriptor/SpriteDescriptor.ts +16 -0
  31. package/src/descriptor/TextDescriptor.ts +41 -0
  32. package/src/descriptor/TransformControllerDescriptor.ts +32 -0
  33. package/src/descriptor/animation/AnimationActionDescriptor.ts +52 -0
  34. package/src/descriptor/geometry/BoxGeometryDescriptor.ts +26 -0
  35. package/src/descriptor/geometry/BufferGeometryDescriptor.ts +15 -0
  36. package/src/descriptor/geometry/CircleGeometryDescriptor.ts +22 -0
  37. package/src/descriptor/geometry/CylinderGeometryDescriptor.ts +30 -0
  38. package/src/descriptor/geometry/ExtrudeGeometryDescriptor.ts +35 -0
  39. package/src/descriptor/geometry/GeometryDescriptor.ts +8 -0
  40. package/src/descriptor/geometry/PlaneGeometryDescriptor.ts +22 -0
  41. package/src/descriptor/geometry/RingGeometryDescriptor.ts +26 -0
  42. package/src/descriptor/geometry/SphereGeometryDescriptor.ts +27 -0
  43. package/src/descriptor/geometry/SurfaceGeometryDescriptor.ts +15 -0
  44. package/src/descriptor/geometry/TubeGeometryDescriptor.ts +25 -0
  45. package/src/descriptor/helper/AxesHelperDescriptor.ts +8 -0
  46. package/src/descriptor/index.ts +45 -0
  47. package/src/descriptor/light/AmbientLightDescriptor.ts +8 -0
  48. package/src/descriptor/light/DirectionalLightDescriptor.ts +33 -0
  49. package/src/descriptor/light/HemisphereLightDescriptor.ts +16 -0
  50. package/src/descriptor/light/LightDescriptor.ts +16 -0
  51. package/src/descriptor/light/PointLightDescriptor.ts +24 -0
  52. package/src/descriptor/light/RectAreaLightDescriptor.ts +20 -0
  53. package/src/descriptor/light/SpotLightDescriptor.ts +30 -0
  54. package/src/descriptor/material/MaterialDescriptor.ts +84 -0
  55. package/src/descriptor/material/MeshBasicMaterialDescriptor.ts +53 -0
  56. package/src/descriptor/material/MeshPhongMaterialDescriptor.ts +102 -0
  57. package/src/descriptor/material/MeshStandardMaterialDescriptor.ts +99 -0
  58. package/src/descriptor/material/PointsMaterialDescriptor.ts +31 -0
  59. package/src/descriptor/material/ShaderMaterialDescriptor.ts +35 -0
  60. package/src/descriptor/material/ShadowMaterialDescriptor.ts +19 -0
  61. package/src/descriptor/material/SpriteMaterialDescriptor.ts +31 -0
  62. package/src/descriptor/texture/TextureDescriptor.ts +110 -0
  63. package/src/index.ts +9 -0
  64. package/src/interpreter/ComposerServiceInterpreter.ts +25 -0
  65. package/src/interpreter/GeoMapInterpreter.ts +253 -0
  66. package/src/interpreter/HTMLConvertInterpreter.ts +31 -0
  67. package/src/interpreter/InstancedMeshInterpreter.ts +76 -0
  68. package/src/interpreter/MeshInterpreter.ts +25 -0
  69. package/src/interpreter/ModelInterpreter.ts +61 -0
  70. package/src/interpreter/NodeInterpreter.ts +65 -0
  71. package/src/interpreter/OrbitControllerInterpreter.ts +47 -0
  72. package/src/interpreter/OrthographicCameraInterpreter.ts +13 -0
  73. package/src/interpreter/ParticleInterpreter.ts +221 -0
  74. package/src/interpreter/PassInterpreter.ts +43 -0
  75. package/src/interpreter/PerspectiveCameraInterpreter.ts +33 -0
  76. package/src/interpreter/PointsInterpreter.ts +61 -0
  77. package/src/interpreter/SceneServiceInterpreter.ts +119 -0
  78. package/src/interpreter/ServiceSchedulerInterpreter.ts +23 -0
  79. package/src/interpreter/SpriteInterpreter.ts +45 -0
  80. package/src/interpreter/TextInterpreter.ts +76 -0
  81. package/src/interpreter/TransformControllerInterpreter.ts +44 -0
  82. package/src/interpreter/animation/AnimationActionInterpreter.ts +66 -0
  83. package/src/interpreter/geometry/BoxGeometryInterpreter.ts +34 -0
  84. package/src/interpreter/geometry/BufferGeometryInterpreter.ts +47 -0
  85. package/src/interpreter/geometry/CircleGeometryInterpreter.ts +34 -0
  86. package/src/interpreter/geometry/CylinderGeometryInterpreter.ts +34 -0
  87. package/src/interpreter/geometry/ExtrudeGeometryInterpreter.ts +55 -0
  88. package/src/interpreter/geometry/PlaneGeometryInterpreter.ts +34 -0
  89. package/src/interpreter/geometry/RingGeometryInterpreter.ts +34 -0
  90. package/src/interpreter/geometry/SphereGeometryInterpreter.ts +34 -0
  91. package/src/interpreter/geometry/SurfaceGeometryInterpreter.ts +39 -0
  92. package/src/interpreter/geometry/TubeGeometryInterpreter.ts +42 -0
  93. package/src/interpreter/helper/AxesHelperInterpreter.ts +38 -0
  94. package/src/interpreter/index.ts +45 -0
  95. package/src/interpreter/light/AmbientLightInterpreter.ts +30 -0
  96. package/src/interpreter/light/DirectionalLightInterpreter.ts +84 -0
  97. package/src/interpreter/light/HemisphereLightInterpreter.ts +32 -0
  98. package/src/interpreter/light/PointLightInterpreter.ts +46 -0
  99. package/src/interpreter/light/RectAreaLightInterpreter.ts +34 -0
  100. package/src/interpreter/light/SpotLightInterpreter.ts +68 -0
  101. package/src/interpreter/material/MaterialInterpreter.ts +34 -0
  102. package/src/interpreter/material/MeshBasicMaterialInterpreter.ts +43 -0
  103. package/src/interpreter/material/MeshPhongMaterialInterpreter.ts +63 -0
  104. package/src/interpreter/material/MeshStandardMaterialInterpreter.ts +58 -0
  105. package/src/interpreter/material/PointsMaterialInterpreter.ts +36 -0
  106. package/src/interpreter/material/ShaderMaterialInterpreter.ts +51 -0
  107. package/src/interpreter/material/ShadowMaterialInterpreter.ts +31 -0
  108. package/src/interpreter/material/SpriteMaterialInterpreter.ts +36 -0
  109. package/src/interpreter/texture/TextureInterpreter.ts +59 -0
  110. package/src/locale/Language.ts +10 -0
  111. package/src/locale/LanguageProvider.ts +16 -0
  112. package/src/locale/index.ts +2 -0
  113. package/src/preset/execute/GeoMap/drilldown.ts +61 -0
  114. package/src/preset/execute/GeoMap/index.ts +1 -0
  115. package/src/preset/execute/index.ts +1 -0
  116. package/src/preset/index.ts +7 -0
  117. package/src/preset/routine/GeoMap/drilldown.ts +26 -0
  118. package/src/preset/routine/GeoMap/index.ts +1 -0
  119. package/src/preset/routine/index.ts +1 -0
  120. package/src/utils/dispose/index.ts +23 -0
  121. package/src/utils/geometry/index.ts +82 -0
  122. package/src/utils/index.ts +7 -0
  123. package/src/utils/material/index.ts +53 -0
  124. package/src/utils/pickup/index.ts +16 -0
  125. package/src/utils/random/index.ts +7 -0
  126. package/src/utils/text/index.ts +492 -0
  127. package/src/utils/texture/index.ts +19 -0
@@ -0,0 +1,119 @@
1
+ import { Camera, PerspectiveCamera, Raycaster, Vector2, } from 'three'
2
+ import { CameraDescriptor, Descriptor, HTMLActor, Interpreter, ServiceDescriptor, ServiceInterpreter, UpdateArgs } from '@vyr/engine'
3
+ import { SceneServiceDescriptor } from '../descriptor'
4
+ import { NodeActor, SceneServiceActor } from '../actor'
5
+ import { PickupNode } from './NodeInterpreter'
6
+
7
+ class SceneServiceInterpreter extends ServiceInterpreter {
8
+ static type = SceneServiceDescriptor.type
9
+
10
+ static ray = new Raycaster()
11
+ static direcation = new Vector2()
12
+
13
+ private _unlisten = -1
14
+ protected createActor(descriptor: SceneServiceDescriptor, args: UpdateArgs) {
15
+ const actor = new SceneServiceActor(descriptor.uuid)
16
+ return actor
17
+ }
18
+
19
+ protected setSize(actor: SceneServiceActor) {
20
+ const rect = actor.pipeline.domElement.getBoundingClientRect()
21
+ actor.pipeline.setSize(rect.width, rect.height)
22
+ actor.screenPipeline.setSize(rect.width, rect.height)
23
+ return rect
24
+ }
25
+ protected resize = () => {
26
+ const descriptor = Descriptor.get<Descriptor>(this.unit.uuid)
27
+ const actor = this.getActor<SceneServiceActor>(descriptor, { delta: 0 })
28
+ this.setSize(actor)
29
+ }
30
+
31
+ update(descriptor: SceneServiceDescriptor, args: UpdateArgs) {
32
+ super.update(descriptor, args)
33
+
34
+ const actor = this.getActor<SceneServiceActor>(descriptor, args)
35
+ actor.update(descriptor, args)
36
+
37
+ this.resize()
38
+ actor.pipeline.shadowMap.enabled = descriptor.shadowMap
39
+ actor.pipeline.shadowMap.autoUpdate = descriptor.autoUpdateShadowMap
40
+ //@ts-ignore
41
+ actor.pipeline.shadowMap.type = descriptor.shadowMapType
42
+ actor.pipeline.shadowMap.needsUpdate = true
43
+ }
44
+
45
+ mount(descriptor: SceneServiceDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
46
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
47
+
48
+ const actor = this.getActor<SceneServiceActor>(descriptor, args)
49
+ actor.clearStyleClass(actor.pipeline.domElement)
50
+
51
+ const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
52
+ if (parenActor instanceof HTMLActor) parenActor.add(actor)
53
+
54
+ this._unlisten = this.graphics.engine.inputSystem.listen('resize', this.resize, { target: window })
55
+ }
56
+
57
+ unmount(descriptor: SceneServiceDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
58
+ const actor = this.getActor<SceneServiceActor>(descriptor, args)
59
+
60
+ const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
61
+ parenActor.remove(actor)
62
+
63
+ this.graphics.engine.inputSystem.unlisten(this._unlisten)
64
+ this.resize()
65
+
66
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
67
+ }
68
+
69
+ free(descriptor: SceneServiceDescriptor, args: UpdateArgs) {
70
+ const actor = this.getActor<SceneServiceActor>(descriptor, args)
71
+ actor.dispose()
72
+ super.free(descriptor, args)
73
+ }
74
+
75
+ clear(service: ServiceDescriptor, args: UpdateArgs): void {
76
+ const actor = this.getActor<SceneServiceActor>(service, args)
77
+ actor.pipeline.clear()
78
+ }
79
+
80
+ beforeRender(service: SceneServiceDescriptor, args: UpdateArgs) {
81
+ const actor = this.getActor<SceneServiceActor>(service, args)
82
+ actor.scene.updateMatrixWorld()
83
+ }
84
+
85
+ render(service: SceneServiceDescriptor, args: UpdateArgs) {
86
+ const cameraDescriptor = CameraDescriptor.get<CameraDescriptor>(this.graphics.scheduler.camera)
87
+ if (cameraDescriptor === null) return
88
+ const actor = this.getActor<SceneServiceActor>(service, args)
89
+
90
+ const cameraInterpreter = this.graphics.getInterpreter(cameraDescriptor)
91
+ const camera = cameraInterpreter.getActor<NodeActor<Camera>>(cameraDescriptor, args)
92
+ if (camera.object instanceof PerspectiveCamera) {
93
+ const aspect = actor.pipeline.domElement.clientWidth / actor.pipeline.domElement.clientHeight
94
+ if (aspect !== camera.object.aspect) {
95
+ camera.object.aspect = aspect
96
+ camera.object.updateProjectionMatrix()
97
+ }
98
+ }
99
+
100
+ actor.render(service, camera, args)
101
+ }
102
+
103
+ beforePickup(mouse: { x: number; y: number }, rect: DOMRect, args: UpdateArgs) {
104
+ const currentCamera = SceneServiceDescriptor.get<CameraDescriptor>(this.graphics.scheduler.camera)
105
+ const camera = this.graphics.getInterpreter(currentCamera).getActor<NodeActor<Camera>>(currentCamera, args)
106
+
107
+ SceneServiceInterpreter.direcation.x = (mouse.x / rect.width) * 2 - 1
108
+ SceneServiceInterpreter.direcation.y = -(mouse.y / rect.height) * 2 + 1
109
+
110
+ SceneServiceInterpreter.ray.setFromCamera(SceneServiceInterpreter.direcation, camera.object)
111
+ }
112
+
113
+ orderBy(result: PickupNode[]) {
114
+ result.sort((a, b) => a.minDistance - b.minDistance)
115
+ }
116
+ }
117
+ ServiceInterpreter.register(SceneServiceInterpreter)
118
+
119
+ export { SceneServiceInterpreter }
@@ -0,0 +1,23 @@
1
+ import { AnimationMixer, Object3D } from 'three'
2
+ import { ServiceSchedulerInterpreter as SchedulerInterpreter, ServiceSchedulerDescriptor, UpdateArgs } from '@vyr/engine'
3
+
4
+ class ServiceSchedulerInterpreter extends SchedulerInterpreter {
5
+ readonly mixer = new AnimationMixer(new Object3D())
6
+
7
+ updateMixer = (args: UpdateArgs) => {
8
+ this.mixer.update(args.delta)
9
+ }
10
+
11
+ install(descriptor: ServiceSchedulerDescriptor, args: UpdateArgs) {
12
+ super.install(descriptor, args)
13
+ this.graphics.engine.listen('beforeRender', this.updateMixer)
14
+ }
15
+
16
+ uninstall(descriptor: ServiceSchedulerDescriptor, args: UpdateArgs) {
17
+ this.graphics.engine.unlisten('beforeRender', this.updateMixer)
18
+ super.uninstall(descriptor, args)
19
+ }
20
+ }
21
+ SchedulerInterpreter.register(ServiceSchedulerInterpreter)
22
+
23
+ export { ServiceSchedulerInterpreter }
@@ -0,0 +1,45 @@
1
+ import { Sprite, SpriteMaterial } from "three";
2
+ import { Asset, UpdateArgs } from "@vyr/engine";
3
+ import { SpriteDescriptor } from "../descriptor";
4
+ import { NodeInterpreter } from "./NodeInterpreter";
5
+ import { MaterialActor, NodeActor } from "../actor";
6
+
7
+ class SpriteInterpreter extends NodeInterpreter {
8
+ private static _material: SpriteMaterial | null = null
9
+
10
+ static get material() {
11
+ if (this._material === null) {
12
+ this._material = new SpriteMaterial()
13
+ }
14
+ return this._material
15
+ }
16
+
17
+ static type = SpriteDescriptor.type
18
+
19
+ protected createActor(descriptor: SpriteDescriptor, args: UpdateArgs) {
20
+ const actor = new NodeActor(new Sprite())
21
+ return actor
22
+ }
23
+
24
+ useMaterial(material: string, args: UpdateArgs) {
25
+ const materialDescriptor = Asset.get(material)
26
+ if (materialDescriptor === null) return SpriteInterpreter.material
27
+
28
+ const interpreter = this.graphics.getInterpreter(materialDescriptor)
29
+ const actor = interpreter.getActor<MaterialActor>(materialDescriptor, args)
30
+ return actor.object instanceof SpriteMaterial ? actor.object : SpriteInterpreter.material
31
+ }
32
+
33
+ getMaterial(descriptor: SpriteDescriptor, args: UpdateArgs) {
34
+ return this.useMaterial(descriptor.material, args)
35
+ }
36
+
37
+ update(descriptor: SpriteDescriptor, args: UpdateArgs) {
38
+ super.update(descriptor, args)
39
+ const actor = this.getActor<NodeActor<Sprite>>(descriptor, args)
40
+ actor.object.material = this.getMaterial(descriptor, args)
41
+ }
42
+ }
43
+ NodeInterpreter.register(SpriteInterpreter)
44
+
45
+ export { SpriteInterpreter }
@@ -0,0 +1,76 @@
1
+ import { BufferGeometry, Mesh } from "three";
2
+ import { Font } from 'three/examples/jsm/loaders/FontLoader.js'
3
+ import { Asset, UpdateArgs } from "@vyr/engine";
4
+ import { TextDescriptor } from "../descriptor";
5
+ import { NodeInterpreter } from "./NodeInterpreter";
6
+ import { NodeActor } from "../actor";
7
+ import { geometry, TextUtils, material } from "../utils";
8
+
9
+ class TextInterpreter extends NodeInterpreter {
10
+ static type = TextDescriptor.type
11
+ private _geometry = new BufferGeometry()
12
+ private _cacheKey = ''
13
+
14
+ protected createActor(descriptor: TextDescriptor, args: UpdateArgs) {
15
+ const actor = new NodeActor(new Mesh(this._geometry, material.defaultMaterial()))
16
+ return actor
17
+ }
18
+
19
+ private _fastHash(str: string): number {
20
+ let hash1 = 5381; // djb2初始值
21
+ let hash2 = 0x811C9DC5; // FNV-1初始值
22
+
23
+ for (let i = 0; i < str.length; i++) {
24
+ const char = str.charCodeAt(i);
25
+ hash1 = (hash1 * 33) ^ char;
26
+ hash2 = (hash2 * 0x01000193) ^ char;
27
+ }
28
+
29
+ // 组合两个哈希值,大幅降低碰撞概率
30
+ return ((hash1 >>> 0) ^ (hash2 >>> 0)) >>> 0;
31
+ }
32
+
33
+ getCacheKey(descriptor: TextDescriptor) {
34
+ return `${this._fastHash(descriptor.text)}_${descriptor.size}_${descriptor.lineHeight}_${descriptor.maxWidth}_${descriptor.letterSpacing}`
35
+ }
36
+
37
+ setAttribute(descriptor: TextDescriptor, args: UpdateArgs) {
38
+ const font = Asset.get<Font>(descriptor.font)
39
+ if (font instanceof Font) {
40
+ const options = {
41
+ size: descriptor.size,
42
+ lineHeight: descriptor.lineHeight,
43
+ maxWidth: descriptor.maxWidth,
44
+ letterSpacing: descriptor.letterSpacing,
45
+ }
46
+ const source = TextUtils.createTextGeometry(descriptor.text, descriptor.maxWidth, font, options)
47
+ this._geometry.copy(source)
48
+ source.dispose()
49
+ } else {
50
+ const source = new BufferGeometry()
51
+ this._geometry.copy(source)
52
+ source.dispose()
53
+ }
54
+
55
+ if (descriptor.flattenUVsToPlane) geometry.flattenUVsToPlane(this._geometry)
56
+ }
57
+
58
+ update(descriptor: TextDescriptor, args: UpdateArgs) {
59
+ super.update(descriptor, args)
60
+ const actor = this.getActor<NodeActor<Mesh>>(descriptor, args)
61
+ const cacheKey = this.getCacheKey(descriptor)
62
+ if (this._cacheKey !== cacheKey) {
63
+ this.setAttribute(descriptor, args)
64
+ this._cacheKey = cacheKey
65
+ }
66
+ actor.object.material = material.getMaterial(descriptor.material, this.graphics, args)
67
+ }
68
+
69
+ free(descriptor: TextDescriptor, args: UpdateArgs) {
70
+ this._geometry.dispose()
71
+ super.free(descriptor, args)
72
+ }
73
+ }
74
+ NodeInterpreter.register(TextInterpreter)
75
+
76
+ export { TextInterpreter }
@@ -0,0 +1,44 @@
1
+ import { Descriptor, Interpreter, UpdateArgs } from "@vyr/engine";
2
+ import { TransformControllerDescriptor } from '../descriptor'
3
+ import { NodeActor, TransformControllerActor } from "../actor"
4
+
5
+ class TransformControllerInterpreter extends Interpreter {
6
+ static type = TransformControllerDescriptor.type
7
+
8
+ protected createActor(descriptor: TransformControllerDescriptor, args: UpdateArgs) {
9
+ const actor = new TransformControllerActor()
10
+ return actor
11
+ }
12
+
13
+ update(descriptor: TransformControllerDescriptor, args: UpdateArgs) {
14
+ super.update(descriptor, args)
15
+ const actor = this.getActor<TransformControllerActor>(descriptor, args)
16
+ actor.update(descriptor, this.graphics, args)
17
+ }
18
+
19
+ mount(descriptor: TransformControllerDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
20
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
21
+ const parenActor = parentInterpreter.getActor<NodeActor>(parentDescriptor, args)
22
+ const actor = this.getActor<TransformControllerActor>(descriptor, args)
23
+ parenActor.add(actor)
24
+ }
25
+
26
+ unmount(descriptor: TransformControllerDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
27
+ const parenActor = parentInterpreter.getActor<NodeActor>(parentDescriptor, args)
28
+ const actor = this.getActor<TransformControllerActor>(descriptor, args)
29
+ parenActor.remove(actor)
30
+ actor.unlisten(this.graphics)
31
+
32
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
33
+ }
34
+
35
+ free(descriptor: TransformControllerDescriptor, args: UpdateArgs) {
36
+ const actor = this.getActor<TransformControllerActor>(descriptor, args)
37
+ actor.dispose(this.graphics)
38
+ super.free(descriptor, args)
39
+ }
40
+ }
41
+ Interpreter.register(TransformControllerInterpreter)
42
+
43
+
44
+ export { TransformControllerInterpreter }
@@ -0,0 +1,66 @@
1
+ import { AnimationAction, AnimationMixer } from 'three'
2
+ import { Descriptor, Interpreter, UpdateArgs } from "@vyr/engine"
3
+ import { AnimationActionDescriptor, ModelDescriptor } from "../../descriptor"
4
+ import { ModelInterpreter } from '../ModelInterpreter'
5
+ import { ServiceSchedulerInterpreter } from '../ServiceSchedulerInterpreter'
6
+
7
+ class AnimationActionInterpreter extends Interpreter {
8
+ static type = AnimationActionDescriptor.type
9
+ animationAction: AnimationAction | null = null
10
+
11
+ freeAction(mixer: AnimationMixer) {
12
+ if (this.animationAction) {
13
+ this.animationAction.stop()
14
+ const clip = this.animationAction.getClip()
15
+ mixer.uncacheAction(clip, this.animationAction.getRoot())
16
+ this.animationAction = null
17
+ }
18
+ }
19
+
20
+ setProperty(action: AnimationAction, descriptor: AnimationActionDescriptor, args: UpdateArgs) {
21
+ action.enabled = descriptor.enabled
22
+ action.timeScale = descriptor.timeScale
23
+ action.weight = descriptor.weight
24
+ action.zeroSlopeAtStart = descriptor.zeroSlopeAtStart
25
+ action.zeroSlopeAtEnd = descriptor.zeroSlopeAtEnd
26
+ action.startAt(descriptor.startTime)
27
+ action.setDuration(descriptor.duration)
28
+ action.setLoop(descriptor.loop as any, descriptor.repetitions)
29
+ descriptor.play ? action.play() : action.stop()
30
+ }
31
+
32
+ update(descriptor: AnimationActionDescriptor, args: UpdateArgs) {
33
+ super.update(descriptor, args)
34
+ const scheduler = this.graphics.getInterpreter<ServiceSchedulerInterpreter>(this.graphics.scheduler)
35
+ this.freeAction(scheduler.mixer)
36
+
37
+ const parentDescriptor = ModelDescriptor.get<ModelDescriptor>(this.unit.parent)
38
+ const parentInterpreter = this.graphics.getInterpreter<ModelInterpreter>(parentDescriptor)
39
+
40
+ if (parentInterpreter instanceof ModelInterpreter) {
41
+ const model = parentInterpreter.wrapper.children[0]
42
+ if (model === undefined) return
43
+ for (const clip of model.animations) {
44
+ if (clip.name === descriptor.clip) {
45
+ this.animationAction = scheduler.mixer.clipAction(clip, model)
46
+ this.animationAction.clampWhenFinished = true
47
+ this.setProperty(this.animationAction, descriptor, args)
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ mount(descriptor: AnimationActionDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
54
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
55
+ this.getActor(descriptor, args)
56
+ }
57
+
58
+ unmount(descriptor: AnimationActionDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
59
+ const scheduler = this.graphics.getInterpreter<ServiceSchedulerInterpreter>(this.graphics.scheduler)
60
+ this.freeAction(scheduler.mixer)
61
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
62
+ }
63
+ }
64
+ Interpreter.register(AnimationActionInterpreter)
65
+
66
+ export { AnimationActionInterpreter }
@@ -0,0 +1,34 @@
1
+ import { BufferGeometry, BoxGeometry } from "three";
2
+ import { Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { BoxGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ class BoxGeometryInterpreter extends Interpreter {
7
+ static type = BoxGeometryDescriptor.type
8
+
9
+ protected createActor(descriptor: BoxGeometryDescriptor, args: UpdateArgs) {
10
+ const actor = new GeometryActor(new BufferGeometry())
11
+ return actor
12
+ }
13
+
14
+ setAttribute(actor: GeometryActor<BoxGeometry>, descriptor: BoxGeometryDescriptor) {
15
+ const source = new BoxGeometry(descriptor.width, descriptor.height, descriptor.depth, descriptor.widthSegments, descriptor.heightSegments, descriptor.depthSegments)
16
+ actor.object.copy(source)
17
+ source.dispose()
18
+ }
19
+
20
+ update(descriptor: BoxGeometryDescriptor, args: UpdateArgs) {
21
+ super.update(descriptor, args)
22
+ const actor = this.getActor<GeometryActor<BoxGeometry>>(descriptor, args)
23
+ this.setAttribute(actor, descriptor)
24
+ }
25
+
26
+ free(descriptor: BoxGeometryDescriptor, args: UpdateArgs) {
27
+ const actor = this.getActor<GeometryActor<BoxGeometry>>(descriptor, args)
28
+ actor.object.dispose()
29
+ super.free(descriptor, args)
30
+ }
31
+ }
32
+ Interpreter.register(BoxGeometryInterpreter)
33
+
34
+ export { BoxGeometryInterpreter }
@@ -0,0 +1,47 @@
1
+ import { BufferGeometry, BufferGeometryLoader } from "three";
2
+ import { DatasetDescriptor, Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { BufferGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ let _loader: BufferGeometryLoader | null = null
7
+ class BufferGeometryInterpreter extends Interpreter {
8
+ static type = BufferGeometryDescriptor.type
9
+ static get loader() {
10
+ if (_loader === null) {
11
+ _loader = new BufferGeometryLoader()
12
+ }
13
+ return _loader
14
+ }
15
+
16
+ protected createActor(descriptor: BufferGeometryDescriptor, args: UpdateArgs) {
17
+ const actor = new GeometryActor(new BufferGeometry())
18
+ return actor
19
+ }
20
+
21
+ setAttribute(actor: GeometryActor<BufferGeometry>, descriptor: BufferGeometryDescriptor) {
22
+ const buffer = DatasetDescriptor.getData(descriptor.buffer)
23
+ let source
24
+ if (buffer === null) {
25
+ source = new BufferGeometry()
26
+ } else {
27
+ source = BufferGeometryInterpreter.loader.parse(buffer)
28
+ }
29
+ actor.object.copy(source)
30
+ source.dispose()
31
+ }
32
+
33
+ update(descriptor: BufferGeometryDescriptor, args: UpdateArgs) {
34
+ super.update(descriptor, args)
35
+ const actor = this.getActor<GeometryActor<BufferGeometry>>(descriptor, args)
36
+ this.setAttribute(actor, descriptor)
37
+ }
38
+
39
+ free(descriptor: BufferGeometryDescriptor, args: UpdateArgs) {
40
+ const actor = this.getActor<GeometryActor<BufferGeometry>>(descriptor, args)
41
+ actor.object.dispose()
42
+ super.free(descriptor, args)
43
+ }
44
+ }
45
+ Interpreter.register(BufferGeometryInterpreter)
46
+
47
+ export { BufferGeometryInterpreter }
@@ -0,0 +1,34 @@
1
+ import { BufferGeometry, CircleGeometry } from "three";
2
+ import { Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { CircleGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ class CircleGeometryInterpreter extends Interpreter {
7
+ static type = CircleGeometryDescriptor.type
8
+
9
+ protected createActor(descriptor: CircleGeometryDescriptor, args: UpdateArgs) {
10
+ const actor = new GeometryActor(new BufferGeometry())
11
+ return actor
12
+ }
13
+
14
+ setAttribute(actor: GeometryActor<CircleGeometry>, descriptor: CircleGeometryDescriptor) {
15
+ const source = new CircleGeometry(descriptor.radius, descriptor.segments, descriptor.thetaStart, descriptor.thetaLength)
16
+ actor.object.copy(source)
17
+ source.dispose()
18
+ }
19
+
20
+ update(descriptor: CircleGeometryDescriptor, args: UpdateArgs) {
21
+ super.update(descriptor, args)
22
+ const actor = this.getActor<GeometryActor<CircleGeometry>>(descriptor, args)
23
+ this.setAttribute(actor, descriptor)
24
+ }
25
+
26
+ free(descriptor: CircleGeometryDescriptor, args: UpdateArgs) {
27
+ const actor = this.getActor<GeometryActor<CircleGeometry>>(descriptor, args)
28
+ actor.object.dispose()
29
+ super.free(descriptor, args)
30
+ }
31
+ }
32
+ Interpreter.register(CircleGeometryInterpreter)
33
+
34
+ export { CircleGeometryInterpreter }
@@ -0,0 +1,34 @@
1
+ import { BufferGeometry, CylinderGeometry } from "three";
2
+ import { Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { CylinderGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ class CylinderGeometryInterpreter extends Interpreter {
7
+ static type = CylinderGeometryDescriptor.type
8
+
9
+ protected createActor(descriptor: CylinderGeometryDescriptor, args: UpdateArgs) {
10
+ const actor = new GeometryActor(new BufferGeometry())
11
+ return actor
12
+ }
13
+
14
+ setAttribute(actor: GeometryActor<CylinderGeometry>, descriptor: CylinderGeometryDescriptor) {
15
+ const source = new CylinderGeometry(descriptor.radiusTop, descriptor.radiusBottom, descriptor.height, descriptor.radialSegments, descriptor.heightSegments, descriptor.openEnded, descriptor.thetaStart, descriptor.thetaLength)
16
+ actor.object.copy(source)
17
+ source.dispose()
18
+ }
19
+
20
+ update(descriptor: CylinderGeometryDescriptor, args: UpdateArgs) {
21
+ super.update(descriptor, args)
22
+ const actor = this.getActor<GeometryActor<CylinderGeometry>>(descriptor, args)
23
+ this.setAttribute(actor, descriptor)
24
+ }
25
+
26
+ free(descriptor: CylinderGeometryDescriptor, args: UpdateArgs) {
27
+ const actor = this.getActor<GeometryActor<CylinderGeometry>>(descriptor, args)
28
+ actor.object.dispose()
29
+ super.free(descriptor, args)
30
+ }
31
+ }
32
+ Interpreter.register(CylinderGeometryInterpreter)
33
+
34
+ export { CylinderGeometryInterpreter }
@@ -0,0 +1,55 @@
1
+ import { BufferGeometry, ExtrudeGeometry, Path, Shape, } from "three";
2
+ import { DatasetDescriptor, Interpreter, JsonAsset, UpdateArgs } from "@vyr/engine";
3
+ import { ExtrudeGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+ import { geometry } from "../../utils";
6
+
7
+ class ExtrudeGeometryInterpreter extends Interpreter {
8
+ static type = ExtrudeGeometryDescriptor.type
9
+
10
+ protected createActor(descriptor: ExtrudeGeometryDescriptor, args: UpdateArgs) {
11
+ const actor = new GeometryActor(new BufferGeometry())
12
+ return actor
13
+ }
14
+
15
+ createShapes(collection: JsonAsset[], shapes: Shape[], descriptor: ExtrudeGeometryDescriptor) {
16
+ for (const shapeData of collection) {
17
+ const region = shapeData[0]
18
+ const shape = new Shape(geometry.getPointsOfshapeData(region, descriptor.offset))
19
+ shapes.push(shape)
20
+
21
+ if (shapeData.length <= 1) continue
22
+ for (let i = 1; i < shapeData.length; i++) {
23
+ const path = new Path(geometry.getPointsOfshapeData(shapeData[i], descriptor.offset))
24
+ shape.holes.push(path)
25
+ }
26
+ }
27
+ }
28
+
29
+ setAttribute(actor: GeometryActor<ExtrudeGeometry>, descriptor: ExtrudeGeometryDescriptor, args: UpdateArgs) {
30
+ const collection = DatasetDescriptor.getCollection<JsonAsset>(descriptor.shapes)
31
+ const shapes: Shape[] = []
32
+ this.createShapes(collection, shapes, descriptor)
33
+
34
+ const source = new ExtrudeGeometry(shapes, geometry.getExtrudeOptions(descriptor))
35
+ actor.object.copy(source)
36
+ source.dispose()
37
+
38
+ if (descriptor.flattenUVsToPlane) geometry.flattenUVsToPlane(actor.object)
39
+ }
40
+
41
+ update(descriptor: ExtrudeGeometryDescriptor, args: UpdateArgs) {
42
+ super.update(descriptor, args)
43
+ const actor = this.getActor<GeometryActor<ExtrudeGeometry>>(descriptor, args)
44
+ this.setAttribute(actor, descriptor, args)
45
+ }
46
+
47
+ free(descriptor: ExtrudeGeometryDescriptor, args: UpdateArgs) {
48
+ const actor = this.getActor<GeometryActor<ExtrudeGeometry>>(descriptor, args)
49
+ actor.object.dispose()
50
+ super.free(descriptor, args)
51
+ }
52
+ }
53
+ Interpreter.register(ExtrudeGeometryInterpreter)
54
+
55
+ export { ExtrudeGeometryInterpreter }
@@ -0,0 +1,34 @@
1
+ import { BufferGeometry, PlaneGeometry } from "three";
2
+ import { Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { PlaneGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ class PlaneGeometryInterpreter extends Interpreter {
7
+ static type = PlaneGeometryDescriptor.type
8
+
9
+ protected createActor(descriptor: PlaneGeometryDescriptor, args: UpdateArgs) {
10
+ const actor = new GeometryActor(new BufferGeometry())
11
+ return actor
12
+ }
13
+
14
+ setAttribute(actor: GeometryActor<PlaneGeometry>, descriptor: PlaneGeometryDescriptor) {
15
+ const source = new PlaneGeometry(descriptor.width, descriptor.height, descriptor.widthSegments, descriptor.heightSegments)
16
+ actor.object.copy(source)
17
+ source.dispose()
18
+ }
19
+
20
+ update(descriptor: PlaneGeometryDescriptor, args: UpdateArgs) {
21
+ super.update(descriptor, args)
22
+ const actor = this.getActor<GeometryActor<PlaneGeometry>>(descriptor, args)
23
+ this.setAttribute(actor, descriptor)
24
+ }
25
+
26
+ free(descriptor: PlaneGeometryDescriptor, args: UpdateArgs) {
27
+ const actor = this.getActor<GeometryActor<PlaneGeometry>>(descriptor, args)
28
+ actor.object.dispose()
29
+ super.free(descriptor, args)
30
+ }
31
+ }
32
+ Interpreter.register(PlaneGeometryInterpreter)
33
+
34
+ export { PlaneGeometryInterpreter }
@@ -0,0 +1,34 @@
1
+ import { BufferGeometry, RingGeometry } from "three";
2
+ import { Interpreter, UpdateArgs } from "@vyr/engine";
3
+ import { RingGeometryDescriptor } from "../../descriptor";
4
+ import { GeometryActor } from "../../actor";
5
+
6
+ class RingGeometryInterpreter extends Interpreter {
7
+ static type = RingGeometryDescriptor.type
8
+
9
+ protected createActor(descriptor: RingGeometryDescriptor, args: UpdateArgs) {
10
+ const actor = new GeometryActor(new BufferGeometry())
11
+ return actor
12
+ }
13
+
14
+ setAttribute(actor: GeometryActor<RingGeometry>, descriptor: RingGeometryDescriptor) {
15
+ const source = new RingGeometry(descriptor.innerRadius, descriptor.outerRadius, descriptor.thetaSegments, descriptor.phiSegments, descriptor.thetaStart, descriptor.thetaLength)
16
+ actor.object.copy(source)
17
+ source.dispose()
18
+ }
19
+
20
+ update(descriptor: RingGeometryDescriptor, args: UpdateArgs) {
21
+ super.update(descriptor, args)
22
+ const actor = this.getActor<GeometryActor<RingGeometry>>(descriptor, args)
23
+ this.setAttribute(actor, descriptor)
24
+ }
25
+
26
+ free(descriptor: RingGeometryDescriptor, args: UpdateArgs) {
27
+ const actor = this.getActor<GeometryActor<RingGeometry>>(descriptor, args)
28
+ actor.object.dispose()
29
+ super.free(descriptor, args)
30
+ }
31
+ }
32
+ Interpreter.register(RingGeometryInterpreter)
33
+
34
+ export { RingGeometryInterpreter }