Exemple #1
0
def wireframe_json_to_segment_list(filename=None):
    segment_list = []

    if filename is not None and hg.GetFilesystem().Exists(filename):
        with open(hg.GetFilesystem().MapToAbsolute(filename), 'r') as fp:
            data = json.load(fp)

        # print(data)

        for _object in data:
            _object_dict = data[_object]['object']

            _object_name = _object_dict['object_name']
            print('Found an object, named \'%s\'' % _object_name)

            for _segment in _object_dict['segments']:
                for _vertex_as_array in _segment:
                    # print(_vertex_as_array)
                    segment_list.append(_vertex_as_array)
                    # _vertex = Vector3()

                if len(_object_dict['segments']) > 0:
                    segment_list.append(_object_dict['segments'][-1])

    print("found total " + str(len(segment_list)) + " segment(s).")
    return segment_list
Exemple #2
0
 def save_json_script(
         self,
         scene,
         output_filename="assets/scripts/clouds_parameters.json"):
     script_parameters = self.__getstate__()
     json_script = json.dumps(script_parameters, indent=4)
     return hg.GetFilesystem().StringToFile(output_filename, json_script)
 def load_parameters(self,
                     file_name="assets/scripts/water_reflection.json"):
     json_script = hg.GetFilesystem().FileToString(file_name)
     if json_script != "":
         script_parameters = json.loads(json_script)
         self.color = list_to_color(script_parameters["color"])
         self.reflect_level = script_parameters["reflect_level"]
Exemple #4
0
def get_sprite_seq_max_frame(filename_base, file_extension=".png"):
    n = 0
    while hg.GetFilesystem().Exists("@assets/" + filename_base + str(n) +
                                    file_extension):
        n += 1

    return n
Exemple #5
0
def save_json_matrix(pos: hg.Vector3, rot: hg.Vector3, output_filename):
    script_parameters = {
        "position": vec3_to_list(pos),
        "rotation": vec3_to_list_degrees(rot)
    }
    json_script = json.dumps(script_parameters, indent=4)
    return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #6
0
 def load_json_script(self, file_name="assets/scripts/sea_parameters.json"):
     json_script = hg.GetFilesystem().FileToString(file_name)
     if json_script != "":
         script_parameters = json.loads(json_script)
         self.horizon_N_color = list_to_color(
             script_parameters["horizon_N_color"])
         self.horizon_S_color = list_to_color(
             script_parameters["horizon_S_color"])
         self.zenith_color = list_to_color(
             script_parameters["zenith_color"])
         self.zenith_falloff = script_parameters["zenith_falloff"]
         self.tex_sky_N_intensity = script_parameters["tex_sky_N_intensity"]
         self.horizon_line_color = list_to_color(
             script_parameters["horizon_line_color"])
         self.sea_color = list_to_color(script_parameters["sea_color"])
         self.sea_scale = list_to_vec3(script_parameters["sea_scale"])
         self.sea_reflection = script_parameters["sea_reflection"]
         self.horizon_line_size = script_parameters["horizon_line_size"]
         self.sea_filtering = script_parameters["sea_filtering"]
         self.max_filter_samples = script_parameters["max_filter_samples"]
         self.filter_precision = script_parameters["filter_precision"]
         self.clouds_scale = list_to_vec3(script_parameters["clouds_scale"])
         self.clouds_altitude = script_parameters["clouds_altitude"]
         self.clouds_absorption = script_parameters["clouds_absorption"]
         self.reflect_offset = script_parameters["reflect_offset"]
         self.render_scene_reflection = script_parameters[
             "render_scene_reflection"]
Exemple #7
0
def load_json_matrix(file_name):
    json_script = hg.GetFilesystem().FileToString(file_name)
    if json_script != "":
        script_parameters = json.loads(json_script)
        pos = list_to_vec3(script_parameters["position"])
        rot = list_to_vec3_radians(script_parameters["rotation"])
        return pos, rot
    return None, None
 def save_parameters(self,
                     output_filename="assets/scripts/water_reflection.json"
                     ):
     script_parameters = {
         "color": color_to_list(self.color),
         "reflect_level": self.reflect_level
     }
     json_script = json.dumps(script_parameters, indent=4)
     return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #9
