@dcl/sdk 7.0.0-3548419522.commit-ddcf4b7 → 7.0.0

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 (75) hide show
  1. package/ecs.d.ts +1 -0
  2. package/ecs.js +2 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +11 -0
  5. package/internal/Observable.d.ts +36 -0
  6. package/internal/Observable.js +190 -0
  7. package/internal/transports/networkTransport.d.ts +2 -0
  8. package/internal/transports/networkTransport.js +16 -0
  9. package/internal/transports/rendererTransport.d.ts +7 -0
  10. package/internal/transports/rendererTransport.js +39 -0
  11. package/math.d.ts +3 -0
  12. package/math.js +4 -0
  13. package/messageBus.d.ts +10 -0
  14. package/messageBus.js +43 -0
  15. package/observables.d.ts +225 -0
  16. package/observables.js +75 -0
  17. package/package.json +12 -18
  18. package/react-ecs.d.ts +3 -0
  19. package/react-ecs.js +4 -0
  20. package/src/ecs.ts +1 -0
  21. package/src/index.ts +18 -0
  22. package/src/internal/Observable.ts +425 -0
  23. package/src/internal/transports/networkTransport.ts +24 -0
  24. package/src/internal/transports/rendererTransport.ts +60 -0
  25. package/src/math.ts +3 -0
  26. package/src/messageBus.ts +62 -0
  27. package/src/observables.ts +579 -0
  28. package/src/react-ecs.ts +3 -0
  29. package/tsconfig.json +11 -0
  30. package/types/tsconfig.ecs7.json +3 -8
  31. package/dist/ecs7/index.d.ts +0 -4679
  32. package/dist/ecs7/index.js +0 -15202
  33. package/dist/ecs7/index.min.js +0 -1
  34. package/dist/ecs7/index.min.js.map +0 -1
  35. package/dist/ecs7/proto-definitions/README.md +0 -32
  36. package/dist/ecs7/proto-definitions/Transform.md +0 -25
  37. package/dist/ecs7/proto-definitions/animator.proto +0 -19
  38. package/dist/ecs7/proto-definitions/audio_source.proto +0 -13
  39. package/dist/ecs7/proto-definitions/audio_stream.proto +0 -11
  40. package/dist/ecs7/proto-definitions/avatar_attach.proto +0 -19
  41. package/dist/ecs7/proto-definitions/avatar_modifier_area.proto +0 -19
  42. package/dist/ecs7/proto-definitions/avatar_shape.proto +0 -32
  43. package/dist/ecs7/proto-definitions/billboard.proto +0 -17
  44. package/dist/ecs7/proto-definitions/camera_mode.proto +0 -10
  45. package/dist/ecs7/proto-definitions/camera_mode_area.proto +0 -14
  46. package/dist/ecs7/proto-definitions/common/camera_type.proto +0 -8
  47. package/dist/ecs7/proto-definitions/common/id.md +0 -2
  48. package/dist/ecs7/proto-definitions/common/id.proto +0 -8
  49. package/dist/ecs7/proto-definitions/common/input_action.proto +0 -20
  50. package/dist/ecs7/proto-definitions/common/texts.proto +0 -20
  51. package/dist/ecs7/proto-definitions/gltf_container.proto +0 -13
  52. package/dist/ecs7/proto-definitions/material.proto +0 -56
  53. package/dist/ecs7/proto-definitions/mesh_collider.proto +0 -35
  54. package/dist/ecs7/proto-definitions/mesh_renderer.proto +0 -30
  55. package/dist/ecs7/proto-definitions/nft_shape.proto +0 -40
  56. package/dist/ecs7/proto-definitions/pointer_events_result.proto +0 -25
  57. package/dist/ecs7/proto-definitions/pointer_hover_feedback.proto +0 -31
  58. package/dist/ecs7/proto-definitions/pointer_lock.proto +0 -9
  59. package/dist/ecs7/proto-definitions/raycast.proto +0 -20
  60. package/dist/ecs7/proto-definitions/raycast_result.proto +0 -25
  61. package/dist/ecs7/proto-definitions/text_shape.proto +0 -33
  62. package/dist/ecs7/proto-definitions/ui_background.proto +0 -11
  63. package/dist/ecs7/proto-definitions/ui_text.proto +0 -17
  64. package/dist/ecs7/proto-definitions/ui_transform.proto +0 -141
  65. package/dist/ecs7/proto-definitions/visibility_component.proto +0 -9
  66. package/dist/playground/snippets/billboard.ts +0 -108
  67. package/dist/playground/snippets/cube-spawner.ts +0 -39
  68. package/dist/playground/snippets/info.json +0 -1
  69. package/dist/playground/snippets/material.ts +0 -48
  70. package/dist/playground/snippets/mesh.ts +0 -68
  71. package/dist/playground/snippets/pointer-events.ts +0 -50
  72. package/dist/playground/snippets/raycast-hit-many.ts +0 -63
  73. package/dist/playground/snippets/raycast-hit.ts +0 -62
  74. package/dist/playground/snippets/ui.tsx +0 -134
  75. package/types/ecs7/index.d.ts +0 -4679
