Skip to content

Commit

Permalink
feat: texture mapping movement tween support (#1028)
Browse files Browse the repository at this point in the history
* Updated protocol

* Updated playground-assets.api.md

* Fixed Material tests

* Fixed test in UiBackground.spec.ts

* Fix lint pass

* Set protocol PR and updated the API

* Added TextureMove to the helper methods

* Updated API

* Updated protocol PR. Updated API. Added test to reach 100% coverage

* Fixed Tween TextureMove test

* Updated protocol with branch PR. Added TextureMove mode for backwardsTween to support YOYO repeat mode in TweenSequence. Added test for TextureMove tween

* Lint pass

* Updated protocol and rebuilt API

* Removed properties from test

* Updated protocol and API

* Updated protocol pointer

* Properly updated protocol

* Updated snapshots

* Fix test

* update snapshots

---------

Co-authored-by: Gonzalo DCL <[email protected]>
  • Loading branch information
AlejandroAlvarezMelucciDCL and gonpombo8 authored Jan 10, 2025
1 parent 392992d commit 293fd08
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 63 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
"dependencies": {
"@actions/core": "^1.10.0",
"@dcl/protocol": "1.0.0-11780504028.commit-c886080",
"@dcl/protocol": "1.0.0-11954515774.commit-3fb0262",
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
"@dcl/ts-proto": "1.153.0",
"@types/fs-extra": "^9.0.12",
Expand Down
13 changes: 12 additions & 1 deletion packages/@dcl/ecs/src/components/extended/Tween.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine'
import { Tween, PBTween, Move, Rotate, Scale } from '../generated/index.gen'
import { Tween, PBTween, Move, Rotate, Scale, TextureMove } from '../generated/index.gen'

/**
* @public
Expand All @@ -17,6 +17,11 @@ export interface TweenHelper {
* @returns a move mode tween
*/
Scale: (scale: Scale) => PBTween['mode']

/**
* @returns a texture move mode tween
*/
TextureMove: (textureMove: TextureMove) => PBTween['mode']
}

/**
Expand Down Expand Up @@ -47,6 +52,12 @@ const TweenHelper: TweenHelper = {
$case: 'scale',
scale
}
},
TextureMove(textureMove) {
return {
$case: 'textureMove',
textureMove
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/@dcl/ecs/src/systems/tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export function createTweenSystem(engine: IEngine): TweenSystem {
if (tween.mode?.$case === 'scale' && tween.mode.scale) {
return { ...tween, mode: { ...tween.mode, scale: { start: tween.mode.scale.end, end: tween.mode.scale.start } } }
}
if (tween.mode?.$case === 'textureMove' && tween.mode.textureMove) {
return {
...tween,
mode: { ...tween.mode, textureMove: { start: tween.mode.textureMove.end, end: tween.mode.textureMove.start } }
}
}

/* istanbul ignore next */
throw new Error('Invalid tween')
Expand Down
29 changes: 29 additions & 0 deletions packages/@dcl/playground-assets/etc/playground-assets.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,9 @@ export interface PBTween {
} | {
$case: "scale";
scale: Scale;
} | {
$case: "textureMove";
textureMove: TextureMove;
} | undefined;
playing?: boolean | undefined;
}
Expand Down Expand Up @@ -3959,6 +3962,30 @@ export interface TextureHelper {
// @public
export type TextureMode = 'nine-slices' | 'center' | 'stretch';

// @public (undocumented)
export interface TextureMove {
// (undocumented)
end: PBVector2 | undefined;
movementType?: TextureMovementType | undefined;
// (undocumented)
start: PBVector2 | undefined;
}

// @public (undocumented)
export namespace TextureMove {
// (undocumented)
export function decode(input: _m0.Reader | Uint8Array, length?: number): TextureMove;
// (undocumented)
export function encode(message: TextureMove, writer?: _m0.Writer): _m0.Writer;
}

// @public (undocumented)
export const enum TextureMovementType {
TMT_OFFSET = 0,
// (undocumented)
TMT_TILING = 1
}

// @public (undocumented)
export interface TextureUnion {
// (undocumented)
Expand Down Expand Up @@ -4081,6 +4108,8 @@ export interface TweenHelper {
Rotate: (rotate: Rotate) => PBTween['mode'];
// (undocumented)
Scale: (scale: Scale) => PBTween['mode'];
// (undocumented)
TextureMove: (textureMove: TextureMove) => PBTween['mode'];
}

// @public (undocumented)
Expand Down
14 changes: 7 additions & 7 deletions packages/@dcl/sdk-commands/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@dcl/sdk-commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@dcl/inspector": "file:../inspector",
"@dcl/linker-dapp": "^0.14.2",
"@dcl/mini-comms": "1.0.1-20230216163137.commit-a4c75be",
"@dcl/protocol": "1.0.0-11780504028.commit-c886080",
"@dcl/protocol": "1.0.0-11954515774.commit-3fb0262",
"@dcl/quests-client": "^1.0.3",
"@dcl/quests-manager": "^0.1.4",
"@dcl/rpc": "^1.1.1",
Expand Down
17 changes: 16 additions & 1 deletion test/ecs/components/Tween.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { EasingFunction, Engine, components } from '../../../packages/@dcl/ecs/src'
import { EasingFunction, Engine, TextureMovementType, components } from '../../../packages/@dcl/ecs/src'
import { testComponentSerialization } from './assertion'

describe('Generated Tween ProtoBuf', () => {
const start = { x: 0, y: 0, z: 0 }
const end = { x: 8, y: 8, z: 8 }
const start2d = { x: 0, y: 0 }
const end2d = { x: 8, y: 8 }

it('should serialize/deserialize move Tween', () => {
const newEngine = Engine()
const Tween = components.Tween(newEngine)
Expand Down Expand Up @@ -31,5 +34,17 @@ describe('Generated Tween ProtoBuf', () => {
playing: false,
currentTime: 0
})

testComponentSerialization(Tween, {
duration: 1,
easingFunction: EasingFunction.EF_LINEAR,
mode: Tween.Mode.TextureMove({
start: { ...start2d },
end: { ...end2d },
movementType: TextureMovementType.TMT_OFFSET
}),
playing: false,
currentTime: 0
})
})
})
4 changes: 2 additions & 2 deletions test/ecs/components/UiBackground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('Generated UiBackground ProtoBuf', () => {
src: 'some-src',
wrapMode: TextureWrapMode.TWM_CLAMP,
filterMode: TextureFilterMode.TFM_BILINEAR,
tiling: undefined,
offset: undefined
offset: undefined,
tiling: undefined
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion test/ecs/events/tween.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
components
} from '../../../packages/@dcl/ecs/src'
import { createTweenSystem } from '../../../packages/@dcl/ecs/src/systems/tween'
import { Quaternion, Vector3 } from '../../../packages/@dcl/sdk/math'
import { Quaternion, Vector2, Vector3 } from '../../../packages/@dcl/sdk/math'

function mockTweenEngine(engine: IEngine, Tween: TweenComponentDefinitionExtended) {
return async function (entity: Entity, mode?: PBTween['mode']) {
Expand Down Expand Up @@ -103,6 +103,13 @@ describe('Tween System', () => {
expect(Tween.get(entity).mode).toMatchCloseTo(Tween.Mode.Scale({ end: Vector3.Left(), start: Vector3.Right() }))
})

it('should change to backwards the TextureMove Tween when its completed', async () => {
await mockTween(entity, Tween.Mode.TextureMove({ start: Vector2.Zero(), end: Vector2.One() }))
await mockTweenStatus(entity)
expect(completed).toBeCalledTimes(1)
expect(Tween.get(entity).mode).toMatchCloseTo(Tween.Mode.TextureMove({ end: Vector2.Zero(), start: Vector2.One() }))
})

it('should create a RESTART tweenSequence for the entity and restart the tween once its completed', async () => {
TweenState.deleteFrom(entity)
const tween = await mockTween(entity, Tween.Mode.Move({ start: Vector3.Forward(), end: Vector3.Down() }))
Expand Down
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/static-scene.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=453.4k bytes
SCENE_COMPILED_JS_SIZE_PROD=456k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/static-scene.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 54k
MALLOC_COUNT = 13673
MALLOC_COUNT = 13705
ALIVE_OBJS_DELTA ~= 2.70k
CALL onStart()
main.crdt: PUT_COMPONENT e=0x200 c=1 t=0 data={"position":{"x":5.880000114440918,"y":2.7916901111602783,"z":7.380000114440918},"rotation":{"x":0,"y":0,"z":0,"w":1},"scale":{"x":1,"y":1,"z":1},"parent":0}
Expand Down Expand Up @@ -56,4 +56,4 @@ CALL onUpdate(0.1)
OPCODES ~= 3k
MALLOC_COUNT = -5
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1194.77k bytes
MEMORY_USAGE_COUNT ~= 1199.30k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/testing-fw.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=453.9k bytes
SCENE_COMPILED_JS_SIZE_PROD=456.5k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/testing-fw.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14194
MALLOC_COUNT = 14226
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1203.39k bytes
MEMORY_USAGE_COUNT ~= 1207.91k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/two-way-crdt.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=454k bytes
SCENE_COMPILED_JS_SIZE_PROD=456.5k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/two-way-crdt.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14194
MALLOC_COUNT = 14226
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1203.39k bytes
MEMORY_USAGE_COUNT ~= 1207.92k bytes
2 changes: 1 addition & 1 deletion test/snapshots/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/snapshots/production-bundles/append-value-crdt.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=198.1k bytes
SCENE_COMPILED_JS_SIZE_PROD=199.4k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,8 +9,8 @@ EVAL test/snapshots/production-bundles/append-value-crdt.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 65k
MALLOC_COUNT = 12723
ALIVE_OBJS_DELTA ~= 2.84k
MALLOC_COUNT = 12753
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
Renderer: APPEND_VALUE e=0x200 c=1063 t=0 data={"button":0,"hit":{"position":{"x":1,"y":2,"z":3},"globalOrigin":{"x":1,"y":2,"z":3},"direction":{"x":1,"y":2,"z":3},"normalHit":{"x":1,"y":2,"z":3},"length":10,"meshName":"mesh","entityId":512},"state":1,"timestamp":1,"analog":5,"tickNumber":0}
OPCODES ~= 8k
Expand Down Expand Up @@ -55,4 +55,4 @@ CALL onUpdate(0.1)
OPCODES ~= 14k
MALLOC_COUNT = 31
ALIVE_OBJS_DELTA ~= 0.01k
MEMORY_USAGE_COUNT ~= 899.73k bytes
MEMORY_USAGE_COUNT ~= 903.06k bytes
8 changes: 4 additions & 4 deletions test/snapshots/production-bundles/billboard.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=231.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=232.4k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,8 +9,8 @@ EVAL test/snapshots/production-bundles/billboard.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 66k
MALLOC_COUNT = 14836
ALIVE_OBJS_DELTA ~= 3.24k
MALLOC_COUNT = 14865
ALIVE_OBJS_DELTA ~= 3.25k
CALL onStart()
OPCODES ~= 0k
MALLOC_COUNT = 4
Expand Down Expand Up @@ -77,4 +77,4 @@ CALL onUpdate(0.1)
OPCODES ~= 10k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1042.09k bytes
MEMORY_USAGE_COUNT ~= 1045.40k bytes
Loading

0 comments on commit 293fd08

Please sign in to comment.