Ejemplo n.º 1
0
TFMarkerArrows::TFMarkerArrows(rviz::DisplayContext* context, Ogre::SceneNode*
    parentNode, TFMarker* parent, const Ogre::Quaternion& orientation, const
    Ogre::Vector3& scale, double distance) :
  TFMarkerControl(context, parentNode, parent, true, false,
    "<b>Left-Click:</b> Move."),
  positiveArrow(new rviz::Arrow(context->getSceneManager(), sceneNode)),
  negativeArrow(new rviz::Arrow(context->getSceneManager(), sceneNode)) {
  cursor = rviz::makeIconCursor("package://rviz/icons/move1d.svg");
  
  positiveArrow->setOrientation(Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(
    Ogre::Vector3::UNIT_X));
  positiveArrow->set(0.5, 0.6, 0.5, 1.0);
  
  negativeArrow->setOrientation(Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(
    Ogre::Vector3::NEGATIVE_UNIT_X));
  negativeArrow->set(0.5, 0.6, 0.5, 1.0);
  
  setOrientation(orientation);
  setScale(scale);
  setDistance(distance);
  
  addMaterial(positiveArrow->getShaft()->getMaterial());
  addMaterial(positiveArrow->getHead()->getMaterial());
  addMaterial(negativeArrow->getShaft()->getMaterial());
  addMaterial(negativeArrow->getHead()->getMaterial());  
}
Ejemplo n.º 2
0
void * addFont(zoneInfo_t* info, const char* name, char* data, int dataLen)
{
	if (dataLen > 0) { Com_Error(false, "Can't add new fonts!"); return NULL; }

	Font* font = (Font*)data;

	addAsset(info, ASSET_TYPE_MATERIAL, font->image->name, addMaterial(info, font->image->name, (char*)font->image, -1));
	addAsset(info, ASSET_TYPE_MATERIAL, font->glowImage->name, addMaterial(info, font->glowImage->name, (char*)font->glowImage, -1));

	return data;
}
Ejemplo n.º 3
0
// Set the current material
GLC_uint GLC_Mesh::setCurrentMaterial(GLC_Material* pMaterial, int lod, double accuracy)
{

	// Test if a primitive group hash exists for the specified lod
	if (!m_PrimitiveGroups.contains(lod))
	{
		m_PrimitiveGroups.insert(lod, new LodPrimitiveGroups());

		m_MeshData.appendLod(accuracy);
	}

	GLC_uint returnId;
	if (NULL == pMaterial)
	{
		returnId= m_DefaultMaterialId; // Default material id

		// Test if the material has been already load
		if (m_DefaultMaterialId == 0)
		{
			pMaterial= new GLC_Material();
			// Add the material to the mesh
			addMaterial(pMaterial);
			m_DefaultMaterialId= pMaterial->id();
			returnId= m_DefaultMaterialId;

		}
		// Test if a primitive group for this material exist
		if (!m_PrimitiveGroups.value(lod)->contains(returnId))
		{
			m_PrimitiveGroups.value(lod)->insert(returnId, new GLC_PrimitiveGroup(returnId));
		}
	}
	else
	{
		returnId= pMaterial->id();
		// Test if the material has been already load
		if (!containsMaterial(returnId))
		{
			// Add the material to the mesh
			addMaterial(pMaterial);
			m_PrimitiveGroups.value(lod)->insert(returnId, new GLC_PrimitiveGroup(returnId));

		}
		else if (!m_PrimitiveGroups.value(lod)->contains(returnId))
		{
			// Add the material to the group
			m_PrimitiveGroups.value(lod)->insert(returnId, new GLC_PrimitiveGroup(returnId));
		}
	}

	return returnId;
}
Ejemplo n.º 4
0
void ResourceManager::addTextureMaterialSprite(
        const std::string&                  id,
              resource_group::ResourceGroup resourceGroup,
        const std::string&                  shader,
        const glm::vec4&                    colour,
        const std::string&                  texturePath,
              unsigned                      frameRate,
              bool                          repeat,
              unsigned                      begin,
              unsigned                      end,
              int                           layer,
        const glm::vec2&                    size,
        const glm::vec2&                    texSize,
        const glm::vec2&                    texOffset,
              unsigned                      textureFlags,
              unsigned                      materialFlags )
{
    // texture
    addTexture(
        id, resourceGroup, texturePath, frameRate,
        repeat, begin, end, textureFlags );
    // material
    addMaterial( id, resourceGroup, shader, colour, id, materialFlags );
    // sprite
    addSprite( id, resourceGroup, layer, id, size, texSize, texOffset );
}
Ejemplo n.º 5
0
void ResourceManager::addTextureMaterialGeometryMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
    const std::string&                  texturePath,
          unsigned                      frameRate,
          bool                          repeat,
          unsigned                      begin,
          unsigned                      end,
    const std::string&                  geometryPath,
          int                           layer,
          unsigned                      textureFlags,
          unsigned                      materialFlags )
{
    // texture
    addTexture(
        id, resourceGroup, texturePath, frameRate,
        repeat, begin, end, textureFlags );
    // material
    addMaterial( id, resourceGroup, shader, colour, id, materialFlags );
    // geometry
    addGeometry( id, resourceGroup, geometryPath );
    // mesh
    addMesh( id, resourceGroup, layer, id, id );
}
Ejemplo n.º 6
0
/* =============================================================================
    ADD MATERIAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\* This function adds a
    material to our model manually since .obj has no such info ADD MATERIAL
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
 =============================================================================== */
