简体   繁体   English

更新线框几何

[英]Updating Wireframe Geometry

Is it possible to show the wireframe and the object itself, whose vertices constantly updating with a shader. 是否可以显示线框和对象本身,其顶点会通过着色器不断更新。

my code is basically; 我的代码基本上是

var mainGeo = new THREE.SphereGeometry(100, 80, 80);
var shaderMaterial = new THREE.ShaderMaterial({
  transparent: true,
  uniforms: displacementUniforms,
  vertexShader: document.getElementById('displacement_vertex').textContent,
  fragmentShader: document.getElementById('displacement_fragment').textContent,  
});

myObject = new THREE.Object3D();

objectLayer1 = new THREE.Mesh(mainGeo, shaderMaterial);
objectLayer2 = new THREE.LineSegments(
  new THREE.WireframeGeometry( objectLayer1.geometry ),
  new THREE.LineBasicMaterial({
    color: 0xff5555,
    transparent: true,
    opacity: 0.5
  })
);

myObject.add(objectLayer1);
myObject.add(objectLayer2);
scene.add(myObject);

update();

updateRender(){
  //RenderScene
  //RenderShaderSourceScene
}

update(){

  //do some stuff

  updateUniforms();
  updateRender();

  requestAnimationFrame(update);
}

updateUniforms(){

  //change shader uniform values

}

I tried wireframeGeometry but i can't update its vertices. 我尝试了wireframeGeometry,但无法更新其顶点。

for example; 例如; i created this object with a displacement shader, and changing its values over time.. 我用置换着色器创建了这个对象,并随时间更改了它的值。

置换着色器对象

now my aim is; 现在我的目标是 show a wireframe around the object and also access the wireframe's properties like width, color, opacity, etc.. 在对象周围显示线框,还可以访问线框的属性,例如宽度,颜色,不透明度等。

How is that possible? 那怎么可能?

Thanks in advance.. 提前致谢..

i figured out! 我想通了!

    objectLayer2 = new THREE.LineSegments(objectLayer1.geometry,shaderMaterial);

but we have a color issue now. 但现在有颜色问题。


EDIT, YAY! 编辑,是的!

Since my linesegments getting their vertex and color values from the shader, i needed to write a little fragment shader to recolor my line segments. 由于我的线段是从着色器获取顶点和颜色值的,因此我需要编写一个小片段着色器以重新着色线段。

here it is; 这里是;

uniform vec3 lineSegmentColor;

void main() { 
  gl_FragColor = vec4( lineSegmentColor, 1.0 );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM