@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,76 @@
1
+ import { Color, InstancedMesh, Matrix4, Object3D } from 'three'
2
+ import { DatasetDescriptor, UpdateArgs } from "@vyr/engine";
3
+ import { InstancedMeshDescriptor, InstancedSetting } from "../descriptor";
4
+ import { PickupNode } from './NodeInterpreter';
5
+ import { MeshInterpreter } from "./MeshInterpreter";
6
+ import { NodeActor } from '../actor';
7
+ import { material, geometry, collectionPickupResult } from '../utils';
8
+
9
+ class InstancedMeshInterpreter extends MeshInterpreter {
10
+ static type = InstancedMeshDescriptor.type
11
+
12
+ readonly wrapper!: Object3D
13
+ instancedMesh!: InstancedMesh
14
+ count = -1
15
+
16
+ createActor(descriptor: InstancedMeshDescriptor, args: UpdateArgs) {
17
+ const actor = new NodeActor(new Object3D())
18
+ //@ts-ignore
19
+ this.wrapper = new Object3D()
20
+ actor.object.add(this.wrapper)
21
+ return actor
22
+ }
23
+
24
+ updateInstanceMesh(setting: InstancedSetting[], instance: InstancedMesh) {
25
+ const color = new Color()
26
+ const matrix = new Matrix4()
27
+
28
+ for (let i = 0; i < setting.length; i++) {
29
+ const setItem = setting[i]
30
+ color.setStyle(setItem.color)
31
+ matrix.fromArray(setItem.matrix)
32
+ instance.setMatrixAt(i, matrix)
33
+ instance.setColorAt(i, color)
34
+ }
35
+
36
+ instance.instanceMatrix.needsUpdate = true
37
+ if (instance.instanceColor) instance.instanceColor.needsUpdate = true
38
+ }
39
+
40
+ getInstancedMesh(descriptor: InstancedMeshDescriptor, args: UpdateArgs, setting: InstancedSetting[]) {
41
+ const instancedMesh = new InstancedMesh(geometry.defaultGeometry(), material.defaultMaterial(), setting.length)
42
+ return instancedMesh
43
+ }
44
+
45
+ setInstancedMesh(descriptor: InstancedMeshDescriptor, args: UpdateArgs) {
46
+ const setting = DatasetDescriptor.getCollection<InstancedSetting>(descriptor.setting)
47
+ if (this.count !== setting.length) {
48
+ this.count = setting.length
49
+ this.wrapper.clear()
50
+ if (this.instancedMesh) this.instancedMesh.dispose()
51
+ this.instancedMesh = this.getInstancedMesh(descriptor, args, setting)
52
+ this.wrapper.add(this.instancedMesh)
53
+ }
54
+ this.updateInstanceMesh(setting, this.instancedMesh)
55
+ }
56
+
57
+ update(descriptor: InstancedMeshDescriptor, args: UpdateArgs) {
58
+ super.update(descriptor, args)
59
+ this.setInstancedMesh(descriptor, args)
60
+ this.instancedMesh.geometry = geometry.getGeometry(descriptor.geometry, this.graphics, args)
61
+ this.instancedMesh.material = material.getMaterial(descriptor.material, this.graphics, args)
62
+ }
63
+
64
+ free(descriptor: InstancedMeshDescriptor, args: UpdateArgs) {
65
+ this.instancedMesh.dispose()
66
+ super.free(descriptor, args)
67
+ }
68
+
69
+ pickup(descriptor: InstancedMeshDescriptor, args: UpdateArgs, result: PickupNode[]) {
70
+ if (descriptor.visible === false) return
71
+ collectionPickupResult(this.wrapper, true, descriptor, result)
72
+ }
73
+ }
74
+ MeshInterpreter.register(InstancedMeshInterpreter)
75
+
76
+ export { InstancedMeshInterpreter }
@@ -0,0 +1,25 @@
1
+ import { Mesh } from "three";
2
+ import { UpdateArgs } from "@vyr/engine";
3
+ import { MeshDescriptor } from "../descriptor";
4
+ import { NodeInterpreter } from "./NodeInterpreter";
5
+ import { NodeActor } from "../actor";
6
+ import { geometry, material } from "../utils";
7
+
8
+ class MeshInterpreter extends NodeInterpreter {
9
+ static type = MeshDescriptor.type
10
+
11
+ protected createActor(descriptor: MeshDescriptor, args: UpdateArgs): NodeActor {
12
+ const actor = new NodeActor(new Mesh(geometry.defaultGeometry(), material.defaultMaterial()))
13
+ return actor
14
+ }
15
+
16
+ update(descriptor: MeshDescriptor, args: UpdateArgs) {
17
+ super.update(descriptor, args)
18
+ const actor = this.getActor<NodeActor<Mesh>>(descriptor, args)
19
+ actor.object.geometry = geometry.getGeometry(descriptor.geometry, this.graphics, args)
20
+ actor.object.material = material.getMaterial(descriptor.material, this.graphics, args)
21
+ }
22
+ }
23
+ NodeInterpreter.register(MeshInterpreter)
24
+
25
+ export { MeshInterpreter }
@@ -0,0 +1,61 @@
1
+ import { Object3D } from 'three'
2
+ import { Asset, Descriptor, UpdateArgs } from "@vyr/engine";
3
+ import { ModelDescriptor } from "../descriptor";
4
+ import { NodeInterpreter, PickupNode } from "./NodeInterpreter";
5
+ import { NodeActor } from '../actor';
6
+ import { collectionPickupResult, diaposeObject3D } from '../utils'
7
+
8
+ class ModelInterpreter extends NodeInterpreter {
9
+ static type = ModelDescriptor.type
10
+
11
+ readonly wrapper!: Object3D
12
+ url = ''
13
+
14
+ protected createActor(descriptor: Descriptor, args: UpdateArgs) {
15
+ const actor = super.createActor(descriptor, args)
16
+ //@ts-ignore
17
+ this.wrapper = new Object3D()
18
+ actor.object.add(this.wrapper)
19
+ return actor
20
+ }
21
+
22
+ setModel(descriptor: ModelDescriptor, args: UpdateArgs) {
23
+
24
+ if (this.url !== descriptor.url) {
25
+ diaposeObject3D(this.wrapper)
26
+ this.wrapper.clear()
27
+
28
+ if (descriptor.url) {
29
+ this.url = descriptor.url
30
+ const currentUrl = `${descriptor.url}?${descriptor.uuid}`
31
+ const model = Asset.get<Object3D>(currentUrl)
32
+ this.wrapper.add(model)
33
+ } else {
34
+ this.url = ''
35
+ }
36
+ }
37
+
38
+ this.wrapper.traverse(sub => {
39
+ sub.castShadow = descriptor.castShadow
40
+ sub.receiveShadow = descriptor.receiveShadow
41
+ })
42
+ }
43
+
44
+ update(descriptor: ModelDescriptor, args: UpdateArgs) {
45
+ super.update(descriptor, args)
46
+ this.setModel(descriptor, args)
47
+ }
48
+
49
+ free(descriptor: ModelDescriptor, args: UpdateArgs) {
50
+ diaposeObject3D(this.wrapper)
51
+ super.free(descriptor, args)
52
+ }
53
+
54
+ pickup(descriptor: ModelDescriptor, args: UpdateArgs, result: PickupNode[]) {
55
+ if (descriptor.visible === false) return
56
+ collectionPickupResult(this.wrapper, true, descriptor, result)
57
+ }
58
+ }
59
+ NodeInterpreter.register(ModelInterpreter)
60
+
61
+ export { ModelInterpreter }
@@ -0,0 +1,65 @@
1
+ import { Object3D, Intersection } from "three";
2
+ import { Descriptor, Interpreter, NodeDescriptor, PickupObject, UpdateArgs } from "@vyr/engine";
3
+ import { NodeActor } from "../actor";
4
+ import { collectionPickupResult } from "../utils";
5
+
6
+ interface PickupNode extends PickupObject {
7
+ minDistance: number
8
+ intersection: Intersection<Object3D>[]
9
+ }
10
+
11
+ class NodeInterpreter extends Interpreter {
12
+ static type = NodeDescriptor.type
13
+
14
+ protected createActor(descriptor: Descriptor, args: UpdateArgs) {
15
+ const actor = new NodeActor(new Object3D())
16
+ return actor
17
+ }
18
+
19
+ setProperty(actor: NodeActor, descriptor: NodeDescriptor, args: UpdateArgs) {
20
+ actor.object.layers.set(descriptor.layer)
21
+ actor.object.visible = descriptor.visible
22
+ actor.object.renderOrder = descriptor.renderOrder
23
+ actor.object.castShadow = descriptor.castShadow
24
+ actor.object.receiveShadow = descriptor.receiveShadow
25
+ }
26
+
27
+ setTransform(actor: NodeActor, descriptor: NodeDescriptor, args: UpdateArgs) {
28
+ const scale = descriptor.scale
29
+ const position = descriptor.position
30
+ const rotation = descriptor.rotation
31
+ actor.object.scale.set(scale.x, scale.y, scale.z)
32
+ actor.object.position.set(position.x, position.y, position.z)
33
+ actor.object.rotation.set(rotation.x, rotation.y, rotation.z)
34
+ }
35
+
36
+ update(descriptor: NodeDescriptor, args: UpdateArgs) {
37
+ super.update(descriptor, args)
38
+ const actor = this.getActor<NodeActor>(descriptor, args)
39
+ this.setProperty(actor, descriptor, args)
40
+ this.setTransform(actor, descriptor, args)
41
+ }
42
+
43
+ mount(descriptor: NodeDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
44
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
45
+ const parenActor = parentInterpreter.getActor<NodeActor>(parentDescriptor, args)
46
+ const actor = this.getActor<NodeActor>(descriptor, args)
47
+ parenActor.add(actor)
48
+ }
49
+
50
+ unmount(descriptor: NodeDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
51
+ const parenActor = parentInterpreter.getActor<NodeActor>(parentDescriptor, args)
52
+ const actor = this.getActor<NodeActor>(descriptor, args)
53
+ parenActor.remove(actor)
54
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
55
+ }
56
+
57
+ pickup(descriptor: NodeDescriptor, args: UpdateArgs, result: PickupNode[]) {
58
+ if (descriptor.visible === false) return
59
+ const actor = this.getActor<NodeActor>(descriptor, args)
60
+ collectionPickupResult(actor.object, false, descriptor, result)
61
+ }
62
+ }
63
+ Interpreter.register(NodeInterpreter)
64
+
65
+ export { PickupNode, NodeInterpreter }
@@ -0,0 +1,47 @@
1
+ import { Descriptor, Interpreter, PickupObject, UpdateArgs } from "@vyr/engine";
2
+ import { OrbitControllerDescriptor } from "../descriptor";
3
+ import { NodeActor, OrbitControllerActor } from "../actor";
4
+
5
+ class OrbitControllerInterpreter extends Interpreter {
6
+ static type = OrbitControllerDescriptor.type
7
+
8
+ protected createActor(descriptor: OrbitControllerDescriptor, args: UpdateArgs) {
9
+ const actor = new OrbitControllerActor(descriptor.uuid, this.graphics)
10
+ return actor
11
+ }
12
+
13
+ update(descriptor: OrbitControllerDescriptor, args: UpdateArgs) {
14
+ const actor = this.getActor<OrbitControllerActor>(descriptor, args)
15
+ actor.update(descriptor, this.graphics, args)
16
+ super.update(descriptor, args)
17
+ }
18
+
19
+ mount(descriptor: OrbitControllerDescriptor, 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<OrbitControllerActor>(descriptor, args)
23
+ parenActor.add(actor)
24
+ actor.listen(descriptor, this.graphics, args)
25
+ }
26
+
27
+ unmount(descriptor: OrbitControllerDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
28
+ const parenActor = parentInterpreter.getActor<NodeActor>(parentDescriptor, args)
29
+ const actor = this.getActor<OrbitControllerActor>(descriptor, args)
30
+ parenActor.remove(actor)
31
+ actor.unlisten(descriptor, this.graphics, args)
32
+
33
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
34
+ }
35
+
36
+ free(descriptor: OrbitControllerDescriptor, args: UpdateArgs) {
37
+ const actor = this.getActor<OrbitControllerActor>(descriptor, args)
38
+ actor.dispose()
39
+ super.free(descriptor, args)
40
+ }
41
+
42
+ pickup(descriptor: OrbitControllerDescriptor, args: UpdateArgs, result: PickupObject[]) { }
43
+ }
44
+ Interpreter.register(OrbitControllerInterpreter)
45
+
46
+
47
+ export { OrbitControllerInterpreter }
@@ -0,0 +1,13 @@
1
+ import { PickupObject, UpdateArgs } from "@vyr/engine";
2
+ import { OrthographicCameraDescriptor } from "../descriptor";
3
+ import { NodeInterpreter } from "./NodeInterpreter";
4
+
5
+ class OrthographicCameraInterpreter extends NodeInterpreter {
6
+ static type = OrthographicCameraDescriptor.type
7
+
8
+ pickup(descriptor: OrthographicCameraDescriptor, args: UpdateArgs, result: PickupObject[]) { }
9
+ }
10
+ NodeInterpreter.register(OrthographicCameraInterpreter)
11
+
12
+
13
+ export { OrthographicCameraInterpreter }
@@ -0,0 +1,221 @@
1
+ import {
2
+ BufferGeometry,
3
+ BufferAttribute,
4
+ Points,
5
+ WebGLProgramParametersWithUniforms,
6
+ WebGLRenderer,
7
+ DataTexture,
8
+ PointsMaterial,
9
+ RGBAFormat,
10
+ FloatType,
11
+ ClampToEdgeWrapping,
12
+ LinearFilter,
13
+ CatmullRomCurve3,
14
+ Vector3,
15
+ } from "three";
16
+ import { DatasetDescriptor, UpdateArgs } from "@vyr/engine";
17
+ import { ParticleDescriptor } from "../descriptor";
18
+ import { NodeInterpreter } from "./NodeInterpreter";
19
+ import { NodeActor } from "../actor";
20
+ import { randomRange, texture } from "../utils";
21
+
22
+ class ParticleInterpreter extends NodeInterpreter {
23
+ static type = ParticleDescriptor.type;
24
+
25
+ private _duration = 0;
26
+ private _geometry = new BufferGeometry();
27
+ private _material = new PointsMaterial();
28
+ private _tracRadio = { value: 0 };
29
+ private _trackTexture = { value: new DataTexture() };
30
+ uptime = 0;
31
+
32
+ protected createActor(descriptor: ParticleDescriptor, args: UpdateArgs) {
33
+ const actor = new NodeActor(new Points(this._geometry, this._material));
34
+ return actor;
35
+ }
36
+ private _createTypeArray(trackData: number[][], count: number) {
37
+ const typeArray = new Float32Array(count * 4);
38
+
39
+ const points: Vector3[] = [];
40
+ for (const point of trackData) {
41
+ points.push(new Vector3(point[0], point[1], point[2]));
42
+ }
43
+
44
+ const curve = new CatmullRomCurve3(points, false, "catmullrom", 0);
45
+ for (let i = 0; i < count; i++) {
46
+ const point = curve.getPointAt(i / count);
47
+ typeArray[i * 4] = point.x; // R
48
+ typeArray[i * 4 + 1] = point.y; // G
49
+ typeArray[i * 4 + 2] = point.z; // B
50
+ typeArray[i * 4 + 3] = 1.0; // A
51
+ }
52
+
53
+ return typeArray;
54
+ }
55
+ private _decorateShader(params: WebGLProgramParametersWithUniforms, renderer: WebGLRenderer) {
56
+ const precode = [
57
+ "attribute vec3 trackScale;",
58
+ "attribute vec3 trackRotation;",
59
+ "attribute vec3 trackOffset;",
60
+ "attribute float vSize;",
61
+ "uniform sampler2D trackTexture;", // 位置纹理
62
+ "uniform float tracRadio;",
63
+
64
+ // 从欧拉角创建旋转矩阵的函数
65
+ "mat4 rotationMatrixFromEuler(vec3 euler) {",
66
+ " float cx = cos(euler.x);",
67
+ " float sx = sin(euler.x);",
68
+ " float cy = cos(euler.y);",
69
+ " float sy = sin(euler.y);",
70
+ " float cz = cos(euler.z);",
71
+ " float sz = sin(euler.z);",
72
+ " return mat4(",
73
+ " cy * cz, cx * sz + sx * sy * cz, sx * sz - cx * sy * cz, 0.0,",
74
+ " -cy * sz, cx * cz - sx * sy * sz, sx * cz + cx * sy * sz, 0.0,",
75
+ " sy, -sx * cy, cx * cy, 0.0,",
76
+ " 0.0, 0.0, 0.0, 1.0",
77
+ " );",
78
+ "}",
79
+
80
+ // 从纹理采样位置的函数
81
+ "vec3 getPositionFromTexture(float u) {",
82
+ " vec2 uv = vec2(u, 0.5);", // 水平用传入的u,垂直固定0.5
83
+ " vec4 texel = texture2D(trackTexture, uv);",
84
+ " return texel.rgb;",
85
+ "}",
86
+ ].join("\n");
87
+
88
+ // 在着色器开头插入precode
89
+ params.vertexShader = precode + "\n" + params.vertexShader;
90
+
91
+ // 然后替换begin_vertex部分
92
+ params.vertexShader = params.vertexShader.replace(
93
+ "#include <begin_vertex>",
94
+ [
95
+ "#include <begin_vertex>",
96
+ "",
97
+ "// 从纹理获取位置",
98
+ "vec3 texturePosition = getPositionFromTexture(tracRadio);",
99
+ "",
100
+ "// 应用旋转变换",
101
+ "mat4 rotationMatrix = rotationMatrixFromEuler(trackRotation);",
102
+ "transformed = (rotationMatrix * vec4(texturePosition, 1.0)).xyz;",
103
+ "",
104
+ "// 应用缩放变换",
105
+ "transformed *= trackScale;",
106
+ "",
107
+ "// 应用偏移变换",
108
+ "transformed += trackOffset;",
109
+ ].join("\n")
110
+ ).replace(
111
+ 'gl_PointSize = size;',
112
+ 'gl_PointSize = vSize * size;'
113
+ );
114
+ }
115
+ private _setTrackMap(descriptor: ParticleDescriptor, args: UpdateArgs) {
116
+ this.clear();
117
+
118
+ const trackData = DatasetDescriptor.getCollection<number[]>(descriptor.track);
119
+ const count = Math.ceil(trackData.length / 512) * 512;
120
+ const typeArray = this._createTypeArray(trackData, count);
121
+ this._trackTexture.value = new DataTexture(typeArray, count, 1, RGBAFormat, FloatType);
122
+ this._trackTexture.value.wrapS = ClampToEdgeWrapping;
123
+ this._trackTexture.value.wrapT = ClampToEdgeWrapping;
124
+ this._trackTexture.value.minFilter = LinearFilter;
125
+ this._trackTexture.value.magFilter = LinearFilter;
126
+ this._trackTexture.value.generateMipmaps = false;
127
+ this._trackTexture.value.needsUpdate = true;
128
+
129
+ this._material.onBeforeCompile = (params, renderer) => {
130
+ params.uniforms.trackTexture = this._trackTexture;
131
+ params.uniforms.tracRadio = this._tracRadio;
132
+ this._decorateShader(params, renderer);
133
+ };
134
+ this.graphics.engine.listen("beforeRender", this._updateRadio);
135
+ }
136
+ private _updateMaterial(descriptor: ParticleDescriptor, args: UpdateArgs) {
137
+ this._setTrackMap(descriptor, args);
138
+ texture.setMap(this._material, "map", descriptor, this.graphics, args);
139
+ texture.setMap(this._material, "alphaMap", descriptor, this.graphics, args);
140
+ this._material.alphaTest = descriptor.alphaTest;
141
+ this._material.transparent = descriptor.transparent;
142
+ this._material.colorWrite = descriptor.colorWrite;
143
+ this._material.depthTest = descriptor.depthTest;
144
+ this._material.depthWrite = descriptor.depthrWrite;
145
+ //@ts-ignore
146
+ this._material.side = descriptor.side
147
+ //@ts-ignore
148
+ this._material.depthFunc = descriptor.depthFunc
149
+ //@ts-ignore
150
+ this._material.blending = descriptor.blending
151
+ this._material.vertexColors = descriptor.vertexColors;
152
+ this._material.color.setStyle(descriptor.color.value);
153
+ this._material.opacity = descriptor.color.opacity;
154
+ this._material.size = 1;
155
+ this._material.sizeAttenuation = descriptor.sizeAttenuation;
156
+ this._material.fog = descriptor.fog;
157
+ this._material.needsUpdate = true;
158
+ }
159
+ private _updateGeometry(descriptor: ParticleDescriptor) {
160
+ const positions: number[] = [];
161
+ const offsets: number[] = [];
162
+ const rotations: number[] = [];
163
+ const scales: number[] = [];
164
+ const sizes: number[] = []
165
+
166
+ for (let i = 0; i < descriptor.count; i++) {
167
+ positions.push(0, 0, 0);
168
+
169
+ const offsetX = randomRange(descriptor.minTrackOffset.x, descriptor.maxTrackOffset.x);
170
+ const offsetY = randomRange(descriptor.minTrackOffset.y, descriptor.maxTrackOffset.y);
171
+ const offsetZ = randomRange(descriptor.minTrackOffset.z, descriptor.maxTrackOffset.z);
172
+ offsets.push(offsetX, offsetY, offsetZ);
173
+
174
+ const rotationX = randomRange(descriptor.minTrackRotation.x, descriptor.maxTrackRotation.x);
175
+ const rotationY = randomRange(descriptor.minTrackRotation.y, descriptor.maxTrackRotation.y);
176
+ const rotationZ = randomRange(descriptor.minTrackRotation.z, descriptor.maxTrackRotation.z);
177
+ rotations.push(rotationX, rotationY, rotationZ);
178
+
179
+ const scaleX = randomRange(descriptor.minTrackScale.x, descriptor.maxTrackScale.x);
180
+ const scaleY = randomRange(descriptor.minTrackScale.y, descriptor.maxTrackScale.y);
181
+ const scaleZ = randomRange(descriptor.minTrackScale.z, descriptor.maxTrackScale.z);
182
+ scales.push(scaleX, scaleY, scaleZ);
183
+
184
+ const size = randomRange(descriptor.minSize, descriptor.maxSize)
185
+ sizes.push(size)
186
+ }
187
+ const geometry = new BufferGeometry()
188
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
189
+ geometry.setAttribute("trackOffset", new BufferAttribute(new Float32Array(offsets), 3));
190
+ geometry.setAttribute("trackRotation", new BufferAttribute(new Float32Array(rotations), 3));
191
+ geometry.setAttribute("trackScale", new BufferAttribute(new Float32Array(scales), 3));
192
+ geometry.setAttribute('vSize', new BufferAttribute(new Float32Array(sizes), 1));
193
+
194
+ this._geometry.copy(geometry)
195
+ }
196
+ private _updateRadio = (args: UpdateArgs) => {
197
+ this.uptime += args.delta;
198
+ const currentTime = this.uptime % this._duration;
199
+ this._tracRadio.value = currentTime / this._duration;
200
+ };
201
+
202
+ update(descriptor: ParticleDescriptor, args: UpdateArgs) {
203
+ super.update(descriptor, args);
204
+ this._duration = descriptor.duration;
205
+ this._updateGeometry(descriptor);
206
+ this._updateMaterial(descriptor, args);
207
+ }
208
+
209
+ clear() {
210
+ this.graphics.engine.unlisten("beforeRender", this._updateRadio);
211
+ this._trackTexture.value.dispose();
212
+ }
213
+
214
+ free(descriptor: ParticleDescriptor, args: UpdateArgs) {
215
+ this.clear();
216
+ super.free(descriptor, args);
217
+ }
218
+ }
219
+ NodeInterpreter.register(ParticleInterpreter);
220
+
221
+ export { ParticleInterpreter };
@@ -0,0 +1,43 @@
1
+ // import { Descriptor, Interpreter, UpdateArgs } from "@vyr/engine";
2
+ // import { PassDescriptor } from '../descriptor/PassDescriptor'
3
+ // import { ComposerServiceActor, PassActor } from "../actor"
4
+
5
+ // class PassInterpreter extends Interpreter {
6
+ // static type = PassDescriptor.type
7
+
8
+ // protected createActor(descriptor: PassDescriptor, args: UpdateArgs) {
9
+ // const actor = new PassActor(descriptor)
10
+ // return actor
11
+ // }
12
+
13
+ // update(descriptor: PassDescriptor, args: UpdateArgs) {
14
+ // super.update(descriptor, args)
15
+ // const actor = this.getActor<PassActor>(descriptor, args)
16
+ // actor.update(descriptor)
17
+ // }
18
+
19
+ // mount(descriptor: PassDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
20
+ // super.mount(descriptor, args, parentInterpreter, parentDescriptor)
21
+ // const parenActor = parentInterpreter.getActor<ComposerServiceActor>(parentDescriptor, args)
22
+ // const actor = this.getActor<PassActor>(descriptor, args)
23
+ // parenActor.add(actor)
24
+ // }
25
+
26
+ // unmount(descriptor: PassDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
27
+ // const parenActor = parentInterpreter.getActor<ComposerServiceActor>(parentDescriptor, args)
28
+ // const actor = this.getActor<PassActor>(descriptor, args)
29
+ // parenActor.remove(actor)
30
+
31
+ // super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
32
+ // }
33
+
34
+ // free(descriptor: PassDescriptor, args: UpdateArgs) {
35
+ // const actor = this.getActor<PassActor>(descriptor, args)
36
+ // actor.dispose()
37
+ // super.free(descriptor, args)
38
+ // }
39
+ // }
40
+ // Interpreter.register(PassInterpreter)
41
+
42
+
43
+ // export { PassInterpreter }
@@ -0,0 +1,33 @@
1
+ import { PerspectiveCamera } from "three";
2
+ import { PickupObject, UpdateArgs } from "@vyr/engine";
3
+ import { PerspectiveCameraDescriptor } from "../descriptor";
4
+ import { NodeInterpreter } from "./NodeInterpreter";
5
+ import { NodeActor } from "../actor";
6
+
7
+ class PerspectiveCameraInterpreter extends NodeInterpreter {
8
+ static type = PerspectiveCameraDescriptor.type
9
+
10
+ protected createActor(descriptor: PerspectiveCameraDescriptor, args: UpdateArgs) {
11
+ const actor = new NodeActor(new PerspectiveCamera())
12
+ return actor
13
+ }
14
+
15
+ setCamera(actor: NodeActor<PerspectiveCamera>, descriptor: PerspectiveCameraDescriptor, args: UpdateArgs) {
16
+ actor.object.fov = descriptor.fov
17
+ actor.object.updateMatrix()
18
+ actor.object.updateMatrixWorld()
19
+ actor.object.updateProjectionMatrix()
20
+ }
21
+
22
+ update(descriptor: PerspectiveCameraDescriptor, args: UpdateArgs) {
23
+ super.update(descriptor,args)
24
+ const actor = this.getActor<NodeActor<PerspectiveCamera>>(descriptor, args)
25
+ this.setCamera(actor, descriptor, args)
26
+ }
27
+
28
+ pickup(descriptor: PerspectiveCameraDescriptor, args: UpdateArgs, result: PickupObject[]) { }
29
+ }
30
+ NodeInterpreter.register(PerspectiveCameraInterpreter)
31
+
32
+
33
+ export { PerspectiveCameraInterpreter }
@@ -0,0 +1,61 @@
1
+ import { BufferGeometry, Points, Material, PointsMaterial } from "three";
2
+ import { Asset, UpdateArgs } from "@vyr/engine";
3
+ import { PointsDescriptor } from "../descriptor";
4
+ import { NodeInterpreter } from "./NodeInterpreter";
5
+ import { GeometryActor, MaterialActor, NodeActor } from "../actor";
6
+
7
+ class PointsInterpreter extends NodeInterpreter {
8
+ private static _geometry: BufferGeometry | null = null
9
+ private static _material: Material | null = null
10
+ static get geometry() {
11
+ if (this._geometry === null) {
12
+ this._geometry = new BufferGeometry()
13
+ }
14
+ return this._geometry
15
+ }
16
+ static get material() {
17
+ if (this._material === null) {
18
+ this._material = new PointsMaterial()
19
+ }
20
+ return this._material
21
+ }
22
+
23
+ static type = PointsDescriptor.type
24
+
25
+ protected createActor(descriptor: PointsDescriptor, args: UpdateArgs) {
26
+ const actor = new NodeActor(new Points())
27
+ return actor
28
+ }
29
+
30
+ getGeometry(descriptor: PointsDescriptor, args: UpdateArgs) {
31
+ const geometryDescriptor = Asset.get(descriptor.geometry)
32
+ if (geometryDescriptor === null) return PointsInterpreter.geometry
33
+
34
+ const interpreter = this.graphics.getInterpreter(geometryDescriptor)
35
+ const actor = interpreter.getActor<GeometryActor<BufferGeometry>>(geometryDescriptor, args)
36
+ return actor.object instanceof BufferGeometry ? actor.object : PointsInterpreter.geometry
37
+ }
38
+
39
+ useMaterial(material: string, args: UpdateArgs) {
40
+ const materialDescriptor = Asset.get(material)
41
+ if (materialDescriptor === null) return PointsInterpreter.material
42
+
43
+ const interpreter = this.graphics.getInterpreter(materialDescriptor)
44
+ const actor = interpreter.getActor<MaterialActor<Material>>(materialDescriptor, args)
45
+ return actor.object instanceof Material ? actor.object : PointsInterpreter.material
46
+ }
47
+
48
+ getMaterial(descriptor: PointsDescriptor, args: UpdateArgs) {
49
+ return this.useMaterial(descriptor.material, args)
50
+ }
51
+
52
+ update(descriptor: PointsDescriptor, args: UpdateArgs) {
53
+ super.update(descriptor, args)
54
+ const actor = this.getActor<NodeActor<Points>>(descriptor, args)
55
+ actor.object.geometry = this.getGeometry(descriptor, args)
56
+ actor.object.material = this.getMaterial(descriptor, args)
57
+ }
58
+ }
59
+ NodeInterpreter.register(PointsInterpreter)
60
+
61
+ export { PointsInterpreter }