Example #1
0
File: file.c Project: kahrs/cda
initfile(File *f)
{
	int i;
	Line *l;
	Dict *r,*d = f->d;
	File *x;
	if (d->n > 0) {
		free(d->key);
		free(d->val);
		d->n = 0;
	}
	for (l = f->dl; l; l = l->next)		/* start with ref dictionaries */
		if (l->type == REF) {
			if ((x = (File *) lookup(((Ref *)l)->filename,files)) == 0)
				readfile(((Ref *)l)->filename);
			r = ((File *)lookup(((Ref *)l)->filename,files))->d;
			for (i = 0; i < r->n; i++)
				if (r->key[i])
					assign(r->key[i],(char *)r->val[i],d);
		}
	for (l = f->dl; l; l = l->next)		/* add local master defs */
		if (l->type == MASTER)
			assign(((Master *)l)->name,(char *) l,d);
	mbb(f->dl,d);
}
Example #2
0
IMeshBuffer* CIrrBMeshFileLoader::createMeshBuffer(u32 idx)
{
    CDynamicMeshBuffer*     buffer = 0;
    struct IrrbVertex       *pivb;
    u32                     *pindices;
    video::E_INDEX_TYPE     iType=video::EIT_16BIT;

    struct IrrbMeshBufInfo& mbi=MBuffer[idx];
    pivb = &VBuffer[mbi.iVertStart];
    pindices = &IBuffer[mbi.iIndexStart];
    if(mbi.iIndexCount > 65536)
        iType = video::EIT_32BIT;

    buffer = new CDynamicMeshBuffer((video::E_VERTEX_TYPE)mbi.iVertexType, iType);
    scene::IVertexBuffer& Vertices = buffer->getVertexBuffer();
    buffer->Material = Materials[mbi.iMaterialIndex];

    for(idx=0; idx<mbi.iVertCount; idx++)
    {

        video::S3DVertex vtx0;
		video::S3DVertex2TCoords vtx1;
		video::S3DVertexTangents vtx2;

        video::S3DVertex* vtx=0;


        if(mbi.iVertexType == irr::video::EVT_2TCOORDS)
            vtx = &vtx1;
        else if(mbi.iVertexType == irr::video::EVT_TANGENTS)
            vtx = &vtx2;
        else vtx = &vtx0;

        // set common data
        vtx->Pos.X = pivb->vPos.x;
        vtx->Pos.Y = pivb->vPos.y;
        vtx->Pos.Z = pivb->vPos.z;

        vtx->Normal.X = pivb->vNormal.x;
        vtx->Normal.Y = pivb->vNormal.y;
        vtx->Normal.Z = pivb->vNormal.z;

        vtx->Color = pivb->vColor;

        vtx->TCoords.X = pivb->vUV1.x;
        vtx->TCoords.Y = pivb->vUV1.y;

        if(mbi.iVertexType == irr::video::EVT_2TCOORDS)
        {
            vtx1.TCoords2.X = pivb->vUV2.x;
            vtx1.TCoords2.Y = pivb->vUV2.y;
            Vertices.push_back(vtx1);
        }
        else if(mbi.iVertexType == irr::video::EVT_TANGENTS)
        {
            vtx2.Tangent.X = pivb->vTangent.x;
            vtx2.Tangent.Y = pivb->vTangent.y;
            vtx2.Tangent.Z = pivb->vTangent.z;

            vtx2.Binormal.X = pivb->vBiNormal.x;
            vtx2.Binormal.Y = pivb->vBiNormal.y;
            vtx2.Binormal.Z = pivb->vBiNormal.z;
            Vertices.push_back(vtx2);
        }
        else
        {
            Vertices.push_back(vtx0);

        }
        ++pivb;
    }

    scene::IIndexBuffer& Indices = buffer->getIndexBuffer();

    for(idx=0; idx<mbi.iIndexCount; idx++)
    {
        Indices.push_back(*pindices);
        ++pindices;
    }

    core::aabbox3df mbb(mbi.ibbMin.x,mbi.ibbMin.y,mbi.ibbMin.z,
        mbi.ibbMax.x,mbi.ibbMax.y,mbi.ibbMax.z);
    buffer->setBoundingBox(mbb);

    return buffer;
}