Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2005-01-16 09:02:06 +0300
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2005-01-16 09:02:06 +0300
commit3b91ea4309f47d937799382d988a6348e3bb2d7f (patch)
treed45b8087e755ae6b9781845d21898603c038f2a7 /source/gameengine/Ketsji
parent5fcf39d2a5db1d536e9fbfa52edb2bcdc40d8e29 (diff)
Unified KX_BlenderPolyMaterial & GPC_PolygonMaterial into KX_PolygonMaterial.
Make game engine materials use Zoffs in Materials. Added Python material hooks.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp15
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.cpp332
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.h120
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.h2
-rw-r--r--source/gameengine/Ketsji/SConscript1
6 files changed, 471 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp
index ec0ddddafed..66306a44aba 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp
@@ -39,6 +39,10 @@
#include "KX_VertexProxy.h"
+#include "KX_PolygonMaterial.h"
+
+#include "KX_PyMath.h"
+
PyTypeObject KX_MeshProxy::Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -79,7 +83,16 @@ PyMethodDef KX_MeshProxy::Methods[] = {
PyObject*
KX_MeshProxy::_getattr(const STR_String& attr)
{
- _getattr_up(SCA_IObject);
+ if (attr == "materials")
+ {
+ PyObject *materials = PyList_New(0); /* new ref */
+ RAS_MaterialBucket::Set::iterator mit = m_meshobj->GetFirstMaterial();
+ for(; mit != m_meshobj->GetLastMaterial(); ++mit)
+ PyList_Append(materials, static_cast<KX_PolygonMaterial*>((*mit)->GetPolyMaterial()));
+ return materials;
+ }
+
+ _getattr_up(SCA_IObject);
}
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
new file mode 100644
index 00000000000..81ff5ca6a3a
--- /dev/null
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
@@ -0,0 +1,332 @@
+/**
+ * $Id$
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "KX_PolygonMaterial.h"
+
+#include "BKE_mesh.h"
+#include "BKE_global.h"
+#include "BKE_image.h"
+
+extern "C" {
+#include "BDR_drawmesh.h"
+}
+
+#include "DNA_material_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_image_types.h"
+#include "DNA_mesh_types.h"
+
+#include "IMB_imbuf_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RAS_LightObject.h"
+#include "RAS_MaterialBucket.h"
+
+#include "KX_PyMath.h"
+
+KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
+ Material *material,
+ int tile,
+ int tilexrep,
+ int tileyrep,
+ int mode,
+ bool transparant,
+ bool zsort,
+ int lightlayer,
+ bool bIsTriangle,
+ void* clientobject,
+ struct TFace* tface,
+ PyTypeObject *T)
+ : PyObjectPlus(T),
+ RAS_IPolyMaterial(texname,
+ material?STR_String(material->id.name):"",
+ tile,
+ tilexrep,
+ tileyrep,
+ mode,
+ transparant,
+ zsort,
+ lightlayer,
+ bIsTriangle,
+ clientobject),
+ m_tface(tface),
+ m_material(material),
+ m_pymaterial(0),
+ m_pass(0)
+{
+}
+
+KX_PolygonMaterial::~KX_PolygonMaterial()
+{
+ if (m_pymaterial)
+ {
+ Py_DECREF(m_pymaterial);
+ }
+}
+
+bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
+{
+ bool dopass = false;
+ if (m_pymaterial)
+ {
+ PyObject *pyRasty = PyCObject_FromVoidPtr((void*)rasty, NULL); /* new reference */
+ PyObject *pyCachingInfo = PyCObject_FromVoidPtr((void*) &cachingInfo, NULL); /* new reference */
+
+ PyObject *ret = PyObject_CallMethod(m_pymaterial, "activate", "(NNO)", pyRasty, pyCachingInfo, (PyObject*) this);
+ if (ret)
+ {
+ bool value = PyInt_AsLong(ret);
+ Py_DECREF(ret);
+ dopass = value;
+ }
+ else
+ {
+ PyErr_Print();
+ }
+ }
+ else
+ {
+ switch (m_pass++)
+ {
+ case 0:
+ DefaultActivate(rasty, cachingInfo);
+ dopass = true;
+ break;
+ default:
+ m_pass = 0;
+ dopass = false;
+ break;
+ }
+ }
+
+ return dopass;
+}
+
+void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
+{
+ if (GetCachingInfo() != cachingInfo)
+ {
+ if (!cachingInfo)
+ {
+ set_tpage(NULL);
+ }
+ cachingInfo = GetCachingInfo();
+
+ if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED))
+ {
+ update_realtime_texture((struct TFace*) m_tface, rasty->GetTime());
+ set_tpage(m_tface);
+ rasty->EnableTextures(true);
+ }
+ else
+ {
+ set_tpage(NULL);
+ rasty->EnableTextures(false);
+ }
+
+ if(m_drawingmode & RAS_IRasterizer::KX_TWOSIDE)
+ {
+ rasty->SetCullFace(false);
+ }
+ else
+ {
+ rasty->SetCullFace(true);
+ }
+
+ if (m_drawingmode & RAS_IRasterizer::KX_LINES) {
+ rasty->SetLines(true);
+ }
+ else {
+ rasty->SetLines(false);
+ }
+ }
+
+ rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity);
+ rasty->SetShinyness(m_shininess);
+ rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0);
+ if (m_material)
+ rasty->SetPolygonOffset(-m_material->zoffs, 0.0);
+}
+
+//----------------------------------------------------------------------------
+//Python
+
+
+PyMethodDef KX_PolygonMaterial::Methods[] = {
+ KX_PYMETHODTABLE(KX_PolygonMaterial, setCustomMaterial),
+ KX_PYMETHODTABLE(KX_PolygonMaterial, updateTexture),
+ KX_PYMETHODTABLE(KX_PolygonMaterial, setTexture),
+ KX_PYMETHODTABLE(KX_PolygonMaterial, activate),
+// KX_PYMETHODTABLE(KX_PolygonMaterial, setPerPixelLights),
+
+ {NULL,NULL} //Sentinel
+};
+
+
+PyTypeObject KX_PolygonMaterial::Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0,
+ "KX_PolygonMaterial",
+ sizeof(KX_PolygonMaterial),
+ 0,
+ PyDestructor,
+ 0,
+ __getattr,
+ __setattr,
+ 0, //&MyPyCompare,
+ __repr,
+ 0 //&cvalue_as_number,
+};
+
+PyParentObject KX_PolygonMaterial::Parents[] = {
+ &PyObjectPlus::Type,
+ &KX_PolygonMaterial::Type,
+ NULL
+};
+
+PyObject* KX_PolygonMaterial::_getattr(const STR_String& attr)
+{
+ if (attr == "texture")
+ return PyString_FromString(m_texturename.ReadPtr());
+ if (attr == "material")
+ return PyString_FromString(m_materialname.ReadPtr());
+
+ if (attr == "tface")
+ return PyCObject_FromVoidPtr(m_tface, NULL);
+
+ if (attr == "gl_texture")
+ {
+ Image *ima = (Image*) m_tface->tpage;
+ int bind = 0;
+ if (ima)
+ bind = ima->bindcode;
+
+ return PyInt_FromLong(bind);
+ }
+
+ if (attr == "tile")
+ return PyInt_FromLong(m_tile);
+ if (attr == "tilexrep")
+ return PyInt_FromLong(m_tilexrep);
+ if (attr == "tileyrep")
+ return PyInt_FromLong(m_tileyrep);
+
+ if (attr == "drawingmode")
+ return PyInt_FromLong(m_drawingmode);
+ if (attr == "transparent")
+ return PyInt_FromLong(m_transparant);
+ if (attr == "zsort")
+ return PyInt_FromLong(m_zsort);
+ if (attr == "lightlayer")
+ return PyInt_FromLong(m_lightlayer);
+ if (attr == "triangle")
+ return PyInt_FromLong(m_bIsTriangle);
+
+ if (attr == "diffuse")
+ return PyObjectFrom(m_diffuse);
+ if (attr == "shininess")
+ return PyFloat_FromDouble(m_shininess);
+ if (attr == "specular")
+ return PyObjectFrom(m_specular);
+ if (attr == "specularity")
+ return PyFloat_FromDouble(m_specularity);
+
+ _getattr_up(PyObjectPlus);
+}
+
+int KX_PolygonMaterial::_setattr(const STR_String &attr, PyObject *pyvalue)
+{
+ return PyObjectPlus::_setattr(attr, pyvalue);
+}
+
+KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)")
+{
+ PyObject *material;
+ if (PyArg_ParseTuple(args, "O", &material))
+ {
+ if (m_pymaterial)
+ Py_DECREF(m_pymaterial);
+
+ m_pymaterial = material;
+ Py_INCREF(m_pymaterial);
+ Py_Return;
+ }
+
+ return NULL;
+}
+
+KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rasty)")
+{
+ PyObject *pyrasty, *pytface;
+ if (PyArg_ParseTuple(args, "O!O!", &PyCObject_Type, &pytface, &PyCObject_Type, &pyrasty))
+ {
+ TFace *tface = (TFace*) PyCObject_AsVoidPtr(pytface);
+ RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCObject_AsVoidPtr(pyrasty);
+ update_realtime_texture(tface, rasty->GetTime());
+ Py_Return;
+ }
+
+ return NULL;
+}
+
+KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)")
+{
+ PyObject *pytface;
+ if (PyArg_ParseTuple(args, "O!", &PyCObject_Type, &pytface))
+ {
+ TFace *tface = (TFace*) PyCObject_AsVoidPtr(pytface);
+ set_tpage(tface);
+ Py_Return;
+ }
+
+ return NULL;
+}
+
+KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)")
+{
+ PyObject *pyrasty, *pyCachingInfo;
+ if (PyArg_ParseTuple(args, "O!O!", &PyCObject_Type, &pyrasty, &PyCObject_Type, &pyCachingInfo))
+ {
+ RAS_IRasterizer *rasty = static_cast<RAS_IRasterizer*>(PyCObject_AsVoidPtr(pyrasty));
+ TCachingInfo *cachingInfo = static_cast<TCachingInfo*>(PyCObject_AsVoidPtr(pyCachingInfo));
+ if (rasty && cachingInfo)
+ {
+ DefaultActivate(rasty, *cachingInfo);
+ Py_Return;
+ }
+ }
+
+ return NULL;
+}
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h
new file mode 100644
index 00000000000..14071ae6fc5
--- /dev/null
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h
@@ -0,0 +1,120 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+#ifndef __KX_POLYGONMATERIAL_H__
+#define __KX_POLYGONMATERIAL_H__
+
+#include "PyObjectPlus.h"
+
+#include "RAS_MaterialBucket.h"
+#include "RAS_IRasterizer.h"
+
+struct TFace;
+struct Material;
+struct MTex;
+
+/**
+ * Material class.
+ *
+ * This holds the shader, textures and python methods for setting the render state before
+ * rendering.
+ */
+class KX_PolygonMaterial : public PyObjectPlus, public RAS_IPolyMaterial
+{
+ Py_Header;
+private:
+ /** Blender texture face structure. */
+ TFace* m_tface;
+ Material* m_material;
+
+ PyObject* m_pymaterial;
+
+ mutable int m_pass;
+public:
+
+ KX_PolygonMaterial(const STR_String &texname,
+ Material* ma,
+ int tile,
+ int tilexrep,
+ int tileyrep,
+ int mode,
+ bool transparant,
+ bool zsort,
+ int lightlayer,
+ bool bIsTriangle,
+ void* clientobject,
+ struct TFace* tface,
+ PyTypeObject *T = &Type);
+ virtual ~KX_PolygonMaterial();
+
+ /**
+ * Returns the caching information for this material,
+ * This can be used to speed up the rasterizing process.
+ * @return The caching information.
+ */
+ virtual TCachingInfo GetCachingInfo(void) const
+ {
+ return (void*) this;
+ }
+
+ /**
+ * Activates the material in the (OpenGL) rasterizer.
+ * On entry, the cachingInfo contains info about the last activated material.
+ * On exit, the cachingInfo should contain updated info about this material.
+ * @param rasty The rasterizer in which the material should be active.
+ * @param cachingInfo The information about the material used to speed up rasterizing.
+ */
+ void DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const;
+ virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const;
+
+ /**
+ * Returns the Blender texture face structure that is used for this material.
+ * @return The material's texture face.
+ */
+ TFace* GetTFace(void) const
+ {
+ return m_tface;
+ }
+
+
+ KX_PYMETHOD_DOC(KX_PolygonMaterial, updateTexture);
+ KX_PYMETHOD_DOC(KX_PolygonMaterial, setTexture);
+ KX_PYMETHOD_DOC(KX_PolygonMaterial, activate);
+
+ KX_PYMETHOD_DOC(KX_PolygonMaterial, setCustomMaterial);
+ KX_PYMETHOD_DOC(KX_PolygonMaterial, loadProgram);
+
+ virtual PyObject* _getattr(const STR_String& attr);
+ virtual int _setattr(const STR_String& attr, PyObject *pyvalue);
+};
+
+#endif // __KX_POLYGONMATERIAL_H__
+
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
index 3afea847405..7683ce19f19 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp
@@ -338,6 +338,7 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject*,
m_vertex->SetRGBA(MT_Vector4(r, g, b, a));
Py_Return;
}
+ PyErr_Clear();
int rgba;
if (PyArg_ParseTuple(args,"i",&rgba))
@@ -345,7 +346,8 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject*,
m_vertex->SetRGBA(rgba);
Py_Return;
}
- Py_Return;
+
+ return NULL;
}
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h
index 29fee7d6ae7..bf3e1982c8c 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.h
+++ b/source/gameengine/Ketsji/KX_VertexProxy.h
@@ -57,7 +57,7 @@ public:
// stuff for python integration
virtual PyObject* _getattr(const STR_String& attr);
- virtual int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue);
+ virtual int _setattr(const STR_String& attr, PyObject *pyvalue);
KX_PYMETHOD(KX_VertexProxy,GetXYZ);
KX_PYMETHOD(KX_VertexProxy,SetXYZ);
diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript
index 05b81baec05..948e0135eef 100644
--- a/source/gameengine/Ketsji/SConscript
+++ b/source/gameengine/Ketsji/SConscript
@@ -31,6 +31,7 @@ source_files = ['KX_WorldIpoController.cpp',
'KX_PythonInit.cpp',
'KX_PyConstraintBinding.cpp',
'KX_PositionInterpolator.cpp',
+ 'KX_PolygonMaterial.cpp',
'KX_PhysicsObjectWrapper.cpp',
'KX_OrientationInterpolator.cpp',
'KX_ObjectActuator.cpp',