0
 def load_parameters(self, file_name="assets/scripts/post_render.json"):
     json_script = hg.GetFilesystem().FileToString(file_name)
     if json_script != "":
         script_parameters = json.loads(json_script)
         self.contrast = script_parameters["contrast"]
         self.contrast_threshold = script_parameters["contrast_threshold"]
         self.hue = script_parameters["hue"]
         self.saturation = script_parameters["saturation"]
         self.value = script_parameters["value"]
Exemple #10
0
def save_scene_parameters(output_filename="assets/scripts/scene_parameters.json"):
	environment = Main.scene.GetEnvironment()
	script_parameters = {"sunlight_color": color_to_list(Main.ligth_sun.GetLight().GetDiffuseColor()),
		"skylight_color": color_to_list(Main.ligth_sky.GetLight().GetDiffuseColor()),
		"ambient_color": color_to_list(environment.GetAmbientColor()),
		"ambient_intensity": environment.GetAmbientIntensity(), "render_clouds": Main.render_volumetric_clouds
						 }
	json_script = json.dumps(script_parameters, indent=4)
	return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #11
0
def init_scene(plus):
	Main.scene = plus.NewScene()
	Main.camera = plus.AddCamera(Main.scene, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 10, -10)))

	Main.camera.SetName("Camera")
	Main.camera.GetCamera().SetZNear(1.)
	Main.camera.GetCamera().SetZFar(40000)

	plus.LoadScene(Main.scene, "assets/aircraft/aircraft.scn")
	plus.LoadScene(Main.scene, "assets/ennemyaircraft/ennemy_aircraft.scn")
	plus.LoadScene(Main.scene, "assets/aircraft_carrier/aircraft_carrier.scn")
	plus.LoadScene(Main.scene, "assets/island/island.scn")
	plus.LoadScene(Main.scene, "assets/feed_backs/feed_backs.scn")

	init_lights(plus)

	while not Main.scene.IsReady():  # Wait until scene is ready
		#plus.UpdateScene(Main.scene, plus.UpdateClock())
		Main.scene.Commit()
		Main.scene.WaitCommit()

	#for i in range(256):
	#   plus.UpdateScene(Main.scene, plus.UpdateClock())
	#	Main.scene.Commit()
	#	Main.scene.WaitCommit()

	Main.satellite_camera = plus.AddCamera(Main.scene, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1000, 0)))
	setup_satellite_camera(Main.satellite_camera)

	# ---- Clouds:
	json_script = hg.GetFilesystem().FileToString("assets/scripts/clouds_parameters.json")
	if json_script != "":
		clouds_parameters = json.loads(json_script)
		Main.clouds = Clouds(plus, Main.scene, Main.scene.GetNode("Sun"), Main.resolution, clouds_parameters)

	Main.island = Main.scene.GetNode("island")
	Main.island.GetTransform().SetPosition(hg.Vector3(0, 0, 3000))
	Main.island.GetTransform().SetRotation(hg.Vector3(0, 0, 0))

	Main.sea_render_script = hg.RenderScript("assets/lua_scripts/sea_render.lua")
	Main.sea_render_script.SetEnabled(False)
	Main.sea_render = SeaRender(plus, Main.scene, Main.sea_render_script)
	Main.sea_render.load_json_script()

	Main.sea_render.update_render_script(Main.scene, Main.resolution, hg.time_to_sec_f(plus.GetClock()))
	Main.scene.AddComponent(Main.sea_render_script)

	Main.water_reflection = WaterReflection(plus, Main.scene, Main.resolution, Main.resolution.x / 4)

	#Main.clouds_render_script=hg.LogicScript("assets/lua_scripts/clouds_render.lua")
	#Main.scene.AddComponent(Main.clouds_render_script)

	#plus.UpdateScene(Main.scene)
	Main.scene.Commit()
	Main.scene.WaitCommit()
	load_scene_parameters()
Exemple #12
0
def load_scene_parameters(file_name="assets/scripts/scene_parameters.json"):
	json_script = hg.GetFilesystem().FileToString(file_name)
	environment = Main.scene.GetEnvironment()
	if json_script != "":
		script_parameters = json.loads(json_script)
		Main.ligth_sun.GetLight().SetDiffuseColor(list_to_color(script_parameters["sunlight_color"]))
		Main.ligth_sky.GetLight().SetDiffuseColor(list_to_color(script_parameters["skylight_color"]))
		environment.SetAmbientColor(list_to_color(script_parameters["ambient_color"]))
		environment.SetAmbientIntensity(script_parameters["ambient_intensity"])
		Main.render_volumetric_clouds = script_parameters["render_clouds"]
