← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1744: 1. Fix facet lighting, mill shown with wire=False now (looks better)

 

Merge authors:
  Václav Šmilauer <vaclav@flux>
------------------------------------------------------------
revno: 1744 [merge]
committer: Václav Šmilauer <vaclav@flux>
branch nick: trunk
timestamp: Fri 2009-08-28 08:41:57 +0200
message:
  1. Fix facet lighting, mill shown with wire=False now (looks better)
  2. Revert recent useless change in QtGUI-python
removed:
  examples/mill.py
added:
  examples/mill.py
modified:
  gui/qt3/QtGUI-python.cpp
  lib/opengl/OpenGLWrapper.hpp
  pkg/common/RenderingEngine/GLDrawGeometricalModel/GLDrawFacet.cpp
  pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp
  scripts/debian-prep


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== removed file 'examples/mill.py'
--- examples/mill.py	2009-08-27 22:37:02 +0000
+++ examples/mill.py	1970-01-01 00:00:00 +0000
@@ -1,74 +0,0 @@
-# encoding: utf-8
-from yade import pack
-from numpy import linspace
-# geometry parameters
-bumpNum=20
-bumpHt,bumpTipAngle=0.07,60*pi/180
-millRad,millDp=1,1 # radius and depth (cylinder length) of the mill
-sphRad,sphRadFuzz=0.03,.8 # mean radius and relative fuzz of the radius (random, uniformly distributed between sphRad*(1-.5*sphRadFuzz)…sphRad*(1+.5*sphRadFuzz))
-dTheta=pi/24 # circle division angle
-
-
-
-###
-### mill geometry (parameteric)
-###
-bumpPeri=2*bumpHt*tan(.5*bumpTipAngle) # length of a bump on the perimeter of the mill
-bumpAngle=bumpPeri/millRad # angle of one bump from the axis of the mill
-interBumpAngle=2*pi/bumpNum
-bumpRad=millRad-bumpHt
-pts=[]; thMin=0
-for i in range(0,bumpNum):
-	thMin+=interBumpAngle
-	thMax=thMin+interBumpAngle-bumpAngle
-	thTip=thMax+.5*bumpAngle
-	# the circular parts spanning from thMin to thMax
-	for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint=True):
-		pts.append(Vector3(-.5*millDp,millRad*cos(th0),millRad*sin(th0)))
-	# tip of the bump
-	pts.append(Vector3(-.5*millDp,bumpRad*cos(thTip),bumpRad*sin(thTip)))
-# close the curve
-pts+=[pts[0]]
-# make the second contour, just shifted by millDp; ppts contains both
-ppts=[pts,[p+Vector3(millDp,0,0) for p in pts]]
-mill=pack.sweptPolylines2gtsSurface(ppts,threshold=.01*min(dTheta*millRad,bumpHt))#,capStart=True,capEnd=True)
-millIds=O.bodies.append(pack.gtsSurface2Facets(mill,color=(1,0,1))) # add triangles, save their ids
-# make the caps less comfortably, but looking better as two triangle couples over the mill
-mrs2=millRad*sqrt(2)
-cap1,cap2=[Vector3(0,0,mrs2),Vector3(0,-mrs2,0),Vector3(0,0,-mrs2)],[Vector3(0,0,mrs2),Vector3(0,0,-mrs2),Vector3(0,mrs2,0)] # 2 triangles at every side
-for xx in -.5*millDp,.5*millDp: millIds+=O.bodies.append([utils.facet([p+Vector3(xx,0,0) for p in cap1],color=(0,0,0)),utils.facet([p+Vector3(xx,0,0) for p in cap2],color=(0,0,0))])
-
-# define domains for initial cloud of red and blue spheres
-packHt=.8*millRad # size of the area
-bboxes=[(Vector3(-.5*millDp,-.5*packHt,-.5*packHt),Vector3(.5*millDp,0,.5*packHt)),(Vector3(-.5*millDp,0,-.5*packHt),Vector3(.5*millDp,.5*packHt,.5*packHt))]
-colors=(1,0,0),(0,0,1)
-for i in (0,1): # red and blue spheres
-	sp=pack.SpherePack(); bb=bboxes[i]; vol=(bb[1][0]-bb[0][0])*(bb[1][1]-bb[0][1])*(bb[1][2]-bb[0][2])
-	sp.makeCloud(bb[0],bb[1],sphRad,sphRadFuzz,int(.25*vol/((4./3)*pi*sphRad**3)),False)
-	O.bodies.append([utils.sphere(s[0],s[1],density=3000,color=colors[i]) for s in sp])
-
-print "Numer of grains",len(O.bodies)-len(millIds)
-
-O.dt=utils.PWaveTimeStep()
-
-O.engines=[
-	BexResetter(),
-	BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingFacet2AABB(),MetaInteractingGeometry2AABB()]),
-	InsertionSortCollider(),
-	InteractionDispatchers(
-		[ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
-		[SimpleElasticRelationships()],
-		[Law2_Dem3Dof_Elastic_Elastic()],
-	),
-	GravityEngine(gravity=(0,0,-3e4)), # gravity artificially high, to make it faster going ;-)
-	RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(1,0,0),angularVelocity=-120,subscribedBodies=millIds),
-	SnapshotEngine(iterPeriod=30,fileBase='/tmp/mill-',viewNo=0,label='snapshooter'),
-	NewtonsDampedLaw(damping=.3),
-]
-
-O.saveTmp()
-from yade import qt
-v=qt.View()
-v.eyePosition=(3,.8,.96); v.upVector=(-.4,-.4,.8); v.viewDir=(-.9,-.25,-.3); v.axes=True; v.sceneRadius=1.9
-O.run(10000); O.wait()
-utils.encodeVideoFromFrames(snapshooter['savedSnapshots'],out='/tmp/mill.ogg',fps=30)

