[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49228] branches/soc-2012-swiss_cheese: Adding a new uvs attribute to KX_VertexProxy that returns a list of uvs for the vertex .

Mitchell Stokes mogurijin at gmail.com
Wed Jul 25 22:51:04 CEST 2012


Revision: 49228
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49228
Author:   moguri
Date:     2012-07-25 20:51:04 +0000 (Wed, 25 Jul 2012)
Log Message:
-----------
Adding a new uvs attribute to KX_VertexProxy that returns a list of uvs for the vertex. This is currently the only way to access uv layers >2 via Python.

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/doc/python_api/rst/bge.types.rst
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.h

Modified: branches/soc-2012-swiss_cheese/doc/python_api/rst/bge.types.rst
===================================================================
--- branches/soc-2012-swiss_cheese/doc/python_api/rst/bge.types.rst	2012-07-25 20:39:49 UTC (rev 49227)
+++ branches/soc-2012-swiss_cheese/doc/python_api/rst/bge.types.rst	2012-07-25 20:51:04 UTC (rev 49228)
@@ -3518,7 +3518,13 @@
       The alpha component of the vertex color. 0.0 <= a <= 1.0.
 
       :type: float
+	  
+   .. attribute:: uvs
 
+      A list of uvs for the vertex.
+	  
+	  :type: list [[u1, v1], [u2, v2], ...]
+
    .. method:: getXYZ()
 
       Gets the position of this vertex.

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.cpp	2012-07-25 20:39:49 UTC (rev 49227)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.cpp	2012-07-25 20:51:04 UTC (rev 49228)
@@ -94,6 +94,7 @@
 
 	KX_PYATTRIBUTE_RW_FUNCTION("XYZ", KX_VertexProxy, pyattr_get_XYZ, pyattr_set_XYZ),
 	KX_PYATTRIBUTE_RW_FUNCTION("UV", KX_VertexProxy, pyattr_get_UV, pyattr_set_UV),
+	KX_PYATTRIBUTE_RW_FUNCTION("uvs", KX_VertexProxy, pyattr_get_uvs, pyattr_set_uvs),
 
 	KX_PYATTRIBUTE_RW_FUNCTION("color", KX_VertexProxy, pyattr_get_color, pyattr_set_color),
 	KX_PYATTRIBUTE_RW_FUNCTION("normal", KX_VertexProxy, pyattr_get_normal, pyattr_set_normal),
@@ -179,6 +180,19 @@
 	return PyObjectFrom(MT_Point2(self->m_vertex->getUV(0)));
 }
 
+PyObject* KX_VertexProxy::pyattr_get_uvs(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
+	
+	PyObject* uvlist = PyList_New(RAS_TexVert::MAX_UNIT);
+	for (int i=0; i<RAS_TexVert::MAX_UNIT; ++i)
+	{
+		PyList_SET_ITEM(uvlist, i, PyObjectFrom(MT_Point2(self->m_vertex->getUV(i))));
+	}
+
+	return uvlist;
+}
+
 PyObject* KX_VertexProxy::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
@@ -399,6 +413,32 @@
 	return PY_SET_ATTR_FAIL;
 }
 
+int KX_VertexProxy::pyattr_set_uvs(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
+	if (PySequence_Check(value))
+	{
+		MT_Point2 vec;
+		for (int i=0; i<PySequence_Size(value) && i<RAS_TexVert::MAX_UNIT; ++i)
+		{
+			if (PyVecTo(PySequence_GetItem(value, i), vec))
+			{
+				self->m_vertex->SetUV(i, vec);
+				self->m_mesh->SetMeshModified(true);
+			}
+			else
+			{
+				PyErr_SetString(PyExc_AttributeError, STR_String().Format("list[%d] was not a vector", i).ReadPtr());
+				return PY_SET_ATTR_FAIL;
+			}
+		}
+		
+		self->m_mesh->SetMeshModified(true);
+		return PY_SET_ATTR_SUCCESS;
+	}
+	return PY_SET_ATTR_FAIL;
+}
+
 int KX_VertexProxy::pyattr_set_color(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.h	2012-07-25 20:39:49 UTC (rev 49227)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Ketsji/KX_VertexProxy.h	2012-07-25 20:51:04 UTC (rev 49228)
@@ -72,6 +72,7 @@
 	static PyObject* pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject* pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject* pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static PyObject* pyattr_get_uvs(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject* pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject* pyattr_get_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int pyattr_set_x(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
@@ -87,6 +88,7 @@
 	static int pyattr_set_a(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static int pyattr_set_XYZ(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static int pyattr_set_UV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+	static int pyattr_set_uvs(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static int pyattr_set_color(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static int pyattr_set_normal(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 




More information about the Bf-blender-cvs mailing list