@vyr/engine 0.0.33 → 0.0.34
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 +6 -3
- package/src/ArrayUtils.ts +63 -65
- package/src/AsyncTask.ts +67 -71
- package/src/Category.ts +69 -86
- package/src/Color.ts +3 -111
- package/src/Engine.ts +12 -24
- package/src/Executor.ts +109 -0
- package/src/Generate.ts +23 -40
- package/src/InputSystem.ts +106 -108
- package/src/Listener.ts +58 -59
- package/src/ObjectPool.ts +83 -84
- package/src/ObjectUtils.ts +97 -49
- package/src/Scriptable.ts +82 -0
- package/src/Serialization.ts +4 -6
- package/src/Traverser.ts +41 -39
- package/src/actor/Actor.ts +23 -27
- package/src/actor/AnimationUnitActor.ts +22 -36
- package/src/actor/DivActor.ts +21 -41
- package/src/actor/FragmentActor.ts +1 -5
- package/src/actor/HTMLActor.ts +81 -0
- package/src/actor/HTMLServiceActor.ts +49 -0
- package/src/actor/{HTMTransformControllerActor.ts → HTMLTransformControllerActor.ts} +178 -71
- package/src/actor/InputActor.ts +50 -0
- package/src/actor/TextActor.ts +51 -0
- package/src/actor/index.ts +6 -5
- package/src/asset/Asset.ts +23 -68
- package/src/asset/AssetGraph.ts +21 -28
- package/src/descriptor/AnimationUnit.ts +81 -0
- package/src/descriptor/Camera.ts +12 -0
- package/src/descriptor/Controller.ts +6 -0
- package/src/descriptor/Descriptor.ts +133 -113
- package/src/descriptor/Div.ts +29 -0
- package/src/descriptor/HTML.ts +22 -0
- package/src/descriptor/HTMLService.ts +42 -0
- package/src/descriptor/HTMLTransformController.ts +67 -0
- package/src/descriptor/Input.ts +29 -0
- package/src/descriptor/Interaction.ts +80 -0
- package/src/descriptor/Node.ts +98 -0
- package/src/descriptor/Scene.ts +110 -0
- package/src/descriptor/Service.ts +11 -0
- package/src/descriptor/Store.ts +136 -0
- package/src/descriptor/Text.ts +36 -0
- package/src/descriptor/index.ts +14 -15
- package/src/graphics/Collection.ts +1 -5
- package/src/graphics/Compilation.ts +15 -19
- package/src/graphics/Graphics.ts +41 -54
- package/src/graphics/Observer.ts +6 -14
- package/src/graphics/Unit.ts +3 -9
- package/src/graphics/VariableProxy.ts +11 -15
- package/src/index.ts +5 -5
- package/src/interpreter/AnimationUnitInterpreter.ts +7 -9
- package/src/interpreter/DivInterpreter.ts +10 -13
- package/src/interpreter/FragmentInterpreter.ts +2 -6
- package/src/interpreter/HTMLServiceInterpreter.ts +25 -15
- package/src/interpreter/HTMLTransformControllerInterpreter.ts +9 -12
- package/src/interpreter/InputInterpreter.ts +41 -0
- package/src/interpreter/Interpreter.ts +3 -4
- package/src/interpreter/SceneInterpreter.ts +93 -0
- package/src/interpreter/ServiceInterpreter.ts +8 -15
- package/src/interpreter/StoreInterpreter.ts +7 -0
- package/src/interpreter/TextInterpreter.ts +41 -0
- package/src/interpreter/index.ts +5 -7
- package/src/locale/Language.ts +1 -5
- package/src/locale/LanguageProvider.ts +164 -21
- package/src/math/Euler.ts +2 -5
- package/src/math/Matrix4.ts +2 -4
- package/src/math/Quaternion.ts +2 -4
- package/src/math/Vector2.ts +4 -4
- package/src/math/Vector3.ts +2 -4
- package/src/math/utils.ts +1 -5
- package/src/schema/AnimationUnit.ts +68 -0
- package/src/schema/Asset.ts +13 -0
- package/src/schema/Descriptor.ts +41 -0
- package/src/schema/HTML.ts +261 -0
- package/src/schema/Interaction.ts +50 -0
- package/src/schema/Scene.ts +138 -0
- package/src/schema/Store.ts +8 -0
- package/src/schema/index.ts +7 -0
- package/src/scripts/ConditionScriptable.ts +196 -0
- package/src/scripts/FetchScriptable.ts +51 -0
- package/src/scripts/FindScriptable.ts +23 -0
- package/src/scripts/InvokeScriptable.ts +13 -0
- package/src/scripts/SwitchSceneScriptable.ts +18 -0
- package/src/scripts/UpdateScriptable.ts +60 -0
- package/src/scripts/index.ts +6 -0
- package/src/utils/AssetProvider.ts +4 -77
- package/src/utils/DOM.ts +37 -0
- package/src/utils/HTML.ts +5 -0
- package/src/utils/Service.ts +40 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/http.ts +2 -21
- package/src/utils/index.ts +3 -1
- package/src/actor/HTMActor.ts +0 -169
- package/src/actor/HTMServiceActor.ts +0 -57
- package/src/actor/StyleActor.ts +0 -96
- package/src/descriptor/AnimationUnitDescriptor.ts +0 -65
- package/src/descriptor/CameraDescriptor.ts +0 -12
- package/src/descriptor/ControllerDescriptor.ts +0 -16
- package/src/descriptor/DatasetDescriptor.ts +0 -90
- package/src/descriptor/DivDescriptor.ts +0 -18
- package/src/descriptor/DynamicDescriptor.ts +0 -27
- package/src/descriptor/HTMLDescriptor.ts +0 -87
- package/src/descriptor/HTMLServiceDescriptor.ts +0 -19
- package/src/descriptor/HTMLTransformControllerDescriptor.ts +0 -34
- package/src/descriptor/NodeDescriptor.ts +0 -32
- package/src/descriptor/PrefabDescriptor.ts +0 -53
- package/src/descriptor/PrefabInstanceDescriptor.ts +0 -32
- package/src/descriptor/ServiceDescriptor.ts +0 -32
- package/src/descriptor/ServiceSchedulerDescriptor.ts +0 -32
- package/src/descriptor/StyleDescriptor.ts +0 -213
- package/src/interaction/InteractionDescriptor.ts +0 -96
- package/src/interaction/InteractionExecutor.ts +0 -84
- package/src/interaction/Scriptable.ts +0 -44
- package/src/interaction/index.ts +0 -3
- package/src/interpreter/DatasetInterpreter.ts +0 -11
- package/src/interpreter/DynamicInterpreter.ts +0 -207
- package/src/interpreter/PrefaInterpreter.ts +0 -11
- package/src/interpreter/PrefabInstanceInterpreter.ts +0 -12
- package/src/interpreter/ServiceSchedulerInterpreter.ts +0 -42
- package/src/interpreter/StyleInterpreter.ts +0 -66
- package/src/preset/execute/dataset/index.ts +0 -1
- package/src/preset/execute/dataset/update.ts +0 -51
- package/src/preset/execute/graphics/index.ts +0 -1
- package/src/preset/execute/graphics/invoke.ts +0 -48
- package/src/preset/execute/index.ts +0 -4
- package/src/preset/execute/net/http.ts +0 -52
- package/src/preset/execute/net/index.ts +0 -1
- package/src/preset/execute/scheduler/index.ts +0 -1
- package/src/preset/execute/scheduler/switch.ts +0 -46
- package/src/preset/index.ts +0 -7
- package/src/preset/interaction/graphics/index.ts +0 -1
- package/src/preset/interaction/graphics/invoke.ts +0 -27
- package/src/preset/interaction/index.ts +0 -2
- package/src/preset/interaction/scheduler/index.ts +0 -1
- package/src/preset/interaction/scheduler/switch.ts +0 -27
- package/src/setup/index.ts +0 -17
- package/src/utils/compile.ts +0 -50
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Descriptor } from "./Descriptor"
|
|
2
|
+
import { HtmlAttributes } from "../schema";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* HTML接口
|
|
6
|
+
* 表示HTML元素,用于在二维场景中显示HTML内容
|
|
7
|
+
*
|
|
8
|
+
* 作用:作为二维界面元素的接口,提供了HTML元素的基础属性
|
|
9
|
+
*/
|
|
10
|
+
export interface HTML extends Descriptor {
|
|
11
|
+
|
|
12
|
+
/**是否为HTML节点 */
|
|
13
|
+
isHTML: true
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 是否可见
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
visible: boolean
|
|
20
|
+
|
|
21
|
+
htmlAttributes: HtmlAttributes
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { HtmlAttributes, HtmlAttributesSchema } from "../schema"
|
|
3
|
+
import { Service } from "./Service"
|
|
4
|
+
import { Descriptor } from "./Descriptor"
|
|
5
|
+
import { registerService } from "../utils/Service"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 二维(HTML)场景渲染服务
|
|
9
|
+
*
|
|
10
|
+
* 作用:负责管理二维节点(如Div、ELButton等)的渲染。必须作为Scene的直接子节点挂载,
|
|
11
|
+
* 否则所有二维节点将无法正常渲染。
|
|
12
|
+
*
|
|
13
|
+
* 使用要求:
|
|
14
|
+
* 1. 必须添加为Scene的子节点
|
|
15
|
+
* 2. 在场景中仅需一个实例
|
|
16
|
+
* 3. 应在其他二维节点之前初始化
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // 场景结构示例
|
|
20
|
+
* Scene
|
|
21
|
+
* └── HtmlSceneService // 必须在此位置
|
|
22
|
+
* └── Div // 依赖此服务才能渲染
|
|
23
|
+
*/
|
|
24
|
+
export class HTMLService extends Descriptor implements Service {
|
|
25
|
+
/**类类型标识 */
|
|
26
|
+
static type = 'HTMLService'
|
|
27
|
+
|
|
28
|
+
readonly isHTML = true
|
|
29
|
+
|
|
30
|
+
visible: boolean
|
|
31
|
+
|
|
32
|
+
htmlAttributes: HtmlAttributes
|
|
33
|
+
|
|
34
|
+
constructor(descriptor: Partial<DeserializationObject<HTMLService>> = {}) {
|
|
35
|
+
super(descriptor)
|
|
36
|
+
this.visible = descriptor.visible ?? true
|
|
37
|
+
this.htmlAttributes = HtmlAttributesSchema.parse(descriptor.htmlAttributes)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Descriptor.register(HTMLService)
|
|
42
|
+
registerService(HTMLService.type)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { Descriptor } from "./Descriptor"
|
|
3
|
+
import { Controller } from "./Controller"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* HTML变换控制器类
|
|
7
|
+
* 用于控制HTML元素的变换操作
|
|
8
|
+
*
|
|
9
|
+
* 作用:提供对HTML元素的变换控制功能,如移动、缩放、旋转等操作
|
|
10
|
+
* 支持通过摄像机和目标元素进行交互控制
|
|
11
|
+
*/
|
|
12
|
+
export class HTMLTransformController extends Descriptor implements Controller {
|
|
13
|
+
/**类类型标识 */
|
|
14
|
+
static type = 'HTMLTransformController'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 控制器是否启用
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
enabled: boolean
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 控制器的摄像机
|
|
24
|
+
* 指定用于交互控制的摄像机UUID
|
|
25
|
+
* @default ""
|
|
26
|
+
*/
|
|
27
|
+
camera: string
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 控制器的模式
|
|
31
|
+
* 定义控制器的操作模式
|
|
32
|
+
* @default ""
|
|
33
|
+
*/
|
|
34
|
+
mode: string
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 控制器的目标
|
|
38
|
+
* 指定要控制的目标元素UUID
|
|
39
|
+
* @default ""
|
|
40
|
+
*/
|
|
41
|
+
target: string
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 控制器触发事件时执行的脚本依赖
|
|
45
|
+
* 指定事件触发时要执行的脚本
|
|
46
|
+
* @default ""
|
|
47
|
+
*/
|
|
48
|
+
event: string
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 高亮目标
|
|
52
|
+
* 指定要高亮显示的元素UUID
|
|
53
|
+
* @default ""
|
|
54
|
+
*/
|
|
55
|
+
highlight: string
|
|
56
|
+
|
|
57
|
+
constructor(descriptor: Partial<DeserializationObject<HTMLTransformController>> = {}) {
|
|
58
|
+
super(descriptor)
|
|
59
|
+
this.enabled = descriptor.enabled ?? false
|
|
60
|
+
this.camera = descriptor.camera ?? ''
|
|
61
|
+
this.mode = descriptor.mode ?? ''
|
|
62
|
+
this.target = descriptor.target ?? ''
|
|
63
|
+
this.event = descriptor.event ?? ''
|
|
64
|
+
this.highlight = descriptor.highlight ?? ''
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
Descriptor.register(HTMLTransformController)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { HtmlAttributes, HtmlAttributesSchema } from "../schema"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
import { HTML } from "./HTML"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Input类
|
|
8
|
+
* 表示一个HTML input元素,用于在二维场景中接收用户输入
|
|
9
|
+
*
|
|
10
|
+
* 作用:作为二维界面的输入控件,支持文本输入、密码输入等多种输入类型
|
|
11
|
+
* 继承自HTML类,拥有HTML元素的所有样式和布局属性
|
|
12
|
+
*/
|
|
13
|
+
export class Input extends Descriptor implements HTML {
|
|
14
|
+
/**类类型标识 */
|
|
15
|
+
static type = 'Input'
|
|
16
|
+
|
|
17
|
+
readonly isHTML = true
|
|
18
|
+
|
|
19
|
+
visible: boolean
|
|
20
|
+
|
|
21
|
+
htmlAttributes: HtmlAttributes
|
|
22
|
+
|
|
23
|
+
constructor(descriptor: Partial<DeserializationObject<Input>> = {}) {
|
|
24
|
+
super(descriptor)
|
|
25
|
+
this.visible = descriptor.visible ?? true
|
|
26
|
+
this.htmlAttributes = HtmlAttributesSchema.parse(descriptor.htmlAttributes)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Descriptor.register(Input)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DeserializationObject, Serialization } from "../Serialization";
|
|
2
|
+
import { Descriptor } from "./Descriptor";
|
|
3
|
+
import { Graphics } from "../graphics";
|
|
4
|
+
import { Executor } from "../Executor";
|
|
5
|
+
import { InteractionMapper, InteractionNode, InteractionNodeInputCollection, InteractionNodeArraySchame, InteractionNodeArray } from "../schema";
|
|
6
|
+
|
|
7
|
+
const privateState = {
|
|
8
|
+
executorPool: new WeakMap<Descriptor, Executor>()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 交互类
|
|
13
|
+
* 派生自Descriptor,用于定义和管理交互流程
|
|
14
|
+
*
|
|
15
|
+
* 作用:作为交互系统的核心类,用于组织和执行交互节点,控制交互流程的执行顺序
|
|
16
|
+
*/
|
|
17
|
+
export class Interaction extends Descriptor {
|
|
18
|
+
/** 类类型标识 */
|
|
19
|
+
static type = 'Interaction'
|
|
20
|
+
/** 交互的所有根节点集合(每个连线的第一个节点) */
|
|
21
|
+
roots: string[]
|
|
22
|
+
/** 交互的所有节点 */
|
|
23
|
+
nodes: InteractionNodeArray
|
|
24
|
+
/** 交互节点的执行顺序(连线顺序,source表示左侧,target表示右侧,从左到右) */
|
|
25
|
+
mappers: InteractionMapper[]
|
|
26
|
+
|
|
27
|
+
constructor(descriptor: Partial<DeserializationObject<Interaction>> = {}) {
|
|
28
|
+
super(descriptor)
|
|
29
|
+
this.roots = descriptor.roots ? Serialization.deepClone(descriptor.roots) : []
|
|
30
|
+
this.nodes = InteractionNodeArraySchame.parse(descriptor.nodes)
|
|
31
|
+
this.mappers = descriptor.mappers ? Serialization.deepClone(descriptor.mappers) : []
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 添加节点到交互中
|
|
36
|
+
* 同时自动创建节点之间的映射关系
|
|
37
|
+
* @param nodes 要添加的节点数组
|
|
38
|
+
*/
|
|
39
|
+
addNode(nodes: InteractionNode[]) {
|
|
40
|
+
const count = nodes.length
|
|
41
|
+
const max = count - 1
|
|
42
|
+
for (let i = 0; i < count; i++) {
|
|
43
|
+
const node = nodes[i]
|
|
44
|
+
this.nodes.push(node)
|
|
45
|
+
if (i < max) {
|
|
46
|
+
this.mappers.push({ source: node.id, target: nodes[i + 1].id })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 执行交互
|
|
53
|
+
* @param nodes 交互节点集合
|
|
54
|
+
* @param graphics 图形对象
|
|
55
|
+
* @param trigger 触发条件
|
|
56
|
+
* @param otherArgs 其他参数
|
|
57
|
+
*/
|
|
58
|
+
async execute(nodes: InteractionNodeInputCollection, graphics: Graphics, trigger: string, otherArgs?: { [k: string]: any }) {
|
|
59
|
+
let executor = privateState.executorPool.get(this)
|
|
60
|
+
if (executor === undefined) {
|
|
61
|
+
executor = new Executor()
|
|
62
|
+
executor.update(this)
|
|
63
|
+
privateState.executorPool.set(this, executor)
|
|
64
|
+
}
|
|
65
|
+
await executor.execute(nodes, this, graphics, trigger, otherArgs)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 设置需要更新
|
|
70
|
+
* 当交互配置发生变化时调用,更新执行器
|
|
71
|
+
*/
|
|
72
|
+
setNeedsUpdate() {
|
|
73
|
+
const executor = privateState.executorPool.get(this)
|
|
74
|
+
if (executor === undefined) return
|
|
75
|
+
executor.update(this)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Descriptor.register(Interaction)
|
|
80
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Euler, Vector3 } from "../math"
|
|
2
|
+
import { DeserializationObject } from "../Serialization"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 节点类
|
|
7
|
+
* 3D场景的基础容器节点,用于组织和管理三维空间中的对象层次结构。
|
|
8
|
+
*
|
|
9
|
+
* 主要作用:
|
|
10
|
+
* 1. 作为3D场景的逻辑容器,用于对子节点进行分组和管理
|
|
11
|
+
* 2. 提供统一的变换(位置、旋转、缩放)继承体系
|
|
12
|
+
* 3. 控制渲染状态(可见性、渲染顺序、阴影设置等)
|
|
13
|
+
* 4. 通过层级系统实现对象的分组和过滤
|
|
14
|
+
*
|
|
15
|
+
* 特性说明:
|
|
16
|
+
* - 此类是纯容器节点,本身不包含任何可渲染的几何体或材质
|
|
17
|
+
* - 所有变换属性(position、rotation、scale)将传递给子节点
|
|
18
|
+
* - 通过 layer 属性支持场景对象的分层管理和选择性渲染
|
|
19
|
+
* - 通过 renderOrder 属性控制同级节点的渲染顺序
|
|
20
|
+
* - 通过 visible 属性可控制节点及其所有子节点的可见性
|
|
21
|
+
* - 通过 castShadow/receiveShadow 控制阴影投射和接收行为(影响子节点)
|
|
22
|
+
*
|
|
23
|
+
* 注意:此节点类型仅作为组织和管理用途,不会在渲染管线中产生任何绘制调用。
|
|
24
|
+
* 若需要显示几何体,请使用 Mesh 或其它可渲染节点类型。
|
|
25
|
+
*/
|
|
26
|
+
export class Node extends Descriptor {
|
|
27
|
+
/**类类型标识 */
|
|
28
|
+
static type = 'Node'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 缩放向量
|
|
32
|
+
* 控制节点在三维空间中的缩放比例
|
|
33
|
+
* @default {x:1,y:1,z:1}
|
|
34
|
+
*/
|
|
35
|
+
readonly scale: Vector3
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 位置向量
|
|
39
|
+
* 控制节点在三维空间中的位置坐标
|
|
40
|
+
* @default {x:0,y:0,z:0}
|
|
41
|
+
*/
|
|
42
|
+
readonly position: Vector3
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 旋转欧拉角
|
|
46
|
+
* 控制节点在三维空间中的旋转状态
|
|
47
|
+
* @default {x:0,y:0,z:0,order:'XYZ'}
|
|
48
|
+
*/
|
|
49
|
+
readonly rotation: Euler
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 节点层级
|
|
53
|
+
* 用于节点的分层管理和渲染过滤
|
|
54
|
+
* @default 0
|
|
55
|
+
*/
|
|
56
|
+
layer: number
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 是否可见
|
|
60
|
+
* 控制节点是否在场景中可见
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
visible: boolean
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 渲染顺序
|
|
67
|
+
* 控制节点的渲染先后顺序
|
|
68
|
+
* @default 0
|
|
69
|
+
*/
|
|
70
|
+
renderOrder: number
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 是否投射阴影
|
|
74
|
+
* 控制节点是否向场景中投射阴影
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
castShadow: boolean
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 是否接收阴影
|
|
81
|
+
* 控制节点是否接收来自其他物体的阴影
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
receiveShadow: boolean
|
|
85
|
+
|
|
86
|
+
constructor(descriptor: Partial<DeserializationObject<Node>> = {}) {
|
|
87
|
+
super(descriptor)
|
|
88
|
+
this.scale = descriptor.scale ? Vector3.create(descriptor.scale) : Vector3.create(1, 1, 1)
|
|
89
|
+
this.position = Vector3.create(descriptor.position)
|
|
90
|
+
this.rotation = Euler.create(descriptor.rotation)
|
|
91
|
+
this.layer = descriptor.layer ?? 0
|
|
92
|
+
this.visible = descriptor.visible ?? true
|
|
93
|
+
this.renderOrder = descriptor.renderOrder ?? 0
|
|
94
|
+
this.castShadow = descriptor.castShadow ?? false
|
|
95
|
+
this.receiveShadow = descriptor.receiveShadow ?? false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
Descriptor.register(Node)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Vector2, Vector3 } from "../math";
|
|
2
|
+
import { SharedCSSStyle } from "../schema";
|
|
3
|
+
import { DeserializationObject } from "../Serialization"
|
|
4
|
+
import { Descriptor } from "./Descriptor"
|
|
5
|
+
import { Service } from "./Service";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 射线 intersection接口
|
|
9
|
+
* 定义了射线与对象相交的信息
|
|
10
|
+
*/
|
|
11
|
+
export interface RayIntersection {
|
|
12
|
+
object: Descriptor
|
|
13
|
+
distance: number
|
|
14
|
+
point: Vector3
|
|
15
|
+
normal: Vector2 | null
|
|
16
|
+
uv: Vector2 | null
|
|
17
|
+
uv1: Vector2 | null
|
|
18
|
+
faceIndex: number | null
|
|
19
|
+
instanceId: number | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Scene类
|
|
24
|
+
* 场景类,作为场景资产的根节点,负责管理和调度场景中的所有服务节点
|
|
25
|
+
*
|
|
26
|
+
* 作用:
|
|
27
|
+
* 1. 作为服务节点的容器,管理子服务节点的生命周期
|
|
28
|
+
* 2. 提供全局样式注册和管理功能,支持场景级别的样式定义
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // 场景结构示例
|
|
32
|
+
* Scene
|
|
33
|
+
* └── HtmlSceneService // 服务节点
|
|
34
|
+
* └── Div // 依赖此服务才能渲染
|
|
35
|
+
* └── Scene3DService // 服务节点
|
|
36
|
+
* └── Mesh // 依赖此服务才能渲染
|
|
37
|
+
*/
|
|
38
|
+
export class Scene extends Descriptor {
|
|
39
|
+
/**类类型标识,用于运行时类型识别 */
|
|
40
|
+
static type = 'Scene'
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 全局样式存储Map
|
|
44
|
+
* 键:CSS选择器字符串
|
|
45
|
+
* 值:CSS属性键值对对象
|
|
46
|
+
* 作用:集中管理场景中所有全局样式定义
|
|
47
|
+
*/
|
|
48
|
+
static globalStyle = new Map<string, any>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 注册全局样式
|
|
52
|
+
* 将CSS样式注册到全局样式表中
|
|
53
|
+
* @param selector - CSS选择器,如'.button', '#header'
|
|
54
|
+
* @param cssContent - CSS属性对象,如{ color: 'red', fontSize: '14px' }
|
|
55
|
+
*/
|
|
56
|
+
static registerGlobalStyle = (selector: string, cssContent: any) => {
|
|
57
|
+
this.globalStyle.set(selector, cssContent)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 生成全局样式字符串
|
|
62
|
+
* 将注册的所有全局样式转换为CSS字符串格式
|
|
63
|
+
* @returns 格式化的CSS样式字符串,可直接嵌入style标签
|
|
64
|
+
*/
|
|
65
|
+
static useGlobalStyle = () => {
|
|
66
|
+
const entries = this.globalStyle.entries()
|
|
67
|
+
|
|
68
|
+
let cssContent = ''
|
|
69
|
+
for (const [selector, content] of entries) {
|
|
70
|
+
const keys = Object.keys(content)
|
|
71
|
+
let style = `${selector} {\n`
|
|
72
|
+
for (const key of keys) {
|
|
73
|
+
style += `${key}:${content[key]};\n`
|
|
74
|
+
}
|
|
75
|
+
style += '}\n\n'
|
|
76
|
+
cssContent += style
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return cssContent
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 子服务节点数组
|
|
84
|
+
* 声明并约束children必须为Service类型的数组
|
|
85
|
+
* 场景作为服务调度器,其直接子节点只能是服务节点
|
|
86
|
+
*/
|
|
87
|
+
declare children: Service[]
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 场景渲染相机标识
|
|
91
|
+
* 指定用于渲染当前场景的相机UUID
|
|
92
|
+
* 空字符串表示使用默认相机
|
|
93
|
+
* @default ""
|
|
94
|
+
*/
|
|
95
|
+
camera: string
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 共享CSS样式对象
|
|
99
|
+
* 包含类名样式和动画定义,可在场景内的服务节点间共享
|
|
100
|
+
* 用于实现样式复用和统一管理
|
|
101
|
+
*/
|
|
102
|
+
sharedCSSStyle: SharedCSSStyle
|
|
103
|
+
|
|
104
|
+
constructor(descriptor: Partial<DeserializationObject> = {}) {
|
|
105
|
+
super(descriptor)
|
|
106
|
+
this.camera = descriptor.camera ?? ''
|
|
107
|
+
this.sharedCSSStyle = descriptor.sharedCSSStyle ? Descriptor.deepClone(descriptor.sharedCSSStyle) : { classNames: {}, animations: {} }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
Descriptor.register(Scene)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { StoreData, StoreDataSchema } from "../schema";
|
|
2
|
+
import { Asset } from "../asset";
|
|
3
|
+
import { observer } from "../graphics/Observer";
|
|
4
|
+
import { DeserializationObject } from "../Serialization";
|
|
5
|
+
import { Descriptor } from "./Descriptor";
|
|
6
|
+
|
|
7
|
+
export interface Data {
|
|
8
|
+
[k: string]: any
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 数据容器类
|
|
13
|
+
* 用于管理和操作结构化数据集合
|
|
14
|
+
*
|
|
15
|
+
* 作用:作为数据存储和获取的统一接口,提供数据缓存、数据更新通知等功能
|
|
16
|
+
* 注意:该类仅负责数据存储和管理,不涉及视图渲染
|
|
17
|
+
*
|
|
18
|
+
* 典型应用:
|
|
19
|
+
* - 为图表、列表、表单等组件提供动态数据支持
|
|
20
|
+
* - 在交互节点中动态更新数据集,实现数据驱动的流程控制
|
|
21
|
+
* - 作为多个组件间的共享数据源,支持状态同步
|
|
22
|
+
*
|
|
23
|
+
* 与组件集成:通过变量映射机制实现响应式数据绑定
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "uuid": "div-instance-uuid",
|
|
27
|
+
* "type": "Div",
|
|
28
|
+
* "store": "/static:/assets/data/profile.store.json",
|
|
29
|
+
* "variables": {
|
|
30
|
+
* "name": { "type": "key", "enabled": true, "value": "name" },
|
|
31
|
+
* "bgColor": { "type": "key", "enabled": true, "value": "style.htmlAttributes.backgroundColor" },
|
|
32
|
+
* "items": { "type": "key", "enabled": true, "value": "items" }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* 对应的数据集资产:
|
|
38
|
+
* ```json
|
|
39
|
+
* {
|
|
40
|
+
* "uuid": "store-profile-uuid",
|
|
41
|
+
* "type": "Store",
|
|
42
|
+
* "name": "用户资料数据集",
|
|
43
|
+
* "data": {
|
|
44
|
+
* "name": "张三",
|
|
45
|
+
* "bgColor": "#00ff00",
|
|
46
|
+
* "items": ["选项1", "选项2", "选项3"]
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* 交互系统集成:支持作为数据源或目标
|
|
52
|
+
*
|
|
53
|
+
* 1. 数据集获取节点
|
|
54
|
+
* ```json
|
|
55
|
+
* {
|
|
56
|
+
* "id": "exec-find-store",
|
|
57
|
+
* "type": "Execute",
|
|
58
|
+
* "script": "find",
|
|
59
|
+
* "input": {
|
|
60
|
+
* "target": "store-uuid",
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* 2. 数据更新节点:
|
|
66
|
+
* ```json
|
|
67
|
+
* {
|
|
68
|
+
* "id": "exec-update-store",
|
|
69
|
+
* "type": "Execute",
|
|
70
|
+
* "script": "update",
|
|
71
|
+
* "input": {
|
|
72
|
+
* "target": "exec-find-store",
|
|
73
|
+
* "value": { "data": { "name": "李四", "bgColor": "#ff0000" } },
|
|
74
|
+
* "nodeIds":""
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* 数据流动机制:
|
|
80
|
+
* ```
|
|
81
|
+
* 交互节点更新 → 依赖组件收到通知 → 重新读取数据 → 变量映射更新 → 重绘组件
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* 使用场景:
|
|
85
|
+
* - UI数据源:为Div、图表、列表等提供动态数据
|
|
86
|
+
* - 表单/列表管理:存储和管理数据集合
|
|
87
|
+
* - 状态管理:作为全局或局部状态容器,支持多组件状态同步
|
|
88
|
+
*
|
|
89
|
+
* 最佳实践:
|
|
90
|
+
* - 命名应具业务语义,便于识别
|
|
91
|
+
* - 数据设计建议扁平化,避免过深嵌套
|
|
92
|
+
* - 频繁更新的字段可拆分独立数据集,减少通知开销
|
|
93
|
+
* - 组件只映射所需字段,避免不必要依赖
|
|
94
|
+
* - UUID全局唯一,便于精确定位
|
|
95
|
+
*/
|
|
96
|
+
export class Store extends Descriptor {
|
|
97
|
+
/**类类型标识 */
|
|
98
|
+
static type = 'Store'
|
|
99
|
+
|
|
100
|
+
static getData<T = Data>(store: string) {
|
|
101
|
+
const descriptor = Asset.get(store)
|
|
102
|
+
if (descriptor instanceof Store) {
|
|
103
|
+
return descriptor.data as T
|
|
104
|
+
} else {
|
|
105
|
+
return null
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static getCollection<T = Data>(store: string): T[] {
|
|
110
|
+
const data = this.getData<T>(store)
|
|
111
|
+
|
|
112
|
+
if (data === null) return []
|
|
113
|
+
|
|
114
|
+
return Array.isArray(data) ? data : [data]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 数据
|
|
119
|
+
* @default {}
|
|
120
|
+
*/
|
|
121
|
+
data: StoreData
|
|
122
|
+
|
|
123
|
+
constructor(descriptor: Partial<DeserializationObject<Store>> = {}) {
|
|
124
|
+
super(descriptor)
|
|
125
|
+
this.data = StoreDataSchema.parse(descriptor.data)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 设置需要更新
|
|
130
|
+
*/
|
|
131
|
+
setNeedsUpdate() {
|
|
132
|
+
observer.trigger('updateDeps', { self: this.uuid })
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
Descriptor.register(Store)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DeserializationObject } from "../Serialization"
|
|
2
|
+
import { HtmlAttributes, HtmlAttributesSchema } from "../schema"
|
|
3
|
+
import { Descriptor } from "./Descriptor"
|
|
4
|
+
import { HTML } from "./HTML"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Text类
|
|
8
|
+
* 表示一个HTML文本元素,用于在二维场景中显示文本内容
|
|
9
|
+
*
|
|
10
|
+
* 作用:作为二维界面的文本显示控件,支持文本内容的展示
|
|
11
|
+
* 继承自HTML类,拥有HTML元素的所有样式和布局属性
|
|
12
|
+
*/
|
|
13
|
+
export class Text extends Descriptor implements HTML {
|
|
14
|
+
/**类类型标识 */
|
|
15
|
+
static type = 'Text'
|
|
16
|
+
|
|
17
|
+
readonly isHTML = true
|
|
18
|
+
|
|
19
|
+
visible: boolean
|
|
20
|
+
|
|
21
|
+
htmlAttributes: HtmlAttributes
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 文本内容
|
|
25
|
+
* @default ""
|
|
26
|
+
*/
|
|
27
|
+
content: string
|
|
28
|
+
|
|
29
|
+
constructor(descriptor: Partial<DeserializationObject<Text>> = {}) {
|
|
30
|
+
super(descriptor)
|
|
31
|
+
this.visible = descriptor.visible ?? true
|
|
32
|
+
this.htmlAttributes = HtmlAttributesSchema.parse(descriptor.htmlAttributes)
|
|
33
|
+
this.content = descriptor.content ?? ''
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
Descriptor.register(Text)
|
package/src/descriptor/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
export * from './Descriptor'
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './ServiceSchedulerDescriptor'
|
|
2
|
+
export * from './Interaction'
|
|
3
|
+
export * from './Store'
|
|
4
|
+
export * from './HTML'
|
|
5
|
+
export * from './Div'
|
|
6
|
+
export * from './Input'
|
|
7
|
+
export * from './Text'
|
|
8
|
+
export * from './Node'
|
|
9
|
+
export * from './Camera'
|
|
10
|
+
export * from './AnimationUnit'
|
|
11
|
+
export * from './Controller'
|
|
12
|
+
export * from './HTMLTransformController'
|
|
13
|
+
export * from './Service'
|
|
14
|
+
export * from './HTMLService'
|
|
15
|
+
export * from './Scene'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Unit } from "./Unit"
|
|
2
2
|
|
|
3
|
-
class UnitCollection {
|
|
3
|
+
export class UnitCollection {
|
|
4
4
|
private readonly instanceCollection = new Map<string, Unit>()
|
|
5
5
|
|
|
6
6
|
set(unit: Unit) {
|
|
@@ -18,8 +18,4 @@ class UnitCollection {
|
|
|
18
18
|
values() {
|
|
19
19
|
return [...this.instanceCollection.values()]
|
|
20
20
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
UnitCollection
|
|
25
21
|
}
|