Skip to content

Commit b179401

Browse files
committed
Add option to scale map in import menu
1 parent 91ee61d commit b179401

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

io_scene_a3d/BattleMapBlenderImporter.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ class BattleMapBlenderImporter:
150150
# Allows subsequent map loads to be faster
151151
libraryCache = {}
152152

153-
def __init__(self, mapData, lightmapData, propLibrarySourcePath, import_static_geom=True, import_collision_geom=False, import_spawn_points=False, import_lightmapdata=False):
153+
def __init__(self, mapData, lightmapData, propLibrarySourcePath, map_scale_factor=0.01, import_static_geom=True, import_collision_geom=False, import_spawn_points=False, import_lightmapdata=False):
154154
self.mapData = mapData
155155
self.lightmapData = lightmapData
156156
self.propLibrarySourcePath = propLibrarySourcePath
157+
self.map_scale_factor = map_scale_factor
157158
self.import_static_geom = import_static_geom
158159
self.import_collision_geom = import_collision_geom
159160
self.import_spawn_points = import_spawn_points
@@ -195,20 +196,29 @@ def importData(self):
195196
ob = self.createBlenderSpawnPoint(spawnPointData)
196197
spawnPointObjects.append(ob)
197198

198-
# Create empty objects to house each type of object
199+
# Create container object to store all our objects
199200
objects = propObjects + collisionObjects + spawnPointObjects
201+
mapOB = bpy.data.objects.new("BattleMap", None)
202+
mapOB.empty_display_size = 100
203+
mapOB.scale = (self.map_scale_factor, self.map_scale_factor, self.map_scale_factor)
204+
objects.append(mapOB)
205+
206+
# Create empty objects to house each type of object
200207
if self.import_static_geom:
201208
groupOB = bpy.data.objects.new("StaticGeometry", None)
209+
groupOB.parent = mapOB
202210
objects.append(groupOB)
203211
for ob in propObjects:
204212
ob.parent = groupOB
205213
if self.import_collision_geom:
206214
groupOB = bpy.data.objects.new("CollisionGeometry", None)
215+
groupOB.parent = mapOB
207216
objects.append(groupOB)
208217
for ob in collisionObjects:
209218
ob.parent = groupOB
210219
if self.import_spawn_points:
211220
groupOB = bpy.data.objects.new("SpawnPoints", None)
221+
groupOB.parent = mapOB
212222
objects.append(groupOB)
213223
for ob in spawnPointObjects:
214224
ob.parent = groupOB
@@ -223,6 +233,8 @@ def importData(self):
223233
lightAngleX, lightAngleZ = self.lightmapData.lightAngle
224234
ob.rotation_mode = "XYZ"
225235
ob.rotation_euler = (lightAngleX, 0.0, lightAngleZ)
236+
237+
ob.parent = mapOB
226238
objects.append(ob)
227239

228240
# Set ambient world light

io_scene_a3d/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import bpy
2424
from bpy.types import Operator, OperatorFileListElement, AddonPreferences
25-
from bpy.props import StringProperty, BoolProperty, CollectionProperty
25+
from bpy.props import StringProperty, BoolProperty, CollectionProperty, FloatProperty
2626
from bpy_extras.io_utils import ImportHelper
2727

2828
from .A3D import A3D
@@ -112,6 +112,7 @@ class ImportBattleMap(Operator, ImportHelper):
112112
import_collision_geom: BoolProperty(name="Import collision geometry", description="Collision geometry defines the geometry used for collision checks and cannot normally be seen by players", default=False)
113113
import_spawn_points: BoolProperty(name="Import spawn points", description="Places a marker at locations where tanks can spawn", default=False)
114114
import_lightmapdata: BoolProperty(name="Import lighting information", description="Loads the lightmapdata file which stores information about the sun, ambient lighting and shadow settings. Only works on remaster maps.", default=True)
115+
map_scale_factor: FloatProperty(name="Map scale", description="Sets the map's default scale, maps and models are at a 100x scale so this allows you to directly import the map in the right size.", default=0.01, min=0.0, soft_max=1.0)
115116

116117
def draw(self, context):
117118
import_panel_options_battlemap(self.layout, self)
@@ -139,7 +140,7 @@ def execute(self, context):
139140

140141
# Import data into blender
141142
preferences = context.preferences.addons[__package__].preferences # TODO: check if this is set before proceeding
142-
mapImporter = BattleMapBlenderImporter(mapData, lightmapData, preferences.propLibrarySourcePath, self.import_static_geom, self.import_collision_geom, self.import_spawn_points, self.import_lightmapdata)
143+
mapImporter = BattleMapBlenderImporter(mapData, lightmapData, preferences.propLibrarySourcePath, self.map_scale_factor, self.import_static_geom, self.import_collision_geom, self.import_spawn_points, self.import_lightmapdata)
143144
objects = mapImporter.importData()
144145

145146
# Link objects
@@ -171,6 +172,7 @@ def import_panel_options_battlemap(layout, operator):
171172
body.prop(operator, "import_collision_geom")
172173
body.prop(operator, "import_spawn_points")
173174
body.prop(operator, "import_lightmapdata")
175+
body.prop(operator, "map_scale_factor")
174176

175177
def menu_func_import_a3d(self, context):
176178
self.layout.operator(ImportA3D.bl_idname, text="Alternativa3D HTML5 (.a3d)")

0 commit comments

Comments
 (0)