[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26410] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/blender_interface: Improvements of mesh importing .

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sat Jan 30 02:36:12 CET 2010


Revision: 26410
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26410
Author:   kjym3
Date:     2010-01-30 02:36:12 +0100 (Sat, 30 Jan 2010)

Log Message:
-----------
Improvements of mesh importing.

Previously mesh vertices imported from vlak nodes were transformed
from the camera coordinate system to the object local coordinate
system.  This causes a difficulty in recovering object local vertices
when mesh deforming modifiers (e.g., curve, cloth, and soft body) have
been applied.  Now the view map creation is done based on mesh
vertices in the camera coordinate system.  Advantages of this approach
includes: 1) faster mesh importing because of less matrix-based
transformations; and 2) proper handling of meshes with deforming
modifiers.

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

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-01-30 01:25:02 UTC (rev 26409)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp	2010-01-30 01:36:12 UTC (rev 26410)
@@ -207,32 +207,10 @@
 
 void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id)
 {
+	// 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;
-	
-	// Mesh *mesh = (Mesh *)ob->data;
-	//---------------------
-	// mesh => obr
-	
-	// 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);
-	//---------------------
-	// M allows to recover world coordinates from camera coordinates
-	// M => obr->ob->imat * obr->obmat  (multiplication from left to right)
-	float M[4][4];
-	mul_m4_m4m4(M, obr->ob->imat, obr->ob->obmat); 
-	
-	// 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);
-	// mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
-	//---------------------
-	// already calculated and availabe in vlak ?	
-//	printf("%s\n", obr->ob->id.name + 2);
-	
-	// We build the rep:
-	IndexedFaceSet *rep;
 	unsigned numFaces = 0;
 	int clip_1[3], clip_2[3];
 	for(int a=0; a < obr->totvlak; a++) {
@@ -250,6 +228,7 @@
 	if (numFaces == 0)
 		return;
 
+	// We allocate memory for the meshes to be imported
 	NodeTransform *currentMesh = new NodeTransform;
 	NodeShape * shape = new NodeShape;
 
@@ -283,11 +262,9 @@
 	ls.currentMIndex = 0;
 	
 	FrsMaterial 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.
-	//lib3ds_vector_transform(pvtmp, M, mesh->pointL[mesh->faceL[0].points[0]].pos);
 
+	// We parse the vlak nodes again and import meshes while applying the clipping
+	// by the near and far view planes.
 	int p;
 	for(p=0; p < obr->totvlak; ++p) // we parse the faces of the mesh
 	{
@@ -344,10 +321,6 @@
 
 			if (numTris_1 > 0) {
 				clipTriangle(numTris_1, triCoords, vlr->v1, vlr->v2, vlr->v3, clip_1);
-				for (i = 0; i < 2 + numTris_1; i++) {
-					mul_m4_v3(M, triCoords[i]); // camera to world
-//					printf("%d %f, %f, %f\n", i, triCoords[i][0], triCoords[i][1], triCoords[i][2]);
-				}
 				for (i = 0; i < numTris_1; i++) {
 					addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]);
 					_numFacesRead++;
@@ -356,10 +329,6 @@
 
 			if (numTris_2 > 0) {
 				clipTriangle(numTris_2, triCoords, vlr->v1, vlr->v3, vlr->v4, clip_2);
-				for (i = 0; i < 2 + numTris_2; i++) {
-					mul_m4_v3(M, triCoords[i]); // camera to world
-//					printf("%d %f, %f, %f\n", i, triCoords[i][0], triCoords[i][1], triCoords[i][2]);
-				}
 				for (i = 0; i < numTris_2; i++) {
 					addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]);
 					_numFacesRead++;
@@ -406,6 +375,7 @@
 	delete [] NIndices;
 	
 	// Create the IndexedFaceSet with the retrieved attributes
+	IndexedFaceSet *rep;
 	rep = new IndexedFaceSet(cleanVertices, cvSize, 
 	                         cleanNormals, cnSize,
 	                         marray, meshFrsMaterials.size(),

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-01-30 01:25:02 UTC (rev 26409)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-01-30 01:36:12 UTC (rev 26410)
@@ -94,16 +94,17 @@
 	}
 
 	void init_camera(Render* re){
-		Object* maincam_obj = re->scene->camera;
-		// Camera *cam = (Camera*) maincam_obj->data;
+		// It is assumed that imported meshes are in the camera coordinate system.
+		// Therefore, the view point (i.e., camera position) is at the origin, and
+		// the the model-view matrix is simply the identity matrix.
+
+		freestyle_viewpoint[0] = 0.0;
+		freestyle_viewpoint[1] = 0.0;
+		freestyle_viewpoint[2] = 0.0;
 		
-		freestyle_viewpoint[0] = maincam_obj->obmat[3][0];
-		freestyle_viewpoint[1] = maincam_obj->obmat[3][1];
-		freestyle_viewpoint[2] = maincam_obj->obmat[3][2];
-		
 		for( int i = 0; i < 4; i++ )
 		   for( int j = 0; j < 4; j++ )
-			freestyle_mv[i][j] = re->viewmat[i][j];
+			freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
 		
 		for( int i = 0; i < 4; i++ )
 		   for( int j = 0; j < 4; j++ )





More information about the Bf-blender-cvs mailing list