@dcl/sdk 7.0.0-3516625640.commit-f059a45 → 7.0.0-3524388923.commit-eb91c8a

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.
@@ -13,7 +13,6 @@ enum RaycastQueryType {
13
13
  }
14
14
 
15
15
  message PBRaycast {
16
- int32 timestamp = 1;
17
16
  decentraland.common.Vector3 origin = 2;
18
17
  decentraland.common.Vector3 direction = 3;
19
18
  float max_distance = 4;
@@ -1 +1 @@
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":"Raycast Hit Oscilator","category":"sample","path":"raycast-hit-oscilator.ts"},{"name":"Container","category":"ui","path":"ui.tsx"}]
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,33 +1,63 @@
1
- function createCube(x: number, y: number, z: number) {
1
+ function createCube(
2
+ x: number,
3
+ y: number,
4
+ z: number,
5
+ scaleMultiplier: number = 1
6
+ ) {
2
7
  const cubeEntity = engine.addEntity()
3
8
 
4
- Transform.create(cubeEntity, { position: { x, y, z } })
9
+ Transform.create(cubeEntity, {
10
+ position: { x, y, z },
11
+ scale: { x: scaleMultiplier, y: scaleMultiplier, z: scaleMultiplier }
12
+ })
5
13
 
6
14
  MeshRenderer.create(cubeEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
7
15
  MeshCollider.create(cubeEntity, { mesh: { $case: 'box', box: {} } })
8
16
 
9
- // This should be removed and keep working ok!
10
- // TODO: see physics layers
11
- PointerHoverFeedback.create(cubeEntity)
12
17
  return cubeEntity
13
18
  }
14
19
 
15
- engine.addSystem(() => {
16
- for (const [_, result] of engine.getEntitiesWith(RaycastResult)) {
17
- log(`This should be '2': '${result.hits.length}'`)
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'
18
39
  }
19
- })
20
-
21
- // Init
22
- createCube(8, 1, 8)
23
- createCube(8, 1, 4)
40
+ )
24
41
 
25
- Raycast.createOrReplace(engine.addEntity(), {
26
- timestamp: 123,
27
- origin: Vector3.create(8, 1, 0),
28
- direction: Vector3.create(0, 0, 1),
29
- maxDistance: 16,
30
- queryType: RaycastQueryType.RQT_QUERY_ALL
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
+ }
31
61
  })
32
62
 
33
63
 
@@ -1,32 +1,62 @@
1
- function createCube(x: number, y: number, z: number) {
1
+ function createCube(
2
+ x: number,
3
+ y: number,
4
+ z: number,
5
+ scaleMultiplier: number = 1
6
+ ) {
2
7
  const cubeEntity = engine.addEntity()
3
8
 
4
- Transform.create(cubeEntity, { position: { x, y, z } })
9
+ Transform.create(cubeEntity, {
10
+ position: { x, y, z },
11
+ scale: { x: scaleMultiplier, y: scaleMultiplier, z: scaleMultiplier }
12
+ })
5
13
 
6
14
  MeshRenderer.create(cubeEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
7
15
  MeshCollider.create(cubeEntity, { mesh: { $case: 'box', box: {} } })
8
16
 
9
- // This should be removed and keep working ok!
10
- // TODO: see physics layers
11
- PointerHoverFeedback.create(cubeEntity)
12
17
  return cubeEntity
13
18
  }
14
19
 
15
- engine.addSystem(() => {
16
- for (const [_, result] of engine.getEntitiesWith(RaycastResult)) {
17
- log(`This should be '1': '${result.hits.length}'`)
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'
18
38
  }
19
- })
20
-
21
- // Init
22
- createCube(8, 1, 8)
39
+ )
23
40
 
24
- Raycast.createOrReplace(engine.addEntity(), {
25
- timestamp: 123,
26
- origin: Vector3.create(8, 1, 0),
27
- direction: Vector3.create(0, 0, 1),
28
- maxDistance: 16,
29
- queryType: RaycastQueryType.RQT_HIT_FIRST
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
+ }
30
60
  })
31
61
 
32
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/sdk",
3
- "version": "7.0.0-3516625640.commit-f059a45",
3
+ "version": "7.0.0-3524388923.commit-eb91c8a",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -23,13 +23,13 @@
23
23
  "artifacts"
24
24
  ],
