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

查看:73
本文介绍了在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 应该可以正常工作.另外,叠加层是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天全站免登陆