Skip to content

Commit

Permalink
Merge pull request #46 from JVital2013/optimizations
Browse files Browse the repository at this point in the history
Two Fixes
  • Loading branch information
adizanni authored Aug 28, 2021
2 parents 942b219 + dc6ff1f commit 484af54
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dist/floor3d-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "floor3d-card",
"version": "1.0.4alpha",
"version": "1.0.5alpha",
"description": "Lovelace floor3d-card",
"keywords": [
"home-assistant",
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CARD_VERSION = '1.0.4alpha';
export const CARD_VERSION = '1.0.5alpha';
41 changes: 31 additions & 10 deletions src/floor3d-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ export class Floor3dCard extends LitElement {
this._card_id = 'ha-card-1';
console.log('New Card');
}

public connectedCallback(): void {
super.connectedCallback();

if(this._to_animate) {
this._clock = new THREE.Clock();
this._renderer.setAnimationLoop(() => this._rotateobjects());
}
}

public disconnectedCallback(): void {
super.disconnectedCallback();

if(this._to_animate) {
this._clock = null;
this._renderer.setAnimationLoop(null);
}
}

public static async getConfigElement(): Promise<LovelaceCardEditor> {
return document.createElement('floor3d-card-editor');
Expand Down Expand Up @@ -710,6 +728,7 @@ export class Floor3dCard extends LitElement {
}
}
light.position.set(x, y, z);
this._setNoShadowLight(_foundobject);
_foundobject.traverseAncestors(this._setNoShadowLight.bind(this));
light.castShadow = true;
light.name = element.object_id + '_light';
Expand Down Expand Up @@ -983,18 +1002,20 @@ export class Floor3dCard extends LitElement {
else if(!this._to_animate) {
this._to_animate = true;
this._clock = new THREE.Clock();
this._renderer.setAnimationLoop(() => {
let moveBy = this._clock.getDelta() * Math.PI * 2;
this._renderer.setAnimationLoop(() => this._rotateobjects());
}
}

private _rotateobjects() {
let moveBy = this._clock.getDelta() * Math.PI * 2;

this._rotation_state.forEach((state, index) => {
if (state != 0) {
this._objects_to_rotate[index].rotation[this._axis_to_rotate[index]] += this._round_per_seconds[index] * state * moveBy;
}
});
this._rotation_state.forEach((state, index) => {
if (state != 0) {
this._objects_to_rotate[index].rotation[this._axis_to_rotate[index]] += this._round_per_seconds[index] * state * moveBy;
}
});

this._renderer.render(this._scene, this._camera);
});
}
this._renderer.render(this._scene, this._camera);
}

private _rotatedoor(_obj: THREE.Mesh, side: string, direction: string, pos: number[], _doorstate: string) {
Expand Down

0 comments on commit 484af54

Please sign in to comment.