Skip to content

Commit

Permalink
1.1.4 Shadow for light and attributes for text
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea DI ZANNI committed Nov 10, 2021
1 parent 3bb9f60 commit bff7079
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 98 deletions.
188 changes: 102 additions & 86 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.1.3",
"version": "1.1.4",
"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.1.3';
export const CARD_VERSION = '1.1.4';
18 changes: 18 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,16 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
.configAttribute=${'lumens'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
editable
label="Shadow"
.value=${config.light.shadow
? config.light.shadow
: ""}
.configObject=${config.light}
.configAttribute=${"shadow"}
@value-changed=${this._valueChanged}
></paper-input>
<paper-dropdown-menu
label="Light Vertical Alignment"
@selected-item-changed=${this._valueChanged}
Expand Down Expand Up @@ -1436,6 +1446,14 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
.configAttribute=${'font'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
editable
label="Attribute"
.value=${config.text.attribute ? config.text.attribute : ''}
.configObject=${config.text}
.configAttribute=${'attribute'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
editable
label="Span percentage"
Expand Down
63 changes: 53 additions & 10 deletions src/floor3d-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class Floor3dCard extends LitElement {
private _lights?: string[];
private _canvas?: HTMLCanvasElement[];
private _unit_of_measurement?: string[];
private _text?: string[];
private _objposition: number[][];
private _slidingdoorposition: THREE.Vector3[][];
private _objects_to_rotate: THREE.Group[];
Expand Down Expand Up @@ -102,6 +103,7 @@ export class Floor3dCard extends LitElement {
private _point_light: THREE.PointLight;
_helper: THREE.DirectionalLightHelper;
_modelready: boolean;
private _maxtextureimage: number;

constructor() {
super();
Expand Down Expand Up @@ -211,7 +213,7 @@ export class Floor3dCard extends LitElement {
this._renderer.setAnimationLoop(null);
this._resizeObserver.disconnect();
window.clearInterval(this._zIndexInterval);

this._renderer.domElement.remove();
this._renderer = null;

Expand Down Expand Up @@ -471,11 +473,25 @@ export class Floor3dCard extends LitElement {
this._brightness = [];
this._lights = [];
this._canvas = [];
this._text = [];

this._config.entities.forEach((entity) => {
if (entity.entity !== '') {
this._states.push(this._statewithtemplate(entity));
this._canvas.push(null);
if (entity.type3d == 'text') {
if (entity.text.attribute) {
if (hass.states[entity.entity].attributes[entity.text.attribute]) {
this._text.push(hass.states[entity.entity].attributes[entity.text.attribute]);
} else {
this._text.push('');
}
} else {
this._text.push(this._statewithtemplate(entity))
}
} else {
this._text.push('');
}
if (entity.type3d == 'light') {
this._lights.push(entity.object_id + '_light');
} else {
Expand Down Expand Up @@ -511,7 +527,6 @@ export class Floor3dCard extends LitElement {
this._config.entities.forEach((entity, i) => {
if (entity.entity !== '') {
let state = this._statewithtemplate(entity);

if (entity.type3d == 'light') {
let toupdate = false;
if (this._states[i] !== state) {
Expand Down Expand Up @@ -547,6 +562,28 @@ export class Floor3dCard extends LitElement {
this._updatelight(entity, i);
torerender = true;
}
} else if (entity.type3d == 'text') {
let toupdate = false;
if (entity.text.attribute) {
if (hass.states[entity.entity].attributes[entity.text.attribute]) {
if (this._text[i] != hass.states[entity.entity].attributes[entity.text.attribute]) {
this._text[i] = hass.states[entity.entity].attributes[entity.text.attribute];
toupdate = true;
}
} else {
this._text[i] = '';
toupdate = true;
}
} else {
if (this._text[i] != this._statewithtemplate(entity)) {
this._text[i] = this._statewithtemplate(entity);
toupdate = true;
}
}
if (this._canvas[i] && toupdate) {
this._updatetext(entity, this._text[i], this._canvas[i], this._unit_of_measurement[i]);
torerender = true;
}
} else if (entity.type3d == 'rotate') {
this._states[i] = state;
this._rotatecalc(entity, i);
Expand All @@ -564,11 +601,6 @@ export class Floor3dCard extends LitElement {
} else if (entity.type3d == 'door') {
this._updatedoor(entity, i);
torerender = true;
} else if (entity.type3d == 'text') {
if (this._canvas[i]) {
this._updatetext(entity, this._states[i], this._canvas[i], this._unit_of_measurement[i]);
torerender = true;
}
}
}
}
Expand Down Expand Up @@ -598,6 +630,13 @@ export class Floor3dCard extends LitElement {
this._scene.add(this._direction_light);
this._scene.add(this._ambient_light);
this._renderer = new THREE.WebGLRenderer({ antialias: true });
this._maxtextureimage = this._renderer.context.getParameter(
this._renderer.context.MAX_TEXTURE_IMAGE_UNITS
);
console.log("Max Texture Image Units: " + this._maxtextureimage);
console.log(
"Max Texture Image Units: number of lights casting shadow should be less than the above number"
);
this._renderer.domElement.style.width = '100%';
this._renderer.domElement.style.height = '100%';
this._renderer.domElement.style.display = 'block';
Expand Down Expand Up @@ -807,7 +846,7 @@ export class Floor3dCard extends LitElement {
this._objposition = [];
this._slidingdoorposition = [];
this._to_animate = false;

this._config.entities.forEach((entity, i) => {
this._objposition.push([0, 0, 0]);
this._pivot.push(null);
Expand Down Expand Up @@ -1017,7 +1056,11 @@ export class Floor3dCard extends LitElement {
light.position.set(x, y, z);
this._setNoShadowLight(_foundobject);
_foundobject.traverseAncestors(this._setNoShadowLight.bind(this));
light.castShadow = true;
if (entity.light.shadow == "no") {
light.castShadow = false;
} else {
light.castShadow = true;
}
light.name = element.object_id + '_light';
//this._updatelight(entity, this._states[i], this._lights[i], this._color[i], this._brightness[i]);
}
Expand Down Expand Up @@ -1050,7 +1093,7 @@ export class Floor3dCard extends LitElement {
} else if (entity.type3d == 'door') {
this._updatedoor(entity, i);
} else if (entity.type3d == 'text') {
this._canvas[i] = this._createTextCanvas(entity, this._states[i], this._unit_of_measurement[i]);
this._canvas[i] = this._createTextCanvas(entity, this._text[i], this._unit_of_measurement[i]);
} else if (entity.type3d == 'rotate') {
this._rotatecalc(entity, i);
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Floor3dCardConfig {
path: string;
name: string;
font: string;
attribute: string;
objfile: string;
mtlfile: string;
objectlist: string;
Expand Down

0 comments on commit bff7079

Please sign in to comment.