[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12311] branches/qdune/blender: MSVC compatibility fix, thanks to 'oogsnoepje' for the patch, though I

Alfredo de Greef eeshlo at yahoo.com
Sat Oct 20 21:09:14 CEST 2007


Revision: 12311
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12311
Author:   eeshlo
Date:     2007-10-20 21:09:14 +0200 (Sat, 20 Oct 2007)

Log Message:
-----------
MSVC compatibility fix, thanks to 'oogsnoepje' for the patch, though I
solved the problems a bit different, I hope it works...
Also added vertex normals, though doesn't quite work as it should yet.
The polygon mesh can only either be completely 'smooth' or 'solid'.
Setting individual faces to smooth shading doesn't work yet.
There is also a fix for a strange problem I seemed to experience
somewhat randomly. The halton_sample() function in rayshade.c
(it is not even used, but apparently is still called) caused some
mysterious 'freezes' from time to time. The cause for this
was a value becoming negative, and causing an infinite loop.
This minor modification makes sure it is always positive.

Modified Paths:
--------------
    branches/qdune/blender/extern/qdune/core/Mathutil.h
    branches/qdune/blender/extern/qdune/core/QDRender.h
    branches/qdune/blender/extern/qdune/ribparse/ri.cpp
    branches/qdune/blender/source/blender/render/intern/source/convertblender.c
    branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
    branches/qdune/blender/source/blender/render/intern/source/rayshade.c

Modified: branches/qdune/blender/extern/qdune/core/Mathutil.h
===================================================================
--- branches/qdune/blender/extern/qdune/core/Mathutil.h	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/extern/qdune/core/Mathutil.h	2007-10-20 19:09:14 UTC (rev 12311)
@@ -7,6 +7,9 @@
 
 #define _USE_MATH_DEFINES
 #include <cmath>
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
 #include <cassert>
 // for mem...()
 #include <cstring>

Modified: branches/qdune/blender/extern/qdune/core/QDRender.h
===================================================================
--- branches/qdune/blender/extern/qdune/core/QDRender.h	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/extern/qdune/core/QDRender.h	2007-10-20 19:09:14 UTC (rev 12311)
@@ -7,6 +7,13 @@
 #include <exception>
 #include <cstdio>
 
+#ifdef _MSC_VER
+#define and &&
+#define or ||
+#define not !
+#define strcasecmp stricmp
+#endif
+
 //-------------------------------------------------------------------------------
 // exception class for error reports
 class RiException_t : public std::exception

Modified: branches/qdune/blender/extern/qdune/ribparse/ri.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/ribparse/ri.cpp	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/extern/qdune/ribparse/ri.cpp	2007-10-20 19:09:14 UTC (rev 12311)
@@ -1422,7 +1422,9 @@
 		return;
 	}
 	if (!haveP("RiPolygonV", n, tokens, parms)) return;
-	State::Instance()->insert(new Polygon(nverts, n, tokens, parms), motion_pos);
+	// we're using the namespace here to prevent the MSVC compiler from getting confused, as Polygon
+	// is already defined as a GDI function...
+	State::Instance()->insert(new QDRender::Polygon(nverts, n, tokens, parms), motion_pos);
 }
 
 RtVoid RiGeneralPolygon(RtInt nloops, RtInt nverts[], ...)

Modified: branches/qdune/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/convertblender.c	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/source/blender/render/intern/source/convertblender.c	2007-10-20 19:09:14 UTC (rev 12311)
@@ -1253,7 +1253,16 @@
 	   (ob->fluidsimSettings->meshSurface) )
 		rmesh.use_fluid_normals= 1;
 
-	rmesh.use_vertex_normals= rmesh.use_fluid_normals;
+	if (re->r.renderer == R_QDUNE)	{
+		// need vertex normals for qdune renderer
+		// For now, use the state of the flag of the first face in the mesh,
+		// but really should know per face/vertex if it is smooth.
+		// (face has smooth flag, but since vertex normals are added in add_vertex(),
+		//  it needs a smooth flag or access to corresponding face, but has neither currently)
+		rmesh.use_vertex_normals = ((me->mface->flag & ME_SMOOTH) != 0);
+	}
+	else
+		rmesh.use_vertex_normals= rmesh.use_fluid_normals;
 
 	/* attempt to autsmooth on original mesh, only without subsurf */
 	if(do_autosmooth && me->totvert==totvert && me->totface==totface)

