Exemplo n.º 1
0
void Navigation::AddOrRemoveObject()
{
    // Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
    Vector3 hitPos;
    Drawable* hitDrawable;
    
    if (Raycast(250.0f, hitPos, hitDrawable))
    {
        // The part of the navigation mesh we must update, which is the world bounding box of the associated
        // drawable component
        BoundingBox updateBox;
        
        Node* hitNode = hitDrawable->GetNode();
        if (hitNode->GetName() == "Mushroom")
        {
            updateBox = hitDrawable->GetWorldBoundingBox();
            hitNode->Remove();
        }
        else
        {
            Node* newNode = CreateMushroom(hitPos);
            updateBox = newNode->GetComponent<StaticModel>()->GetWorldBoundingBox();
        }
        
        // Rebuild part of the navigation mesh, then recalculate path if applicable
        scene_->GetComponent<NavigationMesh>()->Build(updateBox);
        RecalculatePath();
    }
}
Exemplo n.º 2
0
void Decals::PaintDecal()
{
    Vector3 hitPos;
    Drawable* hitDrawable;

    if (Raycast(250.0f, hitPos, hitDrawable))
    {
        // Check if target scene node already has a DecalSet component. If not, create now
        Node* targetNode = hitDrawable->GetNode();
        DecalSet* decal = targetNode->GetComponent<DecalSet>();
        if (!decal)
        {
            ResourceCache* cache = GetSubsystem<ResourceCache>();

            decal = targetNode->CreateComponent<DecalSet>();
            decal->SetMaterial(cache->GetResource<Material>("Materials/UrhoDecal.xml"));
        }
        // Add a square decal to the decal set using the geometry of the drawable that was hit, orient it to face the camera,
        // use full texture UV's (0,0) to (1,1). Note that if we create several decals to a large object (such as the ground
        // plane) over a large area using just one DecalSet component, the decals will all be culled as one unit. If that is
        // undesirable, it may be necessary to create more than one DecalSet based on the distance
        decal->AddDecal(hitDrawable, hitPos, cameraNode_->GetRotation(), 0.5f, 1.0f, 1.0f, Vector2::ZERO,
            Vector2::ONE);
    }
}
void Urho3DTemplate::AddOrRemoveObject()
{
    //Raycast and check if we hit a mushroom node. If yes, remove it, if no create a new one
    Vector3 hitPos;
    Drawable* hitDrawable;

    if (RayCast(250.0f, hitPos, hitDrawable))
    {
        Node* hitNode = hitDrawable->GetNode();
        if (hitNode->GetName() == "Mushroom")
        {
            hitNode->Remove();
        }
        else
        {
            CreateMushroom(hitPos);
        }
    }
}
void ObjectPositionEditor::OnMouseLeftDown(float x,float y,unsigned int buttons)
{
	EditorRoot* pEditorRoot = EditorRoot::Instance();
	Editor3dGizmo* pGizmo = pEditorRoot->GetGizmo();

	//判断点击的内容,如果是物件判断有没有按住Ctrl多重选择
	IntVector2 pos(x,y);
	vector<SceneHitResult> result = SceneHelper::Instance()->QueryCurrentMousePosObjects(250.0,&pos);

	//判断是否是坐标轴
	if(is_axis_object(result) == true)
	{
		Graphics* graphics = GetSubsystem<Graphics>();
		Camera* camera = pEditorRoot->cameraNode_->GetComponent<Camera>();

		Ray cameraWorldRay = camera->GetScreenRay(x / graphics->GetWidth(),y / graphics->GetHeight());

		//判断并记录哪些坐标轴被选中了
		bool bXSelect;
		bool bYSelect;
		bool bZSelect;
		pGizmo->QuerySelectedStateByWorldRay(cameraWorldRay,bXSelect,bYSelect,bZSelect);
		pGizmo->gizmoAxisX->selected = bXSelect;
		pGizmo->gizmoAxisY->selected = bYSelect;
		pGizmo->gizmoAxisZ->selected = bZSelect;

		if(pGizmo->IsSelected())
		{
			pGizmo->BeginDrag();
		}

		//判断Ctrl有没有按下
		pGizmo->update_model();
	}
	else
	{
		Drawable* selObject = get_edit_object(result);
		if(selObject == NULL)
		{
			if(pEditorRoot->IsCtrlPressed() == false)
			{
				pEditorRoot->CancelAllSelection();
			}

			pEditorRoot->RectSelectionFrame_->Begin(x,y);

			isRectSelectionMode = true;
			rectSelectionStart.x_ = x;
			rectSelectionStart.y_ = y;
		}
		else
		{
			//选中的节点(后面要根据是否按住Ctrl来判断增加还是去除)
			Node* pSelNode = selObject->GetNode();
			pEditorRoot->OnNodeSelect(pSelNode);

			//
			pGizmo->gizmoAxisX->selected = true;
			pGizmo->gizmoAxisY->selected = true;
			pGizmo->gizmoAxisZ->selected = true;

			pGizmo->BeginDrag();
			pGizmo->update_model();
		}
	}
}
//1.框选模式 还是单选
//2.单选还是移动
void ObjectPositionEditor::OnMouseMove(float x,float y,unsigned int buttons)
{
	EditorRoot* pEditorRoot = EditorRoot::Instance();
	//显示名字UI
	char szName[256];

	//矩形框选模式
	if(isRectSelectionMode == true)
	{
		pEditorRoot->RectSelectionFrame_->UpdateShow(x,y);

		//遍历场景找到属于框内的对象
		pEditorRoot->RectSelectionNodes = SceneHelper::Instance()->QueryScreenRectNodes(pEditorRoot->RectSelectionFrame_->vecStart,pEditorRoot->RectSelectionFrame_->vecEnd);

		sprintf(szName,"Selected:%d",pEditorRoot->RectSelectionNodes.size());
		pEditorRoot->ObjectNameTip_->SetText(szName);
		pEditorRoot->ObjectNameTip_->UpdateShow(x,y);
	}
	else	//单选或者移动
	{
		Editor3dGizmo* pGizmo = pEditorRoot->GetGizmo();
		pEditorRoot->ObjectNameTip_->Hide();

		IntVector2 pos(x,y);
		vector<SceneHitResult> result = SceneHelper::Instance()->QueryCurrentMousePosObjects(250.0,&pos);

		Node* pHoverNode = NULL;
		Drawable* selObject = get_edit_object(result);
		if(selObject != NULL)
		{
			pHoverNode = selObject->GetNode();
		}

		//更新鼠标射线相对于坐标轴的情况(是否拖动都需要)
		Graphics* graphics = GetSubsystem<Graphics>();
		Camera* camera = pEditorRoot->cameraNode_->GetComponent<Camera>();

		Ray cameraWorldRay = camera->GetScreenRay(x / graphics->GetWidth(),y / graphics->GetHeight());

		//判断并记录哪些坐标轴被选中了
		bool bXHover;
		bool bYHover;
		bool bZHover;
		pGizmo->QuerySelectedStateByWorldRay(cameraWorldRay,bXHover,bYHover,bZHover);
		if(pGizmo->IsDrag == true)
		{
			pGizmo->UpdateMovePosition();
		}
		else
		{
			//当前落在坐标轴上
			if(is_axis_object(result) == true)
			{
				pGizmo->gizmoAxisX->hovered = bXHover;
				pGizmo->gizmoAxisY->hovered = bYHover;
				pGizmo->gizmoAxisZ->hovered = bZHover;
				pGizmo->update_model();

				if(bXHover || bYHover || bZHover)
				{
					EditorRoot::Instance()->GetMainWindow()->setCursor(Qt::SizeAllCursor);
				}
				else
				{
					EditorRoot::Instance()->GetMainWindow()->setCursor(Qt::ArrowCursor);
				}
			}
			else
			{
				//判断是否是选择的物体
				if(selObject == NULL)
				{
					//非当前可编辑的对象,直接退出
					EditorRoot::Instance()->GetMainWindow()->setCursor(Qt::ArrowCursor);
					return;
				}

				sprintf(szName,"%s - %s",result[0].object->GetTypeName().CString(),result[0].object->GetNode()->GetName().CString());
				pEditorRoot->ObjectNameTip_->SetText(szName);
				pEditorRoot->ObjectNameTip_->UpdateShow(x,y);

				//当前悬浮的是选择的
				bool isHoverInSel = pEditorRoot->IsNodeInSelections(selObject->GetNode());

				//仅当在非当前选择的节点上时才显示+
				if(isHoverInSel == false)
				{
					EditorRoot::Instance()->GetMainWindow()->setCursor(Qt::CrossCursor);
				}

				if(isHoverInSel == false && selObject == NULL)
				{
					EditorRoot::Instance()->GetMainWindow()->setCursor(Qt::ArrowCursor);
				}
			}
		}
	}
}