Exemple #13
0
def load_game_parameters(file_name="assets/scripts/dogfight.json"):
	json_script = hg.GetFilesystem().FileToString(file_name)
	if json_script != "":
		script_parameters = json.loads(json_script)
		set_p1_missiles_smoke_color(list_to_color(script_parameters["p1_missiles_smoke_color"]))
		set_p2_missiles_smoke_color(list_to_color(script_parameters["p2_missiles_smoke_color"]))
		set_p1_gun_color(list_to_color(script_parameters["p1_gun_color"]))
		set_p2_gun_color(list_to_color(script_parameters["p2_gun_color"]))
		Main.radial_blur_strength=script_parameters["radial_blur_strength"]
		Main.deceleration_blur_strength=script_parameters["deceleration_blur_strength"]
		Main.acceleration_blur_strength=script_parameters["acceleration_blur_strength"]
Exemple #14
0
def save_game_parameters(output_filename="assets/scripts/dogfight.json"):
	script_parameters = {"p1_missiles_smoke_color": color_to_list(Main.p1_missiles_smoke_color),
		"p2_missiles_smoke_color": color_to_list(Main.p2_missiles_smoke_color),
		"p1_gun_color": color_to_list(Main.bullets.colors[0]),
		"p2_gun_color": color_to_list(Main.ennemy_bullets.colors[0]),
		"radial_blur_strength": Main.radial_blur_strength,
		"deceleration_blur_strength": Main.deceleration_blur_strength,
		"acceleration_blur_strength": Main.acceleration_blur_strength
						 }
	json_script = json.dumps(script_parameters, indent=4)
	return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #15
0
 def save_parameters(self,
                     output_filename="assets/scripts/post_render.json"):
     script_parameters = {
         "contrast": self.contrast,
         "contrast_threshold": self.contrast_threshold,
         "hue": self.hue,
         "saturation": self.saturation,
         "value": self.value
     }
     json_script = json.dumps(script_parameters, indent=4)
     return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #16
0
def post_processes_save_parameters(output_filename="assets/scripts/post_render.json"):
	script_parameters = {"hue": Main.HSL_postProcess.GetH(),
						 "saturation": Main.HSL_postProcess.GetS(),
						 "value":Main.HSL_postProcess.GetL(),
						 "flag_MotionBlur":Main.flag_MotionBlur,
						 "mb_blur_radius":Main.MotionBlur_postProcess.GetBlurRadius(),
						 "mb_exposure":Main.MotionBlur_postProcess.GetExposure(),
						 "mb_sample_count":Main.MotionBlur_postProcess.GetSampleCount()
						 }
	json_script = json.dumps(script_parameters, indent=4)
	return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #17
0
def save_json_matrix(pos: hg.Vector3,
                     rot: hg.Vector3,
                     output_filename="assets/scripts/camera_positions.json"):
    script_parameters = {
        "x": pos.x,
        "y": pos.y,
        "z": pos.z,
        "rot_x": rot.x,
        "rot_y": rot.y,
        "rot_z": rot.z
    }
    json_script = json.dumps(script_parameters, indent=4)
    return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #18
0
def load_json_matrix(file_name="assets/scripts/camera_positions.json"):
    json_script = hg.GetFilesystem().FileToString(file_name)
    if json_script != "":
        pos = hg.Vector3()
        rot = hg.Vector3()
        script_parameters = json.loads(json_script)
        pos.x = script_parameters["x"]
        pos.y = script_parameters["y"]
        pos.z = script_parameters["z"]
        rot.x = script_parameters["rot_x"]
        rot.y = script_parameters["rot_y"]
        rot.z = script_parameters["rot_z"]
        return pos, rot
    return None, None
