[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43591] trunk/blender: cucumber merge: world scaling + video texture constants

Dalai Felinto dfelinto at gmail.com
Sun Jan 22 04:21:43 CET 2012


Revision: 43591
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43591
Author:   dfelinto
Date:     2012-01-22 03:21:28 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
cucumber merge: world scaling + video texture constants
revisions: 38166,38167,38177,38179,38180,38187,38242

To be implemented after merge:
1) add pydocs(rst) for the video texture new defines
2) see if a NodeSetLocalMatrix would fit well

#43439 by kupoman
Changing the worldTransform and localTransform python attributes to use BLI_math to simplify the code

#38242 by kupoman
Adding the constants SOURCE_ERROR, SOURCE_EMPTY, SOURCE_READY, SOURCE_PLAYING, SOURCE_STOPPED to the video texture module. Updates to the documentation will follow after a merge with trunk

#38187 by kupoman
Updates to the documentation to reflect that worldScale is now writable, and added localTransform and worldTransform to KX_GameObject.

#38180 by kupoman
The Transform attribute of KX_GameObject was based on world space data. I converted that one to worldTransform, and added a localTransform for local space transform information.

#38179 by kupoman
Fixed the transform attribute of KX_GameObject's set method to properly deal with negative scaling.

#38177 by kupoman
Updated the transform property on KX_GameObject so that it is now read/write, and added the corresponding set method. Also simplified the get method by calling GetOpenGLMatrix instead of making the matrix myself.

#38167 by kupoman
Adding a read only transform attribute to KX_GameObject that returns a 4x4 matrix representing the object's transformations.

#38166 by kupoman
Adding a worldScale attribute to KX_GameObject. This attribute scales the object independently of its parent's scale.

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.types.rst
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/VideoTexture/blendVideoTex.cpp

Property Changed:
----------------
    trunk/blender/


Property changes on: trunk/blender
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2011-cucumber:37517,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998
/branches/soc-2011-tomato:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42443-42444,42446,42467,42472,42486,42650-42652,42654-42655,42709-42710,42733-42734,42801
   + /branches/soc-2011-cucumber:37517,38166-38167,38177,38179-38180,38187,38242,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998,43439
/branches/soc-2011-tomato:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42443-42444,42446,42467,42472,42486,42650-42652,42654-42655,42709-42710,42733-42734,42801

Modified: trunk/blender/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2012-01-22 00:53:53 UTC (rev 43590)
+++ trunk/blender/doc/python_api/rst/bge.types.rst	2012-01-22 03:21:28 UTC (rev 43591)
@@ -980,7 +980,7 @@
 
    .. attribute:: worldScale
 
-      The object's world scaling factor. Read-only. [sx, sy, sz]
+      The object's world scaling factor. [sx, sy, sz]
 
       :type: :class:`mathutils.Vector`
 
@@ -995,6 +995,18 @@
       The object's world position. [x, y, z]
 
       :type: :class:`mathutils.Vector`
+
+   .. attribute:: localTransform
+
+      The object's local space transform matrix. 4x4 Matrix.
+
+      :type: :class:`mathutils.Matrix`
+
+   .. attribute:: worldTransform
+
+      The object's world space transform matrix. 4x4 Matrix.
+
+      :type: :class:`mathutils.Matrix`
 	  
    .. attribute:: localLinearVelocity
       

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2012-01-22 00:53:53 UTC (rev 43590)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2012-01-22 03:21:28 UTC (rev 43591)
@@ -1153,6 +1153,36 @@
 	}
 }
 
