@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
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vyr/three",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"author": "",
|
|
7
|
+
"sideEffects": true,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@vyr/locale": "0.0.1",
|
|
11
|
+
"@vyr/engine": "0.0.1",
|
|
12
|
+
"postprocessing": "^6.38.0",
|
|
13
|
+
"three": "0.175.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/three": "0.175.0"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"package.json",
|
|
20
|
+
"src/"
|
|
21
|
+
],
|
|
22
|
+
"vyr": {
|
|
23
|
+
"type": "universal",
|
|
24
|
+
"order": 10
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { EffectComposer, RenderPass, EffectPass, SMAAEffect, SMAAPreset, EdgeDetectionMode, PredicationMode } from 'postprocessing'
|
|
2
|
+
import { Actor, ArrayUtils, Descriptor, UpdateArgs } from '@vyr/engine';
|
|
3
|
+
import { ComposerServiceDescriptor } from '../descriptor/ComposerServiceDescriptor';
|
|
4
|
+
import { SceneServiceActor } from "./SceneServiceActor";
|
|
5
|
+
import { PassActor } from './PassActor';
|
|
6
|
+
import { Camera } from 'three';
|
|
7
|
+
import { NodeActor } from './NodeActor';
|
|
8
|
+
|
|
9
|
+
class ComposerServiceActor extends SceneServiceActor {
|
|
10
|
+
private _cacheKey = ''
|
|
11
|
+
private _composer: EffectComposer | null = null
|
|
12
|
+
private _renderPass
|
|
13
|
+
private _antiAliasPass
|
|
14
|
+
readonly passQueue: PassActor[] = []
|
|
15
|
+
|
|
16
|
+
constructor(descriptor: ComposerServiceDescriptor) {
|
|
17
|
+
super(descriptor.uuid, 'high-performance', false)
|
|
18
|
+
this._renderPass = new RenderPass()
|
|
19
|
+
const smaa = new SMAAEffect({
|
|
20
|
+
preset: SMAAPreset.HIGH, // 高质量
|
|
21
|
+
edgeDetectionMode: EdgeDetectionMode.COLOR, // 默认值
|
|
22
|
+
predicationMode: PredicationMode.DISABLED // 默认值
|
|
23
|
+
})
|
|
24
|
+
this._antiAliasPass = new EffectPass(undefined, smaa)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getEffectComposer(descriptor: ComposerServiceDescriptor) {
|
|
28
|
+
const cacheKey = `${descriptor.frameBufferType}_${descriptor.depthBuffer}_${descriptor.stencilBuffer}`
|
|
29
|
+
if (this._composer === null) {
|
|
30
|
+
this._cacheKey = cacheKey
|
|
31
|
+
this._composer = new EffectComposer(this.pipeline, {
|
|
32
|
+
frameBufferType: descriptor.frameBufferType,
|
|
33
|
+
depthBuffer: true,
|
|
34
|
+
stencilBuffer: descriptor.stencilBuffer,
|
|
35
|
+
})
|
|
36
|
+
this._composer.autoRenderToScreen = true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (cacheKey !== this._cacheKey) {
|
|
40
|
+
this.reset()
|
|
41
|
+
this._cacheKey = cacheKey
|
|
42
|
+
this._composer = new EffectComposer(this.pipeline, {
|
|
43
|
+
frameBufferType: descriptor.frameBufferType,
|
|
44
|
+
depthBuffer: descriptor.depthBuffer,
|
|
45
|
+
stencilBuffer: descriptor.stencilBuffer,
|
|
46
|
+
})
|
|
47
|
+
this._composer.autoRenderToScreen = true
|
|
48
|
+
}
|
|
49
|
+
return this._composer
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
add(actor: Actor) {
|
|
53
|
+
if (actor instanceof PassActor) {
|
|
54
|
+
ArrayUtils.insert(this.passQueue, actor)
|
|
55
|
+
} else {
|
|
56
|
+
super.add(actor)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
remove(actor: Actor) {
|
|
61
|
+
if (actor instanceof PassActor) {
|
|
62
|
+
ArrayUtils.remove(this.passQueue, actor)
|
|
63
|
+
} else {
|
|
64
|
+
super.remove(actor)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
update(descriptor: ComposerServiceDescriptor, args: UpdateArgs) {
|
|
69
|
+
super.update(descriptor, args)
|
|
70
|
+
|
|
71
|
+
const graphics = Actor.getGraphics(this)
|
|
72
|
+
const camera = Descriptor.get<Descriptor>(graphics.scheduler.camera)
|
|
73
|
+
const cameraActor = graphics.getActor<NodeActor<Camera>>(camera, args)
|
|
74
|
+
|
|
75
|
+
const composer = this.getEffectComposer(descriptor)
|
|
76
|
+
composer.addPass(this._renderPass)
|
|
77
|
+
// for (const pass of this.passQueue) composer.addPass(pass.effect)
|
|
78
|
+
composer.addPass(this._antiAliasPass)
|
|
79
|
+
|
|
80
|
+
composer.multisampling = descriptor.multisampling
|
|
81
|
+
composer.setRenderer(this.pipeline)
|
|
82
|
+
composer.setMainScene(this.scene)
|
|
83
|
+
composer.setMainCamera(cameraActor.object)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render(service: ComposerServiceDescriptor, camera: NodeActor<Camera>, args: UpdateArgs) {
|
|
87
|
+
const composer = this.getEffectComposer(service)
|
|
88
|
+
composer.render(args.delta)
|
|
89
|
+
this.screenPipeline.render(this.scene, camera.object)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
reset() {
|
|
93
|
+
if (this._composer === null) return
|
|
94
|
+
this._cacheKey = ''
|
|
95
|
+
this._composer.dispose()
|
|
96
|
+
this._composer.passes.length = 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
dispose() {
|
|
100
|
+
super.dispose()
|
|
101
|
+
this.reset()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
ComposerServiceActor
|
|
107
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Actor } from "@vyr/engine"
|
|
2
|
+
import { BufferGeometry } from "three"
|
|
3
|
+
|
|
4
|
+
class GeometryActor<T extends BufferGeometry = BufferGeometry> extends Actor {
|
|
5
|
+
readonly object: T
|
|
6
|
+
|
|
7
|
+
constructor(object: T) {
|
|
8
|
+
super()
|
|
9
|
+
this.object = object
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { GeometryActor }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Object3D } from 'three'
|
|
2
|
+
import { CSS3DSprite } from 'three/examples/jsm/renderers/CSS3DRenderer.js'
|
|
3
|
+
import { Actor, ArrayUtils, Descriptor, HTMLActor, Interpreter, UpdateArgs } from "@vyr/engine"
|
|
4
|
+
import { NodeActor } from "./NodeActor"
|
|
5
|
+
|
|
6
|
+
class HTMLConvertActor extends NodeActor {
|
|
7
|
+
declare object: Object3D
|
|
8
|
+
private _spriteCollection = new Map<string, CSS3DSprite>()
|
|
9
|
+
private _sprite: CSS3DSprite | null = null
|
|
10
|
+
private _collection: Actor[] = []
|
|
11
|
+
|
|
12
|
+
overrideUpdate = (descriptor: Descriptor, interpreter: Interpreter, args: UpdateArgs) => {
|
|
13
|
+
interpreter.update(descriptor, args)
|
|
14
|
+
const actor = interpreter.getActor<HTMLActor>(descriptor, args)
|
|
15
|
+
const wrapper = actor.getWrapper()
|
|
16
|
+
if (wrapper === null) return
|
|
17
|
+
wrapper.style.position = ''
|
|
18
|
+
wrapper.style.top = ''
|
|
19
|
+
wrapper.style.left = ''
|
|
20
|
+
if (this._spriteCollection.has(descriptor.uuid)) return
|
|
21
|
+
const sprite = new CSS3DSprite(wrapper)
|
|
22
|
+
this._spriteCollection.set(descriptor.uuid, sprite)
|
|
23
|
+
this.object.add(sprite)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(actor: Actor) {
|
|
27
|
+
const graphics = NodeActor.getGraphics(this)
|
|
28
|
+
ArrayUtils.insert(this._collection, actor)
|
|
29
|
+
if (actor instanceof HTMLActor) {
|
|
30
|
+
graphics.setOverrideByUpdate(actor.uuid, this.overrideUpdate)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
remove(actor: Actor) {
|
|
35
|
+
const graphics = NodeActor.getGraphics(this)
|
|
36
|
+
ArrayUtils.remove(this._collection, actor)
|
|
37
|
+
if (actor instanceof HTMLActor) {
|
|
38
|
+
graphics.deleteOverrideByUpdate(actor.uuid)
|
|
39
|
+
const sprite = this._spriteCollection.get(actor.uuid)
|
|
40
|
+
if (sprite === undefined) return
|
|
41
|
+
this.object.remove(sprite)
|
|
42
|
+
sprite.element.remove()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
clear() {
|
|
47
|
+
while (this._collection.length > 0) {
|
|
48
|
+
const actor = this._collection.pop()
|
|
49
|
+
if (actor === undefined) continue
|
|
50
|
+
this.remove(actor)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { HTMLConvertActor }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Actor } from "@vyr/engine"
|
|
2
|
+
import { Material } from "three"
|
|
3
|
+
|
|
4
|
+
class MaterialActor<T extends Material = Material> extends Actor {
|
|
5
|
+
readonly object: T
|
|
6
|
+
|
|
7
|
+
constructor(object: T) {
|
|
8
|
+
super()
|
|
9
|
+
this.object = object
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { MaterialActor }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Actor } from "@vyr/engine"
|
|
2
|
+
import { Object3D } from "three"
|
|
3
|
+
|
|
4
|
+
class NodeActor<T extends Object3D = Object3D> extends Actor {
|
|
5
|
+
readonly object: T
|
|
6
|
+
|
|
7
|
+
constructor(object: T) {
|
|
8
|
+
super()
|
|
9
|
+
this.object = object
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
add(actor: Actor) {
|
|
13
|
+
if (actor.object instanceof Object3D) {
|
|
14
|
+
this.object.add(actor.object)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
remove(actor: Actor) {
|
|
19
|
+
if (actor.object instanceof Object3D) {
|
|
20
|
+
this.object.remove(actor.object)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { NodeActor }
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Object3D } from "three";
|
|
2
|
+
import { Actor, CameraDescriptor, Graphics, UpdateArgs } from "@vyr/engine"
|
|
3
|
+
import { OrbitControllerDescriptor, SceneServiceDescriptor } from "../descriptor";
|
|
4
|
+
import { CameraControls } from '../controls'
|
|
5
|
+
import { SceneServiceActor } from "./SceneServiceActor";
|
|
6
|
+
import { NodeActor } from "./NodeActor";
|
|
7
|
+
|
|
8
|
+
class OrbitControllerActor extends Actor {
|
|
9
|
+
readonly controls
|
|
10
|
+
readonly uuid: string
|
|
11
|
+
readonly object = new Object3D()
|
|
12
|
+
|
|
13
|
+
constructor(uuid: string, graphics: Graphics) {
|
|
14
|
+
super()
|
|
15
|
+
this.uuid = uuid
|
|
16
|
+
this.controls = new CameraControls(graphics)
|
|
17
|
+
this.controls.addEventListener('update', this._onUpdate)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private _getCameraDescriptor(uuid: string, graphics: Graphics, args: UpdateArgs) {
|
|
21
|
+
return graphics.variableProxy.get<CameraDescriptor>(uuid, graphics, args)
|
|
22
|
+
}
|
|
23
|
+
private _getWrapper(descriptor: OrbitControllerDescriptor, graphics: Graphics, args: UpdateArgs) {
|
|
24
|
+
let wrapper
|
|
25
|
+
const service = graphics.traceService(descriptor)
|
|
26
|
+
if (service instanceof SceneServiceDescriptor) {
|
|
27
|
+
const interpreter = graphics.getInterpreter(service)
|
|
28
|
+
const actor = interpreter.getActor<SceneServiceActor>(service, args)
|
|
29
|
+
wrapper = actor.getWrapper()
|
|
30
|
+
}
|
|
31
|
+
return wrapper as HTMLElement
|
|
32
|
+
}
|
|
33
|
+
private _onBeforeRender = (args: UpdateArgs) => {
|
|
34
|
+
this.controls.update(args.delta)
|
|
35
|
+
}
|
|
36
|
+
private _onUpdate = (args: UpdateArgs) => {
|
|
37
|
+
const graphics = Actor.getGraphics(this)
|
|
38
|
+
const camera = this._getCameraDescriptor(graphics.scheduler.camera, graphics, args)
|
|
39
|
+
if (camera === null) return
|
|
40
|
+
camera.position.x = this.controls.camera.position.x
|
|
41
|
+
camera.position.y = this.controls.camera.position.y
|
|
42
|
+
camera.position.z = this.controls.camera.position.z
|
|
43
|
+
camera.rotation.x = this.controls.camera.rotation.x
|
|
44
|
+
camera.rotation.y = this.controls.camera.rotation.y
|
|
45
|
+
camera.rotation.z = this.controls.camera.rotation.z
|
|
46
|
+
camera.scale.x = this.controls.camera.scale.x
|
|
47
|
+
camera.scale.y = this.controls.camera.scale.y
|
|
48
|
+
camera.scale.z = this.controls.camera.scale.z
|
|
49
|
+
}
|
|
50
|
+
getCamera(graphics: Graphics, args: UpdateArgs) {
|
|
51
|
+
const camera = this._getCameraDescriptor(graphics.scheduler.camera, graphics, args)
|
|
52
|
+
const interpreter = graphics.getInterpreter(camera)
|
|
53
|
+
interpreter.update(camera, args)
|
|
54
|
+
const actor = interpreter.getActor<NodeActor<any>>(camera, args)
|
|
55
|
+
return actor.object
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
listen(descriptor: OrbitControllerDescriptor, graphics: Graphics, args: UpdateArgs) {
|
|
59
|
+
this.controls.minZoom = descriptor.minZoom
|
|
60
|
+
this.controls.maxZoom = descriptor.maxZoom
|
|
61
|
+
this.controls.minPolarAngle = descriptor.minPolarAngle
|
|
62
|
+
this.controls.maxPolarAngle = descriptor.maxPolarAngle
|
|
63
|
+
this.controls.minAzimuthAngle = descriptor.minAzimuthAngle
|
|
64
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
65
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
66
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
67
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
68
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
69
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
70
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
71
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
72
|
+
this.controls.maxAzimuthAngle = descriptor.maxAzimuthAngle
|
|
73
|
+
this.controls.boundaryFriction = descriptor.boundaryFriction
|
|
74
|
+
this.controls.boundaryEnclosesCamera = descriptor.boundaryEnclosesCamera
|
|
75
|
+
this.controls.smoothTime = descriptor.smoothTime
|
|
76
|
+
this.controls.draggingSmoothTime = descriptor.draggingSmoothTime
|
|
77
|
+
this.controls.azimuthRotateSpeed = descriptor.azimuthRotateSpeed
|
|
78
|
+
this.controls.polarRotateSpeed = descriptor.polarRotateSpeed
|
|
79
|
+
this.controls.dollySpeed = descriptor.dollySpeed
|
|
80
|
+
this.controls.truckSpeed = descriptor.truckSpeed
|
|
81
|
+
this.controls.dollyToCursor = descriptor.dollyToCursor
|
|
82
|
+
this.controls.dollyDragInverted = descriptor.dollyDragInverted
|
|
83
|
+
this.controls.infinityDolly = descriptor.infinityDolly
|
|
84
|
+
this.controls.restThreshold = descriptor.restThreshold
|
|
85
|
+
|
|
86
|
+
const camera = this.getCamera(graphics, args)
|
|
87
|
+
if (this.controls.camera !== camera) this.controls.listen(camera)
|
|
88
|
+
this.controls.connect(this._getWrapper(descriptor, graphics, args))
|
|
89
|
+
graphics.engine.listen('beforeRender', this._onBeforeRender)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
unlisten(descriptor: OrbitControllerDescriptor, graphics: Graphics, args: UpdateArgs) {
|
|
93
|
+
this.controls.disconnect()
|
|
94
|
+
graphics.engine.unlisten('beforeRender', this._onBeforeRender)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
update(descriptor: OrbitControllerDescriptor, graphics: Graphics, args: UpdateArgs) {
|
|
98
|
+
this.unlisten(descriptor, graphics, args)
|
|
99
|
+
if (descriptor.enabled === false) return
|
|
100
|
+
this.listen(descriptor, graphics, args)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
dispose() {
|
|
104
|
+
const graphics = Actor.getGraphics(this)
|
|
105
|
+
graphics.engine.unlisten('beforeRender', this._onBeforeRender)
|
|
106
|
+
this.controls.dispose()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { OrbitControllerActor }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Object3D } from 'three'
|
|
2
|
+
import { EffectPass, SelectiveBloomEffect } from "postprocessing"
|
|
3
|
+
import { Actor, Descriptor } from "@vyr/engine"
|
|
4
|
+
import { PassDescriptor } from "../descriptor/PassDescriptor"
|
|
5
|
+
|
|
6
|
+
//TODO 继续实现渲染通道
|
|
7
|
+
// 添加效果描述器,效果分别由 描边 辉光 等。
|
|
8
|
+
// pass 负责组合效果,一旦pass在更新时发现效果发生了变更(数量,类型,顺序),就重新创建pass,且将旧的从composer里替换掉
|
|
9
|
+
// SelectiveBloomEffect 选择的对象必须关闭深度写入,且自身不能被其他对象遮挡
|
|
10
|
+
|
|
11
|
+
class PassActor extends Actor {
|
|
12
|
+
|
|
13
|
+
constructor(descriptor: PassDescriptor) {
|
|
14
|
+
super()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
update(descriptor: PassDescriptor) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
dispose() {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { PassActor }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Camera, LinearToneMapping, Object3D, Scene, SRGBColorSpace, WebGLRenderer } from "three"
|
|
2
|
+
import { CSS3DRenderer } from 'three/examples/jsm/renderers/CSS3DRenderer.js'
|
|
3
|
+
import { HTMLActor, UpdateArgs, Actor, Asset } from "@vyr/engine"
|
|
4
|
+
import { SceneServiceDescriptor, TextureDescriptor } from "../descriptor"
|
|
5
|
+
import { TextureActor } from "./TextureActor"
|
|
6
|
+
import { NodeActor } from "./NodeActor"
|
|
7
|
+
|
|
8
|
+
class SceneServiceActor extends HTMLActor {
|
|
9
|
+
private _wrapper: HTMLElement | null = null
|
|
10
|
+
readonly scene
|
|
11
|
+
readonly pipeline
|
|
12
|
+
readonly screenPipeline
|
|
13
|
+
|
|
14
|
+
constructor(uuid: string, powerPreference: WebGLPowerPreference = 'default', antialias = true) {
|
|
15
|
+
super(uuid)
|
|
16
|
+
this.scene = new Scene()
|
|
17
|
+
this.scene.matrixAutoUpdate = false
|
|
18
|
+
|
|
19
|
+
this.pipeline = new WebGLRenderer({
|
|
20
|
+
antialias,
|
|
21
|
+
powerPreference,
|
|
22
|
+
alpha: true,
|
|
23
|
+
//需要截图,必须开启。后续可以优化
|
|
24
|
+
preserveDrawingBuffer: true
|
|
25
|
+
})
|
|
26
|
+
this.pipeline.outputColorSpace = SRGBColorSpace
|
|
27
|
+
this.pipeline.toneMapping = LinearToneMapping
|
|
28
|
+
this.pipeline.toneMappingExposure = 1
|
|
29
|
+
this.pipeline.domElement.setAttribute(HTMLActor.uuidKey, uuid)
|
|
30
|
+
this.pipeline.setClearColor(0, 0)
|
|
31
|
+
this.pipeline.clear()
|
|
32
|
+
this.pipeline.autoClear = false
|
|
33
|
+
|
|
34
|
+
this.pipeline.domElement.style.width = '100%'
|
|
35
|
+
this.pipeline.domElement.style.height = '100%'
|
|
36
|
+
this.pipeline.domElement.style.position = 'relative'
|
|
37
|
+
|
|
38
|
+
this.screenPipeline = new CSS3DRenderer()
|
|
39
|
+
this.screenPipeline.domElement.style.position = 'absolute'
|
|
40
|
+
this.screenPipeline.domElement.style.left = '0px'
|
|
41
|
+
this.screenPipeline.domElement.style.top = '0px'
|
|
42
|
+
this.screenPipeline.domElement.style.transformOrigin = '0 0 0'
|
|
43
|
+
this.screenPipeline.domElement.style.backgroundColor = 'transparent'
|
|
44
|
+
|
|
45
|
+
const wrapper = this.getWrapper()
|
|
46
|
+
wrapper.appendChild(this.pipeline.domElement)
|
|
47
|
+
wrapper.appendChild(this.screenPipeline.domElement)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected createWrapper() {
|
|
51
|
+
const wrapper = document.createElement('div')
|
|
52
|
+
wrapper.setAttribute('class', HTMLActor.className)
|
|
53
|
+
wrapper.setAttribute(HTMLActor.uuidKey, this.uuid)
|
|
54
|
+
return wrapper
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getWrapper() {
|
|
58
|
+
if (this._wrapper === null) {
|
|
59
|
+
this._wrapper = this.createWrapper()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return this._wrapper
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
add(actor: Actor) {
|
|
66
|
+
if (actor instanceof HTMLActor) {
|
|
67
|
+
const wrapper = actor.getWrapper()
|
|
68
|
+
if (wrapper === null) return
|
|
69
|
+
const selfWrapper = this.getWrapper()
|
|
70
|
+
if (selfWrapper.contains(wrapper)) return
|
|
71
|
+
selfWrapper.appendChild(wrapper)
|
|
72
|
+
} else {
|
|
73
|
+
if (actor.object instanceof Object3D) {
|
|
74
|
+
this.scene.add(actor.object)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
remove(actor: Actor) {
|
|
80
|
+
if (actor instanceof HTMLActor) {
|
|
81
|
+
const wrapper = actor.getWrapper()
|
|
82
|
+
if (wrapper === null) return
|
|
83
|
+
const selfWrapper = this.getWrapper()
|
|
84
|
+
if (selfWrapper.contains(wrapper) === false) return
|
|
85
|
+
selfWrapper.removeChild(wrapper)
|
|
86
|
+
} else {
|
|
87
|
+
if (actor.object instanceof Object3D) {
|
|
88
|
+
this.scene.remove(actor.object)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setBackground(descriptor: SceneServiceDescriptor, args: UpdateArgs) {
|
|
94
|
+
if (descriptor.background) {
|
|
95
|
+
const graphics = Actor.getGraphics(this)
|
|
96
|
+
const texture = Asset.get<TextureDescriptor>(descriptor.background)
|
|
97
|
+
const actor = graphics.getActor<TextureActor>(texture, args)
|
|
98
|
+
this.scene.background = texture instanceof TextureDescriptor ? actor.object : null
|
|
99
|
+
} else {
|
|
100
|
+
this.scene.background = null
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
update(descriptor: SceneServiceDescriptor, args: UpdateArgs) {
|
|
105
|
+
const wrapper = this.getWrapper()
|
|
106
|
+
this.setHTMLStyle(wrapper, this.getWrapperStyle(descriptor, args))
|
|
107
|
+
this.setHTMLStyle(this.pipeline.domElement, this.getLayoutStyle(descriptor, args))
|
|
108
|
+
this.setStyleClass(this.pipeline.domElement, this.getStyleClass(descriptor, args))
|
|
109
|
+
this.setBackground(descriptor, args)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render(service: SceneServiceDescriptor, camera: NodeActor<Camera>, args: UpdateArgs) {
|
|
113
|
+
this.pipeline.render(this.scene, camera.object)
|
|
114
|
+
this.screenPipeline.render(this.scene, camera.object)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
dispose() {
|
|
118
|
+
this.pipeline.dispose()
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { SceneServiceActor }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Actor } from "@vyr/engine"
|
|
2
|
+
import { Texture } from "three"
|
|
3
|
+
|
|
4
|
+
class TextureActor<T extends Texture = Texture> extends Actor {
|
|
5
|
+
readonly object: T
|
|
6
|
+
|
|
7
|
+
constructor(object: T) {
|
|
8
|
+
super()
|
|
9
|
+
this.object = object
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { TextureActor }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Actor, Graphics, UpdateArgs } from "@vyr/engine"
|
|
2
|
+
import { TransformControllerDescriptor } from "../descriptor"
|
|
3
|
+
import { TransformControls } from "../controls"
|
|
4
|
+
|
|
5
|
+
class TransformControllerActor extends Actor {
|
|
6
|
+
readonly object = new TransformControls()
|
|
7
|
+
|
|
8
|
+
update(descriptor: TransformControllerDescriptor, graphics: Graphics, args: UpdateArgs) {
|
|
9
|
+
this.object.unlisten(graphics)
|
|
10
|
+
if (descriptor.enabled === false) return
|
|
11
|
+
this.object.listen(descriptor, graphics, args)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
unlisten(graphics: Graphics) {
|
|
15
|
+
this.object.unlisten(graphics)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
dispose(graphics: Graphics) {
|
|
19
|
+
this.object.dispose(graphics)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { TransformControllerActor }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './SceneServiceActor'
|
|
2
|
+
export * from './OrbitControllerActor'
|
|
3
|
+
export * from './TransformControllerActor'
|
|
4
|
+
export * from './MaterialActor'
|
|
5
|
+
export * from './GeometryActor'
|
|
6
|
+
export * from './TextureActor'
|
|
7
|
+
export * from './NodeActor'
|
|
8
|
+
export * from './HTMLConvertActor'
|
|
9
|
+
// export * from './ComposerServiceActor'
|
|
10
|
+
// export * from './PassActor'
|