This repository was archived by the owner on Aug 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColladaExport.py
More file actions
149 lines (130 loc) · 4.02 KB
/
ColladaExport.py
File metadata and controls
149 lines (130 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Blender script by KiwifruitDev
# Import arg 1 as "Valve Map Format (.vmf)" and export to arg 2 as "Collada (.dae)"
import bpy
import sys
import os
from plumber.plumber import Importer, FileSystem
from plumber.asset import AssetCallbacks
# Get the arguments
argv = sys.argv
argv = argv[argv.index("--") + 1:]
# Get the file paths
inputPath = argv[0]
outputPath = argv[1]
# Delete the default cube if it exists
if bpy.data.objects.get("Cube") is not None:
bpy.data.objects["Cube"].select_set(True)
bpy.ops.object.delete()
# Delete the default light if it exists
if bpy.data.objects.get("Light") is not None:
bpy.data.objects["Light"].select_set(True)
bpy.ops.object.delete()
# Delete the default camera if it exists
if bpy.data.objects.get("Camera") is not None:
bpy.data.objects["Camera"].select_set(True)
bpy.ops.object.delete()
# Import the VMF
rootgame = "D:\SteamLibrary\steamapps\common\Source SDK Base 2013 Multiplayer"
game = "hl2"
fs = FileSystem("HALF-LIFE 2", [
("WILDCARD", rootgame + "/" + game + "/custom"),
("VPK", rootgame + "/" + game + "/hl2_pak.vpk"),
("VPK", rootgame + "/" + game + "/hl2_textures.vpk"),
("VPK", rootgame + "/" + game + "/hl2_misc.vpk"),
("DIR", rootgame + "/" + game),
])
asset_callbacks = AssetCallbacks(
bpy.context,
main_collection=None,
brush_collection=None,
overlay_collection=None,
prop_collection=None,
light_collection=None,
entity_collection=None,
apply_armatures=False,
)
try:
importer = Importer(
fs,
asset_callbacks,
3,
import_lights=False,
light_factor=0,
sun_factor=0,
ambient_factor=0,
import_sky_camera=False,
sky_equi_height=None,
import_unknown_entities=False,
scale=1,
target_fps=24,
remove_animations=True,
simple_materials=True,
allow_culling=True,
editor_materials=False,
texture_interpolation="Linear",
# automatic map data path detection happens here
vmf_path=inputPath,
map_data_path="",
)
except OSError as err:
print(f"Could not parse vmf: {err}")
try:
importer.import_vmf(
inputPath,
False,
import_brushes=True,
import_overlays=True,
epsilon=0.001,
cut_threshold=0.001,
merge_solids="SEPARATE",
invisible_solids="SKIP",
import_materials=True,
import_props=True,
import_entities=False,
import_sky=False,
scale=1,
)
except OSError as err:
print(f"Could not import vmf: {err}")
asset_callbacks.finish()
# Select all objects
bpy.ops.object.select_all(action='SELECT')
# Remove all armature modifiers
for obj in bpy.context.selected_objects:
for modifier in obj.modifiers:
if modifier.type == "ARMATURE":
obj.modifiers.remove(modifier)
# Apply position/rotation to geometry
bpy.context.view_layer.objects.active = obj
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
# Remove all armatures
for armature in bpy.data.armatures:
bpy.data.armatures.remove(armature)
# Rename all material slot names without prefixed path
for material in bpy.data.materials:
# Get last slash index
lastSlash = material.name.rfind("/")
# Get the material name
materialName = material.name[lastSlash + 1:]
# Set the material name
material.name = materialName
# Rename all image names without prefixed path
for image in bpy.data.images:
# Ignore Render Result and Viewer Node
if image.name == "Render Result" or image.name == "Viewer Node":
continue
# Get last slash index
lastSlash = image.name.rfind("/")
# Get the image name
imageName = image.name[lastSlash + 1:]
# Set the image name
image.name = imageName
# Save as DAE (Y up, -Z forward)
bpy.ops.wm.collada_export(filepath=outputPath,
check_existing=False,
export_global_forward_selection='-Z',
export_global_up_selection='Y',
apply_global_orientation=True,
)
# Exit Blender
bpy.ops.wm.quit_blender()