add argument so recent bge function mesh.transform_uv() so you can optionally transform between UV1 / UV2
This commit is contained in:
@@ -1966,7 +1966,7 @@ Types
|
||||
:arg matrix: transformation matrix.
|
||||
:type matrix: 4x4 matrix [[float]]
|
||||
|
||||
.. method:: transform_uv(matid, matrix, uv_index=-1)
|
||||
.. method:: transform_uv(matid, matrix, uv_index=-1, uv_index_from=-1)
|
||||
|
||||
Transforms the vertices UV's of a mesh.
|
||||
|
||||
@@ -1974,8 +1974,10 @@ Types
|
||||
:type matid: integer
|
||||
:arg matrix: transformation matrix.
|
||||
:type matrix: 4x4 matrix [[float]]
|
||||
:arg matid: optional uv index, -1 for all, otherwise 0 or 1.
|
||||
:type matid: integer
|
||||
:arg uv_index: optional uv index, -1 for all, otherwise 0 or 1.
|
||||
:type uv_index: integer
|
||||
:arg uv_index_from: optional uv index to copy from, -1 to transform the current uv.
|
||||
:type uv_index_from: integer
|
||||
|
||||
.. class:: SCA_MouseSensor(SCA_ISensor)
|
||||
|
||||
|
@@ -260,7 +260,8 @@ PyObject *KX_MeshProxy::PyTransform(PyObject *args, PyObject *kwds)
|
||||
for (slot->begin(it); !slot->end(it); slot->next(it)) {
|
||||
size_t i;
|
||||
for (i = it.startvertex; i < it.endvertex; i++) {
|
||||
it.vertex[i].Transform(transform, ntransform);
|
||||
RAS_TexVert *vert = &it.vertex[i];
|
||||
vert->Transform(transform, ntransform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,11 +287,12 @@ PyObject *KX_MeshProxy::PyTransformUV(PyObject *args, PyObject *kwds)
|
||||
int matindex;
|
||||
PyObject *pymat;
|
||||
int uvindex = -1;
|
||||
int uvindex_from = -1;
|
||||
bool ok = false;
|
||||
|
||||
MT_Matrix4x4 transform;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"iO|ii:transform_uv", &matindex, &pymat, &uvindex) ||
|
||||
if (!PyArg_ParseTuple(args,"iO|iii:transform_uv", &matindex, &pymat, &uvindex, &uvindex_from) ||
|
||||
!PyMatTo(pymat, transform))
|
||||
{
|
||||
return NULL;
|
||||
@@ -298,9 +300,17 @@ PyObject *KX_MeshProxy::PyTransformUV(PyObject *args, PyObject *kwds)
|
||||
|
||||
if (uvindex < -1 || uvindex > 1) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"mesh.transform_uv(...): invalid uv index %d", uvindex);
|
||||
"mesh.transform_uv(...): invalid uv_index %d", uvindex);
|
||||
return NULL;
|
||||
}
|
||||
if (uvindex_from < -1 || uvindex_from > 1 || uvindex == -1) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"mesh.transform_uv(...): invalid uv_index_from %d", uvindex);
|
||||
return NULL;
|
||||
}
|
||||
if (uvindex_from == uvindex) {
|
||||
uvindex_from = -1;
|
||||
}
|
||||
|
||||
/* transform mesh verts */
|
||||
unsigned int mit_index = 0;
|
||||
@@ -326,16 +336,22 @@ PyObject *KX_MeshProxy::PyTransformUV(PyObject *args, PyObject *kwds)
|
||||
size_t i;
|
||||
|
||||
for (i = it.startvertex; i < it.endvertex; i++) {
|
||||
RAS_TexVert *vert = &it.vertex[i];
|
||||
if (uvindex_from != -1) {
|
||||
if (uvindex_from == 0) vert->SetUV2(vert->getUV1());
|
||||
else vert->SetUV1(vert->getUV2());
|
||||
}
|
||||
|
||||
switch (uvindex) {
|
||||
case 0:
|
||||
it.vertex[i].TransformUV(transform);
|
||||
vert->TransformUV1(transform);
|
||||
break;
|
||||
case 1:
|
||||
it.vertex[i].TransformUV2(transform);
|
||||
vert->TransformUV2(transform);
|
||||
break;
|
||||
case -1:
|
||||
it.vertex[i].TransformUV(transform);
|
||||
it.vertex[i].TransformUV2(transform);
|
||||
vert->TransformUV1(transform);
|
||||
vert->TransformUV2(transform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -63,8 +63,8 @@ PyTypeObject KX_VertexProxy::Type = {
|
||||
PyMethodDef KX_VertexProxy::Methods[] = {
|
||||
{"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_NOARGS},
|
||||
{"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_O},
|
||||
{"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV,METH_NOARGS},
|
||||
{"setUV", (PyCFunction)KX_VertexProxy::sPySetUV,METH_O},
|
||||
{"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV1, METH_NOARGS},
|
||||
{"setUV", (PyCFunction)KX_VertexProxy::sPySetUV1, METH_O},
|
||||
|
||||
{"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_NOARGS},
|
||||
{"setUV2", (PyCFunction)KX_VertexProxy::sPySetUV2,METH_VARARGS},
|
||||
@@ -247,7 +247,7 @@ int KX_VertexProxy::pyattr_set_u(void *self_v, const struct KX_PYATTRIBUTE_DEF *
|
||||
float val = PyFloat_AsDouble(value);
|
||||
MT_Point2 uv = self->m_vertex->getUV1();
|
||||
uv[0] = val;
|
||||
self->m_vertex->SetUV(uv);
|
||||
self->m_vertex->SetUV1(uv);
|
||||
self->m_mesh->SetMeshModified(true);
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ int KX_VertexProxy::pyattr_set_v(void *self_v, const struct KX_PYATTRIBUTE_DEF *
|
||||
float val = PyFloat_AsDouble(value);
|
||||
MT_Point2 uv = self->m_vertex->getUV1();
|
||||
uv[1] = val;
|
||||
self->m_vertex->SetUV(uv);
|
||||
self->m_vertex->SetUV1(uv);
|
||||
self->m_mesh->SetMeshModified(true);
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
@@ -389,9 +389,8 @@ int KX_VertexProxy::pyattr_set_UV(void *self_v, const struct KX_PYATTRIBUTE_DEF
|
||||
if (PySequence_Check(value))
|
||||
{
|
||||
MT_Point2 vec;
|
||||
if (PyVecTo(value, vec))
|
||||
{
|
||||
self->m_vertex->SetUV(vec);
|
||||
if (PyVecTo(value, vec)) {
|
||||
self->m_vertex->SetUV1(vec);
|
||||
self->m_mesh->SetMeshModified(true);
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
@@ -521,18 +520,18 @@ PyObject *KX_VertexProxy::PySetRGBA(PyObject *value)
|
||||
}
|
||||
|
||||
|
||||
PyObject *KX_VertexProxy::PyGetUV()
|
||||
PyObject *KX_VertexProxy::PyGetUV1()
|
||||
{
|
||||
return PyObjectFrom(MT_Vector2(m_vertex->getUV1()));
|
||||
}
|
||||
|
||||
PyObject *KX_VertexProxy::PySetUV(PyObject *value)
|
||||
PyObject *KX_VertexProxy::PySetUV1(PyObject *value)
|
||||
{
|
||||
MT_Point2 vec;
|
||||
if (!PyVecTo(value, vec))
|
||||
return NULL;
|
||||
|
||||
m_vertex->SetUV(vec);
|
||||
m_vertex->SetUV1(vec);
|
||||
m_mesh->SetMeshModified(true);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
@@ -92,8 +92,8 @@ public:
|
||||
|
||||
KX_PYMETHOD_NOARGS(KX_VertexProxy,GetXYZ);
|
||||
KX_PYMETHOD_O(KX_VertexProxy,SetXYZ);
|
||||
KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV);
|
||||
KX_PYMETHOD_O(KX_VertexProxy,SetUV);
|
||||
KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV1);
|
||||
KX_PYMETHOD_O(KX_VertexProxy,SetUV1);
|
||||
|
||||
KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV2);
|
||||
KX_PYMETHOD_VARARGS(KX_VertexProxy,SetUV2);
|
||||
|
@@ -75,21 +75,32 @@ void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
|
||||
xyz.getValue(m_localxyz);
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetXYZ(const float *xyz)
|
||||
void RAS_TexVert::SetXYZ(const float xyz[3])
|
||||
{
|
||||
m_localxyz[0] = xyz[0]; m_localxyz[1] = xyz[1]; m_localxyz[2] = xyz[2];
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetUV(const MT_Point2& uv)
|
||||
void RAS_TexVert::SetUV1(const MT_Point2& uv)
|
||||
{
|
||||
uv.getValue(m_uv1);
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetUV1(const float uv[3])
|
||||
{
|
||||
m_uv1[0] = uv[0];
|
||||
m_uv1[1] = uv[1];
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetUV2(const MT_Point2& uv)
|
||||
{
|
||||
uv.getValue(m_uv2);
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetUV2(const float uv[3])
|
||||
{
|
||||
m_uv2[0] = uv[0];
|
||||
m_uv2[1] = uv[1];
|
||||
}
|
||||
|
||||
void RAS_TexVert::SetRGBA(const unsigned int rgba)
|
||||
{
|
||||
@@ -151,9 +162,9 @@ void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
|
||||
SetTangent((nmat*MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0)).getValue());
|
||||
}
|
||||
|
||||
void RAS_TexVert::TransformUV(const MT_Matrix4x4& mat)
|
||||
void RAS_TexVert::TransformUV1(const MT_Matrix4x4& mat)
|
||||
{
|
||||
SetUV((mat * MT_Vector4(m_uv1[0], m_uv1[1], 0.0, 1.0)).getValue());
|
||||
SetUV1((mat * MT_Vector4(m_uv1[0], m_uv1[1], 0.0, 1.0)).getValue());
|
||||
}
|
||||
|
||||
void RAS_TexVert::TransformUV2(const MT_Matrix4x4& mat)
|
||||
|
@@ -122,9 +122,11 @@ public:
|
||||
}
|
||||
|
||||
void SetXYZ(const MT_Point3& xyz);
|
||||
void SetXYZ(const float *xyz);
|
||||
void SetUV(const MT_Point2& uv);
|
||||
void SetXYZ(const float xyz[3]);
|
||||
void SetUV1(const MT_Point2& uv);
|
||||
void SetUV2(const MT_Point2& uv);
|
||||
void SetUV1(const float uv[2]);
|
||||
void SetUV2(const float uv[2]);
|
||||
|
||||
void SetRGBA(const unsigned int rgba);
|
||||
void SetNormal(const MT_Vector3& normal);
|
||||
@@ -137,7 +139,7 @@ public:
|
||||
|
||||
void Transform(const class MT_Matrix4x4& mat,
|
||||
const class MT_Matrix4x4& nmat);
|
||||
void TransformUV(const MT_Matrix4x4& mat);
|
||||
void TransformUV1(const MT_Matrix4x4& mat);
|
||||
void TransformUV2(const MT_Matrix4x4& mat);
|
||||
|
||||
// compare two vertices, to test if they can be shared, used for
|
||||
|
Reference in New Issue
Block a user