-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next and new bfu_import_module for Unreal Engine
- Loading branch information
Showing
7 changed files
with
190 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ====================== BEGIN GPL LICENSE BLOCK ============================ | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# All rights reserved. | ||
# | ||
# ======================= END GPL LICENSE BLOCK ============================= | ||
|
||
import importlib | ||
|
||
from . import asset_import | ||
from . import sequencer_import | ||
|
||
if "asset_import" in locals(): | ||
importlib.reload(asset_import) | ||
if "sequencer_import" in locals(): | ||
importlib.reload(sequencer_import) | ||
|
||
|
||
|
||
print("Import module loaded.") | ||
|
||
def run_asset_import(assets_data): | ||
pass | ||
asset_import.ImportAllAssets(assets_data) | ||
|
||
def run_sequencer_import(sequence_data): | ||
pass | ||
sequencer_import.CreateSequencer(sequence_data) |
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
71 changes: 71 additions & 0 deletions
71
blender-for-unrealengine/bfu_import_module/asset_import_script.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This script was generated with the addons Blender for UnrealEngine : https://github.com/xavier150/Blender-For-UnrealEngine-Addons | ||
# It will import into Unreal Engine all the assets of type StaticMesh, SkeletalMesh, Animation and Pose | ||
# The script must be used in Unreal Engine Editor with Python plugins : https://docs.unrealengine.com/en-US/Engine/Editor/ScriptingAndAutomation/Python | ||
# Use this command in Unreal cmd consol: py "[ScriptLocation]\asset_import_script.py" | ||
|
||
import importlib | ||
import sys | ||
import os | ||
import json | ||
|
||
def JsonLoad(json_file): | ||
# Changed in Python 3.9: The keyword argument encoding has been removed. | ||
if sys.version_info >= (3, 9): | ||
return json.load(json_file) | ||
else: | ||
return json.load(json_file, encoding="utf8") | ||
|
||
def JsonLoadFile(json_file_path): | ||
if sys.version_info[0] < 3: | ||
with open(json_file_path, "r") as json_file: | ||
return JsonLoad(json_file) | ||
else: | ||
with open(json_file_path, "r", encoding="utf8") as json_file: | ||
return JsonLoad(json_file) | ||
|
||
def load_module(import_module_path): | ||
# Import and run the module | ||
module_name = os.path.basename(import_module_path).replace('.py', '') | ||
module_dir = os.path.dirname(import_module_path) | ||
|
||
if module_dir not in sys.path: | ||
sys.path.append(module_dir) | ||
|
||
imported_module = importlib.import_module(module_name) | ||
|
||
if "bfu_import_module" in locals(): | ||
importlib.reload(imported_module) | ||
|
||
# Assuming the module has a main function to run | ||
if hasattr(imported_module, 'main'): | ||
imported_module.main() | ||
|
||
return imported_module, module_name | ||
|
||
def unload_module(module_name): | ||
# Vérifier si le module est dans sys.modules | ||
if module_name in sys.modules: | ||
# Récupérer la référence du module | ||
module = sys.modules[module_name] | ||
# Supprimer la référence globale | ||
del sys.modules[module_name] | ||
del module | ||
|
||
def RunImportScriptWithJsonData(): | ||
# Prepare process import | ||
json_data_file = 'ImportAssetData.json' | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
import_assets_data = JsonLoadFile(os.path.join(dir_path, json_data_file)) | ||
|
||
import_module_path = import_assets_data["info"]["import_modiule_path"] # Module to run | ||
print("Module path to import:", import_module_path) | ||
|
||
imported_module, module_name = load_module(import_module_path) | ||
|
||
unload_module(module_name) | ||
imported_module.run_asset_import(import_assets_data) | ||
|
||
print("Start importing assets.") | ||
RunImportScriptWithJsonData() | ||
print("Importing assets finished.") |
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
71 changes: 71 additions & 0 deletions
71
blender-for-unrealengine/bfu_import_module/sequencer_import_script.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This script was generated with the addons Blender for UnrealEngine : https://github.com/xavier150/Blender-For-UnrealEngine-Addons | ||
# It will import into Unreal Engine all the assets of type StaticMesh, SkeletalMesh, Animation and Pose | ||
# The script must be used in Unreal Engine Editor with Python plugins : https://docs.unrealengine.com/en-US/Engine/Editor/ScriptingAndAutomation/Python | ||
# Use this command in Unreal cmd consol: py "[ScriptLocation]\sequencer_import_script.py" | ||
|
||
import importlib | ||
import sys | ||
import os | ||
import json | ||
|
||
def JsonLoad(json_file): | ||
# Changed in Python 3.9: The keyword argument encoding has been removed. | ||
if sys.version_info >= (3, 9): | ||
return json.load(json_file) | ||
else: | ||
return json.load(json_file, encoding="utf8") | ||
|
||
def JsonLoadFile(json_file_path): | ||
if sys.version_info[0] < 3: | ||
with open(json_file_path, "r") as json_file: | ||
return JsonLoad(json_file) | ||
else: | ||
with open(json_file_path, "r", encoding="utf8") as json_file: | ||
return JsonLoad(json_file) | ||
|
||
def load_module(import_module_path): | ||
# Import and run the module | ||
module_name = os.path.basename(import_module_path).replace('.py', '') | ||
module_dir = os.path.dirname(import_module_path) | ||
|
||
if module_dir not in sys.path: | ||
sys.path.append(module_dir) | ||
|
||
imported_module = importlib.import_module(module_name) | ||
|
||
if "bfu_import_module" in locals(): | ||
importlib.reload(imported_module) | ||
|
||
# Assuming the module has a main function to run | ||
if hasattr(imported_module, 'main'): | ||
imported_module.main() | ||
|
||
return imported_module, module_name | ||
|
||
def unload_module(module_name): | ||
# Vérifier si le module est dans sys.modules | ||
if module_name in sys.modules: | ||
# Récupérer la référence du module | ||
module = sys.modules[module_name] | ||
# Supprimer la référence globale | ||
del sys.modules[module_name] | ||
del module | ||
|
||
def RunImportScriptWithJsonData(): | ||
# Prepare process import | ||
json_data_file = 'ImportSequencerData.json' | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
sequence_data = JsonLoadFile(os.path.join(dir_path, json_data_file)) | ||
|
||
import_module_path = sequence_data["info"]["import_modiule_path"] # Module to run | ||
print("Module path to import:", import_module_path) | ||
|
||
imported_module, module_name = load_module(import_module_path) | ||
|
||
unload_module(module_name) | ||
imported_module.run_sequencer_import(sequence_data) | ||
|
||
print("Start importing assets.") | ||
RunImportScriptWithJsonData() | ||
print("Importing assets finished.") |
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
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