提交 2202f0a6 编写于 作者: A alteredq

Fixed broken custom attributes demo.

Attributes were not in fact updated before.
上级 ece93dfe
......@@ -88,6 +88,8 @@
var sphere, uniforms, attributes;
var noise = [];
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight;
......@@ -136,9 +138,11 @@
var vertices = sphere.geometry.vertices;
var values = attributes.displacement.value;
for( var v = 0; v < vertices.length; v++ ) {
values[ v ] = Math.random() * 5;
values[ v ] = 0;
noise[ v ] = Math.random() * 5;
}
......@@ -157,6 +161,11 @@
}
function cap( x, a, b ) {
return ( x < a ) ? a : ( ( x > b ) ? b : x );
}
var i, value;
function animate() {
......@@ -170,18 +179,21 @@
function render() {
sphere.rotation.y += 0.01;
sphere.rotation.z += 0.01;
var time = new Date().getTime() * 0.01;
sphere.rotation.y = 0.01 * time;
sphere.rotation.z = 0.01 * time;
uniforms.amplitude.value = 2.5 * Math.sin( sphere.rotation.y * 0.125 );
THREE.ColorUtils.adjustHSV( uniforms.color.value, 0.0005, 0, 0 );
for( i = 0; i < attributes.displacement.value.length; i++ ) {
value = attributes.displacement.value[ i ];
value[ i ] += 0.5 * ( 0.5 - Math.random() );
if ( value[ i ] < -5 ) value[ i ] = -5;
if ( value[ i ] > 5 ) value[ i ] = 5;
attributes.displacement.value[ i ] = Math.sin( 0.1*i + time );
noise[ i ] += 0.5 * ( 0.5 - Math.random() );
noise[ i ] = cap( noise[ i ], -5, 5 );
attributes.displacement.value[ i ] += noise[ i ];
}
attributes.displacement.needsUpdate = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册