3D viewer: switch STEP engine to occt-wasm (OCCT V8, module worker); fix mobile rendering (Uint16 chunking, index wrapping, tight near/far); state-coloured box + debug line; app widget parity; licenses/docs
This commit is contained in:
+14
-35
@@ -1,38 +1,17 @@
|
||||
self.onmessage = function (e) {
|
||||
import { OcctKernel } from "https://YOUR-INSTANCE.example.com/api/notes/__OCCT_JS_ID__/download";
|
||||
let kernel = null;
|
||||
let initP = null;
|
||||
self.onmessage = async function (e) {
|
||||
var d = e.data;
|
||||
if (d.type === 'loadLib') {
|
||||
try { importScripts(d.libUrl); } catch (err) {
|
||||
self.postMessage({ type: 'error', message: 'importScripts: ' + (err && err.message || err) }); return;
|
||||
}
|
||||
if (typeof self.occtimportjs !== 'function') {
|
||||
self.postMessage({ type: 'error', message: 'STEP parser not found.' }); return;
|
||||
}
|
||||
self.occtimportjs({ locateFile: function () { return 'occt.wasm'; }, wasmBinary: d.wasm }).then(function (occt) {
|
||||
self.occt = occt;
|
||||
self.postMessage({ type: 'ready' });
|
||||
}).catch(function (err) {
|
||||
self.postMessage({ type: 'error', message: 'STEP init: ' + (err && err.message || err) });
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (d.type === 'parse' && self.occt) {
|
||||
try {
|
||||
var result = self.occt.ReadStepFile(d.data, d.params);
|
||||
var meshes = [];
|
||||
(result.meshes || []).forEach(function (m) {
|
||||
if (!m.attributes || !m.attributes.position) return;
|
||||
var out = { position: m.attributes.position.array, color: m.color };
|
||||
if (m.attributes.index && m.attributes.index.array) out.index = m.attributes.index.array;
|
||||
meshes.push(out);
|
||||
});
|
||||
var transfer = [];
|
||||
meshes.forEach(function (m) {
|
||||
if (m.position && m.position.buffer) transfer.push(m.position.buffer);
|
||||
if (m.index && m.index.buffer) transfer.push(m.index.buffer);
|
||||
});
|
||||
self.postMessage({ type: 'done', success: !!result.success, meshes: meshes }, transfer);
|
||||
} catch (err) {
|
||||
self.postMessage({ type: 'error', message: 'parse: ' + (err && err.message || err) });
|
||||
}
|
||||
if (d.type !== "parse") return;
|
||||
try {
|
||||
if (!initP) initP = OcctKernel.init({ wasm: d.wasm });
|
||||
kernel = await initP;
|
||||
var shape = kernel.importStep(d.data);
|
||||
var mesh = kernel.tessellate(shape, d.params);
|
||||
kernel.release(shape);
|
||||
self.postMessage({ type: "done", positions: mesh.positions, normals: mesh.normals, indices: mesh.indices }, [mesh.positions.buffer, mesh.normals.buffer, mesh.indices.buffer]);
|
||||
} catch (err) {
|
||||
self.postMessage({ type: "error", message: "parse: " + (err && err.message || err) });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user