25
25
  "dependencies": {
26
- "@dcl/amd": "7.0.0-3516625640.commit-f059a45",
27
- "@dcl/build-ecs": "7.0.0-3516625640.commit-f059a45",
28
- "@dcl/js-runtime": "7.0.0-3516625640.commit-f059a45",
26
+ "@dcl/amd": "7.0.0-3524388923.commit-eb91c8a",
27
+ "@dcl/build-ecs": "7.0.0-3524388923.commit-eb91c8a",
28
+ "@dcl/js-runtime": "7.0.0-3524388923.commit-eb91c8a",
29
29
  "@dcl/kernel": "^1.0.0-3339209749.commit-fa9e5d7",
30
30
  "@dcl/posix": "^1.0.4",
31
31
  "@dcl/unity-renderer": "^1.0.59980-20221027151836.commit-cc26142"
32
32
  },
33
33
  "minCliVersion": "3.12.3",
34
- "commit": "f059a450ced467827681c935f0256e0ff8789040"
34
+ "commit": "eb91c8a0f32174d1cc8fa92de52434534a6df33e"
35
35
  }
@@ -3006,7 +3006,6 @@ declare interface PBPosition {
3006
3006
  }
3007
3007
 
3008
3008
  declare interface PBRaycast {
3009
- timestamp: number;
3010
3009
  origin: PBVector3 | undefined;
3011
3010
  direction: PBVector3 | undefined;
3012
3011
  maxDistance: number;
@@ -1,69 +0,0 @@
1
- const CubeComponent = engine.defineComponent(
2
- {
3
- t: Schemas.Float
4
- },
5
- 212
6
- )
7
-
8
- const RaycasterComponent = engine.defineComponent(
9
- {
10
- ts: Schemas.Int,
11
- t: Schemas.Float
12
- },
13
- 213
14
- )
15
-
16
- function createCube(x: number, y: number, z: number) {
17
- const cubeEntity = engine.addEntity()
18
-
19
- Transform.create(cubeEntity, { position: { x, y, z } })
20
- CubeComponent.create(cubeEntity)
21
-
22
- MeshRenderer.create(cubeEntity, { mesh: { $case: 'box', box: { uvs: [] } } })
23
- MeshCollider.create(cubeEntity, { mesh: { $case: 'box', box: {} } })
24
-
25
- // This should be removed and keep working ok!
26
- // TODO: see physics layers
27
- PointerHoverFeedback.create(cubeEntity)
28
- return cubeEntity
29
- }
30
-
31
- engine.addSystem((dt) => {
32
- for (const [entity] of engine.getEntitiesWith(RaycasterComponent)) {
33
- const raycaster = RaycasterComponent.getMutable(entity)
34
- raycaster.t += dt
35
-
36
- if (raycaster.t > 0.1) {
37
- raycaster.ts++
38
- raycaster.t = 0
39
-
40
- Raycast.createOrReplace(entity, {
41
- timestamp: raycaster.ts,
42
- origin: Vector3.create(8, 1, 0),
43
- direction: Vector3.create(0, 0, 1),
44
- maxDistance: 16,
45
- queryType: RaycastQueryType.RQT_HIT_FIRST
46
- })
47
- }
48
- }
49
-
50
- for (const [_, result] of engine.getEntitiesWith(RaycastResult)) {
51
- log(result.hits.length)
52
- }
53
- })
54
-
55
- engine.addSystem((dt) => {
56
- for (const [entity, cube] of engine.getEntitiesWith(
57
- CubeComponent,
58
- Transform
59
- )) {
60
- CubeComponent.getMutable(entity).t += dt
61
- Transform.getMutable(entity).position.y = 2 + Math.cos(cube.t)
62
- }
63
- })
64
-
65
- // Init
66
- createCube(8, 1, 8)
67
- RaycasterComponent.create(engine.addEntity())
68
-
69
-