Пример #1
0
void CFieldMap::load (File::Load::CLoadField &fin, std::vector<CBaseItems> &temps)
{
	hurdle = fin.loadHurdle ();
	substratum = fin.loadSubstratum ();

	if ( substratum )
	{
		int ID;
		Engine::CSprite::KIND kind;

		fin.loadNumberTexture (kind, ID);
		ground = new Engine::CSprite( findTexture (temps, kind, ID));

		fin.loadRect (ground->rectSprite);
	}

	if ( hurdle )
	{
		Engine::CSprite::KIND kind;
		int ID;

		fin.loadNumberTexture (kind, ID);
		obstancle = new Engine::CSprite(findTexture (temps, kind, ID));

		fin.loadRect (obstancle->rectSprite);
	}
}
Пример #2
0
//! loads a Texture
ITexture* CNullDriver::getTexture(const path& filename)
{
	// Identify textures by their absolute filenames if possible.
	const path absolutePath = FileSystem->getAbsolutePath(filename);

	ITexture* texture = findTexture(absolutePath);
	if (texture)
		return texture;

	// Then try the raw filename, which might be in an Archive
	texture = findTexture(filename);
	if (texture)
		return texture;

	// Now try to open the file using the complete path.
	IReadFile* file = FileSystem->createAndOpenFile(absolutePath);

	if (!file)
	{
		// Try to open it using the raw filename.
		file = FileSystem->createAndOpenFile(filename);
	}

	if (file)
	{
		// Re-check name for actual archive names
		texture = findTexture(file->getFileName());
		if (texture)
		{
			file->releaseRef();
			return texture;
		}

		texture = loadTextureFromFile(file);
		file->releaseRef();

		if (texture)
		{
			addTexture(texture);
			texture->releaseRef(); // drop it because we created it, one grab too much
		}
		else
			Printer::log("Could not load texture", filename, ELL_ERROR);
		return texture;
	}
	else
	{
		Printer::log("Could not open file of texture", filename, ELL_WARNING);
		return 0;
	}
}
Пример #3
0
// -----------------------------------------------------------------
// Name : findTexture
// -----------------------------------------------------------------
Texture * TextureEngine::findTexture(string sFilename)
{
    if (sFilename ==  "") {
        return NULL;
    }

    for (u16 i = 0; i < m_AllTextures.size(); i++) {
        if (m_AllTextures[i]->m_sFilename == sFilename) {
            return m_AllTextures[i];
        }
    }

    // Not found => might be a virtual texture that we need to create from master texture
    if (sFilename.find(":") != string::npos) {
    	size_t pos = sFilename.find_first_of(':', 0);
    	string rootFile = sFilename.substr(0, pos);
    	string title = sFilename.substr(pos+1);
    	Texture * pMaster = findTexture(rootFile);
    	if (pMaster != NULL) {
    		VirtualTexture * vTex = VirtualTexture::build(pMaster, sFilename, title);
    		if (vTex != NULL) {
    			m_AllTextures.push_back(vTex);
    			return vTex;
    		}
    	}
        _debug->error(string("Texture not found: ") + sFilename);
    }

    return NULL;
}
Пример #4
0
int TextureManager::LoadExternTexture(const char* filename, bool complain, bool mipmap, bool grayscale) {
	Texture *t = NULL;

	if (gl_quick_texture_reload.getBool()) {
		t = findTexture(filename);
		if (t != NULL)
			return t->textureId;
	}


	t = LoadFile(filename, complain);
	if (!t)
		return 0;

	if (!t->hasData()) {
		delete t;
		return 0;
	}

	t->mipmap = mipmap;
	t->bytesPerPixel = 4;
	t->grayscale = grayscale;

	t = LoadTexture(t);
	return t->textureId;
}
Пример #5
0
//! loads a Texture
ITexture* CNullDriver::getTexture(IReadFile* file)
{
	ITexture* texture = 0;

	if (file)
	{
		texture = findTexture(file->getFileName());

		if (texture)
			return texture;

		texture = loadTextureFromFile(file);

		if (texture)
		{
			addTexture(texture);
			texture->releaseRef(); // drop it because we created it, one grab too much
		}

		if (!texture)
			Printer::log("Could not load texture", file->getFileName(), ELL_WARNING);
	}

	return texture;
}
Пример #6
0
render::render(const char *textName, int texX1, int texX2, int texY1, int texY2,
  float sizX, float sizY, int red_, int green_, int blue_, int alpha_, float rotRad)
  : comptexture(findTexture(textName)), textX1(texX1), textX2(texX2), textY1(texY1), textY2(texY2),
    textXSize(sizX), textYSize(sizY),
  red(red_), green(green_), blue(blue_), alpha(alpha_), rot(rotRad)
{
}
Пример #7
0
void Sprite::loadIndex(PFPChunk *chunk)
/*!\brief Laden des Sprite-Index
 *
 * \desc
 * Diese Funktion wird intern verwendet, um den INDX-Chunk der Sprite-Datei einzulesen.
 * Sie darf erst nach Aufruf von Sprite::LoadTexture verwendet werden.
 *
 * \param[in] chunk Pointer auf den INDX-Chunk
 * \returns Konnte der Index erfolgreich eingelesen und alle Texturen zugeordnet werden,
 * liefert die Funktion true (1) zurück, andernfalls false (0).
 */
{
	char *buffer=(char*)chunk->data();
	int num=Peek32(buffer);		// Anzahl Einträge in der Tabelle
	char *p=buffer+4;
	SpriteIndexItem item;
	for (int i=0;i<num;i++) {
		item.id=Peek32(p+0);
		item.surface=findTexture(Peek16(p+4));
		item.r.x1=Peek16(p+6+0);
		item.r.y1=Peek16(p+6+2);
		item.r.x2=Peek16(p+6+4)+1;
		item.r.y2=Peek16(p+6+6)+1;
		item.Pivot.x=Peek16(p+14+0);
		item.Pivot.y=Peek16(p+14+2);
		item.Offset.x=Peek16(p+18+0);
		item.Offset.y=Peek16(p+18+2);
		/*
		PrintDebug("Id: %i, (%i/%i)-(%i/%i)\n",
			item->id,item->r.left,item->r.top,item->r.right,item->r.bottom);
			*/
		SpriteList.add(item.id,item);
		p+=22;
	}
}
Пример #8
0
bool SceneLoader::aplicaTextures(Object * o, Texture * tex)
{
	Texture * tex2;

	if(o->tex_id=="null")
		o->tex=tex;
	else if(o->tex_id=="clear")
		o->tex=this->no_tex;
	else
	{
		tex2=findTexture(o->tex_id);
		if(tex2==NULL)
			return false;
		o->tex=tex2;
	}

	if(o->type=="compound")
	{
		for(unsigned int i=0; i<o->getObjs()->size(); i++)
		{
			if(!aplicaTextures(o->getObjs()->at(i), o->tex))
				return false;
		}
	}
	return true;
}
Пример #9
0
ITexture*
TextureMgr::loadTexture (const std::string& filename,
                         Ctr::PixelFormat format)
{
    if (filename.length() == 0)
        return nullptr;
    LOG ("Attempting to load texture " << filename);

    ITexture* texture = findTexture (filename);
    if (!texture)
    {
        std::vector<std::string>       filenames;
        filenames.push_back(filename);
        TextureParameters resource = 
            TextureParameters(filenames, loadImages(filenames),Ctr::TwoD);

        if (texture = _deviceInterface->createTexture(&resource))
        {
            _textures.insert (std::make_pair(std::string(filename),
                              texture));
            LOG ("Loaded texture " << filename);
        }
        else
        {
            LOG ("Failed  " << filename);

        }
    }
    return texture;
}
Пример #10
0
 TexturePtr
 TextureManager::getTexture(const std::string & theTextureId) const{
     TexturePtr myTexture = findTexture(theTextureId);
     if (!myTexture) {
         throw TextureManagerException(std::string("Request for texture '") + theTextureId + "' failed.", PLUS_FILE_LINE);
     }
     return myTexture;
 }
