-
Notifications
You must be signed in to change notification settings - Fork 9
/
POLYGON_StreetRacer.py
49 lines (42 loc) · 1.75 KB
/
POLYGON_StreetRacer.py
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
import bpy
import os
def import_characters():
# Deselect all
bpy.ops.object.select_all(action='DESELECT')
# Highlight the 'Characters' collection - https://blender.stackexchange.com/a/248563
bpy.context.view_layer.active_layer_collection = \
bpy.context.view_layer.layer_collection.children['Characters']
# Import the characters
bpy.ops.import_scene.fbx(
filepath=bpy.path.abspath("//PolygonStreetRacer_SourceFiles\\FBX\\Characters.fbx"),
use_anim=False,
ignore_leaf_bones=True,
force_connect_children=True,
automatic_bone_orientation=True,
)
collection = bpy.data.collections["Characters"]
# Apply location, rotation, scale to deltas
for obj in collection.all_objects:
obj.delta_location += obj.location
obj.location = (0, 0, 0)
obj.delta_rotation_euler.rotate(obj.rotation_euler)
obj.rotation_euler = (0, 0, 0)
obj.delta_scale = obj.scale
obj.scale = (1, 1, 1)
# Textures pointing to the wrong directory. Fix that
# https://blender.stackexchange.com/a/280804
for image in bpy.data.images.values():
# Textures are pointing towards PolygonCity. Fix that
filename = os.path.basename(image.filepath)
if image.source == "FILE":
if filename == "PolygonStreetRacer_Texture_Master.psd":
# Make absolute
image.filepath = bpy.path.abspath(
"//PolygonStreetRacer_SourceFiles\\Textures\\PolygonStreetRacer_Texture_01_A.png"
)
else:
# Make absolute
image.filepath = bpy.path.abspath(
"//PolygonStreetRacer_SourceFiles\\Textures\\" + filename
)
import_characters()