int C3DModel::addMaterial(string strName, string strFile, color clr, int iTxMode)
{
	CMaterialPtr pMat = new CMaterial();
	pMat->setTextureId(-1);
	pMat->setColor(clr);
	pMat->setHeight(0);
	pMat->setWidth(0);
	pMat->setName(strName);

	// If we have a file name passed in, copy it to our material structure
	if (strFile.size())
	{
		int w, h;
		pMat->setLink(strFile);

		GLuint	txID = createTexture(pMat->getLink(), w, h, iTxMode);
		pMat->setTextureId(txID);
		pMat->setHeight(h);
		pMat->setWidth(w);
	}

	pMat->setShared(false);

	addMaterial(pMat);
	return pMat->getTextureId();
}
Ejemplo n.º 7
0
void WldModel::readAllMaterials()
{
    WLD* wld        = m_wld;
    auto& frag30s   = wld->getFragsByType(0x30);
    
    if (frag30s.size() == 0)
        throw 1; //fixme
    
    if (m_materialIndicesByF30.size() > 0)
        return;
    
    // Materials
    uint32_t i = 1; // Zeroth material is the NULL material
    
    for (Fragment* frag : frag30s)
    {
        Frag30* f30 = (Frag30*)frag;
        addMaterial(new WldMaterial(wld->getFragName(f30), f30->visibilityFlag));
        m_materialIndicesByF30[f30] = i++;
    }
    
    // VertexBuffers
    initVertexBuffers();
    
    // Textures
    for (Fragment* frag : frag30s)
    {
        Frag30* f30 = (Frag30*)frag;
        handleF30(f30);
    }
}
Ejemplo n.º 8
0
void parseMaterials(GeometryConverter *cvt, std::ostream &os, const fs::path &texturesDir, 
		const fs::path &mtlFileName, std::set<std::string> &mtlList) {
	SLog(EInfo, "Loading OBJ materials from \"%s\" ..", mtlFileName.file_string().c_str());
	fs::ifstream is(mtlFileName);
	if (is.bad() || is.fail())
		SLog(EError, "Unexpected I/O error while accessing material file '%s'!", 
			mtlFileName.file_string().c_str());
	std::string buf, line;
	std::string mtlName;
	Spectrum diffuse(0.0f);
	std::string diffuseMap, maskMap;

	while (is >> buf) {
		if (buf == "newmtl") {
			mtlList.insert(mtlName);
			addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap);
			std::getline(is, line);
			mtlName = trim(line.substr(1, line.length()-1));
			diffuse = Spectrum(0.0f);
			diffuseMap = "";
			maskMap = "";
		} else if (buf == "Kd") {
			Float r, g, b;
			is >> r >> g >> b;
			if (cvt->m_srgb)
				diffuse.fromSRGB(r, g, b);
			else
				diffuse.fromLinearRGB(r, g, b);
		} else if (buf == "map_Kd") {
Ejemplo n.º 9
0
void WldModel::readMaterials(Frag36* f36)
{
    WLD* wld = m_wld;
    
    // f36 -> f31 -> f30
    
    Frag31* f31 = (Frag31*)wld->getFrag(f36->materialListRef);
    
    if (!f31) throw 1; //fixme
    
    for (uint32_t i = 0; i < f31->refCount; i++)
    {
        Frag30* f30 = (Frag30*)wld->getFrag(f31->refList[i]);
        addMaterial(new WldMaterial(wld->getFragName(f30), f30->visibilityFlag));
        m_materialIndicesByF30[f30] = i + 1;
    }
    
    initVertexBuffers();
    
    for (uint32_t i = 0; i < f31->refCount; i++)
    {
        Frag30* f30 = (Frag30*)wld->getFrag(f31->refList[i]);
        handleF30(f30);
    }
}
Ejemplo n.º 10
0
void CMC_ModelData::loadFromTZW(const char *fileName)
{

    // load All materials
    auto data = tzw::Tfile::getInstance()->getData (fileName,true);
    rapidjson::Document d;
    d.Parse((const char *)data.getBytes ());

    auto& materialsObj= d["materials"];
    for(auto iter = materialsObj.Begin ();iter!=materialsObj.End ();iter++)
    {
        auto& materialObj = *iter;
        auto material = new CMC_Material();
        material->loadFromTZW (materialObj);
        addMaterial (material);
    }

    //load all meshes.
    auto& meshesObj = d["meshes"];
    for(auto iter = meshesObj.Begin ();iter!= meshesObj.End ();iter++)
    {
        auto& meshObj = *iter;
        auto mesh = new CMC_MeshData();
        mesh->loadFromTZW (meshObj);
        addMesh (mesh);
    }
}
Ejemplo n.º 11
0
// Load the mesh from binary data stream
void GLC_Mesh::loadFromDataStream(QDataStream& stream, const MaterialHash& materialHash, const QHash<GLC_uint, GLC_uint>& materialIdMap)
{
	quint32 chunckId;
	stream >> chunckId;
	Q_ASSERT(chunckId == m_ChunkId);

	// The mesh name
	QString meshName;
	stream >> meshName;
	setName(meshName);

	// The wire data
	stream >> GLC_Geometry::m_WireData;

	// The mesh next primitive local id
	GLC_uint localId;
	stream >> localId;
	setNextPrimitiveLocalId(localId);

	// Retrieve geom mesh data
	stream >> m_MeshData;

	// Retrieve primitiveGroupLodList
	QList<int> primitiveGroupLodList;
	stream >> primitiveGroupLodList;

	// Retrieve primitiveGroup list
	QList<QList<GLC_PrimitiveGroup> > primitiveListOfGroupList;
	stream >> primitiveListOfGroupList;

	// Construct mesh primitiveGroupHash
	const int lodCount= primitiveGroupLodList.size();
	for (int i= 0; i < lodCount; ++i)
	{
		GLC_Mesh::LodPrimitiveGroups* pCurrentPrimitiveGroup= new GLC_Mesh::LodPrimitiveGroups();
		m_PrimitiveGroups.insert(primitiveGroupLodList.at(i), pCurrentPrimitiveGroup);
		const int groupCount= primitiveListOfGroupList.at(i).size();
		for (int iGroup= 0; iGroup < groupCount; ++iGroup)
		{
			Q_ASSERT(materialIdMap.contains(primitiveListOfGroupList.at(i).at(iGroup).id()));
			const GLC_uint newId= materialIdMap.value(primitiveListOfGroupList.at(i).at(iGroup).id());
			// Test if the mesh contains the material
			if (!containsMaterial(newId))
			{
				addMaterial(materialHash.value(newId));
			}
			GLC_PrimitiveGroup* pGroup= new GLC_PrimitiveGroup(primitiveListOfGroupList.at(i).at(iGroup), newId);

			Q_ASSERT(! m_PrimitiveGroups.value(primitiveGroupLodList.at(i))->contains(newId));
			m_PrimitiveGroups.value(primitiveGroupLodList.at(i))->insert(newId, pGroup);
		}
	}
	stream >> m_NumberOfVertice;
	stream >> m_NumberOfNormals;

	finishSerialized();
	//qDebug() << "Mesh mem size= " << memmorySize();
}
Ejemplo n.º 12
0
void * addTracer(zoneInfo_t* info, const char* name, char* data, int dataLen)
{
	if (dataLen > 0)  { Com_Error(false, "Can only export built in Tracers!");  return NULL; }

	Tracer* t = (Tracer*)data;
	addAsset(info, ASSET_TYPE_MATERIAL, t->material->name, addMaterial(info, t->material->name, (char*)t->material, -1));

	return t;
}
Ejemplo n.º 13
0
OBJGroup::OBJGroup( const std::string& name ) :

    m_name( name ),
    m_hasTextureCoordinates( false ),
    m_hasNormals( true )

{
    addMaterial( "" );
}
Ejemplo n.º 14
0
Mesh::Mesh(const DFFGeometry& geometry, bool autoSubmeshes)
		: vertexCount(geometry.getVertexCount()), frame(NULL)
{
	flags = 0;
	const float* vertices = geometry.getVertices();
	const float* normals = geometry.getNormals();
	const uint8_t* colors = geometry.getVertexColors();
	const float* texCoords = NULL;
	const uint8_t* boneIndices = geometry.getBoneIndices();
	const float* boneWeights = geometry.getBoneWeights();

	if (geometry.getUVSetCount() > 0) {
		texCoords = geometry.getUVCoordSet(0);
	}

	if (geometry.isTriangleStripFormat()) {
		vertexFormat = VertexFormatTriangleStrips;
	} else {
		vertexFormat = VertexFormatTriangles;
	}

	if (normals) {
		flags |= MeshNormals;
	}
	if (texCoords) {
		flags |= MeshTexCoords;
	}
	if (colors) {
		flags |= MeshVertexColors;
	}
	if (boneIndices) {
		flags |= MeshSkinData;
	}

	if (geometry.isDynamicLightingEnabled()) {
		flags |= MeshDynamicLighting;
	}

	DFFGeometry::ConstMaterialIterator it;
	for (it = geometry.getMaterialBegin() ; it != geometry.getMaterialEnd() ; it++) {
		Material* material = new Material(**it);
		addMaterial(material);
	}

	if (autoSubmeshes) {
		DFFGeometry::ConstPartIterator pit;
		for (pit = geometry.getPartBegin() ; pit != geometry.getPartEnd() ; pit++) {
			Submesh* submesh = new Submesh(this, **pit);
		}
	}

	const DFFBoundingSphere* b = geometry.getBounds();
	setBounds(b->x, b->y, b->z, b->radius);

	init(flags, vertices, normals, texCoords, colors, boneIndices, boneWeights);
}
Ejemplo n.º 15
0
//////////////////////////////////////////////
//Interface branch
void FEMesh::addInterfaceElement(InterfaceElement *ed)
{
  edgement.push_back(ed);
  //Caution! Assume that normal elements (triangles and quads) get added
  //first before edge elements.
  ed->set_index(element.size()+edgement.size()-1);
  //std::cout << *ed << std::endl;
  if(ed->material()) 
    addMaterial(ed->material());
}
Ejemplo n.º 16
0
void CScene::init (const string& fileName)
{
  m_boundingSpheresMode = false;
  m_selectedItem        = NULL;

  addMaterial(new CMaterial(this));

  cout << "Chargement de la scène " << fileName << endl;
  ObjImporter::import(this,fileName,m_objectsArray);
  computeBoundingBox();
}
Ejemplo n.º 17
0
// Replace the Master material
void GLC_Geometry::replaceMasterMaterial(GLC_Material* pMaterial)
{
	Q_ASSERT(!m_IsWire);
	if (!m_MaterialHash.isEmpty())
	{
		if (pMaterial != firstMaterial())
		{
			// Remove the first material
			MaterialHash::iterator iMaterial= m_MaterialHash.begin();
			removeMaterial(iMaterial.value()->id());

			// Add the new material
			addMaterial(pMaterial);
		}
	}
	else
	{
		addMaterial(pMaterial);
	}
}
Ejemplo n.º 18
0
// Replace the Master material
void GLC_Mesh::replaceMasterMaterial(GLC_Material* pMat)
{
	if (hasMaterial())
	{
		GLC_uint oldId= firstMaterial()->id();
		replaceMaterial(oldId, pMat);
	}
	else
	{
		addMaterial(pMat);
	}
}
Ejemplo n.º 19
0
void ResourceManager::addMatrialKeyFrameMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
          int                           layer,
    const std::string&                  keyFramePath,
          unsigned                      materialFlags )
{
    addMaterial( id, resourceGroup, shader, colour, materialFlags );
    addKeyFrameMesh( id, resourceGroup, layer, id, keyFramePath );
}
Ejemplo n.º 20
0
/* =============================================================================
    routine to add a material from another already created texture
 =============================================================================== */
int C3DModel::addMaterial(string strName, int txID, int sizeX, int sizeY, color clr, bool bMipMap)
{
	CMaterialPtr pMat = new CMaterial();
	pMat->setTextureId(txID);
	pMat->setColor(clr);
	pMat->setHeight(sizeY);
	pMat->setWidth(sizeX);
	pMat->setName(strName);
	pMat->setShared(true);
	pMat->setMipMap(bMipMap);
	addMaterial(pMat);
	return pMat->getTextureId();
}
Ejemplo n.º 21
0
void ResourceManager::addTextureMatrialKeyFrameMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const std::string&                  texturePath,
          int                           layer,
    const std::string&                  keyFramePath,
          unsigned                      textureFlags,
          unsigned                      materialFlags )
{
    addTexture( id, resourceGroup, texturePath, textureFlags );
    addMaterial( id, resourceGroup, shader, id, materialFlags );
    addKeyFrameMesh( id, resourceGroup, layer, id, keyFramePath );
}
Ejemplo n.º 22
0
void ResourceManager::addMaterialText(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
          int                           layer,
    const std::string&                  font,
    const std::string&                  str,
          float                         size,
          unsigned                      materialFlags )
{
    addMaterial( id, resourceGroup, shader, colour, materialFlags );
    addText( id, resourceGroup, layer, id, font, str, size );
}
Ejemplo n.º 23
0
GameComponentPtr
MeshRenderComponent::clone() const noexcept
{
	auto result = std::make_shared<MeshRenderComponent>();
	result->setCastShadow(this->getCastShadow());
	result->setReceiveShadow(this->getReceiveShadow());
	result->setName(this->getName());

	for (auto& it : this->getSharedMaterials())
	{
		result->addMaterial(it);
		result->addSharedMaterial(it);
	}

	return result;
}
Ejemplo n.º 24
0
//===================================================================
Mesh::Mesh(QObject *parent) : QObject(parent),
  mDebugView(false), mMode(GL_TRIANGLES), mTexture(0), mTextureImage(0), mOpacity(1)
{
    // ctor

    mShaderProgram = new QOpenGLShaderProgram(this);

    mVertexBuffer = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
    mIndexBuffer  = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);
    mTexture      = new QOpenGLTexture(QOpenGLTexture::Target2D);

    resetTransform();


    addMaterial(Material());
}
Ejemplo n.º 25
0
void ResourceManager::addMaterialGeometryMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
    const std::string&                  geometryPath,
          int                           layer,
          unsigned                      materialFlags )
{
    // material
    addMaterial( id, resourceGroup, shader, colour, materialFlags );
    // geometry
    addGeometry( id, resourceGroup, geometryPath );
    // mesh
    addMesh( id, resourceGroup, layer, id, id );
}
Ejemplo n.º 26
0
void FEMesh::refreshMaterials(PyObject *skeletoncontext) {
  for(ElementIterator ei=element_iterator(); !ei.end(); ++ei) {
    Element *element = ei.element();
    const Material *oldmat = element->material();
    element->refreshMaterial(skeletoncontext);
    const Material *newmat = element->material();
    if(newmat != oldmat) {
      if(oldmat)
	removeMaterial(oldmat);
      if(newmat)
	addMaterial(newmat);
    }
  }
  // TODO INTERFACE: Should this just be in-line here?
  refreshInterfaceMaterials(skeletoncontext);
}
Ejemplo n.º 27
0
void ResourceManager::addMaterialSprite(
        const std::string&                  id,
              resource_group::ResourceGroup resourceGroup,
        const std::string&                  shader,
        const glm::vec4&                    colour,
              int                           layer,
        const glm::vec2&                    size,
        const glm::vec2&                    texSize,
        const glm::vec2&                    texOffset,
              unsigned                      materialFlags )
{
    // material
    addMaterial( id, resourceGroup, shader, colour, materialFlags );
    // sprite
    addSprite( id, resourceGroup, layer, id, size, texSize, texOffset );
}
Ejemplo n.º 28
0
/* =============================================================================
 =============================================================================== */