Пример #11
0
// FIXME: should we check that image have appropriate size as bindFromImage do?
void TextureManager::bindTexture(const QString& name, QGLWidget* cxt)
{
    Create();
    Q_ASSERT( "Must be called only with valid GL context" && cxt );

    CacheIter it = findTexture( name );
    if( it != m_p->m_textures.constEnd() )
        bindImage( *it, cxt );
}
Пример #12
0
const QImage& TextureManager::getImage(const QString& name)
{
    Create();
    if(name.isEmpty())
        return emptyImage;
    CacheIter it = findTexture( name );
    if( it != m_p->m_textures.constEnd() ) {
        return *it;
    } else {
        return emptyImage;
    }
}
Пример #13
0
kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *state, const char *name) {
	int index = findTexture(state, name);
	if (index < 0) {
		int location = glGetUniformLocation(state->impl.programId, name);
		glCheckErrors();
		index = state->impl.textureCount;
		state->impl.textureValues[index] = location;
		strcpy(state->impl.textures[index], name);
		++state->impl.textureCount;
	}
	kinc_g4_texture_unit_t unit;
	unit.impl.unit = index;
	return unit;
}
Пример #14
0
Файл: gfx.cpp Проект: amecky/DT
	// -------------------------------------------------
	// load texture
	// -------------------------------------------------
	int loadTexture(const char* name) {
		LOGC("assets") << "load texture: " << name;
		int idx = findTexture(name);
		if (idx != -1) {
			LOGC("assets") << "found already existing texture - returning " << idx;
			return idx;
		}
		TextureAsset asset;
		char fileName[256];
		sprintf(fileName, "content\\%s.png", name);
		LOGC("assets") << "loading texture from file: " << fileName;
		HRESULT result = D3DX11CreateShaderResourceViewFromFile(ctx->device, fileName, NULL, NULL, &asset.texture, NULL);
		if (FAILED(result)) {
			return -1;
		}
		assetCtx->textures.push_back(asset);
		return assetCtx->textures.size() - 1;
	}
