Skip to content

Commit

Permalink
Bug on groups and new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
adizanni committed Aug 9, 2021
1 parent eb104b3 commit 795ff0e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
19 changes: 18 additions & 1 deletion dist/floor3d-card.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,23 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
.configAttribute=${'lumens'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-dropdown-menu
label="Light Vertical Alignment"
@selected-item-changed=${this._valueChanged}
.configObject=${config.light}
.configAttribute=${'vertical_alignment'}
.ignoreNull=${true}
>
<paper-listbox
slot="dropdown-content"
attr-for-selected="item-name"
selected="${config.light.vertical_alignment ? config.light.vertical_alignment : null}"
>
<paper-item item-name="bottom">bottom</paper-item>
<paper-item item-name="middle">middle</paper-item>
<paper-item item-name="hide">top</paper-item>
</paper-listbox>
</paper-dropdown-menu>
`
: ''}
</div>
Expand Down
57 changes: 34 additions & 23 deletions src/floor3d-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Projector } from 'three/examples/jsm/renderers/Projector';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader';
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader';
import { Material, Mesh, Vector3 } from 'three';
import { BooleanKeyframeTrack, Material, Mesh, Vector3 } from 'three';
import { TrackballControls } from 'three/examples/jsm/controls/TrackballControls';
import { Sky } from 'three/examples/jsm/objects/Sky';
import { NotEqualStencilFunc, Object3D } from 'three';
Expand Down Expand Up @@ -240,25 +240,22 @@ export class Floor3dCard extends LitElement {
if (getLovelace().editMode) {
window.prompt('Object:', intersects[0].object.name);
} else {
this._config.entities.forEach((entity) => {
this._config.entities.forEach((entity, i) => {
if (entity.type3d == 'light' || entity.type3d == 'gesture') {
this._object_ids.forEach((element) => {
if (entity.entity == element.entity) {
element.objects.forEach((obj) => {
if (obj.object_id == intersects[0].object.name) {
if (entity.type3d == 'light') {
this._hass.callService(entity.entity.split('.')[0], 'toggle', {
entity_id: entity.entity,
});
} else if (entity.type3d == 'gesture') {
this._hass.callService(entity.gesture.domain, entity.gesture.service, {
entity_id: entity.entity,
});
}
}
});
for (let j = 0; j < this._object_ids[i].objects.length; j++) {
if (this._object_ids[i].objects[j].object_id == intersects[0].object.name) {
if (entity.type3d == 'light') {
this._hass.callService(entity.entity.split('.')[0], 'toggle', {
entity_id: entity.entity,
});
} else if (entity.type3d == 'gesture') {
this._hass.callService(entity.gesture.domain, entity.gesture.service, {
entity_id: entity.entity,
});
}
break;
}
});
}
}
});
}
Expand Down Expand Up @@ -666,11 +663,25 @@ export class Floor3dCard extends LitElement {
const box: THREE.Box3 = new THREE.Box3();
box.setFromObject(_foundobject);
const light: THREE.PointLight = new THREE.PointLight(new THREE.Color('#ffffff'), 0, 700, 2);
light.position.set(
(box.max.x - box.min.x) / 2 + box.min.x + this._modelX,
(box.max.y - box.min.y) / 2 + box.min.y + this._modelY,
(box.max.z - box.min.z) / 2 + box.min.z + this._modelZ,
);
let x: number, y: number, z: number;

x = (box.max.x - box.min.x) / 2 + box.min.x + this._modelX;
z = (box.max.z - box.min.z) / 2 + box.min.z + this._modelZ;
y = (box.max.y - box.min.y) / 2 + box.min.y + this._modelY;
if (entity.light.vertical_alignment) {
switch (entity.light.vertical_alignment) {
case 'top':
y = box.max.y + this._modelY;
break;
case 'middle':
y = (box.max.y - box.min.y) / 2 + box.min.y + this._modelY;
break;
case 'bottom':
y = box.min.y + this._modelY;
break;
}
}
light.position.set(x, y, z);
_foundobject.traverseAncestors(this._setNoShadowLight.bind(this));
light.castShadow = true;
light.name = element.object_id + '_light';
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export interface Floor3dCardConfig {
lumens: number;
colorcondition: any;
light: any;
door: any;
text: any;
gesture: any;
span: string;
vertical_alignment: string;
textbgcolor: string;
textfgcolor: string;
camera_position: any;
Expand Down

0 comments on commit 795ff0e

Please sign in to comment.