예제 #1
0
OSG::Vec3i VRPyBase::parseVec3i(PyObject *args) {
    if (pySize(args) == 1) return parseVec3iList( parseObject(args) );

    int x,y,z; x=y=z=0;
    if (! PyArg_ParseTuple(args, "iii", &x, &y, &z)) return OSG::Vec3i();
    return OSG::Vec3i(x,y,z);
}
예제 #2
0
PyObject* VRPyMaterial::setTexture(VRPyMaterial* self, PyObject* args) {
	if (self->objPtr == 0) { PyErr_SetString(err, "VRPyMaterial::setTexture, C obj is invalid"); return NULL; }

	int aN = pySize(args);
	if (aN == 1) {
        PyObject* o = parseObject(args);
        if (PyString_Check(o)) self->objPtr->setTexture( PyString_AsString(o) ); // load a file
        else if (VRPyImage::check(o)) {
            VRPyImage* img = (VRPyImage*)o;
            self->objPtr->setTexture( img->objPtr, 0 );
        }
	}

	if (aN > 1) {
        PyObject *data, *dims; int doFl;
        if (! PyArg_ParseTuple(args, "OOi", &data, &dims, &doFl)) return NULL;

        if (pySize(data) == 0) Py_RETURN_TRUE;
        vector<PyObject*> _data = pyListToVector(data);
        int dN = _data.size();

        int vN = pySize(_data[0]);
        if (doFl) {
            vector<float> buf(vN*dN, 0);
            for (int i=0; i<dN; i++) {
                PyObject* dObj = _data[i];
                vector<PyObject*> vec = pyListToVector(dObj);
                for (int j=0; j<vN; j++) buf[i*vN+j] = PyFloat_AsDouble(vec[j]);
            }
            self->objPtr->setTexture( (char*)&buf[0], vN, parseVec3iList(dims), true );
        } else {
            vector<char> buf(vN*dN, 0);
            for (int i=0; i<dN; i++) {
                vector<PyObject*> vec = pyListToVector(_data[i]);
                for (int j=0; j<vN; j++) buf[i*vN+j] = PyInt_AsLong(vec[j]);
            }
            self->objPtr->setTexture( &buf[0], vN, parseVec3iList(dims), false );
        }
	}

	Py_RETURN_TRUE;
}