var bezierPatch = new Array(
    new Array(new Vec3D(1.399999976158142,0,2.4000000953674316),new Vec3D(1.399999976158142,-0.7839999794960022,2.4000000953674316),new Vec3D(0.7839999794960022,-1.399999976158142,2.4000000953674316),new Vec3D(0,-1.399999976158142,2.4000000953674316),new Vec3D(1.337499976158142,0,2.53125),new Vec3D(1.337499976158142,-0.7490000128746033,2.53125),new Vec3D(0.7490000128746033,-1.337499976158142,2.53125),new Vec3D(0,-1.337499976158142,2.53125),new Vec3D(1.4375,0,2.53125),new Vec3D(1.4375,-0.8050000071525574,2.53125),new Vec3D(0.8050000071525574,-1.4375,2.53125),new Vec3D(0,-1.4375,2.53125),new Vec3D(1.5,0,2.4000000953674316),new Vec3D(1.5,-0.8399999737739563,2.4000000953674316),new Vec3D(0.8399999737739563,-1.5,2.4000000953674316),new Vec3D(0,-1.5,2.4000000953674316)),
    new Array(new Vec3D(0,-1.399999976158142,2.4000000953674316),new Vec3D(-0.7839999794960022,-1.399999976158142,2.4000000953674316),new Vec3D(-1.399999976158142,-0.7839999794960022,2.4000000953674316),new Vec3D(-1.399999976158142,0,2.4000000953674316),new Vec3D(0,-1.337499976158142,2.53125),new Vec3D(-0.7490000128746033,-1.337499976158142,2.53125),new Vec3D(-1.337499976158142,-0.7490000128746033,2.53125),new Vec3D(-1.337499976158142,0,2.53125),new Vec3D(0,-1.4375,2.53125),new Vec3D(-0.8050000071525574,-1.4375,2.53125),new Vec3D(-1.4375,-0.8050000071525574,2.53125),new Vec3D(-1.4375,0,2.53125),new Vec3D(0,-1.5,2.4000000953674316),new Vec3D(-0.8399999737739563,-1.5,2.4000000953674316),new Vec3D(-1.5,-0.8399999737739563,2.4000000953674316),new Vec3D(-1.5,0,2.4000000953674316)),
    new Array(new Vec3D(-1.399999976158142,0,2.4000000953674316),new Vec3D(-1.399999976158142,0.7839999794960022,2.4000000953674316),new Vec3D(-0.7839999794960022,1.399999976158142,2.4000000953674316),new Vec3D(0,1.399999976158142,2.4000000953674316),new Vec3D(-1.337499976158142,0,2.53125),new Vec3D(-1.337499976158142,0.7490000128746033,2.53125),new Vec3D(-0.7490000128746033,1.337499976158142,2.53125),new Vec3D(0,1.337499976158142,2.53125),new Vec3D(-1.4375,0,2.53125),new Vec3D(-1.4375,0.8050000071525574,2.53125),new Vec3D(-0.8050000071525574,1.4375,2.53125),new Vec3D(0,1.4375,2.53125),new Vec3D(-1.5,0,2.4000000953674316),new Vec3D(-1.5,0.8399999737739563,2.4000000953674316),new Vec3D(-0.8399999737739563,1.5,2.4000000953674316),new Vec3D(0,1.5,2.4000000953674316)),
    new Array(new Vec3D(0,1.399999976158142,2.4000000953674316),new Vec3D(0.7839999794960022,1.399999976158142,2.4000000953674316),new Vec3D(1.399999976158142,0.7839999794960022,2.4000000953674316),new Vec3D(1.399999976158142,0,2.4000000953674316),new Vec3D(0,1.337499976158142,2.53125),new Vec3D(0.7490000128746033,1.337499976158142,2.53125),new Vec3D(1.337499976158142,0.7490000128746033,2.53125),new Vec3D(1.337499976158142,0,2.53125),new Vec3D(0,1.4375,2.53125),new Vec3D(0.8050000071525574,1.4375,2.53125),new Vec3D(1.4375,0.8050000071525574,2.53125),new Vec3D(1.4375,0,2.53125),new Vec3D(0,1.5,2.4000000953674316),new Vec3D(0.8399999737739563,1.5,2.4000000953674316),new Vec3D(1.5,0.8399999737739563,2.4000000953674316),new Vec3D(1.5,0,2.4000000953674316)),
    new Array(new Vec3D(1.5,0,2.4000000953674316),new Vec3D(1.5,-0.8399999737739563,2.4000000953674316),new Vec3D(0.8399999737739563,-1.5,2.4000000953674316),new Vec3D(0,-1.5,2.4000000953674316),new Vec3D(1.75,0,1.875),new Vec3D(1.75,-0.9800000190734863,1.875),new Vec3D(0.9800000190734863,-1.75,1.875),new Vec3D(0,-1.75,1.875),new Vec3D(2,0,1.350000023841858),new Vec3D(2,-1.1200000047683716,1.350000023841858),new Vec3D(1.1200000047683716,-2,1.350000023841858),new Vec3D(0,-2,1.350000023841858),new Vec3D(2,0,0.8999999761581421),new Vec3D(2,-1.1200000047683716,0.8999999761581421),new Vec3D(1.1200000047683716,-2,0.8999999761581421),new Vec3D(0,-2,0.8999999761581421)),
    new Array(new Vec3D(0,-1.5,2.4000000953674316),new Vec3D(-0.8399999737739563,-1.5,2.4000000953674316),new Vec3D(-1.5,-0.8399999737739563,2.4000000953674316),new Vec3D(-1.5,0,2.4000000953674316),new Vec3D(0,-1.75,1.875),new Vec3D(-0.9800000190734863,-1.75,1.875),new Vec3D(-1.75,-0.9800000190734863,1.875),new Vec3D(-1.75,0,1.875),new Vec3D(0,-2,1.350000023841858),new Vec3D(-1.1200000047683716,-2,1.350000023841858),new Vec3D(-2,-1.1200000047683716,1.350000023841858),new Vec3D(-2,0,1.350000023841858),new Vec3D(0,-2,0.8999999761581421),new Vec3D(-1.1200000047683716,-2,0.8999999761581421),new Vec3D(-2,-1.1200000047683716,0.8999999761581421),new Vec3D(-2,0,0.8999999761581421)),
    new Array(new Vec3D(-1.5,0,2.4000000953674316),new Vec3D(-1.5,0.8399999737739563,2.4000000953674316),new Vec3D(-0.8399999737739563,1.5,2.4000000953674316),new Vec3D(0,1.5,2.4000000953674316),new Vec3D(-1.75,0,1.875),new Vec3D(-1.75,0.9800000190734863,1.875),new Vec3D(-0.9800000190734863,1.75,1.875),new Vec3D(0,1.75,1.875),new Vec3D(-2,0,1.350000023841858),new Vec3D(-2,1.1200000047683716,1.350000023841858),new Vec3D(-1.1200000047683716,2,1.350000023841858),new Vec3D(0,2,1.350000023841858),new Vec3D(-2,0,0.8999999761581421),new Vec3D(-2,1.1200000047683716,0.8999999761581421),new Vec3D(-1.1200000047683716,2,0.8999999761581421),new Vec3D(0,2,0.8999999761581421)),
    new Array(new Vec3D(0,1.5,2.4000000953674316),new Vec3D(0.8399999737739563,1.5,2.4000000953674316),new Vec3D(1.5,0.8399999737739563,2.4000000953674316),new Vec3D(1.5,0,2.4000000953674316),new Vec3D(0,1.75,1.875),new Vec3D(0.9800000190734863,1.75,1.875),new Vec3D(1.75,0.9800000190734863,1.875),new Vec3D(1.75,0,1.875),new Vec3D(0,2,1.350000023841858),new Vec3D(1.1200000047683716,2,1.350000023841858),new Vec3D(2,1.1200000047683716,1.350000023841858),new Vec3D(2,0,1.350000023841858),new Vec3D(0,2,0.8999999761581421),new Vec3D(1.1200000047683716,2,0.8999999761581421),new Vec3D(2,1.1200000047683716,0.8999999761581421),new Vec3D(2,0,0.8999999761581421)),
    new Array(new Vec3D(2,0,0.8999999761581421),new Vec3D(2,-1.1200000047683716,0.8999999761581421),new Vec3D(1.1200000047683716,-2,0.8999999761581421),new Vec3D(0,-2,0.8999999761581421),new Vec3D(2,0,0.44999998807907104),new Vec3D(2,-1.1200000047683716,0.44999998807907104),new Vec3D(1.1200000047683716,-2,0.44999998807907104),new Vec3D(0,-2,0.44999998807907104),new Vec3D(1.5,0,0.22499999403953552),new Vec3D(1.5,-0.8399999737739563,0.22499999403953552),new Vec3D(0.8399999737739563,-1.5,0.22499999403953552),new Vec3D(0,-1.5,0.22499999403953552),new Vec3D(1.5,0,0.15000000596046448),new Vec3D(1.5,-0.8399999737739563,0.15000000596046448),new Vec3D(0.8399999737739563,-1.5,0.15000000596046448),new Vec3D(0,-1.5,0.15000000596046448)),
    new Array(new Vec3D(0,-2,0.8999999761581421),new Vec3D(-1.1200000047683716,-2,0.8999999761581421),new Vec3D(-2,-1.1200000047683716,0.8999999761581421),new Vec3D(-2,0,0.8999999761581421),new Vec3D(0,-2,0.44999998807907104),new Vec3D(-1.1200000047683716,-2,0.44999998807907104),new Vec3D(-2,-1.1200000047683716,0.44999998807907104),new Vec3D(-2,0,0.44999998807907104),new Vec3D(0,-1.5,0.22499999403953552),new Vec3D(-0.8399999737739563,-1.5,0.22499999403953552),new Vec3D(-1.5,-0.8399999737739563,0.22499999403953552),new Vec3D(-1.5,0,0.22499999403953552),new Vec3D(0,-1.5,0.15000000596046448),new Vec3D(-0.8399999737739563,-1.5,0.15000000596046448),new Vec3D(-1.5,-0.8399999737739563,0.15000000596046448),new Vec3D(-1.5,0,0.15000000596046448)),
    new Array(new Vec3D(-2,0,0.8999999761581421),new Vec3D(-2,1.1200000047683716,0.8999999761581421),new Vec3D(-1.1200000047683716,2,0.8999999761581421),new Vec3D(0,2,0.8999999761581421),new Vec3D(-2,0,0.44999998807907104),new Vec3D(-2,1.1200000047683716,0.44999998807907104),new Vec3D(-1.1200000047683716,2,0.44999998807907104),new Vec3D(0,2,0.44999998807907104),new Vec3D(-1.5,0,0.22499999403953552),new Vec3D(-1.5,0.8399999737739563,0.22499999403953552),new Vec3D(-0.8399999737739563,1.5,0.22499999403953552),new Vec3D(0,1.5,0.22499999403953552),new Vec3D(-1.5,0,0.15000000596046448),new Vec3D(-1.5,0.8399999737739563,0.15000000596046448),new Vec3D(-0.8399999737739563,1.5,0.15000000596046448),new Vec3D(0,1.5,0.15000000596046448)),
    new Array(new Vec3D(0,2,0.8999999761581421),new Vec3D(1.1200000047683716,2,0.8999999761581421),new Vec3D(2,1.1200000047683716,0.8999999761581421),new Vec3D(2,0,0.8999999761581421),new Vec3D(0,2,0.44999998807907104),new Vec3D(1.1200000047683716,2,0.44999998807907104),new Vec3D(2,1.1200000047683716,0.44999998807907104),new Vec3D(2,0,0.44999998807907104),new Vec3D(0,1.5,0.22499999403953552),new Vec3D(0.8399999737739563,1.5,0.22499999403953552),new Vec3D(1.5,0.8399999737739563,0.22499999403953552),new Vec3D(1.5,0,0.22499999403953552),new Vec3D(0,1.5,0.15000000596046448),new Vec3D(0.8399999737739563,1.5,0.15000000596046448),new Vec3D(1.5,0.8399999737739563,0.15000000596046448),new Vec3D(1.5,0,0.15000000596046448)),
    new Array(new Vec3D(-1.600000023841858,0,2.0250000953674316),new Vec3D(-1.600000023841858,-0.30000001192092896,2.0250000953674316),new Vec3D(-1.5,-0.30000001192092896,2.25),new Vec3D(-1.5,0,2.25),new Vec3D(-2.299999952316284,0,2.0250000953674316),new Vec3D(-2.299999952316284,-0.30000001192092896,2.0250000953674316),new Vec3D(-2.5,-0.30000001192092896,2.25),new Vec3D(-2.5,0,2.25),new Vec3D(-2.700000047683716,0,2.0250000953674316),new Vec3D(-2.700000047683716,-0.30000001192092896,2.0250000953674316),new Vec3D(-3,-0.30000001192092896,2.25),new Vec3D(-3,0,2.25),new Vec3D(-2.700000047683716,0,1.7999999523162842),new Vec3D(-2.700000047683716,-0.30000001192092896,1.7999999523162842),new Vec3D(-3,-0.30000001192092896,1.7999999523162842),new Vec3D(-3,0,1.7999999523162842)),
    new Array(new Vec3D(-1.5,0,2.25),new Vec3D(-1.5,0.30000001192092896,2.25),new Vec3D(-1.600000023841858,0.30000001192092896,2.0250000953674316),new Vec3D(-1.600000023841858,0,2.0250000953674316),new Vec3D(-2.5,0,2.25),new Vec3D(-2.5,0.30000001192092896,2.25),new Vec3D(-2.299999952316284,0.30000001192092896,2.0250000953674316),new Vec3D(-2.299999952316284,0,2.0250000953674316),new Vec3D(-3,0,2.25),new Vec3D(-3,0.30000001192092896,2.25),new Vec3D(-2.700000047683716,0.30000001192092896,2.0250000953674316),new Vec3D(-2.700000047683716,0,2.0250000953674316),new Vec3D(-3,0,1.7999999523162842),new Vec3D(-3,0.30000001192092896,1.7999999523162842),new Vec3D(-2.700000047683716,0.30000001192092896,1.7999999523162842),new Vec3D(-2.700000047683716,0,1.7999999523162842)),
    new Array(new Vec3D(-2.700000047683716,0,1.7999999523162842),new Vec3D(-2.700000047683716,-0.30000001192092896,1.7999999523162842),new Vec3D(-3,-0.30000001192092896,1.7999999523162842),new Vec3D(-3,0,1.7999999523162842),new Vec3D(-2.700000047683716,0,1.5750000476837158),new Vec3D(-2.700000047683716,-0.30000001192092896,1.5750000476837158),new Vec3D(-3,-0.30000001192092896,1.350000023841858),new Vec3D(-3,0,1.350000023841858),new Vec3D(-2.5,0,1.125),new Vec3D(-2.5,-0.30000001192092896,1.125),new Vec3D(-2.6500000953674316,-0.30000001192092896,0.9375),new Vec3D(-2.6500000953674316,0,0.9375),new Vec3D(-2,0,0.8999999761581421),new Vec3D(-2,-0.30000001192092896,0.8999999761581421),new Vec3D(-1.899999976158142,-0.30000001192092896,0.6000000238418579),new Vec3D(-1.899999976158142,0,0.6000000238418579)),
    new Array(new Vec3D(-3,0,1.7999999523162842),new Vec3D(-3,0.30000001192092896,1.7999999523162842),new Vec3D(-2.700000047683716,0.30000001192092896,1.7999999523162842),new Vec3D(-2.700000047683716,0,1.7999999523162842),new Vec3D(-3,0,1.350000023841858),new Vec3D(-3,0.30000001192092896,1.350000023841858),new Vec3D(-2.700000047683716,0.30000001192092896,1.5750000476837158),new Vec3D(-2.700000047683716,0,1.5750000476837158),new Vec3D(-2.6500000953674316,0,0.9375),new Vec3D(-2.6500000953674316,0.30000001192092896,0.9375),new Vec3D(-2.5,0.30000001192092896,1.125),new Vec3D(-2.5,0,1.125),new Vec3D(-1.899999976158142,0,0.6000000238418579),new Vec3D(-1.899999976158142,0.30000001192092896,0.6000000238418579),new Vec3D(-2,0.30000001192092896,0.8999999761581421),new Vec3D(-2,0,0.8999999761581421)),
    new Array(new Vec3D(1.7000000476837158,0,1.4249999523162842),new Vec3D(1.7000000476837158,-0.6600000262260437,1.4249999523162842),new Vec3D(1.7000000476837158,-0.6600000262260437,0.6000000238418579),new Vec3D(1.7000000476837158,0,0.6000000238418579),new Vec3D(2.5999999046325684,0,1.4249999523162842),new Vec3D(2.5999999046325684,-0.6600000262260437,1.4249999523162842),new Vec3D(3.0999999046325684,-0.6600000262260437,0.824999988079071),new Vec3D(3.0999999046325684,0,0.824999988079071),new Vec3D(2.299999952316284,0,2.0999999046325684),new Vec3D(2.299999952316284,-0.25,2.0999999046325684),new Vec3D(2.4000000953674316,-0.25,2.0250000953674316),new Vec3D(2.4000000953674316,0,2.0250000953674316),new Vec3D(2.700000047683716,0,2.4000000953674316),new Vec3D(2.700000047683716,-0.25,2.4000000953674316),new Vec3D(3.299999952316284,-0.25,2.4000000953674316),new Vec3D(3.299999952316284,0,2.4000000953674316)),
    new Array(new Vec3D(1.7000000476837158,0,0.6000000238418579),new Vec3D(1.7000000476837158,0.6600000262260437,0.6000000238418579),new Vec3D(1.7000000476837158,0.6600000262260437,1.4249999523162842),new Vec3D(1.7000000476837158,0,1.4249999523162842),new Vec3D(3.0999999046325684,0,0.824999988079071),new Vec3D(3.0999999046325684,0.6600000262260437,0.824999988079071),new Vec3D(2.5999999046325684,0.6600000262260437,1.4249999523162842),new Vec3D(2.5999999046325684,0,1.4249999523162842),new Vec3D(2.4000000953674316,0,2.0250000953674316),new Vec3D(2.4000000953674316,0.25,2.0250000953674316),new Vec3D(2.299999952316284,0.25,2.0999999046325684),new Vec3D(2.299999952316284,0,2.0999999046325684),new Vec3D(3.299999952316284,0,2.4000000953674316),new Vec3D(3.299999952316284,0.25,2.4000000953674316),new Vec3D(2.700000047683716,0.25,2.4000000953674316),new Vec3D(2.700000047683716,0,2.4000000953674316)),
    new Array(new Vec3D(2.700000047683716,0,2.4000000953674316),new Vec3D(2.700000047683716,-0.25,2.4000000953674316),new Vec3D(3.299999952316284,-0.25,2.4000000953674316),new Vec3D(3.299999952316284,0,2.4000000953674316),new Vec3D(2.799999952316284,0,2.4749999046325684),new Vec3D(2.799999952316284,-0.25,2.4749999046325684),new Vec3D(3.5250000953674316,-0.25,2.4937500953674316),new Vec3D(3.5250000953674316,0,2.4937500953674316),new Vec3D(2.9000000953674316,0,2.4749999046325684),new Vec3D(2.9000000953674316,-0.15000000596046448,2.4749999046325684),new Vec3D(3.450000047683716,-0.15000000596046448,2.512500047683716),new Vec3D(3.450000047683716,0,2.512500047683716),new Vec3D(2.799999952316284,0,2.4000000953674316),new Vec3D(2.799999952316284,-0.15000000596046448,2.4000000953674316),new Vec3D(3.200000047683716,-0.15000000596046448,2.4000000953674316),new Vec3D(3.200000047683716,0,2.4000000953674316)),
    new Array(new Vec3D(3.299999952316284,0,2.4000000953674316),new Vec3D(3.299999952316284,0.25,2.4000000953674316),new Vec3D(2.700000047683716,0.25,2.4000000953674316),new Vec3D(2.700000047683716,0,2.4000000953674316),new Vec3D(3.5250000953674316,0,2.4937500953674316),new Vec3D(3.5250000953674316,0.25,2.4937500953674316),new Vec3D(2.799999952316284,0.25,2.4749999046325684),new Vec3D(2.799999952316284,0,2.4749999046325684),new Vec3D(3.450000047683716,0,2.512500047683716),new Vec3D(3.450000047683716,0.15000000596046448,2.512500047683716),new Vec3D(2.9000000953674316,0.15000000596046448,2.4749999046325684),new Vec3D(2.9000000953674316,0,2.4749999046325684),new Vec3D(3.200000047683716,0,2.4000000953674316),new Vec3D(3.200000047683716,0.15000000596046448,2.4000000953674316),new Vec3D(2.799999952316284,0.15000000596046448,2.4000000953674316),new Vec3D(2.799999952316284,0,2.4000000953674316)),
    new Array(new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0.800000011920929,0,3.1500000953674316),new Vec3D(0.800000011920929,-0.44999998807907104,3.1500000953674316),new Vec3D(0.44999998807907104,-0.800000011920929,3.1500000953674316),new Vec3D(0,-0.800000011920929,3.1500000953674316),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0.20000000298023224,0,2.700000047683716),new Vec3D(0.20000000298023224,-0.1120000034570694,2.700000047683716),new Vec3D(0.1120000034570694,-0.20000000298023224,2.700000047683716),new Vec3D(0,-0.20000000298023224,2.700000047683716)),
    new Array(new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,-0.800000011920929,3.1500000953674316),new Vec3D(-0.44999998807907104,-0.800000011920929,3.1500000953674316),new Vec3D(-0.800000011920929,-0.44999998807907104,3.1500000953674316),new Vec3D(-0.800000011920929,0,3.1500000953674316),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,-0.20000000298023224,2.700000047683716),new Vec3D(-0.1120000034570694,-0.20000000298023224,2.700000047683716),new Vec3D(-0.20000000298023224,-0.1120000034570694,2.700000047683716),new Vec3D(-0.20000000298023224,0,2.700000047683716)),
    new Array(new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(-0.800000011920929,0,3.1500000953674316),new Vec3D(-0.800000011920929,0.44999998807907104,3.1500000953674316),new Vec3D(-0.44999998807907104,0.800000011920929,3.1500000953674316),new Vec3D(0,0.800000011920929,3.1500000953674316),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(-0.20000000298023224,0,2.700000047683716),new Vec3D(-0.20000000298023224,0.1120000034570694,2.700000047683716),new Vec3D(-0.1120000034570694,0.20000000298023224,2.700000047683716),new Vec3D(0,0.20000000298023224,2.700000047683716)),
    new Array(new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0,3.1500000953674316),new Vec3D(0,0.800000011920929,3.1500000953674316),new Vec3D(0.44999998807907104,0.800000011920929,3.1500000953674316),new Vec3D(0.800000011920929,0.44999998807907104,3.1500000953674316),new Vec3D(0.800000011920929,0,3.1500000953674316),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0,2.8499999046325684),new Vec3D(0,0.20000000298023224,2.700000047683716),new Vec3D(0.1120000034570694,0.20000000298023224,2.700000047683716),new Vec3D(0.20000000298023224,0.1120000034570694,2.700000047683716),new Vec3D(0.20000000298023224,0,2.700000047683716)),
    new Array(new Vec3D(0.20000000298023224,0,2.700000047683716),new Vec3D(0.20000000298023224,-0.1120000034570694,2.700000047683716),new Vec3D(0.1120000034570694,-0.20000000298023224,2.700000047683716),new Vec3D(0,-0.20000000298023224,2.700000047683716),new Vec3D(0.4000000059604645,0,2.549999952316284),new Vec3D(0.4000000059604645,-0.2240000069141388,2.549999952316284),new Vec3D(0.2240000069141388,-0.4000000059604645,2.549999952316284),new Vec3D(0,-0.4000000059604645,2.549999952316284),new Vec3D(1.2999999523162842,0,2.549999952316284),new Vec3D(1.2999999523162842,-0.7279999852180481,2.549999952316284),new Vec3D(0.7279999852180481,-1.2999999523162842,2.549999952316284),new Vec3D(0,-1.2999999523162842,2.549999952316284),new Vec3D(1.2999999523162842,0,2.4000000953674316),new Vec3D(1.2999999523162842,-0.7279999852180481,2.4000000953674316),new Vec3D(0.7279999852180481,-1.2999999523162842,2.4000000953674316),new Vec3D(0,-1.2999999523162842,2.4000000953674316)),
    new Array(new Vec3D(0,-0.20000000298023224,2.700000047683716),new Vec3D(-0.1120000034570694,-0.20000000298023224,2.700000047683716),new Vec3D(-0.20000000298023224,-0.1120000034570694,2.700000047683716),new Vec3D(-0.20000000298023224,0,2.700000047683716),new Vec3D(0,-0.4000000059604645,2.549999952316284),new Vec3D(-0.2240000069141388,-0.4000000059604645,2.549999952316284),new Vec3D(-0.4000000059604645,-0.2240000069141388,2.549999952316284),new Vec3D(-0.4000000059604645,0,2.549999952316284),new Vec3D(0,-1.2999999523162842,2.549999952316284),new Vec3D(-0.7279999852180481,-1.2999999523162842,2.549999952316284),new Vec3D(-1.2999999523162842,-0.7279999852180481,2.549999952316284),new Vec3D(-1.2999999523162842,0,2.549999952316284),new Vec3D(0,-1.2999999523162842,2.4000000953674316),new Vec3D(-0.7279999852180481,-1.2999999523162842,2.4000000953674316),new Vec3D(-1.2999999523162842,-0.7279999852180481,2.4000000953674316),new Vec3D(-1.2999999523162842,0,2.4000000953674316)),
    new Array(new Vec3D(-0.20000000298023224,0,2.700000047683716),new Vec3D(-0.20000000298023224,0.1120000034570694,2.700000047683716),new Vec3D(-0.1120000034570694,0.20000000298023224,2.700000047683716),new Vec3D(0,0.20000000298023224,2.700000047683716),new Vec3D(-0.4000000059604645,0,2.549999952316284),new Vec3D(-0.4000000059604645,0.2240000069141388,2.549999952316284),new Vec3D(-0.2240000069141388,0.4000000059604645,2.549999952316284),new Vec3D(0,0.4000000059604645,2.549999952316284),new Vec3D(-1.2999999523162842,0,2.549999952316284),new Vec3D(-1.2999999523162842,0.7279999852180481,2.549999952316284),new Vec3D(-0.7279999852180481,1.2999999523162842,2.549999952316284),new Vec3D(0,1.2999999523162842,2.549999952316284),new Vec3D(-1.2999999523162842,0,2.4000000953674316),new Vec3D(-1.2999999523162842,0.7279999852180481,2.4000000953674316),new Vec3D(-0.7279999852180481,1.2999999523162842,2.4000000953674316),new Vec3D(0,1.2999999523162842,2.4000000953674316)),
    new Array(new Vec3D(0,0.20000000298023224,2.700000047683716),new Vec3D(0.1120000034570694,0.20000000298023224,2.700000047683716),new Vec3D(0.20000000298023224,0.1120000034570694,2.700000047683716),new Vec3D(0.20000000298023224,0,2.700000047683716),new Vec3D(0,0.4000000059604645,2.549999952316284),new Vec3D(0.2240000069141388,0.4000000059604645,2.549999952316284),new Vec3D(0.4000000059604645,0.2240000069141388,2.549999952316284),new Vec3D(0.4000000059604645,0,2.549999952316284),new Vec3D(0,1.2999999523162842,2.549999952316284),new Vec3D(0.7279999852180481,1.2999999523162842,2.549999952316284),new Vec3D(1.2999999523162842,0.7279999852180481,2.549999952316284),new Vec3D(1.2999999523162842,0,2.549999952316284),new Vec3D(0,1.2999999523162842,2.4000000953674316),new Vec3D(0.7279999852180481,1.2999999523162842,2.4000000953674316),new Vec3D(1.2999999523162842,0.7279999852180481,2.4000000953674316),new Vec3D(1.2999999523162842,0,2.4000000953674316)),
    new Array(new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(1.4249999523162842,0,0),new Vec3D(1.4249999523162842,0.7979999780654907,0),new Vec3D(0.7979999780654907,1.4249999523162842,0),new Vec3D(0,1.4249999523162842,0),new Vec3D(1.5,0,0.07500000298023224),new Vec3D(1.5,0.8399999737739563,0.07500000298023224),new Vec3D(0.8399999737739563,1.5,0.07500000298023224),new Vec3D(0,1.5,0.07500000298023224),new Vec3D(1.5,0,0.15000000596046448),new Vec3D(1.5,0.8399999737739563,0.15000000596046448),new Vec3D(0.8399999737739563,1.5,0.15000000596046448),new Vec3D(0,1.5,0.15000000596046448)),
    new Array(new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,1.4249999523162842,0),new Vec3D(-0.7979999780654907,1.4249999523162842,0),new Vec3D(-1.4249999523162842,0.7979999780654907,0),new Vec3D(-1.4249999523162842,0,0),new Vec3D(0,1.5,0.07500000298023224),new Vec3D(-0.8399999737739563,1.5,0.07500000298023224),new Vec3D(-1.5,0.8399999737739563,0.07500000298023224),new Vec3D(-1.5,0,0.07500000298023224),new Vec3D(0,1.5,0.15000000596046448),new Vec3D(-0.8399999737739563,1.5,0.15000000596046448),new Vec3D(-1.5,0.8399999737739563,0.15000000596046448),new Vec3D(-1.5,0,0.15000000596046448)),
    new Array(new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(-1.4249999523162842,0,0),new Vec3D(-1.4249999523162842,-0.7979999780654907,0),new Vec3D(-0.7979999780654907,-1.4249999523162842,0),new Vec3D(0,-1.4249999523162842,0),new Vec3D(-1.5,0,0.07500000298023224),new Vec3D(-1.5,-0.8399999737739563,0.07500000298023224),new Vec3D(-0.8399999737739563,-1.5,0.07500000298023224),new Vec3D(0,-1.5,0.07500000298023224),new Vec3D(-1.5,0,0.15000000596046448),new Vec3D(-1.5,-0.8399999737739563,0.15000000596046448),new Vec3D(-0.8399999737739563,-1.5,0.15000000596046448),new Vec3D(0,-1.5,0.15000000596046448)),
    new Array(new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,0,0),new Vec3D(0,-1.4249999523162842,0),new Vec3D(0.7979999780654907,-1.4249999523162842,0),new Vec3D(1.4249999523162842,-0.7979999780654907,0),new Vec3D(1.4249999523162842,0,0),new Vec3D(0,-1.5,0.07500000298023224),new Vec3D(0.8399999737739563,-1.5,0.07500000298023224),new Vec3D(1.5,-0.8399999737739563,0.07500000298023224),new Vec3D(1.5,0,0.07500000298023224),new Vec3D(0,-1.5,0.15000000596046448),new Vec3D(0.8399999737739563,-1.5,0.15000000596046448),new Vec3D(1.5,-0.8399999737739563,0.15000000596046448),new Vec3D(1.5,0,0.15000000596046448))
);

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(p3);
    p.push(p2);
    p.push(p1);
    core.addPolygon( p.length, true, p );

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

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

    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]);
            }
        }
    }

}