Ejemplo n.º 1
0
static int HasTangents(lua_State *L) /* and bitangents */
    {
    mesh_t *mesh = checkmesh(L, 1);
    lua_pushboolean(L, mesh->mTangents != NULL && mesh->mBitangents != NULL &&
                        mesh->mNumVertices > 0);
    return 1;
    }
Ejemplo n.º 2
0
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 */
    }
Ejemplo n.º 3
0
static int NumColorChannels(lua_State *L)
    {
    unsigned int n = 0;
    mesh_t *mesh = checkmesh(L, 1);
    while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mesh->mColors[n]) ++n;
    lua_pushinteger(L, n);
    return 1;
    }
Ejemplo n.º 4
0
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]);
    }
Ejemplo n.º 5
0
static int Name(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    if(mesh->mName.length == 0)
        return 0;
    lua_pushstring(L, mesh->mName.data);
    return 1;
    }
Ejemplo n.º 6
0
static int NumTextureCoordsChannels(lua_State *L)
    {
    unsigned int n = 0;
    mesh_t *mesh = checkmesh(L, 1);
    while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mesh->mTextureCoords[n]) ++n;
    lua_pushinteger(L, n);
    return 1;
    }
Ejemplo n.º 7
0
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;
    }
Ejemplo n.º 8
0
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;
    }
Ejemplo n.º 9
0
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;
    }
Ejemplo n.º 10
0
static int Material(lua_State *L)
    {
#define scene ud->scene
    mesh_t *mesh = checkmesh(L, 1);
    ud_t *ud = userdata(mesh);
    if(mesh->mMaterialIndex >= scene->mNumMaterials)
        return unexpected(L);   
    pushmaterial(L, scene->mMaterials[mesh->mMaterialIndex]);
    return 1;
#undef scene
    }
Ejemplo n.º 11
0
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);
    }
Ejemplo n.º 12
0
static int AnimMeshes(lua_State *L)
    {
    unsigned int i;
    mesh_t *mesh = checkmesh(L, 1);
    lua_newtable(L);
    if(mesh->mAnimMeshes == NULL || mesh->mNumAnimMeshes == 0) return 1;
    for(i = 0; i < mesh->mNumAnimMeshes; i++)
        {
        pushanimmesh(L, mesh->mAnimMeshes[i]);
        lua_rawseti(L, -2, i+1);
        }
    return 1;
    }
Ejemplo n.º 13
0
static int Faces(lua_State *L)
    {
    unsigned int i;
    mesh_t *mesh = checkmesh(L, 1);
    lua_newtable(L);
    if(mesh->mFaces == NULL || mesh->mNumFaces == 0) return 1;
    for(i = 0; i < mesh->mNumFaces; i++)
        {
        pushface(L, &(mesh->mFaces[i]));
        lua_rawseti(L, -2, i+1);
        }
    return 1;
    }
Ejemplo n.º 14
0
static int AllIndices(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    int zero_based = optboolean(L, 2, 0);
    unsigned int i;

    lua_newtable(L);
    if(mesh->mFaces == NULL || mesh->mNumFaces == 0)
        return 1;
    for(i = 0; i < mesh->mNumFaces; i++)
        {
        pushfaceindices(L, &(mesh->mFaces[i]), zero_based);
        lua_rawseti(L, -2, i+1);
        }
    return 1;
    }
Ejemplo n.º 15
0
static int AllColors(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    unsigned int chan;
    unsigned int i;
    lua_newtable(L);
    for(chan = 0; chan < AI_MAX_NUMBER_OF_COLOR_SETS; chan++)
        {
        if(mesh->mColors[chan] == NULL) break;
        lua_newtable(L);
        for(i=0; i < mesh->mNumVertices; i++)
            {
            pushcolor4(L, &(mesh->mColors[chan][i]), 1);
            lua_rawseti(L, -2, i+1);
            }
        lua_rawseti(L, -2, chan+1);
        }
    return 1;
    }
Ejemplo n.º 16
0
static int AllTextureCoords(lua_State *L)
    {
    vector3_t *coords;
    vector2_t vec2;
    unsigned int ncomp;
    mesh_t *mesh = checkmesh(L, 1);
    unsigned int chan;
    unsigned int i;

    lua_newtable(L);
    for(chan = 0; chan < AI_MAX_NUMBER_OF_TEXTURECOORDS; chan++)
        {
        if(mesh->mTextureCoords[chan] == NULL) break;
        ncomp = mesh->mNumUVComponents[chan]; /* no. of components */
        lua_newtable(L);
        for(i=0; i<mesh->mNumVertices; i++)
            {
            coords =  &(mesh->mTextureCoords[chan][i]);
            switch(ncomp)
                {
                case 3: pushvector3(L, coords, 1); break;
                case 2: {
                        vec2.x = coords->x;
                        vec2.y = coords->y;
                        pushvector2(L, &vec2, 1);
                        break;
                        }
                case 1: {
                        lua_newtable(L);
                        lua_pushnumber(L, coords->x);
                        lua_rawseti(L, -2, 1);
                        break;
                        }
                default:
                    return unexpected(L); /* 4 components are currently not supported */
                }
            lua_rawseti(L, -2, i+1);
            }
        lua_rawseti(L, -2, chan+1);
        }
    return 1;
    }
Ejemplo n.º 17
0
static int HasNormals(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    lua_pushboolean(L, mesh->mNormals != NULL && mesh->mNumVertices > 0);
    return 1;
    }
