@2112-lab/central-plant 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/index.js +1619 -82
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +462 -0
- package/dist/cjs/src/index.js +4 -0
- package/dist/cjs/src/rendering/modelPreloader.js +241 -81
- package/dist/cjs/src/rendering/objProcessor.js +703 -0
- package/dist/cjs/src/testing/objProcessingDemo.js +254 -0
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +461 -2
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/rendering/modelPreloader.js +241 -81
- package/dist/esm/src/rendering/objProcessor.js +678 -0
- package/dist/esm/src/testing/objProcessingDemo.js +249 -0
- package/package.json +1 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, createForOfIteratorHelper as _createForOfIteratorHelper } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import modelPreloader from '../rendering/modelPreloader.js';
|
|
3
|
+
import ObjProcessor from '../rendering/objProcessor.js';
|
|
4
|
+
|
|
5
|
+
var ObjProcessingDemo = /*#__PURE__*/function () {
|
|
6
|
+
function ObjProcessingDemo() {
|
|
7
|
+
_classCallCheck(this, ObjProcessingDemo);
|
|
8
|
+
this.objProcessor = new ObjProcessor();
|
|
9
|
+
this.componentDictionary = null;
|
|
10
|
+
this.processedResults = new Map();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Load component dictionary
|
|
15
|
+
* @returns {Promise<Object>} Component dictionary
|
|
16
|
+
*/
|
|
17
|
+
return _createClass(ObjProcessingDemo, [{
|
|
18
|
+
key: "loadComponentDictionary",
|
|
19
|
+
value: (function () {
|
|
20
|
+
var _loadComponentDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
21
|
+
var response, _t;
|
|
22
|
+
return _regenerator().w(function (_context) {
|
|
23
|
+
while (1) switch (_context.n) {
|
|
24
|
+
case 0:
|
|
25
|
+
_context.p = 0;
|
|
26
|
+
_context.n = 1;
|
|
27
|
+
return fetch('/library/component-dictionary.json');
|
|
28
|
+
case 1:
|
|
29
|
+
response = _context.v;
|
|
30
|
+
_context.n = 2;
|
|
31
|
+
return response.json();
|
|
32
|
+
case 2:
|
|
33
|
+
this.componentDictionary = _context.v;
|
|
34
|
+
return _context.a(2, this.componentDictionary);
|
|
35
|
+
case 3:
|
|
36
|
+
_context.p = 3;
|
|
37
|
+
_t = _context.v;
|
|
38
|
+
throw _t;
|
|
39
|
+
case 4:
|
|
40
|
+
return _context.a(2);
|
|
41
|
+
}
|
|
42
|
+
}, _callee, this, [[0, 3]]);
|
|
43
|
+
}));
|
|
44
|
+
function loadComponentDictionary() {
|
|
45
|
+
return _loadComponentDictionary.apply(this, arguments);
|
|
46
|
+
}
|
|
47
|
+
return loadComponentDictionary;
|
|
48
|
+
}()
|
|
49
|
+
/**
|
|
50
|
+
* Get all OBJ models from component dictionary
|
|
51
|
+
* @returns {Array} Array of OBJ model configurations
|
|
52
|
+
*/
|
|
53
|
+
)
|
|
54
|
+
}, {
|
|
55
|
+
key: "getObjModels",
|
|
56
|
+
value: function getObjModels() {
|
|
57
|
+
var _this = this;
|
|
58
|
+
if (!this.componentDictionary) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
var objModels = [];
|
|
62
|
+
Object.keys(this.componentDictionary).forEach(function (componentId) {
|
|
63
|
+
var component = _this.componentDictionary[componentId];
|
|
64
|
+
if (component.modelType === 'obj') {
|
|
65
|
+
objModels.push({
|
|
66
|
+
componentId: componentId,
|
|
67
|
+
modelKey: component.modelKey,
|
|
68
|
+
name: component.name,
|
|
69
|
+
boundingBox: component.boundingBox
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return objModels;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Process all OBJ models and store in IndexedDB
|
|
78
|
+
* @returns {Promise<Array>} Array of processing results
|
|
79
|
+
*/
|
|
80
|
+
}, {
|
|
81
|
+
key: "processAllObjModels",
|
|
82
|
+
value: (function () {
|
|
83
|
+
var _processAllObjModels = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
84
|
+
var objModels, processingResults, _iterator, _step, objModel, cachedModelData, result, serializedData, _t3;
|
|
85
|
+
return _regenerator().w(function (_context2) {
|
|
86
|
+
while (1) switch (_context2.n) {
|
|
87
|
+
case 0:
|
|
88
|
+
if (this.componentDictionary) {
|
|
89
|
+
_context2.n = 1;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
_context2.n = 1;
|
|
93
|
+
return this.loadComponentDictionary();
|
|
94
|
+
case 1:
|
|
95
|
+
// Get all OBJ models
|
|
96
|
+
objModels = this.getObjModels();
|
|
97
|
+
if (!(objModels.length === 0)) {
|
|
98
|
+
_context2.n = 2;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
return _context2.a(2, []);
|
|
102
|
+
case 2:
|
|
103
|
+
_context2.n = 3;
|
|
104
|
+
return modelPreloader.preloadAllModels(this.componentDictionary);
|
|
105
|
+
case 3:
|
|
106
|
+
if (!this.objProcessor.idbSupported) {
|
|
107
|
+
_context2.n = 4;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
_context2.n = 4;
|
|
111
|
+
return this.objProcessor.initializeIDB();
|
|
112
|
+
case 4:
|
|
113
|
+
processingResults = []; // Process each OBJ model
|
|
114
|
+
_iterator = _createForOfIteratorHelper(objModels);
|
|
115
|
+
_context2.p = 5;
|
|
116
|
+
_iterator.s();
|
|
117
|
+
case 6:
|
|
118
|
+
if ((_step = _iterator.n()).done) {
|
|
119
|
+
_context2.n = 12;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
objModel = _step.value;
|
|
123
|
+
_context2.p = 7;
|
|
124
|
+
// Get the cached model from preloader
|
|
125
|
+
cachedModelData = modelPreloader.modelCache.get(objModel.modelKey);
|
|
126
|
+
if (!(!cachedModelData || !cachedModelData.isObjModel)) {
|
|
127
|
+
_context2.n = 8;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return _context2.a(3, 11);
|
|
131
|
+
case 8:
|
|
132
|
+
// Extract processing results
|
|
133
|
+
result = {
|
|
134
|
+
componentId: objModel.componentId,
|
|
135
|
+
modelKey: objModel.modelKey,
|
|
136
|
+
name: objModel.name,
|
|
137
|
+
boundingBox: objModel.boundingBox,
|
|
138
|
+
stats: cachedModelData.geometryStats,
|
|
139
|
+
originalObject: cachedModelData.originalObject,
|
|
140
|
+
processedGeometry: cachedModelData.processedGeometry,
|
|
141
|
+
materials: cachedModelData.materials
|
|
142
|
+
};
|
|
143
|
+
processingResults.push(result);
|
|
144
|
+
this.processedResults.set(objModel.modelKey, result);
|
|
145
|
+
|
|
146
|
+
// Store in IndexedDB if supported
|
|
147
|
+
if (!(this.objProcessor.idbSupported && result.processedGeometry)) {
|
|
148
|
+
_context2.n = 9;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
serializedData = this.objProcessor.serializeGeometry(result.processedGeometry);
|
|
152
|
+
_context2.n = 9;
|
|
153
|
+
return this.objProcessor.storeGeometryInIDB(objModel.modelKey, serializedData);
|
|
154
|
+
case 9:
|
|
155
|
+
_context2.n = 11;
|
|
156
|
+
break;
|
|
157
|
+
case 10:
|
|
158
|
+
_context2.p = 10;
|
|
159
|
+
_context2.v;
|
|
160
|
+
return _context2.a(3, 11);
|
|
161
|
+
case 11:
|
|
162
|
+
_context2.n = 6;
|
|
163
|
+
break;
|
|
164
|
+
case 12:
|
|
165
|
+
_context2.n = 14;
|
|
166
|
+
break;
|
|
167
|
+
case 13:
|
|
168
|
+
_context2.p = 13;
|
|
169
|
+
_t3 = _context2.v;
|
|
170
|
+
_iterator.e(_t3);
|
|
171
|
+
case 14:
|
|
172
|
+
_context2.p = 14;
|
|
173
|
+
_iterator.f();
|
|
174
|
+
return _context2.f(14);
|
|
175
|
+
case 15:
|
|
176
|
+
return _context2.a(2, processingResults);
|
|
177
|
+
}
|
|
178
|
+
}, _callee2, this, [[7, 10], [5, 13, 14, 15]]);
|
|
179
|
+
}));
|
|
180
|
+
function processAllObjModels() {
|
|
181
|
+
return _processAllObjModels.apply(this, arguments);
|
|
182
|
+
}
|
|
183
|
+
return processAllObjModels;
|
|
184
|
+
}()
|
|
185
|
+
/**
|
|
186
|
+
* Run the simplified demo - process and store in IndexedDB
|
|
187
|
+
* @returns {Promise<Object>} Demo results
|
|
188
|
+
*/
|
|
189
|
+
)
|
|
190
|
+
}, {
|
|
191
|
+
key: "run",
|
|
192
|
+
value: (function () {
|
|
193
|
+
var _run = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
194
|
+
var processingResults, _t4;
|
|
195
|
+
return _regenerator().w(function (_context3) {
|
|
196
|
+
while (1) switch (_context3.n) {
|
|
197
|
+
case 0:
|
|
198
|
+
_context3.p = 0;
|
|
199
|
+
_context3.n = 1;
|
|
200
|
+
return this.processAllObjModels();
|
|
201
|
+
case 1:
|
|
202
|
+
processingResults = _context3.v;
|
|
203
|
+
return _context3.a(2, {
|
|
204
|
+
processingResults: processingResults,
|
|
205
|
+
totalModelsProcessed: processingResults.length,
|
|
206
|
+
success: true
|
|
207
|
+
});
|
|
208
|
+
case 2:
|
|
209
|
+
_context3.p = 2;
|
|
210
|
+
_t4 = _context3.v;
|
|
211
|
+
return _context3.a(2, {
|
|
212
|
+
processingResults: [],
|
|
213
|
+
totalModelsProcessed: 0,
|
|
214
|
+
success: false,
|
|
215
|
+
error: _t4.message
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}, _callee3, this, [[0, 2]]);
|
|
219
|
+
}));
|
|
220
|
+
function run() {
|
|
221
|
+
return _run.apply(this, arguments);
|
|
222
|
+
}
|
|
223
|
+
return run;
|
|
224
|
+
}()
|
|
225
|
+
/**
|
|
226
|
+
* Get processing results for external use
|
|
227
|
+
* @returns {Map} Map of processing results
|
|
228
|
+
*/
|
|
229
|
+
)
|
|
230
|
+
}, {
|
|
231
|
+
key: "getResults",
|
|
232
|
+
value: function getResults() {
|
|
233
|
+
return this.processedResults;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get geometry by model key
|
|
238
|
+
* @param {string} modelKey - The model key
|
|
239
|
+
* @returns {Object|null} Processing result or null
|
|
240
|
+
*/
|
|
241
|
+
}, {
|
|
242
|
+
key: "getGeometry",
|
|
243
|
+
value: function getGeometry(modelKey) {
|
|
244
|
+
return this.processedResults.get(modelKey) || null;
|
|
245
|
+
}
|
|
246
|
+
}]);
|
|
247
|
+
}(); // Export for use
|
|
248
|
+
|
|
249
|
+
export { ObjProcessingDemo, ObjProcessingDemo as default };
|