Created
April 1, 2022 21:04
-
-
Save VityaSchel/7bbef518ad11a5e2fd4d9cd38d38af3a to your computer and use it in GitHub Desktop.
Import umap level files from Unreal Engine games to Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import json | |
from mathutils import Euler | |
import math | |
base_dir = 'C:\\Users\\VityaSchel\\Documents\\umap-exporter\\' | |
objects = json.load(open(base_dir + 'mapped.json')) | |
if(len(bpy.data.collections) > 1): | |
bpy.context.scene.collection.children.unlink( | |
bpy.data.collections[1] | |
) | |
bpy.data.collections.remove(bpy.data.collections[1]) | |
bpy.context.scene.collection.children.link( | |
bpy.data.collections.new("Level") | |
) | |
wall_objects = [ | |
'floor', | |
'pillar', | |
'wall', | |
'wall_short' | |
] | |
for obj in objects: | |
path = wall_objects.index(obj['name']) | |
src_obj = bpy.data.collections[0].objects[path] | |
new_obj = src_obj.copy() | |
new_obj.data = src_obj.data.copy() | |
#new_obj.animation_data_clear() | |
new_obj.location = (obj['pos']['X'], obj['pos']['Y'], obj['pos']['Z']) | |
size_mult = 100 | |
new_obj.scale = ( | |
obj['scale']['X']*size_mult, | |
obj['scale']['Y']*size_mult, | |
obj['scale']['Z']*size_mult | |
) | |
if('rot' in obj): | |
new_obj.rotation_euler = (#Euler(( | |
math.radians(obj['rot']['Roll']), | |
math.radians(obj['rot']['Pitch']), | |
math.radians(obj['rot']['Yaw']) | |
)#, 'XYZ') | |
new_obj.name = obj['name'] | |
bpy.data.collections[1].objects.link(new_obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs/promises' | |
const umapData = await fs.readFile('./map-data.json', 'utf-8') | |
const umapDataJson = JSON.parse(umapData) | |
// list all types | |
// console.log(new Set(umapDataJson.map(({ Type }) => Type))) | |
const meshes = umapDataJson.filter(({ Type }) => Type === 'StaticMeshComponent') | |
.map(obj => { | |
const _ = obj.Properties | |
return { | |
path: _.StaticMesh?.ObjectPath || _.StaticMesh, | |
pos: _.RelativeLocation, | |
rot: _.RelativeRotation, | |
scale: _.RelativeScale3D | |
} | |
}) | |
const filters = { | |
'TJoC_R/Content/Game/Models/Basement/SM_Bas_Pillar.2': 'pillar', | |
'TJoC_R/Content/Game/Models/Basement/SM_Bas_Wall1.2': 'wall', | |
'TJoC_R/Content/Game/Models/Basement/SM_Bas_WallShort.2': 'wall_short', | |
'TJoC_R/Content/Game/Models/Basement/SM_Bas_Floor.2': 'floor' | |
} | |
fs.writeFile( | |
'mapped.json', | |
JSON.stringify( | |
meshes | |
.filter(obj => Object.keys(filters).includes(obj.path)) | |
.map(({ path, ...obj }) => ({ ...obj, name: filters[path] })) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://youtu.be/cZZkkgE7yzg