[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16002] branches/soc-2008-mxcurioni/source /blender: soc-2008-mxcurioni: first version of lib3ds code.

Maxime Curioni maxime.curioni at gmail.com
Thu Aug 7 17:04:26 CEST 2008


Revision: 16002
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16002
Author:   mxcurioni
Date:     2008-08-07 17:04:25 +0200 (Thu, 07 Aug 2008)

Log Message:
-----------
soc-2008-mxcurioni: first version of lib3ds code. It does NOT work yet and has to be debugged. It can be activate in app_blender/api.cpp by replacing the FRS_scene_3ds_export call in FRS_prepare, by FRS_load_mesh.

All of the reference to the original Material class were renamed to FrsMaterial to resolve a name collision with Blender. To keep the window context necessary to draw the strokes after RE_Database_FromScene has been called, the display_clear function is used.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLDebugRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLDebugRenderer.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLMonoColorRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLMonoColorRenderer.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLRenderer.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLSelectRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLSelectRenderer.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/MaxFileLoader.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/NodeShape.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/NodeShape.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/Rep.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Curve.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeTesselator.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapIO.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapTesselator.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/BlenderFileLoader.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/BlenderFileLoader.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/FrsMaterial.h

Removed Paths:
-------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/Material.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2008-08-07 15:04:25 UTC (rev 16002)
@@ -64,6 +64,8 @@
 
 #include "../system/StringUtils.h"
 
+#include "../scene_graph/BlenderFileLoader.h"
+
 Controller::Controller()
 {
 	
@@ -168,7 +170,108 @@
   _Canvas->setViewer(_pView);
 }
 
+int Controller::LoadMesh(Render *re)
+{
+  if (_pView)
+    _pView->setUpdateMode(false);
+  
+  BlenderFileLoader loader(re);
+  
+  _Chrono.start();
+  
+  NodeGroup *blenderScene = loader.Load();
 
+  if (blenderScene == NULL) {
+	cout << "Cannot load scene" << endl;
+    return 1;
+  }
+
+  cout << "Scene loaded\n" << endl;
+
+  printf("Mesh cleaning    : %lf\n", _Chrono.stop());
+  _SceneNumFaces += loader.numFacesRead();
+
+  if(loader.minEdgeSize() < _minEdgeSize)
+    {
+      _minEdgeSize = loader.minEdgeSize();
+      _EPSILON = _minEdgeSize*1e-6;
+      if(_EPSILON < DBL_MIN)
+	_EPSILON = 0.0;
+    }
+
+  cout << "Epsilon computed : " << _EPSILON << endl;
+
+  // DEBUG
+//   ScenePrettyPrinter spp;
+//   blenderScene->accept(spp);
+	
+  _RootNode->AddChild(blenderScene);
+  _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
+
+  _pView->setModel(_RootNode);
+  //_pView->FitBBox();
+
+
+  _Chrono.start();
+
+  
+  WXEdgeBuilder wx_builder;
+  blenderScene->accept(wx_builder);
+  _winged_edge = wx_builder.getWingedEdge();
+
+  printf("WEdge building   : %lf\n", _Chrono.stop());
+
+ _Chrono.start();
+
+  _Grid.clear();
+  Vec3r size;
+  for(unsigned int i=0; i<3; i++)
+    {
+      size[i] = fabs(_RootNode->bbox().getMax()[i] - _RootNode->bbox().getMin()[i]);
+      size[i] += size[i]/10.0; // let make the grid 1/10 bigger to avoid numerical errors while computing triangles/cells intersections
+      if(size[i]==0){
+          cout << "Warning: the bbox size is 0 in dimension "<<i<<endl;
+      }
+    }
+  _Grid.configure(Vec3r(_RootNode->bbox().getMin() - size / 20.0), size,
+		  _SceneNumFaces);
+
+  // Fill in the grid:
+  WFillGrid fillGridRenderer(&_Grid, _winged_edge);
+  fillGridRenderer.fillGrid();
+
+  printf("Grid building    : %lf\n", _Chrono.stop());
+  
+  // DEBUG
+//   _Grid.displayDebug();
+   
+  _pView->setDebug(_DebugNode);
+
+  //delete stuff
+  //  if(0 != ws_builder)
+  //    {
+  //      delete ws_builder;
+  //      ws_builder = 0;
+  //    }
+  _pView->updateGL();
+  
+
+	//soc QFileInfo qfi(iFileName);
+	//soc string basename((const char*)qfi.fileName().toAscii().data());
+	// char cleaned[FILE_MAX];
+	// BLI_strncpy(cleaned, iFileName, FILE_MAX);
+	// BLI_cleanup_file(NULL, cleaned);
+	// string basename = StringUtils::toAscii( string(cleaned) );
+
+  _ListOfModels.push_back("Blender_models");
+
+  cout << "Triangles nb     : " << _SceneNumFaces << endl;
+  _bboxDiag = (_RootNode->bbox().getMax()-_RootNode->bbox().getMin()).norm();
+  cout << "Bounding Box     : " << _bboxDiag << endl;
+  return 0;
+}
+
+
 int Controller::Load3DSFile(const char *iFileName)
 {
   if (_pView)
@@ -649,6 +752,8 @@
   _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON);
   _ViewMap->setScene3dBBox(_RootNode->bbox());
   
+	printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size() );
+
   //Tesselate the 3D edges:
   _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
   _SilhouetteNode->addRef();
