File size: 1,128 Bytes
71174bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Web worker entry point for mesh simplification operations.
 * Handles VRML processing and mesh optimization through vertex clustering
 * and distance-based merging techniques.
 */

import { processVRML } from './ProcessVRML';

interface WorkerRequest {
    vrmlContent: string;
    mergeCutoff: number;
    reductionFraction: number;
    id: string;
}

interface WorkerResponse {
    success: boolean;
    optimizedVRML?: string;
    error?: string;
    id: string;
}

self.onmessage = async (e: MessageEvent<WorkerRequest>) => {
    try {
        const { vrmlContent, mergeCutoff, reductionFraction, id } = e.data;
        const result = await processVRML(vrmlContent, mergeCutoff, reductionFraction);
        const response: WorkerResponse = {
            success: true,
            optimizedVRML: result,
            id: id
        };
        self.postMessage(response);
    } catch (error) {
        const response: WorkerResponse = {
            success: false,
            error: error instanceof Error ? error.message : 'Unknown error',
            id: "???"
        };
        self.postMessage(response);
    }
};