Skip to content

Commit 7af2bc6

Browse files
committed
Cleanup and README update for first public release
1 parent fc4165f commit 7af2bc6

9 files changed

+142
-23
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
1+
testing/**
2+
!testing/*
23
*.pyc

Diff for: README.md

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,50 @@
1-
# Blender Datasmith addon
1+
# Blender Datasmith Export
22

3-
This addon lets you export your blender scene to UE4 using the Datasmith
4-
format.
3+
Export your Blender scene to UE4 using the Datasmith format.
54

6-
You can see a brief overview of how it works here:
5+
It aims to export all the Datasmith format supports. For now it exports:
6+
7+
* __Meshes__ with normals, vertex colors and UV coordinates.
8+
* __Hierarchy__ is exported keeping meshes references, transforms, parents and
9+
per-instance material overrides from blender.
10+
* __Textures and materials__ are exported using data from the shader graphs.
11+
Materials are closely approximated and a good amount of nodes are supported
12+
(math, mix, fresnel, vertex color and others)
13+
* __Cameras__ are exported trying to match Blender data, keeping focus
14+
distance, focal length, and aperture
15+
* __Lights__ are exported, keeping their type, power, color and size data.
16+
17+
Check out an overview of a previous version here:
718
https://youtu.be/bUUDqerdqAc
819

9-
The plugin is currently in preview status, you can try it by [getting the
10-
testing source build](https://github.com/0xafbf/blender-datasmith-export/archive/master.zip)
11-
and install from the blender addons preferences pane.
20+
## Sample:
21+
__Blender Eevee:__
22+
![Blender Eevee render](docs/blender.jpg)
23+
__UE4 using Datasmith:__
24+
![UE4 render](docs/unreal.jpg)
25+
26+
This result relies on the **DatasmithBlenderContent**, which is a UE4 Plugin
27+
that improves material import compatibility. Consider supporting the project by
28+
purchasing it from the Epic Store or Gumroad (more info coming soon)
29+
30+
This result is in a custom UE4 build, which fixes some issues of the UE4
31+
importer. If you are technical to compile the engine, you can check the fork
32+
[here][ue4 fork]. Hopefully we can get to integrate our fixes into the main
33+
branch.
34+
[ue4 fork]: https://github.com/0xafbf/UnrealEngine/tree/master
35+
36+
Now [__Download the latest version__][download_link] and install from the
37+
Blender addons preferences pane.
38+
39+
[download_link]: https://github.com/0xafbf/blender-datasmith-export/archive/master.zip
40+
41+
If you want to support the project, also consider supporting via [Patreon],
42+
even if it is a little it adds up.
43+
44+
[patreon]: https://www.patreon.com/0xafbf
1245

13-
This is a work in progress, if you want to contribute to improve it, feel free
14-
to submit pull requests or support me on Patreon:
15-
https://www.patreon.com/0xafbf
46+
Please please, [join the project Discord][join_discord] and share your results!
47+
I want to see what you make and I am open to any feedback you have.
1648

17-
This is an unofficial exporter. If you would like to get in touch, please [join the project Discord](https://discord.gg/h2GHqMq)
49+
[join_discord]: https://discord.gg/h2GHqMq
1850

Diff for: __init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
bl_info = {
44
"name": "Unreal Datasmith format",
55
"author": "Andrés Botero",
6-
"version": (0, 1, 0),
7-
"blender": (2, 80, 0),
6+
"version": (0, 1, 1),
7+
"blender": (2, 81, 0),
88
"location": "File > Export > Datasmith (.udatasmith)",
99
"description": "Export scene as Datasmith asset",
1010
"warning": "",

Diff for: docs/blender.jpg

211 KB
Loading

Diff for: docs/unreal.jpg

229 KB
Loading

Diff for: export_datasmith.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ def exp_blend(exp_0, exp_1, blend_type, exp_list):
190190
n.push(Node("1", exp_1))
191191
return {"expression": exp_list.push(n)}
192192

193-
194-
195193
def exp_mixrgb(node, exp_list):
196194
exp_1 = get_expression(node.inputs['Color1'], exp_list)
197195
exp_2 = get_expression(node.inputs['Color2'], exp_list)
@@ -207,16 +205,15 @@ def exp_mixrgb(node, exp_list):
207205
return exp_list.push(lerp)
208206

209207
op_custom_functions = {
210-
"HUE_SAT": "/BlenderDatasmithAdditions/MaterialFunctions/AdjustHSV",
211-
"MAPPING_TEX2D": "/BlenderDatasmithAdditions/MaterialFunctions/MappingTexture2D",
212-
"MAPPING_POINT2D": "/BlenderDatasmithAdditions/MaterialFunctions/MappingPoint2D",
213-
"LAYER_WEIGHT": "/BlenderDatasmithAdditions/MaterialFunctions/LayerWeight",
214-
"CURVE_RGB": "/BlenderDatasmithAdditions/MaterialFunctions/RGBCurveLookup",
208+
"CURVE_RGB": "/DatasmithBlenderContent/MaterialFunctions/RGBCurveLookup",
209+
"FRESNEL": "/DatasmithBlenderContent/MaterialFunctions/BlenderFresnel",
210+
"HUE_SAT": "/DatasmithBlenderContent/MaterialFunctions/AdjustHSV",
211+
"LAYER_WEIGHT": "/DatasmithBlenderContent/MaterialFunctions/LayerWeight",
212+
"MAPPING_POINT2D": "/DatasmithBlenderContent/MaterialFunctions/MappingPoint2D",
213+
"MAPPING_TEX2D": "/DatasmithBlenderContent/MaterialFunctions/MappingTexture2D",
215214
"NORMAL_FROM_HEIGHT": "/Engine/Functions/Engine_MaterialFunctions03/Procedurals/NormalFromHeightmap",
216-
"FRESNEL": "/BlenderDatasmithAdditions/MaterialFunctions/BlenderFresnel",
217215
}
218216

219-
220217
# TODO: this depends on having the material functions in UE4
221218
def exp_hsv(node, exp_list):
222219
n = Node("FunctionCall", { "Function": op_custom_functions["HUE_SAT"]})

Diff for: testing/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Testing tools
2+
In this folder there is a python script that runs the export command, with some
3+
extra steps for testing, and a powershell script that runs the command on
4+
different test files. you can use these as sample scripts for your convenience.
5+

Diff for: testing/export_all.ps1

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# build all files
3+
4+
# & blender -b archiviz/archiviz.blend -P test_datasmith_export.py
5+
# & blender -b pabellon_barcelona/pavillon_barcelone_v1_2.blend -P test_datasmith_export.py
6+
# & blender -b classroom/classroom.blend -P test_datasmith_export.py
7+
& blender -b $PSScriptRoot/the_junk_shop/the_junk_shop.blend -P $PSScriptRoot/test_datasmith_export.py
8+
# & blender -b barbershop/barbershop_interior_cpu.blend -P test_datasmith_export.py
9+
10+
# & blender -b bmw27GE\BMW27GE.blend -P test_datasmith_export.py

Diff for: testing/test_datasmith_export.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
#
3+
# datasmith export test suite
4+
# run this file with the following command:
5+
# blender -b sample_file.blend -P test_datasmith_export.py
6+
7+
import bpy.ops
8+
import bpy
9+
import os
10+
import logging
11+
import time
12+
import shutil
13+
logging_level = logging.INFO # WARNING, INFO, DEBUG
14+
# logging_level = logging.DEBUG # WARNING, INFO, DEBUG
15+
16+
logging.basicConfig(
17+
level=logging_level,
18+
# format='%(asctime)s.%(msecs)03d %(name)-12s %(levelname)-8s %(message)s',
19+
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
20+
datefmt='%Y-%m-%d %H:%M:%S'
21+
)
22+
log = logging.getLogger()
23+
24+
clean_path = os.path.normpath(bpy.data.filepath)
25+
26+
base_dir, file_name = os.path.split(clean_path)
27+
name, ext = os.path.splitext(file_name)
28+
target_path = os.path.join(base_dir, name + ".udatasmith")
29+
30+
31+
log.info("basedir %s", base_dir)
32+
use_diff = True
33+
backup_path = None
34+
if use_diff and os.path.isfile(target_path):
35+
log.info("backing up previous test")
36+
last_modification_time = os.path.getmtime(target_path)
37+
time_str = time.strftime('%Y%m%d_%H%M%S', time.localtime(last_modification_time))
38+
backup_path = os.path.join(base_dir, "%s_%s.udatasmith" % (name, time_str))
39+
log.debug("last modification was:%s", backup_path)
40+
shutil.copy(target_path, backup_path)
41+
42+
log.info("Starting automated export")
43+
44+
custom_args = {}
45+
custom_args["experimental_tex_mode"] = True
46+
custom_args["apply_modifiers"] = True
47+
48+
49+
bpy.ops.export_scene.datasmith(filepath=target_path, **custom_args)
50+
log.info("Ended automated export")
51+
52+
# right now this is not so useful as the export is non deterministic
53+
# i guess it is because the usage of dictionaries
54+
55+
if backup_path:
56+
log.info("writing diff file")
57+
import difflib
58+
59+
with open(backup_path) as ff:
60+
from_lines = ff.readlines()
61+
with open(target_path) as tf:
62+
to_lines = tf.readlines()
63+
64+
diff = difflib.unified_diff(from_lines, to_lines, backup_path, target_path)
65+
66+
new_modification_time = os.path.getmtime(target_path)
67+
new_time_str = time.strftime('%Y%m%d_%H%M%S', time.localtime(new_modification_time))
68+
diff_path = os.path.join(base_dir, "export_diff_%s.diff" % new_time_str)
69+
with open(diff_path, 'w') as diff_file:
70+
diff_file.writelines(diff)
71+
static_diff_path = os.path.join(base_dir, "export_diff.diff")
72+
shutil.copy(diff_path, static_diff_path)
73+
74+

0 commit comments

Comments
 (0)