在 Forge 中更改材料 [英] Changing materials in Forge

查看:47
本文介绍了在 Forge 中更改材料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在让客户端在页面加载时检索对象状态(这将导致模型中的待处理"对象变成不同的颜色).然后我们轮询更改以更新颜色(首先:待查看的对象在查看器加载时被着色,然后我们继续轮询以再次检查和更改状态,使 Forge 以不同的颜色渲染它们并存储它们的旧颜色/材料.当轮询收到一个对象不应再着色的更改时,它会告诉 Forge 再次使用旧的颜色/材料.

问题:我们已经找到了问题所在,但我们无法找到解决方法.问题是在 Forge 中更改材料在启动后不再起作用,它只在前 ~3 秒左右起作用(材料用于显示颜色).

但是,即使在前约 3 秒后设置叠加层仍然有效(显示叠加层而不是材料以显示颜色).这不是我们想要实现的.这看起来没有优化,因为覆盖将显示在所有内容中.

然而,这些材料似乎被锁定"了,例如,在最初的 ~3 秒后无法再更改它们.似乎他们没有刷新或什么

在示例中,我们发现他们使用了 viewer.impl.invalidate(true) 来刷新 Forge 查看器,但这在大约 3 秒后没有任何作用.

我们还尝试了 viewer.impl.invalidate(true, true, true) 以及将 material.needsUpdate 设置为 true 的所有组合,以及尝试重新渲染整个场景.

我们还发现了这个:

ColorOverlay扩展中,材质颜色属性的类型也是错误的,应该也是THREE.Color的类型.将其更改为 THREE.Color 应该可以正常工作.此外,overlay 是覆盖在 3D 对象上的,因此您应该将 viewer.hide() 与您的 setColorOverlay() 一起调用.否则,它看起来不会像一个透明的物体.

不隐藏墙壁的 3D 对象:

隐藏墙壁的 3D 对象:

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

解决方案

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:

这篇关于在 Forge 中更改材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