+void KX_GameObject::NodeSetWorldScale(const MT_Vector3& scale)
+{
+	if (!GetSGNode())
+		return;
+	SG_Node* parent = GetSGNode()->GetSGParent();
+	if (parent != NULL)
+	{
+		// Make sure the objects have some scale
+		MT_Vector3 p_scale = parent->GetWorldScaling();
+		if (fabs(p_scale[0]) < FLT_EPSILON || 
+			fabs(p_scale[1]) < FLT_EPSILON || 
+			fabs(p_scale[2]) < FLT_EPSILON)
+		{ 
+			return; 
+		}
+
+		MT_Vector3 *local = new MT_Vector3(scale);
+
+		p_scale[0] = 1/p_scale[0];
+		p_scale[1] = 1/p_scale[1];
+		p_scale[2] = 1/p_scale[2];
+
+		NodeSetLocalScale(scale * p_scale);
+	}
+	else
+	{
+		NodeSetLocalScale(scale);
+	}
+}
+
 void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans)
 {
 	if (!GetSGNode())
@@ -1620,7 +1650,9 @@
 	KX_PYATTRIBUTE_RW_FUNCTION("localPosition",	KX_GameObject, pyattr_get_localPosition,	pyattr_set_localPosition),
 	KX_PYATTRIBUTE_RW_FUNCTION("worldPosition",	KX_GameObject, pyattr_get_worldPosition,    pyattr_set_worldPosition),
 	KX_PYATTRIBUTE_RW_FUNCTION("localScale",	KX_GameObject, pyattr_get_localScaling,	pyattr_set_localScaling),
-	KX_PYATTRIBUTE_RO_FUNCTION("worldScale",	KX_GameObject, pyattr_get_worldScaling),
+	KX_PYATTRIBUTE_RW_FUNCTION("worldScale",	KX_GameObject, pyattr_get_worldScaling, pyattr_set_worldScaling),
+	KX_PYATTRIBUTE_RW_FUNCTION("localTransform",		KX_GameObject, pyattr_get_localTransform, pyattr_set_localTransform),
+	KX_PYATTRIBUTE_RW_FUNCTION("worldTransform",		KX_GameObject, pyattr_get_worldTransform, pyattr_set_worldTransform),
 	KX_PYATTRIBUTE_RW_FUNCTION("linearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_worldLinearVelocity),
 	KX_PYATTRIBUTE_RW_FUNCTION("localLinearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_localLinearVelocity),
 	KX_PYATTRIBUTE_RW_FUNCTION("worldLinearVelocity", KX_GameObject, pyattr_get_worldLinearVelocity, pyattr_set_worldLinearVelocity),
@@ -2112,6 +2144,18 @@
 #endif
 }
 
+int KX_GameObject::pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+	MT_Vector3 scale;
+	if (!PyVecTo(value, scale))
+		return PY_SET_ATTR_FAIL;
+
+	self->NodeSetWorldScale(scale);
+	self->NodeUpdateGS(0.f);
+	return PY_SET_ATTR_SUCCESS;
+}
+
 PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS
@@ -2134,7 +2178,86 @@
 	return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject* KX_GameObject::pyattr_get_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
 
+	double *mat = MT_CmMatrix4x4().getPointer();
+
+	MT_Transform trans;
+	
+	trans.setOrigin(self->GetSGNode()->GetLocalPosition());
+	trans.setBasis(self->GetSGNode()->GetLocalOrientation());
+	
+	MT_Vector3 scaling = self->GetSGNode()->GetLocalScale();
+	trans.scale(scaling[0], scaling[1], scaling[2]);
+
+	trans.getValue(mat);
+
+	return PyObjectFrom(MT_Matrix4x4(mat));
+}
+
+int KX_GameObject::pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+	MT_Matrix4x4 temp;
+	if (!PyMatTo(value, temp))
+		return PY_SET_ATTR_FAIL;
+
+	float transform[4][4];
+	float loc[3], size[3];
+	float rot[3][3];
+	MT_Matrix3x3 orientation;
+
+	temp.getValue(*transform);
+	mat4_to_loc_rot_size(loc, rot, size, transform);
+
+	self->NodeSetLocalPosition(MT_Point3(loc));
+
+	//MT_Matrix3x3's constructor expects a 4x4 matrix
+	orientation = MT_Matrix3x3();
+	orientation.setValue3x3(*rot);
+	self->NodeSetLocalOrientation(orientation);
+
+	self->NodeSetLocalScale(MT_Vector3(size));
+
+	return PY_SET_ATTR_SUCCESS;
+}
+
+PyObject* KX_GameObject::pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+
+	return PyObjectFrom(MT_Matrix4x4(self->GetOpenGLMatrix()));
+}
+
+int KX_GameObject::pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+	MT_Matrix4x4 temp;
+	if (!PyMatTo(value, temp))
+		return PY_SET_ATTR_FAIL;
+
+	float transform[4][4];
+	float loc[3], size[3];
+	float rot[3][3];
+	MT_Matrix3x3 orientation;
+
+	temp.getValue(*transform);
+	mat4_to_loc_rot_size(loc, rot, size, transform);
+
+	self->NodeSetWorldPosition(MT_Point3(loc));
+
+	//MT_Matrix3x3's constructor expects a 4x4 matrix
+	orientation = MT_Matrix3x3();
+	orientation.setValue3x3(*rot);
+	self->NodeSetGlobalOrientation(orientation);
+
+	self->NodeSetWorldScale(MT_Vector3(size));
+
+	return PY_SET_ATTR_SUCCESS;
+}
+
 PyObject* KX_GameObject::pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2012-01-22 00:53:53 UTC (rev 43590)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2012-01-22 03:21:28 UTC (rev 43591)
@@ -475,6 +475,7 @@
 	void	NodeSetGlobalOrientation(const MT_Matrix3x3& rot	);
 
 	void	NodeSetLocalScale(	const MT_Vector3& scale	);
+	void	NodeSetWorldScale(	const MT_Vector3& scale );
 
 	void	NodeSetRelativeScale(	const MT_Vector3& scale	);
 
@@ -968,8 +969,13 @@
 	static PyObject*	pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int			pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static int			pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int			pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+	static PyObject*	pyattr_get_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static int			pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+	static PyObject*	pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static int			pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int			pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);

Modified: trunk/blender/source/gameengine/VideoTexture/blendVideoTex.cpp
===================================================================
--- trunk/blender/source/gameengine/VideoTexture/blendVideoTex.cpp	2012-01-22 00:53:53 UTC (rev 43590)
+++ trunk/blender/source/gameengine/VideoTexture/blendVideoTex.cpp	2012-01-22 03:21:28 UTC (rev 43591)
@@ -38,6 +38,7 @@
 //#include "TexPlayerGL.h"
 
 #include "ImageBase.h"
+#include "VideoBase.h"
 #include "FilterBase.h"
 #include "Texture.h"
 
@@ -208,6 +209,11 @@
 
 	Py_INCREF(&TextureType);
 	PyModule_AddObject(m, (char*)"Texture", (PyObject*)&TextureType);
+	PyModule_AddIntConstant(m, (char*)"SOURCE_ERROR", SourceError);
+	PyModule_AddIntConstant(m, (char*)"SOURCE_EMPTY", SourceEmpty);
+	PyModule_AddIntConstant(m, (char*)"SOURCE_READY", SourceReady);
+	PyModule_AddIntConstant(m, (char*)"SOURCE_PLAYING", SourcePlaying);
+	PyModule_AddIntConstant(m, (char*)"SOURCE_STOPPED", SourceStopped);
 	
 	// init last error description
 	Exception::m_lastError = "";




More information about the Bf-blender-cvs mailing list