0

Help Shape will not generate

Hello the following code seems error free but tinker cad will not generate the shape or even give the input space 

Any ideas

 

// Convenience Declarations For Dependencies.

// 'Core' Is Configured In Libraries Section.

// Some of these may not be used by this example.

var Conversions = Core.Conversions;

var Debug = Core.Debug;

var Path2D = Core.Path2D;

var Point2D = Core.Point2D;

var Point3D = Core.Point3D;

var Matrix2D = Core.Matrix2D;

var Matrix3D = Core.Matrix3D;

var Mesh3D = Core.Mesh3D;

var Plugin = Core.Plugin;

var Tess = Core.Tess;

var Sketch2D = Core.Sketch2D;

var Solid = Core.Solid;

var Vector2D = Core.Vector2D;

var Vector3D = Core.Vector3D;

 

// Template Code:

/*

  Empty shape example.

 

  Tinkercad developer documentation is at:

     https://tinkercad.com/developer/

 

  To create parameters in the user interface,

  create a 'params' array on the top level of this script.

  For example:

  params = [

  { "id": "radius", "displayName": "Radius", "type": "length", "rangeMin": 1, "rangeMax": 50, "default": 20 }

  ]

 

*/

params = [

  { "id": "phase", "displayName": "Angle", "type": "int", "rangeMin": 0, "rangeMax": 360, "default": 45 },

  { "id":"filter", "displayName": "Height", "type": "float", "rangeMin": 0, "rangeMax": 20, "default": 3 },

  { "id": "r", "displayName": "lenght", "type": "float", "rangeMin": 16, "rangeMax": 40, "default" : 20 }

];

   for (var i = 0; i < angle; i++) {

var xo= length * Math.cos(i * angle);

var yo= length * Math.sin(i * angle);

var zo= 0;

var x1= lenght * Math.cos(i * angle);

var y1= lenght * Math.sin(i * angle);

var z1= 0;

var x2= lenght * Math.cos(i * angle);

var y3= lenght * Math.cos(1 * angle);

var z3= 0;

        angle.push([[x0, y0], [x1, y1], [x2, y2], [x3, y3]]);

     /*

        Debug.line(x0,y0,0,x1,y1,0);

      Debug.line(x1,y1,0,x2,y2,0);

      Debug.line(x2,y2,0,x3,y3,0);

      Debug.line(x3,y3,0,x0,y0,0);

      */

    }

var mesh = new Mesh3D();

    for (var i = 0; i < angle.length; i++) {

        var tong = tongs[i];

        mesh.quad(xyAt(angle[0], 0), xyAt(angle[1], 0), xyAt(angle[2], 0), xyAt(angle[3], 0));

        

        mesh.quad(xyAt(angle[0], 0), xyAt(angle[1], 0), xyAt(angle[1], height), xyAt(angle[0], height));

        mesh.quad(xyAt(angle[1], 0), xyAt(angle[2], 0), xyAt(angle[2], height), xyAt(angle[1], height));

        mesh.quad(xyAt(angle[2], 0), xyAt(angle[3], 0), xyAt(angle[3], height), xyAt(angle[2], height));

        mesh.quad(xyAt(tong[3], 0), xyAt(angle[0], 0), xyAt(angle[0], height), xyAt(angle[3], height));

     

        mesh.quad(xyAt(angle[0], height), xyAt(angle[1], height), xyAt(angle[2], height), xyAt(angle[3], height));

    }

 

var r = params["r"];

                var ndivs = r;

                var tau = 0.8506508084;

                var one = 0.5257311121;

                var lod = 0;

                //var height = params["pitted"] ? -4.0 : 4.0;

                var height = 4.0;

 

                while(ndivs > 6){

                                lod++;

                                ndivs /= 2;

                }

 

                var v = [

                                [ tau, one, 0.0 ],

                                [-tau, one, 0.0 ],

                                [-tau,-one, 0.0 ],

                                [ tau,-one, 0.0 ],

                                [ one, 0.0, tau ],

                                [ one, 0.0,-tau ],

                                [-one, 0.0,-tau ],

                                [-one, 0.0, tau ],

                                [ 0.0, tau, one ],

                                [ 0.0,-tau, one ],

                                [ 0.0,-tau,-one ],

                                [ 0.0, tau,-one ]

                ];

               

                var tris = [

                                [ v[4], v[8], v[7] ],

                                [ v[4], v[7], v[9] ],

                                [ v[5], v[6],v[11] ],

                                [ v[5],v[10], v[6] ],

                                [ v[0], v[4], v[3] ],

                                [ v[0], v[3], v[5] ],

                                [ v[2], v[7], v[1] ],

                                [ v[2], v[1], v[6] ],

                                [ v[8], v[0],v[11] ],

                                [ v[8],v[11], v[1] ],

                                [ v[9],v[10], v[3] ],

                                [ v[9], v[2],v[10] ],

                                [ v[8], v[4], v[0] ],

                                [v[11], v[0], v[5] ],

                                [ v[4], v[9], v[3] ],

                                [ v[5], v[3],v[10] ],

                                [ v[7], v[8], v[1] ],

                                [ v[6], v[1],v[11] ],

                                [ v[7], v[2], v[9] ],

                                [ v[6],v[10], v[2] ]

                ];

               

                function norm(a) {

                                var l = Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);

                                return [ a[0]/l, a[1]/l, a[2]/l ];

                }

 

                function sum(a, b) {

                                return [ (a[0]+b[0]), (a[1]+b[1]), (a[2]+b[2]) ];

                }

 

                function xf(a, s) {

                                var v = dispv([ a[0]*s, a[1]*s, a[2]*s ]);

                                v[2] += s + height;

                                return v;

                }

               

                function dispv(p) {

                                var he = Math.pow((1+noise.turbulence(p[0], p[1], p[2]+params.phase, 2)/2.0), params.filter)*height;

                                var n = norm(p);

                                return [p[0] + n[0]*he, p[1] + n[1]*he, p[2] + n[2]*he];

                }

               

                for (var i = 0; i < lod; i++) {

                                var ntris = [];

                                for(var j = 0; j < tris.length; j++) {

                                                var ma = norm(sum(tris[j][0], tris[j][1]));

                                                var mb = norm(sum(tris[j][1], tris[j][2]));

                                                var mc = norm(sum(tris[j][2], tris[j][0]));

 

                                                ntris.push([tris[j][0], ma, mc]);

                                                ntris.push([tris[j][1], mb, ma]);

                                                ntris.push([tris[j][2], mc, mb]);

                                                ntris.push([ma, mb, mc]);

                                }

                                tris = ntris;

                }

 

                var mesh = new Mesh3D();

                for (var i = 0; i < tris.length; i++) {

                                mesh.triangle(xf(tris[i][0], 10), xf(tris[i][1], 10), xf(tris[i][2], 10));

                }

 

 var solid = Solid.make(mesh);

               

                return solid;

0 comments

Please sign in to leave a comment.