int C3DModel::addMaterial(string strName, const unsigned char *pData, int sizeX, int sizeY, color clr, int iTxMode)
{
	CMaterialPtr pMat = new CMaterial();
	pMat->setTextureId(-1);
	pMat->setColor(clr);
	pMat->setHeight(0);
	pMat->setWidth(0);
	pMat->setName(strName);

	// If we have a file name passed in, let's copy it to our material structure
	GLuint	txID = createTexture(pData, sizeX, sizeY, GL_RGBA, GL_RGBA, iTxMode);
	pMat->setTextureId(txID);
	pMat->setShared(false);

	addMaterial(pMat);
	return pMat->getTextureId();
}
Ejemplo n.º 29
0
//===================================================================
Mesh::Mesh(const Mesh &mesh)
{
    // copy ctor
    mShaderProgram = new QOpenGLShaderProgram(this);

    mDebugView = mesh.mDebugView;
    mIndexBuffer = QOpenGLBuffer(mesh.mIndexBuffer);
    mMode = mesh.mMode;
    mTextureImage = mesh.mTextureImage;
    setTextureImage(mTextureImage);

    for (int index = 0; index < mesh.mVertices.count(); index++)
          mVertices.append(mesh.vertices().at(index)) ;

    addMaterial(Material());
    mOpacity = mesh.mOpacity;
}
Ejemplo n.º 30
0
// TODO INTERFACE: Called from FEMesh::refreshMaterials, but possibly
// from elsewhere also.  Should this function just be in-line in
// refreshMaterials, or is there a good reason for it to stand alone?
void FEMesh::refreshInterfaceMaterials(PyObject *skelctxt)
{
  for(ElementIterator ei=edgement_iterator(); !ei.end(); ++ei) {
    Element *el = ei.element();
    const Material *om = el->material();
    InterfaceElement *ed = dynamic_cast<InterfaceElement*>(el);
    ed->refreshInterfaceMaterial(skelctxt);
    const Material *nm = el->material();
    if (nm != om) {
      if (om) 
	removeMaterial(om);
      if (nm)
	addMaterial(nm);
    }
  }

}