@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.
- package/package.json +26 -0
- package/src/actor/ComposerServiceActor.ts +107 -0
- package/src/actor/GeometryActor.ts +13 -0
- package/src/actor/HTMLConvertActor.ts +55 -0
- package/src/actor/MaterialActor.ts +13 -0
- package/src/actor/NodeActor.ts +25 -0
- package/src/actor/OrbitControllerActor.ts +110 -0
- package/src/actor/PassActor.ts +24 -0
- package/src/actor/SceneServiceActor.ts +122 -0
- package/src/actor/TextureActor.ts +13 -0
- package/src/actor/TransformControllerActor.ts +23 -0
- package/src/actor/index.ts +10 -0
- package/src/asset/index.ts +187 -0
- package/src/controls/CameraControls.ts +2360 -0
- package/src/controls/TransformControls.ts +1747 -0
- package/src/controls/index.ts +2 -0
- package/src/descriptor/ComposerServiceDescriptor.ts +47 -0
- package/src/descriptor/GeoMapDescriptor.ts +24 -0
- package/src/descriptor/HTMLConvertDescriptor.ts +12 -0
- package/src/descriptor/InstancedMeshDescriptor.ts +21 -0
- package/src/descriptor/MeshDescriptor.ts +16 -0
- package/src/descriptor/ModelDescriptor.ts +15 -0
- package/src/descriptor/OrbitControllerDescriptor.ts +84 -0
- package/src/descriptor/OrthographicCameraDescriptor.ts +12 -0
- package/src/descriptor/ParticleDescriptor.ts +88 -0
- package/src/descriptor/PassDescriptor.ts +33 -0
- package/src/descriptor/PerspectiveCameraDescriptor.ts +15 -0
- package/src/descriptor/PointsDescriptor.ts +16 -0
- package/src/descriptor/SceneServiceDescriptor.ts +39 -0
- package/src/descriptor/SpriteDescriptor.ts +16 -0
- package/src/descriptor/TextDescriptor.ts +41 -0
- package/src/descriptor/TransformControllerDescriptor.ts +32 -0
- package/src/descriptor/animation/AnimationActionDescriptor.ts +52 -0
- package/src/descriptor/geometry/BoxGeometryDescriptor.ts +26 -0
- package/src/descriptor/geometry/BufferGeometryDescriptor.ts +15 -0
- package/src/descriptor/geometry/CircleGeometryDescriptor.ts +22 -0
- package/src/descriptor/geometry/CylinderGeometryDescriptor.ts +30 -0
- package/src/descriptor/geometry/ExtrudeGeometryDescriptor.ts +35 -0
- package/src/descriptor/geometry/GeometryDescriptor.ts +8 -0
- package/src/descriptor/geometry/PlaneGeometryDescriptor.ts +22 -0
- package/src/descriptor/geometry/RingGeometryDescriptor.ts +26 -0
- package/src/descriptor/geometry/SphereGeometryDescriptor.ts +27 -0
- package/src/descriptor/geometry/SurfaceGeometryDescriptor.ts +15 -0
- package/src/descriptor/geometry/TubeGeometryDescriptor.ts +25 -0
- package/src/descriptor/helper/AxesHelperDescriptor.ts +8 -0
- package/src/descriptor/index.ts +45 -0
- package/src/descriptor/light/AmbientLightDescriptor.ts +8 -0
- package/src/descriptor/light/DirectionalLightDescriptor.ts +33 -0
- package/src/descriptor/light/HemisphereLightDescriptor.ts +16 -0
- package/src/descriptor/light/LightDescriptor.ts +16 -0
- package/src/descriptor/light/PointLightDescriptor.ts +24 -0
- package/src/descriptor/light/RectAreaLightDescriptor.ts +20 -0
- package/src/descriptor/light/SpotLightDescriptor.ts +30 -0
- package/src/descriptor/material/MaterialDescriptor.ts +84 -0
- package/src/descriptor/material/MeshBasicMaterialDescriptor.ts +53 -0
- package/src/descriptor/material/MeshPhongMaterialDescriptor.ts +102 -0
- package/src/descriptor/material/MeshStandardMaterialDescriptor.ts +99 -0
- package/src/descriptor/material/PointsMaterialDescriptor.ts +31 -0
- package/src/descriptor/material/ShaderMaterialDescriptor.ts +35 -0
- package/src/descriptor/material/ShadowMaterialDescriptor.ts +19 -0
- package/src/descriptor/material/SpriteMaterialDescriptor.ts +31 -0
- package/src/descriptor/texture/TextureDescriptor.ts +110 -0
- package/src/index.ts +9 -0
- package/src/interpreter/ComposerServiceInterpreter.ts +25 -0
- package/src/interpreter/GeoMapInterpreter.ts +253 -0
- package/src/interpreter/HTMLConvertInterpreter.ts +31 -0
- package/src/interpreter/InstancedMeshInterpreter.ts +76 -0
- package/src/interpreter/MeshInterpreter.ts +25 -0
- package/src/interpreter/ModelInterpreter.ts +61 -0
- package/src/interpreter/NodeInterpreter.ts +65 -0
- package/src/interpreter/OrbitControllerInterpreter.ts +47 -0
- package/src/interpreter/OrthographicCameraInterpreter.ts +13 -0
- package/src/interpreter/ParticleInterpreter.ts +221 -0
- package/src/interpreter/PassInterpreter.ts +43 -0
- package/src/interpreter/PerspectiveCameraInterpreter.ts +33 -0
- package/src/interpreter/PointsInterpreter.ts +61 -0
- package/src/interpreter/SceneServiceInterpreter.ts +119 -0
- package/src/interpreter/ServiceSchedulerInterpreter.ts +23 -0
- package/src/interpreter/SpriteInterpreter.ts +45 -0
- package/src/interpreter/TextInterpreter.ts +76 -0
- package/src/interpreter/TransformControllerInterpreter.ts +44 -0
- package/src/interpreter/animation/AnimationActionInterpreter.ts +66 -0
- package/src/interpreter/geometry/BoxGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/BufferGeometryInterpreter.ts +47 -0
- package/src/interpreter/geometry/CircleGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/CylinderGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/ExtrudeGeometryInterpreter.ts +55 -0
- package/src/interpreter/geometry/PlaneGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/RingGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/SphereGeometryInterpreter.ts +34 -0
- package/src/interpreter/geometry/SurfaceGeometryInterpreter.ts +39 -0
- package/src/interpreter/geometry/TubeGeometryInterpreter.ts +42 -0
- package/src/interpreter/helper/AxesHelperInterpreter.ts +38 -0
- package/src/interpreter/index.ts +45 -0
- package/src/interpreter/light/AmbientLightInterpreter.ts +30 -0
- package/src/interpreter/light/DirectionalLightInterpreter.ts +84 -0
- package/src/interpreter/light/HemisphereLightInterpreter.ts +32 -0
- package/src/interpreter/light/PointLightInterpreter.ts +46 -0
- package/src/interpreter/light/RectAreaLightInterpreter.ts +34 -0
- package/src/interpreter/light/SpotLightInterpreter.ts +68 -0
- package/src/interpreter/material/MaterialInterpreter.ts +34 -0
- package/src/interpreter/material/MeshBasicMaterialInterpreter.ts +43 -0
- package/src/interpreter/material/MeshPhongMaterialInterpreter.ts +63 -0
- package/src/interpreter/material/MeshStandardMaterialInterpreter.ts +58 -0
- package/src/interpreter/material/PointsMaterialInterpreter.ts +36 -0
- package/src/interpreter/material/ShaderMaterialInterpreter.ts +51 -0
- package/src/interpreter/material/ShadowMaterialInterpreter.ts +31 -0
- package/src/interpreter/material/SpriteMaterialInterpreter.ts +36 -0
- package/src/interpreter/texture/TextureInterpreter.ts +59 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +16 -0
- package/src/locale/index.ts +2 -0
- package/src/preset/execute/GeoMap/drilldown.ts +61 -0
- package/src/preset/execute/GeoMap/index.ts +1 -0
- package/src/preset/execute/index.ts +1 -0
- package/src/preset/index.ts +7 -0
- package/src/preset/routine/GeoMap/drilldown.ts +26 -0
- package/src/preset/routine/GeoMap/index.ts +1 -0
- package/src/preset/routine/index.ts +1 -0
- package/src/utils/dispose/index.ts +23 -0
- package/src/utils/geometry/index.ts +82 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/material/index.ts +53 -0
- package/src/utils/pickup/index.ts +16 -0
- package/src/utils/random/index.ts +7 -0
- package/src/utils/text/index.ts +492 -0
- package/src/utils/texture/index.ts +19 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MeshStandardMaterial } from "three";
|
|
2
|
+
import { UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { MaterialInterpreter } from "./MaterialInterpreter";
|
|
4
|
+
import { MeshStandardMaterialDescriptor } from "../../descriptor";
|
|
5
|
+
import { MaterialActor } from "../../actor";
|
|
6
|
+
import { texture } from "../../utils";
|
|
7
|
+
|
|
8
|
+
class MeshStandardMaterialInterpreter extends MaterialInterpreter {
|
|
9
|
+
static type = MeshStandardMaterialDescriptor.type
|
|
10
|
+
|
|
11
|
+
protected createActor(descriptor: MeshStandardMaterialDescriptor, args: UpdateArgs) {
|
|
12
|
+
const actor = new MaterialActor(new MeshStandardMaterial())
|
|
13
|
+
return actor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setProperty(material: MeshStandardMaterial, descriptor: MeshStandardMaterialDescriptor) {
|
|
17
|
+
super.setProperty(material, descriptor)
|
|
18
|
+
|
|
19
|
+
material.color.setStyle(descriptor.color.value)
|
|
20
|
+
material.opacity = descriptor.color.opacity
|
|
21
|
+
material.lightMapIntensity = descriptor.lightMapIntensity
|
|
22
|
+
material.envMapIntensity = descriptor.envMapIntensity
|
|
23
|
+
material.envMapRotation.set(descriptor.envMapRotation.x, descriptor.envMapRotation.y, descriptor.envMapRotation.z)
|
|
24
|
+
material.bumpScale = descriptor.bumpScale
|
|
25
|
+
material.aoMapIntensity = descriptor.aoMapIntensity
|
|
26
|
+
material.displacementScale = descriptor.displacementScale
|
|
27
|
+
material.displacementBias = descriptor.displacementBias
|
|
28
|
+
material.emissive.setStyle(descriptor.emissive)
|
|
29
|
+
material.emissiveIntensity = descriptor.emissiveIntensity
|
|
30
|
+
material.metalness = descriptor.metalness
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
material.normalMapType = descriptor.normalMapType
|
|
33
|
+
material.normalScale.set(descriptor.normalScale.x, descriptor.normalScale.y)
|
|
34
|
+
material.roughness = descriptor.roughness
|
|
35
|
+
material.flatShading = descriptor.flatShading
|
|
36
|
+
material.fog = descriptor.fog
|
|
37
|
+
material.wireframe = descriptor.wireframe
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
update(descriptor: MeshStandardMaterialDescriptor, args: UpdateArgs) {
|
|
41
|
+
super.update(descriptor, args)
|
|
42
|
+
const actor = this.getActor<MaterialActor<MeshStandardMaterial>>(descriptor, args)
|
|
43
|
+
this.setProperty(actor.object, descriptor)
|
|
44
|
+
texture.setMap(actor.object, 'map', descriptor, this.graphics, args)
|
|
45
|
+
texture.setMap(actor.object, 'alphaMap', descriptor, this.graphics, args)
|
|
46
|
+
texture.setMap(actor.object, 'lightMap', descriptor, this.graphics, args)
|
|
47
|
+
texture.setMap(actor.object, 'aoMap', descriptor, this.graphics, args)
|
|
48
|
+
texture.setMap(actor.object, 'bumpMap', descriptor, this.graphics, args)
|
|
49
|
+
texture.setMap(actor.object, 'displacementMap', descriptor, this.graphics, args)
|
|
50
|
+
texture.setMap(actor.object, 'emissiveMap', descriptor, this.graphics, args)
|
|
51
|
+
texture.setMap(actor.object, 'metalnessMap', descriptor, this.graphics, args)
|
|
52
|
+
texture.setMap(actor.object, 'normalMap', descriptor, this.graphics, args)
|
|
53
|
+
texture.setMap(actor.object, 'roughnessMap', descriptor, this.graphics, args)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
MaterialInterpreter.register(MeshStandardMaterialInterpreter)
|
|
57
|
+
|
|
58
|
+
export { MeshStandardMaterialInterpreter }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PointsMaterial } from "three";
|
|
2
|
+
import { UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { MaterialInterpreter } from './MaterialInterpreter'
|
|
4
|
+
import { PointsMaterialDescriptor } from "../../descriptor";
|
|
5
|
+
import { MaterialActor } from "../../actor";
|
|
6
|
+
import { texture } from "../../utils";
|
|
7
|
+
|
|
8
|
+
class PointsMaterialInterpreter extends MaterialInterpreter {
|
|
9
|
+
static type = PointsMaterialDescriptor.type
|
|
10
|
+
|
|
11
|
+
protected createActor(descriptor: PointsMaterialDescriptor, args: UpdateArgs) {
|
|
12
|
+
const actor = new MaterialActor(new PointsMaterial())
|
|
13
|
+
return actor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setProperty(material: PointsMaterial, descriptor: PointsMaterialDescriptor) {
|
|
17
|
+
super.setProperty(material, descriptor)
|
|
18
|
+
|
|
19
|
+
material.color.setStyle(descriptor.color.value)
|
|
20
|
+
material.opacity = descriptor.color.opacity
|
|
21
|
+
material.size = descriptor.size
|
|
22
|
+
material.sizeAttenuation = descriptor.sizeAttenuation
|
|
23
|
+
material.fog = descriptor.fog
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
update(descriptor: PointsMaterialDescriptor, args: UpdateArgs) {
|
|
27
|
+
super.update(descriptor, args)
|
|
28
|
+
const actor = this.getActor<MaterialActor<PointsMaterial>>(descriptor, args)
|
|
29
|
+
this.setProperty(actor.object, descriptor)
|
|
30
|
+
texture.setMap(actor.object, 'map', descriptor, this.graphics, args)
|
|
31
|
+
texture.setMap(actor.object, 'alphaMap', descriptor, this.graphics, args)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
MaterialInterpreter.register(PointsMaterialInterpreter)
|
|
35
|
+
|
|
36
|
+
export { PointsMaterialInterpreter }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ShaderMaterial } from "three";
|
|
2
|
+
import { Asset, Scriptable, UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { MaterialInterpreter } from './MaterialInterpreter'
|
|
4
|
+
import { MaterialActor } from "../../actor";
|
|
5
|
+
import { ShaderMaterialAttribute, ShaderMaterialDescriptor } from "../../descriptor";
|
|
6
|
+
|
|
7
|
+
class ShaderMaterialInterpreter extends MaterialInterpreter {
|
|
8
|
+
static type = ShaderMaterialDescriptor.type
|
|
9
|
+
static defaultVertexShader = 'void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}'
|
|
10
|
+
static defaultFragmentShader = 'void main() { gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );}'
|
|
11
|
+
|
|
12
|
+
protected createActor(descriptor: ShaderMaterialDescriptor, args: UpdateArgs) {
|
|
13
|
+
const actor = new MaterialActor(new ShaderMaterial())
|
|
14
|
+
return actor
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setProperty(material: ShaderMaterial, descriptor: ShaderMaterialDescriptor) {
|
|
18
|
+
super.setProperty(material, descriptor)
|
|
19
|
+
material.lights = descriptor.lights
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
material.flatShading = descriptor.flatShading
|
|
22
|
+
material.fog = descriptor.fog
|
|
23
|
+
material.wireframe = descriptor.wireframe
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setShaderAsset(material: ShaderMaterial, descriptor: ShaderMaterialDescriptor, args: UpdateArgs) {
|
|
27
|
+
material.uniforms = {}
|
|
28
|
+
material.vertexShader = ShaderMaterialInterpreter.defaultVertexShader
|
|
29
|
+
material.fragmentShader = ShaderMaterialInterpreter.defaultFragmentShader
|
|
30
|
+
material.uniformsNeedUpdate = true
|
|
31
|
+
|
|
32
|
+
if (descriptor.shader) {
|
|
33
|
+
const shaderAsset = Asset.get<Scriptable>(descriptor.shader)
|
|
34
|
+
if (shaderAsset === null) return
|
|
35
|
+
const attribute: ShaderMaterialAttribute = shaderAsset.execute(descriptor, this.graphics, args)
|
|
36
|
+
material.uniforms = attribute.uniforms
|
|
37
|
+
material.fragmentShader = attribute.fragmentShader
|
|
38
|
+
material.vertexShader = attribute.vertexShader
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
update(descriptor: ShaderMaterialDescriptor, args: UpdateArgs) {
|
|
43
|
+
super.update(descriptor, args)
|
|
44
|
+
const actor = this.getActor<MaterialActor<ShaderMaterial>>(descriptor, args)
|
|
45
|
+
this.setProperty(actor.object, descriptor)
|
|
46
|
+
this.setShaderAsset(actor.object, descriptor, args)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
MaterialInterpreter.register(ShaderMaterialInterpreter)
|
|
50
|
+
|
|
51
|
+
export { ShaderMaterialInterpreter }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ShadowMaterial } from "three";
|
|
2
|
+
import { UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { MaterialInterpreter } from './MaterialInterpreter'
|
|
4
|
+
import { ShadowMaterialDescriptor } from "../../descriptor";
|
|
5
|
+
import { MaterialActor } from "../../actor";
|
|
6
|
+
|
|
7
|
+
class ShadowMaterialInterpreter extends MaterialInterpreter {
|
|
8
|
+
static type = ShadowMaterialDescriptor.type
|
|
9
|
+
|
|
10
|
+
protected createActor(descriptor: ShadowMaterialDescriptor, args: UpdateArgs) {
|
|
11
|
+
const actor = new MaterialActor(new ShadowMaterial())
|
|
12
|
+
return actor
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setProperty(material: ShadowMaterial, descriptor: ShadowMaterialDescriptor) {
|
|
16
|
+
super.setProperty(material, descriptor)
|
|
17
|
+
|
|
18
|
+
material.color.setStyle(descriptor.color.value)
|
|
19
|
+
material.opacity = descriptor.color.opacity
|
|
20
|
+
material.fog = descriptor.fog
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
update(descriptor: ShadowMaterialDescriptor, args: UpdateArgs) {
|
|
24
|
+
super.update(descriptor, args)
|
|
25
|
+
const actor = this.getActor<MaterialActor<ShadowMaterial>>(descriptor, args)
|
|
26
|
+
this.setProperty(actor.object, descriptor)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
MaterialInterpreter.register(ShadowMaterialInterpreter)
|
|
30
|
+
|
|
31
|
+
export { ShadowMaterialInterpreter }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SpriteMaterial } from "three";
|
|
2
|
+
import { UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { MaterialInterpreter } from './MaterialInterpreter'
|
|
4
|
+
import { SpriteMaterialDescriptor } from "../../descriptor";
|
|
5
|
+
import { MaterialActor } from "../../actor";
|
|
6
|
+
import { texture } from "../../utils";
|
|
7
|
+
|
|
8
|
+
class SpriteMaterialInterpreter extends MaterialInterpreter {
|
|
9
|
+
static type = SpriteMaterialDescriptor.type
|
|
10
|
+
|
|
11
|
+
protected createActor(descriptor: SpriteMaterialDescriptor, args: UpdateArgs) {
|
|
12
|
+
const actor = new MaterialActor(new SpriteMaterial())
|
|
13
|
+
return actor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setProperty(material: SpriteMaterial, descriptor: SpriteMaterialDescriptor) {
|
|
17
|
+
super.setProperty(material, descriptor)
|
|
18
|
+
|
|
19
|
+
material.color.setStyle(descriptor.color.value)
|
|
20
|
+
material.opacity = descriptor.color.opacity
|
|
21
|
+
material.rotation = descriptor.rotation
|
|
22
|
+
material.sizeAttenuation = descriptor.sizeAttenuation
|
|
23
|
+
material.fog = descriptor.fog
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
update(descriptor: SpriteMaterialDescriptor, args: UpdateArgs) {
|
|
27
|
+
super.update(descriptor, args)
|
|
28
|
+
const actor = this.getActor<MaterialActor<SpriteMaterial>>(descriptor, args)
|
|
29
|
+
this.setProperty(actor.object, descriptor)
|
|
30
|
+
texture.setMap(actor.object, 'map', descriptor, this.graphics, args)
|
|
31
|
+
texture.setMap(actor.object, 'alphaMap', descriptor, this.graphics, args)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
MaterialInterpreter.register(SpriteMaterialInterpreter)
|
|
35
|
+
|
|
36
|
+
export { SpriteMaterialInterpreter }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Texture } from "three";
|
|
2
|
+
import { Asset, Interpreter, UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { TextureDescriptor } from '../../descriptor'
|
|
4
|
+
import { TextureActor } from "../../actor";
|
|
5
|
+
|
|
6
|
+
class TextureInterpreter extends Interpreter {
|
|
7
|
+
static type = TextureDescriptor.type
|
|
8
|
+
|
|
9
|
+
protected createActor(descriptor: TextureDescriptor, args: UpdateArgs) {
|
|
10
|
+
const actor = new TextureActor(new Texture())
|
|
11
|
+
return actor
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setProperty(actor: TextureActor, descriptor: TextureDescriptor) {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
actor.object.mapping = descriptor.mapping
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
actor.object.wrapS = descriptor.wrapS
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
actor.object.wrapT = descriptor.wrapT
|
|
21
|
+
//@ts-ignore
|
|
22
|
+
actor.object.format = descriptor.format
|
|
23
|
+
//@ts-ignore
|
|
24
|
+
actor.object.type = descriptor.ftype
|
|
25
|
+
actor.object.colorSpace = descriptor.colorSpace
|
|
26
|
+
|
|
27
|
+
actor.object.offset.set(descriptor.offset.x, descriptor.offset.y)
|
|
28
|
+
actor.object.repeat.set(descriptor.repeat.x, descriptor.repeat.y)
|
|
29
|
+
actor.object.center.set(descriptor.center.x, descriptor.center.y)
|
|
30
|
+
actor.object.rotation = descriptor.rotation
|
|
31
|
+
actor.object.generateMipmaps = descriptor.generateMipmaps
|
|
32
|
+
actor.object.premultiplyAlpha = descriptor.premultiplyAlpha
|
|
33
|
+
actor.object.flipY = descriptor.flipY
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setImage(actor: TextureActor, descriptor: TextureDescriptor) {
|
|
37
|
+
if (descriptor.url) {
|
|
38
|
+
const image = Asset.get<HTMLImageElement>(descriptor.url)
|
|
39
|
+
if (image instanceof HTMLImageElement) actor.object.image = image
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
update(descriptor: TextureDescriptor, args: UpdateArgs) {
|
|
44
|
+
super.update(descriptor, args)
|
|
45
|
+
let actor = this.getActor<TextureActor>(descriptor, args)
|
|
46
|
+
this.setProperty(actor, descriptor)
|
|
47
|
+
this.setImage(actor, descriptor)
|
|
48
|
+
if (actor.object.image) actor.object.needsUpdate = true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
free(descriptor: TextureDescriptor, args: UpdateArgs) {
|
|
52
|
+
const actor = this.getActor<TextureActor>(descriptor, args)
|
|
53
|
+
actor.object.dispose()
|
|
54
|
+
super.free(descriptor, args)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
Interpreter.register(TextureInterpreter)
|
|
58
|
+
|
|
59
|
+
export { TextureInterpreter }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Locale } from "@vyr/locale";
|
|
2
|
+
import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
|
|
3
|
+
|
|
4
|
+
Locale.register(zhCnLanguageProvider)
|
|
5
|
+
|
|
6
|
+
const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
language
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LanguageProvider } from '@vyr/locale'
|
|
2
|
+
|
|
3
|
+
interface ZhCNLanguageProvider extends LanguageProvider {
|
|
4
|
+
'/virtual:/preset/GeoMap/drilldown.ts': string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
8
|
+
id: 'zh_CN',
|
|
9
|
+
name: '@vyr/three',
|
|
10
|
+
'/virtual:/preset/GeoMap/drilldown.ts': '地图下钻',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
ZhCNLanguageProvider,
|
|
15
|
+
zhCnLanguageProvider,
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Asset, Descriptor, Graphics, RoutineNode, Scriptable, UpdateArgs } from "@vyr/engine"
|
|
2
|
+
import { language } from '../../../locale'
|
|
3
|
+
import { GeoMapDescriptor } from "../../../descriptor"
|
|
4
|
+
|
|
5
|
+
const scriptable = Asset.createVirtualUrl('preset/GeoMap/drilldown.ts')
|
|
6
|
+
class RoutineScriptable extends Scriptable {
|
|
7
|
+
async execute(descriptor: Descriptor, graphics: Graphics, args: UpdateArgs) {
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
const { dataset, geoMap } = args.input.user
|
|
10
|
+
|
|
11
|
+
const data = dataset.value.getData()
|
|
12
|
+
if (data.level === "district") return
|
|
13
|
+
|
|
14
|
+
if (geoMap.value instanceof GeoMapDescriptor) {
|
|
15
|
+
const clips = geoMap.value.geojsonRegion.split('/')
|
|
16
|
+
clips.pop()
|
|
17
|
+
|
|
18
|
+
const root = clips.join('/')
|
|
19
|
+
geoMap.value.geojsonRegion = `${root}/${data.adcode}.json`
|
|
20
|
+
geoMap.value.geojsonBorder = `${root}/${data.adcode}_full.json`
|
|
21
|
+
|
|
22
|
+
Asset.load(geoMap.value.geojsonRegion)
|
|
23
|
+
Asset.load(geoMap.value.geojsonBorder)
|
|
24
|
+
|
|
25
|
+
await Asset.readly()
|
|
26
|
+
Asset.graph.update(graphics.url)
|
|
27
|
+
|
|
28
|
+
geoMap.value.setNeedsUpdate()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Asset.provider(scriptable, async () => ({ default: RoutineScriptable }))
|
|
33
|
+
|
|
34
|
+
const createExecuteInput = (args: any = {}) => {
|
|
35
|
+
const input = {
|
|
36
|
+
dataset: { value: args.dataset ?? '' },
|
|
37
|
+
geoMap: { value: args.geoMap ?? '' },
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return input
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const createExecuteNode = (options: { id: string; position?: any; input?: any }) => {
|
|
44
|
+
const executeNode: RoutineNode = {
|
|
45
|
+
id: options.id,
|
|
46
|
+
label: language.get(scriptable as any),
|
|
47
|
+
position: { x: options?.position?.x ?? 20, y: options?.position?.y ?? 20 },
|
|
48
|
+
routine: 'Execute',
|
|
49
|
+
url: scriptable,
|
|
50
|
+
input: createExecuteInput(options.input)
|
|
51
|
+
}
|
|
52
|
+
return executeNode
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
scriptable,
|
|
57
|
+
createExecuteInput,
|
|
58
|
+
createExecuteNode,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as drilldown from './drilldown'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as GeoMap from './GeoMap'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Asset, RoutineDescriptor } from "@vyr/engine"
|
|
2
|
+
import { GeoMap } from "../../execute"
|
|
3
|
+
|
|
4
|
+
const url = Asset.createVirtualUrl('preset/GeoMap/drilldown.routine.json')
|
|
5
|
+
const nodes = {
|
|
6
|
+
drilldown: 'drilldown',
|
|
7
|
+
}
|
|
8
|
+
let _currentRoutine: RoutineDescriptor | null = null
|
|
9
|
+
const routineProvider = async () => {
|
|
10
|
+
if (_currentRoutine === null) {
|
|
11
|
+
_currentRoutine = new RoutineDescriptor()
|
|
12
|
+
const drilldownNode = GeoMap.drilldown.createExecuteNode({ id: nodes.drilldown })
|
|
13
|
+
_currentRoutine.addNode([drilldownNode])
|
|
14
|
+
_currentRoutine.roots.push(drilldownNode.id)
|
|
15
|
+
}
|
|
16
|
+
return _currentRoutine
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Asset.provider(url, routineProvider)
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
url,
|
|
23
|
+
nodes,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as drilldown from './drilldown'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as GeoMap from './GeoMap'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Material, Mesh, Object3D, Skeleton, Texture } from 'three'
|
|
2
|
+
|
|
3
|
+
function disposeMaterial(material: Material) {
|
|
4
|
+
material.dispose();
|
|
5
|
+
|
|
6
|
+
const keys = Object.keys(material) as Array<keyof Material>
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
const value = material[key]
|
|
9
|
+
if (value && value instanceof Texture) value.dispose()
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const diaposeObject3D = (obj: Object3D) => {
|
|
14
|
+
obj.traverse(sub => {
|
|
15
|
+
if (sub instanceof Mesh) {
|
|
16
|
+
Array.isArray(sub.material) ? sub.material.forEach(disposeMaterial) : disposeMaterial(sub.material)
|
|
17
|
+
sub.geometry.dispose()
|
|
18
|
+
}
|
|
19
|
+
if (sub instanceof Skeleton) sub.boneTexture?.dispose()
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { diaposeObject3D }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Box3, BufferGeometry, Vector2, Vector3 } from 'three'
|
|
2
|
+
import { Asset, Graphics, JsonAsset, UpdateArgs, Vector2 as V2 } from '@vyr/engine'
|
|
3
|
+
import { ExtrudeGeometryDescriptor } from '../../descriptor'
|
|
4
|
+
import { GeometryActor } from '../../actor'
|
|
5
|
+
|
|
6
|
+
const getPointsOfshapeData = (data: JsonAsset, offset: V2) => {
|
|
7
|
+
const points: Vector2[] = []
|
|
8
|
+
|
|
9
|
+
for (let i = 0; i < data.length; i++) {
|
|
10
|
+
points.push(new Vector2(data[i][0] + offset.x, data[i][1] + offset.y))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return points
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getPointsOfLineData = (data: JsonAsset, offset: V2) => {
|
|
17
|
+
const points: Vector3[] = []
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < data.length; i++) {
|
|
20
|
+
points.push(new Vector3(data[i][0] + offset.x, data[i][1] + offset.y, 0))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return points
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getExtrudeOptions = (descriptor: ExtrudeGeometryDescriptor) => {
|
|
27
|
+
return {
|
|
28
|
+
curveSegments: descriptor.curveSegments,
|
|
29
|
+
steps: descriptor.steps,
|
|
30
|
+
depth: descriptor.depth,
|
|
31
|
+
bevelEnabled: descriptor.bevelEnabled,
|
|
32
|
+
bevelThickness: descriptor.bevelThickness,
|
|
33
|
+
bevelSize: descriptor.bevelSize,
|
|
34
|
+
bevelOffset: descriptor.bevelOffset,
|
|
35
|
+
bevelSegments: descriptor.bevelSegments,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const flattenUVsToPlane = (geometry: BufferGeometry) => {
|
|
40
|
+
geometry.computeBoundingBox()
|
|
41
|
+
const box3 = geometry.boundingBox as Box3
|
|
42
|
+
const bboxSize = box3.getSize(new Vector3());
|
|
43
|
+
const bboxMin = box3.min
|
|
44
|
+
|
|
45
|
+
const position = geometry.getAttribute('position')
|
|
46
|
+
const uv = geometry.getAttribute('uv')
|
|
47
|
+
for (let i = 0; i < position.count; i++) {
|
|
48
|
+
const x = position.getX(i)
|
|
49
|
+
const y = position.getY(i)
|
|
50
|
+
|
|
51
|
+
const u = (x - bboxMin.x) / bboxSize.x;
|
|
52
|
+
const v = (y - bboxMin.y) / bboxSize.y;
|
|
53
|
+
uv.setX(i, u)
|
|
54
|
+
uv.setY(i, v)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let _geometry: BufferGeometry | null = null
|
|
59
|
+
const defaultGeometry = () => {
|
|
60
|
+
if (_geometry === null) {
|
|
61
|
+
_geometry = new BufferGeometry()
|
|
62
|
+
}
|
|
63
|
+
return _geometry
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const getGeometry = (geometry: string, graphics: Graphics, args: UpdateArgs) => {
|
|
67
|
+
const geometryDescriptor = Asset.get(geometry)
|
|
68
|
+
if (geometryDescriptor === null) return defaultGeometry()
|
|
69
|
+
|
|
70
|
+
const interpreter = graphics.getInterpreter(geometryDescriptor)
|
|
71
|
+
const actor = interpreter.getActor<GeometryActor<BufferGeometry>>(geometryDescriptor, args)
|
|
72
|
+
return actor.object instanceof BufferGeometry ? actor.object : defaultGeometry()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
getPointsOfshapeData,
|
|
77
|
+
getPointsOfLineData,
|
|
78
|
+
getExtrudeOptions,
|
|
79
|
+
flattenUVsToPlane,
|
|
80
|
+
defaultGeometry,
|
|
81
|
+
getGeometry,
|
|
82
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Material, MeshBasicMaterial } from 'three'
|
|
2
|
+
import { Asset, AssetPropertyCollection, Category, Graphics, Port, UpdateArgs } from '@vyr/engine'
|
|
3
|
+
import { MaterialActor } from '../../actor'
|
|
4
|
+
|
|
5
|
+
let _material: Material | null = null
|
|
6
|
+
const defaultMaterial = () => {
|
|
7
|
+
if (_material === null) {
|
|
8
|
+
_material = new MeshBasicMaterial()
|
|
9
|
+
}
|
|
10
|
+
return _material
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const useMaterial = (material: string, graphics: Graphics, args: UpdateArgs) => {
|
|
14
|
+
const materialDescriptor = Asset.get(material)
|
|
15
|
+
if (materialDescriptor === null) return defaultMaterial()
|
|
16
|
+
|
|
17
|
+
const interpreter = graphics.getInterpreter(materialDescriptor)
|
|
18
|
+
const actor = interpreter.getActor<MaterialActor<Material>>(materialDescriptor, args)
|
|
19
|
+
return actor.object instanceof Material ? actor.object : defaultMaterial()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getMaterial = (materialValue: string | AssetPropertyCollection, graphics: Graphics, args: UpdateArgs) => {
|
|
23
|
+
if (typeof materialValue === 'string') {
|
|
24
|
+
return useMaterial(materialValue, graphics, args)
|
|
25
|
+
} else {
|
|
26
|
+
const materials: Material[] = []
|
|
27
|
+
for (const material of materialValue) {
|
|
28
|
+
const actor = useMaterial(material.url, graphics, args)
|
|
29
|
+
materials.push(actor)
|
|
30
|
+
}
|
|
31
|
+
return materials
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pickMaterial = (source: string | AssetPropertyCollection, port: Port) => {
|
|
36
|
+
if (Array.isArray(source)) {
|
|
37
|
+
for (let i = 0; i < source.length; i++) {
|
|
38
|
+
const material = source[i]
|
|
39
|
+
if (material.url) {
|
|
40
|
+
port.edges.push({ key: `material[${i}].url`, category: Category.material, asset: material.url })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (source) port.edges.push({ key: 'material', category: Category.material, asset: source })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
defaultMaterial,
|
|
50
|
+
useMaterial,
|
|
51
|
+
getMaterial,
|
|
52
|
+
pickMaterial,
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Object3D } from "three";
|
|
2
|
+
import { Descriptor } from "@vyr/engine";
|
|
3
|
+
import { PickupNode, SceneServiceInterpreter } from "../../interpreter";
|
|
4
|
+
|
|
5
|
+
const collectionPickupResult = (target: Object3D, recursive: boolean, descriptor: Descriptor, result: PickupNode[]) => {
|
|
6
|
+
const intersection = SceneServiceInterpreter.ray.intersectObject(target, recursive)
|
|
7
|
+
if (intersection.length === 0) return
|
|
8
|
+
let minDistance = Infinity
|
|
9
|
+
for (const item of intersection) if (item.distance < minDistance) minDistance = item.distance
|
|
10
|
+
const pickupObject: PickupNode = { uuid: descriptor.uuid, generatedBy: descriptor.generatedBy, intersection, minDistance }
|
|
11
|
+
result.push(pickupObject)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
collectionPickupResult
|
|
16
|
+
}
|