三种不同材质和方向光强的js线条
Three.JS Lines with different materials and directional light intensity
Three.js非常好,但是我有一个小问题。
我在这里创建了一个小提琴:
http://jsfiddle.net/ntsim/aekPu/4/var railingGeo = new THREE.Geometry();
railingGeo.vertices.push(new THREE.Vector3(50, 25, 50));
railingGeo.vertices.push(new THREE.Vector3(50, 35, 50));
railingGeo.vertices.push(new THREE.Vector3(-50, 35, 50));
railingGeo.vertices.push(new THREE.Vector3(-50, 25, 50));
railingGeo.vertices.push(new THREE.Vector3(-50, 35, 50));
railingGeo.vertices.push(new THREE.Vector3(-50, 35, -50));
railingGeo.vertices.push(new THREE.Vector3(-50, 25, -50));
railingGeo.vertices.push(new THREE.Vector3(-50, 35, -50));
railingGeo.vertices.push(new THREE.Vector3(50, 35, -50));
railingGeo.vertices.push(new THREE.Vector3(50, 25, -50));
railingGeo.vertices.push(new THREE.Vector3(50, 35, -50));
railingGeo.vertices.push(new THREE.Vector3(50, 35, 50));
var yellowLineBasicMaterial = new THREE.LineBasicMaterial({
color: 0x777700,
shading: THREE.FlatShading
});
var yellowMeshPhongMaterial = new THREE.MeshPhongMaterial({ //shininess: 40,
specular: 0x770000,
ambient: 0x770000,
emissive: 0x000000,
color: 0x777700,
shading: THREE.FlatShading
});
var railing=new THREE.Line(railingGeo,yellowLineBasicMaterial); // railing glows yellow when lights are out
//var railing = new THREE.Line(railingGeo, yellowMeshPhongMaterial); // railing dims when lights goo out but WEBGL ERROR ocurs
// error is:WebGL: INVALID_OPERATION: vertexAttribPointer: no bound ARRAY_BUFFER
building.add(railing);
return building;
在这个场景中,我创建了一个小建筑,屋顶上有一个栏杆,有一个方向灯。光的强度随时间在0到100之间振荡。
我的问题是关于栏杆的,它实际上只是一组简单的线条。
我想让整个建筑和栏杆变暗,因为光的强度为零。
检查my fiddle的第72行和第73行。
当我用LineBasicMaterial创建栏杆时,不管光线强度如何,栏杆总是发光的。那不是我想要的。
如果我将栏杆的材质属性改为MeshPhongMaterial,那么栏杆在一定程度上随着光强度变为零而变暗,但是这段代码会在Chrome浏览器控制台上产生"WEBGL错误:INVALID_OPERATION: vertexAttribPointer: no bound ARRAY_BUFFER"。
我想我明白为什么WEBGL错误。我认为这是因为直线没有法线来反射光线?或者类似的东西
尽管如此,在我看来,我应该能够在我的线条中强制使用某种材料属性,这样线条的颜色强度就可以通过场景的整体光强度来降低,而不会出现WEBGL错误。几年前,我用opengl编写了一个c++程序,我能够做到这一点,没有任何问题。这可能是一个THREE.js错误或WEBGL问题吗?当光线强度变化时,我可以动态地改变线条的颜色值,但是有更好的方法吗?
谢谢!
LineBasicMaterial
对灯光没有反应,由于您提到的原因,其他材料也不适合做线条。
你可以这样做:
yellowLineBasicMaterial.color.setRGB( light.intensity / 100, light.intensity / 100, 0 );
另一种解决方案是栏杆用CubeGeometry
,栏杆材料用MeshPhongMaterial
,设置wireframe: true
。在这种情况下,你应该得到你想要的效果。
three.js r.58
- ng映射方向备选方案
- RubyonRails——构建交互式接口应该朝哪个方向发展
- 需要帮助谷歌地图方向面板在FancyBox中显示
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 我怎样才能知道用户滑动的方向
- 在可触摸的高光上添加compnant
- 使用谷歌地图API和phonegap显示当前位置+方向
- 用真或假初始化变量是否在 Javascript 中建立了内容的方向
- 带有自定义标记的谷歌地图方向APIv3
- 在角度方向的元素之前插入
- 更改D3方向力图中箭头标记的方向
- fullpage.js在滚动时更改滚动方向
- 基于谷歌地图API方向服务构建的替代路线
- 点击 中的 <强> 代码时,Google 代码未触发
- 双击泛光灯单击
- 如何将字符串地址传递到传单路由机,以根据字符串地址获得方向
- 在画布中以相反方向移动矩形
- .show()不会改变效果或方向
- JavaScript位置/方向计算
- 三种不同材质和方向光强的js线条