Skip to content

Commit

Permalink
Fix portal gun animation glitches
Browse files Browse the repository at this point in the history
The skeletool command for model generation placed model flags before
default flags.

Normally this isn't a problem, but v_portalgun.flags overrides the
default scene scale by specifying the same argument again with a
different value. Since its arguments were not last in the command,
the scale was not overridden and its animations were incorrect.

Fixed by refactoring the convert_asset script into a more general
run_command script, which supports the required functionality of reading
arguments from a file while also allowing the caller to choose their
position relative to other arguments.
  • Loading branch information
mwpenny committed Nov 29, 2024
1 parent c3a96fb commit 7e53d12
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 43 deletions.
4 changes: 2 additions & 2 deletions assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ set(MODEL_SCALE 0.01)
set(SCENE_SCALE 128)

# Tools for asset conversion
set(CONVERT_ASSET "${PROJECT_SOURCE_DIR}/tools/convert_asset.py")
set(GEN_SEGMENT_LD "${PROJECT_SOURCE_DIR}/tools/generate_segment_ld.js")
set(EXPORT_FBX "${PROJECT_SOURCE_DIR}/tools/models/export_fbx.py")
set(GEN_SEGMENT_LD "${PROJECT_SOURCE_DIR}/tools/generate_segment_ld.js")
set(MODEL_LIST_UTILS "${PROJECT_SOURCE_DIR}/tools/models/model_list_utils.js")
set(RUN_COMMAND "${PROJECT_SOURCE_DIR}/tools/run_command.py")

add_subdirectory(fonts)
add_subdirectory(materials)
Expand Down
6 changes: 3 additions & 3 deletions assets/materials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,16 @@ function(_add_texture_transform_command TEXTURE_SCRIPT OUTPUT_LIST)

add_custom_command(
DEPENDS
${CONVERT_ASSET} ${DEPENDENCY_FILES}
${RUN_COMMAND} ${DEPENDENCY_FILES}
OUTPUT
${OUTPUT_FILES}
COMMAND
${CMAKE_COMMAND} -E make_directory "$<PATH:GET_PARENT_PATH,${OUTPUT_FILE}>"
COMMAND
${Python3_EXECUTABLE} ${CONVERT_ASSET}
${Python3_EXECUTABLE} ${RUN_COMMAND}
${ImageMagickConvert_EXECUTABLE}
${INPUT_FILE}
${TEXTURE_SCRIPT}
@${TEXTURE_SCRIPT}
${OUTPUT_FILE}
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
Expand Down
6 changes: 3 additions & 3 deletions assets/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function(_add_model_generate_command MODEL_NAME MODEL_FBX MODEL_OUTPUT_LIST ANIM
DEPENDS
textures "$<TARGET_PROPERTY:textures,OUTPUTS>"
skeletool64::skeletool64
${CONVERT_ASSET}
${RUN_COMMAND}
${MODEL_FBX}
${MODEL_FLAGS}
${MODEL_MATERIALS}
Expand All @@ -154,14 +154,14 @@ function(_add_model_generate_command MODEL_NAME MODEL_FBX MODEL_OUTPUT_LIST ANIM
COMMAND
${CMAKE_COMMAND} -E make_directory "$<PATH:GET_PARENT_PATH,${OUTPUT_FILE_NO_EXTENSION}>"
COMMAND
${Python3_EXECUTABLE} ${CONVERT_ASSET}
${Python3_EXECUTABLE} ${RUN_COMMAND}
$<TARGET_FILE:skeletool64::skeletool64>
${MODEL_FBX}
${MODEL_FLAGS}
--fixed-point-scale ${SCENE_SCALE}
--model-scale ${MODEL_SCALE}
--name ${MODEL_NAME}
--output ${OUTPUT_FILE_H}
@${MODEL_FLAGS}
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
COMMENT
Expand Down
6 changes: 3 additions & 3 deletions assets/sound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ function(_add_sound_transform_command_sox SOUND_SCRIPT INPUT_FILE OUTPUT_FILE)
add_custom_command(
DEPENDS
extract_vpks ${INPUT_FILE}
${CONVERT_ASSET}
${RUN_COMMAND}
${SOUND_SCRIPT}
OUTPUT
${OUTPUT_FILE}
COMMAND
${CMAKE_COMMAND} -E make_directory "$<PATH:GET_PARENT_PATH,${OUTPUT_FILE}>"
COMMAND
${Python3_EXECUTABLE} ${CONVERT_ASSET}
${Sox_EXECUTABLE} ${INPUT_FILE} ${SOUND_SCRIPT} ${OUTPUT_FILE} -V1
${Python3_EXECUTABLE} ${RUN_COMMAND}
${Sox_EXECUTABLE} ${INPUT_FILE} @${SOUND_SCRIPT} ${OUTPUT_FILE} -V1
COMMENT
"Transforming $<PATH:RELATIVE_PATH,${INPUT_FILE},${PROJECT_SOURCE_DIR}>"
VERBATIM
Expand Down
32 changes: 0 additions & 32 deletions tools/convert_asset.py

This file was deleted.

34 changes: 34 additions & 0 deletions tools/run_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

import subprocess
import shlex
import sys

# Arguments to commands for converting assets are stored in text files
#
# This helper script allows calling the commands with the arguments from
# such files in a cross-platform way.

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Runs a specified command with the given arguments")
print("Arguments prefixed with '@' are read as files containing arguments")
print()
print(f"Usage: {sys.argv[0]} COMMAND [ARG]...")
sys.exit(1)

command, *args = sys.argv[1:]
parsed_args = []

for arg in args:
if arg.startswith('@'):
with open(arg[1:]) as f:
parsed_args += shlex.split(f.read().strip())
else:
parsed_args.append(arg)

rc = subprocess.run([
command,
*parsed_args
])
sys.exit(rc.returncode)

0 comments on commit 7e53d12

Please sign in to comment.