# Face index
args = sys.argv
if len(args) < 4:
    iface = 0
else:
    iface = int(args[3]) - 1

strf = format(iface + 1, '03')

tolvis = 1.e-3
nrsvis = 32

#################################################
## Set Scene
scene = bpy.context.scene
lbu.clear_scene(meshes=True, lamps=True, cameras=False)

lbu.set_scene(resolution_x=800,
              resolution_y=800,
              resolution_percentage=100,
              alpha_mode='SKY',
              horizon_color=[1, 1, 1],
              light_samples=16,
              use_environment_light=True,
              environment_energy=0.3,
              environment_color='PLAIN')

## Set Lighting
lbu.add_point_light(name="lamp",
                    energy=1.2,
                    shadow_method='RAY_SHADOW',
ROOT = '/home/bastien/'#'/d/bandrieu/'#

import bpy
import numpy
from numpy.polynomial.chebyshev import chebval, chebgrid2d, chebval2d

import sys
sys.path.append(ROOT + 'GitHub/Code/Python/')
import lib_blender_util as lbu
import lib_blender_edit as lbe
import lib_cadcheb as lcad
import lib_chebyshev as lch


lbu.clear_scene(True, True, True)

cs = lch.read_polynomial2(ROOT+'GitHub/FFTsurf/test/coeffstest/C2_test10.txt')
m = 100
u = numpy.linspace(-1, 1, m)
xyz = chebgrid2d(u, u, cs)
v, f = lbu.tensor_product_mesh_vf(xyz[0], xyz[1], xyz[2])
surf = lbu.pydata_to_mesh(
    v,
    f,
    name='surface'
)
lbe.set_smooth(surf)

hmin = 1e-3
hmax = 1
tolchord = 1e-3