Changing materials in Forge
Asked Answered
E

1

6

We are currently making the client retrieve the object states when the page loads (which will cause the 'pending' objects in the model to turn into different colors). Then we poll for changes to update the coloring (Firstly: pending object gets colored when the viewer loads, and then we keep polling to check and change state again, to make Forge render those in a different color and store their old color/material. When the polling received a change that an object should no longer be colored, it tells Forge to use the old color/material again.

The problem: We've found out what the problem is, but we couldn't find out how to fix it. The problem is that changing materials in Forge doesn't work after startup anymore, it only works in the first ~3 seconds or so (the materials were used to show the colors).

However, setting overlays works even after the first ~3 seconds, (showing overlays instead of materials to show the colors). This is not what we want to achieve. This looks unoptimized, because overlays will be shown through everything.

The materials, however, seem to be 'locked', as in, they cannot be changed anymore after the first ~3 seconds. It seems like they aren't refreshed or something

In the examples, we found they used viewer.impl.invalidate(true) to refresh the Forge viewer, but that doesn't do anything after ~3 seconds.

We've also tried every combination of viewer.impl.invalidate(true, true, true) as well as setting material.needsUpdate to true, as well as trying to re-render the entire scene.

We also found this GitHub issue, but we couldn't find a good way to do that in Forge, we tried viewer.requestSilentRender() but that didn't do anything either.

As for the content, here is all the code you will need to understand what is happening: DROPBOX LINK

And here is a small part of the index.html file that sets the color:

try
{
   viewer.restoreAllColorOverlays(); //for materials instead of overlays: viewer.restoreAllColorMaterials();
   $.each(colors, function(color, selectionIds)
   {
      viewer.setColorOverlay(selectionIds, color); //for materials instead of overlays: viewer.setColorMaterial(selectionIds, color);
   });
}
catch(error)
{
   console.error(error);
}
Excel answered 29/8, 2017 at 20:35 Comment(1)
I want to do the same thing. I want to highlight "pending" things. Where and how are you polling for the state of the objects?Frymire
P
1

I have no idea how you implement your app, so I can only tell what I found in your codes. If you want to resolve the issue you addressed, you can consider providing a reproducible case demonstrating that, I will gladly pass it to our dev team. If your reproducible cannot be posted publicly, you can send it to this address: [email protected] after removing any sensitive data or information.


Something I found in your code:

I found here are some wrong types and missing actions in your ColorMaterial extension. The color property of an material should the a type of the THREE.Color. Here is my modification:

Autodesk.Viewing.Viewer3D.prototype.setColorMaterial = function(objectIds, color)
    {
        if( !(color instanceof THREE.Color) ) throw 'Invalid argument: Color';
 
        var material = new THREE.MeshPhongMaterial
        ({
             color:      color,
             opacity:    0.8,
             transparent: true
         });

        viewer.impl.matman().addMaterial( 'ColorMaterial-' + new Date().getTime(), material, true );

        // ...........
    };

The new result is shown below:

updated output

In the ColorOverlay extension, The type of material color property is also wrong, it should be a type of THREE.Color, too. Changing it into THREE.Color should work fine. In addition, overlay is covers on 3D objects, so you should call viewer.hide() with your setColorOverlay() together. Otherwise, it won't look like a transparent object.

Without hidding 3D object of the wall:

Hide 3D object of the wall:

Philibeg answered 31/8, 2017 at 3:32 Comment(1)
.Hi, thanks a lot for your reply. We've taken the steps as described in part 2 of your reply. Sadly, it didn't cause the materials to work, but it cause the overlays to look a lot better now. We'd be very interested in sharing our project with [email protected]Excel

© 2022 - 2024 — McMap. All rights reserved.