コード例 #1
0
ファイル: EC_VideoView.cpp プロジェクト: Ilikia/naali
void EC_VideoSource::UpdateSignals()
{
    if (!GetParentEntity())
    {
        LogError("Couldn't update singals cause component dont have parent entity set.");
        return;
    }
    Scene::SceneManager *scene = GetParentEntity()->GetScene();
    if(!scene)
    {
        LogError("Fail to update signals cause parent entity's scene is null.");
        return;
    }

    // hack hack: seems phonon is more unstable to if we login to a world and instantiate many
    // players ~at the same time, so here we do a random timer to instantiate the objects so the QThreads are not
    // started ~at the same time and we minimize risk or crashing. Yes i know its stupid, blame phonon!
    int rand_time = qrand();
    while(rand_time > 3000)
        rand_time /= 2;
        if (rand_time < 500)
            rand_time = 500;
 
    // The magic number of instances before certain unstability is two, 
    // lets not let instantiate more phonon players than that for now
    Scene::EntityList list = GetFramework()->Scene()->GetDefaultScene()->GetEntitiesWithComponent(TypeNameStatic());
    if (list.size() < 2)
    {
        LogDebug(QString("Launching video ec in %1 ms").arg(rand_time).toStdString());
        QTimer::singleShot(rand_time, this, SLOT(InitializePhonon()));
    }
    else
    {
        LogDebug("Will not instantiate Phonon objects, world already has 2 EC_VideoSources. Limit hit.");
        canvas_ = Get3DCanvas();
        if (!canvas_)
        {
            LogError("Could not get 3D Canvas component");
            return;
        }

        // Tell in the 3D scene that the video cannot be displayed as two videos are already instantiated
        error_label_ = new QLabel("Maximum of inworld videos already in use");
        error_label_->setFont(QFont("Arial", 14));
        error_label_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        error_label_->setAlignment(Qt::AlignCenter);
        QSize size = error_label_->size();
        size.setHeight(size.height()+10);
        size.setWidth(size.width()+10);
        error_label_->resize(size);
  
        canvas_->SetWidget(error_label_);
        canvas_->SetRefreshRate(0);
        canvas_->SetSubmesh(0);
        QTimer::singleShot(100, canvas_, SLOT(Update()));
    }

    RegisterActions();
}
コード例 #2
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : iInterpolator - 
// Output : IPositionInterpolator
//-----------------------------------------------------------------------------
IPositionInterpolator* CMapKeyFrame::SetupPositionInterpolator( int iInterpolator )
{
	if( iInterpolator != m_iPositionInterpolator )
	{
		if( m_pPositionInterpolator )
			m_pPositionInterpolator->Release();

		m_pPositionInterpolator = Motion_GetPositionInterpolator( iInterpolator );
		m_iPositionInterpolator = iInterpolator;

		// Feed keys..
		CMapEntity *pEnt = GetParentEntity();
		if( pEnt )
		{
			for ( int i=pEnt->GetFirstKeyValue(); i != pEnt->GetInvalidKeyValue(); i=pEnt->GetNextKeyValue( i ) )
			{
				m_pPositionInterpolator->ProcessKey( 
					pEnt->GetKey( i ),
					pEnt->GetKeyValue( i ) );
			}
		}
	}


	return m_pPositionInterpolator;
}
コード例 #3
0
//-----------------------------------------------------------------------------
// Purpose: Called when an object that we depend on has changed.
//-----------------------------------------------------------------------------
void CMapKeyFrame::OnNotifyDependent(CMapClass *pObject, Notify_Dependent_t eNotifyType)
{
	CMapClass::OnNotifyDependent(pObject, eNotifyType);

	if ((pObject == m_pAnimator) && (eNotifyType == Notify_Removed))
	{
		SetAnimator(NULL);
	}

	//
	// If our next keyframe was deleted, try to link to the one after it.
	//
	if ((pObject == m_pNextKeyFrame) && (eNotifyType == Notify_Removed))
	{
		CMapEntity *pNextParent = m_pNextKeyFrame->GetParentEntity();
		CMapEntity *pParent = GetParentEntity();

		if ( pNextParent && pParent )
		{
			const char *szNext = pNextParent->GetKeyValue("NextKey");
			pParent->SetKeyValue("NextKey", szNext);
		}
	}

	m_bRebuildPath = true;
}
コード例 #4
0
ファイル: EC_ChatBubble.cpp プロジェクト: caocao/naali
void EC_ChatBubble::ShowMessage(const QString &msg)
{
    if (renderer_.expired())
        return;

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

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

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

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

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

        std::string newName = std::string("material") + renderer_.lock()->GetUniqueObjectName(); 
        Ogre::MaterialPtr material = OgreRenderer::CloneMaterial("UnlitTexturedSoftAlpha", newName);
        billboardSet_->setMaterialName(newName);

        billboard_ = billboardSet_->createBillboard(Ogre::Vector3(0, 0, 1.5f));
        assert(billboard_);
        billboard_->setDimensions(2, 1);

        sceneNode->attachObject(billboardSet_);
    }

    if (msg.isNull() || msg.isEmpty())
        return;

    messages_.push_back(msg);

    // Set timer for removing the message
    int timeToShow = 0;
    const int minTime = 4000;
    if (msg.length() * 400 < minTime)
        timeToShow = minTime;
    else
        timeToShow = msg.length() * 400;

    QTimer::singleShot(timeToShow, this, SLOT(RemoveLastMessage()));

    Refresh();
}
コード例 #5
0
ファイル: EC_VideoView.cpp プロジェクト: Ilikia/naali
EC_3DCanvas *EC_VideoSource::Get3DCanvas()
{
    EC_3DCanvas *canvas = 0;
    Scene::Entity* entity = GetParentEntity();
    if (entity)
        canvas = dynamic_cast<EC_3DCanvas*>(entity->GetOrCreateComponent(EC_3DCanvas::TypeNameStatic()).get());
    else
        LogError("Could not get parent entity");
    return canvas;
}
コード例 #6
0
ファイル: EC_VideoView.cpp プロジェクト: Ilikia/naali
void EC_VideoSource::RegisterActions()
{
    Scene::Entity *entity = GetParentEntity();
    assert(entity);
    if (entity)
    {
        entity->ConnectAction("Play", this, SLOT(Play()));
        entity->ConnectAction("Stop", this, SLOT(Stop()));
        entity->ConnectAction("Pause", this, SLOT(Pause()));
    }
}
コード例 #7
0
void DebugEmitterComponent::Render(const UpdateContext& updateContext)
{
	if (!_model)
		return;

	auto parent = GetParentEntity();
	vec3f center = GetModelCenter();
	vec3f desiredPos = parent->GetPosition();
	vec3f desiredScale = parent->GetScale();
	mat4f desiredPose = parent->GetPose();

	enableZTest();
	changeZTest(GL_LEQUAL);

	mat4f ident, NT, T, S, R, x, y, z;
	ident.loadIdentity();
	_matrixStack.PushMatrix(ident);
	//NT.loadTranslation(-center.x, -center.y, -center.z);
	T.loadTranslation(desiredPos.x, desiredPos.y, desiredPos.z);
	S.loadScale(desiredScale.x, desiredScale.y, desiredScale.z);
	R = desiredPose;
	R.m[12] = 0.0f;
	R.m[13] = 0.0f;
	R.m[14] = 0.0f;
	R.m[15] = 1.0f;

	_matrixStack.MultiplyMatrix(T);
	_matrixStack.MultiplyMatrix(S);
	_matrixStack.MultiplyMatrix(R);
	//_matrixStack.MultiplyMatrix(NT);
	//	_matrixStack.MultiplyMatrix(parent->GetTransform());

	/*vec3f rot = parent->GetDirection();
	mat4f xRot, yRot, zRot;

	xRot.loadXRotation(rot.x);
	yRot.loadYRotation(rot.y);
	zRot.loadZRotation(rot.z);

	xRot *= yRot;
	xRot *= zRot;
	_matrixStack.MultiplyMatrix(xRot);*/

	mat4f MV;
	MV = getMatrix(MATRIX_MODEL);
	_RenderNode(_model->RootNode, updateContext);
	_matrixStack.PopMatrix();
	setMatrix(MATRIX_MODEL, MV);
}
コード例 #8
0
ファイル: EC_Touchable.cpp プロジェクト: A-K/naali
void EC_Touchable::RegisterActions()
{
    Scene::Entity *entity = GetParentEntity();
    assert(entity);
    if (entity)
    {
        // Generic actions
        entity->ConnectAction("Show", this, SLOT(Show()));
        entity->ConnectAction("Hide", this, SLOT(Hide()));
        // Mouse actions
        entity->ConnectAction("MouseHover", this, SLOT(OnHover()));
        entity->ConnectAction("MouseHoverIn", this, SLOT(OnHoverIn()));
        entity->ConnectAction("MouseHoverOut", this, SLOT(OnHoverOut()));
        entity->ConnectAction("MousePress", this, SLOT(OnClick()));
    }
}
コード例 #9
0
ファイル: EC_Clone.cpp プロジェクト: caocao/naali
void EC_Clone::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;

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

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

        originalEntity = ec_mesh->GetEntity();
        sceneNode_ = ec_mesh->GetAdjustmentSceneNode();
    }
    else if(entity->GetComponent(OgreRenderer::EC_OgreCustomObject::NameStatic()))
    {
        OgreRenderer::EC_OgreCustomObject *ec_custom = entity->GetComponent<OgreRenderer::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_OgreMesh or EC_OgreCustomObject present. Cannot create EC_Highlight.");
        return;
    }

    assert(originalEntity);
    if (!originalEntity)
        return;

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

    // Clone the Ogre entity.
    cloneName_ = std::string("entity") + renderer_.lock()->GetUniqueObjectName();
    entityClone_ = originalEntity->clone(cloneName_);
    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 = std::string("HighlightMaterial") + renderer_.lock()->GetUniqueObjectName();
    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_);
}
コード例 #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
ファイル: EC_ChatBubble.cpp プロジェクト: A-K/naali
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
ファイル: EC_VideoView.cpp プロジェクト: Ilikia/naali
void EC_VideoSource::UpdateCanvas()
{
    if (!video_widget_ || !media_object_)
        return;

    Scene::Entity* entity = GetParentEntity();
    if (!entity)
    {
        LogError("No parent entity, cannot create/update 3DCanvas");
        return;
    }

    // If entity has no valid mesh or prim yet, start a retry timer and try to set the canvas later
    if ((!entity->GetComponent(EC_Mesh::TypeNameStatic())) && 
        (!entity->GetComponent(EC_OgreCustomObject::TypeNameStatic())))
    {
        LogDebug("Mesh or prim did not exist yet, retrying");
        QTimer::singleShot(500, this, SLOT(UpdateCanvas()));
        return;
    }

    canvas_ = Get3DCanvas();
    if (!canvas_)
    {
        LogError("Could not get 3D Canvas component");
        return;
    }

    // Update widget
    if (canvas_->GetWidget() != player_)
    {
        canvas_->SetWidget(player_);
        LogDebug("Widget set");
    }

    // Update submesh
    int submesh = getsubmeshIndex();
    if (submesh < 0)
        submesh = 0;
    if (!canvas_->GetSubMeshes().contains(submesh))
    {
        canvas_->SetSubmesh(submesh);
        LogDebug("Submesh set");
    }

    // Update refresh rate
    if (getrefreshRate() > 0)
    {
        int ref_rate_msec = 1000 / getrefreshRate();
        if (canvas_->GetRefreshRate() != ref_rate_msec)
        {
            canvas_->SetRefreshRate(getrefreshRate());
            LogDebug("Refresh rate set");
        }
    }
    else
        canvas_->SetRefreshRate(0);

    // Scale down widget
    if (getscaleDown() && player_)
    {
        if (original_size_.isNull())
        {
            original_size_ = player_->size();
            if (original_size_.width() < 1 && original_size_.height() < 1)
                original_size_ = QSize(0,0);
            else
                qDebug() << "Original size set: " << original_size_;
        }

        if (!original_size_.isNull())
        {
            QSize scale_down_size(320, 240);
            if (player_->size().width() > scale_down_size.width() && player_->size().height() > scale_down_size.height())
            {
                //player_->resize(scale_down_size);
                //LogDebug("Scaled video widget down to 320x240 for performance");
            }
        }
    }

    if (start_canvas_)
    {
        canvas_->Start();
        start_canvas_ = false;
        playing_canvas_ = true;
        LogDebug("Started rendering updates");

        if (ready_poller_->isActive())
            ready_poller_->stop();
    }

    if (stop_canvas_)
    {
        canvas_->Stop();
        start_canvas_ = false;
        stop_canvas_ = false;
        playing_canvas_ = false;
        LogDebug("Stoppend rendering updates");
    }
}