=== added file 'examples/mill.py'
--- examples/mill.py	1970-01-01 00:00:00 +0000
+++ examples/mill.py	2009-08-28 06:41:57 +0000
@@ -0,0 +1,74 @@
+# encoding: utf-8
+from yade import pack
+from numpy import linspace
+# geometry parameters
+bumpNum=20
+bumpHt,bumpTipAngle=0.07,60*pi/180
+millRad,millDp=1,1 # radius and depth (cylinder length) of the mill
+sphRad,sphRadFuzz=0.03,.8 # mean radius and relative fuzz of the radius (random, uniformly distributed between sphRad*(1-.5*sphRadFuzz)…sphRad*(1+.5*sphRadFuzz))
+dTheta=pi/24 # circle division angle
+
+
+
+###
+### mill geometry (parameteric)
+###
+bumpPeri=2*bumpHt*tan(.5*bumpTipAngle) # length of a bump on the perimeter of the mill
+bumpAngle=bumpPeri/millRad # angle of one bump from the axis of the mill
+interBumpAngle=2*pi/bumpNum
+bumpRad=millRad-bumpHt
+pts=[]; thMin=0
+for i in range(0,bumpNum):
+	thMin+=interBumpAngle
+	thMax=thMin+interBumpAngle-bumpAngle
+	thTip=thMax+.5*bumpAngle
+	# the circular parts spanning from thMin to thMax
+	for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint=True):
+		pts.append(Vector3(-.5*millDp,millRad*cos(th0),millRad*sin(th0)))
+	# tip of the bump
+	pts.append(Vector3(-.5*millDp,bumpRad*cos(thTip),bumpRad*sin(thTip)))
+# close the curve
+pts+=[pts[0]]
+# make the second contour, just shifted by millDp; ppts contains both
+ppts=[pts,[p+Vector3(millDp,0,0) for p in pts]]
+mill=pack.sweptPolylines2gtsSurface(ppts,threshold=.01*min(dTheta*millRad,bumpHt))#,capStart=True,capEnd=True)
+millIds=O.bodies.append(pack.gtsSurface2Facets(mill,color=(1,0,1),wire=False)) # add triangles, save their ids
+# make the caps less comfortably, but looking better as two triangle couples over the mill
+mrs2=millRad*sqrt(2)
+cap1,cap2=[Vector3(0,0,mrs2),Vector3(0,-mrs2,0),Vector3(0,0,-mrs2)],[Vector3(0,0,mrs2),Vector3(0,0,-mrs2),Vector3(0,mrs2,0)] # 2 triangles at every side
+for xx in -.5*millDp,.5*millDp: millIds+=O.bodies.append([utils.facet([p+Vector3(xx,0,0) for p in cap1],color=(0,0,0)),utils.facet([p+Vector3(xx,0,0) for p in cap2],color=(0,0,0))])
+
+# define domains for initial cloud of red and blue spheres
+packHt=.8*millRad # size of the area
+bboxes=[(Vector3(-.5*millDp,-.5*packHt,-.5*packHt),Vector3(.5*millDp,0,.5*packHt)),(Vector3(-.5*millDp,0,-.5*packHt),Vector3(.5*millDp,.5*packHt,.5*packHt))]
+colors=(1,0,0),(0,0,1)
+for i in (0,1): # red and blue spheres
+	sp=pack.SpherePack(); bb=bboxes[i]; vol=(bb[1][0]-bb[0][0])*(bb[1][1]-bb[0][1])*(bb[1][2]-bb[0][2])
+	sp.makeCloud(bb[0],bb[1],sphRad,sphRadFuzz,int(.25*vol/((4./3)*pi*sphRad**3)),False)
+	O.bodies.append([utils.sphere(s[0],s[1],density=3000,color=colors[i]) for s in sp])
+
+print "Numer of grains",len(O.bodies)-len(millIds)
+
+O.dt=utils.PWaveTimeStep()
+
+O.engines=[
+	BexResetter(),
+	BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingFacet2AABB(),MetaInteractingGeometry2AABB()]),
+	InsertionSortCollider(),
+	InteractionDispatchers(
+		[ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
+		[SimpleElasticRelationships()],
+		[Law2_Dem3Dof_Elastic_Elastic()],
+	),
+	GravityEngine(gravity=(0,0,-3e4)), # gravity artificially high, to make it faster going ;-)
+	RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(1,0,0),angularVelocity=-120,subscribedBodies=millIds),
+	SnapshotEngine(iterPeriod=30,fileBase='/tmp/mill-',viewNo=0,label='snapshooter'),
+	NewtonsDampedLaw(damping=.3),
+]
+
+O.saveTmp()
+from yade import qt
+v=qt.View()
+v.eyePosition=(3,.8,.96); v.upVector=(-.4,-.4,.8); v.viewDir=(-.9,-.25,-.3); v.axes=True; v.sceneRadius=1.9
+O.run(20000); O.wait()
+utils.encodeVideoFromFrames(snapshooter['savedSnapshots'],out='/tmp/mill.ogg',fps=30)

