summaryrefslogtreecommitdiffhomepage
path: root/Magic2
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-04-06 02:34:19 +0200
committerAki <please@ignore.pl>2024-04-06 02:34:19 +0200
commitfbe5f352ff0f238266bc690a0b750674f80b1f02 (patch)
tree4ec2758cc6513014b6e3ef80b2d6c01da7337c7b /Magic2
parenteffc8802a77375437b676ac4534789e819731671 (diff)
downloadstarshatter-fbe5f352ff0f238266bc690a0b750674f80b1f02.zip
starshatter-fbe5f352ff0f238266bc690a0b750674f80b1f02.tar.gz
starshatter-fbe5f352ff0f238266bc690a0b750674f80b1f02.tar.bz2
Added obj2mag and mag2obj utilities
Diffstat (limited to 'Magic2')
-rw-r--r--Magic2/MagicDoc.cpp153
1 files changed, 17 insertions, 136 deletions
diff --git a/Magic2/MagicDoc.cpp b/Magic2/MagicDoc.cpp
index 55ecd8d..c57d922 100644
--- a/Magic2/MagicDoc.cpp
+++ b/Magic2/MagicDoc.cpp
@@ -15,6 +15,7 @@
#include "Magic.h"
#include "MagicDoc.h"
+#include "MagicLoad.h"
#include "ModelFileMAG.h"
#include "ModelFileOBJ.h"
#include "ModelFile3DS.h"
@@ -22,12 +23,8 @@
#include "Selector.h"
#include "Editor.h"
#include "Command.h"
-
-#include "Bitmap.h"
-#include "Color.h"
#include "D3DXImage.h"
#include "Geometry.h"
-#include "Pcx.h"
#include "Polygon.h"
#include "Solid.h"
@@ -236,146 +233,30 @@ BOOL MagicDoc::OnOpenDocument(LPCTSTR path_name)
return TRUE;
}
+
bool
MagicDoc::ImportFile(LPCTSTR path_name)
{
if (strstr(path_name, ".obj") || strstr(path_name, ".OBJ")) {
- ModelFileOBJ obj_file(path_name);
-
- if (solid->GetModel()) {
- Solid* s = new Solid;
-
- if (s->Load(&obj_file)) {
- // todo: insert command here
- Model* orig = solid->GetModel();
- Model* imported = s->GetModel();
-
- orig->GetMaterials().append(imported->GetMaterials());
- orig->GetSurfaces().append(imported->GetSurfaces());
- orig->OptimizeMaterials();
-
- imported->GetMaterials().clear();
- imported->GetSurfaces().clear();
-
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- delete s;
- return true;
- }
-
- delete s;
- }
- else {
- if (solid->Load(&obj_file)) {
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- return true;
- }
- }
-
- return false;
+ if (!ImportInto<ModelFileOBJ>(path_name, solid))
+ return false;
+ SetModifiedFlag(FALSE);
+ UpdateAllViews(NULL);
+ return true;
}
-
if (strstr(path_name, ".3ds") || strstr(path_name, ".3DS")) {
- ModelFile3DS model_file(path_name);
-
- if (solid->GetModel()) {
- Solid* s = new Solid;
-
- if (s->Load(&model_file)) {
- // todo: insert command here
- Model* orig = solid->GetModel();
- Model* imported = s->GetModel();
-
- orig->GetMaterials().append(imported->GetMaterials());
- orig->GetSurfaces().append(imported->GetSurfaces());
- orig->OptimizeMaterials();
-
- imported->GetMaterials().clear();
- imported->GetSurfaces().clear();
-
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- delete s;
- return true;
- }
-
- delete s;
- }
- else {
- if (solid->Load(&model_file)) {
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- return true;
- }
- }
-
- return false;
- }
-
- FILE* fp = fopen(path_name, "rb");
- if (!fp) {
- ::MessageBox(0, "Import Failed: could not open file", "ERROR", MB_OK);
- return false;
- }
-
- int version = 1;
- char file_id[5];
- fread(file_id, 4, 1, fp);
- file_id[4] = '\0';
- fclose(fp);
-
- if (strncmp(file_id, "MAG", 3)) {
- ::MessageBox(0, "Open Failed: Invalid file type", "ERROR", MB_OK);
- return false;
- }
-
- switch (file_id[3]) {
- case '6': version = 6; break;
- case '5': version = 5; break;
- default: version = 0; break;
+ if (!ImportInto<ModelFile3DS>(path_name, solid))
+ return false;
+ SetModifiedFlag(FALSE);
+ UpdateAllViews(NULL);
+ return true;
}
-
- if (version < 5 || version > 6) {
- ::MessageBox(0, "Open Failed: Unsupported version", "ERROR", MB_OK);
+ if (!ImportInto<ModelFile3DS>(path_name, solid))
return false;
- }
-
- ModelFileMAG mag_file(path_name);
-
- if (solid->GetModel()) {
- Solid* s = new Solid;
- if (s->Load(&mag_file)) {
- // todo: insert command here
- Model* orig = solid->GetModel();
- Model* imported = s->GetModel();
-
- orig->GetMaterials().append(imported->GetMaterials());
- orig->GetSurfaces().append(imported->GetSurfaces());
- orig->OptimizeMaterials();
-
- imported->GetMaterials().clear();
- imported->GetSurfaces().clear();
-
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- delete s;
- return true;
- }
-
- delete s;
- }
- else {
- InitCommandStack();
-
- if (solid->Load(&mag_file)) {
- SetModifiedFlag(FALSE);
- UpdateAllViews(NULL);
- return true;
- }
- }
-
- return false;
+ InitCommandStack();
+ SetModifiedFlag(FALSE);
+ UpdateAllViews(NULL);
+ return true;
}
bool