这篇文章来自 Autodesk ADN 的梁晓冬,如下以我简称。html
对于大多数的模型文档均可以透过 Autodesk Forge Model Derivative 服务提取、转换在 Viewer 里渲染(Render)构件外观时所需的材质(Material)及贴图(Texture)。在 Viewer 里渲染这些材质是会耗损计算机内存(Memory)的,但有时候咱们观注的是构件的几何信息,贴图(Texture)反却是能够被忽略的,但这要怎么作到呢?浏览器
在 Viewer API 里有一个函数matman()
能够获取 Viewer 的材质管理员,透过它能够取得全部 Viewer 自带和自订的材质。因此咱们能够透过它遍历全部材质,找出咱们想隐藏贴图的那些材质,将它的颜色设置为灰色,同时也能够透过它将隐藏贴图的材质回复。ide
注:这个例子没办法在没贴图的材质上有做用;这范例在浏览器 Console 测试过,且使用默认的 Viewer 实例 NOP_VIEWER。函数
//store textures data var oldTextures = new Array(); //store color data var oldColors = new Array(); //remove texture function hideTexture() { //get materials list var mats = NOP_VIEWER.impl.matman()._materials; //define a grey color var grey = new THREE.Color(0.5, 0.5, 0.5); //iterate materials for (index in mats) { //index is the material name (unique string in the list) m = mats[index]; //store texture info oldTextures[index] = m.map; oldColors[index] = m.color; //set the material without texture and the grey color m.map = null; m.color = grey; //mark the material dirty. The viewer will refresh m.needsUpdate = true; } //refresh the scene NOP_VIEWER.impl.invalidate(true, true, false); } //show texture function showTexture() { //get materials list var mats = NOP_VIEWER.impl.matman()._materials; //iterate materials for (index in mats) { //index is the material name (unique string in the list) m = mats[index]; //restore m.map = oldTextures[index]; m.color = oldColors[index];; m.needsUpdate = true; } //refresh the scene NOP_VIEWER.impl.invalidate(true, true, false); }
在隐藏贴图前的样子:测试
在移除贴图后的样子:spa
上述的例子我没有在 Shader Material 上测试,或许有更有的办法可行,我建议各位朋友们能够参考我同事发布的其余博客:rest