var bezierPatch = new Array(
    new Array(new Vec3D(0.4090909957885742,0.7727270126342773,0),new Vec3D(0.4090909957885742,0.7727270126342773,-0.22909100353717804),new Vec3D(0.22909100353717804,0.7727270126342773,-0.4090909957885742),new Vec3D(0,0.7727270126342773,-0.4090909957885742),new Vec3D(0.4090909957885742,0.8863639831542969,0),new Vec3D(0.4090909957885742,0.8863639831542969,-0.22909100353717804),new Vec3D(0.22909100353717804,0.8863639831542969,-0.4090909957885742),new Vec3D(0,0.8863639831542969,-0.4090909957885742),new Vec3D(0.4545449912548065,0.8863639831542969,0),new Vec3D(0.4545449912548065,0.8863639831542969,-0.2545450031757355),new Vec3D(0.2545450031757355,0.8863639831542969,-0.4545449912548065),new Vec3D(0,0.8863639831542969,-0.4545449912548065),new Vec3D(0.4545449912548065,0.7727270126342773,0),new Vec3D(0.4545449912548065,0.7727270126342773,-0.2545450031757355),new Vec3D(0.2545450031757355,0.7727270126342773,-0.4545449912548065),new Vec3D(0,0.7727270126342773,-0.4545449912548065)),
    new Array(new Vec3D(0,0.7727270126342773,-0.4090909957885742),new Vec3D(-0.22909100353717804,0.7727270126342773,-0.4090909957885742),new Vec3D(-0.4090909957885742,0.7727270126342773,-0.22909100353717804),new Vec3D(-0.4090909957885742,0.7727270126342773,0),new Vec3D(0,0.8863639831542969,-0.4090909957885742),new Vec3D(-0.22909100353717804,0.8863639831542969,-0.4090909957885742),new Vec3D(-0.4090909957885742,0.8863639831542969,-0.22909100353717804),new Vec3D(-0.4090909957885742,0.8863639831542969,0),new Vec3D(0,0.8863639831542969,-0.4545449912548065),new Vec3D(-0.2545450031757355,0.8863639831542969,-0.4545449912548065),new Vec3D(-0.4545449912548065,0.8863639831542969,-0.2545450031757355),new Vec3D(-0.4545449912548065,0.8863639831542969,0),new Vec3D(0,0.7727270126342773,-0.4545449912548065),new Vec3D(-0.2545450031757355,0.7727270126342773,-0.4545449912548065),new Vec3D(-0.4545449912548065,0.7727270126342773,-0.2545450031757355),new Vec3D(-0.4545449912548065,0.7727270126342773,0)),
    new Array(new Vec3D(-0.4090909957885742,0.7727270126342773,0),new Vec3D(-0.4090909957885742,0.7727270126342773,0.22909100353717804),new Vec3D(-0.22909100353717804,0.7727270126342773,0.4090909957885742),new Vec3D(0,0.7727270126342773,0.4090909957885742),new Vec3D(-0.4090909957885742,0.8863639831542969,0),new Vec3D(-0.4090909957885742,0.8863639831542969,0.22909100353717804),new Vec3D(-0.22909100353717804,0.8863639831542969,0.4090909957885742),new Vec3D(0,0.8863639831542969,0.4090909957885742),new Vec3D(-0.4545449912548065,0.8863639831542969,0),new Vec3D(-0.4545449912548065,0.8863639831542969,0.2545450031757355),new Vec3D(-0.2545450031757355,0.8863639831542969,0.4545449912548065),new Vec3D(0,0.8863639831542969,0.4545449912548065),new Vec3D(-0.4545449912548065,0.7727270126342773,0),new Vec3D(-0.4545449912548065,0.7727270126342773,0.2545450031757355),new Vec3D(-0.2545450031757355,0.7727270126342773,0.4545449912548065),new Vec3D(0,0.7727270126342773,0.4545449912548065)),
    new Array(new Vec3D(0,0.7727270126342773,0.4090909957885742),new Vec3D(0.22909100353717804,0.7727270126342773,0.4090909957885742),new Vec3D(0.4090909957885742,0.7727270126342773,0.22909100353717804),new Vec3D(0.4090909957885742,0.7727270126342773,0),new Vec3D(0,0.8863639831542969,0.4090909957885742),new Vec3D(0.22909100353717804,0.8863639831542969,0.4090909957885742),new Vec3D(0.4090909957885742,0.8863639831542969,0.22909100353717804),new Vec3D(0.4090909957885742,0.8863639831542969,0),new Vec3D(0,0.8863639831542969,0.4545449912548065),new Vec3D(0.2545450031757355,0.8863639831542969,0.4545449912548065),new Vec3D(0.4545449912548065,0.8863639831542969,0.2545450031757355),new Vec3D(0.4545449912548065,0.8863639831542969,0),new Vec3D(0,0.7727270126342773,0.4545449912548065),new Vec3D(0.2545450031757355,0.7727270126342773,0.4545449912548065),new Vec3D(0.4545449912548065,0.7727270126342773,0.2545450031757355),new Vec3D(0.4545449912548065,0.7727270126342773,0)),
    new Array(new Vec3D(0.4545449912548065,0.7727270126342773,0),new Vec3D(0.4545449912548065,0.7727270126342773,-0.2545450031757355),new Vec3D(0.2545450031757355,0.7727270126342773,-0.4545449912548065),new Vec3D(0,0.7727270126342773,-0.4545449912548065),new Vec3D(0.4545449912548065,0.5454549789428711,0),new Vec3D(0.4545449912548065,0.5454549789428711,-0.2545450031757355),new Vec3D(0.2545450031757355,0.5454549789428711,-0.4545449912548065),new Vec3D(0,0.5454549789428711,-0.4545449912548065),new Vec3D(0.4545449912548065,0.27272701263427734,0),new Vec3D(0.4545449912548065,0.27272701263427734,-0.2545450031757355),new Vec3D(0.2545450031757355,0.27272701263427734,-0.4545449912548065),new Vec3D(0,0.27272701263427734,-0.4545449912548065),new Vec3D(0.31818199157714844,0.04545449838042259,0),new Vec3D(0.31818199157714844,0.04545449838042259,-0.17818200588226318),new Vec3D(0.17818200588226318,0.04545449838042259,-0.31818199157714844),new Vec3D(0,0.04545449838042259,-0.31818199157714844)),
    new Array(new Vec3D(0,0.7727270126342773,-0.4545449912548065),new Vec3D(-0.2545450031757355,0.7727270126342773,-0.4545449912548065),new Vec3D(-0.4545449912548065,0.7727270126342773,-0.2545450031757355),new Vec3D(-0.4545449912548065,0.7727270126342773,0),new Vec3D(0,0.5454549789428711,-0.4545449912548065),new Vec3D(-0.2545450031757355,0.5454549789428711,-0.4545449912548065),new Vec3D(-0.4545449912548065,0.5454549789428711,-0.2545450031757355),new Vec3D(-0.4545449912548065,0.5454549789428711,0),new Vec3D(0,0.27272701263427734,-0.4545449912548065),new Vec3D(-0.2545450031757355,0.27272701263427734,-0.4545449912548065),new Vec3D(-0.4545449912548065,0.27272701263427734,-0.2545450031757355),new Vec3D(-0.4545449912548065,0.27272701263427734,0),new Vec3D(0,0.04545449838042259,-0.31818199157714844),new Vec3D(-0.17818200588226318,0.04545449838042259,-0.31818199157714844),new Vec3D(-0.31818199157714844,0.04545449838042259,-0.17818200588226318),new Vec3D(-0.31818199157714844,0.04545449838042259,0)),
    new Array(new Vec3D(-0.4545449912548065,0.7727270126342773,0),new Vec3D(-0.4545449912548065,0.7727270126342773,0.2545450031757355),new Vec3D(-0.2545450031757355,0.7727270126342773,0.4545449912548065),new Vec3D(0,0.7727270126342773,0.4545449912548065),new Vec3D(-0.4545449912548065,0.5454549789428711,0),new Vec3D(-0.4545449912548065,0.5454549789428711,0.2545450031757355),new Vec3D(-0.2545450031757355,0.5454549789428711,0.4545449912548065),new Vec3D(0,0.5454549789428711,0.4545449912548065),new Vec3D(-0.4545449912548065,0.27272701263427734,0),new Vec3D(-0.4545449912548065,0.27272701263427734,0.2545450031757355),new Vec3D(-0.2545450031757355,0.27272701263427734,0.4545449912548065),new Vec3D(0,0.27272701263427734,0.4545449912548065),new Vec3D(-0.31818199157714844,0.04545449838042259,0),new Vec3D(-0.31818199157714844,0.04545449838042259,0.17818200588226318),new Vec3D(-0.17818200588226318,0.04545449838042259,0.31818199157714844),new Vec3D(0,0.04545449838042259,0.31818199157714844)),
    new Array(new Vec3D(0,0.7727270126342773,0.4545449912548065),new Vec3D(0.2545450031757355,0.7727270126342773,0.4545449912548065),new Vec3D(0.4545449912548065,0.7727270126342773,0.2545450031757355),new Vec3D(0.4545449912548065,0.7727270126342773,0),new Vec3D(0,0.5454549789428711,0.4545449912548065),new Vec3D(0.2545450031757355,0.5454549789428711,0.4545449912548065),new Vec3D(0.4545449912548065,0.5454549789428711,0.2545450031757355),new Vec3D(0.4545449912548065,0.5454549789428711,0),new Vec3D(0,0.27272701263427734,0.4545449912548065),new Vec3D(0.2545450031757355,0.27272701263427734,0.4545449912548065),new Vec3D(0.4545449912548065,0.27272701263427734,0.2545450031757355),new Vec3D(0.4545449912548065,0.27272701263427734,0),new Vec3D(0,0.04545449838042259,0.31818199157714844),new Vec3D(0.17818200588226318,0.04545449838042259,0.31818199157714844),new Vec3D(0.31818199157714844,0.04545449838042259,0.17818200588226318),new Vec3D(0.31818199157714844,0.04545449838042259,0)),
    new Array(new Vec3D(0.27272701263427734,0.04545449838042259,0),new Vec3D(0.27272701263427734,0.04545449838042259,-0.15272699296474457),new Vec3D(0.15272699296474457,0.04545449838042259,-0.27272701263427734),new Vec3D(0,0.04545449838042259,-0.27272701263427734),new Vec3D(0.4090909957885742,0.27272701263427734,0),new Vec3D(0.4090909957885742,0.27272701263427734,-0.22909100353717804),new Vec3D(0.22909100353717804,0.27272701263427734,-0.4090909957885742),new Vec3D(0,0.27272701263427734,-0.4090909957885742),new Vec3D(0.4090909957885742,0.5454549789428711,0),new Vec3D(0.4090909957885742,0.5454549789428711,-0.22909100353717804),new Vec3D(0.22909100353717804,0.5454549789428711,-0.4090909957885742),new Vec3D(0,0.5454549789428711,-0.4090909957885742),new Vec3D(0.4090909957885742,0.7727270126342773,0),new Vec3D(0.4090909957885742,0.7727270126342773,-0.22909100353717804),new Vec3D(0.22909100353717804,0.7727270126342773,-0.4090909957885742),new Vec3D(0,0.7727270126342773,-0.4090909957885742)),
    new Array(new Vec3D(0,0.04545449838042259,-0.27272701263427734),new Vec3D(-0.15272699296474457,0.04545449838042259,-0.27272701263427734),new Vec3D(-0.27272701263427734,0.04545449838042259,-0.15272699296474457),new Vec3D(-0.27272701263427734,0.04545449838042259,0),new Vec3D(0,0.27272701263427734,-0.4090909957885742),new Vec3D(-0.22909100353717804,0.27272701263427734,-0.4090909957885742),new Vec3D(-0.4090909957885742,0.27272701263427734,-0.22909100353717804),new Vec3D(-0.4090909957885742,0.27272701263427734,0),new Vec3D(0,0.5454549789428711,-0.4090909957885742),new Vec3D(-0.22909100353717804,0.5454549789428711,-0.4090909957885742),new Vec3D(-0.4090909957885742,0.5454549789428711,-0.22909100353717804),new Vec3D(-0.4090909957885742,0.5454549789428711,0),new Vec3D(0,0.7727270126342773,-0.4090909957885742),new Vec3D(-0.22909100353717804,0.7727270126342773,-0.4090909957885742),new Vec3D(-0.4090909957885742,0.7727270126342773,-0.22909100353717804),new Vec3D(-0.4090909957885742,0.7727270126342773,0)),
    new Array(new Vec3D(-0.27272701263427734,0.04545449838042259,0),new Vec3D(-0.27272701263427734,0.04545449838042259,0.15272699296474457),new Vec3D(-0.15272699296474457,0.04545449838042259,0.27272701263427734),new Vec3D(0,0.04545449838042259,0.27272701263427734),new Vec3D(-0.4090909957885742,0.27272701263427734,0),new Vec3D(-0.4090909957885742,0.27272701263427734,0.22909100353717804),new Vec3D(-0.22909100353717804,0.27272701263427734,0.4090909957885742),new Vec3D(0,0.27272701263427734,0.4090909957885742),new Vec3D(-0.4090909957885742,0.5454549789428711,0),new Vec3D(-0.4090909957885742,0.5454549789428711,0.22909100353717804),new Vec3D(-0.22909100353717804,0.5454549789428711,0.4090909957885742),new Vec3D(0,0.5454549789428711,0.4090909957885742),new Vec3D(-0.4090909957885742,0.7727270126342773,0),new Vec3D(-0.4090909957885742,0.7727270126342773,0.22909100353717804),new Vec3D(-0.22909100353717804,0.7727270126342773,0.4090909957885742),new Vec3D(0,0.7727270126342773,0.4090909957885742)),
    new Array(new Vec3D(0,0.04545449838042259,0.27272701263427734),new Vec3D(0.15272699296474457,0.04545449838042259,0.27272701263427734),new Vec3D(0.27272701263427734,0.04545449838042259,0.15272699296474457),new Vec3D(0.27272701263427734,0.04545449838042259,0),new Vec3D(0,0.27272701263427734,0.4090909957885742),new Vec3D(0.22909100353717804,0.27272701263427734,0.4090909957885742),new Vec3D(0.4090909957885742,0.27272701263427734,0.22909100353717804),new Vec3D(0.4090909957885742,0.27272701263427734,0),new Vec3D(0,0.5454549789428711,0.4090909957885742),new Vec3D(0.22909100353717804,0.5454549789428711,0.4090909957885742),new Vec3D(0.4090909957885742,0.5454549789428711,0.22909100353717804),new Vec3D(0.4090909957885742,0.5454549789428711,0),new Vec3D(0,0.7727270126342773,0.4090909957885742),new Vec3D(0.22909100353717804,0.7727270126342773,0.4090909957885742),new Vec3D(0.4090909957885742,0.7727270126342773,0.22909100353717804),new Vec3D(0.4090909957885742,0.7727270126342773,0)),
    new Array(new Vec3D(-0.4545449912548065,0.7045450210571289,0),new Vec3D(-0.4545449912548065,0.7045450210571289,-0.04545449838042259),new Vec3D(-0.4545449912548065,0.7727270126342773,-0.04545449838042259),new Vec3D(-0.4545449912548065,0.7727270126342773,0),new Vec3D(-0.7727270126342773,0.8636360168457031,0),new Vec3D(-0.7727270126342773,0.8636360168457031,-0.04545449838042259),new Vec3D(-0.8181819915771484,0.9545450210571289,-0.04545449838042259),new Vec3D(-0.8181819915771484,0.9545450210571289,0),new Vec3D(-0.7727270126342773,0.5227270126342773,0),new Vec3D(-0.7727270126342773,0.5227270126342773,-0.04545449838042259),new Vec3D(-0.9090909957885742,0.47727298736572266,-0.04545449838042259),new Vec3D(-0.9090909957885742,0.47727298736572266,0),new Vec3D(-0.4090909957885742,0.36363598704338074,0),new Vec3D(-0.4090909957885742,0.36363598704338074,-0.04545449838042259),new Vec3D(-0.4090909957885742,0.2954550087451935,-0.04545449838042259),new Vec3D(-0.4090909957885742,0.2954550087451935,0)),
    new Array(new Vec3D(-0.4545449912548065,0.7727270126342773,0),new Vec3D(-0.4545449912548065,0.7727270126342773,0.04545449838042259),new Vec3D(-0.4545449912548065,0.7045450210571289,0.04545449838042259),new Vec3D(-0.4545449912548065,0.7045450210571289,0),new Vec3D(-0.8181819915771484,0.9545450210571289,0),new Vec3D(-0.8181819915771484,0.9545450210571289,0.04545449838042259),new Vec3D(-0.7727270126342773,0.8636360168457031,0.04545449838042259),new Vec3D(-0.7727270126342773,0.8636360168457031,0),new Vec3D(-0.9090909957885742,0.47727298736572266,0),new Vec3D(-0.9090909957885742,0.47727298736572266,0.04545449838042259),new Vec3D(-0.7727270126342773,0.5227270126342773,0.04545449838042259),new Vec3D(-0.7727270126342773,0.5227270126342773,0),new Vec3D(-0.4090909957885742,0.2954550087451935,0),new Vec3D(-0.4090909957885742,0.2954550087451935,0.04545449838042259),new Vec3D(-0.4090909957885742,0.36363598704338074,0.04545449838042259),new Vec3D(-0.4090909957885742,0.36363598704338074,0)),
    new Array(new Vec3D(0.31818199157714844,0.04545449838042259,0),new Vec3D(0.31818199157714844,0.04545449838042259,-0.17818200588226318),new Vec3D(0.17818200588226318,0.04545449838042259,-0.31818199157714844),new Vec3D(0,0.04545449838042259,-0.31818199157714844),new Vec3D(0.5454549789428711,0.04545449838042259,0),new Vec3D(0.5454549789428711,0.04545449838042259,-0.3054549992084503),new Vec3D(0.3054549992084503,0.04545449838042259,-0.5454549789428711),new Vec3D(0,0.04545449838042259,-0.5454549789428711),new Vec3D(0.7272729873657227,0.13636399805545807,0),new Vec3D(0.7272729873657227,0.13636399805545807,-0.40727299451828003),new Vec3D(0.40727299451828003,0.13636399805545807,-0.7272729873657227),new Vec3D(0,0.13636399805545807,-0.7272729873657227),new Vec3D(0.9090909957885742,0.13636399805545807,0),new Vec3D(0.9090909957885742,0.13636399805545807,-0.5090910196304321),new Vec3D(0.5090910196304321,0.13636399805545807,-0.9090909957885742),new Vec3D(0,0.13636399805545807,-0.9090909957885742)),
    new Array(new Vec3D(0,0.04545449838042259,-0.31818199157714844),new Vec3D(-0.17818200588226318,0.04545449838042259,-0.31818199157714844),new Vec3D(-0.31818199157714844,0.04545449838042259,-0.17818200588226318),new Vec3D(-0.31818199157714844,0.04545449838042259,0),new Vec3D(0,0.04545449838042259,-0.5454549789428711),new Vec3D(-0.3054549992084503,0.04545449838042259,-0.5454549789428711),new Vec3D(-0.5454549789428711,0.04545449838042259,-0.3054549992084503),new Vec3D(-0.5454549789428711,0.04545449838042259,0),new Vec3D(0,0.13636399805545807,-0.7272729873657227),new Vec3D(-0.40727299451828003,0.13636399805545807,-0.7272729873657227),new Vec3D(-0.7272729873657227,0.13636399805545807,-0.40727299451828003),new Vec3D(-0.7272729873657227,0.13636399805545807,0),new Vec3D(0,0.13636399805545807,-0.9090909957885742),new Vec3D(-0.5090910196304321,0.13636399805545807,-0.9090909957885742),new Vec3D(-0.9090909957885742,0.13636399805545807,-0.5090910196304321),new Vec3D(-0.9090909957885742,0.13636399805545807,0)),
    new Array(new Vec3D(-0.31818199157714844,0.04545449838042259,0),new Vec3D(-0.31818199157714844,0.04545449838042259,0.17818200588226318),new Vec3D(-0.17818200588226318,0.04545449838042259,0.31818199157714844),new Vec3D(0,0.04545449838042259,0.31818199157714844),new Vec3D(-0.5454549789428711,0.04545449838042259,0),new Vec3D(-0.5454549789428711,0.04545449838042259,0.3054549992084503),new Vec3D(-0.3054549992084503,0.04545449838042259,0.5454549789428711),new Vec3D(0,0.04545449838042259,0.5454549789428711),new Vec3D(-0.7272729873657227,0.13636399805545807,0),new Vec3D(-0.7272729873657227,0.13636399805545807,0.40727299451828003),new Vec3D(-0.40727299451828003,0.13636399805545807,0.7272729873657227),new Vec3D(0,0.13636399805545807,0.7272729873657227),new Vec3D(-0.9090909957885742,0.13636399805545807,0),new Vec3D(-0.9090909957885742,0.13636399805545807,0.5090910196304321),new Vec3D(-0.5090910196304321,0.13636399805545807,0.9090909957885742),new Vec3D(0,0.13636399805545807,0.9090909957885742)),
    new Array(new Vec3D(0,0.04545449838042259,0.31818199157714844),new Vec3D(0.17818200588226318,0.04545449838042259,0.31818199157714844),new Vec3D(0.31818199157714844,0.04545449838042259,0.17818200588226318),new Vec3D(0.31818199157714844,0.04545449838042259,0),new Vec3D(0,0.04545449838042259,0.5454549789428711),new Vec3D(0.3054549992084503,0.04545449838042259,0.5454549789428711),new Vec3D(0.5454549789428711,0.04545449838042259,0.3054549992084503),new Vec3D(0.5454549789428711,0.04545449838042259,0),new Vec3D(0,0.13636399805545807,0.7272729873657227),new Vec3D(0.40727299451828003,0.13636399805545807,0.7272729873657227),new Vec3D(0.7272729873657227,0.13636399805545807,0.40727299451828003),new Vec3D(0.7272729873657227,0.13636399805545807,0),new Vec3D(0,0.13636399805545807,0.9090909957885742),new Vec3D(0.5090910196304321,0.13636399805545807,0.9090909957885742),new Vec3D(0.9090909957885742,0.13636399805545807,0.5090910196304321),new Vec3D(0.9090909957885742,0.13636399805545807,0)),
    new Array(new Vec3D(0.9090909957885742,0.13636399805545807,0),new Vec3D(0.9090909957885742,0.13636399805545807,-0.5090910196304321),new Vec3D(0.5090910196304321,0.13636399805545807,-0.9090909957885742),new Vec3D(0,0.13636399805545807,-0.9090909957885742),new Vec3D(1,0.13636399805545807,0),new Vec3D(1,0.13636399805545807,-0.5600000023841858),new Vec3D(0.5600000023841858,0.13636399805545807,-1),new Vec3D(0,0.13636399805545807,-1),new Vec3D(1,0.09090910106897354,0),new Vec3D(1,0.09090910106897354,-0.5600000023841858),new Vec3D(0.5600000023841858,0.09090910106897354,-1),new Vec3D(0,0.09090910106897354,-1),new Vec3D(0.9090909957885742,0.09090910106897354,0),new Vec3D(0.9090909957885742,0.09090910106897354,-0.5090910196304321),new Vec3D(0.5090910196304321,0.09090910106897354,-0.9090909957885742),new Vec3D(0,0.09090910106897354,-0.9090909957885742)),
    new Array(new Vec3D(0,0.13636399805545807,-0.9090909957885742),new Vec3D(-0.5090910196304321,0.13636399805545807,-0.9090909957885742),new Vec3D(-0.9090909957885742,0.13636399805545807,-0.5090910196304321),new Vec3D(-0.9090909957885742,0.13636399805545807,0),new Vec3D(0,0.13636399805545807,-1),new Vec3D(-0.5600000023841858,0.13636399805545807,-1),new Vec3D(-1,0.13636399805545807,-0.5600000023841858),new Vec3D(-1,0.13636399805545807,0),new Vec3D(0,0.09090910106897354,-1),new Vec3D(-0.5600000023841858,0.09090910106897354,-1),new Vec3D(-1,0.09090910106897354,-0.5600000023841858),new Vec3D(-1,0.09090910106897354,0),new Vec3D(0,0.09090910106897354,-0.9090909957885742),new Vec3D(-0.5090910196304321,0.09090910106897354,-0.9090909957885742),new Vec3D(-0.9090909957885742,0.09090910106897354,-0.5090910196304321),new Vec3D(-0.9090909957885742,0.09090910106897354,0)),
    new Array(new Vec3D(-0.9090909957885742,0.13636399805545807,0),new Vec3D(-0.9090909957885742,0.13636399805545807,0.5090910196304321),new Vec3D(-0.5090910196304321,0.13636399805545807,0.9090909957885742),new Vec3D(0,0.13636399805545807,0.9090909957885742),new Vec3D(-1,0.13636399805545807,0),new Vec3D(-1,0.13636399805545807,0.5600000023841858),new Vec3D(-0.5600000023841858,0.13636399805545807,1),new Vec3D(0,0.13636399805545807,1),new Vec3D(-1,0.09090910106897354,0),new Vec3D(-1,0.09090910106897354,0.5600000023841858),new Vec3D(-0.5600000023841858,0.09090910106897354,1),new Vec3D(0,0.09090910106897354,1),new Vec3D(-0.9090909957885742,0.09090910106897354,0),new Vec3D(-0.9090909957885742,0.09090910106897354,0.5090910196304321),new Vec3D(-0.5090910196304321,0.09090910106897354,0.9090909957885742),new Vec3D(0,0.09090910106897354,0.9090909957885742)),
    new Array(new Vec3D(0,0.13636399805545807,0.9090909957885742),new Vec3D(0.5090910196304321,0.13636399805545807,0.9090909957885742),new Vec3D(0.9090909957885742,0.13636399805545807,0.5090910196304321),new Vec3D(0.9090909957885742,0.13636399805545807,0),new Vec3D(0,0.13636399805545807,1),new Vec3D(0.5600000023841858,0.13636399805545807,1),new Vec3D(1,0.13636399805545807,0.5600000023841858),new Vec3D(1,0.13636399805545807,0),new Vec3D(0,0.09090910106897354,1),new Vec3D(0.5600000023841858,0.09090910106897354,1),new Vec3D(1,0.09090910106897354,0.5600000023841858),new Vec3D(1,0.09090910106897354,0),new Vec3D(0,0.09090910106897354,0.9090909957885742),new Vec3D(0.5090910196304321,0.09090910106897354,0.9090909957885742),new Vec3D(0.9090909957885742,0.09090910106897354,0.5090910196304321),new Vec3D(0.9090909957885742,0.09090910106897354,0)),
    new Array(new Vec3D(0.9090909957885742,0.09090910106897354,0),new Vec3D(0.9090909957885742,0.09090910106897354,-0.5090910196304321),new Vec3D(0.5090910196304321,0.09090910106897354,-0.9090909957885742),new Vec3D(0,0.09090910106897354,-0.9090909957885742),new Vec3D(0.7272729873657227,0.09090910106897354,0),new Vec3D(0.7272729873657227,0.09090910106897354,-0.40727299451828003),new Vec3D(0.40727299451828003,0.09090910106897354,-0.7272729873657227),new Vec3D(0,0.09090910106897354,-0.7272729873657227),new Vec3D(0.5454549789428711,0,0),new Vec3D(0.5454549789428711,0,-0.3054549992084503),new Vec3D(0.3054549992084503,0,-0.5454549789428711),new Vec3D(0,0,-0.5454549789428711),new Vec3D(0.31818199157714844,0,0),new Vec3D(0.31818199157714844,0,-0.17818200588226318),new Vec3D(0.17818200588226318,0,-0.31818199157714844),new Vec3D(0,0,-0.31818199157714844)),
    new Array(new Vec3D(0,0.09090910106897354,-0.9090909957885742),new Vec3D(-0.5090910196304321,0.09090910106897354,-0.9090909957885742),new Vec3D(-0.9090909957885742,0.09090910106897354,-0.5090910196304321),new Vec3D(-0.9090909957885742,0.09090910106897354,0),new Vec3D(0,0.09090910106897354,-0.7272729873657227),new Vec3D(-0.40727299451828003,0.09090910106897354,-0.7272729873657227),new Vec3D(-0.7272729873657227,0.09090910106897354,-0.40727299451828003),new Vec3D(-0.7272729873657227,0.09090910106897354,0),new Vec3D(0,0,-0.5454549789428711),new Vec3D(-0.3054549992084503,0,-0.5454549789428711),new Vec3D(-0.5454549789428711,0,-0.3054549992084503),new Vec3D(-0.5454549789428711,0,0),new Vec3D(0,0,-0.31818199157714844),new Vec3D(-0.17818200588226318,0,-0.31818199157714844),new Vec3D(-0.31818199157714844,0,-0.17818200588226318),new Vec3D(-0.31818199157714844,0,0)),
    new Array(new Vec3D(-0.9090909957885742,0.09090910106897354,0),new Vec3D(-0.9090909957885742,0.09090910106897354,0.5090910196304321),new Vec3D(-0.5090910196304321,0.09090910106897354,0.9090909957885742),new Vec3D(0,0.09090910106897354,0.9090909957885742),new Vec3D(-0.7272729873657227,0.09090910106897354,0),new Vec3D(-0.7272729873657227,0.09090910106897354,0.40727299451828003),new Vec3D(-0.40727299451828003,0.09090910106897354,0.7272729873657227),new Vec3D(0,0.09090910106897354,0.7272729873657227),new Vec3D(-0.5454549789428711,0,0),new Vec3D(-0.5454549789428711,0,0.3054549992084503),new Vec3D(-0.3054549992084503,0,0.5454549789428711),new Vec3D(0,0,0.5454549789428711),new Vec3D(-0.31818199157714844,0,0),new Vec3D(-0.31818199157714844,0,0.17818200588226318),new Vec3D(-0.17818200588226318,0,0.31818199157714844),new Vec3D(0,0,0.31818199157714844)),
    new Array(new Vec3D(0,0.09090910106897354,0.9090909957885742),new Vec3D(0.5090910196304321,0.09090910106897354,0.9090909957885742),new Vec3D(0.9090909957885742,0.09090910106897354,0.5090910196304321),new Vec3D(0.9090909957885742,0.09090910106897354,0),new Vec3D(0,0.09090910106897354,0.7272729873657227),new Vec3D(0.40727299451828003,0.09090910106897354,0.7272729873657227),new Vec3D(0.7272729873657227,0.09090910106897354,0.40727299451828003),new Vec3D(0.7272729873657227,0.09090910106897354,0),new Vec3D(0,0,0.5454549789428711),new Vec3D(0.3054549992084503,0,0.5454549789428711),new Vec3D(0.5454549789428711,0,0.3054549992084503),new Vec3D(0.5454549789428711,0,0),new Vec3D(0,0,0.31818199157714844),new Vec3D(0.17818200588226318,0,0.31818199157714844),new Vec3D(0.31818199157714844,0,0.17818200588226318),new Vec3D(0.31818199157714844,0,0))
);

