@dcl/sdk 7.0.0-3046198202.commit-4f23ef8 → 7.0.0-3063934984.commit-cdc4e28
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/playground/snippets/cube-spawner-example.ts +57 -0
- package/dist/playground/snippets/info.json +1 -0
- package/dist/playground/snippets/material-test.ts +33 -0
- package/dist/playground/snippets/meshes-test-creation.ts +56 -0
- package/dist/playground/snippets/pointer-event-test.ts +49 -0
- package/dist/playground/snippets/raycast-hit-oscillator-example.ts +69 -0
- package/dist/playground/snippets/raycast-test-hit-many.ts +33 -0
- package/dist/playground/snippets/raycast-test-hit-one.ts +32 -0
- package/package.json +4 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Cube factory
|
|
2
|
+
function createCube(x: number, y: number, z: number, spawner = true): Entity {
|
|
3
|
+
const meshEntity = engine.addEntity()
|
|
4
|
+
Transform.create(meshEntity, { position: { x, y, z } })
|
|
5
|
+
MeshRenderer.create(meshEntity, { box: { uvs: [] } })
|
|
6
|
+
MeshCollider.create(meshEntity, { box: {} })
|
|
7
|
+
if (spawner) {
|
|
8
|
+
PointerEvents.create(meshEntity, {
|
|
9
|
+
pointerEvents: [
|
|
10
|
+
{
|
|
11
|
+
eventType: PointerEventType.DOWN,
|
|
12
|
+
eventInfo: {
|
|
13
|
+
button: ActionButton.PRIMARY,
|
|
14
|
+
hoverText: 'Press E to spawn',
|
|
15
|
+
maxDistance: 100,
|
|
16
|
+
showFeedback: true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
return meshEntity
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Systems
|
|
26
|
+
function circularSystem(dt: number) {
|
|
27
|
+
const entitiesWithBoxShapes = engine.getEntitiesWith(BoxShape, Transform)
|
|
28
|
+
for (const [entity, _boxShape, _transform] of entitiesWithBoxShapes) {
|
|
29
|
+
const mutableTransform = Transform.getMutable(entity)
|
|
30
|
+
|
|
31
|
+
mutableTransform.rotation = Quaternion.multiply(
|
|
32
|
+
mutableTransform.rotation,
|
|
33
|
+
Quaternion.angleAxis(dt * 10, Vector3.Up())
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function spawnerSystem() {
|
|
39
|
+
const clickedCubes = engine.getEntitiesWith(PointerEvents)
|
|
40
|
+
for (const [entity] of clickedCubes) {
|
|
41
|
+
if (wasEntityClicked(entity, ActionButton.PRIMARY)) {
|
|
42
|
+
createCube(
|
|
43
|
+
1 + Math.random() * 8,
|
|
44
|
+
Math.random() * 8,
|
|
45
|
+
1 + Math.random() * 8,
|
|
46
|
+
false
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Init
|
|
53
|
+
createCube(8, 1, 8)
|
|
54
|
+
engine.addSystem(circularSystem)
|
|
55
|
+
engine.addSystem(spawnerSystem)
|
|
56
|
+
|
|
57
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"content":[{"path":"cube-spawner-example.ts"},{"path":"material-test.ts"},{"path":"meshes-test-creation.ts"},{"path":"pointer-event-test.ts"},{"path":"raycast-hit-oscillator-example.ts"},{"path":"raycast-test-hit-many.ts"},{"path":"raycast-test-hit-one.ts"}]}
|
|
@@ -0,0 +1,33 @@
|
|
|
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, { sphere: {} })
|
|
5
|
+
return meshEntity
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
Material.create(createSphere(15, 1, 15), {
|
|
9
|
+
albedoColor: { r: 0, g: 0, b: 1 },
|
|
10
|
+
reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
|
|
11
|
+
metallic: 0.8,
|
|
12
|
+
roughness: 0.1
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
Material.create(createSphere(13, 1, 15), {
|
|
16
|
+
albedoColor: { r: 1, g: 1, b: 0 },
|
|
17
|
+
reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
|
|
18
|
+
metallic: 0.1,
|
|
19
|
+
roughness: 0.8,
|
|
20
|
+
|
|
21
|
+
alphaTest: 0.2,
|
|
22
|
+
transparencyMode: TransparencyMode.AlphaTest
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
Material.create(createSphere(11, 1, 15), {
|
|
26
|
+
albedoColor: { r: 0, g: 0, b: 1 },
|
|
27
|
+
reflectivityColor: { r: 0.5, g: 0.5, b: 0.5 },
|
|
28
|
+
metallic: 0.1,
|
|
29
|
+
roughness: 0.1
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// add textures
|
|
33
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
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, { box: { uvs: [] } })
|
|
21
|
+
if (withCollider) MeshCollider.create(meshEntity, { box: {} })
|
|
22
|
+
break
|
|
23
|
+
case Mesh.SPHERE:
|
|
24
|
+
MeshRenderer.create(meshEntity, { sphere: {} })
|
|
25
|
+
if (withCollider) MeshCollider.create(meshEntity, { sphere: {} })
|
|
26
|
+
break
|
|
27
|
+
case Mesh.CONE:
|
|
28
|
+
case Mesh.CYLINDER:
|
|
29
|
+
MeshRenderer.create(meshEntity, {
|
|
30
|
+
cylinder: {
|
|
31
|
+
radiusBottom: 1,
|
|
32
|
+
radiusTop: mesh === Mesh.CONE ? 0 : 1
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
if (withCollider)
|
|
36
|
+
MeshCollider.create(meshEntity, {
|
|
37
|
+
cylinder: {
|
|
38
|
+
radiusBottom: 1,
|
|
39
|
+
radiusTop: mesh === Mesh.CONE ? 0 : 1
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
break
|
|
43
|
+
}
|
|
44
|
+
return meshEntity
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
createMesh(15, 1, 15, Mesh.BOX)
|
|
48
|
+
createMesh(12, 1, 15, Mesh.CONE)
|
|
49
|
+
createMesh(9, 1, 15, Mesh.SPHERE)
|
|
50
|
+
createMesh(6, 1, 15, Mesh.CYLINDER)
|
|
51
|
+
createMesh(15, 1, 1, Mesh.BOX, true)
|
|
52
|
+
createMesh(12, 1, 1, Mesh.CONE, true)
|
|
53
|
+
createMesh(9, 1, 1, Mesh.SPHERE, true)
|
|
54
|
+
createMesh(6, 1, 1, Mesh.CYLINDER, true)
|
|
55
|
+
|
|
56
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Cube factory
|
|
2
|
+
function createCube(
|
|
3
|
+
x: number,
|
|
4
|
+
y: number,
|
|
5
|
+
z: number,
|
|
6
|
+
pointerEvents: PBPointerEvents_Entry[]
|
|
7
|
+
): Entity {
|
|
8
|
+
const meshEntity = engine.addEntity()
|
|
9
|
+
Transform.create(meshEntity, { position: { x, y, z } })
|
|
10
|
+
MeshRenderer.create(meshEntity, { box: { uvs: [] } })
|
|
11
|
+
PointerEvents.create(meshEntity, { pointerEvents })
|
|
12
|
+
return meshEntity
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
createCube(15, 1, 15, [
|
|
16
|
+
{
|
|
17
|
+
eventType: PointerEventType.DOWN,
|
|
18
|
+
eventInfo: {
|
|
19
|
+
button: ActionButton.PRIMARY,
|
|
20
|
+
hoverText: 'PrimaryDown',
|
|
21
|
+
maxDistance: 5,
|
|
22
|
+
showFeedback: true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
createCube(13, 1, 15, [
|
|
28
|
+
{
|
|
29
|
+
eventType: PointerEventType.UP,
|
|
30
|
+
eventInfo: {
|
|
31
|
+
button: ActionButton.SECONDARY,
|
|
32
|
+
hoverText: 'Secondary Up',
|
|
33
|
+
maxDistance: 5,
|
|
34
|
+
showFeedback: true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
createCube(11, 1, 15, [
|
|
40
|
+
{
|
|
41
|
+
eventType: PointerEventType.HOVER_ENTER,
|
|
42
|
+
eventInfo: {
|
|
43
|
+
button: ActionButton.ANY,
|
|
44
|
+
hoverText: 'Infinity Hover',
|
|
45
|
+
maxDistance: 10000000,
|
|
46
|
+
showFeedback: true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
])
|
|
@@ -0,0 +1,69 @@
|
|
|
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, { box: { uvs: [] } })
|
|
23
|
+
MeshCollider.create(cubeEntity, { box: {} })
|
|
24
|
+
|
|
25
|
+
// This should be removed and keep working ok!
|
|
26
|
+
// TODO: see physics layers
|
|
27
|
+
PointerEvents.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.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
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function createCube(x: number, y: number, z: number) {
|
|
2
|
+
const cubeEntity = engine.addEntity()
|
|
3
|
+
|
|
4
|
+
Transform.create(cubeEntity, { position: { x, y, z } })
|
|
5
|
+
|
|
6
|
+
MeshRenderer.create(cubeEntity, { box: { uvs: [] } })
|
|
7
|
+
MeshCollider.create(cubeEntity, { box: {} })
|
|
8
|
+
|
|
9
|
+
// This should be removed and keep working ok!
|
|
10
|
+
// TODO: see physics layers
|
|
11
|
+
PointerEvents.create(cubeEntity)
|
|
12
|
+
return cubeEntity
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
engine.addSystem(() => {
|
|
16
|
+
for (const [_, result] of engine.getEntitiesWith(RaycastResult)) {
|
|
17
|
+
log(`This should be '2': '${result.hits.length}'`)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Init
|
|
22
|
+
createCube(8, 1, 8)
|
|
23
|
+
createCube(8, 1, 4)
|
|
24
|
+
|
|
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.QUERY_ALL
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function createCube(x: number, y: number, z: number) {
|
|
2
|
+
const cubeEntity = engine.addEntity()
|
|
3
|
+
|
|
4
|
+
Transform.create(cubeEntity, { position: { x, y, z } })
|
|
5
|
+
|
|
6
|
+
MeshRenderer.create(cubeEntity, { box: { uvs: [] } })
|
|
7
|
+
MeshCollider.create(cubeEntity, { box: {} })
|
|
8
|
+
|
|
9
|
+
// This should be removed and keep working ok!
|
|
10
|
+
// TODO: see physics layers
|
|
11
|
+
PointerEvents.create(cubeEntity)
|
|
12
|
+
return cubeEntity
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
engine.addSystem(() => {
|
|
16
|
+
for (const [_, result] of engine.getEntitiesWith(RaycastResult)) {
|
|
17
|
+
log(`This should be '1': '${result.hits.length}'`)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Init
|
|
22
|
+
createCube(8, 1, 8)
|
|
23
|
+
|
|
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.HIT_FIRST
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
|
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-3063934984.commit-cdc4e28",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"src/cli/**/*.js"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/amd": "6.11.
|
|
31
|
-
"@dcl/build-ecs": "6.11.
|
|
30
|
+
"@dcl/amd": "6.11.9-3063934984.commit-cdc4e28",
|
|
31
|
+
"@dcl/build-ecs": "6.11.9-3063934984.commit-cdc4e28",
|
|
32
32
|
"@dcl/kernel": "1.0.0-2994874542.commit-c3ae489",
|
|
33
33
|
"@dcl/posix": "^1.0.4",
|
|
34
34
|
"@dcl/schemas": "4.8.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"ignore": "^5.1.8"
|
|
39
39
|
},
|
|
40
40
|
"minCliVersion": "3.10.2",
|
|
41
|
-
"commit": "
|
|
41
|
+
"commit": "cdc4e2877cf4998688a3587031111ff6ea2021f4"
|
|
42
42
|
}
|