@@ -953,9 +1058,9 @@
                                        vector<ViewEdge*>::iterator vedges_end)
 {
   ViewMapTesselator2D tesselator2D;
-  Material mat;
+  FrsMaterial mat;
   mat.setDiffuse(1,1,0.3,1);
-  tesselator2D.setMaterial(mat);
+  tesselator2D.setFrsMaterial(mat);
 
   return (tesselator2D.Tesselate(vedges_begin, vedges_end));
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h	2008-08-07 15:04:25 UTC (rev 16002)
@@ -51,6 +51,16 @@
 class InteractiveShader;
 class Shader;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+	#include "render_types.h"
+
+#ifdef __cplusplus
+}
+#endif
+
 class Controller
 {
 public:
@@ -62,6 +72,7 @@
   //soc
 	void init_options();
 
+	int  LoadMesh( Render *re );
   int  Load3DSFile(const char *iFileName);
   void CloseFile();
   void LoadViewMapFile(const char *iFileName, bool only_camera = false);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp	2008-08-07 15:04:25 UTC (rev 16002)
@@ -14,6 +14,7 @@
 #include "renderpipeline.h"
 
 #include "BLI_blenlib.h"
+#include "BIF_renderwin.h"
 #include "BPY_extern.h"
 
 #ifdef __cplusplus
@@ -103,6 +104,10 @@
 		}
 	}
 	
+	void FRS_load_mesh( Render *re ){
+		controller->LoadMesh(re);
+	}
+	
 	void FRS_prepare(Render* re) {
 		FRS_initialize();
 		
@@ -110,15 +115,12 @@
 		FRS_init_camera(re);
 		
 		FRS_scene_3ds_export(re);
+		//FRS_load_mesh(re);
 	}
 
 	void FRS_render(Render* re, int render_in_layer) {
 		
-		if(render_in_layer) {
-			view->workingBuffer = GL_COLOR_ATTACHMENT1_EXT;
-		} else {
-			view->workingBuffer = GL_BACK;
-		}
+		view->workingBuffer = GL_BACK;
 		
 		// add style module
 		cout << "Module: " << style_module << endl;
@@ -185,8 +187,13 @@
 			}
 			
 		} else {
-			FRS_render(re, render_in_layer);
+			// used to reobtain ogl context after RE_Database_FromScene call
+			re->display_clear(re->result);
 			
+			// render strokes
+			FRS_render(re, render_in_layer);		
+			
+			// display result
 			RenderResult rres;
 			RE_GetResultImage(re, &rres);
 			view->readPixels(0, 0, re->winx, re->winy, AppGLWidget::RGBA, rres.rectf );		

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp	2008-08-07 15:04:25 UTC (rev 16002)
@@ -190,9 +190,9 @@
 	return py_vs;
 }
 
-PyObject * BPy_FrsMaterial_from_Material( Material& m ){
+PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m ){
 	PyObject *py_m = FrsMaterial_Type.tp_new( &FrsMaterial_Type, 0, 0 );
-	((BPy_FrsMaterial*) py_m)->m = new Material( m );
+	((BPy_FrsMaterial*) py_m)->m = new FrsMaterial( m );
 
 	return py_m;
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h	2008-08-07 15:04:25 UTC (rev 16002)
@@ -20,8 +20,8 @@
 // Interface1D
 #include "../view_map/Interface1D.h"
 
-// Material
-#include "../scene_graph/Material.h"
+// FrsMaterial
+#include "../scene_graph/FrsMaterial.h"
 
 // Nature::VertexNature, Nature::EdgeNature
 #include "../winged_edge/Nature.h"
@@ -78,7 +78,7 @@
 PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
 PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
 PyObject * BPy_IntegrationType_from_IntegrationType( int i );
-PyObject * BPy_FrsMaterial_from_Material( Material& m );
+PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
 PyObject * BPy_Nature_from_Nature( unsigned short n );
 PyObject * BPy_MediumType_from_MediumType( int n );
 PyObject * BPy_SShape_from_SShape( SShape& ss );

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp	2008-08-07 15:04:25 UTC (rev 16002)
@@ -180,17 +180,17 @@
         return -1;
 
 	if( !obj1 ){
-		self->m = new Material();
+		self->m = new FrsMaterial();
 
 	} else if( BPy_FrsMaterial_Check(obj1) ) {
 		if( ((BPy_FrsMaterial *) obj1)->m )
-			self->m = new Material(*( ((BPy_FrsMaterial *) obj1)->m ));
+			self->m = new FrsMaterial(*( ((BPy_FrsMaterial *) obj1)->m ));
 		else
 			return -1;
 
 	} else if( PyFloat_Check(obj1) ) {
 		f1 = PyFloat_AsDouble(obj1);
-		self->m = new Material(&f1, &f2, &f3, &f4, f5);
+		self->m = new FrsMaterial(&f1, &f2, &f3, &f4, f5);
 
 	} else {
 		return -1;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.h	2008-08-07 15:03:52 UTC (rev 16001)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.h	2008-08-07 15:04:25 UTC (rev 16002)
@@ -1,7 +1,7 @@
 #ifndef FREESTYLE_PYTHON_FRSMATERIAL_H
 #define FREESTYLE_PYTHON_FRSMATERIAL_H
 
-#include "../scene_graph/Material.h"
+#include "../scene_graph/FrsMaterial.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -18,7 +18,7 @@
 /*---------------------------Python BPy_FrsMaterial structure definition----------*/
 typedef struct {
 	PyObject_HEAD
-	Material *m;
+	FrsMaterial *m;
 } BPy_FrsMaterial;
 
 /*---------------------------Python BPy_FrsMaterial visible prototypes-----------*/

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp	2008-08-07 15:03:52 UTC (rev 16001)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list