1

I am currently developing an application using Create React Appand Node v16.13.1 that involves extracting metadata from 3D models or geometries. However, in some cases, the 3D models can be quite large, necessitating the use of a Web worker for performing resource-intensive calculations.

Fortunately, there is an existing method called executeUserFunction link that handles these calculations. During the development environment, this method functions perfectly as expected. However, when I run the application using the production build command (npm run build), the method fails to work.

Based on my analysis, it seems that the method is not being included along with the rest of the files in the production build.

enter image description here

enter image description here

Abed Aarabi
  • 51
  • 1
  • 5

1 Answers1

1

Please note that the function you're passing to model.getPropertyDb().executeUserFunction(...) must be called userFunction. The following code snippet works as expected:

Autodesk.Viewing.Initializer({ accessToken: ACCESS_TOKEN }, async function () {
    const viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('preview'));
    viewer.start();
    loadModel(viewer, MODEL_URN);
    viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, async function () {
        const result = await viewer.model.getPropertyDb().executeUserFunction(function userFunction(pdb) {
            let propertyNames = new Set();
            pdb.enumObjects(dbid => {
                let p = pdb.getObjectProperties(dbid);
                if (p.name) {
                    propertyNames.add(p.name);
                }
            });
            return Array.from(propertyNames.values());
        });
        console.log(result);
    });
});

But if you rename userFunction to anything else, you'll get an error.

I'm guessing in this case it could be an issue with your build uglifying the function name. Check the output JavaScript code generated by your build, and if that's the case, try and see if you could configure your uglifier/minifier to keep this function name intact.

Petr Broz
  • 8,891
  • 2
  • 15
  • 24
  • I completely agree. The issue lies between the web workers and React webpack. It appears that some function/method names are being altered in a way that is not compatible with the web worker's .executeUserFunction(function userFunction(pdb) syntax. I am currently working on reconfiguring the React application to resolve this problem using rewired! But, just to let you know `userFunction` it dose a great job :) – Abed Aarabi May 25 '23 at 20:09