Пример #15
0
// -----------------------------------------------------------------
// Name : loadTexture
// -----------------------------------------------------------------
Texture * TextureEngine::loadTexture(string sFilename, bool bComposed, bool bMipmap, int ustart, int uend, int vstart, int vend)
{
    if (sFilename == "") {
        return NULL;
    }

    Texture * pTex = findTexture(sFilename);
    if (pTex != NULL) { // Texture already loaded
        return pTex;
    }

    pTex = new Texture(sFilename, bComposed, bMipmap);
    m_AllTextures.push_back(pTex);
    if (!pTex->load()) {
        return pTex;
    } else {
        textureLoaded(pTex);
    }

    pTex->m_bIsLoadedInVideo = true;

    // Set u/v coords
    if (ustart >= 0)
    {
        pTex->m_fU0 = (GLfloat)ustart / (GLfloat)pTex->getWidth();
        pTex->m_fU1 = (GLfloat)uend / (GLfloat)pTex->getWidth();
    }
    else
    {
        pTex->m_fU0 = 0.0f;
        pTex->m_fU1 = 1.0f;
    }
    if (vstart >= 0)
    {
        pTex->m_fV0 = (GLfloat)vstart / (GLfloat)pTex->getHeight();
        pTex->m_fV1 = (GLfloat)vend / (GLfloat)pTex->getHeight();
    }
    else
    {
        pTex->m_fV0 = 0.0f;
        pTex->m_fV1 = 1.0f;
    }
    return pTex;
}
Пример #16
0
ITexture*
TextureMgr::loadTextureSet (const std::string& key, 
                            const std::vector<std::string>      & filenames)
{
    ITexture* texture = findTexture (key);
    if (!texture)
    {
        TextureParameters resource = TextureParameters(filenames, loadImages(filenames), Ctr::TwoD);
        if (texture = _deviceInterface->createTexture(&resource))
        {
            _textures.insert (std::make_pair(std::string(key),
                              texture));

            LOG ("Loaded texture array from: ")
            for (size_t i = 0;i < filenames.size(); i++)
            {
                LOG ("    " << filenames[i].c_str());
            }
        }
Пример #17
0
Texture *TextureManager::LoadTexture(Texture *texture) {
	// See if the texture has already been loaded
	texture->calculateHash();
	Texture *found = findTexture(texture);
	if (found != NULL) {
		if (found->isMissMatch(texture)) {
			Con_DPrintf("GL_LoadTexture: cache mismatch\n");
			removeTexture(found);
			delete found;
		} else {
			delete texture;
			return found;
		}
	}

	if (!isDedicated) {
		texture->upload();
	}

	checkGLError("Loading texture");

	addTexture(texture);
	return texture;
}
Пример #18
0
bool SceneLoader::loadScene()
{ 
	sgxElement = doc.FirstChildElement( "sgx" );
	globalsElement = sgxElement->FirstChildElement( "globals" );
	viewElement = sgxElement->FirstChildElement( "view" );
	illuminationElement = sgxElement->FirstChildElement("illumination");
	texturesElement = sgxElement->FirstChildElement("textures");
	objectsElement = sgxElement->FirstChildElement("objects");
	materialsElement = sgxElement->FirstChildElement("materials");

	Material * mat;
	Texture * tex;


	// Inicialização
	// Um exemplo de um conjunto de nós bem conhecidos e obrigatórios

	if(sgxElement == NULL) {
		cout << "Bloco sgx nao encontrado\n";
		system("pause");
		return false;
	}
	
	if(globalsElement != NULL)
	{
		if(!loadGlobals())
			return false;
	}
	else
	{
		cout<<"Bloco globals nao encontrado\n";
		system("pause");
		return false;
	}

	if (viewElement != NULL) 
	{
		if(!loadView())
			return false;
	}
	else
	{
		cout << "Bloco view nao encontrado\n";
		system("pause");
		return false;
	}

	if(illuminationElement != NULL)
	{
		if(!loadIllumination())
			return false;
	}
	else
	{
		cout<<"Bloco illumination nao econtrado\n";
		system("pause");
		return false;
	}
	
	if(texturesElement != NULL)
	{
		if(!loadTextures())
			return false;
	}
	else
	{
		cout<<"Bloco textures nao econtrado\n";
		system("pause");
		return false;
	}
	if(materialsElement != NULL)
	{
		if(!loadMaterials())
			return false;
	}
	else
	{
		cout<<"Bloco materials nao econtrado\n";
		system("pause");
		return false;
	}
	if(objectsElement!=NULL)
	{
		if(!loadObjects())
			return false;
		if(!loadCompound())
			return false;
		root_object=findObject(global.root);
		if(root_object==NULL)
			return false;
		if(root_object->mat_id=="null")
			mat=this->mat_base;
		else
		{
			mat=findMaterial(root_object->mat_id);
			if(mat==NULL)
				return false;
		}
		if(!aplicaMaterials(root_object, mat))
			return false;

		if(root_object->tex_id=="null"||root_object->tex_id=="clear")
			tex=this->no_tex;
		else
		{
			tex=findTexture(root_object->tex_id);
			if(tex==NULL)
				return false;
		}
		if(!aplicaTextures(root_object, tex))
			return false;


	}
	else
	{
		cout<<"Bloco objects nao econtrado\n";
		system("pause");
		return false;
	}

	return true;
}
Пример #19
0
int defuse(const char *fileName)
{
    numtextures = 0;

    int fd;
    fd = _open(fileName, O_RDONLY | O_BINARY);
    if (fd <= 0)
    {
        fprintf(stderr, "could not open %s for reading\n", fileName);
        return -1;
    }
    //fprintf(stderr,"converting %s\n",argv[filenum]);
    struct stat statbuf;
    fstat(fd, &statbuf);
    size = statbuf.st_size;
    buf = new char[size + 1000];
    buf2 = new char[size + 100000];
    readpos = buf;
    writepos = buf2;
    memset(buf, 0, size + 1000);
    if ((buf2 == NULL) || (buf == NULL))
    {
        fprintf(stderr, "out of memory\n");
        return -1;
    }
    _read(fd, buf, size);
    int numref = 0;
    numtextures = 0;
    while (findTexture())
    {
        texture *currentTex = getTexture(currentTexturename, currentEnvironment, currentBlendMode);
        if (currentTex)
        {
            // already defined texture
            sprintf(writepos, " USE %s \n", currentTex->defName);
            writepos += strlen(writepos);
            numref++;
        }
        else
        {
            // new texture
            currentTex = new texture(currentTexturename, currentEnvironment, currentBlendMode);
            //fprintf(stderr,"currentEnvironment %d\n" , currentEnvironment);
            addTexture(currentTex);
            sprintf(writepos, " DEF %s ImageTexture{ url \"%s\"\n", currentTex->defName, currentTex->name);
            writepos += strlen(writepos);
            if (currentTex->env)
            {
                sprintf(writepos, " environment TRUE\n");
                writepos += strlen(writepos);
            }
            if (currentTex->blendMode > 0)
            {
                sprintf(writepos, " blendMode %d\n", currentTex->blendMode);
                writepos += strlen(writepos);
            }
            sprintf(writepos, "}\n");
            writepos += strlen(writepos);
        }
    }

    _close(fd);
    //fprintf(stderr,"found %d textures, %d references\n",numtextures, numref);
    if (numref == 0)
    {
        //fprintf(stderr,"%s unchanged\n",argv[filenum]);
    }
    else
    {

        fd = _open(fileName, O_WRONLY | O_CREAT | O_BINARY | O_TRUNC, 0777);
        if (fd <= 0)
        {
            fprintf(stderr, "could not open %s for writing\n", fileName);
            return -1;
        }
        _write(fd, buf2, (int)(writepos - buf2));
        _close(fd);
    }
    delete[] buf;
    delete[] buf2;
    return 0;
}
Пример #20
0
void generateRoomGeometry(room_s* r)
{
	if(!r)return;

	if(r->vertexBuffer)linearFree(r->vertexBuffer);
	if(r->numIndices)linearFree(r->numIndices);
	if(r->indexBufferTextures)linearFree(r->indexBufferTextures);
	if(r->indexBuffers)
	{
		int i; for(i=0; i<r->numIndexBuffers; i++)linearFree(r->indexBuffers[i]);
		free(r->indexBuffers);
	}
	r->vertexBuffer=NULL;
	r->numIndices=NULL;
	r->indexBufferTextures=NULL;
	r->indexBuffers=NULL;
	r->numIndexBuffers=0;

	rectangleVertex_s* tmpVertex=malloc(sizeof(rectangleVertex_s)*r->rectangles.num*4);
	if(!tmpVertex)return;

	{
		texture_s** tmpTextures=calloc(TEXTURES_NUM, sizeof(texture_s*));
		int* tmpNumIndices=calloc(TEXTURES_NUM, sizeof(int));

		r->numIndexBuffers=0;
		listCell_s* l=r->rectangles.first;
		while(l)
		{
			if(l->data.hide){l=l->next; continue;}
			texture_s* t=getRectangleTexture(&l->data);
			int i=findTexture(t, tmpTextures, r->numIndexBuffers);
			if(i<0)tmpTextures[i=(r->numIndexBuffers++)]=t;
			tmpNumIndices[i]++;
			l=l->next;
		}
		r->indexBuffers=calloc(r->numIndexBuffers, sizeof(u16*));
		r->numIndices=calloc(r->numIndexBuffers, sizeof(int));
		r->indexBufferTextures=calloc(r->numIndexBuffers, sizeof(texture_s*));
		int i; for(i=0; i<r->numIndexBuffers; i++)r->indexBuffers[i]=linearAlloc(sizeof(u16)*6*tmpNumIndices[i]);

		free(tmpTextures);
		free(tmpNumIndices);
	}

	{
		r->numIndexBuffers=0;

		r->vertexBuffer=tmpVertex;
		r->numVertices=0;
		listCell_s* l=r->rectangles.first;
		while(l)
		{
			if(l->data.hide){l=l->next; continue;}

			texture_s* t=getRectangleTexture(&l->data);
			int b=findTexture(t, r->indexBufferTextures, r->numIndexBuffers);
			if(b<0)
			{
				r->indexBufferTextures[b=r->numIndexBuffers++]=t;
			}

			vect3Di_s texCoords[4];
			getMaterialTextureCoord(&l->data, texCoords);
			generateRectangleGeometry(&l->data, texCoords, r->vertexBuffer, &r->numVertices, r->indexBuffers[b], &r->numIndices[b]);

			l=l->next;
		}
	}

	r->vertexBuffer=linearAlloc(sizeof(rectangleVertex_s)*r->numVertices);
	memcpy(r->vertexBuffer, tmpVertex, sizeof(rectangleVertex_s)*r->numVertices);

	free(tmpVertex);
}
Пример #21
0
//--------------------------------------------------------------------
// read a brick set for the world
void ChunkWorld::readBrickSet(
  BrickSetFile& brickSetFile)
{
  m_brickSet = new BrickSet();

  // assign index to each texture used
  m_nextTextureId = 0;
  m_textureIds.removeAll();

  // add an entry for air
  BrickDefn* desc = new BrickDefn();
  desc->m_trans[BRICK_FACE_XMIN] = true;
  desc->m_trans[BRICK_FACE_XMAX] = true;
  desc->m_trans[BRICK_FACE_YMIN] = true;
  desc->m_trans[BRICK_FACE_YMAX] = true;
  desc->m_trans[BRICK_FACE_ZMIN] = true;
  desc->m_trans[BRICK_FACE_ZMAX] = true;
  m_brickSet->m_defns[0] = desc;
  m_brickSet->m_defns[0]->m_subDefns[0] = new BrickSubDefn();

  // for each brick type
  for (int i = 0; i < brickSetFile.m_brickTags.length(); i++)
  {
    BrickTag* brick = (BrickTag*) brickSetFile.m_brickTags[i];

    // get existing defn, if any, for this major code
    desc = m_brickSet->m_defns[brick->m_majorCode];
    if (desc == NULL)
    {
      desc = new BrickDefn();
      m_brickSet->m_defns[brick->m_majorCode] = desc;
    }

    // get entry for minor code
    if (brick->m_minorCode < 0 || brick->m_minorCode >= SUBDEFN_COUNT)
      throw new mgException("Invalid brick defn minor code %02x%02x", 
        brick->m_majorCode, brick->m_minorCode);

    // don't allow duplicates
    BrickSubDefn* subDefn = desc->m_subDefns[brick->m_minorCode];
    if (subDefn != NULL)
      throw new mgException("Duplicate brick defn code %02x%02x", 
        brick->m_majorCode, brick->m_minorCode);

    // create new subdefinition
    subDefn = new BrickSubDefn();
    desc->m_subDefns[brick->m_minorCode] = subDefn;

    int shape;
    if (brick->m_shape.equalsIgnoreCase("slab"))
      shape = SHAPE_SLAB;
    else if (brick->m_shape.equalsIgnoreCase("column"))
      shape = SHAPE_COLUMN;
    else if (brick->m_shape.equalsIgnoreCase("cap"))
      shape = SHAPE_CAP;
    else if (brick->m_shape.equalsIgnoreCase("stair"))
      shape = SHAPE_STAIR;
    else if (brick->m_shape.equalsIgnoreCase("cube"))
      shape = SHAPE_CUBE;

    else shape = SHAPE_DEFN;

    // minor code 0 sets shape and transparency of brick
    if (brick->m_minorCode == 0)
    {
      desc->m_shape = shape;
      switch (desc->m_shape)
      {
        case SHAPE_CUBE:
          desc->m_trans[BRICK_FACE_XMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_XMAX] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_YMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_YMAX] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_ZMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_ZMAX] = brick->m_transparent;
          break;

        case SHAPE_SLAB:
          desc->m_trans[BRICK_FACE_XMIN] = true;
          desc->m_trans[BRICK_FACE_XMAX] = true;
          desc->m_trans[BRICK_FACE_YMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_YMAX] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_ZMIN] = true;
          desc->m_trans[BRICK_FACE_ZMAX] = true;
          break;
        
        case SHAPE_CAP:
          desc->m_trans[BRICK_FACE_XMIN] = true;
          desc->m_trans[BRICK_FACE_XMAX] = true;
          desc->m_trans[BRICK_FACE_YMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_YMAX] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_ZMIN] = true;
          desc->m_trans[BRICK_FACE_ZMAX] = true;
          break;

        case SHAPE_STAIR:
          desc->m_trans[BRICK_FACE_XMIN] = true;
          desc->m_trans[BRICK_FACE_XMAX] = true;
          desc->m_trans[BRICK_FACE_YMIN] = brick->m_transparent;
          desc->m_trans[BRICK_FACE_YMAX] = true;
          desc->m_trans[BRICK_FACE_ZMIN] = true;
          desc->m_trans[BRICK_FACE_ZMAX] = true;
          break;

        case SHAPE_COLUMN:
          desc->m_trans[BRICK_FACE_XMIN] = true;
          desc->m_trans[BRICK_FACE_XMAX] = true;
          desc->m_trans[BRICK_FACE_YMIN] = true;
          desc->m_trans[BRICK_FACE_YMAX] = true;
          desc->m_trans[BRICK_FACE_ZMIN] = true;
          desc->m_trans[BRICK_FACE_ZMAX] = true;
          break;
      
        case SHAPE_DEFN:
          desc->m_trans[BRICK_FACE_XMIN] = true;
          desc->m_trans[BRICK_FACE_XMAX] = true;
          desc->m_trans[BRICK_FACE_YMIN] = true;
          desc->m_trans[BRICK_FACE_YMAX] = true;
          desc->m_trans[BRICK_FACE_ZMIN] = true;
          desc->m_trans[BRICK_FACE_ZMAX] = true;
          break;
      }

      // set summary flags
      desc->m_hasTransparent = false;
      desc->m_hasOpaque = false;
    
      for (int j = 0; j < 6; j++)
      {
        if (desc->m_trans[j])
          desc->m_hasTransparent = true;
        else desc->m_hasOpaque = true;
      }
    }

    // find all the textures specified
    if (!brick->m_xminTexture.isEmpty())
      subDefn->m_xmin = findTexture(brick->m_xminTexture);
    if (!brick->m_xmaxTexture.isEmpty())
      subDefn->m_xmax = findTexture(brick->m_xmaxTexture);
    if (!brick->m_yminTexture.isEmpty())
      subDefn->m_ymin = findTexture(brick->m_yminTexture);
    if (!brick->m_ymaxTexture.isEmpty())
      subDefn->m_ymax = findTexture(brick->m_ymaxTexture);
    if (!brick->m_zminTexture.isEmpty())
      subDefn->m_zmin = findTexture(brick->m_zminTexture);
    if (!brick->m_zmaxTexture.isEmpty())
      subDefn->m_zmax = findTexture(brick->m_zmaxTexture);

    if (brick->m_dir < 0 || brick->m_dir >= DIRECTION_COUNT)
      throw new mgException("Invalid direction on brick defn code %02x%02x", 
                brick->m_majorCode, brick->m_minorCode);

    if (shape == SHAPE_DEFN)
      subDefn->m_shapeDefn = readShape(brick->m_shape);

    subDefn->m_dir = brick->m_dir;
    subDefn->m_light = brick->m_light;
    if (brick->m_light)
      mgDebug("light on brick code %02x%02x", brick->m_majorCode, brick->m_minorCode);
  }

  // combine minor and major definitions, check for missing info
  checkBrickSet();
}
Пример #22
0
void load3ds(Lib3dsFile *f)
{
	int i,j,meshV,meshT,meshNum;
	Lib3dsMesh *m;
	Lib3dsMaterial *mat;
	//First thing need to count all the vertices and triangles;
	nVertices=0;
	nTriangles=0;
	nSubmeshes=0;
	printf("Loading 3ds File\n");
	

	extractMaterialData(f);

	for (m=f->meshes; m; m=m->next)
	{
		nVertices+=m->points;
		nTriangles+=m->faces;
		for(i=1;i<m->faces;i++)
			if(strcmp(m->faceL[i-1].material,m->faceL[i].material)!=0)
				nSubmeshes++;
		nSubmeshes++;
	}
	printf("Vertices: %d Triangles: %d Submeshes: %d\n",nVertices,nTriangles,nSubmeshes);
	dVertices=new ModelVertex[nVertices];
	dTriangles=new uint16[nTriangles*3];
	dSubmeshes=new ModelGeoset[nSubmeshes];
	nTextureUnits=nSubmeshes;
	dTextureUnits=new ModelTexUnit[nTextureUnits];

	//Load initial vertex & triangle data
	meshV=0;
	meshT=0;
	meshNum=0;
	Matrix meshMat;
	for (m=f->meshes; m; m=m->next)
	{
		printf("Processing Mesh %d\n",meshNum);
		
		//This mesh must have something in it
		
		dSubmeshes[meshNum].id=0;
		dSubmeshes[meshNum].vstart=meshV;
		dSubmeshes[meshNum].vcount=m->points;
		dSubmeshes[meshNum].istart=meshT*3;
		dSubmeshes[meshNum].icount=m->faces*3;
		dSubmeshes[meshNum].d2=0;
		dSubmeshes[meshNum].d3=1;
		dSubmeshes[meshNum].d4=0;
		dSubmeshes[meshNum].d5=1;
		dSubmeshes[meshNum].d6=0;
		dSubmeshes[meshNum].v.x=0.001168764;
		dSubmeshes[meshNum].v.y=5.960465E-9;
		dSubmeshes[meshNum].v.z=0.6214849;
		
		//For now we are going to fake the texture unit data
		int matNum=materialNumber(m->faceL[0].material,f);
		dTextureUnits[meshNum].flags=0;
		dTextureUnits[meshNum].order=0;
		dTextureUnits[meshNum].op=meshNum;
		dTextureUnits[meshNum].op2=meshNum;
		dTextureUnits[meshNum].colorIndex=matNum;
		dTextureUnits[meshNum].flagsIndex=matNum;
		dTextureUnits[meshNum].texunit=0;
		dTextureUnits[meshNum].textureid=findTexture(m->faceL[0].material,f);
		dTextureUnits[meshNum].texunit2=0;
		dTextureUnits[meshNum].transid=matNum;
		dTextureUnits[meshNum].texanimid=0;
		dTextureUnits[meshNum].d4=1;
		
		meshNum++;

		
		for(i=0;i<m->points;i++)
		{
			dVertices[i+meshV].pos=Vec3D(m->pointL[i].pos[0],m->pointL[i].pos[1],m->pointL[i].pos[2])*0.01*.33*Scale;
			dVertices[i+meshV].texcoords=Vec2D(m->texelL[i][0],m->texelL[i][1]);

			dVertices[i+meshV].texcoords[1]=1-dVertices[i+meshV].texcoords[1];
			for(j=0;j<4;j++)
			{
				dVertices[i+meshV].bones[j]=0;
				dVertices[i+meshV].weights[j]=0;
			}
			dVertices[i+meshV].weights[0]=255;
			dVertices[i+meshV].unk1=0;
			dVertices[i+meshV].unk2=0;
			//Calculate Normal
			Vec3D Normal;
			Normal=Vec3D(0,0,0);
			for(j=0;j<m->faces;j++)
			{
				if((m->faceL[j].points[0]==i)||(m->faceL[j].points[2]==i)||(m->faceL[j].points[2]==i))
					Normal+=Vec3D(m->faceL[j].normal[0],m->faceL[j].normal[1],m->faceL[j].normal[2]);
			}
			Normal.normalize();
			dVertices[i+meshV].normal=Normal;
		}
		for(i=0;i<m->faces;i++)
		{
			if(i!=0)
			{
				if(strcmp(m->faceL[i-1].material,m->faceL[i].material)!=0)
				{
					//This mesh must have something in it
					dSubmeshes[meshNum].id=0;
					dSubmeshes[meshNum].vstart=meshV;
					dSubmeshes[meshNum].vcount=m->points;
					dSubmeshes[meshNum].istart=meshT*3+i*3;
					//Change count numbers
					dSubmeshes[meshNum-1].icount-=m->faces*3-i*3;
					dSubmeshes[meshNum].icount=m->faces*3-i*3;
					dSubmeshes[meshNum].d2=0;
					dSubmeshes[meshNum].d3=1;
					dSubmeshes[meshNum].d4=0;
					dSubmeshes[meshNum].d5=1;
					dSubmeshes[meshNum].d6=0;
					dSubmeshes[meshNum].v.x=0.001168764;
					dSubmeshes[meshNum].v.y=5.960465E-9;
					dSubmeshes[meshNum].v.z=0.6214849;
					//For now we are going to fake the texture unit data
					dTextureUnits[meshNum].flags=0;
					dTextureUnits[meshNum].colorIndex=0;
					dTextureUnits[meshNum].order=0;
					dTextureUnits[meshNum].op=meshNum;
					dTextureUnits[meshNum].op2=meshNum;
					dTextureUnits[meshNum].colorIndex=0;
					dTextureUnits[meshNum].flagsIndex=0;
					dTextureUnits[meshNum].texunit=0;
					dTextureUnits[meshNum].textureid=findTexture(m->faceL[i].material,f);
					dTextureUnits[meshNum].texunit2=0;
					dTextureUnits[meshNum].transid=0;
					dTextureUnits[meshNum].texanimid=0;
					dTextureUnits[meshNum].d4=1;
					
					meshNum++;
				}
			}
			dTriangles[(i+meshT)*3]=(uint16)m->faceL[i].points[0]+meshV;
			dTriangles[(i+meshT)*3+1]=(uint16)m->faceL[i].points[1]+meshV;
			dTriangles[(i+meshT)*3+2]=(uint16)m->faceL[i].points[2]+meshV;
			
		}
		meshV+=m->points;
		meshT+=m->faces;
	}
}
Пример #23
0
	//after each object is converter, including collision object, create a graphics object (and bind them)
	virtual void createGraphicsObject(_bObj* tmpObject, class btCollisionObject* bulletObject)
	{
		btRigidBody* body = btRigidBody::upcast(bulletObject);

		btRenderMesh* mesh = 0;
		if (tmpObject->data.mesh && tmpObject->data.mesh->vert_count && tmpObject->data.mesh->face_count)
		{
			if (tmpObject->data.mesh->vert_count> 16300)
			{
				printf("tmpObject->data.mesh->vert_count = %d\n",tmpObject->data.mesh->vert_count);
				
			}


			mesh = new btRenderMesh();
			mesh->m_bulletObject = bulletObject;

			btAlignedObjectArray<btVector3> originalVertices;
			originalVertices.resize(tmpObject->data.mesh->vert_count);

			for (int v=0;v<tmpObject->data.mesh->vert_count;v++)
			{
				float* vt3 = tmpObject->data.mesh->vert[v].xyz;
				originalVertices[v].setValue( IRR_X_M*vt3[IRR_X],IRR_Y_M*vt3[IRR_Y],IRR_Z_M*vt3[IRR_Z]);
			}
			int numVertices = 0;
			int numTriangles=0;
			int currentIndex=0;
			btTexVert* texVert = 0;
			

			for (int t=0;t<tmpObject->data.mesh->face_count;t++)
			{
				
				int originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_0_X];
				mesh->m_indices.push_back(currentIndex);
				texVert = &mesh->m_vertices.expand();
				texVert->m_localxyz = originalVertices[originalIndex];
				texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_X][0];
				texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_X][1];
				numVertices++;
				currentIndex++;

				originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_0_Y];
				mesh->m_indices.push_back(currentIndex);
				texVert = &mesh->m_vertices.expand();
				texVert->m_localxyz = originalVertices[originalIndex];
				texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_Y][0];
				texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_Y][1];
				numVertices++;
				currentIndex++;

				originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_0_Z];
				mesh->m_indices.push_back(currentIndex);
				texVert = &mesh->m_vertices.expand();
				texVert->m_localxyz = originalVertices[originalIndex];
				texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_Z][0];
				texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_0_Z][1];
				numVertices++;
				currentIndex++;
				numTriangles++;

				if (tmpObject->data.mesh->face[t].v[3])
				{
					originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_1_X];
					mesh->m_indices.push_back(currentIndex);
					texVert = &mesh->m_vertices.expand();
					texVert->m_localxyz = originalVertices[originalIndex];
					texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_X][0];
					texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_X][1];
					numVertices++;
					currentIndex++;

					originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_1_Y];
					mesh->m_indices.push_back(currentIndex);
					texVert = &mesh->m_vertices.expand();
					texVert->m_localxyz = originalVertices[originalIndex];
					texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_Y][0];
					texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_Y][1];
					numVertices++;
					currentIndex++;

					originalIndex = tmpObject->data.mesh->face[t].v[IRR_TRI_1_Z];
					mesh->m_indices.push_back(currentIndex);
					texVert = &mesh->m_vertices.expand();
					texVert->m_localxyz = originalVertices[originalIndex];
					texVert->m_uv1[0] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_Z][0];
					texVert->m_uv1[1] = tmpObject->data.mesh->face[t].uv[IRR_TRI_1_Z][1];
					numVertices++;
					numTriangles++;
					currentIndex++;
				}
			}

			if (numTriangles>0)
			{
				m_renderMeshes.push_back(mesh);
				printf("numTris = %d\n",numTriangles);
				//scene::ISceneNode* node = createMeshNode(mesh->m_vertices,numVertices,indices,numIndices,numTriangles,bulletObject,tmpObject);
				//if (newMotionState && node)
				//	newMotionState->addIrrlichtNode(node);

			}
		}

		if (tmpObject->data.mesh->face[0].m_image)
		{
			const char* fileName = tmpObject->data.mesh->face[0].m_image->m_imagePathName;
			
			BasicTexture* texture0 = findTexture(fileName);

			if (!texture0)
			{
				void* jpgData = tmpObject->data.mesh->face[0].m_image->m_packedImagePtr;
				int jpgSize = tmpObject->data.mesh->face[0].m_image->m_sizePackedImage;
				if (jpgSize)
				{
					texture0 = new BasicTexture((unsigned char*)jpgData,jpgSize);
					printf("texture filename=%s\n",fileName);
					texture0->loadTextureMemory(fileName);

					m_textures.insert(fileName,texture0);
					

				}
			}

			if (texture0 && mesh)
			{
				mesh->m_texture = texture0;
			}
		}
	}