scale_factor = 5.0

gs.plus.create_workers()
gs.LoadPlugins(gs.get_default_plugins_path())

render.init(1280, 720, "../pkg.core")

scn = scene.new_scene()
cam = scene.add_camera(scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, 3.5, -12.5)))
cam.GetTransform().SetRotation(gs.Vector3(pi * 5.0 / 180.0, pi * -5.0 / 180.0, 0))

scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.65, -0.45, 0)), gs.Light.Model_Linear, 150)
scene.add_light(
    scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.55, pi, 0.2)), gs.Light.Model_Linear, diffuse=gs.Color(0.3, 0.3, 0.4)
)
scene.add_physic_plane(scn)

# nodes = add_kapla_tower(scn, 0.5, 2, 2, 6, 16)

width, height, length = 1, 1, 1

node_list = []
stream_list = []


def make_solid_pos(x, y):
    return gs.Vector3(x * 1.15, y + height * 0.5, cos(x * y + x) * 0.15)


cube_masks = [[0, 0, 1, 0], [0, 1, 1, 0], [1, 1, 1, 1]]
render.init(1280, 720, "../pkg.core")

scn = scene.new_scene()
cam = scene.add_camera(scn,
                       gs.Matrix4.TranslationMatrix(gs.Vector3(0, 3.5, -12.5)))
cam.GetTransform().SetRotation(
    gs.Vector3(pi * 5.0 / 180.0, pi * -5.0 / 180.0, 0))

scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.65, -0.45, 0)),
                gs.Light.Model_Linear, 150)
scene.add_light(scn,
                gs.Matrix4.RotationMatrix(gs.Vector3(0.55, pi, 0.2)),
                gs.Light.Model_Linear,
                diffuse=gs.Color(0.3, 0.3, 0.4))
scene.add_physic_plane(scn)

# nodes = add_kapla_tower(scn, 0.5, 2, 2, 6, 16)

width, height, length = 1, 1, 1

node_list = []
stream_list = []


def make_solid_pos(x, y):
    return gs.Vector3(x * 1.15, y + height * 0.5, cos(x * y + x) * 0.15)


cube_masks = [[0, 0, 1, 0], [0, 1, 1, 0], [1, 1, 1, 1]]
gs.plus.create_workers()
gs.LoadPlugins(gs.get_default_plugins_path())

render.init(1024, int(1024 * md_screen_h / md_screen_w), "../pkg.core")

scn = scene.new_scene()
scn.GetPhysicSystem().SetDefaultRigidBodyAxisLock(gs.LockZ + gs.LockRotX + gs.LockRotY)
scn.GetPhysicSystem().SetDebugVisuals(True)

cam = scene.add_camera(scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, 0.0, -md_screen_w * 1.15)))

screen = scene.add_plane(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(0,0,0), gs.Vector3(radians(-90),0,0)), width=md_screen_w, depth=md_screen_h)

scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.65, -0.45, 0)), gs.Light.Model_Linear, 150)
scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.55, pi, 0.2)), gs.Light.Model_Linear, diffuse=gs.Color(0.3, 0.3, 0.4))
ground = scene.add_physic_plane(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(0,-md_screen_h / 2,0), gs.Vector3(0,0,0)))


def enable_ground(flag):
	global ground, node_list
	ground[1].SetEnabled(flag)

	# if flag is False:
	# 	for _node in node_list:
	# 		if _node.GetComponent("RigidBody").GetIsSleeping():
	# 			print("Node is sleeping!")
	# 			_node.GetComponent("RigidBody").SetIsSleeping(False)
	# 			_node.GetComponent("RigidBody").ApplyLinearImpulse(gs.Vector3(0,-10,0))
	# 			_node.GetComponent("RigidBody").ApplyLinearForce(gs.Vector3(0,-10,0))