Revision: 20840
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20840
Author:   eman
Date:     2009-06-12 23:02:17 +0200 (Fri, 12 Jun 2009)

Log Message:
-----------
First pass of Laurynas's Trimming Curve system.
This is incomplete, and does not expose any new functionality (yet).

Modified Paths:
--------------
    branches/nurbs/blender/intern/nurbana/CMakeLists.txt
    branches/nurbs/blender/intern/nurbana/extern/nurbana.h
    branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.cpp
    branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.h
    branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
    branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.h
    branches/nurbs/blender/intern/nurbana/intern/blenderNurbsStruct.h
    branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
    branches/nurbs/blender/source/blender/blenkernel/BKE_displist.h
    branches/nurbs/blender/source/blender/blenkernel/intern/curve.c
    branches/nurbs/blender/source/blender/blenkernel/intern/displist.c
    branches/nurbs/blender/source/blender/blenkernel/intern/mesh.c
    branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h
    branches/nurbs/blender/source/blender/render/intern/source/convertblender.c
    branches/nurbs/blender/source/blender/src/drawobject.c

Added Paths:
-----------
    branches/nurbs/blender/intern/nurbana/intern/nbGridTessellator.cpp
    branches/nurbs/blender/intern/nurbana/intern/nbGridTessellator.h
    branches/nurbs/blender/intern/nurbana/intern/nbTessellator.cpp
    branches/nurbs/blender/intern/nurbana/intern/nbTessellator.h
    branches/nurbs/blender/intern/nurbana/intern/nbTrimTessellator.cpp
    branches/nurbs/blender/intern/nurbana/intern/nbTrimTessellator.h
    branches/nurbs/blender/intern/nurbana/intern/trim/
    branches/nurbs/blender/intern/nurbana/intern/trim/nbSubDiv.cpp
    branches/nurbs/blender/intern/nurbana/intern/trim/nbSubDiv.h
    branches/nurbs/blender/intern/nurbana/intern/trim/nbTessGrid.cpp
    branches/nurbs/blender/intern/nurbana/intern/trim/nbTessGrid.h
    branches/nurbs/blender/intern/nurbana/intern/trim/nbTrimPatch.cpp
    branches/nurbs/blender/intern/nurbana/intern/trim/nbTrimPatch.h

Modified: branches/nurbs/blender/intern/nurbana/CMakeLists.txt
===================================================================
--- branches/nurbs/blender/intern/nurbana/CMakeLists.txt        2009-06-12 
19:13:52 UTC (rev 20839)
+++ branches/nurbs/blender/intern/nurbana/CMakeLists.txt        2009-06-12 
21:02:17 UTC (rev 20840)
@@ -28,8 +28,9 @@
 
 SET(INC include)
 
