+ m_spritenode->setMaterialTexture(0,
+ tsrc->getTexture(texturestring));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 1)
+ {
+ m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
+ m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
+ m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
+ }
+
+ m_spritenode->getMaterial(0).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_spritenode->getMaterial(0).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ }
+ if(m_animated_meshnode)
+ {
+ if(m_prop.visual == "mesh")
+ {
+ for (u32 i = 0; i < m_prop.textures.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
+ {
+ std::string texturestring = m_prop.textures[i];
+ if(texturestring == "")
+ continue; // Empty texture string means don't modify that material
+ texturestring += mod;
+ video::ITexture* texture = tsrc->getTexture(texturestring);
+ if(!texture)
+ {
+ errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
+ continue;
+ }
+
+ // Set material flags and texture
+ video::SMaterial& material = m_animated_meshnode->getMaterial(i);
+ material.TextureLayer[0].Texture = texture;
+ material.setFlag(video::EMF_LIGHTING, false);
+ material.setFlag(video::EMF_BILINEAR_FILTER, false);
+
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ for (u32 i = 0; i < m_prop.colors.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
+ {
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
+ m_animated_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
+ }
+ }
+ }
+ if(m_meshnode)
+ {
+ if(m_prop.visual == "cube")
+ {
+ for (u32 i = 0; i < 6; ++i)
+ {
+ std::string texturestring = "unknown_node.png";
+ if(m_prop.textures.size() > i)
+ texturestring = m_prop.textures[i];
+ texturestring += mod;
+
+
+ // Set material flags and texture
+ video::SMaterial& material = m_meshnode->getMaterial(i);
+ material.setFlag(video::EMF_LIGHTING, false);
+ material.setFlag(video::EMF_BILINEAR_FILTER, false);
+ material.setTexture(0,
+ tsrc->getTexture(texturestring));
+ material.getTextureMatrix(0).makeIdentity();
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() > i)
+ {
+ m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
+ m_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
+ }
+
+ m_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ }
+ else if(m_prop.visual == "upright_sprite")
+ {
+ scene::IMesh *mesh = m_meshnode->getMesh();
+ {
+ std::string tname = "unknown_object.png";
+ if(m_prop.textures.size() >= 1)
+ tname = m_prop.textures[0];
+ tname += mod;
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
+ buf->getMaterial().setTexture(0,
+ tsrc->getTexture(tname));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 1)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[0];
+ buf->getMaterial().DiffuseColor = m_prop.colors[0];
+ buf->getMaterial().SpecularColor = m_prop.colors[0];
+ }
+
+ buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ {
+ std::string tname = "unknown_object.png";
+ if(m_prop.textures.size() >= 2)
+ tname = m_prop.textures[1];
+ else if(m_prop.textures.size() >= 1)
+ tname = m_prop.textures[0];
+ tname += mod;
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
+ buf->getMaterial().setTexture(0,
+ tsrc->getTexture(tname));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 2)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[1];
+ buf->getMaterial().DiffuseColor = m_prop.colors[1];
+ buf->getMaterial().SpecularColor = m_prop.colors[1];
+ }
+ else if(m_prop.colors.size() >= 1)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[0];
+ buf->getMaterial().DiffuseColor = m_prop.colors[0];
+ buf->getMaterial().SpecularColor = m_prop.colors[0];
+ }
+
+ buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ }
+ }
+ }
+
+ void updateAnimation()
+ {
+ if(m_animated_meshnode == NULL)
+ return;
+
+ m_animated_meshnode->setFrameLoop((int)m_animation_range.X, (int)m_animation_range.Y);
+ m_animated_meshnode->setAnimationSpeed(m_animation_speed);
+ m_animated_meshnode->setTransitionTime(m_animation_blend);
+ }
+
+ void updateBonePosition()
+ {
+ if(!m_bone_position.size() || m_animated_meshnode == NULL)
+ return;
+
+ m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ std::string bone_name = (*ii).first;
+ v3f bone_pos = (*ii).second.X;
+ v3f bone_rot = (*ii).second.Y;
+ irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
+ if(bone)
+ {
+ bone->setPosition(bone_pos);
+ bone->setRotation(bone_rot);
+ }
+ }
+ }
+
+ void updateAttachments()
+ {
+ m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
+ m_is_visible = !m_attached_to_local; // Objects attached to the local player should always be hidden
+
+ if(getParent() == NULL || m_attached_to_local) // Detach or don't attach
+ {
+ if(m_meshnode)
+ {
+ v3f old_position = m_meshnode->getAbsolutePosition();
+ v3f old_rotation = m_meshnode->getRotation();
+ m_meshnode->setParent(m_smgr->getRootSceneNode());
+ m_meshnode->setPosition(old_position);
+ m_meshnode->setRotation(old_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ if(m_animated_meshnode)
+ {
+ v3f old_position = m_animated_meshnode->getAbsolutePosition();
+ v3f old_rotation = m_animated_meshnode->getRotation();
+ m_animated_meshnode->setParent(m_smgr->getRootSceneNode());
+ m_animated_meshnode->setPosition(old_position);
+ m_animated_meshnode->setRotation(old_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ if(m_spritenode)
+ {
+ v3f old_position = m_spritenode->getAbsolutePosition();
+ v3f old_rotation = m_spritenode->getRotation();
+ m_spritenode->setParent(m_smgr->getRootSceneNode());
+ m_spritenode->setPosition(old_position);
+ m_spritenode->setRotation(old_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ if(m_is_local_player)
+ {
+ LocalPlayer *player = m_env->getLocalPlayer();
+ player->isAttached = false;
+ }
+ }
+ else // Attach
+ {
+ scene::IMeshSceneNode *parent_mesh = NULL;
+ if(getParent()->getMeshSceneNode())
+ parent_mesh = getParent()->getMeshSceneNode();
+ scene::IAnimatedMeshSceneNode *parent_animated_mesh = NULL;
+ if(getParent()->getAnimatedMeshSceneNode())
+ parent_animated_mesh = getParent()->getAnimatedMeshSceneNode();
+ scene::IBillboardSceneNode *parent_sprite = NULL;
+ if(getParent()->getSpriteSceneNode())
+ parent_sprite = getParent()->getSpriteSceneNode();
+
+ scene::IBoneSceneNode *parent_bone = NULL;
+ if(parent_animated_mesh && m_attachment_bone != "")
+ parent_bone = parent_animated_mesh->getJointNode(m_attachment_bone.c_str());
+
+ // The spaghetti code below makes sure attaching works if either the parent or child is a spritenode, meshnode, or animatedmeshnode
+ // TODO: Perhaps use polymorphism here to save code duplication
+ if(m_meshnode){
+ if(parent_bone){
+ m_meshnode->setParent(parent_bone);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_meshnode->setParent(parent_mesh);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_meshnode->setParent(parent_animated_mesh);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_meshnode->setParent(parent_sprite);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_animated_meshnode){
+ if(parent_bone){
+ m_animated_meshnode->setParent(parent_bone);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_animated_meshnode->setParent(parent_mesh);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_animated_meshnode->setParent(parent_animated_mesh);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_animated_meshnode->setParent(parent_sprite);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_spritenode){
+ if(parent_bone){
+ m_spritenode->setParent(parent_bone);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_spritenode->setParent(parent_mesh);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_spritenode->setParent(parent_animated_mesh);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_spritenode->setParent(parent_sprite);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_is_local_player)
+ {
+ LocalPlayer *player = m_env->getLocalPlayer();
+ player->isAttached = true;