@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.
- package/dist/ecs7/index.d.ts +0 -1
- package/dist/ecs7/index.js +2 -8
- package/dist/ecs7/index.min.js +1 -1
- package/dist/ecs7/index.min.js.map +1 -1
- package/dist/ecs7/proto-definitions/raycast.proto +0 -1
- package/dist/playground/snippets/info.json +1 -1
- package/dist/playground/snippets/raycast-hit-many.ts +49 -19
- package/dist/playground/snippets/raycast-hit.ts +48 -18
- package/package.json +5 -5
- package/types/ecs7/index.d.ts +0 -1
- package/dist/playground/snippets/raycast-hit-oscilator.ts +0 -69
@@ -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":"
|
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(
|
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, {
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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(
|
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, {
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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-
|
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-
|
27
|
-
"@dcl/build-ecs": "7.0.0-
|
28
|
-
"@dcl/js-runtime": "7.0.0-
|
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": "
|
34
|
+
"commit": "eb91c8a0f32174d1cc8fa92de52434534a6df33e"
|
35
35
|
}
|
package/types/ecs7/index.d.ts
CHANGED
@@ -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
|
-
|