|
Blender
V2.59
|
00001 00004 /* $Id: blendVideoTex.cpp 35176 2011-02-25 13:39:34Z jesterking $ 00005 ----------------------------------------------------------------------------- 00006 This source file is part of VideoTexture library 00007 00008 Copyright (c) 2006 The Zdeno Ash Miklas 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include <PyObjectPlus.h> 00027 00028 #include <RAS_GLExtensionManager.h> 00029 00030 #include <RAS_IPolygonMaterial.h> 00031 00032 //Old API 00033 //#include "TexPlayer.h" 00034 //#include "TexImage.h" 00035 //#include "TexFrameBuff.h" 00036 00037 //#include "TexPlayerGL.h" 00038 00039 #include "ImageBase.h" 00040 #include "FilterBase.h" 00041 #include "Texture.h" 00042 00043 #include "Exception.h" 00044 00045 00046 // get material id 00047 static PyObject * getMaterialID (PyObject *self, PyObject *args) 00048 { 00049 // parameters - game object with video texture 00050 PyObject * obj = NULL; 00051 // material name 00052 char * matName; 00053 00054 // get parameters 00055 if (!PyArg_ParseTuple(args, "Os:materialID", &obj, &matName)) 00056 return NULL; 00057 // get material id 00058 short matID = getMaterialID(obj, matName); 00059 // if material was not found, report errot 00060 if (matID < 0) 00061 { 00062 PyErr_SetString(PyExc_RuntimeError, "VideoTexture.materialID(ob, string): Object doesn't have material with given name"); 00063 return NULL; 00064 } 00065 // return material ID 00066 return Py_BuildValue("h", matID); 00067 } 00068 00069 00070 // get last error description 00071 static PyObject * getLastError (PyObject *self, PyObject *args) 00072 { 00073 return PyUnicode_FromString(Exception::m_lastError.c_str()); 00074 } 00075 00076 // set log file 00077 static PyObject * setLogFile (PyObject *self, PyObject *args) 00078 { 00079 // get parameters 00080 if (!PyArg_ParseTuple(args, "s:setLogFile", &Exception::m_logFile)) 00081 return Py_BuildValue("i", -1); 00082 // log file was loaded 00083 return Py_BuildValue("i", 0); 00084 } 00085 00086 00087 // image to numpy array 00088 static PyObject * imageToArray (PyObject * self, PyObject *args) 00089 { 00090 // parameter is Image object 00091 PyObject * pyImg; 00092 char *mode = NULL; 00093 if (!PyArg_ParseTuple(args, "O|s:imageToArray", &pyImg, &mode) || !pyImageTypes.in(pyImg->ob_type)) 00094 { 00095 // if object is incorect, report error 00096 PyErr_SetString(PyExc_TypeError, "VideoTexture.imageToArray(image): The value must be a image source object"); 00097 return NULL; 00098 } 00099 // get image structure 00100 PyImage * img = reinterpret_cast<PyImage*>(pyImg); 00101 return Image_getImage(img, mode); 00102 } 00103 00104 00105 // metody modulu 00106 static PyMethodDef moduleMethods[] = 00107 { 00108 {"materialID", getMaterialID, METH_VARARGS, "Gets object's Blender Material ID"}, 00109 {"getLastError", getLastError, METH_NOARGS, "Gets last error description"}, 00110 {"setLogFile", setLogFile, METH_VARARGS, "Sets log file name"}, 00111 {"imageToArray", imageToArray, METH_VARARGS, "get buffer from image source, color channels are selectable"}, 00112 {NULL} /* Sentinel */ 00113 }; 00114 00115 #if WITH_FFMPEG 00116 extern PyTypeObject VideoFFmpegType; 00117 extern PyTypeObject ImageFFmpegType; 00118 #endif 00119 extern PyTypeObject FilterBlueScreenType; 00120 extern PyTypeObject FilterGrayType; 00121 extern PyTypeObject FilterColorType; 00122 extern PyTypeObject FilterLevelType; 00123 extern PyTypeObject FilterNormalType; 00124 extern PyTypeObject FilterRGB24Type; 00125 extern PyTypeObject FilterRGBA32Type; 00126 extern PyTypeObject FilterBGR24Type; 00127 extern PyTypeObject ImageBuffType; 00128 extern PyTypeObject ImageMixType; 00129 extern PyTypeObject ImageRenderType; 00130 extern PyTypeObject ImageMirrorType; 00131 extern PyTypeObject ImageViewportType; 00132 extern PyTypeObject ImageViewportType; 00133 00134 00135 static void registerAllTypes(void) 00136 { 00137 #if WITH_FFMPEG 00138 pyImageTypes.add(&VideoFFmpegType, "VideoFFmpeg"); 00139 pyImageTypes.add(&ImageFFmpegType, "ImageFFmpeg"); 00140 #endif 00141 pyImageTypes.add(&ImageBuffType, "ImageBuff"); 00142 pyImageTypes.add(&ImageMixType, "ImageMix"); 00143 pyImageTypes.add(&ImageRenderType, "ImageRender"); 00144 pyImageTypes.add(&ImageMirrorType, "ImageMirror"); 00145 pyImageTypes.add(&ImageViewportType, "ImageViewport"); 00146 00147 pyFilterTypes.add(&FilterBlueScreenType, "FilterBlueScreen"); 00148 pyFilterTypes.add(&FilterGrayType, "FilterGray"); 00149 pyFilterTypes.add(&FilterColorType, "FilterColor"); 00150 pyFilterTypes.add(&FilterLevelType, "FilterLevel"); 00151 pyFilterTypes.add(&FilterNormalType, "FilterNormal"); 00152 pyFilterTypes.add(&FilterRGB24Type, "FilterRGB24"); 00153 pyFilterTypes.add(&FilterRGBA32Type, "FilterRGBA32"); 00154 pyFilterTypes.add(&FilterBGR24Type, "FilterBGR24"); 00155 } 00156 00157 static struct PyModuleDef VideoTexture_module_def = { 00158 {}, /* m_base */ 00159 "VideoTexture", /* m_name */ 00160 "Module that allows to play video files on textures in GameBlender.", /* m_doc */ 00161 0, /* m_size */ 00162 moduleMethods, /* m_methods */ 00163 0, /* m_reload */ 00164 0, /* m_traverse */ 00165 0, /* m_clear */ 00166 0, /* m_free */ 00167 }; 00168 00169 PyObject* initVideoTexture(void) 00170 { 00171 PyObject * m; 00172 00173 // initialize GL extensions 00174 //bgl::InitExtensions(0); 00175 00176 // prepare classes 00177 registerAllTypes(); 00178 registerAllExceptions(); 00179 00180 if (!pyImageTypes.ready()) 00181 return NULL; 00182 if (!pyFilterTypes.ready()) 00183 return NULL; 00184 if (PyType_Ready(&TextureType) < 0) 00185 return NULL; 00186 00187 /* Use existing module where possible 00188 * be careful not to init any runtime vars after this */ 00189 m = PyImport_ImportModule( "VideoTexture" ); 00190 if(m) { 00191 Py_DECREF(m); 00192 return m; 00193 } 00194 else { 00195 PyErr_Clear(); 00196 00197 m = PyModule_Create(&VideoTexture_module_def); 00198 PyDict_SetItemString(PySys_GetObject("modules"), VideoTexture_module_def.m_name, m); 00199 } 00200 00201 if (m == NULL) 00202 return NULL; 00203 00204 // initialize classes 00205 pyImageTypes.reg(m); 00206 pyFilterTypes.reg(m); 00207 00208 Py_INCREF(&TextureType); 00209 PyModule_AddObject(m, (char*)"Texture", (PyObject*)&TextureType); 00210 00211 // init last error description 00212 Exception::m_lastError = ""; 00213 00214 return m; 00215 } 00216 00217 // registration to Image types, put here because of silly linker bug