在Forge Viewer中剪切平面无法使用ShaderMaterial剪切对象 [英] clipping planes in forge viewer not able to clip objects with ShaderMaterial
问题描述
我正在尝试在THREE.ShaderMaterial
添加自定义对象,我能够在overlayScene
中添加和呈现对象.
I am trying to add custom objects with THREE.ShaderMaterial
in forge-viewer, I am able to add and render the objects in forge-viewer's overlayScene
.
我提到了此用于添加相同内容的博客.
I referred this blog for adding the same.
我面临的问题是: 伪造查看器的剪切平面无法剪切自定义添加的对象. 如果我尝试与其他材料添加同一对象,则剪切平面可以对其进行剪切.
The problem I am facing is: The forge-viewer's clipping planes are not able to clip the custom added objects. If I try to add same object with other material, then clipping planes are able to clip them.
我尝试了此.但是我收到Cannot resolve #include<clipping_planes_pars_vertex.glsl>
的错误(与其他着色器源相同).我试图在THREE.ShaderChunk
中添加这些着色器,但是没有用.
I have tried this. But I am getting error that Cannot resolve #include<clipping_planes_pars_vertex.glsl>
(same for other shader sources). I have tried to add these shaders in THREE.ShaderChunk
but not worked.
我已经看到错误来自ShaderChunk.ts
,因为它没有在chunks[]
中找到着色器.
I have seen that the error comes from in ShaderChunk.ts
because it didn't found shader in chunks[]
.
- 有什么方法可以在
THREE.ShaderMaterial
中使用剪切平面吗? - 是否需要在
ShaderChunk.ts
中的chunks[]
中添加我的自定义着色器?如果是,怎么办?
- Is there any way to use clipping planes with
THREE.ShaderMaterial
? - Do I need to add my custom shaders in
chunks[]
fromShaderChunk.ts
? If yes How?
请分享一个演示示例.
推荐答案
与您发现的另一个Stack Overflow问题类似,Forge Viewer中的section工具使用了自定义着色器逻辑,该逻辑仅包含在Viewer自己的材料中.尝试在材质着色器中包含以下片段:
Similarly to the other Stack Overflow question you found, the section tool in Forge Viewer uses a custom shader logic that is only included in the Viewer's own materials. Try including the following snippets in your material shaders:
在顶点着色器中:
...
#if NUM_CUTPLANES > 0
varying vec3 vWorldPosition;
#endif
...
void main() {
...
#if NUM_CUTPLANES > 0
vWorldPosition = vec3(/* include your own vertex world position here */);
#endif
...
}
...
在片段着色器中:
...
#if NUM_CUTPLANES > 0
varying highp vec3 vWorldPosition;
#endif
#include<cutplanes>
...
void main() {
...
#if NUM_CUTPLANES > 0
checkCutPlanes(vWorldPosition);
#endif
...
}
...
在定义新的THREE.ShaderMaterial
时,您还需要包括几个特定于部门的制服:
And when defining the new THREE.ShaderMaterial
, you also need to include a couple of sectioning-specific uniforms:
const uniforms = {
...
"cutplanes": { type: "v4v", value: [] },
"hatchParams": { type: "v2", value: new THREE.Vector2(1.0, 10.0) },
"hatchTintColor": { type: "c", value: new THREE.Color( 0xFFFFFF ) },
"hatchTintIntensity": { type: "f", value: 1.0 },
...
}
有关向
这篇关于在Forge Viewer中剪切平面无法使用ShaderMaterial剪切对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!