[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27019] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/blender_interface: Added support for procedural duplication ( such as DupliVerts and DupliFaces).

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Fri Feb 19 02:10:05 CET 2010


Revision: 27019
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27019
Author:   kjym3
Date:     2010-02-19 02:10:04 +0100 (Fri, 19 Feb 2010)

Log Message:
-----------
Added support for procedural duplication (such as DupliVerts and DupliFaces).

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp	2010-02-18 19:43:13 UTC (rev 27018)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp	2010-02-19 01:10:04 UTC (rev 27019)
@@ -19,7 +19,6 @@
 NodeGroup* BlenderFileLoader::Load()
 {
 	ObjectInstanceRen *obi;
-	ObjectRen *obr;
 
 	cout << "\n===  Importing triangular meshes into Blender  ===" << endl;
 
@@ -42,13 +41,14 @@
 	for(obi= (ObjectInstanceRen *) _re->instancetable.first; obi; obi=obi->next) {
 		if (!(obi->lay & _re->scene->lay & _srl->lay))
 			continue;
+		char *name = obi->ob->id.name;
+		//cout << name[0] << name[1] << ":" << (name+2) <<;
+		//print_m4("obi->mat", obi->mat);
 
-		obr= obi->obr;
-		
-		if( obr->totvlak > 0)
-			insertShapeNode(obr, ++id);
+		if( obi->obr->totvlak > 0)
+			insertShapeNode(obi, ++id);
 		else
-			cout << "  Sorry, only vlak-based shapes are supported." << endl;
+			cout << "Warning: " << (name+2) << " is not a vlak-based object (ignored)" << endl;
 	}
 
 	//Returns the built scene.
@@ -61,9 +61,9 @@
 
 // check if each vertex of a triangle (V1, V2, V3) is clipped by the near/far plane
 // and calculate the number of triangles to be generated by clipping
-int BlenderFileLoader::countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, int clip[3])
+int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3])
 {
-	VertRen *v[3];
+	float *v[3];
 	int numClipped, sum, numTris;
 
 	v[0] = v1;
@@ -71,10 +71,10 @@
 	v[2] = v3;
 	numClipped = sum = 0;
 	for (int i = 0; i < 3; i++) {
-		if (v[i]->co[2] > _z_near) {
+		if (v[i][2] > _z_near) {
 			clip[i] = CLIPPED_BY_NEAR;
 			numClipped++;
-		} else if (v[i]->co[2] < _z_far) {
+		} else if (v[i][2] < _z_far) {
 			clip[i] = CLIPPED_BY_FAR;
 			numClipped++;
 		} else {
@@ -109,23 +109,23 @@
 // find the intersection point C between the line segment from V1 to V2 and
 // a clipping plane at depth Z (i.e., the Z component of C is known, while
 // the X and Y components are unknown).
-void BlenderFileLoader::clipLine(VertRen *v1, VertRen *v2, float c[3], float z)
+void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z)
 {
 	double d[3];
 	for (int i = 0; i < 3; i++)
-		d[i] = v2->co[i] - v1->co[i];
-	double t = (z - v1->co[2]) / d[2];
-	c[0] = v1->co[0] + t * d[0];
-	c[1] = v1->co[1] + t * d[1];
+		d[i] = v2[i] - v1[i];
+	double t = (z - v1[2]) / d[2];
+	c[0] = v1[0] + t * d[0];
+	c[1] = v1[1] + t * d[1];
 	c[2] = z;
 }
 
 // clip the triangle (V1, V2, V3) by the near and far clipping plane and
 // obtain a set of vertices after the clipping.  The number of vertices
 // is at most 5.
-void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], VertRen *v1, VertRen *v2, VertRen *v3, int clip[3])
+void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], int clip[3])
 {
-	VertRen *v[3];
+	float *v[3];
 	int i, j, k;
 
 	v[0] = v1;
@@ -135,7 +135,7 @@
 	for (i = 0; i < 3; i++) {
 		j = (i + 1) % 3;
 		if (clip[i] == NOT_CLIPPED) {
-			copy_v3_v3(triCoords[k++], v[i]->co);
+			copy_v3_v3(triCoords[k++], v[i]);
 			if (clip[j] != NOT_CLIPPED) {
 				clipLine(v[i], v[j], triCoords[k++], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
 			}
@@ -205,24 +205,37 @@
 	}
 }
 
-void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id)
+void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
 {
+	ObjectRen *obr = obi->obr;
+
 	// We parse vlak nodes and count the number of faces after the clipping by
 	// the near and far view planes is applied (Note: mesh vertices are in the
 	// camera coordinate system).
 	VlakRen *vlr;
 	unsigned numFaces = 0;
+	float v1[3], v2[3], v3[3], v4[3];
 	int clip_1[3], clip_2[3];
 	for(int a=0; a < obr->totvlak; a++) {
 		if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
 		else vlr++;
-//		printf("v1 %f, %f, %f\n", vlr->v1->co[0], vlr->v1->co[1], vlr->v1->co[2]);
-//		printf("v2 %f, %f, %f\n", vlr->v2->co[0], vlr->v2->co[1], vlr->v2->co[2]);
-//		printf("v3 %f, %f, %f\n", vlr->v3->co[0], vlr->v3->co[1], vlr->v3->co[2]);
-//		if (vlr->v4) printf("v4 %f, %f, %f\n", vlr->v4->co[0], vlr->v4->co[1], vlr->v4->co[2]);
-		numFaces += countClippedFaces(vlr->v1, vlr->v2, vlr->v3, clip_1);
+		copy_v3_v3(v1, vlr->v1->co);
+		copy_v3_v3(v2, vlr->v2->co);
+		copy_v3_v3(v3, vlr->v3->co);
+		if (vlr->v4) copy_v3_v3(v4, vlr->v4->co);
+		if (obi->flag & R_TRANSFORMED) {
+			mul_m4_v3(obi->mat, v1);
+			mul_m4_v3(obi->mat, v2);
+			mul_m4_v3(obi->mat, v3);
+			if (vlr->v4) mul_m4_v3(obi->mat, v4);
+		}
+//		print_v3("v1", v1);
+//		print_v3("v2", v2);
+//		print_v3("v3", v3);
+//		if (vlr->v4) print_v3("v4", v4);
+		numFaces += countClippedFaces(v1, v2, v3, clip_1);
 		if (vlr->v4)
-			numFaces += countClippedFaces(vlr->v1, vlr->v3, vlr->v4, clip_2);
+			numFaces += countClippedFaces(v1, v3, v4, clip_2);
 	}
 //	cout <<"numFaces " <<numFaces<<endl;
 	if (numFaces == 0)
@@ -272,10 +285,20 @@
 			// Lib3dsMaterial *mat=0;
 			if((p & 255)==0) vlr = obr->vlaknodes[p>>8].vlak;
 			else vlr++;
+			copy_v3_v3(v1, vlr->v1->co);
+			copy_v3_v3(v2, vlr->v2->co);
+			copy_v3_v3(v3, vlr->v3->co);
+			if (vlr->v4) copy_v3_v3(v4, vlr->v4->co);
+			if (obi->flag & R_TRANSFORMED) {
+				mul_m4_v3(obi->mat, v1);
+				mul_m4_v3(obi->mat, v2);
+				mul_m4_v3(obi->mat, v3);
+				if (vlr->v4) mul_m4_v3(obi->mat, v4);
+			}
 
 			unsigned numTris_1, numTris_2;
-			numTris_1 = countClippedFaces(vlr->v1, vlr->v2, vlr->v3, clip_1);
-			numTris_2 = (vlr->v4) ? countClippedFaces(vlr->v1, vlr->v3, vlr->v4, clip_2) : 0;
+			numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
+			numTris_2 = (vlr->v4) ? countClippedFaces(v1, v3, v4, clip_2) : 0;
 			if (numTris_1 == 0 && numTris_2 == 0)
 				continue;
 
@@ -320,7 +343,7 @@
 			float triCoords[5][3];
 
 			if (numTris_1 > 0) {
-				clipTriangle(numTris_1, triCoords, vlr->v1, vlr->v2, vlr->v3, clip_1);
+				clipTriangle(numTris_1, triCoords, v1, v2, v3, clip_1);
 				for (i = 0; i < numTris_1; i++) {
 					addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]);
 					_numFacesRead++;
@@ -328,7 +351,7 @@
 			}
 
 			if (numTris_2 > 0) {
-				clipTriangle(numTris_2, triCoords, vlr->v1, vlr->v3, vlr->v4, clip_2);
+				clipTriangle(numTris_2, triCoords, v1, v3, v4, clip_2);
 				for (i = 0; i < numTris_2; i++) {
 					addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]);
 					_numFacesRead++;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h	2010-02-18 19:43:13 UTC (rev 27018)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h	2010-02-19 01:10:04 UTC (rev 27019)
@@ -62,11 +62,11 @@
   inline real minEdgeSize() {return _minEdgeSize;}
 
 protected:
-	void insertShapeNode(ObjectRen *obr, int id);
-	int countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, int clipped[3]);
-	void clipLine(VertRen *v1, VertRen *v2, float c[3], float z);
-	void clipTriangle(int numTris, float triCoords[][3], VertRen *v1, VertRen *v2, VertRen *v3, int clip[3]);
-	void addTriangle(struct LoaderState *state, float v1[3], float v2[3], float v3[3]);
+	void insertShapeNode(ObjectInstanceRen *obi, int id);
+	int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]);
+	void clipLine(float v1[3], float v2[3], float c[3], float z);
+	void clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], int clip[3]);
+	void addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3]);
 
 protected:
 	Render* _re;





More information about the Bf-blender-cvs mailing list