@@ -1,141 +0,0 @@
1
- syntax = "proto3";
2
-
3
- package decentraland.sdk.components;
4
-
5
- import "decentraland/sdk/components/common/id.proto";
6
-
7
- option (common.ecs_component_id) = 1050;
8
-
9
- enum YGPositionType {
10
- YGPT_RELATIVE = 0;
11
- YGPT_ABSOLUTE = 1;
12
- }
13
-
14
- enum YGAlign {
15
- YGA_AUTO = 0;
16
- YGA_FLEX_START = 1;
17
- YGA_CENTER = 2;
18
- YGA_FLEX_END = 3;
19
- YGA_STRETCH = 4;
20
- YGA_BASELINE = 5;
21
- YGA_SPACE_BETWEEN = 6;
22
- YGA_SPACE_AROUND = 7;
23
- }
24
-
25
- enum YGUnit {
26
- YGU_UNDEFINED = 0;
27
- YGU_POINT = 1;
28
- YGU_PERCENT = 2;
29
- YGU_AUTO = 3;
30
- }
31
-
32
- enum YGFlexDirection {
33
- YGFD_ROW = 0;
34
- YGFD_COLUMN = 1;
35
- YGFD_COLUMN_REVERSE = 2;
36
- YGFD_ROW_REVERSE = 3;
37
- }
38
-
39
- enum YGWrap {
40
- YGW_NO_WRAP = 0;
41
- YGW_WRAP = 1;
42
- YGW_WRAP_REVERSE = 2;
43
- }
44
-
45
- enum YGJustify {
46
- YGJ_FLEX_START = 0;
47
- YGJ_CENTER = 1;
48
- YGJ_FLEX_END = 2;
49
- YGJ_SPACE_BETWEEN = 3;
50
- YGJ_SPACE_AROUND = 4;
51
- YGJ_SPACE_EVENLY = 5;
52
- }
53
-
54
- enum YGOverflow {
55
- YGO_VISIBLE = 0;
56
- YGO_HIDDEN = 1;
57
- YGO_SCROLL = 2;
58
- }
59
-
60
- enum YGDisplay {
61
- YGD_FLEX = 0;
62
- YGD_NONE = 1;
63
- }
64
-
65
- enum YGEdge {
66
- YGE_LEFT = 0;
67
- YGE_TOP = 1;
68
- YGE_RIGHT = 2;
69
- YGE_BOTTOM = 3;
70
- YGE_START = 4;
71
- YGE_END = 5;
72
- YGE_HORIZONTAL = 6;
73
- YGE_VERTICAL = 7;
74
- YGE_ALL = 8;
75
- }
76
-
77
- message PBUiTransform {
78
- int32 parent = 1;
79
- int32 right_of = 2;
80
-
81
- optional YGAlign align_content = 3; // default: YGAlign.YGA_FLEX_START
82
- optional YGAlign align_items = 4; // default: YGAlign.YGA_STRETCH
83
- optional YGWrap flex_wrap = 5; // default: YGWrap.YGW_WRAP
84
- optional float flex_shrink = 6; // default: 1
85
-
86
- YGPositionType position_type = 7; // YGPositionType.YGPT_RELATIVE
87
-
88
- YGAlign align_self = 8; // YGAlign.YGA_AUTO
89
- YGFlexDirection flex_direction = 9; // YGFlexDirection.YGFD_ROW
90
- YGJustify justify_content = 10; // YGJustify.YGJ_FLEX_START
91
-
92
- YGOverflow overflow = 11; // YGOverflow.YGO_VISIBLE
93
- YGDisplay display = 12; // YGDisplay.YGD_FLEX
94
-
95
- YGUnit flex_basis_unit = 13; // YGUnit.YGU_UNDEFINED
96
- float flex_basis = 14;
97
-
98
- float flex_grow = 15;
99
-
100
- YGUnit width_unit = 16; // YGUnit.YGU_UNDEFINED
101
- float width = 17;
102
- YGUnit height_unit = 18; // YGUnit.YGU_UNDEFINED
103
- float height = 19;
104
-
105
- YGUnit min_width_unit = 20; // YGUnit.YGU_UNDEFINED
106
- float min_width = 21;
107
- YGUnit min_height_unit = 22; // YGUnit.YGU_UNDEFINED
108
- float min_height = 23;
109
-
110
- YGUnit max_width_unit = 24; // YGUnit.YGU_UNDEFINED
111
- float max_width = 25;
112
- YGUnit max_height_unit = 26; // YGUnit.YGU_UNDEFINED
113
- float max_height = 27;
114
-
115
- YGUnit position_left_unit = 28; // YGUnit.YGU_UNDEFINED
116
- float position_left = 29;
117
- YGUnit position_top_unit = 30; // YGUnit.YGU_UNDEFINED
118
- float position_top = 31;
119
- YGUnit position_right_unit = 32; // YGUnit.YGU_UNDEFINED
120
- float position_right = 33;
121
- YGUnit position_bottom_unit = 34; // YGUnit.YGU_UNDEFINED
122
- float position_bottom = 35;
123
-
124
- YGUnit margin_left_unit = 36; // YGUnit.YGU_UNDEFINED
125
- float margin_left = 37;
126
- YGUnit margin_top_unit = 38; // YGUnit.YGU_UNDEFINED
127
- float margin_top = 39;
128
- YGUnit margin_right_unit = 40; // YGUnit.YGU_UNDEFINED
129
- float margin_right = 41;
130
- YGUnit margin_bottom_unit = 42; // YGUnit.YGU_UNDEFINED
131
- float margin_bottom = 43;
132
-
133
- YGUnit padding_left_unit = 44; // YGUnit.YGU_UNDEFINED
134
- float padding_left = 45;
135
- YGUnit padding_top_unit = 46; // YGUnit.YGU_UNDEFINED
136
- float padding_top = 47;
137
- YGUnit padding_right_unit = 48; // YGUnit.YGU_UNDEFINED
138
- float padding_right = 49;
139
- YGUnit padding_bottom_unit = 50; // YGUnit.YGU_UNDEFINED
140
- float padding_bottom = 51;
141
- }
@@ -1,9 +0,0 @@
1
- syntax = "proto3";
2
- package decentraland.sdk.components;
3
-
4
- import "decentraland/sdk/components/common/id.proto";
5
- option (common.ecs_component_id) = 1081;
6
-
7
- message PBVisibilityComponent {
8
- optional bool visible = 1; // default=true
9
- }
@@ -1,108 +0,0 @@
1
- function createPlaneTexture(x: number, y: number, z: number): Entity {
2
- const meshEntity = engine.addEntity()
3
-
4
- Material.create(meshEntity, {
5
- material: {
6
- $case: 'pbr',
7
- pbr: {
8
- texture: {
9
- tex: {
10
- $case: 'texture',
11
- texture: { src: 'models/polaroid2.png' }
12
- }
13
- }
14
- }
15
- }
16
- })
17
- Transform.create(meshEntity, {
18
- position: { x, y, z },
19
- scale: Vector3.create(2, 2, 2)
20
- })
21
- MeshRenderer.create(meshEntity, {
22
- mesh: {
23
- $case: 'plane',
24
- plane: {
25
- uvs: [...Array.from({ length: 40 }, () => 0), 0, 1, 1, 1, 1, 0, 0, 0]
26
- }
27
- }
28
- })
29
- return meshEntity
30
- }
31
-
32
- function createBillboards() {
33
- const plane1 = createPlaneTexture(8, 3, 1)
34
- const plane2 = createPlaneTexture(12, 3, 1)
35
- createPlaneTexture(4, 3, 1)
36
-
37
- const plane5 = createPlaneTexture(8, 3, 8)
38
- const plane4 = createPlaneTexture(12, 3, 8)
39
- createPlaneTexture(4, 3, 8)
40
-
41
- Billboard.create(plane1, {
42
- billboardMode: BillboardMode.BM_Y_AXE
43
- })
44
- Billboard.create(plane2)
45
- Billboard.create(plane4, {
46
- oppositeDirection: true,
47
- billboardMode: BillboardMode.BM_ALL_AXES
48
- })
49
- Billboard.create(plane5, {
50
- oppositeDirection: true,
51
- billboardMode: BillboardMode.BM_Y_AXE
52
- })
53
- }
54
-
55
- function createTextShape(text: string, position: Vector3, textColor: Color4) {
56
- const entity = engine.addEntity()
57
- Transform.create(entity, { position })
58
- return TextShape.create(entity, {
59
- text,
60
- fontSize: 3,
61
- outlineWidth: 0.1,
62
- outlineColor: Color3.Black(),
63
- textColor
64
- })
65
- }
66
-
67
- function createTextShapes() {
68
- const regularColor = Color4.create(1, 0.2, 0.8, 0.8)
69
- const oppositeColor = Color4.create(0.8, 0.2, 1, 0.8)
70
-
71
- createTextShape(
72
- 'Regular, only Y-rotation',
73
- Vector3.create(8, 1, 1),
74
- regularColor
75
- )
76
- createTextShape('Regular', Vector3.create(12, 1, 1), regularColor)
77
- createTextShape('Without billboard', Vector3.create(4, 1, 1), regularColor)
78
- createTextShape('Opposite, only Y', Vector3.create(8, 1, 8), oppositeColor)
79
- createTextShape('Opposite', Vector3.create(12, 1, 8), oppositeColor)
80
- createTextShape('Without billboard', Vector3.create(4, 1, 8), oppositeColor)
81
- }
82
-
83
- createBillboards()
84
- createTextShapes()
85
-
86
- const BouncingBillboard = engine.defineComponent(
87
- {
88
- t: Schemas.Number,
89
- originalPosition: Schemas.Vector3
90
- },
91
- 123123
92
- )
93
-
94
- engine.addSystem((dt: number) => {
95
- for (const [entity] of engine.getEntitiesWith(Billboard, Transform)) {
96
- if (BouncingBillboard.getOrNull(entity) === null) {
97
- BouncingBillboard.create(entity, {
98
- originalPosition: Transform.get(entity).position
99
- })
100
- }
101
-
102
- const bounce = BouncingBillboard.getMutable(entity)
103
- bounce.t += dt
104
-
105
- Transform.getMutable(entity).position.y =
106
- bounce.originalPosition.y + 0.05 * Math.sin(10 * bounce.t)
107
- }
108
- })
@@ -1,39 +0,0 @@
1
- // Cube factory
2
- function createCube(x: number, y: number, z: number): Entity {
3
- const meshEntity = engine.addEntity()
4
- Transform.create(meshEntity, { position: { x, y, z } })
5
- MeshRenderer.create(meshEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
6
- MeshCollider.create(meshEntity, { mesh: { $case: 'box', box: {} } })
7
-
8
- return meshEntity
9
- }
10
-
11
- // Systems
12
- function circularSystem(dt: number) {
13
- const entitiesWithMeshRenderer = engine.getEntitiesWith(
14
- MeshRenderer,
15
- Transform
16
- )
17
- for (const [entity, _meshRenderer, _transform] of entitiesWithMeshRenderer) {
18
- const mutableTransform = Transform.getMutable(entity)
19
-
20
- mutableTransform.rotation = Quaternion.multiply(
21
- mutableTransform.rotation,
22
- Quaternion.fromAngleAxis(dt * 10, Vector3.Up())
23
- )
24
- }
25
- }
26
-
27
- // Init
28
- const initEntity = createCube(8, 1, 8)
29
- EventsSystem.onPointerDown(
30
- initEntity,
31
- () => {
32
- createCube(1 + Math.random() * 8, Math.random() * 8, 1 + Math.random() * 8)
33
- },
34
- { button: InputAction.IA_PRIMARY, hoverText: 'Press E to spawn' }
35
- )
36
-
37
- engine.addSystem(circularSystem)
38
-
39
-
@@ -1 +0,0 @@
1
- [{"name":"Billboard","category":"sample","path":"billboard.ts"},{"name":"Cube Spawner","category":"sample","path":"cube-spawner.ts"},{"name":"Material","category":"component","path":"material.ts"},{"name":"Mesh","category":"component","path":"mesh.ts"},{"name":"Pointer Events","category":"sample","path":"pointer-events.ts"},{"name":"Raycast Hit","category":"component","path":"raycast-hit.ts"},{"name":"Raycast Hit many","category":"sample","path":"raycast-hit-many.ts"},{"name":"Container","category":"ui","path":"ui.tsx"}]
@@ -1,48 +0,0 @@
1
- function createSphere(x: number, y: number, z: number): Entity {
2
- const meshEntity = engine.addEntity()
3
- Transform.create(meshEntity, { position: { x, y, z } })
4
- MeshRenderer.create(meshEntity, { mesh: { $case: 'sphere', sphere: {} } })
5
- return meshEntity
6
- }
7
-
8
- Material.create(createSphere(15, 1, 15), {
9
- material: {
10
- $case: 'pbr',
11
- pbr: {
12
- albedoColor: { r: 0, g: 0, b: 1 },
13
- reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
14
- metallic: 0.8,
15
- roughness: 0.1
16
- }
17
- }
18
- })
19
-
20
- Material.create(createSphere(13, 1, 15), {
21
- material: {
22
- $case: 'pbr',
23
- pbr: {
24
- albedoColor: { r: 1, g: 1, b: 0 },
25
- reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
26
- metallic: 0.1,
27
- roughness: 0.8,
28
-
29
- alphaTest: 0.2,
30
- transparencyMode: MaterialTransparencyMode.MTM_ALPHA_TEST
31
- }
32
- }
33
- })
34
-
35
- Material.create(createSphere(11, 1, 15), {
36
- material: {
37
- $case: 'pbr',
38
- pbr: {
39
- albedoColor: { r: 0, g: 0, b: 1 },
40
- reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
41
- metallic: 0.1,
42
- roughness: 0.1
43
- }
44
- }
45
- })
46
-
47
- // add textures
48
-
@@ -1,68 +0,0 @@
1
- enum Mesh {
2
- BOX,
3
- CYLINDER,
4
- SPHERE,
5
- CONE
6
- }
7
-
8
- function createMesh(
9
- x: number,
10
- y: number,
11
- z: number,
12
- mesh: Mesh,
13
- withCollider: boolean = false
14
- ) {
15
- const meshEntity = engine.addEntity()
16
- Transform.create(meshEntity, { position: { x, y, z } })
17
-
18
- switch (mesh) {
19
- case Mesh.BOX:
20
- MeshRenderer.create(meshEntity, {
21
- mesh: { $case: 'box', box: { uvs: [] } }
22
- })
23
- if (withCollider)
24
- MeshCollider.create(meshEntity, { mesh: { $case: 'box', box: {} } })
25
- break
26
- case Mesh.SPHERE:
27
- MeshRenderer.create(meshEntity, { mesh: { $case: 'sphere', sphere: {} } })
28
- if (withCollider)
29
- MeshCollider.create(meshEntity, {
30
- mesh: { $case: 'sphere', sphere: {} }
31
- })
32
- break
33
- case Mesh.CONE:
34
- case Mesh.CYLINDER:
35
- MeshRenderer.create(meshEntity, {
36
- mesh: {
37
- $case: 'cylinder',
38
- cylinder: {
39
- radiusBottom: 1,
40
- radiusTop: mesh === Mesh.CONE ? 0 : 1
41
- }
42
- }
43
- })
44
- if (withCollider)
45
- MeshCollider.create(meshEntity, {
46
- mesh: {
47
- $case: 'cylinder',
48
- cylinder: {
49
- radiusBottom: 1,
50
- radiusTop: mesh === Mesh.CONE ? 0 : 1
51
- }
52
- }
53
- })
54
- break
55
- }
56
- return meshEntity
57
- }
58
-
59
- createMesh(15, 1, 15, Mesh.BOX)
60
- createMesh(12, 1, 15, Mesh.CONE)
61
- createMesh(9, 1, 15, Mesh.SPHERE)
62
- createMesh(6, 1, 15, Mesh.CYLINDER)
63
- createMesh(15, 1, 1, Mesh.BOX, true)
64
- createMesh(12, 1, 1, Mesh.CONE, true)
65
- createMesh(9, 1, 1, Mesh.SPHERE, true)
66
- createMesh(6, 1, 1, Mesh.CYLINDER, true)
67
-
68
-
@@ -1,50 +0,0 @@
1
- // Cube factory
2
- function createCube(
3
- x: number,
4
- y: number,
5
- z: number,
6
- pointerEvents: PBPointerHoverFeedback_Entry[]
7
- ): Entity {
8
- const meshEntity = engine.addEntity()
9
- Transform.create(meshEntity, { position: { x, y, z } })
10
- MeshRenderer.create(meshEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
11
- MeshCollider.create(meshEntity, { mesh: { $case: 'box', box: {} } })
12
- PointerHoverFeedback.create(meshEntity, { pointerEvents })
13
- return meshEntity
14
- }
15
-
16
- createCube(15, 1, 15, [
17
- {
18
- eventType: PointerEventType.PET_DOWN,
19
- eventInfo: {
20
- button: InputAction.IA_PRIMARY,
21
- hoverText: 'PrimaryDown',
22
- maxDistance: 5,
23
- showFeedback: true
24
- }
25
- }
26
- ])
27
-
28
- createCube(13, 1, 15, [
29
- {
30
- eventType: PointerEventType.PET_UP,
31
- eventInfo: {
32
- button: InputAction.IA_SECONDARY,
33
- hoverText: 'Secondary Up',
34
- maxDistance: 5,
35
- showFeedback: true
36
- }
37
- }
38
- ])
39
-
40
- createCube(11, 1, 15, [
41
- {
42
- eventType: PointerEventType.PET_HOVER_ENTER,
43
- eventInfo: {
44
- button: InputAction.IA_ANY,
45
- hoverText: 'Infinity Hover',
46
- maxDistance: 10000000,
47
- showFeedback: true
48
- }
49
- }
50
- ])
@@ -1,63 +0,0 @@
1
- function createCube(
2
- x: number,
3
- y: number,
4
- z: number,
5
- scaleMultiplier: number = 1
6
- ) {
7
- const cubeEntity = engine.addEntity()
8
-
9
- Transform.create(cubeEntity, {
10
- position: { x, y, z },
11
- scale: { x: scaleMultiplier, y: scaleMultiplier, z: scaleMultiplier }
12
- })
13
-
14
- MeshRenderer.create(cubeEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
15
- MeshCollider.create(cubeEntity, { mesh: { $case: 'box', box: {} } })
16
-
17
- return cubeEntity
18
- }
19
-
20
- // Create cube to hit
21
- const cubeEntity = createCube(8, 1, 8)
22
- const _cubeEntity2 = createCube(8, 1, 13)
23
- const raycastEntity = engine.addEntity()
24
-
25
- // Add OnPointerDown component to cube entity to trigger ray casting on interaction
26
- EventsSystem.onPointerDown(
27
- cubeEntity,
28
- () => {
29
- Raycast.createOrReplace(raycastEntity, {
30
- origin: Vector3.create(8, 1, 0.1),
31
- direction: Vector3.create(0, 0, 1),
32
- maxDistance: 16,
33
- queryType: RaycastQueryType.RQT_QUERY_ALL
34
- })
35
- },
36
- {
37
- button: InputAction.IA_POINTER,
38
- hoverText: 'CAST RAY'
39
- }
40
- )
41
-
42
- // System to detect new raycast responses and instantiate a cube where the ray hits
43
- let lastRaycastTimestamp = -1
44
- engine.addSystem(() => {
45
- for (const [_entity, result] of engine.getEntitiesWith(RaycastResult)) {
46
- if (result.hits?.length === 0 || result.timestamp <= lastRaycastTimestamp)
47
- continue
48
- lastRaycastTimestamp = result.timestamp
49
-
50
- if (result.hits[0] && result.hits[0].position) {
51
- createCube(
52
- result.hits[0].position.x,
53
- result.hits[0].position.y,
54
- result.hits[0].position.z,
55
- 0.3
56
- )
57
- }
58
-
59
- log(`Hits (this should be '2' the first time): '${result.hits.length}'`)
60
- }
61
- })
62
-
63
-
@@ -1,62 +0,0 @@
1
- function createCube(
2
- x: number,
3
- y: number,
4
- z: number,
5
- scaleMultiplier: number = 1
6
- ) {
7
- const cubeEntity = engine.addEntity()
8
-
9
- Transform.create(cubeEntity, {
10
- position: { x, y, z },
11
- scale: { x: scaleMultiplier, y: scaleMultiplier, z: scaleMultiplier }
12
- })
13
-
14
- MeshRenderer.create(cubeEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
15
- MeshCollider.create(cubeEntity, { mesh: { $case: 'box', box: {} } })
16
-
17
- return cubeEntity
18
- }
19
-
20
- // Create cube to hit
21
- const cubeEntity = createCube(8, 1, 8)
22
- const raycastEntity = engine.addEntity()
23
-
24
- // Add OnPointerDown component to cube entity to trigger ray casting on interaction
25
- EventsSystem.onPointerDown(
26
- cubeEntity,
27
- () => {
28
- Raycast.createOrReplace(raycastEntity, {
29
- origin: Vector3.create(8, 1, 0.1),
30
- direction: Vector3.create(0, 0, 1),
31
- maxDistance: 16,
32
- queryType: RaycastQueryType.RQT_HIT_FIRST
33
- })
34
- },
35
- {
36
- button: InputAction.IA_POINTER,
37
- hoverText: 'CAST RAY'
38
- }
39
- )
40
-
41
- // System to detect new raycast responses and instantiate a cube where the ray hits
42
- let lastRaycastTimestamp = -1
43
- engine.addSystem(() => {
44
- for (const [_entity, result] of engine.getEntitiesWith(RaycastResult)) {
45
- if (result.hits?.length === 0 || result.timestamp <= lastRaycastTimestamp)
46
- continue
47
- lastRaycastTimestamp = result.timestamp
48
-
49
- if (result.hits[0] && result.hits[0].position) {
50
- createCube(
51
- result.hits[0].position.x,
52
- result.hits[0].position.y,
53
- result.hits[0].position.z,
54
- 0.3
55
- )
56
- }
57
-
58
- log(`Hits (this should be '1'): '${result.hits.length}'`)
59
- }
60
- })
61
-
62
-