Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Debug = Core.Debug;
  2. var Mesh3D = Core.Mesh3D;
  3. var Solid = Core.Solid;
  4. var Vector3D = Core.Vector3D;
  5.  
  6. /*
  7.   params = [
  8.   { "id": "radius", "displayName": "Radius", "type": "length", "rangeMin": 1, "rangeMax": 50, "default": 20 }
  9.   ]
  10. */
  11.  
  12. function er(phi){
  13.   return new Vector3D(Math.cos(phi),Math.sin(phi),0);
  14. }
  15.  
  16. function addQuad(mesh, v1, v2, v3, v4){
  17.   var p1=[v1.x,v1.y,v1.z];
  18.   var p2=[v2.x,v2.y,v2.z];
  19.   var p3=[v3.x,v3.y,v3.z];
  20.   var p4=[v4.x,v4.y,v4.z];
  21.   mesh.quad(p1,p2,p3,p4);
  22. }
  23.  
  24. function p(v){
  25.   return [v.x,v.y,v.z];
  26. }
  27.  
  28. function pD(v){
  29.   return "("+v.x+","+v.y+","+v.z+")";
  30. }
  31.  
  32. function process(params) {
  33.   var mesh = new Mesh3D();
  34.   var inner_radius=100.0;
  35.   var outer_radius=120.0;
  36.   var points=5;
  37.   var points_z=10;
  38.   var twist=Math.PI*2.0;
  39.   var height=200.0;
  40.  
  41.   var layers=[];
  42.   for(var j=0;j<points_z-1;++j){
  43.     var l=[];
  44.     var phi0=twist/points_z*j;
  45.     var z0=new Vector3D(0,0,height/points_z*j);
  46.     Debug.log(pD(z0));
  47.    
  48.     var r0=1.0-1.0*j/points_z;
  49.     for(var i=0; i<points; i++){
  50.       l.push(er(i*Math.PI/points+phi0).scale(inner_radius*r0).add(z0));
  51.       l.push(er((i+0.5)*Math.PI/points+phi0).scale(outer_radius*r0).add(z0));
  52.     }
  53.     layers.push(l);
  54.   }
  55.   var top=new Vector3D([0,0,height]);
  56.   var bottom_centre=new Vector3D([0,0,0]);
  57.  
  58.   for(i=0;i<layers.length-1;++i){
  59.     for(j=0;j<layers[i].length;++j){
  60.       mesh.quad(p(layers[i][j]),p(layers[i][(j+1)%layers[i].length]),p(layers[i+1][(j+1)%layers[i+1].length]),p(layers[i+1][j]));
  61.     }
  62.   }
  63.   for(j=0;j<layers[layers.length-1].length;j++){
  64.     mesh.triangle(p(layers[i][j]),p(layers[i][(j+1)%layers[i].length]),p(top));
  65.     //Debug.log(pD(layers[i][j]));
  66.   }
  67.   for(j=0;j<layers[0].length;j++){
  68.     mesh.triangle(p(layers[0][j]),p(bottom_centre),p(layers[0][(j+1)%layers[0].length]));
  69.   }
  70.  
  71.   return Solid.make(mesh);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement