示例#1
0
void EC_WaterPlane::AttachEntity()
{
    if (attached_ || entity_ == 0)
        return;

    EC_Placeable* placeable = dynamic_cast<EC_Placeable* >(FindPlaceable().get());
    
    // If there exist placeable attach node and entity to it
    if (placeable != 0 )
    {
        Ogre::SceneNode* node = placeable->GetSceneNode();
        node->addChild(node_);
        node_->attachObject(entity_);
        node_->setVisible(true);
    }
    else
    {
        // There is no placeable attacht entity to OgreSceneRoot 
        Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager();
        node_->attachObject(entity_);
        sceneMgr->getRootSceneNode()->addChild(node_);
        node_->setVisible(true);
        attachedToRoot_ = true;
    }

    attached_ = true;
}
示例#2
0
void EC_WaterPlane::DetachEntity()
{
    if (!attached_ || entity_ == 0)
        return;

    EC_Placeable* placeable = dynamic_cast<EC_Placeable*>(FindPlaceable().get());
    if (placeable != 0 && !attachedToRoot_)
    {
        Ogre::SceneNode* node = placeable->GetSceneNode();
        node_->detachObject(entity_);
        node->removeChild(node_); 
    }
    else
    {
        // Attached to root.
        // Sanity check..
        if (entity_->isAttached() )
        {
            Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager();
            node_->detachObject(entity_);
            sceneMgr->getRootSceneNode()->removeChild(node_);
            attachedToRoot_ = false;
        }
    }

    attached_ = false;
}
示例#3
0
void EC_OgreCustomObject::DetachEntity()
{
    if ((placeable_) && (attached_) && (entity_))
    {
        EC_Placeable* placeable = checked_static_cast<EC_Placeable*>(placeable_.get());
        Ogre::SceneNode* node = placeable->GetSceneNode();
        node->detachObject(entity_);
        attached_ = false;
    }
}
示例#4
0
文件: EC_Mesh.cpp 项目: katik/naali
void EC_Mesh::DetachEntity()
{
    if ((!attached_) || (!entity_) || (!placeable_))
        return;
    
    EC_Placeable* placeable = checked_static_cast<EC_Placeable*>(placeable_.get());
    Ogre::SceneNode* node = placeable->GetSceneNode();
    adjustment_node_->detachObject(entity_);
    node->removeChild(adjustment_node_);
    attached_ = false;
}
示例#5
0
文件: EC_Mesh.cpp 项目: katik/naali
void EC_Mesh::AttachEntity()
{
    if ((attached_) || (!entity_) || (!placeable_))
        return;
    
    EC_Placeable* placeable = checked_static_cast<EC_Placeable*>(placeable_.get());
    Ogre::SceneNode* node = placeable->GetSceneNode();
    node->addChild(adjustment_node_);
    adjustment_node_->attachObject(entity_);

    // Honor the EC_Placeable's isVisible attribute by enforcing its values on this mesh.
    adjustment_node_->setVisible(placeable->visible.Get());

    attached_ = true;
}
示例#6
0
void EC_HoveringText::ShowMessage(const QString &text)
{
    if (!ViewEnabled())
        return;
    if (world_.expired())
        return;
    
    OgreWorldPtr world = world_.lock();
    Ogre::SceneManager *scene = world->OgreSceneManager();
    assert(scene);
    if (!scene)
        return;

    Entity* entity = ParentEntity();
    assert(entity);
    if (!entity)
        return;

    EC_Placeable *node = entity->GetComponent<EC_Placeable>().get();
    if (!node)
        return;

    Ogre::SceneNode *sceneNode = node->GetSceneNode();
    assert(sceneNode);
    if (!sceneNode)
        return;

    // Create billboard if it doesn't exist.
    if (!billboardSet_)
    {
        billboardSet_ = scene->createBillboardSet(world->GetUniqueObjectName("EC_HoveringText"), 1);
        assert(billboardSet_);
        billboardSet_->Ogre::MovableObject::setUserAny(Ogre::Any(static_cast<IComponent *>(this)));
        billboardSet_->Ogre::Renderable::setUserAny(Ogre::Any(static_cast<IComponent *>(this)));
        sceneNode->attachObject(billboardSet_);
    }

    if (billboardSet_ && !billboard_)
    {
        billboard_ = billboardSet_->createBillboard(Ogre::Vector3(0, 0, 0.7f));

        SetBillboardSize(width.Get(), height.Get());
        SetPosition(position.Get());
    }

    Redraw();
}
示例#7
0
文件: EC_Mesh.cpp 项目: A-K/naali
QVector3D EC_Mesh::GetWorldSize() const
{
    QVector3D size(0,0,0);
    if (!entity_ || !adjustment_node_ || !placeable_)
        return size;

    // Get mesh bounds and scale it to the scene node
    EC_Placeable* placeable = checked_static_cast<EC_Placeable*>(placeable_.get());
    Ogre::AxisAlignedBox bbox = entity_->getMesh()->getBounds();
    bbox.scale(adjustment_node_->getScale());

    // Get size and take placeable scale into consideration to get real naali inworld size
    const Ogre::Vector3& bbsize = bbox.getSize();
    const Vector3df &placeable_scale = placeable->GetScale();
    // Swap y and z to make it align with other naali vectors
    size = QVector3D(bbsize.x*placeable_scale.x, bbsize.z*placeable_scale.z, bbsize.y*placeable_scale.y);
    return size;
}
示例#8
0
文件: EC_Mesh.cpp 项目: Ilikia/naali
QVector3D EC_Mesh::GetWorldSize() const
{
    QVector3D size(0,0,0);
    if (!entity_ || !adjustment_node_ || !placeable_)
        return size;

    // Get mesh bounds and scale it to the scene node
    EC_Placeable* placeable = checked_static_cast<EC_Placeable*>(placeable_.get());
    Ogre::AxisAlignedBox bbox = entity_->getMesh()->getBounds();
    ///\bug Rewrite this code to properly take the world transform into account. -jj.
    bbox.scale(adjustment_node_->getScale());

    // Get size and take placeable scale into consideration to get real in-world size
    const Ogre::Vector3& bbsize = bbox.getSize();
    const float3 &placeable_scale = placeable->WorldScale();
    // Swap y and z to make it align with other vectors
    size = QVector3D(bbsize.x*placeable_scale.x, bbsize.y*placeable_scale.y, bbsize.z*placeable_scale.z);
    return size;
}
示例#9
0
void EC_WaterPlane::ComponentAdded(IComponent* component, AttributeChange::Type type)
{
    if (component->TypeName() == EC_Placeable::TypeNameStatic())
    {
        DetachEntity();

        EC_Placeable* placeable = static_cast<EC_Placeable* >(component);
        if (placeable == 0)
            return;
        if (entity_ == 0)
            return;

        Ogre::SceneNode* node = placeable->GetSceneNode();
        
        node->addChild(node_);
        node_->attachObject(entity_);
        node_->setVisible(true);

        attached_ = true;
    }
}
示例#10
0
文件: EC_Ruler.cpp 项目: A-K/naali
void EC_Ruler::Create()
{
    if (renderer_.expired())
        return;

    Ogre::SceneManager *scene_mgr= renderer_.lock()->GetSceneManager();
    assert(scene_mgr);
    if (!scene_mgr)
        return;

    Scene::Entity *entity = GetParentEntity();
    assert(entity);
    if (!entity)
        return;

    EC_Placeable *placeable = entity->GetComponent<EC_Placeable>().get();
    assert(placeable);
    if (!placeable)
        return;
    sceneNode_ = placeable->GetSceneNode();

    assert(sceneNode_);
    if (!sceneNode_)
        return;
    
    if(scene_mgr->hasManualObject(rulerName)){
        rulerObject = scene_mgr->getManualObject(rulerName);
        if(rulerObject->isAttached())
#if OGRE_VERSION_MINOR <= 6 && OGRE_VERSION_MAJOR <= 1
            rulerObject->detatchFromParent();
#else
            rulerObject->detachFromParent();
#endif
    } else {
        rulerObject = scene_mgr->createManualObject(rulerName);
    }
    if(scene_mgr->hasManualObject(rulerMovingPartName)){
        gridObject = scene_mgr->getManualObject(rulerMovingPartName);
        if(gridObject->isAttached())
#if OGRE_VERSION_MINOR <= 6 && OGRE_VERSION_MAJOR <= 1
            gridObject->detatchFromParent();
#else
            gridObject->detachFromParent();
#endif
    } else {
        gridObject = scene_mgr->createManualObject(rulerMovingPartName);
    }
    
    switch(typeAttr_.Get()) {
        case EC_Ruler::Rotation:
            SetupRotationRuler();
            break;
        case EC_Ruler::Translation:
            SetupTranslateRuler();
            break;
        case EC_Ruler::Scale:
            SetupScaleRuler();
            break;
    }

    if(localAttr_.Get()) {
        sceneNode_->attachObject(rulerObject);
    } else {
        // get translateNode only when we are working in world space
        if(scene_mgr->hasSceneNode(nodeName)) {
            globalSceneNode = scene_mgr->getSceneNode(nodeName);
        } else {
            globalSceneNode = scene_mgr->getRootSceneNode()->createChildSceneNode(nodeName);
            globalSceneNode->setVisible(true);
        }
        assert(globalSceneNode);
        if(!globalSceneNode)
            return;
            
        if(scene_mgr->hasSceneNode(movingNodeName)) {
            anchorNode = scene_mgr->getSceneNode(movingNodeName);
        } else {
            anchorNode = scene_mgr->getRootSceneNode()->createChildSceneNode(movingNodeName);
            anchorNode->setVisible(true);
        }
        assert(anchorNode);
        if(!anchorNode)
            return;
        
        anchorNode->setPosition(0,0,0);
        anchorNode->attachObject(gridObject);
    
        globalSceneNode->setPosition(sceneNode_->getParent()->getPosition());
        globalSceneNode->attachObject(rulerObject);
    }
}
示例#11
0
void EC_ChatBubble::Update()
{
    if (renderer_.expired())
        return;

    Ogre::SceneManager *scene = renderer_.lock()->GetSceneManager();
    assert(scene);
    if (!scene)
        return;

    Scene::Entity *entity = GetParentEntity();
//    assert(entity);
    if (!entity)
        return;

    EC_Placeable *node = entity->GetComponent<EC_Placeable>().get();
    if (!node)
        return;

    Ogre::SceneNode *sceneNode = node->GetSceneNode();
    assert(sceneNode);
    if (!sceneNode)
        return;

    // Create billboard if it doesn't exist.
    if (!billboardSet_ && !billboard_)
    {
        // Create billboardset and billboard
        billboardSet_ = scene->createBillboardSet(renderer_.lock()->GetUniqueObjectName("EC_ChatBubble"), 1);
        assert(billboardSet_);

        billboard_ = billboardSet_->createBillboard(Ogre::Vector3(0, 0, default_z_pos_));
        assert(billboard_);

        billboardSet_->setDefaultDimensions(2, 1);
        sceneNode->attachObject(billboardSet_);

        // Create material
        materialName_ = renderer_.lock()->GetUniqueObjectName("EC_ChatBubble_Material"); 
        Ogre::MaterialPtr material = OgreRenderer::CloneMaterial("UnlitTexturedSoftAlpha", materialName_);
        billboardSet_->setMaterialName(materialName_);

        // Create texture
        texture_name_ = renderer_.lock()->GetUniqueObjectName("EC_ChatBubble_Texture");
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(
            texture_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D, 1, 1, 0, Ogre::PF_A8R8G8B8, 
            Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

        // Set texture to material
        if (texture.isNull())
            texture_name_ = "";
        else
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
    }
    else
    {
        // Billboard already exists, remove it from the old and attach it to a new scene node.
        LogInfo("Trying to detach chat bubble billboard from its old node and attach to a new node. This feature is not tested.");
        Ogre::SceneNode *oldNode = billboardSet_->getParentSceneNode();
        oldNode->detachObject(billboardSet_);
        sceneNode->attachObject(billboardSet_);
    }
}
示例#12
0
void EC_Highlight::Create()
{
    if (renderer_.expired())
        return;

    Ogre::SceneManager *scene = renderer_.lock()->GetSceneManager();
    assert(scene);
    if (!scene)
        return;

    Scene::Entity *entity = GetParentEntity();
    assert(entity);
    if (!entity)
        return;

    EC_Placeable *placeable = entity->GetComponent<EC_Placeable>().get();
    assert(placeable);
    if (!placeable)
        return;

    // Check out if this entity has EC_Mesh or EC_OgreCustomObject.
    Ogre::Entity *originalEntity  = 0;
    if (entity->GetComponent(EC_Mesh::TypeNameStatic()))
    {
        EC_Mesh *ec_mesh= entity->GetComponent<EC_Mesh>().get();
        assert(ec_mesh);

        originalEntity = ec_mesh->GetEntity();
        sceneNode_ = ec_mesh->GetAdjustmentSceneNode();
    }
    else if(entity->GetComponent(EC_OgreCustomObject::TypeNameStatic()))
    {
        EC_OgreCustomObject *ec_custom = entity->GetComponent<EC_OgreCustomObject>().get();
        assert(ec_custom);
        if (!ec_custom->IsCommitted())
        {
            LogError("Mesh entity have not been created for the target primitive. Cannot create EC_Highlight.");
            return;
        }

        originalEntity = ec_custom->GetEntity();
        sceneNode_ = placeable->GetSceneNode();
    }
    else
    {
        LogError("This entity doesn't have either EC_Mesh or EC_OgreCustomObject present. Cannot create EC_Highlight.");
        return;
    }

    if (!originalEntity)
        return; 

    assert(sceneNode_);
    if (!sceneNode_)
        return;

    // Clone the Ogre entity.
    cloneName_ = renderer_.lock()->GetUniqueObjectName("EC_Highlight_entity");
    entityClone_ = originalEntity->clone(cloneName_);

    //This is set so we can exclude the hightlight mesh from a viewport, if so wanted
    entityClone_->setVisibilityFlags(0x1);
    assert(entityClone_);

    // Disable casting of shadows for the clone.
    entityClone_->setCastShadows(false);

    ///\todo If original entity has skeleton, (try to) link it to the clone.
/*
    if (originalEntity->hasSkeleton())
    {
        Ogre::SkeletonInstance *skel = originalEntity->getSkeleton();
        // If sharing a skeleton, force the attachment mesh to use the same skeleton
        // This is theoretically quite a scary operation, for there is possibility for things to go wrong
        Ogre::SkeletonPtr entity_skel = originalEntity->getMesh()->getSkeleton();
        if (entity_skel.isNull())
        {
            LogError("Cannot share skeleton for attachment, not found");
        }
        else
        {
            try
            {
                entityClone_->getMesh()->_notifySkeleton(entity_skel);
            }
            catch (Ogre::Exception &e)
            {
                LogError("Could not set shared skeleton for attachment: " + std::string(e.what()));
            }
        }
    }
*/

    std::string newMatName = renderer_.lock()->GetUniqueObjectName("EC_Highlight_mat");
    try
    {
        Ogre::MaterialPtr highlightMaterial = OgreRenderer::CloneMaterial("Highlight", newMatName);
        entityClone_->setMaterialName(newMatName);
    }
    catch (Ogre::Exception &e)
    {
        LogError("Could not set material \"" + newMatName + "\": " + std::string(e.what()));
        return;
    }

    sceneNode_->attachObject(entityClone_);
}