Skip to content

Commit 204a8db

Browse files
committed
Fix animation issue when using objec3D.position, scale, rotation as property and from is not defined
1 parent f97468c commit 204a8db

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/components/animation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ module.exports.Component = registerComponent('animation', {
356356
// Parse coordinates.
357357
from = data.from !== ''
358358
? utils.coordinates.parse(data.from) // If data.from defined, use that.
359-
: getComponentProperty(el, data.property); // If data.from not defined, get on the fly.
359+
: getComponentProperty(el, property); // If data.from not defined, get on the fly.
360360
to = utils.coordinates.parse(data.to);
361361

362362
if (property === PROP_ROTATION) {

tests/components/animation.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ suite('animation', function () {
127127
assert.equal(el.object3D.position.z, 0);
128128
});
129129

130+
test('can animate object3D.position directly with no from', function () {
131+
el.setAttribute('position', '3 3 3');
132+
el.setAttribute('animation', {
133+
property: 'object3D.position',
134+
dur: 1000,
135+
to: '5 5 5'
136+
});
137+
let setAttributeSpy = this.sinon.spy(el, 'setAttribute');
138+
component.tick(0, 1);
139+
// setAttribute not called to update the position. object3D updated directly.
140+
assert.notOk(setAttributeSpy.called);
141+
assert.equal(el.object3D.position.x, 3);
142+
assert.equal(el.object3D.position.y, 3);
143+
assert.equal(el.object3D.position.z, 3);
144+
component.tick(0, 500);
145+
assert.ok(el.object3D.position.x > 3);
146+
assert.ok(el.object3D.position.x < 5);
147+
component.tick(0, 500);
148+
assert.equal(el.object3D.position.x, 5);
149+
assert.equal(el.object3D.position.y, 5);
150+
assert.equal(el.object3D.position.z, 5);
151+
});
152+
130153
test('can animate object3D value directly', function () {
131154
el.setAttribute('animation', {
132155
property: 'object3D.position.x',

0 commit comments

Comments
 (0)