Exemple #19
0
def post_processes_load_parameters(file_name="assets/scripts/post_render.json"):
	json_script = hg.GetFilesystem().FileToString(file_name)
	if json_script != "":
		script_parameters = json.loads(json_script)
		Main.HSL_postProcess.SetH(script_parameters["hue"])
		Main.HSL_postProcess.SetS(script_parameters["saturation"])
		Main.HSL_postProcess.SetL(script_parameters["value"])

		Main.flag_MotionBlur=script_parameters["flag_MotionBlur"]
		Main.MotionBlur_postProcess.SetBlurRadius(script_parameters["mb_blur_radius"])
		Main.MotionBlur_postProcess.SetExposure(script_parameters["mb_exposure"])
		Main.MotionBlur_postProcess.SetSampleCount(int(script_parameters["mb_sample_count"]))

		Main.camera.RemoveComponent(Main.MotionBlur_postProcess)
		if Main.flag_MotionBlur:
			Main.camera.AddComponent(Main.MotionBlur_postProcess)
Exemple #20
0
 def save_json_script(
         self, output_filename="assets/scripts/terrain_parameters.json"):
     script_parameters = {
         "map1_scale_x": self.facteur_echelle_terrain_l1.x,
         "map1_scale_y": self.facteur_echelle_terrain_l1.y,
         "map2_scale_x": self.facteur_echelle_terrain_l2.x,
         "map2_scale_y": self.facteur_echelle_terrain_l2.y,
         "map3_scale_x": self.facteur_echelle_terrain_l3.x,
         "map3_scale_y": self.facteur_echelle_terrain_l3.y,
         "map1_amplitude": self.amplitude_l1,
         "map2_amplitude": self.amplitude_l2,
         "map3_amplitude": self.amplitude_l3,
         "distance_factor": self.facteur_precision_distance,
         "water_altitude": self.altitude_eau,
         "water_reflexion": self.reflexion_eau,
         "offset_x": self.offset_terrain.x,
         "offset_y": self.offset_terrain.y,
         "offset_z": self.offset_terrain.z
     }
     json_script = json.dumps(script_parameters, indent=4)
     return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #21
0
 def load_json_script(self,
                      file_name="assets/scripts/terrain_parameters.json"):
     json_script = hg.GetFilesystem().FileToString(file_name)
     if json_script != "":
         script_parameters = json.loads(json_script)
         self.facteur_echelle_terrain_l1 = hg.Vector2(
             script_parameters["map1_scale_x"],
             script_parameters["map1_scale_y"])
         self.facteur_echelle_terrain_l2 = hg.Vector2(
             script_parameters["map2_scale_x"],
             script_parameters["map2_scale_y"])
         self.facteur_echelle_terrain_l3 = hg.Vector2(
             script_parameters["map3_scale_x"],
             script_parameters["map3_scale_y"])
         self.amplitude_l1 = script_parameters["map1_amplitude"]
         self.amplitude_l2 = script_parameters["map2_amplitude"]
         self.amplitude_l3 = script_parameters["map3_amplitude"]
         self.facteur_precision_distance = script_parameters[
             "distance_factor"]
         self.altitude_eau = script_parameters["water_altitude"]
         self.reflexion_eau = script_parameters["water_reflexion"]
         self.offset_terrain.x = script_parameters["offset_x"]
         self.offset_terrain.y = script_parameters["offset_y"]
         self.offset_terrain.z = script_parameters["offset_z"]
Exemple #22
0
 def save_json_script(self,
                      output_filename="assets/scripts/sea_parameters.json"):
     script_parameters = {
         "horizon_N_color": color_to_list(self.horizon_N_color),
         "horizon_S_color": color_to_list(self.horizon_S_color),
         "horizon_line_color": color_to_list(self.horizon_line_color),
         "zenith_color": color_to_list(self.zenith_color),
         "zenith_falloff": self.zenith_falloff,
         "tex_sky_N_intensity": self.tex_sky_N_intensity,
         "sea_color": color_to_list(self.sea_color),
         "sea_reflection": self.sea_reflection,
         "horizon_line_size": self.horizon_line_size,
         "sea_scale": vec3_to_list(self.sea_scale),
         "sea_filtering": self.sea_filtering,
         "max_filter_samples": self.max_filter_samples,
         "filter_precision": self.filter_precision,
         "clouds_scale": vec3_to_list(self.clouds_scale),
         "clouds_altitude": self.clouds_altitude,
         "clouds_absorption": self.clouds_absorption,
         "reflect_offset": self.reflect_offset,
         "render_scene_reflection": self.render_scene_reflection
     }
     json_script = json.dumps(script_parameters, indent=4)
     return hg.GetFilesystem().StringToFile(output_filename, json_script)
Exemple #23
0
import os
import harfang as hg

# mount a standard file system as the 'std:' prefix
hg.MountFileDriver(hg.StdFileDriver(), "std:")

