@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,99 @@
1
+ import { DefaultStyleColor, DeserializationObject, Euler, Vector2 } from "@vyr/engine"
2
+ import { MaterialDescriptor, MaterialNormalMapType } from "./MaterialDescriptor"
3
+
4
+ class MeshStandardMaterialDescriptor extends MaterialDescriptor {
5
+ static type = 'MeshStandardMaterial'
6
+ /**漫反射颜色 */
7
+ color: DefaultStyleColor
8
+ /**漫反射贴图 */
9
+ map: string
10
+ /**透明度贴图 */
11
+ alphaMap: string
12
+ /**环境贴图 */
13
+ envMap: string
14
+ /**环境贴图强度 */
15
+ envMapIntensity: number
16
+ /**光照贴图 */
17
+ lightMap: string
18
+ /**烘焙光的强度 */
19
+ lightMapIntensity: number
20
+
21
+ /**环境贴图的旋转(以弧度为单位)。默认值为 (0,0,0)。 */
22
+ envMapRotation: Euler
23
+ /**该纹理的红色通道用作环境遮挡贴图。默认值为null。aoMap需要第二组UV。 */
24
+ aoMap: string
25
+ /**环境遮挡效果的强度。默认值为1。零是不遮挡效果。 */
26
+ aoMapIntensity: number
27
+ /**凹凸贴图 */
28
+ bumpMap: string
29
+ /**凹凸贴图会对材质产生多大影响 */
30
+ bumpScale: number
31
+ /**位移贴图会影响网格顶点的位置,与仅影响材质的光照和阴影的其他贴图不同,移位的顶点可以投射阴影,阻挡其他对象, 以及充当真实的几何体。位移纹理是指:网格的所有顶点被映射为图像中每个像素的值(白色是最高的),并且被重定位。 */
32
+ displacementMap: string
33
+ /**位移贴图对网格的影响程度(黑色是无位移,白色是最大位移)。如果没有设置位移贴图,则不会应用此值。默认值为1。 */
34
+ displacementScale: number
35
+ /**位移贴图在网格顶点上的偏移量。如果没有设置位移贴图,则不会应用此值。默认值为0。 */
36
+ displacementBias: number
37
+ /**材质的放射(光)颜色 */
38
+ emissive: string
39
+ /**放射(发光)贴图 */
40
+ emissiveMap: string
41
+ /**放射光强度 */
42
+ emissiveIntensity: number
43
+ /**材质的金属度贴图 */
44
+ metalnessMap: string
45
+ /**材质与金属的相似度.木材或石材,使用0.0,金属使用1.0 */
46
+ metalness: number
47
+ /**材质的法线贴图 */
48
+ normalMap: string
49
+ /**法线贴图的类型。*/
50
+ normalMapType: number
51
+ /**法线贴图对材质的影响程度 */
52
+ normalScale: Vector2
53
+ /**材质的粗糙程度 */
54
+ roughness: number
55
+ /**材质的粗糙度贴图 */
56
+ roughnessMap: string
57
+ /**定义材质是否使用平面着色进行渲染。默认值为false。 */
58
+ flatShading: boolean
59
+ /**材质是否受雾影响。默认为true。 */
60
+ fog: boolean
61
+ /**将几何体渲染为线框。默认值为false */
62
+ wireframe: boolean
63
+
64
+ constructor(descriptor: Partial<DeserializationObject<MeshStandardMaterialDescriptor>> = {}) {
65
+ super(descriptor)
66
+ this.color = descriptor.color ? new DefaultStyleColor(descriptor.color) : new DefaultStyleColor({ value: '#ffffff' })
67
+ this.map = descriptor.map ?? ''
68
+ this.alphaMap = descriptor.alphaMap ?? ''
69
+ this.envMapIntensity = descriptor.envMapIntensity ?? 1
70
+ this.lightMapIntensity = descriptor.lightMapIntensity ?? 1
71
+ this.envMap = descriptor.envMap ?? ''
72
+ this.lightMap = descriptor.lightMap ?? ''
73
+
74
+ this.envMapRotation = Euler.create(descriptor.envMapRotation)
75
+ this.aoMap = descriptor.aoMap ?? ''
76
+ this.aoMapIntensity = descriptor.aoMapIntensity ?? 1
77
+ this.bumpMap = descriptor.bumpMap ?? ''
78
+ this.bumpScale = descriptor.bumpScale ?? 1
79
+ this.displacementMap = descriptor.displacementMap ?? ''
80
+ this.displacementScale = descriptor.displacementScale ?? 1
81
+ this.displacementBias = descriptor.displacementBias ?? 0
82
+ this.emissive = descriptor.emissive ?? '#000000'
83
+ this.emissiveMap = descriptor.emissiveMap ?? ''
84
+ this.emissiveIntensity = descriptor.emissiveIntensity ?? 1
85
+ this.metalness = descriptor.metalness ?? 0
86
+ this.metalnessMap = descriptor.metalnessMap ?? ''
87
+ this.normalMap = descriptor.normalMap ?? ''
88
+ this.normalMapType = descriptor.normalMapType ?? MaterialNormalMapType.TangentSpaceNormalMap
89
+ this.normalScale = descriptor.normalScale ? Vector2.create(descriptor.normalScale) : Vector2.create(1, 1)
90
+ this.roughness = descriptor.roughness ?? 1
91
+ this.roughnessMap = descriptor.roughnessMap ?? ''
92
+ this.flatShading = descriptor.flatShading ?? false
93
+ this.fog = descriptor.fog ?? true
94
+ this.wireframe = descriptor.wireframe ?? false
95
+ }
96
+ }
97
+ MaterialDescriptor.register(MeshStandardMaterialDescriptor)
98
+
99
+ export { MeshStandardMaterialDescriptor }
@@ -0,0 +1,31 @@
1
+ import { DefaultStyleColor, DeserializationObject } from "@vyr/engine"
2
+ import { MaterialDescriptor } from "./MaterialDescriptor"
3
+
4
+ class PointsMaterialDescriptor extends MaterialDescriptor {
5
+ static type = 'PointsMaterial'
6
+ /**漫反射颜色 */
7
+ color: DefaultStyleColor
8
+ /**漫反射贴图 */
9
+ map: string
10
+ /**透明度贴图 */
11
+ alphaMap: string
12
+ /**点的的大小 */
13
+ size: number
14
+ /**点的大小是否会被相机深度衰减 */
15
+ sizeAttenuation: boolean
16
+ /**材质是否受雾影响。默认为true。 */
17
+ fog: boolean
18
+
19
+ constructor(descriptor: Partial<DeserializationObject<PointsMaterialDescriptor>> = {}) {
20
+ super(descriptor)
21
+ this.color = descriptor.color ? new DefaultStyleColor(descriptor.color) : new DefaultStyleColor({ value: '#ffffff' })
22
+ this.map = descriptor.map ?? ''
23
+ this.alphaMap = descriptor.alphaMap ?? ''
24
+ this.size = descriptor.size ?? 1
25
+ this.sizeAttenuation = descriptor.sizeAttenuation ?? true
26
+ this.fog = descriptor.fog ?? true
27
+ }
28
+ }
29
+ MaterialDescriptor.register(PointsMaterialDescriptor)
30
+
31
+ export { PointsMaterialDescriptor }
@@ -0,0 +1,35 @@
1
+ import { DeserializationObject } from "@vyr/engine"
2
+ import { MaterialDescriptor } from "./MaterialDescriptor"
3
+
4
+ interface ShaderMaterialAttribute {
5
+ uniforms: { [k: string]: any },
6
+ fragmentShader: string
7
+ vertexShader: string
8
+ }
9
+
10
+ class ShaderMaterialDescriptor extends MaterialDescriptor {
11
+ static type = 'ShaderMaterial'
12
+ /**材质是否受到光照的影响 */
13
+ lights: boolean
14
+ /**定义材质是否使用平面着色进行渲染 */
15
+ flatShading: boolean
16
+ /**材质是否受雾影响。默认为true。 */
17
+ fog: boolean
18
+ /**将几何体渲染为线框。默认值为false */
19
+ wireframe: boolean
20
+ /**着色器材质所需的资产 */
21
+ shader: string
22
+
23
+ constructor(descriptor: Partial<DeserializationObject<ShaderMaterialDescriptor>> = {}) {
24
+ super(descriptor)
25
+ this.lights = descriptor.lights ?? false
26
+ this.vertexColors = descriptor.vertexColors ?? false
27
+ this.flatShading = descriptor.flatShading ?? false
28
+ this.fog = descriptor.fog ?? true
29
+ this.wireframe = descriptor.wireframe ?? false
30
+ this.shader = descriptor.shader ?? ''
31
+ }
32
+ }
33
+ MaterialDescriptor.register(ShaderMaterialDescriptor)
34
+
35
+ export { ShaderMaterialAttribute, ShaderMaterialDescriptor }
@@ -0,0 +1,19 @@
1
+ import { DefaultStyleColor, DeserializationObject } from "@vyr/engine"
2
+ import { MaterialDescriptor } from "./MaterialDescriptor"
3
+
4
+ class ShadowMaterialDescriptor extends MaterialDescriptor {
5
+ static type = 'ShadowMaterial'
6
+ /**漫反射颜色 */
7
+ color: DefaultStyleColor
8
+ /**材质是否受雾影响。默认为true。 */
9
+ fog: boolean
10
+
11
+ constructor(descriptor: Partial<DeserializationObject<ShadowMaterialDescriptor>> = {}) {
12
+ super(descriptor)
13
+ this.color = descriptor.color ? new DefaultStyleColor(descriptor.color) : new DefaultStyleColor({ value: '#ffffff' })
14
+ this.fog = descriptor.fog ?? true
15
+ }
16
+ }
17
+ MaterialDescriptor.register(ShadowMaterialDescriptor)
18
+
19
+ export { ShadowMaterialDescriptor }
@@ -0,0 +1,31 @@
1
+ import { DefaultStyleColor, DeserializationObject } from "@vyr/engine"
2
+ import { MaterialDescriptor } from "./MaterialDescriptor"
3
+
4
+ class SpriteMaterialDescriptor extends MaterialDescriptor {
5
+ static type = 'SpriteMaterial'
6
+ /**漫反射颜色 */
7
+ color: DefaultStyleColor
8
+ /**漫反射贴图 */
9
+ map: string
10
+ /**透明度贴图 */
11
+ alphaMap: string
12
+ /**sprite的转动 */
13
+ rotation: number
14
+ /**精灵的大小是否会被相机深度衰减 */
15
+ sizeAttenuation: boolean
16
+ /**材质是否受雾影响。默认为true。 */
17
+ fog: boolean
18
+
19
+ constructor(descriptor: Partial<DeserializationObject<SpriteMaterialDescriptor>> = {}) {
20
+ super(descriptor)
21
+ this.color = descriptor.color ? new DefaultStyleColor(descriptor.color) : new DefaultStyleColor({ value: '#ffffff' })
22
+ this.map = descriptor.map ?? ''
23
+ this.alphaMap = descriptor.alphaMap ?? ''
24
+ this.rotation = descriptor.rotation ?? 0
25
+ this.sizeAttenuation = descriptor.sizeAttenuation ?? true
26
+ this.fog = descriptor.fog ?? true
27
+ }
28
+ }
29
+ MaterialDescriptor.register(SpriteMaterialDescriptor)
30
+
31
+ export { SpriteMaterialDescriptor }
@@ -0,0 +1,110 @@
1
+ import * as THREE from 'three'
2
+ import { Descriptor, DeserializationObject, Vector2 } from '@vyr/engine'
3
+
4
+ enum TextureMapping {
5
+ UVMapping = THREE.UVMapping,
6
+ CubeReflectionMapping = THREE.CubeReflectionMapping,
7
+ CubeRefractionMapping = THREE.CubeRefractionMapping,
8
+ EquirectangularReflectionMapping = THREE.EquirectangularReflectionMapping,
9
+ EquirectangularRefractionMapping = THREE.EquirectangularRefractionMapping,
10
+ CubeUVReflectionMapping = THREE.CubeUVReflectionMapping,
11
+ }
12
+ enum TextureWrap {
13
+ RepeatWrapping = THREE.RepeatWrapping,
14
+ ClampToEdgeWrapping = THREE.ClampToEdgeWrapping,
15
+ MirroredRepeatWrapping = THREE.MirroredRepeatWrapping,
16
+ }
17
+ enum TextureFType {
18
+ UnsignedByteType = THREE.UnsignedByteType,
19
+ ByteType = THREE.ByteType,
20
+ ShortType = THREE.ShortType,
21
+ UnsignedShortType = THREE.UnsignedShortType,
22
+ IntType = THREE.IntType,
23
+ UnsignedIntType = THREE.UnsignedIntType,
24
+ FloatType = THREE.FloatType,
25
+ HalfFloatType = THREE.HalfFloatType,
26
+ UnsignedShort4444Type = THREE.UnsignedShort4444Type,
27
+ UnsignedShort5551Type = THREE.UnsignedShort5551Type,
28
+ UnsignedInt248Type = THREE.UnsignedInt248Type,
29
+ UnsignedInt5999Type = THREE.UnsignedInt5999Type,
30
+ }
31
+ enum TextureFormat {
32
+ AlphaFormat = THREE.AlphaFormat,
33
+ RedFormat = THREE.RedFormat,
34
+ RedIntegerFormat = THREE.RedIntegerFormat,
35
+ RGFormat = THREE.RGFormat,
36
+ RGIntegerFormat = THREE.RGIntegerFormat,
37
+ RGBFormat = THREE.RGBFormat,
38
+ RGBAFormat = THREE.RGBAFormat,
39
+ RGBAIntegerFormat = THREE.RGBAIntegerFormat,
40
+ DepthFormat = THREE.DepthFormat,
41
+ DepthStencilFormat = THREE.DepthStencilFormat,
42
+ }
43
+ const TextureColorSpace = {
44
+ NoColorSpace: THREE.NoColorSpace,
45
+ SRGBColorSpace: THREE.SRGBColorSpace,
46
+ LinearSRGBColorSpace: THREE.LinearSRGBColorSpace,
47
+ } as const
48
+
49
+ class TextureDescriptor extends Descriptor {
50
+ static type = 'Texture'
51
+ url: string
52
+
53
+ /**图像将如何应用到物体(对象)上。
54
+ *
55
+ * - 1
56
+ */
57
+ mapping: number
58
+ /**这个值定义了纹理贴图在水平方向上将如何包裹
59
+ *
60
+ * - 1
61
+ */
62
+ wrapS: number
63
+ /**这个值定义了纹理贴图在垂直方向上将如何包裹
64
+ *
65
+ * - 1
66
+ */
67
+ wrapT: number
68
+ /**定义shader(着色器)将如何读取的2D纹理或者texels(纹理元素)的元素
69
+ *
70
+ */
71
+ format: number
72
+ /**这个值必须与format相对应 */
73
+ ftype: number
74
+ offset: Vector2
75
+ repeat: Vector2
76
+ center: Vector2
77
+ rotation: number
78
+ generateMipmaps: boolean
79
+ premultiplyAlpha: boolean
80
+ flipY: boolean
81
+ colorSpace: string
82
+
83
+ constructor(descriptor: Partial<DeserializationObject<TextureDescriptor>> = {}) {
84
+ super(descriptor)
85
+ this.url = descriptor.url ?? ''
86
+ this.mapping = descriptor.mapping ?? TextureMapping.UVMapping
87
+ this.wrapS = descriptor.wrapS ?? TextureWrap.ClampToEdgeWrapping
88
+ this.wrapT = descriptor.wrapT ?? TextureWrap.ClampToEdgeWrapping
89
+ this.format = descriptor.format ?? TextureFormat.RGBAFormat
90
+ this.ftype = descriptor.ftype ?? TextureFType.UnsignedByteType
91
+ this.offset = Vector2.create(descriptor.offset)
92
+ this.repeat = descriptor.repeat ? Vector2.create(descriptor.repeat) : Vector2.create(1, 1)
93
+ this.center = Vector2.create(descriptor.center)
94
+ this.rotation = descriptor.rotation ?? 0
95
+ this.generateMipmaps = descriptor.generateMipmaps ?? true
96
+ this.premultiplyAlpha = descriptor.premultiplyAlpha ?? false
97
+ this.flipY = descriptor.flipY ?? true
98
+ this.colorSpace = descriptor.colorSpace ?? TextureColorSpace.SRGBColorSpace
99
+ }
100
+ }
101
+ Descriptor.register(TextureDescriptor)
102
+
103
+ export {
104
+ TextureMapping,
105
+ TextureWrap,
106
+ TextureFType,
107
+ TextureFormat,
108
+ TextureColorSpace,
109
+ TextureDescriptor,
110
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * as THREE from 'three'
2
+ export * from './locale'
3
+ export * from './utils'
4
+ export * from './asset'
5
+ export * from './descriptor'
6
+ export * from './actor'
7
+ export * from './interpreter'
8
+ export * from './preset'
9
+ export * from './controls'
@@ -0,0 +1,25 @@
1
+ // import { UpdateArgs } from '@vyr/engine'
2
+ // import { ComposerServiceDescriptor } from '../descriptor/ComposerServiceDescriptor'
3
+ // import { SceneServiceInterpreter } from './SceneServiceInterpreter'
4
+ // import { ComposerServiceActor } from '../actor'
5
+
6
+ // class ComposerServiceInterpreter extends SceneServiceInterpreter {
7
+ // static type = ComposerServiceDescriptor.type
8
+
9
+ // protected createActor(descriptor: ComposerServiceDescriptor, args: UpdateArgs) {
10
+ // const actor = new ComposerServiceActor(descriptor)
11
+ // return actor
12
+ // }
13
+
14
+ // protected setSize(actor: ComposerServiceActor) {
15
+ // const rect = super.setSize(actor)
16
+ // const descriptor = ComposerServiceDescriptor.get<ComposerServiceDescriptor>(this.unit.uuid)
17
+ // const composer = actor.getEffectComposer(descriptor)
18
+ // composer.setSize(rect.width, rect.height)
19
+ // return rect
20
+ // }
21
+ // }
22
+
23
+ // SceneServiceInterpreter.register(ComposerServiceInterpreter)
24
+
25
+ // export { ComposerServiceInterpreter }
@@ -0,0 +1,253 @@
1
+ import { Material, Mesh, Object3D, Vector2 as _V2, BufferGeometry } from "three";
2
+ import { Asset, AsyncTask, Category, Data, DatasetDescriptor, Descriptor, Generate, Graphics, Interpreter, JsonAsset, observer, PrefabeDescriptor, PrefabInstanceDescriptor, Queue, RoutineDescriptor, RoutineNode, Unit, UpdateArgs, Vector2 } from "@vyr/engine";
3
+ import { ExtrudeGeometryDescriptor, GeoMapDescriptor, GeometryDescriptor, HTMLConvertDescriptor, PlaneGeometryDescriptor, TubeGeometryDescriptor } from '../descriptor'
4
+ import { NodeInterpreter, PickupNode } from "./NodeInterpreter";
5
+ import { material, diaposeObject3D, collectionPickupResult } from "../utils";
6
+ import { NodeActor } from "../actor";
7
+ import { executePreset, routinePreset } from "../preset";
8
+
9
+ interface GeoFeature<T extends BufferGeometry = BufferGeometry> {
10
+ url: string
11
+ descriptor: GeometryDescriptor
12
+ interpreter: Interpreter
13
+ dataset: string
14
+ mesh: Mesh<T>
15
+ }
16
+
17
+ type GeometryFactory<T extends GeometryDescriptor = GeometryDescriptor> = (url: string, dataset: string, feature: JsonAsset, offset: Vector2) => T
18
+
19
+ const tubeFactory: GeometryFactory = (url: string, dataset: string, feature: JsonAsset, offset: Vector2) => {
20
+ const descriptor = new TubeGeometryDescriptor({ name: feature.properties.adcode, track: dataset, offset, radius: 0.05, tubularSegments: 1000 })
21
+ Asset.set(url, descriptor)
22
+
23
+ let datasetDescriptor = Asset.get<DatasetDescriptor>(dataset)
24
+ if (datasetDescriptor === null) {
25
+ datasetDescriptor = new DatasetDescriptor({ name: feature.properties.adcode })
26
+ let data
27
+ if (feature.geometry.type === 'MultiPolygon') {
28
+ data = feature.geometry.coordinates[0][0]
29
+ } else if (feature.geometry.type === 'Polygon') {
30
+ data = feature.geometry.coordinates[0]
31
+ } else {
32
+ data = []
33
+ }
34
+ datasetDescriptor.setData(data)
35
+ Asset.set(dataset, datasetDescriptor)
36
+ }
37
+
38
+ return descriptor
39
+ }
40
+
41
+ const shadowFactory: GeometryFactory = (url: string, dataset: string, feature: JsonAsset, offset: Vector2) => {
42
+ const descriptor = new PlaneGeometryDescriptor({ name: feature.properties.adcode, width: 100, height: 100 })
43
+ Asset.set(url, descriptor)
44
+
45
+ return descriptor
46
+ }
47
+
48
+ const extrudeFactory: GeometryFactory = (url: string, dataset: string, feature: JsonAsset, offset: Vector2) => {
49
+ const descriptor = new ExtrudeGeometryDescriptor({ name: feature.properties.adcode, shapes: dataset, offset, flattenUVsToPlane: true })
50
+ Asset.set(url, descriptor)
51
+
52
+ let datasetDescriptor = Asset.get<DatasetDescriptor>(dataset)
53
+ if (datasetDescriptor === null) {
54
+ datasetDescriptor = new DatasetDescriptor({ name: feature.properties.adcode })
55
+ let data
56
+ if (feature.geometry.type === 'MultiPolygon') {
57
+ data = feature.geometry.coordinates
58
+ } else {
59
+ data = []
60
+ }
61
+ datasetDescriptor.setData(data)
62
+ Asset.set(dataset, datasetDescriptor)
63
+ }
64
+
65
+ return descriptor
66
+ }
67
+
68
+ class GeoMapInterpreter extends NodeInterpreter {
69
+ static type = GeoMapDescriptor.type
70
+ private _task: AsyncTask | null = null
71
+ readonly wrapper = new Object3D()
72
+ readonly features: GeoFeature[] = []
73
+ readonly labels: HTMLConvertDescriptor[] = []
74
+ readonly routines: RoutineDescriptor[] = []
75
+
76
+ protected createActor(descriptor: Descriptor, args: UpdateArgs) {
77
+ const actor = new NodeActor(new Object3D())
78
+ actor.object.add(this.wrapper)
79
+ return actor
80
+ }
81
+
82
+ private createLabel(descriptor: GeoMapDescriptor, prefab: PrefabeDescriptor, featureData: Data, feature: JsonAsset, offset: Vector2) {
83
+ const point = feature.properties.centroid ?? feature.properties.center
84
+ if (!point) return null
85
+
86
+ const label = new HTMLConvertDescriptor({})
87
+ label.position.x = point[0] + offset.x
88
+ label.position.y = point[1] + offset.y
89
+ label.position.z = 2
90
+ label.scale.x = 0.05
91
+ label.scale.y = 0.05
92
+ label.scale.z = 0.05
93
+
94
+ const clone = PrefabInstanceDescriptor.fromPrefab(descriptor.label, prefab)
95
+ label.add(clone)
96
+
97
+ const datasetUrl = Asset.createVirtualUrl(`GeoMap/dataset/label/${feature.properties.adcode}${Category.datasetSuffix}`)
98
+ const dataset = new DatasetDescriptor()
99
+ dataset.setData(featureData)
100
+ Asset.set(datasetUrl, dataset)
101
+
102
+ const inputs = {
103
+ [routinePreset.GeoMap.drilldown.nodes.drilldown]: executePreset.GeoMap.drilldown.createExecuteInput({
104
+ dataset,
105
+ geoMap: descriptor,
106
+ })
107
+ }
108
+ clone.traverse(sub => {
109
+ sub.dataset = datasetUrl
110
+ sub.interactions.push({
111
+ uuid: Generate.uuid(),
112
+ type: "click",
113
+ url: routinePreset.GeoMap.drilldown.url,
114
+ inputs,
115
+ })
116
+ })
117
+
118
+ return label
119
+ }
120
+ private _createGeoData(fullJson: JsonAsset) {
121
+ const data: Data = {}
122
+ for (const feature of fullJson.features) {
123
+ data[feature.properties.adcode] = feature.properties
124
+ }
125
+ return data
126
+ }
127
+ buildLabel(descriptor: GeoMapDescriptor, fullJson: JsonAsset, offset: Vector2, args: UpdateArgs) {
128
+ const prefab = Asset.get<PrefabeDescriptor>(descriptor.label)
129
+ if (prefab === null) return
130
+ const dataset = Asset.get<DatasetDescriptor>(descriptor.dataset)
131
+ const data = dataset === null ? this._createGeoData(fullJson) : dataset.getData<Data>()
132
+
133
+ for (const feature of fullJson.features) {
134
+ const featureData = data[feature.properties.adcode]
135
+ const label = this.createLabel(descriptor, prefab, featureData, feature, offset)
136
+ if (label === null) continue
137
+ this.labels.push(label)
138
+ observer.trigger('add', { puid: this.unit.uuid, self: label.uuid })
139
+ }
140
+ }
141
+
142
+ buildFeature(feature: JsonAsset, materials: Material | Material[], offset: Vector2, factory: GeometryFactory, args: UpdateArgs, flag: string) {
143
+ const geometryUrl = Asset.createVirtualUrl(`GeoMap/geometry/${flag}/${feature.properties.adcode}${Category.geometrySuffix}`)
144
+ const datasetUrl = Asset.createVirtualUrl(`GeoMap/dataset/${flag}/${feature.properties.adcode}${Category.datasetSuffix}`)
145
+
146
+ let geometry = Asset.get<GeometryDescriptor>(geometryUrl)
147
+ if (geometry === null) {
148
+ geometry = factory(geometryUrl, datasetUrl, feature, offset)
149
+ }
150
+ const interpreter = Graphics.createInterpreter(geometry, this.graphics)
151
+ //@ts-ignore
152
+ interpreter.unit = new Unit(geometry.uuid, '', this.unit.queue)
153
+ interpreter.update(geometry, args)
154
+ const actor = interpreter.getActor(geometry, args)
155
+
156
+ const mesh = new Mesh(actor.object, materials)
157
+
158
+ this.wrapper.add(mesh)
159
+
160
+ const item: GeoFeature = { url: geometryUrl, descriptor: geometry, interpreter, dataset: datasetUrl, mesh }
161
+
162
+ return item
163
+ }
164
+
165
+ buildBorder(fullJson: JsonAsset, materials: Material | Material[], offset: Vector2, features: GeoFeature[], args: UpdateArgs) {
166
+ for (const feature of fullJson.features) {
167
+ const item = this.buildFeature(feature, materials, offset, tubeFactory, args, 'border')
168
+ item.mesh.position.z = 1.22
169
+ features.push(item)
170
+ }
171
+ }
172
+
173
+ buildShadow(feature: JsonAsset, materials: Material | Material[], offset: Vector2, args: UpdateArgs) {
174
+ const region = this.buildFeature(feature, materials, offset, shadowFactory, args, 'shadow')
175
+ this.features.push(region)
176
+ return region
177
+ }
178
+
179
+ buildRegion(feature: JsonAsset, materials: Material | Material[], offset: Vector2, args: UpdateArgs) {
180
+ const region = this.buildFeature(feature, materials, offset, extrudeFactory, args, 'region')
181
+ this.features.push(region)
182
+ return region
183
+ }
184
+
185
+ async build(descriptor: GeoMapDescriptor, args: UpdateArgs) {
186
+ const geojson = Asset.get<JsonAsset>(descriptor.geojsonRegion)
187
+ if (Array.isArray(geojson.features) === false || geojson.features.length === 0) return
188
+
189
+ const regionMaterials = material.getMaterial(descriptor.material, this.graphics, args)
190
+ const borderMaterial = descriptor.borderMaterial ? material.getMaterial(descriptor.borderMaterial, this.graphics, args) : regionMaterials
191
+
192
+ const regionJson = geojson.features[0]
193
+ const offset = new Vector2(-regionJson.properties.centroid[0], -regionJson.properties.centroid[1])
194
+ const region = this.buildRegion(regionJson, regionMaterials, offset, args)
195
+ region.mesh.castShadow = descriptor.castShadow
196
+
197
+ if (descriptor.shadowMaterial) {
198
+ const shadowMaterials = material.getMaterial(descriptor.shadowMaterial, this.graphics, args)
199
+ const shadow = this.buildShadow(regionJson, shadowMaterials, offset, args)
200
+ shadow.mesh.receiveShadow = descriptor.castShadow
201
+ }
202
+
203
+ const fullJson = Asset.get<JsonAsset>(descriptor.geojsonBorder)
204
+ if (fullJson !== null && Array.isArray(fullJson.features)) {
205
+ if (descriptor.label) this.buildLabel(descriptor, fullJson, offset, args)
206
+ this.buildBorder(fullJson, borderMaterial, offset, this.features, args)
207
+ }
208
+ }
209
+
210
+ async clear() {
211
+ this.wrapper.clear()
212
+ for (const feature of this.features) {
213
+ diaposeObject3D(feature.mesh)
214
+ Asset.unload(feature.url)
215
+ Asset.unload(feature.dataset)
216
+ }
217
+ this.features.length = 0
218
+ for (const label of this.labels) {
219
+ observer.trigger('remove', { puid: this.unit.uuid, self: label.uuid })
220
+ Asset.unload(label.dataset)
221
+ }
222
+ this.labels.length = 0
223
+ if (this._task !== null) this._task.cancel()
224
+ }
225
+
226
+ update(descriptor: GeoMapDescriptor, args: UpdateArgs) {
227
+ super.update(descriptor, args)
228
+
229
+ this.wrapper.layers.set(descriptor.layer)
230
+ this.wrapper.visible = descriptor.visible
231
+
232
+ this.clear()
233
+ if (descriptor.geojsonRegion) this.build(descriptor, args)
234
+ }
235
+
236
+ unmount(descriptor: GeoMapDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
237
+ this.clear()
238
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
239
+ }
240
+
241
+ free(descriptor: GeoMapDescriptor, args: UpdateArgs) {
242
+ this.clear()
243
+ super.free(descriptor, args)
244
+ }
245
+
246
+ pickup(descriptor: GeoMapDescriptor, args: UpdateArgs, result: PickupNode[]) {
247
+ if (descriptor.visible === false) return
248
+ collectionPickupResult(this.wrapper, true, descriptor, result)
249
+ }
250
+ }
251
+ NodeInterpreter.register(GeoMapInterpreter)
252
+
253
+ export { GeoMapInterpreter }
@@ -0,0 +1,31 @@
1
+ import { Object3D } from 'three'
2
+ import { Descriptor, Interpreter, PickupObject, UpdateArgs } from "@vyr/engine";
3
+ import { HTMLConvertDescriptor } from "../descriptor";
4
+ import { NodeInterpreter } from "./NodeInterpreter";
5
+ import { HTMLConvertActor } from '../actor';
6
+
7
+ class HTMLConvertInterpreter extends NodeInterpreter {
8
+ static type = HTMLConvertDescriptor.type
9
+
10
+ protected createActor(descriptor: Descriptor, args: UpdateArgs) {
11
+ const actor = new HTMLConvertActor(new Object3D())
12
+ return actor
13
+ }
14
+
15
+ unmount(descriptor: HTMLConvertDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
16
+ const actor = this.getActor<HTMLConvertActor>(descriptor, args)
17
+ actor.clear()
18
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
19
+ }
20
+
21
+ free(descriptor: HTMLConvertDescriptor, args: UpdateArgs) {
22
+ const actor = this.getActor<HTMLConvertActor>(descriptor, args)
23
+ actor.clear()
24
+ super.free(descriptor, args)
25
+ }
26
+
27
+ pickup(descriptor: HTMLConvertDescriptor, args: UpdateArgs, result: PickupObject[]) { }
28
+ }
29
+ NodeInterpreter.register(HTMLConvertInterpreter)
30
+
31
+ export { HTMLConvertInterpreter }