diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index f44f61eb4..31d537e9e 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -46,10 +46,15 @@ Material::Material(const XMLNode *node, int index) node->get("name", &m_texname); if (m_texname=="") { - throw std::runtime_error("No texture name specified in %s file\n"); - } + throw std::runtime_error("[Material] No texture name specified in file\n"); + } init(index); + if (m_texname == "smoke.png") + { + printf("breakpoint here\n"); + } + bool b = false; node->get("clampU", &b); if (b) m_clamp_tex |= UCLAMP; b = false; diff --git a/src/graphics/material.hpp b/src/graphics/material.hpp index 8d76e39ae..b21cb8277 100644 --- a/src/graphics/material.hpp +++ b/src/graphics/material.hpp @@ -133,6 +133,9 @@ public: const std::string& getTexFname () const { return m_texname; } int getIndex () const { return m_index; } + + bool isTransparent () const { return m_alpha_testing || m_alpha_blending || m_add; } + // ------------------------------------------------------------------------ /** Returns the fraction of maximum speed on this material. */ float getMaxSpeedFraction() const { return m_max_speed_fraction; } diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 1f4327c82..33111cc7c 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -229,3 +229,15 @@ Material *MaterialManager::getMaterial(const std::string& fname, return m ; } // getMaterial + +bool MaterialManager::hasMaterial(const std::string& fname) +{ + std::string basename=StringUtils::getBasename(fname); + + // Search backward so that temporary (track) textures are found first + for(int i = (int)m_materials.size()-1; i>=0; i-- ) + { + if(m_materials[i]->getTexFname()==basename) return true; + } + return false; +} diff --git a/src/graphics/material_manager.hpp b/src/graphics/material_manager.hpp index f2c8fe90f..d4102ddd8 100644 --- a/src/graphics/material_manager.hpp +++ b/src/graphics/material_manager.hpp @@ -58,6 +58,8 @@ public: void addSharedMaterial(const std::string& filename); bool pushTempMaterial (const std::string& filename); void popTempMaterial (); + + bool hasMaterial(const std::string& fname); }; extern MaterialManager *material_manager; diff --git a/src/graphics/particle_emitter.cpp b/src/graphics/particle_emitter.cpp index 3a8049277..949fa1760 100644 --- a/src/graphics/particle_emitter.cpp +++ b/src/graphics/particle_emitter.cpp @@ -30,6 +30,7 @@ ParticleEmitter::ParticleEmitter(const ParticleKind* type, core::vector3df posit scene::ISceneNode* parent) : m_position(position) { m_node = NULL; + m_particle_type = NULL; m_parent = parent; setParticleType(type); @@ -81,7 +82,7 @@ void ParticleEmitter::setPosition(core::vector3df pos) //----------------------------------------------------------------------------- void ParticleEmitter::setParticleType(const ParticleKind* type) -{ +{ if (m_particle_type == type) return; // already the right type if (m_node != NULL) @@ -116,11 +117,13 @@ void ParticleEmitter::setParticleType(const ParticleKind* type) m_node->setName(debug_name.c_str()); #endif + video::SMaterial& mat0 = m_node->getMaterial(0); + m_node->setPosition(m_position); - material->setMaterialProperties(&(m_node->getMaterial(0))); + material->setMaterialProperties(&mat0); m_node->setMaterialTexture(0, material->getTexture()); - m_node->getMaterial(0).ZWriteEnable = false; // disable z-buffer writes + mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent switch (type->getShape()) { diff --git a/src/graphics/particle_kind.cpp b/src/graphics/particle_kind.cpp index a0aa48b7b..5b6bf8918 100644 --- a/src/graphics/particle_kind.cpp +++ b/src/graphics/particle_kind.cpp @@ -120,10 +120,17 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2 throw std::runtime_error("[ParticleKind] tag has invalid 'file' attribute"); } - m_material = material_manager->getMaterial(materialFile); - if (m_material->getTexture() == NULL) + if (material_manager->hasMaterial(materialFile)) { - throw std::runtime_error("[ParticleKind] Cannot locate file " + materialFile); + m_material = material_manager->getMaterial(materialFile); + if (m_material->getTexture() == NULL) + { + throw std::runtime_error("[ParticleKind] Cannot locate file " + materialFile); + } + } + else + { + fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of currently known materials, it will be opaque", materialFile.c_str()); } // ------------------------------------------------------------------------