Modified: branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/qdinterface.c	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/source/blender/render/intern/source/qdinterface.c	2007-10-20 19:09:14 UTC (rev 12311)
@@ -52,6 +52,7 @@
 	int *nverts;
 	int *verts;
 	float *P;
+	float *No;
 	float (*orco)[3];
 	float (*sticky)[3];
 	float (*uv[8])[3];
@@ -115,8 +116,13 @@
 		if(object->totmaterial > 0)
 			ppoly->material= MEM_callocN(sizeof(float)*mesh->maxface, "QDPPolyMat");
 	}
-	if(mesh->maxvert)
+	if(mesh->maxvert) {
 		ppoly->P= MEM_callocN(sizeof(float)*3*mesh->maxvert, "QDPPolyP");
+		if (mesh->use_vertex_normals && (!mesh->do_subsurf))
+			ppoly->No = MEM_callocN(sizeof(float)*3*mesh->maxvert, "QDPPolyNo");
+		else
+			ppoly->No = NULL;
+	}
 
 	memset(curve, 0, sizeof(QDCurves));
 
@@ -154,10 +160,14 @@
 	QDRenderContext *qdcontext= iface->context;
 	QDPointsPolygons *ppoly= &qdcontext->ppoly;
 	RenderMesh *mesh= qdcontext->mesh;
-	float *P;
+	float *P, *No;
 
 	P= &ppoly->P[ppoly->totvert*3];
 	VECCOPY(P, vertex->co);
+	if (mesh->use_vertex_normals  && (!mesh->do_subsurf)) {
+		No = &ppoly->No[ppoly->totvert*3];
+		VECCOPY(No, vertex->n);
+	}
 
 	if(vertex->orco) {
 		if(!ppoly->orco)
@@ -325,6 +335,11 @@
 		tokens[n]= "P";
 		params[n]= ppoly->P;
 		n++;
+		if (mesh->use_vertex_normals  && (!mesh->do_subsurf)) {
+			tokens[n]= "N";
+			params[n]= ppoly->No;
+			n++;
+		}
 
 		if(ppoly->material) {
 			tokens[n]= "uniform float material";
@@ -368,6 +383,7 @@
 	if(ppoly->verts) MEM_freeN(ppoly->verts);
 	if(ppoly->nverts) MEM_freeN(ppoly->nverts);
 	if(ppoly->P) MEM_freeN(ppoly->P);
+	if(ppoly->No) MEM_freeN(ppoly->No);
 	if(ppoly->orco) MEM_freeN(ppoly->orco);
 	if(ppoly->sticky) MEM_freeN(ppoly->sticky);
 	if(ppoly->stress) MEM_freeN(ppoly->stress);

Modified: branches/qdune/blender/source/blender/render/intern/source/rayshade.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/rayshade.c	2007-10-20 18:57:40 UTC (rev 12310)
+++ branches/qdune/blender/source/blender/render/intern/source/rayshade.c	2007-10-20 19:09:14 UTC (rev 12311)
@@ -638,10 +638,10 @@
 	// incremental halton sequence generator, from:
 	// "Instant Radiosity", Keller A.
 	unsigned int i;
-	
+
 	for (i = 0; i < 2; i++)
 	{
-		double r = (1.0 - ht_nums[i]) - 1e-10;
+		double r = fabs((1.0 - ht_nums[i]) - 1e-10);
 		
 		if (ht_invprimes[i] >= r)
 		{
@@ -719,11 +719,13 @@
 		ht_invprimes[0] = 0.5;
 		ht_invprimes[1] = 1.0/3.0;
 		
+		//printf("QSA_TOT -> %d (thread: %d)\n", qsa->tot, thread), fflush(stdout);
 		for (i=0; i< qsa->tot; i++) {
 			halton_sample(ht_invprimes, ht_nums, r);
 			qsa->samp2d[2*i+0] = r[0];
 			qsa->samp2d[2*i+1] = r[1];
 		}
+		//printf("QMC DONE (thread: %d)\n", thread), fflush(stdout);
 	}
 }
 





More information about the Bf-blender-cvs mailing list