Skip to content

Commit

Permalink
Cleanup and README update for first public release
Browse files Browse the repository at this point in the history
  • Loading branch information
0xafbf committed Dec 28, 2019
1 parent fc4165f commit 7af2bc6
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

testing/**
!testing/*
*.pyc
54 changes: 43 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
# Blender Datasmith addon
# Blender Datasmith Export

This addon lets you export your blender scene to UE4 using the Datasmith
format.
Export your Blender scene to UE4 using the Datasmith format.

You can see a brief overview of how it works here:
It aims to export all the Datasmith format supports. For now it exports:

* __Meshes__ with normals, vertex colors and UV coordinates.
* __Hierarchy__ is exported keeping meshes references, transforms, parents and
per-instance material overrides from blender.
* __Textures and materials__ are exported using data from the shader graphs.
Materials are closely approximated and a good amount of nodes are supported
(math, mix, fresnel, vertex color and others)
* __Cameras__ are exported trying to match Blender data, keeping focus
distance, focal length, and aperture
* __Lights__ are exported, keeping their type, power, color and size data.

Check out an overview of a previous version here:
https://youtu.be/bUUDqerdqAc

The plugin is currently in preview status, you can try it by [getting the
testing source build](https://github.com/0xafbf/blender-datasmith-export/archive/master.zip)
and install from the blender addons preferences pane.
## Sample:
__Blender Eevee:__
![Blender Eevee render](docs/blender.jpg)
__UE4 using Datasmith:__
![UE4 render](docs/unreal.jpg)

This result relies on the **DatasmithBlenderContent**, which is a UE4 Plugin
that improves material import compatibility. Consider supporting the project by
purchasing it from the Epic Store or Gumroad (more info coming soon)

This result is in a custom UE4 build, which fixes some issues of the UE4
importer. If you are technical to compile the engine, you can check the fork
[here][ue4 fork]. Hopefully we can get to integrate our fixes into the main
branch.
[ue4 fork]: https://github.com/0xafbf/UnrealEngine/tree/master

Now [__Download the latest version__][download_link] and install from the
Blender addons preferences pane.

[download_link]: https://github.com/0xafbf/blender-datasmith-export/archive/master.zip

If you want to support the project, also consider supporting via [Patreon],
even if it is a little it adds up.

[patreon]: https://www.patreon.com/0xafbf

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

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

4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
bl_info = {
"name": "Unreal Datasmith format",
"author": "Andrés Botero",
"version": (0, 1, 0),
"blender": (2, 80, 0),
"version": (0, 1, 1),
"blender": (2, 81, 0),
"location": "File > Export > Datasmith (.udatasmith)",
"description": "Export scene as Datasmith asset",
"warning": "",
Expand Down
Binary file added docs/blender.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/unreal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 6 additions & 9 deletions export_datasmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ def exp_blend(exp_0, exp_1, blend_type, exp_list):
n.push(Node("1", exp_1))
return {"expression": exp_list.push(n)}



def exp_mixrgb(node, exp_list):
exp_1 = get_expression(node.inputs['Color1'], exp_list)
exp_2 = get_expression(node.inputs['Color2'], exp_list)
Expand All @@ -207,16 +205,15 @@ def exp_mixrgb(node, exp_list):
return exp_list.push(lerp)

op_custom_functions = {
"HUE_SAT": "/BlenderDatasmithAdditions/MaterialFunctions/AdjustHSV",
"MAPPING_TEX2D": "/BlenderDatasmithAdditions/MaterialFunctions/MappingTexture2D",
"MAPPING_POINT2D": "/BlenderDatasmithAdditions/MaterialFunctions/MappingPoint2D",
"LAYER_WEIGHT": "/BlenderDatasmithAdditions/MaterialFunctions/LayerWeight",
"CURVE_RGB": "/BlenderDatasmithAdditions/MaterialFunctions/RGBCurveLookup",
"CURVE_RGB": "/DatasmithBlenderContent/MaterialFunctions/RGBCurveLookup",
"FRESNEL": "/DatasmithBlenderContent/MaterialFunctions/BlenderFresnel",
"HUE_SAT": "/DatasmithBlenderContent/MaterialFunctions/AdjustHSV",
"LAYER_WEIGHT": "/DatasmithBlenderContent/MaterialFunctions/LayerWeight",
"MAPPING_POINT2D": "/DatasmithBlenderContent/MaterialFunctions/MappingPoint2D",
"MAPPING_TEX2D": "/DatasmithBlenderContent/MaterialFunctions/MappingTexture2D",
"NORMAL_FROM_HEIGHT": "/Engine/Functions/Engine_MaterialFunctions03/Procedurals/NormalFromHeightmap",
"FRESNEL": "/BlenderDatasmithAdditions/MaterialFunctions/BlenderFresnel",
}


# TODO: this depends on having the material functions in UE4
def exp_hsv(node, exp_list):
n = Node("FunctionCall", { "Function": op_custom_functions["HUE_SAT"]})
Expand Down
5 changes: 5 additions & 0 deletions testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Testing tools
In this folder there is a python script that runs the export command, with some
extra steps for testing, and a powershell script that runs the command on
different test files. you can use these as sample scripts for your convenience.

10 changes: 10 additions & 0 deletions testing/export_all.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# build all files

# & blender -b archiviz/archiviz.blend -P test_datasmith_export.py
# & blender -b pabellon_barcelona/pavillon_barcelone_v1_2.blend -P test_datasmith_export.py
# & blender -b classroom/classroom.blend -P test_datasmith_export.py
& blender -b $PSScriptRoot/the_junk_shop/the_junk_shop.blend -P $PSScriptRoot/test_datasmith_export.py
# & blender -b barbershop/barbershop_interior_cpu.blend -P test_datasmith_export.py

# & blender -b bmw27GE\BMW27GE.blend -P test_datasmith_export.py
74 changes: 74 additions & 0 deletions testing/test_datasmith_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
#
# datasmith export test suite
# run this file with the following command:
# blender -b sample_file.blend -P test_datasmith_export.py

import bpy.ops
import bpy
import os
import logging
import time
import shutil
logging_level = logging.INFO # WARNING, INFO, DEBUG
# logging_level = logging.DEBUG # WARNING, INFO, DEBUG

logging.basicConfig(
level=logging_level,
# format='%(asctime)s.%(msecs)03d %(name)-12s %(levelname)-8s %(message)s',
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
log = logging.getLogger()

clean_path = os.path.normpath(bpy.data.filepath)

base_dir, file_name = os.path.split(clean_path)
name, ext = os.path.splitext(file_name)
target_path = os.path.join(base_dir, name + ".udatasmith")


log.info("basedir %s", base_dir)
use_diff = True
backup_path = None
if use_diff and os.path.isfile(target_path):
log.info("backing up previous test")
last_modification_time = os.path.getmtime(target_path)
time_str = time.strftime('%Y%m%d_%H%M%S', time.localtime(last_modification_time))
backup_path = os.path.join(base_dir, "%s_%s.udatasmith" % (name, time_str))
log.debug("last modification was:%s", backup_path)
shutil.copy(target_path, backup_path)

log.info("Starting automated export")

custom_args = {}
custom_args["experimental_tex_mode"] = True
custom_args["apply_modifiers"] = True


bpy.ops.export_scene.datasmith(filepath=target_path, **custom_args)
log.info("Ended automated export")

# right now this is not so useful as the export is non deterministic
# i guess it is because the usage of dictionaries

if backup_path:
log.info("writing diff file")
import difflib

with open(backup_path) as ff:
from_lines = ff.readlines()
with open(target_path) as tf:
to_lines = tf.readlines()

diff = difflib.unified_diff(from_lines, to_lines, backup_path, target_path)

new_modification_time = os.path.getmtime(target_path)
new_time_str = time.strftime('%Y%m%d_%H%M%S', time.localtime(new_modification_time))
diff_path = os.path.join(base_dir, "export_diff_%s.diff" % new_time_str)
with open(diff_path, 'w') as diff_file:
diff_file.writelines(diff)
static_diff_path = os.path.join(base_dir, "export_diff.diff")
shutil.copy(diff_path, static_diff_path)


0 comments on commit 7af2bc6

Please sign in to comment.