static int TextureCoords(lua_State *L) { vector3_t *coords; vector2_t vec2; unsigned int ncomp; mesh_t *mesh = checkmesh(L, 1); unsigned int chan = checkindex(L, 2); unsigned int i = checkindex(L, 3); if( chan >= AI_MAX_NUMBER_OF_TEXTURECOORDS || mesh->mTextureCoords[chan] == NULL) return luaL_argerror(L, 2, "out of range"); if( i >= mesh->mNumVertices) return luaL_argerror(L, 3, "out of range"); ncomp = mesh->mNumUVComponents[chan]; /* no. of components */ coords = &(mesh->mTextureCoords[chan][i]); if(ncomp == 3) return pushvector3(L, coords, 0); if(ncomp == 2) { vec2.x = coords->x; vec2.y = coords->y; return pushvector2(L, &vec2, 0); } if(ncomp == 1) { lua_pushnumber(L, coords->x); return 1; } return unexpected(L); /* 4 components are currently not supported */ }
int checkindices(sqlite3 *db) { int retvalue = 0; int rc; rc = checkindex(db, "IDX_GPSTIME", "gps", "time", 0); if(-1 == rc) return -1; if(rc > 0) retvalue++; checkindex(db, "IDX_GPSTRIP", "gps", "trip", 0); if(-1 == rc) return -1; if(rc > 0) retvalue++; checkindex(db, "IDX_OBDTIME", "obd", "time", 0); if(-1 == rc) return -1; if(rc > 0) retvalue++; checkindex(db, "IDX_OBDTRIP", "obd", "trip", 0); if(-1 == rc) return -1; if(rc > 0) retvalue++; checkindex(db, "IDX_VINECU", "ecu", "vin,ecu", 1); if(-1 == rc) return -1; if(rc > 0) retvalue++; return retvalue; }
static int Color(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int chan = checkindex(L, 2); unsigned int i = checkindex(L, 3); if( chan >= AI_MAX_NUMBER_OF_COLOR_SETS || mesh->mColors[chan] == NULL) return luaL_argerror(L, 2, "out of range"); if( i >= mesh->mNumVertices) return luaL_argerror(L, 3, "out of range"); return pushcolor4(L, &(mesh->mColors[chan][i]), 0); }
static int Texture_path(lua_State *L) { material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); return GetString(L, material, _AI_MATKEY_TEXTURE_BASE, type, index); }
int registerhandler(int fd, short events, FDHandler handler) { checkindex(fd); /* Check that it's not already registered */ if (eventfds[fd].filter!=0) { return 1; } eventfds[fd].ident=fd; if (events & POLLIN) { eventfds[fd].filter=EVFILT_READ; } else { eventfds[fd].filter=EVFILT_WRITE; } eventfds[fd].flags=EV_ADD; eventfds[fd].fflags=0; eventfds[fd].data=0; eventfds[fd].udata=(void *)handler; /* Error("core",ERR_DEBUG,"Adding fd %d filter %d",fd,eventfds[fd].filter); */ if (updates>=UPDATEQUEUESIZE) { kevent(kq, addqueue, updates, NULL, 0, NULL); updates=0; } addqueue[updates++]=eventfds[fd]; eventadds++; regfds++; return 0; }
static int Texture_blend(lua_State *L) { material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); return GetFloat(L, material, _AI_MATKEY_TEXBLEND_BASE, type, index); }
static int Bone(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int i = checkindex(L, 2); if(mesh->mBones == NULL || mesh->mNumBones == 0 || i >= mesh->mNumBones) return luaL_argerror(L, 2, "out of range"); return pushbone(L, mesh->mBones[i]); }
static int Mesh(lua_State *L) { scene_t *scene = checkscene(L, 1); unsigned int i = checkindex(L, 2); /* 1-based */ if(i > scene->mNumMeshes) return luaL_argerror(L, 2, "out of range"); pushmesh(L, scene->mMeshes[i]); return 1; }
static int NumTextureCoordsComponents(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int chan = checkindex(L, 2); if( chan >= AI_MAX_NUMBER_OF_TEXTURECOORDS || mesh->mTextureCoords[chan] == NULL) return luaL_argerror(L, 2, "out of range"); lua_pushinteger(L, mesh->mNumUVComponents[chan]); return 1; }
static int HasTextureCoords(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int i = checkindex(L, 2); if( i >= AI_MAX_NUMBER_OF_TEXTURECOORDS) lua_pushboolean(L, 0); else lua_pushboolean(L, mesh->mTextureCoords[i] != NULL && mesh->mNumVertices > 0); return 1; }
static int HasColors(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int i = checkindex(L, 2); if( i >= AI_MAX_NUMBER_OF_COLOR_SETS) lua_pushboolean(L, 0); else lua_pushboolean(L, mesh->mColors[i] != NULL && mesh->mNumVertices > 0); return 1; }
static int Texture_flags(lua_State *L) { int val; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); if(aiGetMaterialIntegerArray(material, _AI_MATKEY_TEXFLAGS_BASE, type, index, &val, NULL) != AI_SUCCESS) val = 0; return pushtextureflags(L, val, 1); }
static int Texture_mapping(lua_State *L) { int val; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); if(aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPING_BASE, type, index, &val, NULL) != AI_SUCCESS) return 0; pushtexturemapping(L, val); return 1; }
static int Texture_uvscaling(lua_State *L) { struct aiUVTransform trafo; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); unsigned int max = sizeof(struct aiUVTransform); if(AI_SUCCESS != aiGetMaterialFloatArray(material, _AI_MATKEY_UVTRANSFORM_BASE, type, index, (float*)&trafo, &max) || sizeof(struct aiUVTransform) != max) return 0; return pushvector2(L, &(trafo.mScaling), 0); }
static int Texture_axis(lua_State *L) { vector3_t vec; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); unsigned int max = sizeof(vector3_t); if(AI_SUCCESS != aiGetMaterialFloatArray(material, _AI_MATKEY_TEXMAP_AXIS_BASE, type, index, (float*)&vec, &max) || sizeof(vector3_t) != max) return 0; return pushvector3(L, &vec, 0); }
static int Texture_mapmode(lua_State *L) { int val; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); if(aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPINGMODE_U_BASE, type, index, &val, NULL) != AI_SUCCESS) lua_pushnil(L); else pushtexturemapmode(L, val); if(aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPINGMODE_V_BASE, type, index, &val, NULL) != AI_SUCCESS) lua_pushnil(L); else pushtexturemapmode(L, val); return 2; }
static int Texture_uvrotation(lua_State *L) { struct aiUVTransform trafo; material_t *material = checkmaterial(L, 1); unsigned int type = checktexturetype(L, 2); unsigned int index = checkindex(L, 3); unsigned int max = sizeof(struct aiUVTransform); if(AI_SUCCESS != aiGetMaterialFloatArray(material, _AI_MATKEY_UVTRANSFORM_BASE, type, index, (float*)&trafo, &max) || sizeof(struct aiUVTransform) != max) return 0; lua_pushnumber(L, trafo.mRotation); return 1; }
int registerhandler(int fd, short events, FDHandler handler) { checkindex(fd); /* Check that it's not already registered */ if (eventhandlers[fd].handler!=NULL) { return 1; } eventhandlers[fd].handler=handler; eventhandlers[fd].fdarraypos=regfds; eventfds[regfds].fd=fd; eventfds[regfds].events=events; eventfds[regfds].revents=0; eventadds++; regfds++; return 0; }
void scan_tree(Lextok *t, char *mn, char *mx) { char sv[512]; char tmp[32]; int oln = lineno; if (!t) return; lineno = t->ln; if (t->ntyp == NAME) { strcat(mn, t->sym->name); strcat(mx, t->sym->name); if (t->lft) /* array index */ { strcat(mn, "[]"); newbasename(mn); strcpy(sv, mn); /* save */ strcpy(mn, ""); /* clear */ strcat(mx, "["); scan_tree(t->lft, mn, mx); /* index */ strcat(mx, "]"); checkindex(mn, mx); /* match against basenames */ strcpy(mn, sv); /* restore */ delbasename(mn); } if (t->rgt) /* structure element */ { scan_tree(t->rgt, mn, mx); } } else if (t->ntyp == CONST) { strcat(mn, "1"); /* really: t->val */ sprintf(tmp, "%d", t->val); strcat(mx, tmp); } else if (t->ntyp == '.') { strcat(mn, "."); strcat(mx, "."); scan_tree(t->lft, mn, mx); } else { strcat(mn, "??"); strcat(mx, "??"); } lineno = oln; }
struct GMPmat *reducevertices(struct GMPmat *inp) { lrs_dic *P; lrs_dat *Q; lrs_mp_vector output; lrs_mp_matrix Lin; long i; long col; size_t m = GMPmat_Rows(inp); size_t *redRows; redRows = malloc( m*sizeof(*redRows) ); assert( redRows != NULL ); assert( my_lrs_init () == 0 ); Q = lrs_alloc_dat ("LRS globals"); assert ( Q != NULL ); Q->m = m; Q->n = GMPmat_Cols(inp); Q->hull = TRUE; Q->polytope = TRUE; output = lrs_alloc_mp_vector (Q->n); lrs_mp_vector num, den; num = lrs_alloc_mp_vector(GMPmat_Cols(inp)); den = lrs_alloc_mp_vector(GMPmat_Cols(inp)); P = lrs_alloc_dic (Q); assert ( P != NULL ); struct GMPmat *retMat; retMat = GMPmat_create(0, GMPmat_Cols(inp), 1); for (i = 1; i <= m; ++i) { GMPmat_getRow(num, den, inp, i-1); lrs_set_row_mp(P ,Q ,i ,num ,den , GE); } assert ( lrs_getfirstbasis (&P, Q, &Lin, TRUE) ); size_t lastdv = Q->lastdv; size_t d = P->d; size_t ineq; m = P->m_A; for (i = lastdv + 1; i <= m + d; ++i) { ineq = Q->inequality[i - lastdv] - 1; if (!checkindex(P, Q, i)) { retMat = GMPmat_appendRow(retMat, mpq_row_extract(inp, ineq)); GMPmal_everyNrows(retMat, pN, "irredundant vertices/rays"); } } lrs_clear_mp_vector ( output, Q->n); lrs_free_dic ( P , Q); lrs_free_dat ( Q ); GMPmat_destroy(inp); return retMat; }