[Bf-blender-cvs] [8c8a5a6] soc-2014-nurbs: Added 3dm import code for curves and untrimmed surfaces. Debugged issue with homogeneous coordinate differences between Rhino, Blender.
Jonathan deWerd
noreply at git.blender.org
Sun Jun 22 11:40:37 CEST 2014
Commit: 8c8a5a6dc4a958732fc5035fcf073879bb871e22
Author: Jonathan deWerd
Date: Sun Jun 22 05:33:45 2014 -0400
https://developer.blender.org/rB8c8a5a6dc4a958732fc5035fcf073879bb871e22
Added 3dm import code for curves and untrimmed surfaces. Debugged issue with homogeneous coordinate differences between Rhino, Blender.
===================================================================
M extern/opennurbs/opennurbs_brep.h
M source/blender/editors/io/CMakeLists.txt
M source/blender/editors/io/io_ops.c
D source/blender/editors/io/io_rhino.cpp
D source/blender/editors/io/io_rhino.h
A source/blender/editors/io/io_rhino_export.cpp
A source/blender/editors/io/io_rhino_export.h
A source/blender/editors/io/io_rhino_import.cpp
A source/blender/editors/io/io_rhino_import.h
===================================================================
diff --git a/extern/opennurbs/opennurbs_brep.h b/extern/opennurbs/opennurbs_brep.h
index 5bda4bc..5205b3a 100755
--- a/extern/opennurbs/opennurbs_brep.h
+++ b/extern/opennurbs/opennurbs_brep.h
@@ -1567,7 +1567,7 @@ private:
ON_Brep* m_brep;
};
-class ON_CLASS ON_Brep : public ON_Geometry
+class ON_CLASS ON_Brep : public ON_Geometry
{
ON_OBJECT_DECLARE(ON_Brep);
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 0811046..ede5bfc 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -29,6 +29,7 @@ set(INC
../../windowmanager
../../collada
../../../../extern/opennurbs
+ ../../../../intern/guardedalloc
)
set(INC_SYS
@@ -36,11 +37,13 @@ set(INC_SYS
)
set(SRC
- io_rhino.cpp
+ io_rhino_export.cpp
+ io_rhino_import.cpp
io_collada.c
io_ops.c
- io_rhino.h
+ io_rhino_export.h
+ io_rhino_import.h
io_collada.h
io_ops.h
)
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index 355c4cc..226ce68 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -30,7 +30,8 @@
#include "io_collada.h"
-#include "io_rhino.h"
+#include "io_rhino_import.h"
+#include "io_rhino_export.h"
#include "BLI_utildefines.h"
diff --git a/source/blender/editors/io/io_rhino.cpp b/source/blender/editors/io/io_rhino_export.cpp
similarity index 72%
rename from source/blender/editors/io/io_rhino.cpp
rename to source/blender/editors/io/io_rhino_export.cpp
index 99bda67..647dc51 100644
--- a/source/blender/editors/io/io_rhino.cpp
+++ b/source/blender/editors/io/io_rhino_export.cpp
@@ -46,23 +46,7 @@ extern "C" {
// #include "BLI_utildefines.h"
bool BLI_replace_extension(char *path, size_t maxlen, const char *ext);
- #include "io_rhino.h"
-}
-
-static int rhino_import(bContext *C, wmOperator *op) {
- char filename[FILE_MAX];
- FILE *f;
-
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
- BKE_report(op->reports, RPT_ERROR, "No filename given");
- return OPERATOR_CANCELLED;
- }
- RNA_string_get(op->ptr, "filepath", filename);
-
- f = ON::OpenFile(filename, "rb");
- ON::CloseFile(f);
-
- return OPERATOR_FINISHED; //OPERATOR_CANCELLED
+ #include "io_rhino_export.h"
}
static int rhino_export(bContext *C, wmOperator *op) {
@@ -84,7 +68,7 @@ static int rhino_export(bContext *C, wmOperator *op) {
/*--- Operator Registration ---*/
-static int wm_rhino_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+int wm_rhino_export_invoke(bContext *C, wmOperator *op, const struct wmEvent *evt)
{
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
char filepath[FILE_MAX];
@@ -125,21 +109,3 @@ void WM_OT_rhino_export(struct wmOperatorType *ot) {
WM_operator_properties_filesel(ot, FOLDERFILE, FILE_BLENDER, FILE_SAVE,
WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
}
-
-void WM_OT_rhino_import(struct wmOperatorType *ot) {
- ot->name = "Import Rhino 3DM";
- ot->description = "Load a Rhino-compatible .3dm file";
- ot->idname = "WM_OT_rhino_import";
-
- ot->invoke = WM_operator_filesel;
- ot->exec = rhino_import;
- ot->poll = WM_operator_winactive;
-
- RNA_def_string(ot->srna, "filter_glob", "*.3dm", 16,
- "Glob Filter", "Rhino Extension Glob Filter");
- RNA_def_string(ot->srna, "filename_ext", ".3dm", 16,
- "Rhino File Extension", "Rhino File Extension");
-
- WM_operator_properties_filesel(ot, FOLDERFILE , FILE_BLENDER, FILE_OPENFILE,
- WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
-}
diff --git a/source/blender/editors/io/io_rhino.h b/source/blender/editors/io/io_rhino_export.h
similarity index 80%
copy from source/blender/editors/io/io_rhino.h
copy to source/blender/editors/io/io_rhino_export.h
index 4d0c2fb..fbdf8f6 100644
--- a/source/blender/editors/io/io_rhino.h
+++ b/source/blender/editors/io/io_rhino_export.h
@@ -24,12 +24,17 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef __IO_RHINO_H__
-#define __IO_RHINO_H__
+#ifndef __IO_RHINO_EXPORT_H__
+#define __IO_RHINO_EXPORT_H__
+
+#include "BKE_context.h"
struct wmOperatorType;
+struct wmOperator;
+struct wmEvent;
+typedef struct wmOperator wmOperator;
void WM_OT_rhino_export(struct wmOperatorType *ot);
-void WM_OT_rhino_import(struct wmOperatorType *ot);
+int wm_rhino_export_invoke(bContext *C, wmOperator *op, const struct wmEvent *evt);
#endif
diff --git a/source/blender/editors/io/io_rhino_import.cpp b/source/blender/editors/io/io_rhino_import.cpp
new file mode 100644
index 0000000..a4e1a20
--- /dev/null
+++ b/source/blender/editors/io/io_rhino_import.cpp
@@ -0,0 +1,842 @@
+/*
+ * ***** 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 2
+ * 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, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include "opennurbs.h"
+#include <cstdio>
+#include <cstdlib>
+#include <vector>
+
+extern "C" {
+ #include "DNA_scene_types.h"
+ #include "BLF_translation.h"
+ #include "BLI_listbase.h"
+ #include "BKE_context.h"
+ #include "BKE_global.h"
+ #include "BKE_main.h"
+ #include "BKE_report.h"
+ #include "BKE_editmesh.h"
+ #include "BKE_library.h"
+ #include "BKE_curve.h"
+ #include "bmesh.h"
+ #include "ED_screen.h"
+ #include "ED_object.h"
+ #include "ED_util.h"
+ #include "ED_curve.h"
+ #include "RNA_access.h"
+ #include "RNA_define.h"
+ #include "DNA_object_types.h"
+ #include "DNA_curve_types.h"
+ #include "UI_interface.h"
+ #include "UI_resources.h"
+ #include "WM_api.h"
+ #include "WM_types.h"
+ #include "MEM_guardedalloc.h"
+ // BLI's lzma definitions don't play ball with opennurbs's zlib definitions
+ // #include "BLI_blenlib.h"
+ // #include "BLI_utildefines.h"
+ bool BLI_replace_extension(char *path, size_t maxlen, const char *ext);
+
+ #include "io_rhino_import.h"
+}
+
+/* Converts an openNURBS widestring (UTF-16) under memory management by ON
+ * into a char* to a malloc'd UTF-8 string. */
+static char *import_ON_str(ON_wString& onstr) {
+ const wchar_t *curve_name_unmanaged = onstr;
+ if (!curve_name_unmanaged) return NULL;
+ size_t sz = wcslen(curve_name_unmanaged)*sizeof(wchar_t);
+ char *ret = (char*)malloc(sz);
+ wcstombs(ret, curve_name_unmanaged, sz);
+ return ret;
+}
+static void import_ON_str(char *dest, ON_wString& onstr, size_t n) {
+ const wchar_t *curve_name_unmanaged = onstr;
+ if (!curve_name_unmanaged) {
+ *dest = '\0';
+ return;
+ }
+ wcstombs(dest, curve_name_unmanaged, n);
+}
+
+/****************************** Curve Import *********************************/
+static float null_loc[] = {0,0,0};
+static float null_rot[] = {0,0,0};
+static void rhino_import_curve(bContext *C,
+ ON_Curve *curve,
+ ON_Object *Object,
+ ON_3dmObjectAttributes *Attributes,
+ bool newobj=true,
+ bool cast_lines_to_nurbs=false);
+static void rhino_import_mesh(bContext *C,
+ ON_Mesh *curve,
+ ON_Object *Object,
+ ON_3dmObjectAttributes *Attributes,
+ bool newobj=true);
+static void rhino_import_surface(bContext *C,
+ ON_Surface *surf,
+ ON_Object *obj,
+ ON_3dmObjectAttributes *attrs,
+ bool newobj=true);
+
+// !!!!!!########$$$$$$$ todo $$$$$$#########!!!!!!!!!
+// Wrap with curve object creation code
+static void rhino_import_polycurve(bContext *C, ON_PolyCurve *pc, ON_Object *obj, ON_3dmObjectAttributes *attrs, bool newobj) {
+ char curve_name[MAX_ID_NAME];
+ import_ON_str(curve_name,attrs->m_name,MAX_ID_NAME);
+
+ // Create NURBS object in editmode
+ BLI_assert(false);
+
+ const ON_SimpleArray<ON_Curve*> &curves = pc->SegmentCurves();
+ int num_curves = curves.Count();
+ for (int i=0; i<num_curves; i++) {
+ ON_Curve *curve = *curves.At(i);
+ rhino_import_curve(C, curve, obj, attrs, false, true);
+ }
+
+ // Leave NURBS object editmode
+ printf("polycurve done\n");
+}
+
+static void rhino_import_nurbscurve(bContext *C, ON_NurbsCurve *nc, ON_Object *obj, ON_3dmObjectAttributes *attrs, bool newobj) {
+ char curve_name[MAX_ID_NAME];
+ int layer,i;
+ Object *obedit;
+ Curve *cu;
+ Nurb *nu = NULL;
+ ListBase *editnurb;
+ BPoint *bp;
+ int on_dim;
+ double *on_dat;
+ bool is_rational;
+
+ obedit = CTX_data_edit_object(C);
+ layer = attrs->m_layer_index;
+ if (newobj) {
+ import_ON_str(curve_name,attrs->m_name,MAX_ID_NAME);
+ if (layer==0) layer = 1;
+ //Exit editmode if we're in it
+ if (obedit) {
+ ED_object_editmode_load(obedit);
+ BLI_assert(!CTX_data_edit_object(C));
+ }
+ obedit = ED_object_add_type(C, OB_CURVE, null_loc, null_rot, true, layer);
+ rename_id((ID *)obedit, curve_name);
+ rename_id((ID *)obedit->data, curve_name);
+ cu = (Curve*)obedit->data;
+ cu->resolu = 15;
+ cu->resolv = 1;
+ } else {
+ cu = (Curve*)obedit->data;
+ }
+
+ nu = (Nurb *)MEM_callocN(sizeof(Nurb), "rhino_imported_NURBS_curve");
+ nu->flag = CU_3D;
+ nu->type = CU_NURBS;
+ nu->resolu = cu->resolu;
+ nu->resolv = cu->resolv;
+ nu->pntsu = nc->CVCount();
+ nu->pntsv = 1;
+ nu->orderu = nc->Order();
+ nu->orderv = 1;
+ if (nc->IsPeriodic())
+ nu->flagu = CU_NURB_CYCLIC;
+ if (nc->IsClamped())
+ nu->flagu = CU_NURB_ENDPOINT;
+ BLI_assert(nu->pntsu + nu->orderu - 2 == nc->KnotCount());
+ bp = nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * ((nu->pntsu) * 1), "rhino_imported_NURBS_curve_points");
+ nu->knotsu = (float *)MEM_callocN(siz
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list