
local demo_dir = gh_utils.get_demo_dir()
local lib_dir = gh_utils.get_lib_dir() 		
dofile(lib_dir .. "lua/gx_cam_lib_v1.lua")
dofile(lib_dir .. "lua/libfont/libfont1.lua")   
dofile(lib_dir .. "lua/imgui.lua")    
dofile(lib_dir .. "lua/gxl.lua")    
dofile(lib_dir .. "lua/shaderlib.lua")    




winW, winH = gh_window.getsize(0)


keyboard_speed = 10.0
camera_fov = 60.0
camera_lookat_x = 0
camera_lookat_y = 0
camera_lookat_z = 0

camera = gx_camera.create_perspective(camera_fov, 1, 0, 0, winW, winH, 1, 1000)
gh_camera.set_position(camera, 0, 0, 50)
gx_camera.init_orientation(camera, camera_lookat_x, camera_lookat_y, camera_lookat_z, 30, 90)
gx_camera.set_mode_orbit()
--gx_camera.set_mode_fly()
gx_camera.set_orbit_lookat(camera, camera_lookat_x, camera_lookat_y, camera_lookat_z)
gh_camera.set_fov(camera, camera_fov)
gx_camera.set_keyboard_speed(keyboard_speed)







shaderlib.init()
vertex_color = shaderlib.getid("vertex_color")
phong_texture_prog = shaderlib.getid("phong_texture")
phong_prog = shaderlib.getid("phong")

--lighting_prog = gh_node.getid("lighting_prog")
--color_prog = gh_node.getid("color_prog")




local demo_dir = gh_utils.get_demo_dir()

--[[
local model_directory = demo_dir .. "/data/robo_obj_pose4/"
local resource_directory = demo_dir .. "/data/robo_obj_pose4/"
local gltf_file ="scene.gltf"
--]]

---[[
local model_directory = demo_dir .. "/data/jerrycan/"
local resource_directory = demo_dir .. "/data/jerrycan/"
local gltf_file ="scene.gltf"
--]]


num_loaded_textures = 0
num_vertices = 0
mesh0 = 0
mesh1 = 0
mesh2 = 0

--model = gh_model.create_from_file_loader_gltf(gltf_file, model_directory, resource_directory, "")
model = gh_model.create_from_file_loader_assimp_v2(gltf_file, model_directory, resource_directory, "aiProcessPreset_TargetRealtime_MaxQuality")
if (model > 0) then

  -- With some algorithms (shadow mapping for example), it can be useful
  -- to specify the texture unit starting offset (default is 0: the first texture unit
  -- will be 0).
  gh_object.set_materials_texture_unit_offset(model, 0)

  num_loaded_textures = gh_model.load_textures(model, resource_directory)


  gh_object.set_position(model, 0, 0, 0)
  gh_object.set_euler_angles(model, 0, 0, 0)

	num_vertices = gh_object.get_num_vertices_v2(model)

  -- mesh0 = gh_node.get_child_by_index(model, 0)
	-- num_vertices = gh_object.get_num_vertices(mesh0)

  -- mesh1 = gh_node.get_child_by_index(model, 1)
  -- mesh2 = gh_node.get_child_by_index(model, 2)

	--gh_object.compute_faces_normal(mesh0)
  --gh_object.compute_vertices_normal(mes0h)
	--gh_object.average_vertices_normal(mesh0, 0.01)


end







grid = gh_utils.grid_create()
gh_utils.grid_set_lines_color(grid, 0.7, 0.7, 0.7, 1.0)
gh_utils.grid_set_main_lines_color(grid, 1.0, 1.0, 0.0, 1.0)
gh_utils.grid_set_main_x_axis_color(grid, 1.0, 0.0, 0.0, 1.0)
gh_utils.grid_set_main_z_axis_color(grid, 0.0, 0.0, 1.0, 1.0)
local display_main_lines = 1
local display_lines = 1
gh_utils.grid_set_display_lines_options(grid, display_main_lines, display_lines)
gh_utils.grid_set_geometry_params(grid, 100, 100, 20, 20)





gh_renderer.set_vsync(1)

last_time = gh_utils.get_elapsed_time()


gl_renderer = gh_renderer.get_renderer_model()
gl_version = gh_renderer.get_api_version()
