简体   繁体   English

使用three.js使对象部分透明

[英]Make on object partially transparent using three.js

I'm experimenting with three.js. 我正在尝试three.js。 Based on several tutorials I've created a small script that loads an object from obj file, puts a texture on it and provides some interactive features like camera control and collision detection when the cursor moves over the object on screen. 根据一些教程,我创建了一个小脚本,该脚本从obj文件加载对象,在其上放置纹理,并在光标移到屏幕上的对象上时提供一些交互功能,例如相机控制和碰撞检测。

I know how i can change the transparency of the whole object, but now I'm looking for a way to make the loaded object partially transparent depending on the cursors position. 我知道如何更改整个对象的透明度,但是现在我正在寻找一种方法来根据光标的位置使加载的对象部分透明。 If the ray of the cursor intersects the object, all triangles nearby the collision point should get a higher transparency so that i can see other objects inside or behind this object. 如果光标的光线与该对象相交,则碰撞点附近的所有三角形应具有更高的透明度,以便我可以看到该对象内部或后面的其他对象。 Is there a way to do this? 有没有办法做到这一点? Anybody knows a tutorial which shows a solution for the implementation with three.js? 任何人都知道一个教程,该教程显示了Three.js实现的解决方案吗?

For any help or approach I would be grateful. 对于任何帮助或方法,我将不胜感激。

Its possible to write a custom vertex shader for that, where each vertex has a transparent attribute, and with mouse movements, find the intersection face, and modify face's vertex transparent value. 为此可以编写一个自定义顶点着色器,其中每个顶点都有一个透明属性,并通过鼠标移动找到相交面,并修改该面的顶点透明值。

http://jsfiddle.net/meirm/58w9cfb0/ http://jsfiddle.net/meirm/58w9cfb0/

in this example i wrote very simple shader with attribute opacity per pixel, then in the intersection testing i change the opacity for intersected face's vertices 在此示例中,我编写了一个非常简单的着色器,每个像素具有属性不透明度,然后在相交测试中,我更改了相交的脸部顶点的不透明度

attribute float opacity;

...

attributes.opacity.value[intersects[0].face.a] = 0.5;
attributes.opacity.value[intersects[0].face.a] = 0.5;
attributes.opacity.value[intersects[0].face.a] = 0.5;

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

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