=== modified file 'gui/qt3/QtGUI-python.cpp'
--- gui/qt3/QtGUI-python.cpp	2009-08-20 12:00:28 +0000
+++ gui/qt3/QtGUI-python.cpp	2009-08-27 22:29:04 +0000
@@ -172,6 +172,12 @@
 	return ret;
 };
 
+pyGLViewer getPlayerView(){
+	shared_ptr<QtSimulationPlayer> player=ensuredMainWindow()->player;
+	if(!player) throw runtime_error("Player is not active, unable to get its view");
+	return pyGLViewer(0);
+}
+
 
 BOOST_PYTHON_MODULE(_qt){
 	def("Generator",evtGENERATOR,"Start simulation generator");
@@ -185,6 +191,7 @@
 	def("activate",qtGuiActivate,"Attempt to activate the Qt GUI from within python.");
 	def("runPlayerSession",runPlayerSession,runPlayerSession_overloads(args("savedQGLState","dispParamsNo","stride","postLoadHook","startWait")));
 	def("views",getAllViews);
+	def("getPlayerView",getPlayerView,"Get the 3d view of the player (raises exception if player not active)");
 
 	python::class_<OpenGLRenderingEngine, shared_ptr<OpenGLRenderingEngine>, python::bases<Serializable>, noncopyable>("OpenGLRenderingEngine")
 		.def("setRefSe3",&OpenGLRenderingEngine_setBodiesRefSe3,"Make current positions and orientation reference for scaleDisplacements and scaleRotations.");

=== modified file 'lib/opengl/OpenGLWrapper.hpp'
--- lib/opengl/OpenGLWrapper.hpp	2009-06-04 14:50:18 +0000
+++ lib/opengl/OpenGLWrapper.hpp	2009-08-28 06:41:57 +0000
@@ -12,11 +12,11 @@
 #error "This build doesn't support openGL. Therefore, this header must not be used."
 #endif
 
-#include <Wm3Vector3.h>
+#include<Wm3Vector3.h>
 #include<yade/lib-base/yadeWm3.hpp>
 
-#include <GL/gl.h>
-#include <GL/glut.h>
+#include<GL/gl.h>
+#include<GL/glut.h>
 
 template <bool> struct static_assert_;
 template <> struct static_assert_<true> {};
@@ -264,6 +264,7 @@
 template< > inline void glMaterial< float >			( GLenum face, GLenum pname, float param )			{	glMaterialf(face,pname,param);		};
 template< > inline void glMaterial< double >			( GLenum face, GLenum pname, double param )			{	glMaterialf(face,pname,param);		};
 template< > inline void glMaterial< int >			( GLenum face, GLenum pname, int param )			{	glMateriali(face,pname,param);		};
+template< > inline void glMaterialv< Vector3<double> >	( GLenum face, GLenum pname, const Vector3<double> params )	{	Vector3f _p(params[0],params[1],params[2]); glMaterialfv(face,pname,_p);	};
 template< > inline void glMaterialv< Vector3<float> >		( GLenum face, GLenum pname, const Vector3<float> params )	{	glMaterialfv(face,pname,params);	};
 template< > inline void glMaterialv< Vector3<int> >		( GLenum face, GLenum pname, const Vector3<int> params )	{	glMaterialiv(face,pname,params);	};
 

=== modified file 'pkg/common/RenderingEngine/GLDrawGeometricalModel/GLDrawFacet.cpp'
--- pkg/common/RenderingEngine/GLDrawGeometricalModel/GLDrawFacet.cpp	2009-08-03 10:02:11 +0000
+++ pkg/common/RenderingEngine/GLDrawGeometricalModel/GLDrawFacet.cpp	2009-08-28 06:41:57 +0000
@@ -29,12 +29,12 @@
     }
     else
     {
-		glDisable(GL_CULL_FACE);
-		//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
-		//glBegin(GL_TRIANGLES);
-		glEnable(GL_LIGHTING);
-		glBegin(GL_POLYGON);
-			glColor3v(gm->diffuseColor); 
+		glDisable(GL_CULL_FACE); 
+  		glMaterialv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,gm->diffuseColor); glColor3v(gm->diffuseColor); // one of those necessary as well
+		glEnable(GL_LIGHTING); // important
+		Vector3r normal=(facet->vertices[1]-facet->vertices[0]).Cross(facet->vertices[2]-facet->vertices[1]); normal.Normalize();
+		glBegin(GL_TRIANGLES);
+			glNormal3v(normal); // this makes every triangle different WRT the light direction; important!
 			glVertex3v(facet->vertices[0]);
 			glVertex3v(facet->vertices[1]);
 			glVertex3v(facet->vertices[2]);

=== modified file 'pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp'
--- pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp	2009-08-20 12:00:28 +0000
+++ pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp	2009-08-28 06:41:57 +0000
@@ -170,6 +170,7 @@
 	glClearColor(Background_color[0],Background_color[1],Background_color[2],1.0);
 	glLightfv(GL_LIGHT0, GL_POSITION, pos);
 	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientColor);
+	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1); // important: do lighting calculations on both sides of polygons
 	//glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor);
 	glEnable(GL_LIGHT0);
 	glDisable(GL_LIGHTING);

=== modified file 'scripts/debian-prep'
--- scripts/debian-prep	2009-07-11 15:09:39 +0000
+++ scripts/debian-prep	2009-08-27 22:29:04 +0000
@@ -22,7 +22,7 @@
 ## debian/changelog
 DEBDATE=`date -R`
 cat <<EOF > debian/changelog
-yade$_VERSION (1) $DISTRIBUTION; urgency=low
+yade$_VERSION (1~$DISTRIBUTION) $DISTRIBUTION; urgency=low
 
   * Automatic debian changelog entry for yade$_VERSION