Skip to content

Commit

Permalink
Fix animation issue when using objec3D.position, scale, rotation as p…
Browse files Browse the repository at this point in the history
…roperty and from is not defined
  • Loading branch information
dmarcos committed Nov 21, 2024
1 parent f97468c commit 204a8db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ module.exports.Component = registerComponent('animation', {
// Parse coordinates.
from = data.from !== ''
? utils.coordinates.parse(data.from) // If data.from defined, use that.
: getComponentProperty(el, data.property); // If data.from not defined, get on the fly.
: getComponentProperty(el, property); // If data.from not defined, get on the fly.
to = utils.coordinates.parse(data.to);

if (property === PROP_ROTATION) {
Expand Down
23 changes: 23 additions & 0 deletions tests/components/animation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ suite('animation', function () {
assert.equal(el.object3D.position.z, 0);
});

test('can animate object3D.position directly with no from', function () {
el.setAttribute('position', '3 3 3');
el.setAttribute('animation', {
property: 'object3D.position',
dur: 1000,
to: '5 5 5'
});
let setAttributeSpy = this.sinon.spy(el, 'setAttribute');
component.tick(0, 1);
// setAttribute not called to update the position. object3D updated directly.
assert.notOk(setAttributeSpy.called);
assert.equal(el.object3D.position.x, 3);
assert.equal(el.object3D.position.y, 3);
assert.equal(el.object3D.position.z, 3);
component.tick(0, 500);
assert.ok(el.object3D.position.x > 3);
assert.ok(el.object3D.position.x < 5);
component.tick(0, 500);
assert.equal(el.object3D.position.x, 5);
assert.equal(el.object3D.position.y, 5);
assert.equal(el.object3D.position.z, 5);
});

test('can animate object3D value directly', function () {
el.setAttribute('animation', {
property: 'object3D.position.x',
Expand Down

0 comments on commit 204a8db

Please sign in to comment.