Add option to scale map in import menu

This commit is contained in:
Pyogenics
2025-04-10 14:15:44 +01:00
parent 91ee61d692
commit b1794014dc
2 changed files with 18 additions and 4 deletions

View File

@@ -150,10 +150,11 @@ class BattleMapBlenderImporter:
# Allows subsequent map loads to be faster
libraryCache = {}
def __init__(self, mapData, lightmapData, propLibrarySourcePath, import_static_geom=True, import_collision_geom=False, import_spawn_points=False, import_lightmapdata=False):
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):
self.mapData = mapData
self.lightmapData = lightmapData
self.propLibrarySourcePath = propLibrarySourcePath
self.map_scale_factor = map_scale_factor
self.import_static_geom = import_static_geom
self.import_collision_geom = import_collision_geom
self.import_spawn_points = import_spawn_points
@@ -195,20 +196,29 @@ class BattleMapBlenderImporter:
ob = self.createBlenderSpawnPoint(spawnPointData)
spawnPointObjects.append(ob)
# Create empty objects to house each type of object
# Create container object to store all our objects
objects = propObjects + collisionObjects + spawnPointObjects
mapOB = bpy.data.objects.new("BattleMap", None)
mapOB.empty_display_size = 100
mapOB.scale = (self.map_scale_factor, self.map_scale_factor, self.map_scale_factor)
objects.append(mapOB)
# Create empty objects to house each type of object
if self.import_static_geom:
groupOB = bpy.data.objects.new("StaticGeometry", None)
groupOB.parent = mapOB
objects.append(groupOB)
for ob in propObjects:
ob.parent = groupOB
if self.import_collision_geom:
groupOB = bpy.data.objects.new("CollisionGeometry", None)
groupOB.parent = mapOB
objects.append(groupOB)
for ob in collisionObjects:
ob.parent = groupOB
if self.import_spawn_points:
groupOB = bpy.data.objects.new("SpawnPoints", None)
groupOB.parent = mapOB
objects.append(groupOB)
for ob in spawnPointObjects:
ob.parent = groupOB
@@ -223,6 +233,8 @@ class BattleMapBlenderImporter:
lightAngleX, lightAngleZ = self.lightmapData.lightAngle
ob.rotation_mode = "XYZ"
ob.rotation_euler = (lightAngleX, 0.0, lightAngleZ)
ob.parent = mapOB
objects.append(ob)
# Set ambient world light

View File

@@ -22,7 +22,7 @@ SOFTWARE.
import bpy
from bpy.types import Operator, OperatorFileListElement, AddonPreferences
from bpy.props import StringProperty, BoolProperty, CollectionProperty
from bpy.props import StringProperty, BoolProperty, CollectionProperty, FloatProperty
from bpy_extras.io_utils import ImportHelper
from .A3D import A3D
@@ -112,6 +112,7 @@ class ImportBattleMap(Operator, ImportHelper):
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)
import_spawn_points: BoolProperty(name="Import spawn points", description="Places a marker at locations where tanks can spawn", default=False)
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)
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)
def draw(self, context):
import_panel_options_battlemap(self.layout, self)
@@ -139,7 +140,7 @@ class ImportBattleMap(Operator, ImportHelper):
# Import data into blender
preferences = context.preferences.addons[__package__].preferences # TODO: check if this is set before proceeding
mapImporter = BattleMapBlenderImporter(mapData, lightmapData, preferences.propLibrarySourcePath, self.import_static_geom, self.import_collision_geom, self.import_spawn_points, self.import_lightmapdata)
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)
objects = mapImporter.importData()
# Link objects
@@ -171,6 +172,7 @@ def import_panel_options_battlemap(layout, operator):
body.prop(operator, "import_collision_geom")
body.prop(operator, "import_spawn_points")
body.prop(operator, "import_lightmapdata")
body.prop(operator, "map_scale_factor")
def menu_func_import_a3d(self, context):
self.layout.operator(ImportA3D.bl_idname, text="Alternativa3D HTML5 (.a3d)")