-
Notifications
You must be signed in to change notification settings - Fork 0
/
interiors.js
executable file
·193 lines (170 loc) · 6.5 KB
/
interiors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import * as THREE from 'three'
// import mcm from 'vendor/shaders/MatcapMaterial.js'
// let MatcapMaterial = new mcm(THREE)
// import mm from './material-manager.js'
// let MaterialManager = new mm(THREE, MatcapMaterial);
// import om from './obj-manager.js'
// let ObjManager = new om();
import * as HELPER from './helpers.js'
import { Dimension } from './dimensions.js'
import { Drawer } from './spaces/drawers.js'
import { Tray } from './spaces/trays.js'
import { Shelf } from './spaces/shelves.js'
import { Door } from './spaces/doors.js'
// import * as HELPER from './helpers.js'
class Interiors {
constructor(){
this.interior = new THREE.Group();
this.interior.name = "interior";
this.interiorDims = Dimension.getInterior();
this.housingDims = Dimension.getHousing();
this.positions = [];
// this.frontColor;
// this.frontMaterial;
// this.lilo = true;
// this.drawerLatchSide = "right";
//Store loaded mats & meshes for reuse.
this.loaded = {};
}
init(props, om) {
// console.log('INTERIOR INIT');
this.props = props;
this.objManager = om;
let intColor = this.props.colorInt;
this.objManager.materialManager.materials.metalPaintedInt.color.setHex( parseInt( intColor, 16) );
return this.interior;
} // END init()
update(props){
// console.log('INTERIOR UPDATE');
this.props = props;
this.positions = this.props.interiorItems;
this.positionHeights = this.props.interiorHeights.map(function(obj) {
return {
points : obj.component.attributes.metricHeightMm.value, usableH : obj.component.attributes.usableMm.value
}
});
// this.frontColor = parseInt(this.props.selectedDrawerColor.value, 16);
// this.frontMaterial.color.setHex(this.frontColor);
let ceilingH = this.housingDims.ceilingH,
yPos = this.props.housingPoints + this.housingDims.heightDiff - ceilingH,
spaceSettings = {
intWidth : this.props.housingWidth - this.interiorDims.widthOffset,
intDepth : this.props.housingDepth - this.interiorDims.depthOffset
},
doorSettings = {}
// Remove all the old spaces.
while( this.interior.children.length > 0 ) {
let slot = this.interior.children[this.interior.children.length - 1];
HELPER.removeAndDisposeGeom( this.interior, slot );
}
// Get any meshes needed.
this.positions.forEach(function(space) {
switch (space.component.attributes.code.value) {
case 'drawer':
case 'tray':
if ( this.loaded.drawerTrayPull === undefined ) {
this.loaded.drawerTrayPull = {
handle : this.objManager.meshes.drawerHandle.clone(),
leftCap : this.objManager.meshes.drawerHandleCap.clone(),
rightCap : this.objManager.meshes.drawerHandleCap.clone(),
capMat : this.objManager.materialManager.materials.handleCap
}
}
break;
case 'LST_FDL':
case 'LST_FDR':
case 'retractable':
if ( this.loaded.doors === undefined ) {
this.loaded.doors = {
lockFace : this.objManager.materialManager.materials.lockFace
}
}
break;
case 'shelf':
default:
break;
}
}, this);
// Add the new spaces back in.
this.positions.forEach(function(space, i) {
//console.log(space);
spaceSettings.height = this.positionHeights[i].points - this.interiorDims.spaceGap;
spaceSettings.usableHeight = this.positionHeights[i].usableH; //drawer basket heights
spaceSettings.points = this.positionHeights[i].points;
//console.log('spaceSettings: ');
//console.log(spaceSettings);
let spaceMesh;
switch (space.component.attributes.code.value) {
case 'space':
// Do nothing, its a space.
spaceMesh = new THREE.Mesh();
break;
case 'drawer':
spaceSettings.latch = this.props.latch;
spaceMesh = new Drawer( spaceSettings, this.objManager );
spaceMesh.position.setY( yPos - spaceSettings.points/2 );
break;
case 'tray':
// let trayMats = {
// front : this.frontMaterial,
// bottom : this.objManager.materialManager.materials.tops.stainless };
spaceMesh = new Tray( spaceSettings, this.objManager );
let spaceMeshBB = new THREE.Box3().setFromObject( spaceMesh ),
spaceMeshH = spaceMeshBB.max.y + Math.abs( spaceMeshBB.min.y );
spaceMesh.position.setY( yPos - (spaceSettings.height - Math.abs(spaceMeshBB.min.y)) );
break;
case 'shelf':
spaceMesh = new Shelf(spaceSettings);
spaceMesh.position.setY( yPos - (spaceSettings.height - 15/2) );
break;
case 'LST_FDR':
case 'LST_FDL':
doorSettings = {
door : {
type : "flush",
hinge : space.component.attributes.code.value === 'LST_FDR' ? 'right' : 'left',
// hinge : space.type.doorHingePosition.side.toLowerCase(),
lock : "standard"
},
space : spaceSettings
}
let flushDoor = new Door( doorSettings, this.objManager );
spaceMesh = flushDoor.flush();
spaceMesh.position.setY( yPos - spaceSettings.points/2 );
break;
case 'retractable':
doorSettings = {
door : {
type : "retractable",
lock : "standard"
},
space : spaceSettings
}
let retractableDoor = new Door( doorSettings, this.objManager );
spaceMesh = retractableDoor.retractable();
spaceMesh.position.setY( yPos - spaceSettings.points/2 - (Dimension.getDoors().heightSpacer - 2) );
break;
default:
spaceMesh = new THREE.Mesh (
new THREE.BoxGeometry(spaceSettings.intWidth, spaceSettings.height, spaceSettings.intDepth),
new THREE.MeshPhongMaterial( { color: 0xff0000, wireframe: false } )
);
break;
}
yPos = yPos - spaceSettings.points;
spaceMesh.name = 'position_' + (i+1); // Use this name for the outline.
this.interior.add(spaceMesh);
}, this);
// console.log(this.interior);
this.interior.name = "interior";
return this.interior;
}
changeColor(hex) {
this.frontColor = hex;
// this.frontMaterial.color.setHex(this.frontColor);
}
getCeilingH(){
return 42; // TODO: add to data
}
}
export let interior = new Interiors();