void EC_Mesh::OnAttributeUpdated(IAttribute *attribute) { if (attribute == &drawDistance) { if(entity_) entity_->setRenderingDistance(drawDistance.Get()); } else if (attribute == &castShadows) { if(entity_) { if (entity_) entity_->setCastShadows(castShadows.Get()); //! \todo might want to disable shadows for some attachments for (uint i = 0; i < attachment_entities_.size(); ++i) { if (attachment_entities_[i]) attachment_entities_[i]->setCastShadows(castShadows.Get()); } } } else if (attribute == &nodeTransformation) { Ogre::Node* adjustmentTarget = adjustment_node_; if (bone_tagpoint_) adjustmentTarget = bone_tagpoint_; if (adjustmentTarget) { Transform newTransform = nodeTransformation.Get(); adjustmentTarget->setPosition(newTransform.position.x, newTransform.position.y, newTransform.position.z); Quaternion adjust(DEGTORAD * newTransform.rotation.x, DEGTORAD * newTransform.rotation.y, DEGTORAD * newTransform.rotation.z); // Let's not assume the needed haxor adjustment here, but let user specify it as necessary //adjust = Quaternion(PI/2, 0, PI) * adjust; adjustmentTarget->setOrientation(Ogre::Quaternion(adjust.w, adjust.x, adjust.y, adjust.z)); // Prevent Ogre exception from zero scale if (newTransform.scale.x < 0.0000001f) newTransform.scale.x = 0.0000001f; if (newTransform.scale.y < 0.0000001f) newTransform.scale.y = 0.0000001f; if (newTransform.scale.z < 0.0000001f) newTransform.scale.z = 0.0000001f; adjustmentTarget->setScale(newTransform.scale.x, newTransform.scale.y, newTransform.scale.z); } } else if (attribute == &meshRef) { if (!ViewEnabled()) return; //Ensure that mesh is requested only when it's has actually changed. // if(entity_) // if(QString::fromStdString(entity_->getMesh()->getName()) == meshRef.Get().ref/*meshResourceId.Get()*/) // return; /* AssetTransferPtr transfer = GetFramework()->Asset()->RequestAsset(meshRef.Get()); if (transfer) { connect(transfer.get(), SIGNAL(Loaded(AssetPtr)), SLOT(OnMeshAssetLoaded()), Qt::UniqueConnection); } else { RemoveMesh(); } */ if (meshRef.Get().ref.trimmed().isEmpty()) LogDebug("Warning: Mesh \"" + this->parent_entity_->GetName().toStdString() + "\" mesh ref was set to an empty reference!"); meshAsset->HandleAssetRefChange(&meshRef); } else if (attribute == &meshMaterial) { if (!ViewEnabled()) return; // We won't request materials until we are sure that mesh has been loaded and it's safe to apply materials into it. // This logic shouldn't be necessary anymore. -jj. // if(!HasMaterialsChanged()) // return; AssetReferenceList materials = meshMaterial.Get(); // Reallocate the number of material asset reflisteners. while(materialAssets.size() > materials.Size()) materialAssets.pop_back(); while(materialAssets.size() < materials.Size()) materialAssets.push_back(boost::shared_ptr<AssetRefListener>(new AssetRefListener)); for(int i = 0; i < materials.Size(); ++i) { connect(materialAssets[i].get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnMaterialAssetLoaded(AssetPtr)), Qt::UniqueConnection); materialAssets[i]->HandleAssetRefChange(framework_->Asset(), materials[i].ref); } } else if((attribute == &skeletonRef) && (!skeletonRef.Get().ref.isEmpty())) { if (!ViewEnabled()) return; // If same name skeleton already set no point to do it again. // if (entity_ && entity_->getSkeleton() && entity_->getSkeleton()->getName() == skeletonRef.Get().ref/*skeletonId.Get()*/.toStdString()) // return; // AssetTransferPtr transfer = GetFramework()->Asset()->RequestAsset(skeletonRef.Get().ref); // if (transfer) // connect(transfer.get(), SIGNAL(Loaded(AssetPtr)), SLOT(OnSkeletonAssetLoaded(AssetPtr)), Qt::UniqueConnection); skeletonAsset->HandleAssetRefChange(&skeletonRef); } }