Ejemplo n.º 18
0
static int PrimitiveTypes(lua_State *L)
    {
    mesh_t *mesh = checkmesh(L, 1);
    return pushprimitivetype(L, mesh->mPrimitiveTypes, 1);
    }
Ejemplo n.º 19
0
    // Customized triangulation call.
    void custom_triangulate(char *triswitches, struct triangulateio *in, struct triangulateio *out, struct triangulateio *vorout, const int *outside, const int *inside)
    {
        struct mesh m;
        struct behavior b;
        //REAL *holearray;
        //REAL *regionarray;
        triangleinit(& m);
        parsecommandline(1, & triswitches, & b);
        //b.verbose=2;
        m.steinerleft = b.steiner;
        transfernodes(& m, & b, in->pointlist, in->pointattributelist,
                      in->pointmarkerlist, in->numberofpoints,
                      in->numberofpointattributes);
        if ( b.refine ) {
            m.hullsize = reconstruct(& m, & b, in->trianglelist,
                                     in->triangleattributelist, in->trianglearealist,
                                     in->numberoftriangles, in->numberofcorners,
                                     in->numberoftriangleattributes,
                                     in->segmentlist, in->segmentmarkerlist,
                                     in->numberofsegments);
        } else {
            m.hullsize = delaunay(& m, & b);
        }
        m.infvertex1 = ( vertex ) NULL;
        m.infvertex2 = ( vertex ) NULL;
        m.infvertex3 = ( vertex ) NULL;
        if ( b.usesegments ) {
            m.checksegments = 1;
            if ( !b.refine ) {
                formskeleton(& m, & b, in->segmentlist,
                             in->segmentmarkerlist, in->numberofsegments);
            }
        }
 #if 0
        struct osub subsegloop;
        traversalinit(& m.subsegs);
        subsegloop.ss = subsegtraverse(& m);
        subsegloop.ssorient = 0;
        while ( subsegloop.ss != ( subseg * ) NULL ) {
            if ( subsegloop.ss != m.dummysub ) {
                REAL *p1, *p2;
                sorg(subsegloop, p1);
                sdest(subsegloop, p2);
                printf("  Connected (%f,%f) to (%f,%f)\n", p1 [ 0 ], p1 [ 1 ], p2 [ 0 ], p2 [ 1 ]);
                subsegloop.ss = subsegtraverse(& m);
            }
        }
 #endif
        if ( b.poly && ( m.triangles.items > 0 ) ) {
            //holearray = in->holelist;
            m.holes = in->numberofholes;
            //regionarray = in->regionlist;
            m.regions = in->numberofregions;
            if ( !b.refine ) {
                /* Only increase quality if the regions are properly defined. */
                int sane = custom_carveholes(& m, & b, outside, inside);
                b.quality *= sane;
                if ( sane == 0 ) {
                    printf("Probably bad PSLG\n");
                    exit(-1);
                }
            }
        } else {
            m.holes = 0;
            m.regions = 0;
        }
        if ( b.quality && ( m.triangles.items > 0 ) ) {
            enforcequality(& m, & b);
        }
        m.edges = ( 3l * m.triangles.items + m.hullsize ) / 2l;
        if ( b.order > 1 ) {
            highorder(& m, & b);
        }
        if ( !b.quiet ) {
            printf("\n");
        }
        if ( b.jettison ) {
            out->numberofpoints = m.vertices.items - m.undeads;
        } else {
            out->numberofpoints = m.vertices.items;
        }
        out->numberofpointattributes = m.nextras;
        out->numberoftriangles = m.triangles.items;
        out->numberofcorners = ( b.order + 1 ) * ( b.order + 2 ) / 2;
        out->numberoftriangleattributes = m.eextras;
        out->numberofedges = m.edges;
        if ( b.usesegments ) {
            out->numberofsegments = m.subsegs.items;
        } else {
            out->numberofsegments = m.hullsize;
        }
        if ( vorout != ( struct triangulateio * ) NULL ) {
            vorout->numberofpoints = m.triangles.items;
            vorout->numberofpointattributes = m.nextras;
            vorout->numberofedges = m.edges;
        }
        if ( b.nonodewritten || ( b.noiterationnum && m.readnodefile ) ) {
            if ( !b.quiet ) {
                printf("NOT writing vertices.\n");
            }
            numbernodes(& m, & b);
        } else {
            writenodes(& m, & b, & out->pointlist, & out->pointattributelist,
                       & out->pointmarkerlist);
        }

        // Simp. always write the triangles.
        writeelements(& m, & b, & out->trianglelist, & out->triangleattributelist);

        if ( b.poly || b.convex ) {
            writepoly(& m, & b, & out->segmentlist, & out->segmentmarkerlist);
            out->numberofholes = m.holes;
            out->numberofregions = m.regions;
            if ( b.poly ) {
                out->holelist = in->holelist;
                out->regionlist = in->regionlist;
            } else {
                out->holelist = ( REAL * ) NULL;
                out->regionlist = ( REAL * ) NULL;
            }
        }
        if ( b.edgesout ) {
            writeedges(& m, & b, & out->edgelist, & out->edgemarkerlist);
        }
        // Simp. no voronoi
        if ( b.neighbors ) {
            writeneighbors(& m, & b, & out->neighborlist);
        }
        // Simp. No statistics.
        if ( b.docheck ) {
            checkmesh(& m, & b);
            checkdelaunay(& m, & b);
        }
        triangledeinit(& m, & b);
    }