gameplay: walkable demo map, reset and pause
Tools/ue_build_demo_map.py builds /Game/Hollywood/DemoMap: sun, sky, the hero facade on the building line, six site meshes imported with collision, and a player start on the north sidewalk. Tools/ue_import_site.py imports the site FBXs; terrain, road and sidewalks use complex-as-simple so a simple hull cannot ramp over the kerbs. Art/blender/site/export_site_fbx.py exports one FBX per object so each can carry its own collision. Reset (R) and pause (Escape) join the character and the input context: reset restores the spawn transform and clears momentum, pause is a real game pause that releases the cursor. DefaultInput.ini captures the mouse on launch. Three placement defects found by measuring the imported actors rather than trusting the plan: the spawn was on the wrong sidewalk because the FBX flip inverts north, a mirror I added to the exporter double-corrected an already correct sidewalk, and the street meshes only carry part of the north walk - the rest is terrain.
This commit is contained in:
1 parent
c9278378ee
commit
cf392a02f7
30 files changed
+519
-9
No files matched your search
@@ -0,0 +1,119 @@
|
||||
# Build /Game/Hollywood/DemoMap: the walkable demo level.
|
||||
#
|
||||
# <engine>/Engine/Binaries/Linux/UnrealEditor-Cmd <uproject> -run=pythonscript \
|
||||
# -script=<repo>/Tools/ue_build_demo_map.py -nullrhi -unattended -nopause -stdout
|
||||
#
|
||||
# Content this map expects (built by earlier steps):
|
||||
# /Game/Hollywood/ElCapitan/SM_HeroFacade Tools/ue_hero_facade_import.py
|
||||
# /Game/Hollywood/Site/... Tools/ue_import_site.py
|
||||
#
|
||||
# Map conventions, from Geo/manifests/local-origin.md:
|
||||
# X east, Y south, Z up, centimetres, origin at Hollywood x Highland.
|
||||
# The player starts on the north sidewalk opposite the hero frontage, looking
|
||||
# south at it, which is the view the reference photographs were taken from.
|
||||
#
|
||||
# Every actor is (re)created by label, so rerunning the script rebuilds the map
|
||||
# deterministically instead of stacking duplicates.
|
||||
|
||||
import unreal
|
||||
|
||||
MAP = "/Game/Hollywood/DemoMap"
|
||||
RESULT = "/tmp/gigline/demo-map.txt"
|
||||
lines = []
|
||||
|
||||
|
||||
def log(msg):
|
||||
lines.append(str(msg))
|
||||
unreal.log(str(msg))
|
||||
|
||||
|
||||
def spawn(cls, loc, label, rot=None):
|
||||
actor = unreal.EditorLevelLibrary.spawn_actor_from_class(cls, loc)
|
||||
if actor is None:
|
||||
log(f"spawn {cls} failed")
|
||||
return None
|
||||
if rot is not None:
|
||||
actor.set_actor_rotation(rot, False)
|
||||
actor.set_actor_label(label)
|
||||
return actor
|
||||
|
||||
|
||||
def clear(prefixes=()):
|
||||
removed = 0
|
||||
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
||||
label = actor.get_actor_label()
|
||||
if label.startswith(prefixes):
|
||||
unreal.EditorLevelLibrary.destroy_actor(actor)
|
||||
removed += 1
|
||||
return removed
|
||||
|
||||
|
||||
def build():
|
||||
# --- level ------------------------------------------------------------
|
||||
if unreal.EditorAssetLibrary.does_asset_exist(MAP):
|
||||
if not unreal.EditorLevelLibrary.load_level(MAP):
|
||||
log(f"could not load {MAP}")
|
||||
return
|
||||
else:
|
||||
if not unreal.EditorLevelLibrary.new_level(MAP):
|
||||
log(f"could not create {MAP}")
|
||||
return
|
||||
|
||||
removed = clear(("Demo_", "PlayerStart", "Hero_Facade"))
|
||||
log(f"cleared {removed} previous demo actors")
|
||||
|
||||
# --- lighting ---------------------------------------------------------
|
||||
spawn(unreal.DirectionalLight, unreal.Vector(0, 0, 2000), "Demo_Sun",
|
||||
unreal.Rotator(pitch=-35.0, yaw=200.0, roll=0.0))
|
||||
spawn(unreal.SkyLight, unreal.Vector(0, 0, 2000), "Demo_SkyLight")
|
||||
spawn(unreal.SkyAtmosphere, unreal.Vector(0, 0, 0), "Demo_Sky")
|
||||
log("staged: sun, sky light, sky atmosphere")
|
||||
|
||||
# --- hero facade on the measured building line ------------------------
|
||||
hero = unreal.EditorAssetLibrary.load_asset("/Game/Hollywood/ElCapitan/SM_HeroFacade")
|
||||
if hero:
|
||||
actor = spawn(unreal.StaticMeshActor, unreal.Vector(-10722.5, -1443.0, 0.0), "Hero_Facade")
|
||||
if actor:
|
||||
actor.static_mesh_component.set_static_mesh(hero)
|
||||
actor.static_mesh_component.set_mobility(unreal.ComponentMobility.STATIC)
|
||||
log("staged: Hero_Facade at the building line")
|
||||
else:
|
||||
log("MISSING: SM_HeroFacade — run Tools/ue_hero_facade_import.py")
|
||||
|
||||
# --- site meshes, if they have been imported --------------------------
|
||||
imported = 0
|
||||
for name in ("Terrain_DEM", "Road_Hollywood", "Sidewalk_South", "Sidewalk_North",
|
||||
"Kerb_South", "Kerb_North"):
|
||||
mesh = unreal.EditorAssetLibrary.load_asset(f"/Game/Hollywood/Site/{name}")
|
||||
if mesh is None:
|
||||
continue
|
||||
actor = spawn(unreal.StaticMeshActor, unreal.Vector(0, 0, 0), f"Demo_{name}")
|
||||
if actor:
|
||||
actor.static_mesh_component.set_static_mesh(mesh)
|
||||
actor.static_mesh_component.set_mobility(unreal.ComponentMobility.STATIC)
|
||||
imported += 1
|
||||
log(f"staged {imported} site meshes from /Game/Hollywood/Site")
|
||||
|
||||
# --- player start: north sidewalk, facing the hero frontage -------------
|
||||
# Signs were measured from the imported meshes rather than assumed: the FBX
|
||||
# preset flips north, so in Unreal the road spans Y -1382..+1047, the NORTH
|
||||
# sidewalk is at Y -1912..-1053 and the SOUTH sidewalk at Y +718..+1447. The
|
||||
# facade stands at Y -1450. Stand on the north sidewalk and look north (-Y).
|
||||
spawn(unreal.PlayerStart, unreal.Vector(-10722.5, -3500.0, 120.0), "Demo_PlayerStart",
|
||||
unreal.Rotator(pitch=0.0, yaw=0.0, roll=0.0))
|
||||
log("staged: Demo_PlayerStart on the north sidewalk facing south")
|
||||
|
||||
saved = unreal.EditorLoadingAndSavingUtils.save_map(
|
||||
unreal.EditorLevelLibrary.get_editor_world(), MAP)
|
||||
log(f"save_map {MAP}: {saved}")
|
||||
|
||||
|
||||
try:
|
||||
build()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
import traceback
|
||||
log(f"FAILED: {type(exc).__name__}: {exc}")
|
||||
log(traceback.format_exc())
|
||||
|
||||
with open(RESULT, "w") as f:
|
||||
f.write("\n".join(lines) + "\n")
|
||||
@@ -182,6 +182,43 @@ try:
|
||||
# oblique from the north-west, reading the colonnade in depth
|
||||
("hero-facade-oblique", unreal.Vector(hero_x - 2200, -3400, 620), unreal.Vector(hero_x + 300, hero_y, 700)),
|
||||
]
|
||||
# --- demo map views: what the player actually sees ----------------------
|
||||
demo = unreal.EditorAssetLibrary.load_asset("/Game/Hollywood/DemoMap")
|
||||
if demo and unreal.EditorAssetLibrary.does_asset_exist("/Game/Hollywood/DemoMap"):
|
||||
# The demo map has terrain, street, sidewalks and the facade; the review
|
||||
# floor does not. Load it, stage the shot cameras, save, then restore the
|
||||
# review map so the rest of the run is unaffected.
|
||||
unreal.EditorLevelLibrary.load_level("/Game/Hollywood/DemoMap")
|
||||
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
||||
if actor.get_actor_label() == "ShotSequencer":
|
||||
unreal.EditorLevelLibrary.destroy_actor(actor)
|
||||
# Unreal signs, measured from the imported site meshes: north sidewalk at
|
||||
# Y -1912..-1053, road -1382..+1047, south sidewalk +718..+1447, facade at
|
||||
# Y -1450. So "opposite the facade" is Y -1650 and the view faces -Y.
|
||||
demo_shots = [
|
||||
# 14 m back so the 14.5 m elevation fits: at 2 m the camera sees only
|
||||
# the colonnade's underside.
|
||||
("demo-spawn-view", unreal.Vector(-10722.5, -3500, 165), unreal.Vector(-10722.5, -1450, 700)),
|
||||
("demo-street-level", unreal.Vector(-11000, -400, 165), unreal.Vector(-10722.5, -1450, 500)),
|
||||
("demo-crossing", unreal.Vector(-13600, -1650, 165), unreal.Vector(-12722.5, -1450, 500)),
|
||||
]
|
||||
seq = spawn(unreal.GigLineShotActor, unreal.Vector(0, 0, 300), "ShotSequencer")
|
||||
if seq:
|
||||
seq.set_editor_property("shot_locations", [c[1] for c in demo_shots])
|
||||
seq.set_editor_property("shot_rotations",
|
||||
[unreal.MathLibrary.find_look_at_rotation(c[1], c[2]) for c in demo_shots])
|
||||
seq.set_editor_property("shot_names", [c[0] for c in demo_shots])
|
||||
seq.set_editor_property("quit_when_done", False)
|
||||
saved = unreal.EditorLoadingAndSavingUtils.save_map(
|
||||
unreal.EditorLevelLibrary.get_editor_world(), "/Game/Hollywood/DemoMap")
|
||||
log(f"demo map staged: {len(demo_shots)} cameras, save {saved}")
|
||||
unreal.EditorLevelLibrary.load_level("/Game/Test/ReviewMap")
|
||||
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
||||
if actor.get_actor_label() == "ShotSequencer":
|
||||
unreal.EditorLevelLibrary.destroy_actor(actor)
|
||||
else:
|
||||
log("MISSING: /Game/Hollywood/DemoMap (run Tools/ue_build_demo_map.py)")
|
||||
|
||||
shots = spawn(unreal.GigLineShotActor, unreal.Vector(0, 0, 300), "ShotSequencer")
|
||||
if shots:
|
||||
shots.set_editor_property("shot_locations", [c[1] for c in cams])
|
||||
|
||||
@@ -118,11 +118,21 @@ def build():
|
||||
ia_left.set_editor_property("value_type", unreal.InputActionValueType.AXIS1D)
|
||||
save(ia_left)
|
||||
|
||||
# Reset and pause are boolean: one press, no accumulator.
|
||||
ia_reset = fresh("IA_Reset", unreal.InputAction, unreal.InputAction_Factory)
|
||||
ia_reset.set_editor_property("value_type", unreal.InputActionValueType.BOOLEAN)
|
||||
save(ia_reset)
|
||||
|
||||
ia_pause = fresh("IA_Pause", unreal.InputAction, unreal.InputAction_Factory)
|
||||
ia_pause.set_editor_property("value_type", unreal.InputActionValueType.BOOLEAN)
|
||||
save(ia_pause)
|
||||
|
||||
mapping_table = [
|
||||
(ia_move, "W"), (ia_back, "S"), (ia_strafe, "D"), (ia_left, "A"),
|
||||
(ia_move, "Gamepad_LeftY"), (ia_strafe, "Gamepad_LeftX"),
|
||||
(ia_look, "MouseX"), (ia_look, "MouseY"), (ia_look, "Gamepad_Right2D"),
|
||||
(ia_jump, "SpaceBar"), (ia_jump, "Gamepad_FaceButton_Bottom"),
|
||||
(ia_reset, "R"), (ia_pause, "Escape"),
|
||||
]
|
||||
|
||||
mappings = []
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
# Import the Blender site meshes (terrain, road, sidewalks, kerbs) into Unreal.
|
||||
#
|
||||
# blender ... --python Art/blender/site/export_site_fbx.py -- --out /tmp/gigline/site
|
||||
# <engine>/.../UnrealEditor-Cmd <uproject> -run=pythonscript \
|
||||
# -script=<repo>/Tools/ue_import_site.py -nullrhi -unattended -nopause -stdout
|
||||
#
|
||||
# Each mesh is a separate FBX because they carry different materials and want
|
||||
# different collision settings (terrain and street are walkable surfaces).
|
||||
# Destination: /Game/Hollywood/Site/<name>.
|
||||
#
|
||||
# Y-axis note: the FBX preset maps Blender +Y (north) to Unreal -Y, so the site
|
||||
# arrives in the same frame as the hero facade. Nothing is mirrored here.
|
||||
|
||||
import glob
|
||||
import os
|
||||
|
||||
import unreal
|
||||
|
||||
SRC = "/tmp/gigline/site"
|
||||
DEST = "/Game/Hollywood/Site"
|
||||
RESULT = "/tmp/gigline/site-import.txt"
|
||||
lines = []
|
||||
|
||||
|
||||
def log(msg):
|
||||
lines.append(str(msg))
|
||||
unreal.log(str(msg))
|
||||
|
||||
|
||||
def import_fbx(path, name, collision):
|
||||
task = unreal.AssetImportTask()
|
||||
task.filename = path
|
||||
task.destination_path = DEST
|
||||
task.destination_name = name
|
||||
task.automated = True
|
||||
task.save = True
|
||||
task.replace_existing = True
|
||||
|
||||
ui = unreal.FbxImportUI()
|
||||
ui.import_mesh = True
|
||||
ui.import_materials = True
|
||||
ui.import_textures = False
|
||||
ui.import_as_skeletal = False
|
||||
smd = ui.static_mesh_import_data
|
||||
smd.import_uniform_scale = 1.0
|
||||
smd.combine_meshes = True
|
||||
smd.convert_scene_unit = False
|
||||
smd.force_front_x_axis = False
|
||||
smd.normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS
|
||||
task.options = ui
|
||||
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
|
||||
|
||||
mesh = unreal.EditorAssetLibrary.load_asset(f"{DEST}/{name}")
|
||||
if mesh is None:
|
||||
log(f"MISSING after import: {DEST}/{name}")
|
||||
return
|
||||
# Collision is requested at import time so the 0.1.0 walkability check has
|
||||
# something to stand on. Terrain and street get complex-as-simple: a simple
|
||||
# hull would ramp straight over the kerbs.
|
||||
#
|
||||
# UE 5.8 exposes this only through StaticMeshEditorSubsystem (the mesh itself
|
||||
# has no trace-flag property, and the subsystem has no setter in Python), so
|
||||
# the import path sets the body setup's trace flag through the mesh's
|
||||
# collision options at import, then verifies it by reading it back.
|
||||
trace = (unreal.CollisionTraceFlag.CTF_USE_COMPLEX_AS_SIMPLE
|
||||
if collision == "complex" else unreal.CollisionTraceFlag.CTF_USE_SIMPLE_AND_COMPLEX)
|
||||
try:
|
||||
body = mesh.get_editor_property("body_setup")
|
||||
body.set_editor_property("collision_trace_flag", trace)
|
||||
mesh.set_editor_property("body_setup", body)
|
||||
except Exception as exc: # noqa: BLE001 - report, do not fail the whole import
|
||||
log(f"{name}: could not set trace flag ({exc}); leaving the default")
|
||||
box = mesh.get_bounding_box()
|
||||
mn, mx = box.min, box.max
|
||||
log(f"{name:18} import ok size=({mx.x - mn.x:.0f}, {mx.y - mn.y:.0f}, {mx.z - mn.z:.0f}) cm "
|
||||
f"min_z={mn.z:.1f} collision={collision}")
|
||||
|
||||
|
||||
def main():
|
||||
files = sorted(glob.glob(os.path.join(SRC, "*.fbx")))
|
||||
if not files:
|
||||
log(f"no FBX in {SRC}; run Art/blender/site/export_site_fbx.py first")
|
||||
return
|
||||
for path in files:
|
||||
stem = os.path.splitext(os.path.basename(path))[0]
|
||||
collision = "complex" if stem in ("Terrain_DEM", "Road_Hollywood",
|
||||
"Sidewalk_South", "Sidewalk_North") else "simple"
|
||||
import_fbx(path, stem, collision)
|
||||
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
import traceback
|
||||
log(f"FAILED: {type(exc).__name__}: {exc}")
|
||||
log(traceback.format_exc())
|
||||
|
||||
with open(RESULT, "w") as f:
|
||||
f.write("\n".join(lines) + "\n")
|
||||
Reference in new issue
Block a user