function B3(i, t){
    switch(i){
    case 0:
        return Math.pow((1-t), 3);
    case 1:
        return 3*Math.pow((1-t), 2)*t;
    case 2:
        return 3*(1-t)*Math.pow(t, 2);
    case 3:
        return Math.pow(t, 3);
    }
}

function getBezierPoint(u, v, patchPointArray)
{
    if(patchPointArray.length != 16){
        return false;
    }

    var x = 0;
    var y = 0;
    var z = 0;

    for(i = 0; i < 4; ++i){
        for(j = 0; j < 4; ++j){
            var p = patchPointArray[i+j*4];
            x += B3(i, u)*B3(j, v)*p.x;
            y += B3(i, u)*B3(j, v)*p.y;
            z += B3(i, u)*B3(j, v)*p.z;
        }
    }

    return (new Vec3D(x, y, z));
}


function drawSquare(core, p1, p2, p3, p4)
{
    var p = new Array();
    p.push(p1);
    p.push(p2);
    p.push(p3);
    core.addPolygon( p.length, true, p );

    var p = new Array();
    p.push(p4);
    p.push(p3);
    p.push(p2);
    core.addPolygon( p.length, true, p );
}

function buildUI(obj)
{
    obj.addParameterInt('BezierPatchDivision',6,1,1000,true,true);
    obj.setParameter("name", "TeaCup");

    //var rot = new Vec3D(0, 270, 0);
    //obj.setParameter("rotation", rot, true);

    // print param
    /*
    print('-- object type:'+obj.type());
    var info = obj.parameterInfo();
    for (var j=0;j<info.length;j++) {
        print(info[j][0] +" [" + info[j][1] + "]:"+obj.getParameter(info[j][0]));
    }
    */

}

function buildObject(obj){

    // Draw
    var core = obj.core();
    var div = obj.getParameter("BezierPatchDivision");
    var add = 1/div;
    var xnum = div+1;

    for(k = 0; k < bezierPatch.length; ++k){

        // compute bezier patch point
        var pa = bezierPatch[k];
        var drawPointArray = new Array();

        for(v = 0, vc = 0; v <= 1 || vc < xnum; v += add, ++vc){
            for(u = 0, uc = 0 ;u <= 1 || uc < xnum; u += add, ++uc){
                var p = getBezierPoint(u, v, pa);
                drawPointArray.push(p);
            }
        }
        //print("drawPointArray:"+drawPointArray.length);

        // draw polygon
        for(y = 0; y < div; ++y){
            for(x = 0; x < div; ++x){
                var p1 = x+y*xnum;
                var p2 = x+1+y*xnum;
                var p3 = x+(y+1)*xnum;
                var p4 = x+1+(y+1)*xnum;
                //print("x:"+x+" y:"+y+" p1:"+p1+" p2:"+p2+" p3:"+p3+" p4:"+p4);
                drawSquare(core, drawPointArray[p1], drawPointArray[p2], drawPointArray[p3], drawPointArray[p4]);
            }
        }
    }

}