Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/freestyle/intern/scene_graph')
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/DrawingStyle.h82
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp321
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/IndexedFaceSet.h222
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/LineRep.cpp58
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/LineRep.h130
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/Material.h304
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/MaxFileLoader.cpp388
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/MaxFileLoader.h94
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/Node.h97
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeCamera.cpp119
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeCamera.h192
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp34
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h70
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeGroup.cpp122
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeGroup.h84
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeLight.cpp80
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeLight.h86
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeShape.cpp51
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeShape.h89
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeTransform.cpp166
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/NodeTransform.h107
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp31
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/OrientedLineRep.h67
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/Rep.cpp1
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/Rep.h127
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp86
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h105
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/SceneVisitor.cpp1
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/SceneVisitor.h98
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/TriangleRep.cpp59
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/TriangleRep.h106
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/VertexRep.cpp29
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/VertexRep.h87
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/scene_graph.pro86
-rwxr-xr-xsource/blender/freestyle/intern/scene_graph/src.pri41
35 files changed, 3820 insertions, 0 deletions
diff --git a/source/blender/freestyle/intern/scene_graph/DrawingStyle.h b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h
new file mode 100755
index 00000000000..e2be6fa8264
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h
@@ -0,0 +1,82 @@
+//
+// Filename : DrawingStyle.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to define the drawing style of a node
+// Date of creation : 10/10/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef DRAWINGSTYLE_H
+# define DRAWINGSTYLE_H
+
+class DrawingStyle
+{
+public:
+ enum STYLE
+ {FILLED, LINES, POINTS, INVISIBLE};
+
+ inline DrawingStyle() {Style = FILLED; LineWidth = 2.f; PointSize = 2.f; LightingEnabled = true;}
+ inline explicit DrawingStyle(const DrawingStyle& iBrother);
+
+ virtual ~DrawingStyle() {}
+
+ /*! operators */
+ inline DrawingStyle& operator=(const DrawingStyle& ds);
+
+ inline void SetStyle(const STYLE iStyle) {Style = iStyle;}
+ inline void SetLineWidth(const float iLineWidth) {LineWidth = iLineWidth;}
+ inline void SetPointSize(const float iPointSize) {PointSize = iPointSize;}
+ inline void SetLightingEnabled(const bool on) {LightingEnabled = on;}
+
+ inline STYLE style() const {return Style;}
+ inline float lineWidth() const {return LineWidth;}
+ inline float pointSize() const {return PointSize;}
+ inline bool lightingEnabled() const {return LightingEnabled;}
+
+private:
+ STYLE Style;
+ float LineWidth;
+ float PointSize;
+ bool LightingEnabled;
+};
+
+DrawingStyle::DrawingStyle(const DrawingStyle& iBrother)
+{
+ Style = iBrother.Style;
+ LineWidth = iBrother.LineWidth;
+ PointSize = iBrother.PointSize;
+ LightingEnabled = iBrother.LightingEnabled;
+}
+
+DrawingStyle& DrawingStyle::operator=(const DrawingStyle& ds)
+{
+ Style = ds.Style;
+ LineWidth = ds.LineWidth;
+ PointSize = ds.PointSize;
+ LightingEnabled = ds.LightingEnabled;
+
+ return *this;
+}
+
+#endif // DRAWINGSTYLE_H
diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
new file mode 100755
index 00000000000..ec3d3ad748c
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
@@ -0,0 +1,321 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "IndexedFaceSet.h"
+
+IndexedFaceSet::IndexedFaceSet()
+: Rep()
+{
+ _Vertices = NULL;
+ _Normals = NULL;
+ _Materials = 0;
+ _TexCoords = 0;
+ _VSize = 0;
+ _NSize = 0;
+ _MSize = 0;
+ _TSize = 0;
+ _NumFaces = 0;
+ _NumVertexPerFace = NULL;
+ _FaceStyle = NULL;
+ _VIndices = NULL;
+ _VISize = 0;
+ _NIndices = NULL;
+ _NISize = 0;
+ _MIndices = NULL;
+ _MISize = 0;
+ _TIndices = NULL;
+ _TISize = 0;
+ _displayList = 0;
+}
+
+IndexedFaceSet::IndexedFaceSet( real *iVertices, unsigned iVSize,
+ real *iNormals, unsigned iNSize,
+ Material **iMaterials, unsigned iMSize,
+ real *iTexCoords, unsigned iTSize,
+ unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle,
+ unsigned *iVIndices, unsigned iVISize,
+ unsigned *iNIndices, unsigned iNISize,
+ unsigned *iMIndices, unsigned iMISize,
+ unsigned *iTIndices, unsigned iTISize,
+ unsigned iCopy)
+ : Rep()
+{
+ if(1 == iCopy)
+ {
+ _VSize = iVSize;
+ _Vertices = new real[_VSize];
+ memcpy(_Vertices, iVertices, iVSize*sizeof(real));
+
+ _NSize = iNSize;
+ _Normals = new real[_NSize];
+ memcpy(_Normals, iNormals, iNSize*sizeof(real));
+
+ _MSize = iMSize;
+ _Materials = 0;
+ if(iMaterials){
+ _Materials = new Material*[_MSize];
+ for(unsigned i=0; i<_MSize; ++i)
+ _Materials[i] = new Material(*(iMaterials[i]));
+ }
+ _TSize = iTSize;
+ _TexCoords = 0;
+ if(_TSize){
+ _TexCoords = new real[_TSize];
+ memcpy(_TexCoords, iTexCoords, iTSize*sizeof(real));
+ }
+
+ _NumFaces = iNumFaces;
+ _NumVertexPerFace = new unsigned[_NumFaces];
+ memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces*sizeof(unsigned));
+
+ _FaceStyle = new TRIANGLES_STYLE[_NumFaces];
+ memcpy(_FaceStyle, iFaceStyle, _NumFaces*sizeof(TRIANGLES_STYLE));
+
+ _VISize = iVISize;
+ _VIndices = new unsigned[_VISize];
+ memcpy(_VIndices, iVIndices, _VISize*sizeof(unsigned));
+
+ _NISize = iNISize;
+ _NIndices = new unsigned[_NISize];
+ memcpy(_NIndices, iNIndices, _NISize*sizeof(unsigned));
+
+ _MISize = iMISize;
+ _MIndices = 0;
+ if(iMIndices){
+ _MIndices = new unsigned[_MISize];
+ memcpy(_MIndices, iMIndices, _MISize*sizeof(unsigned));
+ }
+ _TISize = iTISize;
+ _TIndices = 0;
+ if(_TISize){
+ _TIndices = new unsigned[_TISize];
+ memcpy(_TIndices, iTIndices, _TISize*sizeof(unsigned));
+ }
+ }
+ else
+ {
+ _VSize = iVSize;
+ _Vertices = iVertices;
+
+ _NSize = iNSize;
+ _Normals = iNormals;
+
+ _MSize = iMSize;
+ _Materials = 0;
+ if(iMaterials)
+ _Materials = iMaterials;
+
+ _TSize = iTSize;
+ _TexCoords = iTexCoords;
+
+ _NumFaces = iNumFaces;
+ _NumVertexPerFace = iNumVertexPerFace;
+ _FaceStyle = iFaceStyle;
+
+ _VISize = iVISize;
+ _VIndices = iVIndices;
+
+ _NISize = iNISize;
+ _NIndices = iNIndices;
+
+ _MISize = iMISize;
+ _MIndices = 0;
+ if(iMISize)
+ _MIndices = iMIndices;
+
+ _TISize = iTISize;
+ _TIndices = iTIndices;
+ }
+
+ _displayList = 0;
+}
+
+IndexedFaceSet::IndexedFaceSet( const IndexedFaceSet& iBrother)
+:Rep(iBrother)
+{
+ _VSize = iBrother.vsize();
+ _Vertices = new real[_VSize];
+ memcpy(_Vertices, iBrother.vertices(), _VSize*sizeof(real));
+
+ _NSize = iBrother.nsize();
+ _Normals = new real[_NSize];
+ memcpy(_Normals, iBrother.normals(), _NSize*sizeof(real));
+
+ _MSize = iBrother.msize();
+ if(_MSize){
+ _Materials = new Material*[_MSize];
+ for(unsigned i=0; i<_MSize; ++i){
+ _Materials[i] = new Material(*(iBrother._Materials[i]));
+ }
+ }else{
+ _Materials = 0;
+ }
+
+ _TSize = iBrother.tsize();
+ _TexCoords = 0;
+ if(_TSize){
+ _TexCoords = new real[_TSize];
+ memcpy(_TexCoords, iBrother.texCoords(), _TSize*sizeof(real));
+ }
+
+ _NumFaces = iBrother.numFaces();
+ _NumVertexPerFace = new unsigned[_NumFaces];
+ memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces*sizeof(unsigned));
+
+ _FaceStyle = new TRIANGLES_STYLE[_NumFaces];
+ memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces*sizeof(TRIANGLES_STYLE));
+
+ _VISize = iBrother.visize();
+ _VIndices = new unsigned[_VISize];
+ memcpy(_VIndices, iBrother.vindices(), _VISize*sizeof(unsigned));
+
+ _NISize = iBrother.nisize();
+ _NIndices = new unsigned[_NISize];
+ memcpy(_NIndices, iBrother.nindices(), _NISize*sizeof(unsigned));
+
+ _MISize = iBrother.misize();
+ if(_MISize){
+ _MIndices = new unsigned[_MISize];
+ memcpy(_MIndices, iBrother.mindices(), _MISize*sizeof(unsigned));
+ }else{
+ _MIndices=0;
+ }
+
+ _TISize = iBrother.tisize();
+ _TIndices = 0;
+ if(_TISize){
+ _TIndices = new unsigned[_TISize];
+ memcpy(_TIndices, iBrother.tindices(), _TISize*sizeof(unsigned));
+ }
+
+ _displayList = 0;
+}
+
+IndexedFaceSet::~IndexedFaceSet()
+{
+ if(NULL != _Vertices)
+ {
+ delete [] _Vertices;
+ _Vertices = NULL;
+ }
+
+ if(NULL != _Normals)
+ {
+ delete [] _Normals;
+ _Normals = NULL;
+ }
+
+ if(NULL != _Materials)
+ {
+ for(unsigned i=0; i<_MSize; ++i)
+ delete _Materials[i];
+ delete [] _Materials;
+ _Materials = NULL;
+ }
+
+ if(NULL != _TexCoords)
+ {
+ delete [] _TexCoords;
+ _TexCoords = NULL;
+ }
+
+ if(NULL != _NumVertexPerFace)
+ {
+ delete [] _NumVertexPerFace;
+ _NumVertexPerFace = NULL;
+ }
+
+ if(NULL != _FaceStyle)
+ {
+ delete [] _FaceStyle;
+ _FaceStyle = NULL;
+ }
+
+ if(NULL != _VIndices)
+ {
+ delete [] _VIndices;
+ _VIndices = NULL;
+ }
+
+ if(NULL != _NIndices)
+ {
+ delete [] _NIndices;
+ _NIndices = NULL;
+ }
+
+ if(NULL != _MIndices)
+ {
+ delete [] _MIndices;
+ _MIndices = NULL;
+ }
+ if(NULL != _TIndices)
+ {
+ delete [] _TIndices;
+ _TIndices = NULL;
+ }
+ // should find a way to deallocates the displayList
+ // glDeleteLists(GLuint list, GLSizei range)
+ _displayList = 0;
+}
+
+void IndexedFaceSet::accept(SceneVisitor& v) {
+ Rep::accept(v);
+ v.visitIndexedFaceSet(*this);
+}
+
+void IndexedFaceSet::ComputeBBox()
+{
+ real XMax = _Vertices[0];
+ real YMax = _Vertices[1];
+ real ZMax = _Vertices[2];
+
+ real XMin = _Vertices[0];
+ real YMin = _Vertices[1];
+ real ZMin = _Vertices[2];
+
+ // parse all the coordinates to find
+ // the Xmax, YMax, ZMax
+ real *v = _Vertices;
+
+ for(unsigned i=0; i<_VSize/3; i++)
+ {
+ // X
+ if(*v > XMax)
+ XMax = *v;
+ if(*v < XMin)
+ XMin = *v;
+ v++;
+
+ if(*v > YMax)
+ YMax = *v;
+ if(*v < YMin)
+ YMin = *v;
+ v++;
+
+ if(*v > ZMax)
+ ZMax = *v;
+ if(*v < ZMin)
+ ZMin = *v;
+ v++;
+ }
+
+ SetBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax)));
+}
diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
new file mode 100755
index 00000000000..c6951942dbb
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
@@ -0,0 +1,222 @@
+//
+// Filename : IndexedFaceSet.h
+// Author(s) : Stephane Grabli
+// Purpose : A Set of indexed faces to represent a surfacic object
+// Date of creation : 22/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef INDEXEDFACESET_H
+# define INDEXEDFACESET_H
+
+# include <stdio.h>
+# include <memory.h>
+
+//! inherits from class Rep
+# include "Rep.h"
+
+# include "../system/FreestyleConfig.h"
+
+class LIB_SCENE_GRAPH_EXPORT IndexedFaceSet : public Rep
+ {
+public:
+
+ /*! Triangles description style:*/
+ enum TRIANGLES_STYLE{TRIANGLE_STRIP, TRIANGLE_FAN, TRIANGLES};
+
+ /*! Builds an empty indexed face set
+ */
+ IndexedFaceSet();
+ /*! Builds an indexed face set
+ iVertices
+ The array of object vertices 3D coordinates (for all faces).
+ If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not.
+ iVSize
+ The size of iVertices (must be a multiple of 3)
+ iNormals
+ The array of object normals 3D coordinates.
+ If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not.
+ iNSize
+ The size of iNormals
+ iMaterials
+ The array of materials
+ iMSize
+ The size of iMaterials
+ iTexCoords
+ The array of texture coordinates.
+ iTSize
+ The size of iTexCoords (must be multiple of 2)
+ iNumFaces
+ The number of faces
+ iNumVertexPerFace
+ Array containing the number of vertices per face.
+ iFaceStyle
+ Array containing the description style of each faces.
+ The style belongs to:
+ - TRIANGLE_STRIP: the face indices describe a triangle strip
+ - TRIANGLE_FAN : the face indices describe a triangle fan
+ - TRIANGLES : the face indices describe single triangles
+ If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not.
+ iVIndices,
+ Array of vertices indices.
+ The integers contained in this array must be multiple of 3.
+ If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not.
+ iVISize
+ The size of iVIndices.
+ iNIndices
+ Array of normals indices.
+ The integers contained in this array must be multiple of 3.
+ If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not.
+ iNISize
+ The size of iNIndices
+ iMIndices
+ The Material indices (per vertex)
+ iMISize
+ The size of iMIndices
+ iTIndices
+ The Texture coordinates indices (per vertex). The integers contained in this array must be multiple of 2.
+ iTISize
+ The size of iMIndices
+ iCopy
+ 0 : the arrays are not copied. The pointers passed as arguments are used.
+ IndexedFaceSet takes these arrays desallocation in charge.
+ 1 : the arrays are copied. The caller is in charge of the arrays, passed
+ as arguments desallocation.
+ */
+ IndexedFaceSet( real *iVertices, unsigned iVSize,
+ real *iNormals, unsigned iNSize,
+ Material **iMaterials, unsigned iMSize,
+ real *iTexCoords, unsigned iTSize,
+ unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle,
+ unsigned *iVIndices, unsigned iVISize,
+ unsigned *iNIndices, unsigned iNISize,
+ unsigned *iMIndices, unsigned iMISize,
+ unsigned *iTIndices, unsigned iTISize,
+ unsigned iCopy = 1
+ );
+
+ /*! Builds an indexed face set from an other indexed face set */
+ IndexedFaceSet(const IndexedFaceSet& iBrother);
+
+ void swap(IndexedFaceSet& ioOther){
+ std::swap(_Vertices, ioOther._Vertices);
+ std::swap(_Normals, ioOther._Normals);
+ std::swap(_Materials, ioOther._Materials);
+ std::swap(_TexCoords, ioOther._TexCoords);
+
+ std::swap(_VSize, ioOther._VSize);
+ std::swap(_NSize, ioOther._NSize);
+ std::swap(_MSize, ioOther._MSize);
+ std::swap(_TSize, ioOther._TSize);
+
+ std::swap(_NumFaces, ioOther._NumFaces);
+ std::swap(_NumVertexPerFace, ioOther._NumVertexPerFace);
+ std::swap(_FaceStyle, ioOther._FaceStyle);
+
+ std::swap(_VIndices, ioOther._VIndices);
+ std::swap(_NIndices, ioOther._NIndices);
+ std::swap(_MIndices, ioOther._MIndices); // Material Indices
+ std::swap(_TIndices, ioOther._TIndices);
+
+ std::swap(_VISize, ioOther._VISize);
+ std::swap(_NISize, ioOther._NISize);
+ std::swap(_MISize, ioOther._MISize);
+ std::swap(_TISize, ioOther._TISize);
+
+ std::swap(_displayList, ioOther._displayList);
+
+ Rep::swap(ioOther);
+ }
+
+ IndexedFaceSet& operator=(const IndexedFaceSet& iBrother){
+ IndexedFaceSet tmp(iBrother);
+ swap(tmp);
+ return *this;
+ }
+
+ /*! Desctructor
+ desallocates all the ressources */
+ virtual ~IndexedFaceSet();
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Compute the Bounding Box */
+ virtual void ComputeBBox();
+
+ /*! modifiers */
+ inline void SetDisplayList(unsigned int index) {_displayList = index;}
+
+ /*! Accessors */
+ virtual const real * vertices() const {return _Vertices;}
+ virtual const real * normals() const {return _Normals;}
+ virtual const Material*const* materials() const {return _Materials;}
+ virtual const real* texCoords() const {return _TexCoords;}
+ virtual const unsigned vsize() const {return _VSize;}
+ virtual const unsigned nsize() const {return _NSize;}
+ virtual const unsigned msize() const {return _MSize;}
+ virtual const unsigned tsize() const {return _TSize;}
+ virtual const unsigned numFaces() const {return _NumFaces;}
+ virtual const unsigned * numVertexPerFaces() const {return _NumVertexPerFace;}
+ virtual const TRIANGLES_STYLE * trianglesStyle() const {return _FaceStyle;}
+ virtual const unsigned* vindices() const {return _VIndices;}
+ virtual const unsigned* nindices() const {return _NIndices;}
+ virtual const unsigned* mindices() const {return _MIndices;}
+ virtual const unsigned* tindices() const {return _TIndices;}
+ virtual const unsigned visize() const {return _VISize;}
+ virtual const unsigned nisize() const {return _NISize;}
+ virtual const unsigned misize() const {return _MISize;}
+ virtual const unsigned tisize() const {return _TISize;}
+ inline unsigned int displayList() const {return _displayList;}
+
+protected:
+ real *_Vertices;
+ real *_Normals;
+ Material** _Materials;
+ real *_TexCoords;
+
+ unsigned _VSize;
+ unsigned _NSize;
+ unsigned _MSize;
+ unsigned _TSize;
+
+ unsigned _NumFaces;
+ unsigned *_NumVertexPerFace;
+ TRIANGLES_STYLE *_FaceStyle;
+
+ unsigned *_VIndices;
+ unsigned *_NIndices;
+ unsigned *_MIndices; // Material Indices
+ unsigned *_TIndices; // Texture coordinates Indices
+
+ unsigned _VISize;
+ unsigned _NISize;
+ unsigned _MISize;
+ unsigned _TISize;
+
+ unsigned int _displayList;
+
+};
+
+#endif // INDEXEDFACESET_H
diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.cpp b/source/blender/freestyle/intern/scene_graph/LineRep.cpp
new file mode 100755
index 00000000000..9dec2ec803f
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/LineRep.cpp
@@ -0,0 +1,58 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "LineRep.h"
+
+void LineRep::ComputeBBox()
+{
+ real XMax = _vertices.front()[0];
+ real YMax = _vertices.front()[1];
+ real ZMax = _vertices.front()[2];
+
+ real XMin = _vertices.front()[0];
+ real YMin = _vertices.front()[1];
+ real ZMin = _vertices.front()[2];
+
+ // parse all the coordinates to find
+ // the XMax, YMax, ZMax
+ vector<Vec3r>::iterator v;
+ for(v=_vertices.begin(); v!=_vertices.end(); v++) {
+ // X
+ if((*v)[0] > XMax)
+ XMax = (*v)[0];
+ if((*v)[0] < XMin)
+ XMin = (*v)[0];
+
+ // Y
+ if((*v)[1] > YMax)
+ YMax = (*v)[1];
+ if((*v)[1] < YMin)
+ YMin = (*v)[1];
+
+ // Z
+ if((*v)[2] > ZMax)
+ ZMax = (*v)[2];
+ if((*v)[2] < ZMin)
+ ZMin = (*v)[2];
+ }
+
+ SetBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax)));
+}
diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.h b/source/blender/freestyle/intern/scene_graph/LineRep.h
new file mode 100755
index 00000000000..1bbba130ba3
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/LineRep.h
@@ -0,0 +1,130 @@
+//
+// Filename : LineRep.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to define the representation of 3D Line.
+// Date of creation : 26/03/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef LINEREP_H
+# define LINEREP_H
+
+# include <vector>
+# include <list>
+# include "Rep.h"
+# include "../system/FreestyleConfig.h"
+
+using namespace std;
+
+/*! Base class for all lines objects */
+class LIB_SCENE_GRAPH_EXPORT LineRep : public Rep
+{
+public:
+
+ /*! Line description style */
+ enum LINES_STYLE{LINES, LINE_STRIP, LINE_LOOP};
+ inline LineRep() : Rep() {_width = 0.f;}
+
+ /*! Builds a single line from 2 vertices
+ * v1
+ * first vertex
+ * v2
+ * second vertex
+ */
+ inline LineRep(const Vec3r& v1, const Vec3r& v2)
+ : Rep()
+ {
+ SetStyle(LINES);
+ AddVertex(v1);
+ AddVertex(v2);
+ _width = 0.f;
+ }
+
+ /*! Builds a line rep from a vertex chain */
+ inline LineRep(const vector<Vec3r>& vertices)
+ : Rep()
+ {
+ _vertices = vertices;
+ SetStyle(LINE_STRIP);
+ _width = 0.f;
+ }
+
+ /*! Builds a line rep from a vertex chain */
+ inline LineRep(const list<Vec3r>& vertices)
+ : Rep()
+ {
+ for(list<Vec3r>::const_iterator v=vertices.begin(), end=vertices.end();
+ v!=end;
+ v++)
+ {
+ _vertices.push_back(*v);
+ }
+ SetStyle(LINE_STRIP);
+ _width = 0.f;
+ }
+
+ virtual ~LineRep()
+ {
+ _vertices.clear();
+ }
+
+ /*! accessors */
+ inline const LINES_STYLE style() const {return _Style;}
+ inline const vector<Vec3r>& vertices() const {return _vertices;}
+ inline float width() const {return _width;}
+
+ /*! modifiers */
+ inline void SetStyle(const LINES_STYLE iStyle) {_Style = iStyle;}
+ inline void AddVertex(const Vec3r& iVertex) {_vertices.push_back(iVertex);}
+ inline void SetVertices(const vector<Vec3r>& iVertices)
+ {
+ if(0 != _vertices.size())
+ {
+ _vertices.clear();
+ }
+ for(vector<Vec3r>::const_iterator v=iVertices.begin(), end=iVertices.end();
+ v!=end;
+ v++)
+ {
+ _vertices.push_back(*v);
+ }
+ }
+ inline void SetWidth(float iWidth) {_width=iWidth;}
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v) {
+ Rep::accept(v);
+ v.visitLineRep(*this);
+ }
+
+ /*! Computes the line bounding box.*/
+ virtual void ComputeBBox();
+
+private:
+ LINES_STYLE _Style;
+ vector<Vec3r> _vertices;
+ float _width;
+};
+
+#endif // LINEREP_H
diff --git a/source/blender/freestyle/intern/scene_graph/Material.h b/source/blender/freestyle/intern/scene_graph/Material.h
new file mode 100755
index 00000000000..09557ad3473
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/Material.h
@@ -0,0 +1,304 @@
+//
+// Filename : Material.h
+// Author(s) : Stephane Grabli
+// Purpose : Class used to handle materials.
+// Date of creation : 10/10/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef MATERIAL_H
+# define MATERIAL_H
+
+# include "../system/FreestyleConfig.h"
+
+/*! Class defining a material */
+class Material
+{
+public:
+ /*! Default constructor */
+ inline Material();
+ /*! Builds a Material from its diffuse, ambiant, specular, emissive
+ * colors and a shininess coefficient.
+ * \param iDiffuse
+ * A 4 element float-array containing the diffuse color.
+ * \param iAmbiant
+ * A 4 element float-array containing the ambiant color.
+ * \param iSpecular
+ * A 4 element float-array containing the specular color.
+ * \param iEmission
+ * A 4 element float-array containing the emissive color.
+ * \param iShininess
+ * The shininess coefficient.
+ */
+ inline Material(const float *iDiffuse,
+ const float *iAmbiant,
+ const float *iSpecular,
+ const float *iEmission,
+ const float iShininess);
+
+ /*! Copy constructor */
+ inline Material(const Material& m);
+ /*! Destructor */
+ virtual ~Material() {}
+
+
+ /*! Returns the diffuse color as a 4 float array */
+ inline const float * diffuse() const { return Diffuse; }
+ /*! Returns the red component of the diffuse color */
+ inline const float diffuseR() const { return Diffuse[0]; }
+ /*! Returns the green component of the diffuse color */
+ inline const float diffuseG() const { return Diffuse[1]; }
+ /*! Returns the blue component of the diffuse color */
+ inline const float diffuseB() const { return Diffuse[2]; }
+ /*! Returns the alpha component of the diffuse color */
+ inline const float diffuseA() const { return Diffuse[3]; }
+
+ /*! Returns the specular color as a 4 float array */
+ inline const float * specular() const { return Specular; }
+ /*! Returns the red component of the specular color */
+ inline const float specularR() const { return Specular[0]; }
+ /*! Returns the green component of the specular color */
+ inline const float specularG() const { return Specular[1]; }
+ /*! Returns the blue component of the specular color */
+ inline const float specularB() const { return Specular[2]; }
+ /*! Returns the alpha component of the specular color */
+ inline const float specularA() const { return Specular[3]; }
+
+ /*! Returns the ambiant color as a 4 float array */
+ inline const float * ambient() const { return Ambient; }
+ /*! Returns the red component of the ambiant color */
+ inline const float ambientR() const { return Ambient[0]; }
+ /*! Returns the green component of the ambiant color */
+ inline const float ambientG() const { return Ambient[1]; }
+ /*! Returns the blue component of the ambiant color */
+ inline const float ambientB() const { return Ambient[2]; }
+ /*! Returns the alpha component of the ambiant color */
+ inline const float ambientA() const { return Ambient[3]; }
+
+ /*! Returns the emissive color as a 4 float array */
+ inline const float * emission() const { return Emission; }
+ /*! Returns the red component of the emissive color */
+ inline const float emissionR() const { return Emission[0]; }
+ /*! Returns the green component of the emissive color */
+ inline const float emissionG() const { return Emission[1]; }
+ /*! Returns the blue component of the emissive color */
+ inline const float emissionB() const { return Emission[2]; }
+ /*! Returns the alpha component of the emissive color */
+ inline const float emissionA() const { return Emission[3]; }
+
+ /*! Returns the shininess coefficient */
+ inline const float shininess() const { return Shininess; }
+
+ /*! Sets the diffuse color.
+ * \param r
+ * Red component
+ * \param g
+ * Green component
+ * \param b
+ * Blue component
+ * \param a
+ * Alpha component
+ */
+ inline void SetDiffuse(const float r, const float g, const float b, const float a);
+ /*! Sets the specular color.
+ * \param r
+ * Red component
+ * \param g
+ * Green component
+ * \param b
+ * Blue component
+ * \param a
+ * Alpha component
+ */
+ inline void SetSpecular(const float r, const float g, const float b, const float a);
+ /*! Sets the ambiant color.
+ * \param r
+ * Red component
+ * \param g
+ * Green component
+ * \param b
+ * Blue component
+ * \param a
+ * Alpha component
+ */
+ inline void SetAmbient(const float r, const float g, const float b, const float a);
+
+ /*! Sets the emissive color.
+ * \param r
+ * Red component
+ * \param g
+ * Green component
+ * \param b
+ * Blue component
+ * \param a
+ * Alpha component
+ */
+ inline void SetEmission(const float r, const float g, const float b, const float a);
+
+ /*! Sets the shininess.
+ * \param s
+ * Shininess
+ */
+ inline void SetShininess(const float s);
+
+ /* operators */
+ inline Material& operator=(const Material& m);
+ inline bool operator!=(const Material& m) const;
+ inline bool operator==(const Material& m) const;
+
+private:
+
+ /*! Material properties */
+ float Diffuse[4];
+ float Specular[4];
+ float Ambient[4];
+ float Emission[4];
+ float Shininess;
+
+};
+
+Material::Material()
+{
+ Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
+ Ambient[3] = 1.f;
+
+ Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f;
+ Diffuse[3] = 1.f;
+
+ Emission[0] = Emission[1] = Emission[2] = 0.f;
+ Emission[3] = 1.f;
+
+ Specular[0] = Specular[1] = Specular[2] = 0.f;
+ Specular[3] = 1.f;
+
+ Shininess = 0.f;
+}
+
+Material::Material(const float *iDiffuse,
+ const float *iAmbiant,
+ const float *iSpecular,
+ const float *iEmission,
+ const float iShininess)
+{
+ for(int i=0; i<4; i++)
+ {
+ Diffuse[i] = iDiffuse[i];
+ Specular[i] = iSpecular[i];
+ Ambient[i] = iAmbiant[i];
+ Emission[i] = iEmission[i];
+ }
+
+ Shininess = iShininess;
+}
+
+Material::Material(const Material& m)
+{
+ for(int i=0; i<4; i++)
+ {
+ Diffuse[i] = m.diffuse()[i];
+ Specular[i] = m.specular()[i];
+ Ambient[i] = m.ambient()[i];
+ Emission[i] = m.emission()[i];
+ }
+
+ Shininess = m.shininess();
+}
+
+void Material::SetDiffuse(const float r, const float g, const float b, const float a)
+{
+ Diffuse[0] = r;
+ Diffuse[1] = g;
+ Diffuse[2] = b;
+ Diffuse[3] = a;
+}
+
+void Material::SetSpecular(const float r, const float g, const float b, const float a)
+{
+ Specular[0] = r;
+ Specular[1] = g;
+ Specular[2] = b;
+ Specular[3] = a;
+}
+
+void Material::SetAmbient(const float r, const float g, const float b, const float a)
+{
+ Ambient[0] = r;
+ Ambient[1] = g;
+ Ambient[2] = b;
+ Ambient[3] = a;
+}
+
+void Material::SetEmission(const float r, const float g, const float b, const float a)
+{
+ Emission[0] = r;
+ Emission[1] = g;
+ Emission[2] = b;
+ Emission[3] = a;
+}
+
+void Material::SetShininess(const float s)
+{
+ Shininess = s;
+}
+
+Material& Material::operator=(const Material& m)
+{
+ for(int i=0; i<4; i++)
+ {
+ Diffuse[i] = m.diffuse()[i];
+ Specular[i] = m.specular()[i];
+ Ambient[i] = m.ambient()[i];
+ Emission[i] = m.emission()[i];
+ }
+
+ Shininess = m.shininess();
+
+ return *this;
+}
+
+bool Material::operator!=(const Material& m) const
+{
+ if(Shininess != m.shininess())
+ return true;
+ for(int i=0; i<4; i++)
+ {
+ if(Diffuse[i] != m.diffuse()[i])
+ return true;
+ if(Specular[i] != m.specular()[i])
+ return true;
+ if(Ambient[i] != m.ambient()[i])
+ return true;
+ if(Emission[i] != m.emission()[i])
+ return true;
+ }
+
+ return false;
+}
+
+bool Material::operator==(const Material& m) const
+{
+ return (!((*this)!=m));
+}
+
+#endif // MATERIAL_H
diff --git a/source/blender/freestyle/intern/scene_graph/MaxFileLoader.cpp b/source/blender/freestyle/intern/scene_graph/MaxFileLoader.cpp
new file mode 100755
index 00000000000..515874c4021
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/MaxFileLoader.cpp
@@ -0,0 +1,388 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "MaxFileLoader.h"
+
+MaxFileLoader::MaxFileLoader()
+{
+ _FileName = NULL;
+ _3dsFile = NULL;
+ _Scene = NULL;
+ _numFacesRead = 0;
+ _minEdgeSize = DBL_MAX;
+}
+
+MaxFileLoader::MaxFileLoader(const char *iFileName)
+{
+ _FileName = new char[strlen(iFileName)+1];
+ strcpy(_FileName, iFileName);
+
+ _3dsFile = NULL;
+ _Scene = NULL;
+ _numFacesRead = 0;
+ _minEdgeSize = DBL_MAX;
+}
+
+MaxFileLoader::~MaxFileLoader()
+{
+ if(NULL != _FileName)
+ {
+ delete [] _FileName;
+ _FileName = NULL;
+ }
+
+ if(NULL != _3dsFile)
+ {
+ lib3ds_file_free(_3dsFile);
+ _3dsFile = NULL;
+ }
+
+ _Scene = NULL;
+}
+
+void MaxFileLoader::SetFileName(const char *iFileName)
+{
+ if(NULL != _FileName)
+ delete [] _FileName;
+
+ _FileName = new char[strlen(iFileName)+1];
+ strcpy(_FileName, iFileName);
+}
+
+NodeGroup* MaxFileLoader::Load()
+{
+ _3dsFile=lib3ds_file_load(_FileName);
+ if(NULL == _3dsFile)
+ return NULL;
+
+ /* No nodes? Fabricate nodes to display all the meshes. */
+ if( !_3dsFile->nodes )
+ {
+ Lib3dsMesh *mesh;
+ Lib3dsNode *node;
+
+ for(mesh = _3dsFile->meshes; mesh != NULL; mesh = mesh->next)
+ {
+ node = lib3ds_node_new_object();
+ strcpy(node->name, mesh->name);
+ node->parent_id = LIB3DS_NO_PARENT;
+ node->data.object.scl_track.keyL = lib3ds_lin3_key_new();
+ node->data.object.scl_track.keyL->value[0] = 1.;
+ node->data.object.scl_track.keyL->value[1] = 1.;
+ node->data.object.scl_track.keyL->value[2] = 1.;
+ lib3ds_file_insert_node(_3dsFile, node);
+ }
+ }
+
+ lib3ds_file_eval(_3dsFile, 0);
+
+ // creation of the scene root node
+ _Scene = new NodeGroup;
+
+ // converts the 3ds format to the scene format
+ // the RenderNode method modifies _Scene.
+ Lib3dsNode *p;
+ for (p=_3dsFile->nodes; p!=0; p=p->next) {
+ RenderNode(p);
+ }
+ //Returns the built scene.
+ return _Scene;
+}
+
+void lib3ds_normal_transform(Lib3dsVector c, Lib3dsMatrix m, Lib3dsVector a)
+{
+ c[0]= (m[0][0]*a[0] + m[1][0]*a[1] + m[2][0]*a[2]);
+ c[1]= (m[0][1]*a[0] + m[1][1]*a[1] + m[2][1]*a[2]);
+ c[2]= (m[0][2]*a[0] + m[1][2]*a[1] + m[2][2]*a[2]);
+
+ // c[0]= (m[0][0]*a[0] + m[1][0]*a[1] + m[2][0]*a[2])/m[0][0];
+ // c[1]= (m[0][1]*a[0] + m[1][1]*a[1] + m[2][1]*a[2])/m[1][1];
+ // c[2]= (m[0][2]*a[0] + m[1][2]*a[1] + m[2][2]*a[2])/m[2][2];
+
+ //lib3ds_vector_normalize(c);
+
+ // c[0] = c[0]*m[0][0];
+ // c[1] = c[1]*m[1][1];
+ // c[2] = c[2]*m[2][2];
+
+}
+
+
+
+void MaxFileLoader::RenderNode(Lib3dsNode *iNode)
+{
+ Lib3dsNode *p;
+ for (p=iNode->childs; p!=0; p=p->next)
+ RenderNode(p);
+
+ float minBBox[3];
+ float maxBBox[3];
+ if (iNode->type==LIB3DS_OBJECT_NODE)
+ {
+ if (strcmp(iNode->name,"$$$DUMMY")==0)
+ return;
+
+ NodeTransform *currentMesh = new NodeTransform;
+ NodeShape * shape;
+
+ if (!iNode->user.d) // If the shape is not built yet, just do it !
+ {
+ Lib3dsMesh *mesh=lib3ds_file_mesh_by_name(_3dsFile, iNode->name);
+ ASSERT(mesh);
+ if (!mesh)
+ return;
+
+ // builds the shape:
+ shape = new NodeShape;
+ iNode->user.d=(unsigned long)shape; // We store as user data the NodeShape address
+
+ // We invert the matrix in order to
+ // be able to retrieve the shape's coordinates
+ // in its local coordinates system (origin is the iNode pivot)
+ Lib3dsMatrix M;
+ lib3ds_matrix_copy(M, mesh->matrix);
+ lib3ds_matrix_inv(M);
+
+ // We compute a normal per vertex and manages the smoothing of the shape:
+ Lib3dsVector *normalL=(Lib3dsVector*)malloc(3*sizeof(Lib3dsVector)*mesh->faces);
+ lib3ds_mesh_calculate_normals(mesh, normalL);
+
+ // We build the rep:
+ IndexedFaceSet *rep;
+ unsigned numFaces = mesh->faces;
+
+ unsigned vSize = 3*3*numFaces;
+ float *vertices = new float[vSize];
+ unsigned nSize = vSize;
+ float *normals = new float[nSize];
+ unsigned *numVertexPerFaces = new unsigned[numFaces];
+ vector<Material> meshMaterials;
+
+ IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces];
+ unsigned i;
+ for (i = 0; i <numFaces; i++) {
+ faceStyle[i] = IndexedFaceSet::TRIANGLES;
+ numVertexPerFaces[i] = 3;
+ }
+
+ unsigned viSize = 3*numFaces;
+ unsigned *VIndices = new unsigned[viSize];
+ unsigned niSize = viSize;
+ unsigned *NIndices = new unsigned[niSize];
+ unsigned *MIndices = new unsigned[viSize]; // Material Indices
+
+
+ float *pv = vertices;
+ float *pn = normals;
+ unsigned *pvi = VIndices;
+ unsigned *pni = NIndices;
+ unsigned *pmi = MIndices;
+
+ unsigned currentIndex = 0;
+ unsigned currentMIndex = 0;
+
+ Material tmpMat;
+
+ // we want to find the min and max coordinates as we build the rep.
+ // We initialize the min and max values whith the first vertex.
+ float pvtmp[3];
+ lib3ds_vector_transform(pvtmp, M, mesh->pointL[mesh->faceL[0].points[0]].pos);
+ minBBox[0] = pvtmp[0];
+ maxBBox[0] = pvtmp[0];
+ minBBox[1] = pvtmp[1];
+ maxBBox[1] = pvtmp[1];
+ minBBox[2] = pvtmp[2];
+ maxBBox[2] = pvtmp[2];
+
+ unsigned p;
+ real vert[3][3];
+ real norm;
+ for(p=0; p<mesh->faces; ++p) // we parse the faces of the mesh
+ {
+ Lib3dsFace *f=&mesh->faceL[p];
+ Lib3dsMaterial *mat=0;
+ if (f->material[0])
+ mat=lib3ds_file_material_by_name(_3dsFile, f->material);
+
+ if (mat)
+ {
+ tmpMat.SetDiffuse(mat->diffuse[0], mat->diffuse[1], mat->diffuse[2], mat->diffuse[3]);
+ tmpMat.SetSpecular(mat->specular[0], mat->specular[1], mat->specular[2], mat->specular[3]);
+ float s = (float)pow(2.0, 10.0*mat->shininess);
+ if(s > 128.f)
+ s = 128.f;
+ tmpMat.SetShininess(s);
+ }
+
+ if(meshMaterials.empty()){
+ meshMaterials.push_back(tmpMat);
+ shape->SetMaterial(tmpMat);
+ }else{
+ // find if the material is aleady in the list
+ unsigned i=0;
+ bool found = false;
+ for(vector<Material>::iterator it=meshMaterials.begin(), itend=meshMaterials.end();
+ it!=itend;
+ ++it){
+ if(*it == tmpMat){
+ currentMIndex = i;
+ found = true;
+ break;
+ }
+ ++i;
+ }
+ if(!found){
+ meshMaterials.push_back(tmpMat);
+ currentMIndex = meshMaterials.size()-1;
+ }
+ }
+
+
+ for(i=0; i<3; ++i) // we parse the vertices of the face f
+ {
+ unsigned j;
+ lib3ds_vector_transform(pv, M, mesh->pointL[f->points[i]].pos); //fills the cells of the pv array
+ for(j=0; j<3; j++) // we parse the xyz coordinates of the vertex i
+ {
+ if(minBBox[j] > pv[j])
+ minBBox[j] = pv[j];
+
+ if(maxBBox[j] < pv[j])
+ maxBBox[j] = pv[j];
+
+ vert[i][j] = pv[j];
+ }
+
+ for(j=0; j<3; j++)
+ pn[j] = f->normal[j];
+
+ lib3ds_normal_transform(pn, M, normalL[3*p+i]); //fills the cells of the pv array
+ //lib3ds_vector_normalize(pn);
+
+
+ *pvi = currentIndex;
+ *pni = currentIndex;
+ *pmi = currentMIndex;
+
+
+ currentIndex +=3;
+ pv += 3;
+ pn += 3;
+ pvi++;
+ pni++;
+ pmi++;
+
+ }
+
+ for(i=0; i<3; i++)
+ {
+ norm = 0.0;
+ for (unsigned j = 0; j < 3; j++)
+ norm += (vert[i][j] - vert[(i+1)%3][j])*(vert[i][j] - vert[(i+1)%3][j]);
+ norm = sqrt(norm);
+ if(_minEdgeSize > norm)
+ _minEdgeSize = norm;
+ }
+
+ _numFacesRead++;
+ }
+
+ free(normalL);
+
+ // We might have several times the same vertex. We want a clean
+ // shape with no real-vertex. Here, we are making a cleaning
+ // pass.
+ real *cleanVertices = NULL;
+ unsigned cvSize;
+ unsigned *cleanVIndices = NULL;
+
+ GeomCleaner::CleanIndexedVertexArray(
+ vertices, vSize,
+ VIndices, viSize,
+ &cleanVertices, &cvSize,
+ &cleanVIndices);
+
+ real *cleanNormals = NULL;
+ unsigned cnSize;
+ unsigned *cleanNIndices = NULL;
+
+ GeomCleaner::CleanIndexedVertexArray(
+ normals, nSize,
+ NIndices, niSize,
+ &cleanNormals, &cnSize,
+ &cleanNIndices);
+
+ // format materials array
+ Material** marray = new Material*[meshMaterials.size()];
+ unsigned mindex=0;
+ for(vector<Material>::iterator m=meshMaterials.begin(), mend=meshMaterials.end();
+ m!=mend;
+ ++m){
+ marray[mindex] = new Material(*m);
+ ++mindex;
+ }
+ // deallocates memory:
+ delete [] vertices;
+ delete [] normals;
+ delete [] VIndices;
+ delete [] NIndices;
+
+ // Create the IndexedFaceSet with the retrieved attributes
+ rep = new IndexedFaceSet(cleanVertices, cvSize,
+ cleanNormals, cnSize,
+ marray, meshMaterials.size(),
+ 0, 0,
+ numFaces, numVertexPerFaces, faceStyle,
+ cleanVIndices, viSize,
+ cleanNIndices, niSize,
+ MIndices, viSize,
+ 0,0,
+ 0);
+ // sets the id of the rep
+ rep->SetId(Id(iNode->node_id, 0));
+
+
+ const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(minBBox[0], minBBox[1], minBBox[2]),
+ Vec3r(maxBBox[0], maxBBox[1], maxBBox[2]));
+ rep->SetBBox(bbox);
+ shape->AddRep(rep);
+ }
+
+ if (iNode->user.d)
+ {
+ if(NULL != iNode->matrix)
+ {
+ Lib3dsObjectData *d = &iNode->data.object;
+ Matrix44r M44f;
+ for(unsigned i=0; i<4; i++)
+ for(unsigned j=0; j<4; j++)
+ M44f(i,j) = iNode->matrix[j][i];
+
+ currentMesh->SetMatrix(Matrix44r(M44f));
+ currentMesh->Translate(-d->pivot[0], -d->pivot[1], -d->pivot[2]);
+ }
+ shape = (NodeShape*)iNode->user.d;
+ currentMesh->AddChild(shape);
+ _Scene->AddChild(currentMesh);
+ }
+ }
+
+}
diff --git a/source/blender/freestyle/intern/scene_graph/MaxFileLoader.h b/source/blender/freestyle/intern/scene_graph/MaxFileLoader.h
new file mode 100755
index 00000000000..ab31e656d46
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/MaxFileLoader.h
@@ -0,0 +1,94 @@
+//
+// Filename : MaxFileLoader.h
+// Author(s) : Stephane Grabli
+// Purpose : Class used to load 3ds models.
+// Date of creation : 10/10/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef MAX_FILE_LOADER_H
+# define MAX_FILE_LOADER_H
+
+# include <string.h>
+# include <float.h>
+# include <lib3ds/file.h>
+# include <lib3ds/node.h>
+# include <lib3ds/camera.h>
+# include <lib3ds/mesh.h>
+# include <lib3ds/material.h>
+# include <lib3ds/matrix.h>
+# include <lib3ds/vector.h>
+# include <lib3ds/file.h>
+# include "../system/FreestyleConfig.h"
+# include "NodeGroup.h"
+# include "NodeTransform.h"
+# include "NodeShape.h"
+# include "IndexedFaceSet.h"
+# include "../geometry/BBox.h"
+# include "../geometry/Geom.h"
+# include "../geometry/GeomCleaner.h"
+
+
+class NodeGroup;
+
+class LIB_SCENE_GRAPH_EXPORT MaxFileLoader
+{
+public:
+ /*! Builds a MaxFileLoader */
+ MaxFileLoader();
+ /*! Builds a MaxFileLoader to load the iFileName
+ file.
+ iFileName
+ The name of the 3dsMax file to load
+ */
+ explicit MaxFileLoader(const char *iFileName);
+ virtual ~MaxFileLoader();
+
+ /*! Sets the name of the 3dsMax file to load */
+ void SetFileName(const char *iFileName);
+
+ /*! Loads the 3D scene and returns
+ * a pointer to the scene root node
+ */
+ NodeGroup * Load();
+ //void Load(const char *iFileName);
+
+ /*! Gets the number of read faces */
+ inline unsigned int numFacesRead() {return _numFacesRead;}
+
+ /*! Gets the smallest edge size read */
+ inline real minEdgeSize() {return _minEdgeSize;}
+
+protected:
+ void RenderNode(Lib3dsNode *iNode);
+
+protected:
+ char *_FileName;
+ Lib3dsFile *_3dsFile;
+ NodeGroup* _Scene;
+ unsigned _numFacesRead;
+ real _minEdgeSize;
+};
+
+#endif // MAX_FILE_LOADER_H
diff --git a/source/blender/freestyle/intern/scene_graph/Node.h b/source/blender/freestyle/intern/scene_graph/Node.h
new file mode 100755
index 00000000000..1726dd3c853
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/Node.h
@@ -0,0 +1,97 @@
+//
+// Filename : Node.h
+// Author(s) : Stephane Grabli
+// Purpose : Abstract class for scene graph nodes. Inherits from
+// BaseObject which defines the addRef release mechanism.
+// Date of creation : 24/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODE_H
+# define NODE_H
+
+# include "../system/FreestyleConfig.h"
+# include "../system/BaseObject.h"
+# include "SceneVisitor.h"
+# include "../geometry/BBox.h"
+# include "../geometry/Geom.h"
+# include "../system/Precision.h"
+
+using namespace std;
+using namespace Geometry;
+
+class LIB_SCENE_GRAPH_EXPORT Node : public BaseObject
+{
+public:
+
+ inline Node() : BaseObject() {}
+ inline Node(const Node& iBrother) : BaseObject()
+ {
+ _BBox = iBrother.bbox();
+ }
+ virtual ~Node(){}
+
+ /*! Accept the corresponding visitor
+ * Each inherited node
+ * must overload this method
+ */
+ virtual void accept(SceneVisitor& v) {
+ v.visitNode(*this);
+ }
+
+ /*! bounding box management */
+ /*! Returns the node bounding box
+ * If no bounding box exists, an empty bbox
+ * is returned
+ */
+ virtual const BBox<Vec3r>& bbox() const {return _BBox;}
+
+ /*! Sets the Node bounding box */
+ virtual void SetBBox(const BBox<Vec3r>& iBox) {_BBox = iBox;}
+
+ /*! Makes the union of _BBox and iBox */
+ virtual void AddBBox(const BBox<Vec3r>& iBox)
+ {
+ if(iBox.empty())
+ return;
+
+ if(_BBox.empty())
+ _BBox = iBox;
+ else
+ _BBox += iBox;
+ }
+
+ /*! Updates the BBox */
+ virtual const BBox<Vec3r>& UpdateBBox() {return _BBox;}
+
+ /*! Clears the bounding box */
+ virtual void clearBBox() { _BBox.clear(); }
+
+protected:
+
+private:
+ BBox<Vec3r> _BBox;
+};
+
+#endif // NODE_H
diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp
new file mode 100644
index 00000000000..2d850287ae5
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp
@@ -0,0 +1,119 @@
+#include "NodeCamera.h"
+#include <math.h>
+
+void loadIdentity(double * matrix){
+ int i;
+
+ // Build Identity matrix
+ for(i=0;i<16;++i){
+ double value ;
+ if((i % 5) == 0)
+ value = 1.0;
+ else
+ value = 0;
+ matrix[i] = value;
+ }
+}
+
+NodeCamera::NodeCamera(CameraType camera_type)
+:camera_type_(camera_type){
+ loadIdentity(modelview_matrix_);
+ loadIdentity(projection_matrix_);
+}
+
+NodeCamera::NodeCamera(const NodeCamera& iBrother)
+:camera_type_(iBrother.camera_type_){
+ memcpy(modelview_matrix_, iBrother.modelview_matrix_, 16*sizeof(double));
+ memcpy(projection_matrix_, iBrother.projection_matrix_, 16*sizeof(double));
+}
+
+void NodeCamera::accept(SceneVisitor& v){
+ v.visitNodeCamera(*this) ;
+}
+
+void NodeCamera::setModelViewMatrix(double modelview_matrix[16]){
+ memcpy(modelview_matrix_, modelview_matrix,16*sizeof(double));
+}
+
+void NodeCamera::setProjectionMatrix(double projection_matrix[16]){
+ memcpy(projection_matrix_, projection_matrix,16*sizeof(double));
+}
+
+NodeOrthographicCamera::NodeOrthographicCamera()
+:NodeCamera(NodeCamera::ORTHOGRAPHIC),
+left_(0),right_(0),bottom_(0),top_(0),zNear_(0),zFar_(0){
+ loadIdentity(projection_matrix_);
+ loadIdentity(modelview_matrix_);
+}
+
+NodeOrthographicCamera::NodeOrthographicCamera(double left
+ , double right
+ , double bottom
+ , double top
+ , double zNear
+ , double zFar
+ )
+:NodeCamera(NodeCamera::ORTHOGRAPHIC),
+left_(left),
+right_(right),
+bottom_(bottom),
+top_(top),
+zNear_(zNear),
+zFar_(zFar){
+
+ loadIdentity(projection_matrix_);
+
+ projection_matrix_[0] = 2.0/(right-left);
+ projection_matrix_[3] = -(right + left) / (right - left) ;
+ projection_matrix_[5] = 2.0/(top-bottom);
+ projection_matrix_[7] = -(top + bottom) / (top - bottom) ;
+ projection_matrix_[10] = -2.0/(zFar-zNear);
+ projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear);
+
+}
+
+NodeOrthographicCamera::NodeOrthographicCamera(const NodeOrthographicCamera& iBrother)
+:NodeCamera(iBrother),left_(iBrother.left_),right_(iBrother.right_),bottom_(iBrother.bottom_),top_(iBrother.top_),zNear_(iBrother.zNear_),zFar_(iBrother.zFar_){
+}
+
+NodePerspectiveCamera::NodePerspectiveCamera()
+:NodeCamera(NodeCamera::PERSPECTIVE){
+}
+
+NodePerspectiveCamera::NodePerspectiveCamera(double fovy
+ , double aspect
+ , double zNear
+ , double zFar)
+:NodeCamera(NodeCamera::PERSPECTIVE){
+ loadIdentity(projection_matrix_);
+
+ double f = cos(fovy/2.0)/sin(fovy/2.0); // cotangent
+
+ projection_matrix_[0] = f/aspect;
+ projection_matrix_[5] = f;
+ projection_matrix_[10] = (zNear+zFar)/(zNear-zFar);
+ projection_matrix_[11] = (2.0*zNear*zFar)/(zNear-zFar);
+ projection_matrix_[14] = -1.0;
+ projection_matrix_[15] = 0;
+
+}
+
+NodePerspectiveCamera::NodePerspectiveCamera(double left,
+ double right,
+ double bottom,
+ double top,
+ double zNear,
+ double zFar)
+:NodeCamera(NodeCamera::PERSPECTIVE){
+ loadIdentity(projection_matrix_);
+
+ projection_matrix_[0] = (2.0*zNear)/(right-left);
+ projection_matrix_[2] = (right+left)/(right-left);
+ projection_matrix_[5] = (2.0*zNear)/(top-bottom);
+ projection_matrix_[6] = (top+bottom)/(top-bottom);
+ projection_matrix_[10] = - (zFar+zNear)/(zFar-zNear);
+ projection_matrix_[11] = - (2.0*zFar*zNear)/(zFar-zNear);
+ projection_matrix_[14] = -1.0;
+ projection_matrix_[15] = 0;
+}
+
diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h b/source/blender/freestyle/intern/scene_graph/NodeCamera.h
new file mode 100644
index 00000000000..76ccf465d38
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h
@@ -0,0 +1,192 @@
+//
+// Filename : NodeCamera.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to represent a light node
+// Date of creation : 25/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef NODE_CAMERA_H_
+#define NODE_CAMERA_H_
+
+# include "../geometry/Geom.h"
+# include "../system/FreestyleConfig.h"
+# include "Node.h"
+
+using namespace Geometry;
+
+class NodeOrthographicCamera;
+class NodePerspectiveCamera;
+class LIB_SCENE_GRAPH_EXPORT NodeCamera : public Node
+{
+public:
+ typedef enum {PERSPECTIVE,ORTHOGRAPHIC,GENERIC} CameraType;
+
+ /*! Default matrices: Identity for both projection and modelview. */
+ NodeCamera(CameraType camera_type = GENERIC);
+ NodeCamera(const NodeCamera& iBrother);
+
+ virtual ~NodeCamera() {}
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Matrix is copied */
+ void setModelViewMatrix(double modelview_matrix[16]);
+ /*! Matrix is copied */
+ void setProjectionMatrix(double projection_matrix[16]);
+
+ double * modelViewMatrix() {return modelview_matrix_;}
+ double * projectionMatrix() {return projection_matrix_;}
+
+protected:
+ // row major right handed matrix
+ double modelview_matrix_[16];
+ // row major right handed matrix
+ double projection_matrix_[16];
+
+ CameraType camera_type_;
+};
+
+class LIB_SCENE_GRAPH_EXPORT NodeOrthographicCamera : public NodeCamera{
+public:
+ NodeOrthographicCamera();
+ /*! Builds a parallel projection matrix a la glOrtho.
+ A 0 0 tx
+ 0 B 0 ty
+ 0 0 C tz
+ 0 0 0 1
+
+ where
+
+ A =
+ 2 / (right - left)
+ B =
+ 2 / (top - bottom)
+ C =
+ -2 / (far - near)
+ tx =
+ -(right + left) / (right - left)
+ ty =
+ -(top + bottom) / (top - bottom)
+ tz =
+ -(zFar + zNear) / (zFar - zNear)
+ */
+ NodeOrthographicCamera(double left
+ , double right
+ , double bottom
+ , double top
+ , double zNear
+ , double zFar
+ );
+
+ double left() const {return left_;}
+ double right() const {return right_;}
+ double bottom() const {return bottom_;}
+ double top() const {return top_;}
+ double zNear() const {return zNear_;}
+ double zFar() const {return zFar_;}
+
+ NodeOrthographicCamera(const NodeOrthographicCamera& iBrother);
+
+private:
+ double left_;
+ double right_;
+ double bottom_;
+ double top_;
+ double zNear_;
+ double zFar_;
+};
+
+class LIB_SCENE_GRAPH_EXPORT NodePerspectiveCamera : public NodeCamera {
+public:
+ NodePerspectiveCamera();
+ /*! Builds a perspective projection matrix a la gluPerspective.
+ Given f defined as follows:
+ fovy
+ f = cotangent(____)
+ 2
+ The generated matrix is
+
+
+ ( f )
+ | ______ |
+ | aspect 0 0 0 |
+ | |
+ | 0 f 0 0 |
+ | |
+ | zNear+zFar 2*zNear*zFar |
+ | __________ ____________ |
+ | 0 0 zNear-zFar zNear-zFar |
+ | |
+ ( 0 0 -1 0 )
+ \param fovy
+ Field of View specified in radians.
+ */
+ NodePerspectiveCamera(double fovy
+ , double aspect
+ , double zNear
+ , double zFar);
+
+ /*! Builds a perspective projection matrix a la glFrustum.
+ ( 2*zNear )
+ | __________ |
+ | right-left 0 A 0 |
+ | |
+ | 2*zNear |
+ | 0 __________ B 0 |
+ | top-bottom |
+ | |
+ | 0 0 C D |
+ | |
+ | 0 0 -1 0 |
+ ( )
+
+ right+left
+ A = __________
+ right-left
+
+ top+bottom
+ B = __________
+ top-bottom
+
+ zFar+zNear
+ C = - __________
+ zFar-zNear
+
+ 2*zFar*zNear
+ D = - ____________
+ zFar-zNear
+ */
+ NodePerspectiveCamera(double left,
+ double right,
+ double bottom,
+ double top,
+ double zNear,
+ double zFar);
+};
+
+
+#endif // NODE_CAMERA_H_ \ No newline at end of file
diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp
new file mode 100755
index 00000000000..acd740ee055
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp
@@ -0,0 +1,34 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "NodeDrawingStyle.h"
+
+void NodeDrawingStyle::accept(SceneVisitor& v) {
+ v.visitNodeDrawingStyle(*this);
+
+ v.visitNodeDrawingStyleBefore(*this);
+ v.visitDrawingStyle(_DrawingStyle);
+ for(vector<Node*>::iterator node=_Children.begin(), end=_Children.end();
+ node!=end;
+ node++)
+ (*node)->accept(v);
+ v.visitNodeDrawingStyleAfter(*this);
+}
diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h
new file mode 100755
index 00000000000..18442ae10f9
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h
@@ -0,0 +1,70 @@
+//
+// Filename : NodeDrawingStyle.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to define a Drawing Style to be applied
+// to the underlying children. Inherits from NodeGroup.
+// Date of creation : 06/02/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODEDRAWINGSTYLE_H
+# define NODEDRAWINGSTYLE_H
+
+# include "../system/FreestyleConfig.h"
+# include "NodeGroup.h"
+# include "DrawingStyle.h"
+
+class LIB_SCENE_GRAPH_EXPORT NodeDrawingStyle : public NodeGroup
+{
+public:
+
+ inline NodeDrawingStyle() : NodeGroup() {}
+ virtual ~NodeDrawingStyle() {}
+
+ inline const DrawingStyle& drawingStyle() const { return _DrawingStyle; }
+ inline void SetDrawingStyle(const DrawingStyle& iDrawingStyle) { _DrawingStyle = iDrawingStyle; }
+
+ /*! Sets the style. Must be one of FILLED, LINES, POINTS, INVISIBLE. */
+ inline void SetStyle(const DrawingStyle::STYLE iStyle) { _DrawingStyle.SetStyle(iStyle); }
+ /*! Sets the line width in the LINES style case */
+ inline void SetLineWidth(const float iLineWidth) { _DrawingStyle.SetLineWidth(iLineWidth); }
+ /*! Sets the Point size in the POINTS style case */
+ inline void SetPointSize(const float iPointSize) { _DrawingStyle.SetPointSize(iPointSize); }
+ /*! Enables or disables the lighting. TRUE = enable */
+ inline void SetLightingEnabled(const bool iEnableLighting) { _DrawingStyle.SetLightingEnabled(iEnableLighting); }
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! accessors */
+ inline DrawingStyle::STYLE style() const {return _DrawingStyle.style();}
+ inline float lineWidth() const {return _DrawingStyle.lineWidth();}
+ inline float pointSize() const {return _DrawingStyle.pointSize();}
+ inline bool lightingEnabled() const {return _DrawingStyle.lightingEnabled();}
+
+private:
+ DrawingStyle _DrawingStyle;
+};
+
+#endif // NODEDRAWINGSTYLE_H
diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp
new file mode 100755
index 00000000000..3d2aa2c8694
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp
@@ -0,0 +1,122 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "NodeGroup.h"
+
+void NodeGroup::AddChild(Node *iChild)
+{
+ if(NULL == iChild)
+ return;
+
+ _Children.push_back(iChild);
+ iChild->addRef();
+}
+
+int NodeGroup::destroy()
+{
+ /*! Node::destroy makes a release on the object
+ * and then returns the reference counter.
+ * If the reference counter is equal to 0,
+ * that means that nobody else is linking
+ * this node group and that we can destroy the whole
+ * underlying tree.
+ * Else, one or several Node link this node group,
+ * and we only returns the reference counter
+ * decremented by Node::destroy();
+ */
+ int refThis = Node::destroy();
+
+ // if refThis != 0, we can't destroy the tree
+ if(0 != refThis)
+ return refThis;
+
+ // If we are here, that means that nobody else
+ // needs our NodeGroup and we can destroy it.
+ int refCount = 0;
+ vector<Node *>::iterator node;
+
+ for(node=_Children.begin(); node!=_Children.end(); node++)
+ {
+ refCount = (*node)->destroy();
+ if(0 == refCount)
+ delete (*node);
+ }
+
+ _Children.clear();
+
+ return refThis;
+}
+
+void NodeGroup::accept(SceneVisitor& v) {
+ v.visitNodeGroup(*this);
+
+ v.visitNodeGroupBefore(*this);
+ for(vector<Node *>::iterator node=_Children.begin(), end=_Children.end();
+ node!=end;
+ node++)
+ (*node)->accept(v);
+ v.visitNodeGroupAfter(*this);
+}
+
+void NodeGroup::DetachChildren()
+{
+ vector<Node *>::iterator node;
+
+ for(node=_Children.begin(); node!=_Children.end(); node++)
+ {
+ (*node)->release();
+ }
+
+ _Children.clear();
+}
+
+void NodeGroup::DetachChild(Node *iChild)
+{
+ int found = 0;
+ vector<Node*>::iterator node;
+
+ for(node=_Children.begin(); node!=_Children.end(); node++)
+ {
+ if((*node) == iChild)
+ {
+ (*node)->release();
+ _Children.erase(node);
+ found = 1;
+ break;
+ }
+ }
+}
+
+void NodeGroup::RetrieveChildren(vector<Node*>& oNodes){
+ oNodes = _Children;
+}
+
+const BBox<Vec3r>& NodeGroup::UpdateBBox()
+{
+ vector<Node *>::iterator node;
+ clearBBox();
+ for(node=_Children.begin(); node!=_Children.end(); node++)
+ {
+ AddBBox((*node)->UpdateBBox());
+ }
+
+ return Node::UpdateBBox();
+}
diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.h b/source/blender/freestyle/intern/scene_graph/NodeGroup.h
new file mode 100755
index 00000000000..a1bd2b57e56
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.h
@@ -0,0 +1,84 @@
+//
+// Filename : NodeGroup.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to represent a group node. This node can contains
+// several children. It also contains a transform matrix
+// indicating the transform state of the underlying
+// children.
+// Date of creation : 24/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODEGROUP_H
+# define NODEGROUP_H
+
+# include <vector>
+# include "../system/FreestyleConfig.h"
+# include "Node.h"
+
+using namespace std;
+
+class LIB_SCENE_GRAPH_EXPORT NodeGroup : public Node
+{
+public:
+
+ inline NodeGroup(): Node() {}
+ virtual ~NodeGroup(){}
+
+ /*! Adds a child. Makes a addRef on the
+ * iChild reference counter */
+ virtual void AddChild(Node *iChild);
+
+ /*! destroys all the underlying nodes
+ * Returns the reference counter
+ * after having done a release() */
+ virtual int destroy();
+
+ /*! Detaches all the children */
+ virtual void DetachChildren();
+
+ /*! Detached the sepcified child */
+ virtual void DetachChild(Node *iChild);
+
+ /*! Retrieve children */
+ virtual void RetrieveChildren(vector<Node*>& oNodes);
+
+
+ /*! Renders every children */
+ // virtual void Render(Renderer *iRenderer);
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Updates the BBox */
+ virtual const BBox<Vec3r>& UpdateBBox();
+
+ /*! Returns the number of children */
+ virtual int numberOfChildren() {return _Children.size();}
+
+protected:
+ vector<Node*> _Children;
+};
+
+#endif // NODEGROUP_H
diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.cpp b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp
new file mode 100755
index 00000000000..61a46155cfa
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp
@@ -0,0 +1,80 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "NodeLight.h"
+
+int NodeLight::numberOfLights = 0;
+
+NodeLight::NodeLight()
+: Node()
+{
+ if(numberOfLights > 7)
+ {
+ _number = 7;
+ }
+ else
+ {
+ _number = numberOfLights;
+ numberOfLights++;
+ }
+
+ Ambient[0] = Ambient[1] = Ambient[2] = 0.f;
+ Ambient[3] = 1.f;
+
+ for(int i=0; i<4; i++)
+ {
+ Diffuse[i] = 1.f;
+ Specular[i] = 1.f;
+ }
+
+ Position[0] = Position[1] = Position[3] = 0.f;
+ Position[2] = 1.f;
+
+ on = true;
+}
+
+NodeLight::NodeLight(NodeLight& iBrother)
+: Node(iBrother)
+{
+ if(numberOfLights > 7)
+ {
+ _number = 7;
+ }
+ else
+ {
+ _number = numberOfLights;
+ numberOfLights++;
+ }
+
+ for(int i=0; i<4; i++)
+ {
+ Ambient[i] = iBrother.ambient()[i];
+ Diffuse[i] = iBrother.diffuse()[i];
+ Specular[i] = iBrother.specular()[i];
+ Position[i] = iBrother.position()[i];
+ }
+
+ on = iBrother.isOn();
+}
+
+void NodeLight::accept(SceneVisitor& v) {
+ v.visitNodeLight(*this);
+}
diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.h b/source/blender/freestyle/intern/scene_graph/NodeLight.h
new file mode 100755
index 00000000000..0689505fb24
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeLight.h
@@ -0,0 +1,86 @@
+//
+// Filename : NodeLight.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to represent a light node
+// Date of creation : 25/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODELIGHT_H
+# define NODELIGHT_H
+
+# include "../geometry/Geom.h"
+# include "../system/FreestyleConfig.h"
+# include "Node.h"
+
+using namespace Geometry;
+
+class LIB_SCENE_GRAPH_EXPORT NodeLight : public Node
+{
+public:
+
+ NodeLight();
+ NodeLight(NodeLight& iBrother);
+
+ virtual ~NodeLight() {}
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Accessors for the light properties */
+ inline const float * ambient() const {return Ambient;}
+ inline const float * diffuse() const {return Diffuse;}
+ inline const float * specular() const {return Specular;}
+ inline const float * position() const {return Position;}
+ inline bool isOn() const {return on;}
+ inline int number() const {return _number;}
+
+private:
+ // Data members
+ // ============
+
+ /*! on=true, the light is on */
+ bool on;
+
+ /*! The color definition */
+ float Ambient[4];
+ float Diffuse[4];
+ float Specular[4];
+
+ /*! Light position. if w = 0, the light is
+ * placed at infinite.
+ */
+ float Position[4];
+
+ /*! used to manage the number of lights */
+ /*! numberOfLights
+ * the number of lights in the scene.
+ * Initially, 0.
+ */
+ static int numberOfLights;
+ /*! The current lignt number */
+ int _number;
+};
+
+#endif // NODELIGHT_H
diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.cpp b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp
new file mode 100755
index 00000000000..2012ef83b9f
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp
@@ -0,0 +1,51 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "NodeShape.h"
+
+NodeShape::~NodeShape()
+{
+ vector<Rep *>::iterator rep;
+
+ if(0 != _Shapes.size())
+ {
+ for(rep=_Shapes.begin(); rep!=_Shapes.end(); rep++)
+ {
+ int refCount = (*rep)->destroy();
+ if(0 == refCount)
+ delete (*rep);
+ }
+
+ _Shapes.clear();
+ }
+}
+
+void NodeShape::accept(SceneVisitor& v) {
+ v.visitNodeShape(*this);
+
+ v.visitMaterial(_Material);
+
+ v.visitNodeShapeBefore(*this);
+ vector<Rep *>::iterator rep;
+ for(rep = _Shapes.begin(); rep != _Shapes.end(); rep++)
+ (*rep)->accept(v);
+ v.visitNodeShapeAfter(*this);
+}
diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.h b/source/blender/freestyle/intern/scene_graph/NodeShape.h
new file mode 100755
index 00000000000..3e963beec38
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeShape.h
@@ -0,0 +1,89 @@
+//
+// Filename : NodeShape.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to build a shape node. It contains a Rep,
+// which is the shape geometry
+// Date of creation : 25/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODESHAPE_H
+# define NODESHAPE_H
+
+# include <vector>
+# include "../system/FreestyleConfig.h"
+# include "Node.h"
+# include "Rep.h"
+# include "../geometry/BBox.h"
+# include "../geometry/Geom.h"
+# include "Material.h"
+
+using namespace std;
+using namespace Geometry;
+
+class LIB_SCENE_GRAPH_EXPORT NodeShape : public Node
+{
+public:
+
+ inline NodeShape() : Node() {}
+
+ virtual ~NodeShape();
+
+ /*! Adds a Rep to the _Shapes list
+ * The delete of the rep is done
+ * when it is not used any more by
+ * the Scene Manager. So, it must not
+ * be deleted by the caller
+ */
+ virtual void AddRep(Rep *iRep)
+ {
+ if(NULL == iRep)
+ return;
+ _Shapes.push_back(iRep);
+ iRep->addRef();
+
+ // updates bbox:
+ AddBBox(iRep->bbox());
+ }
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Sets the shape material */
+ inline void SetMaterial(const Material& iMaterial) { _Material = iMaterial; }
+
+ /*! accessors */
+ /*! returns the shape's material */
+ inline Material& material() { return _Material; }
+ inline const vector<Rep*>& shapes() {return _Shapes;}
+
+private:
+ /*! list of shapes */
+ vector<Rep*> _Shapes;
+
+ /*! Shape Material */
+ Material _Material;
+};
+
+#endif // NODESHAPE_H
diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp
new file mode 100755
index 00000000000..64e9b7a4dd6
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp
@@ -0,0 +1,166 @@
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+#include "../system/FreestyleConfig.h"
+#include "NodeTransform.h"
+
+void NodeTransform::Translate(real x, real y, real z)
+{
+ _Matrix(0, 3) += x;
+ _Matrix(1, 3) += y;
+ _Matrix(2, 3) += z;
+}
+
+void NodeTransform::Rotate(real iAngle, real x, real y, real z)
+{
+ //Normalize the x,y,z vector;
+ real norm = (real)sqrt(x*x+y*y+z*z);
+ if(0 == norm)
+ return;
+
+ x /= norm;
+ y /= norm;
+ z /= norm;
+
+ // find the corresponding matrix with the Rodrigues formula:
+ // R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda
+ Matrix33r Ntilda;
+ Ntilda(0,0) = Ntilda(1,1) = Ntilda(2,2) = 0.f;
+ Ntilda(0,1) = -z;
+ Ntilda(0,2) = y;
+ Ntilda(1,0) = z;
+ Ntilda(1,2) = -x;
+ Ntilda(2,0) = -y;
+ Ntilda(2,1) = x;
+
+ const Matrix33r Ntilda2(Ntilda * Ntilda);
+
+
+ const real sinAngle = (real)sin((iAngle/180.f)*M_PI);
+ const real cosAngle = (real)cos((iAngle/180.f)*M_PI);
+
+ Matrix33r NS(Ntilda*sinAngle);
+ Matrix33r NC(Ntilda2*(1.f-cosAngle));
+ Matrix33r R;
+ R = Matrix33r::identity();
+ R += NS + NC;
+
+ //R4 is the corresponding 4x4 matrix
+ Matrix44r R4;
+ R4 = Matrix44r::identity();
+
+ for(int i=0; i<3; i++)
+ for(int j=0; j<3; j++)
+ R4(i,j) = R(i,j);
+
+ // Finally, we multiply our current matrix by R4:
+ Matrix44r mat_tmp(_Matrix);
+ _Matrix = mat_tmp * R4;
+}
+
+void NodeTransform::Scale(real x, real y, real z)
+{
+ _Matrix(0,0) *= x;
+ _Matrix(1,1) *= y;
+ _Matrix(2,2) *= z;
+
+ _Scaled = true;
+}
+
+void NodeTransform::MultiplyMatrix(const Matrix44r &iMatrix)
+{
+ Matrix44r mat_tmp(_Matrix);
+ _Matrix = mat_tmp * iMatrix;
+}
+
+void NodeTransform::SetMatrix(const Matrix44r &iMatrix)
+{
+ _Matrix = iMatrix;
+ if(isScaled(iMatrix))
+ _Scaled = true;
+}
+
+void NodeTransform::accept(SceneVisitor& v) {
+ v.visitNodeTransform(*this);
+
+ v.visitNodeTransformBefore(*this);
+ for(vector<Node *>::iterator node=_Children.begin(), end=_Children.end();
+ node!=end;
+ node++)
+ (*node)->accept(v);
+ v.visitNodeTransformAfter(*this);
+}
+
+void NodeTransform::AddBBox(const BBox<Vec3r>& iBBox)
+{
+ Vec3r oldMin(iBBox.getMin());
+ Vec3r oldMax(iBBox.getMax());
+
+ // compute the 8 corners of the bbox
+ HVec3r box[8];
+ box[0] = HVec3r(iBBox.getMin());
+ box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]);
+ box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]);
+ box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]);
+ box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]);
+ box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]);
+ box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]);
+ box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]);
+
+ // Computes the transform iBBox
+ HVec3r tbox[8];
+ unsigned i;
+ for(i = 0; i < 8; i++)
+ tbox[i] = _Matrix * box[i];
+
+ Vec3r newMin(tbox[0]);
+ Vec3r newMax(tbox[0]);
+ for (i=0; i<8; i++)
+ {
+ for (unsigned int j=0; j<3; j++)
+ {
+ if (newMin[j] > tbox[i][j])
+ newMin[j] = tbox[i][j];
+ if (newMax[j] < tbox[i][j])
+ newMax[j] = tbox[i][j];
+ }
+ }
+
+ BBox<Vec3r> transformBox(newMin, newMax);
+
+ Node::AddBBox(transformBox);
+}
+
+bool NodeTransform::isScaled(const Matrix44r &M)
+{
+ for(unsigned int j=0; j<3; j++)
+ {
+ real norm = 0;
+ for(unsigned int i=0; i<3; i++)
+ {
+ norm += M(i,j)*M(i,j);
+ }
+ if((norm > 1.01) || (norm < 0.99))
+ return true;
+ }
+
+ return false;
+}
diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.h b/source/blender/freestyle/intern/scene_graph/NodeTransform.h
new file mode 100755
index 00000000000..3929c60996b
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.h
@@ -0,0 +1,107 @@
+//
+// Filename : NodeTransform.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to represent a transform node. A Transform node
+// contains one or several children, all affected by the
+// transformation.
+// Date of creation : 06/02/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef NODETRANSFORM_H
+# define NODETRANSFORM_H
+
+# include "../geometry/Geom.h"
+# include "../system/FreestyleConfig.h"
+# include "NodeGroup.h"
+
+using namespace Geometry;
+
+class LIB_SCENE_GRAPH_EXPORT NodeTransform : public NodeGroup
+{
+public:
+
+ inline NodeTransform() : NodeGroup() {
+ _Matrix = Matrix44r::identity();
+ _Scaled=false;
+ }
+
+ virtual ~NodeTransform() {}
+
+ /*! multiplys the current matrix by the
+ * x, y, z translation matrix.
+ */
+ void Translate(real x, real y, real z);
+
+ /*! multiplys the current matrix by a
+ * rotation matrix
+ * iAngle
+ * The rotation angle
+ * x, y, z
+ * The rotation axis
+ */
+ void Rotate(real iAngle, real x, real y, real z);
+
+ /*! multiplys the current matrix by a
+ * scaling matrix.
+ * x, y, z
+ * The scaling coefficients
+ * with respect to the x,y,z axis
+ */
+ void Scale(real x, real y, real z);
+
+ /*! Multiplys the current matrix
+ * by iMatrix
+ */
+ void MultiplyMatrix(const Matrix44r &iMatrix);
+
+ /*! Sets the current matrix to iMatrix */
+ void SetMatrix(const Matrix44r &iMatrix);
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+ /*! Overloads the Node::AddBBox in order to take care
+ * about the transformation
+ */
+ virtual void AddBBox(const BBox<Vec3r>& iBBox);
+
+ /*! Checks whether a matrix contains a scale factor
+ * or not.
+ * Returns true if yes.
+ * iMatrix
+ * The matrix to check
+ */
+ bool isScaled(const Matrix44r &M);
+
+ /*! accessors */
+ inline const Matrix44r& matrix() const { return _Matrix; }
+ inline bool scaled() const {return _Scaled;}
+
+private:
+ Matrix44r _Matrix;
+ bool _Scaled;
+};
+
+#endif // NODETRANSFORM_H
diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp
new file mode 100755
index 00000000000..2d0205308b9
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp
@@ -0,0 +1,31 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "OrientedLineRep.h"
+#include "../system/BaseObject.h"
+
+void OrientedLineRep::accept(SceneVisitor& v) {
+ Rep::accept(v);
+ if(!material())
+ v.visitOrientedLineRep(*this);
+ else
+ v.visitLineRep(*this);
+}
diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h
new file mode 100755
index 00000000000..4274581e39a
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h
@@ -0,0 +1,67 @@
+//
+// Filename : OrientedLineRep.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to display an oriented line representation.
+// Date of creation : 24/10/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef VIEWEDGEREP_H
+# define VIEWEDGEREP_H
+
+# include "../system/FreestyleConfig.h"
+# include "LineRep.h"
+
+class LIB_SCENE_GRAPH_EXPORT OrientedLineRep : public LineRep
+{
+public:
+
+ OrientedLineRep() : LineRep() {}
+ /*! Builds a single line from 2 vertices
+ * v1
+ * first vertex
+ * v2
+ * second vertex
+ */
+ inline OrientedLineRep(const Vec3r& v1, const Vec3r& v2)
+ : LineRep(v1,v2)
+ {}
+
+ /*! Builds a line rep from a vertex chain */
+ inline OrientedLineRep(const vector<Vec3r>& vertices)
+ : LineRep(vertices)
+ {}
+
+ /*! Builds a line rep from a vertex chain */
+ inline OrientedLineRep(const list<Vec3r>& vertices)
+ : LineRep(vertices)
+ {}
+
+ virtual ~OrientedLineRep() {}
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+};
+
+#endif // VIEWEDGEREP_H
diff --git a/source/blender/freestyle/intern/scene_graph/Rep.cpp b/source/blender/freestyle/intern/scene_graph/Rep.cpp
new file mode 100755
index 00000000000..520d3c41e2e
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/Rep.cpp
@@ -0,0 +1 @@
+#include "Rep.h" \ No newline at end of file
diff --git a/source/blender/freestyle/intern/scene_graph/Rep.h b/source/blender/freestyle/intern/scene_graph/Rep.h
new file mode 100755
index 00000000000..6ccc2152c48
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/Rep.h
@@ -0,0 +1,127 @@
+//
+// Filename : Rep.h
+// Author(s) : Stephane Grabli
+// Purpose : Base class for all shapes. Inherits from BasicObjects
+// for references counter management (addRef, release).
+// Date of creation : 25/01/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef REP_H
+# define REP_H
+
+# include "../system/BaseObject.h"
+# include "SceneVisitor.h"
+# include "../geometry/BBox.h"
+# include "../geometry/Geom.h"
+# include "../system/Precision.h"
+# include "Material.h"
+# include "../system/Id.h"
+
+using namespace Geometry;
+
+class LIB_SCENE_GRAPH_EXPORT Rep : public BaseObject
+{
+public:
+
+ inline Rep() : BaseObject() {_Id = 0; _Material=0;}
+ inline Rep(const Rep& iBrother)
+ : BaseObject()
+ {
+ _Id = iBrother._Id;
+ if(0 == iBrother._Material)
+ _Material = 0;
+ else
+ _Material = new Material(*(iBrother._Material));
+
+ _BBox = iBrother.bbox();
+ }
+ inline void swap(Rep& ioOther){
+ std::swap(_BBox,ioOther._BBox);
+ std::swap(_Id, ioOther._Id);
+ std::swap(_Material,ioOther._Material);
+ }
+ Rep& operator=(const Rep& iBrother){
+ if(&iBrother != this){
+ _Id = iBrother._Id;
+ if(0 == iBrother._Material)
+ _Material = 0;
+ else{
+ if(_Material == 0){
+ _Material = new Material(*iBrother._Material);
+ }else{
+ (*_Material)=(*(iBrother._Material));
+ }
+ _BBox = iBrother.bbox();
+ }
+ }
+ return *this;
+ }
+ virtual ~Rep()
+ {
+ if(0 != _Material)
+ {
+ delete _Material;
+ _Material = 0;
+ }
+ }
+
+ /*! Accept the corresponding visitor
+ * Must be overload by
+ * inherited classes
+ */
+ virtual void accept(SceneVisitor& v) {
+ if(_Material)
+ v.visitMaterial(*_Material);
+ v.visitRep(*this);
+ }
+
+ /*! Computes the rep bounding box.
+ * Each Inherited rep must compute
+ * its bbox depending on the way the data
+ * are stored. So, each inherited class
+ * must overload this method
+ */
+ virtual void ComputeBBox() = 0;
+
+ /*! Returns the rep bounding box */
+ virtual const BBox<Vec3r>& bbox() const {return _BBox;}
+ inline Id getId() const {return _Id;}
+ inline const Material * material() const {return _Material;}
+
+ /*! Sets the Rep bounding box */
+ virtual void SetBBox(const BBox<Vec3r>& iBox) {_BBox = iBox;}
+ inline void SetId(const Id& id) {_Id = id;}
+ inline void SetMaterial(const Material& iMaterial)
+ {
+ _Material = new Material(iMaterial);
+ }
+
+private:
+ BBox<Vec3r> _BBox;
+ Id _Id;
+ Material *_Material;
+};
+
+#endif // REP_H
diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp
new file mode 100755
index 00000000000..aeee87f8222
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp
@@ -0,0 +1,86 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <iomanip>
+#include "ScenePrettyPrinter.h"
+#include "IndexedFaceSet.h"
+
+#define VISIT(CLASS) \
+ void ScenePrettyPrinter::visit##CLASS(CLASS&) { \
+ _ofs << _space << #CLASS << endl; \
+ }
+
+VISIT(Node)
+VISIT(NodeShape)
+VISIT(NodeGroup)
+VISIT(NodeLight)
+VISIT(NodeDrawingStyle)
+VISIT(NodeTransform)
+
+void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape&) {
+ increaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape&) {
+ decreaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup&) {
+ increaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup&) {
+ decreaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle&) {
+ increaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle&) {
+ decreaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform&) {
+ increaseSpace();
+}
+
+void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform&) {
+ decreaseSpace();
+}
+
+VISIT(LineRep)
+VISIT(OrientedLineRep)
+VISIT(TriangleRep)
+VISIT(VertexRep)
+
+void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet& ifs) {
+ const real* vertices = ifs.vertices();
+ unsigned vsize = ifs.vsize();
+
+ _ofs << _space << "IndexedFaceSet" << endl;
+ const real *p = vertices;
+ for (unsigned i = 0; i < vsize / 3; i++) {
+ _ofs << _space << " " << setw(3) << setfill('0') << i << ": "
+ << p[0] << ", " << p[1] << ", " << p[2] << endl;
+ p += 3;
+ }
+}
diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h
new file mode 100755
index 00000000000..4e83825ff55
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h
@@ -0,0 +1,105 @@
+//
+// Filename : ScenePrettyPrinter.h
+// Author(s) : Stephane Grabli, Emmanuel Turquin
+// Purpose : Class to display textual information
+// about a scene graph.
+// Date of creation : 26/04/2003
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef SCENE_PRETTY_PRINTER_H
+# define SCENE_PRETTY_PRINTER_H
+
+# include <iostream>
+# include <fstream>
+# include <string>
+# include "SceneVisitor.h"
+
+using namespace std;
+
+class ScenePrettyPrinter : public SceneVisitor
+{
+public:
+
+ ScenePrettyPrinter(const string filename = "SceneLog.txt")
+ : SceneVisitor() {
+ if (!filename.empty())
+ _ofs.open(filename.c_str());
+ if (!_ofs.is_open())
+ cerr << "Warning, unable to open file \"" << filename << "\"" << endl;
+ _space = "";
+ }
+
+ virtual ~ScenePrettyPrinter() {
+ if (_ofs.is_open())
+ _ofs.close();
+ }
+
+
+ //
+ // visitClass methods
+ //
+ //////////////////////////////////////////////
+
+ VISIT_DECL(Node)
+ VISIT_DECL(NodeShape)
+ VISIT_DECL(NodeGroup)
+ VISIT_DECL(NodeLight)
+ VISIT_DECL(NodeDrawingStyle)
+ VISIT_DECL(NodeTransform)
+
+ VISIT_DECL(LineRep)
+ VISIT_DECL(OrientedLineRep)
+ VISIT_DECL(TriangleRep)
+ VISIT_DECL(VertexRep)
+ VISIT_DECL(IndexedFaceSet)
+
+ virtual void visitNodeShapeBefore(NodeShape&);
+ virtual void visitNodeShapeAfter(NodeShape&);
+ virtual void visitNodeGroupBefore(NodeGroup&);
+ virtual void visitNodeGroupAfter(NodeGroup&);
+ virtual void visitNodeDrawingStyleBefore(NodeDrawingStyle&);
+ virtual void visitNodeDrawingStyleAfter(NodeDrawingStyle&);
+ virtual void visitNodeTransformBefore(NodeTransform&);
+ virtual void visitNodeTransformAfter(NodeTransform&);
+
+ protected:
+
+ void increaseSpace()
+ {
+ _space += " ";
+ }
+
+ void decreaseSpace()
+ {
+ _space.erase(0, 2);
+ }
+
+ private:
+
+ ofstream _ofs;
+ string _space;
+};
+
+#endif // SCENE_PRETTY_PRINTER_H
diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp b/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp
new file mode 100755
index 00000000000..9cfb9d40d24
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.cpp
@@ -0,0 +1 @@
+#include "SceneVisitor.h" \ No newline at end of file
diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
new file mode 100755
index 00000000000..c57bd2e0f6e
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
@@ -0,0 +1,98 @@
+//
+// Filename : SceneVisitor.h
+// Author(s) : Emmanuel Turquin
+// Purpose : Class to visit (without doing anything)
+// a scene graph structure
+// Date of creation : 26/04/2003
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef SCENE_VISITOR_H
+# define SCENE_VISITOR_H
+
+# define VISIT_COMPLETE_DEF(type) \
+virtual void visit##type(type&) {} \
+virtual void visit##type##Before(type&) {} \
+virtual void visit##type##After(type&) {}
+
+# define VISIT_DECL(type) virtual void visit##type(type&);
+
+# define VISIT_COMPLETE_DECL(type) \
+ virtual void visit##type##Before(type&); \
+ virtual void visit##type(type&); \
+ virtual void visit##type##After(type&);
+
+#include "../system/FreestyleConfig.h"
+
+class Node;
+class NodeShape;
+class NodeGroup;
+class NodeLight;
+class NodeCamera;
+class NodeDrawingStyle;
+class NodeTransform;
+
+class Rep;
+class LineRep;
+class OrientedLineRep;
+class TriangleRep;
+class VertexRep;
+class IndexedFaceSet;
+class DrawingStyle;
+class Material;
+
+class LIB_SCENE_GRAPH_EXPORT SceneVisitor
+{
+public:
+
+ SceneVisitor() {}
+ virtual ~SceneVisitor() {}
+
+ virtual void beginScene() {}
+ virtual void endScene() {}
+
+ //
+ // visitClass methods
+ //
+ //////////////////////////////////////////////
+
+ VISIT_COMPLETE_DEF(Node)
+ VISIT_COMPLETE_DEF(NodeShape)
+ VISIT_COMPLETE_DEF(NodeGroup)
+ VISIT_COMPLETE_DEF(NodeLight)
+ VISIT_COMPLETE_DEF(NodeCamera)
+ VISIT_COMPLETE_DEF(NodeDrawingStyle)
+ VISIT_COMPLETE_DEF(NodeTransform)
+
+ VISIT_COMPLETE_DEF(Rep)
+ VISIT_COMPLETE_DEF(LineRep)
+ VISIT_COMPLETE_DEF(OrientedLineRep)
+ VISIT_COMPLETE_DEF(TriangleRep)
+ VISIT_COMPLETE_DEF(VertexRep)
+ VISIT_COMPLETE_DEF(IndexedFaceSet)
+ VISIT_COMPLETE_DEF(DrawingStyle)
+ VISIT_COMPLETE_DEF(Material)
+};
+
+#endif // SCENEVISITOR_H
diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp
new file mode 100755
index 00000000000..215124b0676
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp
@@ -0,0 +1,59 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "TriangleRep.h"
+
+void TriangleRep::ComputeBBox()
+{
+ real XMax = _vertices[0][0];
+ real YMax = _vertices[0][1];
+ real ZMax = _vertices[0][2];
+
+ real XMin = _vertices[0][0];
+ real YMin = _vertices[0][1];
+ real ZMin = _vertices[0][2];
+
+ // parse all the coordinates to find
+ // the XMax, YMax, ZMax
+ for(int i=0; i<3; ++i)
+ {
+ // X
+ if(_vertices[i][0] > XMax)
+ XMax = _vertices[i][0];
+ if(_vertices[i][0] < XMin)
+ XMin = _vertices[i][0];
+
+ // Y
+ if(_vertices[i][1] > YMax)
+ YMax = _vertices[i][1];
+ if(_vertices[i][1] < YMin)
+ YMin = _vertices[i][1];
+
+ // Z
+ if(_vertices[i][2] > ZMax)
+ ZMax = _vertices[i][2];
+ if(_vertices[i][2] < ZMin)
+ ZMin = _vertices[i][2];
+
+ }
+
+ SetBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax)));
+}
diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.h b/source/blender/freestyle/intern/scene_graph/TriangleRep.h
new file mode 100755
index 00000000000..20df12cfd8f
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.h
@@ -0,0 +1,106 @@
+//
+// Filename : TriangleRep.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to define the represenation of a triangle
+// Date of creation : 16/12/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef TRIANGLEREP_H
+# define TRIANGLEREP_H
+
+//! inherits from class Rep
+#include "Rep.h"
+
+/*! Base class for all lines objects */
+class LIB_SCENE_GRAPH_EXPORT TriangleRep : public Rep
+{
+public:
+
+ /*! Line description style */
+ enum TRIANGLE_STYLE{FILL, LINES};
+private:
+ TRIANGLE_STYLE _Style;
+ Vec3r _vertices[3];
+ Vec3r _colors[3];
+public:
+ inline TriangleRep() : Rep() {_Style = FILL;}
+
+ /*! Builds a triangle from 3 vertices
+ * v0
+ * first vertex
+ * v1
+ * second vertex
+ * v2
+ * third vertex
+ */
+ inline TriangleRep(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2)
+ : Rep()
+ {
+ _vertices[0] = v0;
+ _vertices[1] = v1;
+ _vertices[2] = v2;
+ _Style = FILL;
+ }
+ inline TriangleRep( const Vec3r& v0, const Vec3r& c0,
+ const Vec3r& v1, const Vec3r& c1,
+ const Vec3r& v2, const Vec3r& c2)
+ : Rep()
+ {
+ _vertices[0] = v0;
+ _vertices[1] = v1;
+ _vertices[2] = v2;
+ _colors[0] = c0;
+ _colors[1] = c1;
+ _colors[2] = c2;
+ _Style = FILL;
+ }
+
+ virtual ~TriangleRep()
+ {}
+
+ /*! accessors */
+ inline const TRIANGLE_STYLE style() const {return _Style;}
+ inline const Vec3r& vertex(int index) const {return _vertices[index];}
+ inline const Vec3r& color(int index) const {return _colors[index];}
+ /*! modifiers */
+ inline void SetStyle(const TRIANGLE_STYLE iStyle) {_Style = iStyle;}
+ inline void SetVertex(int index, const Vec3r& iVertex) {_vertices[index] = iVertex;}
+ inline void SetColor(int index, const Vec3r& iColor) {_colors[index] = iColor;}
+ inline void SetVertices(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) {_vertices[0] = v0; _vertices[1] = v1; _vertices[2] = v2;}
+ inline void SetColors(const Vec3r& c0, const Vec3r& c1, const Vec3r& c2) {_colors[0] = c0; _colors[1] = c1; _colors[2] = c2;}
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v) {
+ Rep::accept(v);
+ v.visitTriangleRep(*this);
+ }
+
+ /*! Computes the triangle bounding box.*/
+ virtual void ComputeBBox();
+
+
+};
+
+#endif
diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.cpp b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp
new file mode 100755
index 00000000000..1ecb5f141e1
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp
@@ -0,0 +1,29 @@
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "VertexRep.h"
+
+void VertexRep::ComputeBBox()
+{
+
+ SetBBox(BBox<Vec3r>(Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]),
+ Vec3r(_coordinates[0], _coordinates[1], _coordinates[2])));
+}
diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.h b/source/blender/freestyle/intern/scene_graph/VertexRep.h
new file mode 100755
index 00000000000..9dce7fbbe9c
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/VertexRep.h
@@ -0,0 +1,87 @@
+//
+// Filename : VertexRep.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to define the representation of a vertex for
+// displaying purpose.
+// Date of creation : 03/04/2002
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef VERTEXREP_H
+# define VERTEXREP_H
+
+#include "Rep.h"
+
+class LIB_SCENE_GRAPH_EXPORT VertexRep : public Rep
+{
+public:
+
+ inline VertexRep() : Rep() {_vid = 0;_PointSize = 0.f;}
+ inline VertexRep(real x, real y, real z, int id = 0)
+ : Rep()
+ {
+ _coordinates[0] = x;
+ _coordinates[1] = y;
+ _coordinates[2] = z;
+
+ _vid = id;
+ _PointSize = 0.f;
+ }
+
+ inline ~VertexRep() {}
+
+ /*! Accept the corresponding visitor */
+
+ virtual void accept(SceneVisitor& v) {
+ Rep::accept(v);
+ v.visitVertexRep(*this);
+ }
+
+ /*! Computes the rep bounding box.
+ */
+ virtual void ComputeBBox();
+
+ /*! accessors */
+ inline const int vid() const {return _vid;}
+ inline const real * coordinates() const {return _coordinates;}
+ inline real x() const {return _coordinates[0];}
+ inline real y() const {return _coordinates[1];}
+ inline real z() const {return _coordinates[2];}
+ inline float pointSize() const {return _PointSize;}
+
+ /*! modifiers */
+ inline void SetVid(int id) {_vid = id;}
+ inline void setX(real x) {_coordinates[0] = x;}
+ inline void setY(real y) {_coordinates[1] = y;}
+ inline void setZ(real z) {_coordinates[2] = z;}
+ inline void SetCoordinates(real x, real y, real z) {_coordinates[0] = x;_coordinates[1] = y; _coordinates[2] = z;}
+ inline void SetPointSize(float iPointSize) {_PointSize = iPointSize;}
+
+private:
+ int _vid; // vertex id
+ real _coordinates[3];
+ float _PointSize;
+};
+
+#endif // VERTEXREP_H
diff --git a/source/blender/freestyle/intern/scene_graph/scene_graph.pro b/source/blender/freestyle/intern/scene_graph/scene_graph.pro
new file mode 100755
index 00000000000..5736104a597
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/scene_graph.pro
@@ -0,0 +1,86 @@
+# This file should be viewed as a -*- mode: Makefile -*-
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# W A R N I N G ! ! ! #
+# a u t h o r i z e d p e r s o n a l o n l y #
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+include(../Config.pri)
+
+TEMPLATE = lib
+
+TARGET = $${LIB_SCENE_GRAPH}
+VERSION = $${APPVERSION}
+TARGET_VERSION_EXT = $${APPVERSION_MAJ}.$${APPVERSION_MID}
+
+#
+# CONFIG
+#
+#######################################
+
+CONFIG *= dll 3ds$${LIB3DS_VERSION_MAJ}.$${LIB3DS_VERSION_MIN}
+
+
+exists (../libconfig.pri) {
+ include (../libconfig.pri)
+}
+#
+# DEFINES
+#
+#######################################
+
+win32:DEFINES *= MAKE_LIB_SCENE_GRAPH_DLL
+
+#
+# INCLUDE PATH
+#
+#######################################
+
+#INCLUDEPATH *= ../geometry ../system
+
+#
+# BUILD DIRECTORIES
+#
+#######################################
+
+BUILD_DIR = ../../build
+
+OBJECTS_DIR = $${BUILD_DIR}/$${REL_OBJECTS_DIR}
+!win32:DESTDIR = $${BUILD_DIR}/$${REL_DESTDIR}/lib
+win32:DESTDIR = $${BUILD_DIR}/$${REL_DESTDIR}
+
+#
+# LIBS
+#
+#######################################
+
+win32:LIBS *= $${DESTDIR}/$${LIB_GEOMETRY}$${LIBVERSION}.lib \
+ $${DESTDIR}/$${LIB_SYSTEM}$${LIBVERSION}.lib
+!win32 {
+ lib_bundle {
+ LIBS += -F$${DESTDIR} -framework $${LIB_GEOMETRY} \
+ -framework $${LIB_SYSTEM}
+ } else {
+ LIBS *= -L$${DESTDIR}/ -l$${LIB_GEOMETRY} -l$${LIB_SYSTEM}
+ }
+}
+
+#
+# INSTALL
+#
+#######################################
+
+LIB_DIR = ../../lib
+# install library
+target.path = $$LIB_DIR
+# "make install" configuration options
+INSTALLS += target
+
+#
+# SOURCES & HEADERS
+#
+#######################################
+
+!static {
+ include(src.pri)
+}
diff --git a/source/blender/freestyle/intern/scene_graph/src.pri b/source/blender/freestyle/intern/scene_graph/src.pri
new file mode 100755
index 00000000000..994db200812
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/src.pri
@@ -0,0 +1,41 @@
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# W A R N I N G ! ! ! #
+# a u t h o r i z e d p e r s o n a l o n l y #
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+SCENE_GRAPH_DIR = ../scene_graph
+
+SOURCES *= $${SCENE_GRAPH_DIR}/IndexedFaceSet.cpp \
+ $${SCENE_GRAPH_DIR}/LineRep.cpp \
+ $${SCENE_GRAPH_DIR}/MaxFileLoader.cpp \
+ $${SCENE_GRAPH_DIR}/NodeCamera.cpp \
+ $${SCENE_GRAPH_DIR}/NodeDrawingStyle.cpp \
+ $${SCENE_GRAPH_DIR}/NodeGroup.cpp \
+ $${SCENE_GRAPH_DIR}/NodeLight.cpp \
+ $${SCENE_GRAPH_DIR}/NodeShape.cpp \
+ $${SCENE_GRAPH_DIR}/NodeTransform.cpp \
+ $${SCENE_GRAPH_DIR}/OrientedLineRep.cpp \
+ $${SCENE_GRAPH_DIR}/ScenePrettyPrinter.cpp \
+ $${SCENE_GRAPH_DIR}/TriangleRep.cpp \
+ $${SCENE_GRAPH_DIR}/VertexRep.cpp \
+ $${SCENE_GRAPH_DIR}/Rep.cpp \
+ $${SCENE_GRAPH_DIR}/SceneVisitor.cpp
+
+HEADERS *= $${SCENE_GRAPH_DIR}/DrawingStyle.h \
+ $${SCENE_GRAPH_DIR}/IndexedFaceSet.h \
+ $${SCENE_GRAPH_DIR}/LineRep.h \
+ $${SCENE_GRAPH_DIR}/Material.h \
+ $${SCENE_GRAPH_DIR}/MaxFileLoader.h \
+ $${SCENE_GRAPH_DIR}/Node.h \
+ $${SCENE_GRAPH_DIR}/NodeCamera.h \
+ $${SCENE_GRAPH_DIR}/NodeDrawingStyle.h \
+ $${SCENE_GRAPH_DIR}/NodeGroup.h \
+ $${SCENE_GRAPH_DIR}/NodeLight.h \
+ $${SCENE_GRAPH_DIR}/NodeShape.h \
+ $${SCENE_GRAPH_DIR}/NodeTransform.h \
+ $${SCENE_GRAPH_DIR}/OrientedLineRep.h \
+ $${SCENE_GRAPH_DIR}/Rep.h \
+ $${SCENE_GRAPH_DIR}/ScenePrettyPrinter.h \
+ $${SCENE_GRAPH_DIR}/SceneVisitor.h \
+ $${SCENE_GRAPH_DIR}/TriangleRep.h \
+ $${SCENE_GRAPH_DIR}/VertexRep.h