A dynamically deformable circle (+shader)

Advanced application

The method can be used to achieve performant dynamic base geometries very easily.


const geometry = new THREE.CylinderBufferGeometry( 0.5, 0.5, 1, 360, 10, false );
or
const geometry = new THREE.BoxBufferGeometry( 1.0, 1.0, 1.0, 100, 100, 100 );

  vec3 getPoint( vec3 p ) {
    float r = length( p.xzy );
    float phi = atan( p.x, p.z );
    p.xz +=  p.xz * 0.2 * r * sin( 3.0 * phi ) * ( 1.0 + cos( u_time ) ); //   4.0 * phi box
    return p;
  }


const geometry = new THREE.PlaneBufferGeometry( 1.0, 1.0, 100, 100 );

 vec3 getPoint(vec3 p){
    float lenx = length( p.x);
    float leny = length( p.y);
    p.z = 0.04 * ( 1.0 + sin( PI * 24.0 * lenx * leny  ) ) * cos( u_time * 0.3 );
    return p;
  }


const geometry = new THREE.PlaneBufferGeometry( 1.0, 1.0, 100, 100 );

  float f( float d ) {       
        return 0.5 * ( 1.0 + sin( d ) ) * sqrt( d );           
  }
  vec3 getPoint( vec3 p ) {   
    float lenx = length( p.x );
    float leny = length( p.y );  
    p.z = ( lenx - leny ) * ( leny - lenx ) * f( lenx ) * f( leny ) * 6.0 * sin( u_time );
    // p.z = ( lenx + leny ) * ( leny + lenx ) * f( lenx ) * f( leny ) * 0.6 * sin( u_time ); // try out
    return p;
  }


const geometry = new THREE.TorusGeometry( 1, 0.5, 64, 100 );

  vec3 getPoint( vec3 p ) { 
    p.z =  abs( p.z ) > 0.3 ? sign( p.z ) * 0.3 : p.z; // symmetrical
    return p;  
  }

2022-01-09 20.26.01
see also Best way to flatten the top and bottom of a torus geometry - #7 by hofk


const geometry = new THREE.BoxGeometry( 1, 1, 1, 360, 1, 1 );

  vec3 getPoint( vec3 p ) {
   // @author prisoner89
    float r = 2.0;
    float R = 3.0;
    float waves = 5.0;
    float angle = p.x * PI * 2.0;
    float radius = p.z > 0.0 ? R : r;
    float y = p.y < 0.5 ? p.y : p.y + sin( p.x * PI * 2.0 * waves ) * 0.25;
    p = vec3( cos( angle ) * radius,  y, -sin( angle ) * radius );
    return p;  
  }

2022-01-09 20.53.38

see also How to create sine-wave groove in ring geometry with extrudegeometry? - #6 by prisoner849

1 Like