Skip to content

Commit 237b3a7

Browse files
DogDog
andauthored
Add Blender Export (#67)
Co-authored-by: Dog <dog@dog.dev>
1 parent 5490ec3 commit 237b3a7

6 files changed

Lines changed: 42 additions & 5 deletions

File tree

include/NavKit/Resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define IDM_EXTRACT_SCENE_AND_BUILD_ALL 1402
4040
#define IDM_BUILD_OBJ_FROM_SCENE 1500
4141
#define IDM_BUILD_OBJ_FROM_NAVP 1501
42+
#define IDM_BUILD_BLEND_FROM_SCENE 1502
4243
#define IDM_BUILD_NAVP 1510
4344
#define IDM_BUILD_AIRG 1520
4445
#define IDM_HELP_ABOUT 1600

include/NavKit/module/Obj.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Obj {
3838
bool startedObjGeneration;
3939
bool blenderObjStarted;
4040
bool blenderObjGenerationDone;
41+
bool blendFileOnlyExtract;
4142
bool glacier2ObjDebugLogsEnabled;
4243
bool errorBuilding;
4344
bool errorExtracting;
@@ -83,8 +84,12 @@ class Obj {
8384

8485
bool canBuildObjFromScene() const;
8586

87+
bool canBuildBlendFromScene() const;
88+
8689
void handleBuildObjFromSceneClicked();
8790

91+
void handleBuildBlendFromSceneClicked();
92+
8893
void handleBuildObjFromNavpClicked();
8994

9095
void finalizeLoad();

src/NavKit.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ BEGIN
7373
MENUITEM "Build &Navp from Obj and Scene", IDM_BUILD_NAVP
7474
MENUITEM SEPARATOR
7575
MENUITEM "Build &Airg from Navp", IDM_BUILD_AIRG
76+
MENUITEM SEPARATOR
77+
MENUITEM "Build Blend from &Scene" IDM_BUILD_BLEND_FROM_SCENE
7678
END
7779

7880
POPUP "&Help"

src/module/Menu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void Menu::updateMenuState() {
103103
setMenuItemEnabled(IDM_BUILD_AIRG, airg.canBuildAirg());
104104
setMenuItemEnabled(IDM_BUILD_OBJ_FROM_SCENE, obj.canBuildObjFromScene());
105105
setMenuItemEnabled(IDM_BUILD_OBJ_FROM_NAVP, obj.canBuildObjFromNavp());
106+
setMenuItemEnabled(IDM_BUILD_BLEND_FROM_SCENE, obj.canBuildBlendFromScene());
106107

107108
setMenuItemEnabled(IDM_EXTRACT_SCENE, sceneExtract.canExtractFromGame());
108109
setMenuItemEnabled(IDM_EXTRACT_SCENE_AND_BUILD_OBJ, sceneExtract.canExtractFromGameAndBuildObj());
@@ -241,6 +242,9 @@ int Menu::handleMenuClicked(const SDL_SysWMmsg *wmMsg) {
241242
case IDM_BUILD_OBJ_FROM_NAVP:
242243
obj.handleBuildObjFromNavpClicked();
243244
break;
245+
case IDM_BUILD_BLEND_FROM_SCENE:
246+
obj.handleBuildBlendFromSceneClicked();
247+
break;
244248
case IDM_BUILD_OBJ_FROM_SCENE:
245249
obj.handleBuildObjFromSceneClicked();
246250
break;

src/module/Obj.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Obj::Obj() : loadObjName("Load Obj"),
3636
errorBuilding(false),
3737
errorExtracting(false),
3838
extractingAlocsOrPrims(false),
39+
blendFileOnlyExtract(false),
3940
doneExtractingAlocsOrPrims(false),
4041
doObjHitTest(false),
4142
meshTypeForBuild(ALOC),
@@ -168,7 +169,12 @@ void Obj::buildObj() {
168169
command += scene.lastLoadSceneFile;
169170
command += "\" \"";
170171
command += settings.outputFolder;
171-
command += "\\output.obj\"";
172+
if (!blendFileOnlyExtract) {
173+
command += "\\output.obj\"";
174+
}
175+
else {
176+
command += "\\output.blend\"";
177+
}
172178
if (meshTypeForBuild == ALOC) {
173179
command += " ALOC ";
174180
} else {
@@ -284,12 +290,13 @@ void Obj::finalizeObjBuild() {
284290
startedObjGeneration = false;
285291
objToLoad = settings.outputFolder;
286292
objToLoad += "\\" + generatedObjName;
287-
loadObj = true;
293+
loadObj = !blendFileOnlyExtract;
288294
lastObjFileName = settings.outputFolder;
289295
lastObjFileName += generatedObjName;
290296
blenderObjStarted = false;
291297
blenderObjGenerationDone = false;
292298
sceneExtract.alsoBuildObj = false;
299+
blendFileOnlyExtract = false;
293300
}
294301
if (errorBuilding) {
295302
errorBuilding = false;
@@ -299,6 +306,7 @@ void Obj::finalizeObjBuild() {
299306
objLoaded = false;
300307
sceneExtract.alsoBuildAll = false;
301308
sceneExtract.alsoBuildObj = false;
309+
blendFileOnlyExtract = false;
302310
}
303311
Menu::updateMenuState();
304312
}
@@ -437,10 +445,21 @@ bool Obj::canBuildObjFromScene() const {
437445
scene.sceneLoaded && !blenderObjStarted && !blenderObjGenerationDone;
438446
}
439447

448+
bool Obj::canBuildBlendFromScene() const {
449+
// Currently this is the same as Obj::canBuildObjFromScene.
450+
// Its expected this may change if the blend export includes features OBJ can't handle - like lights.
451+
return Obj::canBuildObjFromScene();
452+
}
453+
440454
void Obj::handleBuildObjFromSceneClicked() {
441455
backgroundWorker.emplace(&Obj::extractAlocsOrPrims, this);
442456
}
443457

458+
void Obj::handleBuildBlendFromSceneClicked() {
459+
blendFileOnlyExtract = true;
460+
backgroundWorker.emplace(&Obj::extractAlocsOrPrims, this);
461+
}
462+
444463
void Obj::handleBuildObjFromNavpClicked() {
445464
return buildObjFromNavp(true);
446465
}

src/resource/glacier2obj.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,10 +2566,16 @@ def main():
25662566
if scenario == 1:
25672567
log("INFO", 'Failed to import scenario "%s"' % scene_path , "main")
25682568
return 1
2569-
if bpy.app.version_string[0] == "3":
2570-
bpy.ops.export_scene.obj(filepath=output_path, use_selection=False)
2569+
if(output_path[-6:]=='.blend'):
2570+
log("INFO", "Attempting to save blender file to :" + output_path, "main")
2571+
bpy.ops.wm.save_as_mainfile(filepath=output_path)
25712572
else:
2572-
bpy.ops.wm.obj_export(filepath=output_path) # Export the entire scene
2573+
log("INFO", "Attempting to save obj file to :" + output_path, "main")
2574+
if bpy.app.version_string[0] == "3":
2575+
bpy.ops.export_scene.obj(filepath=output_path, use_selection=False)
2576+
else:
2577+
bpy.ops.wm.obj_export(filepath=output_path) # Export the entire scene
2578+
25732579
return None
25742580

25752581

0 commit comments

Comments
 (0)