Changing materials in Forge

一曲冷凌霜 提交于 2020-11-28 08:31:27

问题


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: https://github.com/mrdoob/three.js/issues/790, but we couldn't find a good way to do that in Forge, we tried viewer.requestSilentRender() but that didn't do anything either.

Anyway, we've tried everything we could come up with and could find online to make the materials work, but nothing made a difference. We are looking to find someone that's more experienced with how Forge works that can see what the material code is doing wrong.

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);
}

回答1:


I have no idea how you implement your app, so I 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. Those following items should be in the reproducible case:

  1. A short exact description of what you are trying to achieve. The behavior you observe versus what you expect, and why this is a problem.
  2. A complete yet minimal sample source model to run a test in.
  3. A complete yet minimal Forge app that can be run and debugged with a simple procedure to analyze its behavior lives in the sample model.
  4. A complete yet minimal pure three.js app that can be run and demonstrated the shader effect you want. Note. Forge Viewer is using r71 three.js.
  5. Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.

If your reproducible case could not be posted here publicly, please send it to the forge.help@autodesk.com and remove sensitive data or information before you send.

=== Something I found in your codes:

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 );

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

Its' result is here:

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:



来源:https://stackoverflow.com/questions/45947925/changing-materials-in-forge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!