[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25203] trunk/blender/source/gameengine: BGE: add hitUV property to mouse focus sensor to return UV coordinates under mouse pointer .

Benoit Bolsee benoit.bolsee at online.be
Tue Dec 8 09:58:24 CET 2009


Revision: 25203
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25203
Author:   ben2610
Date:     2009-12-08 09:58:24 +0100 (Tue, 08 Dec 2009)

Log Message:
-----------
BGE: add hitUV property to mouse focus sensor to return UV coordinates under mouse pointer. Useful for texture painting. More details in PyDoc.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.h
    trunk/blender/source/gameengine/PyDoc/GameTypes.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp	2009-12-08 08:46:07 UTC (rev 25202)
+++ trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp	2009-12-08 08:58:24 UTC (rev 25203)
@@ -150,6 +150,7 @@
 		m_hitObject = hitKXObj;
 		m_hitPosition = result->m_hitPoint;
 		m_hitNormal = result->m_hitNormal;
+		m_hitUV = result->m_hitUV;
 		return true;
 	}
 	
@@ -284,7 +285,8 @@
 	KX_IPhysicsController* physics_controller = cam->GetPhysicsController();
 	PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment();
 
-	KX_RayCast::Callback<KX_MouseFocusSensor> callback(this,physics_controller);
+	// get UV mapping
+	KX_RayCast::Callback<KX_MouseFocusSensor> callback(this,physics_controller,NULL,false,true);
 	 
 	KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback);
 	
@@ -340,6 +342,11 @@
 	return m_hitNormal;
 }
 
+const MT_Vector2& KX_MouseFocusSensor::HitUV() const
+{
+	return m_hitUV;
+}
+
 #ifndef DISABLE_PYTHON
 
 /* ------------------------------------------------------------------------- */
@@ -380,6 +387,7 @@
 	KX_PYATTRIBUTE_RO_FUNCTION("hitObject",		KX_MouseFocusSensor, pyattr_get_hit_object),
 	KX_PYATTRIBUTE_RO_FUNCTION("hitPosition",	KX_MouseFocusSensor, pyattr_get_hit_position),
 	KX_PYATTRIBUTE_RO_FUNCTION("hitNormal",		KX_MouseFocusSensor, pyattr_get_hit_normal),
+	KX_PYATTRIBUTE_RO_FUNCTION("hitUV",		KX_MouseFocusSensor, pyattr_get_hit_uv),
 	KX_PYATTRIBUTE_BOOL_RW("usePulseFocus",	KX_MouseFocusSensor,m_bTouchPulse),
 	{ NULL }	//Sentinel
 };
@@ -428,6 +436,12 @@
 	return PyObjectFrom(self->HitNormal());
 }
 
+PyObject* KX_MouseFocusSensor::pyattr_get_hit_uv(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_MouseFocusSensor* self= static_cast<KX_MouseFocusSensor*>(self_v);
+	return PyObjectFrom(self->HitUV());
+}
+
 #endif // DISABLE_PYTHON
 
 /* eof */

Modified: trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.h	2009-12-08 08:46:07 UTC (rev 25202)
+++ trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.h	2009-12-08 08:58:24 UTC (rev 25203)
@@ -92,6 +92,7 @@
 	const MT_Point3& RayTarget() const;
 	const MT_Point3& HitPosition() const;
 	const MT_Vector3& HitNormal() const;
+	const MT_Vector2& HitUV() const;
 	
 #ifndef DISABLE_PYTHON
 
@@ -106,6 +107,7 @@
 	static PyObject*	pyattr_get_hit_object(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject*	pyattr_get_hit_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject*	pyattr_get_hit_normal(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static PyObject*	pyattr_get_hit_uv(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 		
 #endif // DISABLE_PYTHON
 
@@ -165,6 +167,11 @@
 	MT_Vector3		 m_hitNormal;
 
 	/**
+	 * UV texture coordinate of the hit point if any, (0,0) otherwise
+	 */
+	MT_Vector2		 m_hitUV;
+
+	/**
 	 * The KX scene that holds the camera. The camera position
 	 * determines a part of the start location of the picking ray.  */
 	KX_Scene* m_kxscene;

Modified: trunk/blender/source/gameengine/PyDoc/GameTypes.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/GameTypes.py	2009-12-08 08:46:07 UTC (rev 25202)
+++ trunk/blender/source/gameengine/PyDoc/GameTypes.py	2009-12-08 08:58:24 UTC (rev 25203)
@@ -2414,6 +2414,10 @@
 	@type hitPosition: list (vector of 3 floats)
 	@ivar hitNormal: the worldspace normal from the face at point of intersection.
 	@type hitNormal: list (normalized vector of 3 floats)
+	@ivar hitUV: the UV coordinates at the point of intersection.
+		If the object has no UV mapping, it returns [0,0].
+		The UV coordinates are not normalized, they can be < 0 or > 1 depending on the UV mapping.
+	@type hitUV: list (vector of 2 floats)
 	@ivar usePulseFocus: When enabled, moving the mouse over a different object generates a pulse. (only used when the 'Mouse Over Any' sensor option is set)
 	@type usePulseFocus: bool
 	"""





More information about the Bf-blender-cvs mailing list