-FILE(GLOB SRC intern/*.cpp intern/opennurbs/*.cpp intern/opennurbs/*.c 
intern/opennurbs/zlib/*.c)
+FILE(GLOB SRC intern/*.cpp intern/opennurbs/*.cpp intern/opennurbs/*.c 
intern/opennurbs/zlib/*.c intern/trim/*.cpp)
 
-INCLUDE_DIRECTORIES(../../intern/guardedalloc ./opennurbs ./opennurbs/zlib)
+
+INCLUDE_DIRECTORIES(../../intern/guardedalloc ./opennurbs ./opennurbs/zlib 
intern/trim)
 BLENDERLIB(bf_nurbana "${SRC}" "${INC}")
 #, libtype=['intern','game','game2','player'], priority = [15, 55, 100, 135] )

Modified: branches/nurbs/blender/intern/nurbana/extern/nurbana.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/extern/nurbana.h      2009-06-12 
19:13:52 UTC (rev 20839)
+++ branches/nurbs/blender/intern/nurbana/extern/nurbana.h      2009-06-12 
21:02:17 UTC (rev 20840)
@@ -109,6 +109,7 @@
 //extern NurbanaObj_ptr NRB_addObject(Point3d** CtlPts, short* numCPu, short* 
numCPv, short* orderU, short* orderV, nbReal** knotsU, nbReal** knotsV,  short* 
cyclicU,  short* cyclicV, short* knottypeu, short* knottypev,  short* resolu,  
short* resolv, short* isores, short* isoden, short* isovis) ;
 extern NurbanaObj_ptr NRB_addObject(BlenderNurbs_ptr bNurbs);
 
+
 //extern NurbanaObj_ptr NRB_allocate();
 //extern void NRB_deallocate(NurbanaObj_ptr nop);
 extern void NRB_init(NurbanaObj_ptr nop);
@@ -120,8 +121,10 @@
 
 extern void NRB_changeCyclic(NurbanaObj_ptr nop,int uv);
 
+extern void NRB_getTriangleNormals(float v0[], float v1[], float v2[], float 
n0[], float n1[], float n2[]);
+extern void NRB_getTrimTess(NurbanaObj_ptr surface, float** vertex, int** 
index, int* totindex, float** norm);
+extern void NRB_addTrimCurve(NurbanaObj_ptr surface, void* curve);
 
-
 extern void NRB_ResChanged(NurbanaObj_ptr nop );
 extern void NRB_SizeChanged(NurbanaObj_ptr nop, int newU, int newV);
 extern void NRB_UpdateSize(NurbanaObj_ptr nop);
@@ -155,6 +158,13 @@
 extern void NRB_setIsoDensity(NurbanaObj_ptr nop,int den);
 extern nbReal* NRB_getIsoPoints(NurbanaObj_ptr nop, nbReal* buffer);
 
+
+extern int NRB_getTrianIndexCount(NurbanaObj_ptr nop);
+extern int NRB_getQuadIndexCount(NurbanaObj_ptr nop);
+extern void NRB_getTrianIndexes(NurbanaObj_ptr nop, int* indexes);
+extern void NRB_getQuadIndexes(NurbanaObj_ptr nop, int* indexes);
+extern void NRB_getNormals(NurbanaObj_ptr nop, int* qIndexes, int* tIndexes, 
nbReal* verts, nbReal* nors);
+extern int NRB_getVertexCount(NurbanaObj_ptr nop);
 //extern nbReal* NRB_GenerateSurface(NurbanaObj_ptr nop, nbReal* buffer, int 
dim );
 extern nbReal* NRB_GenerateSurface(NurbanaObj_ptr nop, nbReal* buffer, int 
resU, int resV, int dim);
 

Modified: branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.cpp        
2009-06-12 19:13:52 UTC (rev 20839)
+++ branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.cpp        
2009-06-12 21:02:17 UTC (rev 20840)
@@ -214,3 +214,91 @@
     free(M);
   } //fi
 } //eof NurbanaMath::MultMatrix()
+
+void NurbanaMath::crossProd(nbReal c[], nbReal a[], nbReal b[]) {
+       c[0] = a[1] * b[2] - a[2] * b[1];
+       c[1] = a[2] * b[0] - a[0] * b[2];
+       c[2] = a[0] * b[1] - a[1] * b[0];
+}
+
+void NurbanaMath::calcNormal(nbReal n[], const nbReal o[], const nbReal a[], 
const nbReal b[]) {
+       nbReal v0[3];
+       nbReal v1[3];
+       //nbReal dotProd[3];
+       nbReal dP = 0;
+       for (int i = 0; i < 3; i++) {
+               v0[i] = a[i] - o[i];
+               v1[i] = b[i] - o[i];
+       }
+       crossProd(n, v1, v0);
+       normalize(n);
+}
+
+float NurbanaMath::getAngleSinSquare(const nbReal o[], const nbReal a[], const 
nbReal b[]) {
+       nbReal v0[3];
+       nbReal v1[3];
+       //nbReal dotProd[3];
+       nbReal dP = 0;
+       for (int i = 0; i < 3; i++) {
+               v0[i] = a[i] - o[i];
+               v1[i] = b[i] - o[i];
+       }
+       NurbanaMath::normalize(v0);
+       NurbanaMath::normalize(v1);
+       for (int i = 0; i < 3; i++)
+           dP += v0[i] * v1[i];
+       return 1 - dP * dP;
+}
+
+void NurbanaMath::vectAdd(nbReal to[], const nbReal vect[]) {
+       to[0] += vect[0];
+       to[1] += vect[1];
+       to[2] += vect[2];
+}
+void NurbanaMath::normalize(nbReal a[]) {
+       //TODO take code from blender
+       nbReal d = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
+       if(d>1.0e-15F) {
+               d = (nbReal)sqrt(d);
+               a[0] /= d;
+               a[1] /= d;
+               a[2] /= d;
+       } else {
+               a[0] = a[1] = a[2] = 0;
+               printf("zero normal\n");
+       }
+}
+
+void NurbanaMath::getTriangleNormals(const float v0[], const float v1[], const 
float v2[], float n0[], float n1[], float n2[]) {
+       const nbReal* corners[3] = {&v0[0], &v1[0], &v2[0]};//, verts + 
indexes[i + 3] * 3};
+       nbReal *(normals[3]) = {n0, n1, n2};
+       nbReal normal[3];
+       NurbanaMath::calcNormal(normal, corners[0], corners[2], corners[1]);
+       for (unsigned corner = 0; corner < 3; corner++) {
+               nbReal coef = NurbanaMath::getAngleSinSquare(corners[0], 
corners[2], corners[1]);
+               for (int j = 0; j < 3; j++)
+                       normals[corner][j]+=normal[j]*coef;
+
+               const nbReal *tmp = corners[0];
+               for (unsigned j = 1; j < 3; j++)
+                       corners[j - 1] = corners[j];
+               corners[2] = tmp;
+       }       
+}
+
+void NurbanaMath::getQuadNormals(const float v0[], const float v1[], const 
float v2[], const float v3[], float n0[], float n1[], float n2[], float n3[]) {
+       const nbReal* corners[4] = {&v0[0], &v1[0], &v2[0], &v3[0]};//, verts + 
indexes[i + 3] * 3};
+       nbReal *(normals[4]) = {n0, n1, n2, n3};
+       nbReal normal[3];
+       for (unsigned corner = 0; corner < 4; corner++) {
+               NurbanaMath::calcNormal(normal, corners[0], corners[2], 
corners[1]);
+               nbReal coef = 1;//NurbanaMath::getAngleSinSquare(corners[0], 
corners[2], corners[1]);
+               for (int j = 0; j < 3; j++)
+                       normals[corner][j]+=normal[j]*coef;
+
+               const nbReal *tmp = corners[0];
+               for (unsigned j = 1; j < 4; j++)
+                       corners[j - 1] = corners[j];
+               corners[3] = tmp;
+       }       
+}

Modified: branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.h  2009-06-12 
19:13:52 UTC (rev 20839)
+++ branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.h  2009-06-12 
21:02:17 UTC (rev 20840)
@@ -45,6 +45,14 @@
     
     static  void convertTo4D(nbReal4& point);
     static  void projectTo3D(nbReal4& point);
+    
+    static void crossProd(nbReal c[], nbReal a[], nbReal b[]);
+       static void calcNormal(nbReal n[], const nbReal o[], const nbReal a[], 
const nbReal b[]);
+       static void vectAdd(nbReal to[], const nbReal vect[]);
+       static void normalize(nbReal a[]);
+       static float getAngleSinSquare(const nbReal o[], const nbReal a[], 
const nbReal b[]);
+       static void getTriangleNormals(const float v0[], const float v1[], 
const float v2[], float n0[], float n1[], float n2[]);
+       static void getQuadNormals(const float v0[], const float v1[], const 
float v2[], const float v3[], float n0[], float n1[], float n2[], float n3[]);
 
     static     void    IdentityMatrix(nbReal *M, int S);
     static     void    InvertMatrix(nbReal *M, int S);

Modified: branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp       
2009-06-12 19:13:52 UTC (rev 20839)
+++ branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp       
2009-06-12 21:02:17 UTC (rev 20840)
@@ -1,26 +1,9 @@
 #include "Object_NURBS.h"
-/*
-Object_NURBS::Object_NURBS(Point3d** CtlPts, short* numCPu, short* numCPv, 
short *orderU, short *orderV, nbReal** knotsU, nbReal** knotsV,short* flagU, 
short* flagV, short* knotTypeU, short* knotTypeV, short* resolu, short* resolv, 
short* isores, short* isoden, short* isovis) {//: Object_Base(CtlPts, numCPu, 
numCPv, resolu, resolv, isores, isoden) {
-//     int     i;
-       m_recalculateKnotVectorU = m_recalculateKnotVectorU = false;
-       m_change[0]= m_change[1]= 0;
-       m_recalculateKnotVector= 0;//_FlagUV[0]= _FlagUV[1]= 0;
-       
-       m_sumIPC[0] = NULL;
-       m_sumIPC[1] = NULL;
-       
-       m_ctlPtsOld = NULL;
-       m_oldBuffer = NULL;
-       m_sum = NULL;
-       
-       if (m_blenderData->m_pntsuv[0] + m_blenderData->m_pntsuv[1]) {
-               SetCacheBuffer();
-               ResetIsoLines();
-       }
-       //_Normals= 
(nbReal3*)MEM_callocN(sizeof(nbReal3)*(2*OBJECT_MAX_DENSITY*OBJECT_MAX_DENSITY),"_Normals");
 
-} //eof Object_NURBS::Object_NURBS()
-*/
+#include "nbGridTessellator.h"
+#include "nbTrimTessellator.h"
+
+
 Object_NURBS::Object_NURBS(){
        m_blenderData = NULL;
 /*     m_next = NULL;
@@ -65,6 +48,7 @@
        m_sumIPC[0] = NULL;
        m_sumIPC[1] = NULL;
 }
+
 Object_NURBS::Object_NURBS(BlenderNurbs *bNurbs){
        m_blenderData = bNurbs;
        /*m_next = bNurbs->m_next;
@@ -114,7 +98,46 @@
                ResetIsoLines();
        }
 
+       //m_trimCurve = (Nurb**)trimCurve;
+       if (m_blenderData->m_trimCurve) { 
+               tsslltr = new nbTrimTessellator(*this);
+               tsslltr->update();
+       } else {
+               tsslltr = new nbGridTessellator(*this);
+       }
 }
+
+
+
+
+
+nbPolygon& Object_NURBS::getTess(nbPolygon& p) {
+       unsigned int c2[][3]= {
+//                     {0.5, 0.5}, {0.7, 0.5}, {0.7, 0.7}, {0.5, 0.7}
+                       {-1, -1}, {10, -1}, {10, 10}, {-1, 10}
+       };
+       nbPolygon p2;
+       unsigned pntCount = getLength(0, false) * m_blenderData->m_resoluv[0];
+       float (*array)[3] = new float[pntCount][3];
+       float *tess = &array[0][0];
+       NURBS_Generate::Curve(this, tess, NULL, NULL, pntCount, false);
+       p2.setCoords(array, pntCount);
+       p2.close();
+       p.merge(p2);
+       return p; //FIXME eman check correct
+}
+
+void Object_NURBS::addTrimCurve(Nurb* curve) {
+       if (!m_blenderData->m_trimCurve) {
+               if (tsslltr)
+                       delete tsslltr;
+               tsslltr = new nbTrimTessellator(*this);
+       } else {
+               //TODO reomove old curve
+       }
+       m_blenderData->m_trimCurve = curve;
+}
+
 Object_NURBS::~Object_NURBS() {
 /*  if(m_sum)
                MEM_freeN(m_sum);
@@ -130,11 +153,13 @@
 
 void Object_NURBS::ResetIsoLines()
 {
+
        if(m_sumIPC[0])
                MEM_freeN(m_sumIPC[0]); 
        if(m_sumIPC[1])
                MEM_freeN(m_sumIPC[1]); 
 
+
        if(m_blenderData->m_isovis)
        {
                m_sumIPC[0] = (nbReal*)MEM_mallocN(sizeof(nbReal)*IPCTotPts(), 
"m_sumIPC[0]");
@@ -156,15 +181,17 @@
                if(m_blenderData->m_knotsuv[0])
                        MEM_freeN(m_blenderData->m_knotsuv[0]);
                m_blenderData->m_knotsuv[0] = newKnotVector;
-       }       
+       }
 }
 
 void Object_NURBS::SetCacheBuffer() {
        int U = iGetLength(0);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to