# mount a standard file system pointing to the current directory as the 'cwd:' prefix
hg.MountFileDriver(hg.StdFileDriver(os.path.dirname(__file__)), "cwd:")

# get the full path to this file
this_file_path = os.path.realpath(__file__)

# get this file name (ie. path relative to the current directory)
this_file_name = os.path.basename(__file__)

# the engine can access it relative to the current directory through the 'cwd:' mount point
cwd_path = "cwd:" + this_file_name
res_cwd_access = hg.GetFilesystem().Exists(cwd_path)

# and it can access it using its absolute path through the std: mount point
std_path = "std:" + this_file_path
res_std_access = hg.GetFilesystem().Exists(std_path)

# however, when no prefix is specified the engine has no way to access it from its absolute path
res_direct_access = hg.GetFilesystem().Exists(this_file_path)

print("Can access '%s' (expect KO): %s" % (this_file_path, str(res_direct_access)))
print("Can access '%s' (expect OK): %s" % (cwd_path, str(res_cwd_access)))
print("Can access '%s' (expect OK): %s" % (std_path, str(res_std_access)))
Exemple #24
0
# Access to the file system

import os
import harfang as hg

# mount the system file driver, StdFileDriver wraps the system native file API
hg.MountFileDriver(hg.StdFileDriver())

# test that we indeed have access to the file system
path = os.path.realpath(
    __file__)  # absolute path to this file on the file system
result = hg.GetFilesystem().Exists(path)  # can the engine file system see it?

print("Access OK: %s" % str(result))
Exemple #25
0
# Convert from any supported audio file format to a PCM file

import harfang as hg
import os

hg.LoadPlugins()

hg.MountFileDriver(hg.StdFileDriver())

# open input file as an audio data source
src = hg.GetAudioIO().Open('_data/skaven.it')

# open output file
out = hg.GetFilesystem().Open('skaven.pcm', hg.FileWrite)

pcm = hg.BinaryData()

while src.GetState() != hg.AudioDataEnded:
    # get PCM frame to the binary blob
    size, timestamp = src.GetFrame(pcm)
    # output PCM frame to the file handle
    out.Write(pcm)
    # reset the binary blob, do not free storage
    pcm.Reset()

# - or - extract all PCM data to a huge binary blob and save it to file (consumes much more memory)
"""
# extract all PCM data from the source as a binary blob
sze = hg.ExtractAudioData(src, pcm)

# save the complete PCM binary blob to a file
Exemple #26
0
# Access to a file inside a Zip archive

import harfang as hg

archive_path = "_data/hello.zip"

# mount a std file driver to access the archive
hg.MountFileDriver(hg.StdFileDriver())

# mount a Zip file driver connected to the archive on the prefix "zip:"
file = hg.GetFilesystem().Open(archive_path, hg.FileRead)
hg.MountFileDriver(hg.ZipFileDriver(file), "zip:")

# assert that we can find a file named "hello.txt" on the "zip:" prefix
# ie. inside the archive connected to the ZipFileDriver "zip:" resolves to
res = hg.GetFilesystem().Exists("zip:hello.txt")

print("Can access 'hello.txt' (expect OK): %s" % str(res))
Exemple #27
0
# Sand-boxed access to the file system

import os
import harfang as hg

# mount two std file driver under two different prefixes, only one acts as a sandbox
hg.MountFileDriver(hg.StdFileDriver(os.path.dirname(__file__)), "std:")
hg.MountFileDriver(hg.StdFileDriver(os.path.dirname(__file__), True), "box:")

# access the readme.txt file outside of the std file driver root directory:
std_path = "std:../_data/owl.jpg"
res_std_access = hg.GetFilesystem().Exists(std_path)

# do the same on the sandboxed box: mount point
box_path = "box:../_data/owl.jpg"
res_box_access = hg.GetFilesystem().Exists(box_path)

print("Can access '%s' (expect OK): %s" % (std_path, str(res_std_access)))
print("Can access '%s' (expect KO): %s" % (box_path, str(res_box_access)))
Exemple #28
0
 def load_json_script(self,
                      file_name="assets/scripts/clouds_parameters.json"):
     json_script = hg.GetFilesystem().FileToString(file_name)
     if json_script != "":
         script_parameters = json.loads(json_script)
         self.__setstate__(script_parameters)