void ActorSceneCanvas::OnDestroy(wxWindowDestroyEvent& e) { if (GetSceneManipulator()) { GetSceneManipulator()->getRenderWindow()->setActive(false); } }
bool ActorSceneCanvas::doUpdate(bool isIdle) { if (m_lTargetFPS) { unsigned long thisTime = Ogre::Root::getSingleton().getTimer()->getMilliseconds(); if ((thisTime - m_lLastTime) * m_lTargetFPS < 1000) { if (!isIdle) { if (GetSceneManipulator()) { GetSceneManipulator()->updateWindow(); } } return false; } else if (isIdle) { return false; } } if (GetSceneManipulator()) { GetSceneManipulator()->renderOneFrame(); if( Fairy::CDataManipulator::GetDataManipulator()) { Fairy::CDataManipulator::GetDataManipulator()->updateAnimationInfo(); } } return true; }
void ActorSceneCanvas::OnMouseLeave(wxMouseEvent& e) { if (!GetSceneManipulator()) return; // GetSceneManipulator()->showHitPoint(false); GetSceneManipulator()->setActiveAction(NULL); }
void ActorSceneCanvas::OnSize(wxSizeEvent &e) { if (GetSceneManipulator()) { wxSize size = e.GetSize(); GetSceneManipulator()->resizeWindow(size.x, size.y); } }
void ActorSceneCanvas::OnTimer(wxTimerEvent& event) { if (GetSceneManipulator()) { GetSceneManipulator()->renderOneFrame(); } }
void ActorSceneCanvas::OnEraseBackground(wxEraseEvent &e) { if (!GetSceneManipulator()) { wxWindow::OnEraseBackground(e); } }
void ActorSceneCanvas::OnMouseEnter(wxMouseEvent& e) { if (!GetSceneManipulator()) return; // / GetSceneManipulator()->showHitPoint(true); }
void ActorSceneCanvas::OnLeftDown(wxMouseEvent& e) { SetFocus(); mDragStarted = true; mDragOrigin = Ogre::Vector2(e.GetX(),e.GetY()); mDragDelta = Ogre::Vector2(0.0f,0.0f); if (!GetSceneManipulator()) return; if (HasCapture()) return; wxASSERT(!m_pCameraManip); wxASSERT(mDragButton == wxMOUSE_BTN_NONE); if (!GetActiveAction()) return; //GetSceneManipulator()->setActiveAction("ManipObjectAction"); //GetActiveAction()->setParameter("%CurrentMode", ""); m_pUpdateListener->enable(); mDragButton = e.GetButton(); GetActiveAction()->onBegin(e.GetX(), e.GetY()); CaptureMouse(); }
void ActorAnimationSettingEditor::SetTargetObject(Ogre::String& name) { if(mTargetObject) { GetSceneManipulator()->deselectObject(mTargetObject); mTargetObject.reset(); } mParameters["actor name"] = name; mTargetObject = Fairy::ObjectFactoryManager::getSingleton().createInstance("Actor"); mTargetObject->setPropertyList(mParameters); mTargetObject->createRenderInstance(GetSceneManipulator()); Ogre::Vector3 position = Ogre::Vector3(0,0,500); mTargetObject->setProperty("position", position); Fairy::ActorObject* pTargetObject = dynamic_cast<Fairy::ActorObject*>(mTargetObject.get()); mTargetDObject = pTargetObject->getActor()->getImpl(); }
void BrushSelector::setBrushByTexName(const Ogre::String& textureName) { Ogre::String brushName = GetSceneManipulator()->getTerrainPaintInfoContainer()->findBrushNameByTexName(textureName); CatalogMap::iterator it = mCatalogMap.find(brushName); if (it != mCatalogMap.end()) { mBrushesTree->SelectItem(it->second); } }
void ActorSceneCanvas::OnMiddleDown(wxMouseEvent& e) { SetFocus(); if (!GetSceneManipulator()) return; if (HasCapture()) return; wxASSERT(!m_pCameraManip); wxASSERT(mDragButton == wxMOUSE_BTN_NONE); if (!e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // (None) m_pCameraManip = GetSceneManipulator()->getManip("CameraDragMove"); } else if (!e.ControlDown() && !e.AltDown() && e.ShiftDown() && !e.MetaDown()) { // Shift m_pCameraManip = GetSceneManipulator()->getManip("CameraDragRotate"); } else if (e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // Ctrl m_pCameraManip = GetSceneManipulator()->getManip("CameraPan"); } else if (!e.ControlDown() && e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // Alt m_pCameraManip = GetSceneManipulator()->getManip("CameraRotate"); } if (m_pCameraManip) { mDragButton = e.GetButton(); m_pCameraManip->onBegin(e.GetX(), e.GetY()); CaptureMouse(); } }
//消息函数处理 void ActorSceneCanvas::OnPaint(wxPaintEvent &e) { wxPaintDC dc(this); PrepareDC(dc); if (GetSceneManipulator()) { doUpdate(); } }
void ActorSceneCanvas::OnMouseWheel(wxMouseEvent& e) { if (!GetSceneManipulator()) return; if (HasCapture()) return; Ogre::Real distance = - GetSceneManipulator()->_getWheelSpeed() * e.GetWheelRotation() / e.GetWheelDelta(); GetSceneManipulator()->getCamera()->moveRelative(Ogre::Vector3(0, 0, distance)); GetSceneManipulator()->_fireCameraPosChanged(); wxPoint pt = ScreenToClient(wxPoint(e.GetX(), e.GetY())); if (GetActiveAction()) { GetActiveAction()->onMotion(pt.x, pt.y); } else { //GetSceneManipulator()->getHitIndicator("IntersectPoint")->setHitPoint(pt.x, pt.y); } }
void ActorSceneCanvas::OnMiddleUp(wxMouseEvent& e) { if (!GetSceneManipulator()) return; if (!HasCapture()) return; if (mDragButton == wxMOUSE_BTN_NONE || !e.Button(mDragButton)) return; wxASSERT(m_pCameraManip); m_pCameraManip->onEnd(e.GetX(), e.GetY(), false); m_pCameraManip = NULL; mDragButton = wxMOUSE_BTN_NONE; ReleaseCapture(); }
// // // 把场景坐标转换成游戏逻辑坐标。 // void FairyEditorFrame::TranslateSceneToGameLogic(float &x, float &y, float &z, Ogre::Matrix4& TransformMatrix) { Ogre::Vector3 pos; pos.x = x; pos.y = y; pos.z = z; pos = TransformMatrix * pos; if(GetSceneManipulator()) { pos.x = (pos.x - GetSceneManipulator()->getTerrainData()->mPosition.x) / GetSceneManipulator()->getTerrainData()->mScale.x; pos.y = (pos.y - GetSceneManipulator()->getTerrainData()->mPosition.y) / GetSceneManipulator()->getTerrainData()->mScale.y; pos.z = (pos.z - GetSceneManipulator()->getTerrainData()->mPosition.z) / GetSceneManipulator()->getTerrainData()->mScale.z; } x = pos.x; y = pos.y; z = pos.z; }
void ActorSceneCanvas::OnLeftUp(wxMouseEvent& e) { if (!GetSceneManipulator()) return; mDragStarted = false; mDragOrigin =Ogre::Vector2(e.GetX(), e.GetY()) ; Ogre::Ray ray = GetSceneManipulator()->getWindowToViewportRay(e.GetX(),e.GetY()); bool bAxis = false; std::pair<bool, Ogre::Real> result = Fairy::rayCollide(ray, ( Ogre::MovableObject*) Fairy::CDataManipulator::mAxis_x, true); if (result.first) { _resetAxisMaterial(); mXax = !mXax; mYax = mZax = false; if (mXax) { GetDataManipulator()->m_pMaterialX->setSelfIllumination(1.0,1.0,0); } bAxis = true; } if (!bAxis) { result = Fairy::rayCollide(ray, ( Ogre::MovableObject*) Fairy::CDataManipulator::mAxis_y, true); if (result.first) { _resetAxisMaterial(); mYax = !mYax; mXax = mZax = false; if (mYax) { GetDataManipulator()->m_pMaterialY->setSelfIllumination(1.0,1.0,0); } bAxis = true; } } if (!bAxis) { result = Fairy::rayCollide(ray, ( Ogre::MovableObject*) Fairy::CDataManipulator::mAxis_z, true); if (result.first) { _resetAxisMaterial(); mZax = !mZax; mXax = mYax = false; if (mZax) { GetDataManipulator()->m_pMaterialZ->setSelfIllumination(1.0,1.0,0); } bAxis = true; } } if (!HasCapture()) return; if (mDragButton == wxMOUSE_BTN_NONE || !e.Button(mDragButton)) return; wxASSERT(GetActiveAction()); GetActiveAction()->onEnd(e.GetX(), e.GetY(), false); m_pUpdateListener->disable(); mDragButton = wxMOUSE_BTN_NONE; ReleaseCapture(); }
void BrushSelector::ReloadTextureList(void) { CatalogMap catalogMap; mCatalogMap.clear(); if (!Ogre::ResourceGroupManager::getSingletonPtr()) return; mBrushesTree->Freeze(); mBrushesTree->DeleteAllItems(); wxTreeItemId rootId = mBrushesTree->AddRoot(/*_("Brushes")*/wxT("画刷列表")); // 重新解析定义文件 GetSceneManipulator()->reloadPaintInfo(); const Fairy::TerrainPaintInfoContainer *paintInfoContainer = GetSceneManipulator()->getTerrainPaintInfoContainer(); assert (paintInfoContainer); const Fairy::TextureInfoMap &textureInfoMap = paintInfoContainer->getTextureInfoMap(); OwnerTexs ownerTextures; Fairy::TextureInfoMap::const_iterator it = textureInfoMap.begin(); // 遍历画刷数组 while ( it != textureInfoMap.end() ) { const Fairy::TextureInfos &textureInfos = it->second; // 遍历该画刷下的所有纹理 for ( size_t i=0; i<textureInfos.size(); ++i ) { // 取出所属的大纹理的名称 Ogre::String ownerTexName = textureInfos[i].ownerTextureName; // 记录大纹理的名称 ownerTextures.insert(OwnerTexs::value_type(ownerTexName, ownerTexName)); // 如果该纹理名称中包含了/,说明它是在一个文件夹中的 size_t pos = ownerTexName.find_last_of('/'); // 在文件夹中 if (pos != Ogre::String::npos) { // 先去除纹理文件名,剩下路径名 ownerTexName.erase(pos+1); // 加上画刷的名称 ownerTexName.append(textureInfos[i].brushName); wxTreeItemId id = mBrushesTree->AppendItem( GetParentId(ownerTexName, catalogMap), wxT(textureInfos[i].textureName) ); mCatalogMap.insert(CatalogMap::value_type( textureInfos[i].textureName, id )); } else { Ogre::String brushName = textureInfos[i].brushName; // 如果是在根目录下,就直接用画刷名称来作为路径名 wxTreeItemId id = mBrushesTree->AppendItem( GetParentId(brushName, catalogMap), wxT(textureInfos[i].textureName) ); mCatalogMap.insert(CatalogMap::value_type( textureInfos[i].textureName, id )); } } ++it; } wxString lostTexNames = wxEmptyString; for (OwnerTexs::iterator ownerIt = ownerTextures.begin(); ownerIt != ownerTextures.end(); ++ownerIt) { Ogre::String texName = ownerIt->first; Ogre::FileInfoListPtr fileInfoList = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo("Brushes",texName); Ogre::FileInfoList::const_iterator itBegin = fileInfoList->begin(); Ogre::FileInfoList::const_iterator itEnd = fileInfoList->end(); if (itBegin == itEnd) { lostTexNames+=wxT("\n"); lostTexNames+=texName.c_str(); continue; } Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texName); if (!texture.isNull()) { Ogre::TextureManager::getSingleton().remove(texName); Ogre::Image image; image.load(texName, Fairy::BRUSH_RESOURCE_GROUP_NAME); texture = Ogre::TextureManager::getSingleton() .loadImage(texName, Fairy::BRUSH_RESOURCE_GROUP_NAME, image); } } if (!lostTexNames.empty()) { wxMessageBox(wxT("以下贴图无法找到:")+lostTexNames); } mBrushesTree->Thaw(); }
void BrushSelector::OnUpdateControls(wxUpdateUIEvent& e) { e.Enable(GetSceneManipulator() != 0); }
void ActorSceneCanvas::OnKeyDown(wxKeyEvent& e) { switch(e.GetKeyCode()) { case 'w': case 'W': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Ogre::Vector3 offsetPos = camera->getDirection() * GetSceneManipulator()->getMoveSpeed(); Ogre::Vector3 newPos = oldPos; newPos.x += offsetPos.x; newPos.z += offsetPos.z; GetSceneManipulator()->setCameraPosition(newPos); e.Skip(false); } break; case 's': case 'S': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Ogre::Vector3 offsetPos = camera->getDirection() * -(GetSceneManipulator()->getMoveSpeed()); Ogre::Vector3 newPos = oldPos; newPos.x += offsetPos.x; newPos.z += offsetPos.z; GetSceneManipulator()->setCameraPosition(newPos); e.Skip(false); } break; case 'a': case 'A': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Radian yawAngle( GetSceneManipulator()->getRotateSpeed() / 360.0f ); camera->yaw(yawAngle); e.Skip(false); } break; case 'd': case 'D': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Radian yawAngle( -(GetSceneManipulator()->getRotateSpeed() / 360.0f) ); camera->yaw(yawAngle); e.Skip(false); } break; case 'h': case 'H': { mHideAxis = !mHideAxis; Fairy::CDataManipulator::m_baseNode->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_x->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_y->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_z->setVisible(!mHideAxis); } break; case 'b': case 'B': { GetDataManipulator()->switchBoundingBox(true); } break; case 't': case 'T': { GetSceneManipulator()->setTerrainVisible(!GetSceneManipulator()->getTerrainVisible()); } break; case 'g': case 'G': { GetSceneManipulator()->setGridVisible(!GetSceneManipulator()->getGridVisible()); } break; case 'r': case 'R': { mRotFirst = !mRotFirst; } break; //case 'C': // case 'c': // { // Fairy::LogicModelManager::getSingleton().showModelBoundingBox(!Fairy::LogicModelManager::getSingleton().isShowBoundingBox()); // } // break; // // case 'y': // case 'Y': // { // mYax = !mYax; // mXax = mZax = false; // } // break; // // case 'z': // case 'Z': // { // mZax = !mZax; // mXax = mYax = false; // } //break; //case 'z': //case 'Z': // { // GetSceneManipulator()->setActiveAction("ManipObjectAction"); // GetSceneManipulator()->setUseAxis(!GetSceneManipulator()->getUseAxis()); // } // e.Skip(false); // break; } }
const Fairy::Action * BrushSelector::OnStartAutoTexAction( const wxTreeItemId &itemId, const wxString &brushName ) { // 启动自动纹理拼接action Fairy::Action* action = GetSceneManipulator()->_getAction("AutoTexPaintAction"); // 获取组的名称 wxString groupName = mBrushesTree->GetItemText(itemId); // 设置当前组的名称 action->setParameter( "%GroupName", AS_STRING(brushName) ); // 把之前的路径加上去 wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId); wxTreeItemId rootId = mBrushesTree->GetRootItem(); while ( parentId != rootId ) { wxString parentText = mBrushesTree->GetItemText(parentId); parentText += '/'; groupName.Prepend( parentText ); parentId = mBrushesTree->GetItemParent(parentId); } groupName += "/"; // 获取该目录下的第一个节点 wxTreeItemIdValue dummy; wxTreeItemId childId = mBrushesTree->GetFirstChild(itemId,dummy); while ( childId.IsOk() == true ) { // 遍历每个节点,设置纹理名称 wxString texName = mBrushesTree->GetItemText(childId); childId = mBrushesTree->GetNextChild(itemId,dummy); if ( texName.find('|') == wxString::npos ) continue; action->setParameter( "%TextureName", AS_STRING(texName) ); } // 输入InputFinish表示纹理名称输入完毕 action->setParameter( "%TextureName", "InputFinish" ); // 判断纹理是否正确地进行了初始化 if ( action->getParameter("%IsInit") == "Yes" ) { GetSceneManipulator()->setActiveAction(action); return action; } else { // 启用simplepaintAction action = GetSceneManipulator()->_getAction("SimplePaintAction"); action->setParameter( "%TextureName", "InputBegin" ); // 获取该目录下的第一个节点 wxTreeItemIdValue dummy; wxTreeItemId childId = mBrushesTree->GetFirstChild(itemId,dummy); while ( childId.IsOk() == true ) { // 遍历每个节点,设置纹理名称 wxString texName = mBrushesTree->GetItemText(childId); childId = mBrushesTree->GetNextChild(itemId,dummy); if ( texName.find('|') == wxString::npos ) continue; const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str()); const Fairy::TextureInfo ¤tPaintInfo = GetSceneManipulator()->getTextureInfo(mCurrentFileName.c_str(), texName.c_str()); Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName); // 组成纹理信息字符串 Ogre::String texInfoString; texInfoString += currentPaintInfo.ownerTextureName; texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getHeight()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getWidth()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType); action->setParameter( "%TextureName", AS_STRING(texInfoString) ); // 这里有个错误??,因为没有设置该纹理是否为普通纹理大小,所以如果这一个组中有一个大纹理,那么 // 它可能会只缩放到一格 } if ( action->getParameter("%IsInit") == "Yes" ) { GetSceneManipulator()->setActiveAction(action); return action; } else { // 为能成功初始化,先把active action设为NULL GetSceneManipulator()->setActiveAction(NULL); return NULL; } } }
void BrushSelector::OnPixmapListSelected(wxTreeEvent& event) { try { // 以下是改成定义文件后的修改 // mPaintInOneGrid = false; // 保存当前选中的纹理的大小 int selectedTexXSize = 0; int selectedTexZSize = 0; // 当画刷被选中时,要进行判断 wxTreeItemId itemId = event.GetItem(); wxTreeItemId rootId = mBrushesTree->GetRootItem(); // 如果选中根,就返回 if ( itemId == rootId ) { // 选中根目录名时,所有选项都变灰 mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); mEnablePreview->Enable(false); // 缩略图用黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); return; } if (itemId.IsOk()) { mCurrentOrientationType = 0; // 如果选项的父是root,说明该画刷是放在根目录下的,也有可能是根目录下的子目录 if ( mBrushesTree->GetItemParent(itemId) == rootId ) { mCurrentFileName = mBrushesTree->GetItemText(itemId); } else { // 以下处理不是放在根目录下的画刷 wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId); mCurrentFileName = mBrushesTree->GetItemText(itemId); // 以此取出父目录的目录名,组合成相对路径名,并加上文件名 while ( parentId != rootId ) { wxString parentText = mBrushesTree->GetItemText(parentId); parentText += '/'; mCurrentFileName.Prepend( parentText ); parentId = mBrushesTree->GetItemParent(parentId); } } // 如果名字中有.,说明是文件名,不是目录名 if ( mCurrentFileName.find_first_of('|') != wxString::npos ) { mFlipHorizontal->Enable(true); mFlipVertical->Enable(true); mRotateRightAngle->Enable(true); mMirrorDiagonal->Enable(true); mRandom->Enable(true); mEnablePreview->Enable(true); Ogre::String currentFileName(mCurrentFileName.c_str()); size_t pos = currentFileName.find_last_of('/'); // 取出brush名称 Ogre::String brushName = currentFileName.substr(0,pos); Ogre::String textureName = currentFileName.substr(pos+1); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(brushName); const Fairy::TextureInfo ¤tPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName); Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName); // 组成纹理信息字符串 Ogre::String texInfoString; texInfoString += currentPaintInfo.ownerTextureName; texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getHeight()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(previewImage->getWidth()); texInfoString += "|"; texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType); Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction"); action->setParameter( "%TextureName", "InputBegin" ); action->setParameter( "%TextureName", AS_STRING(texInfoString) ); action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) ); if ( (currentPaintInfo.width > 1 || currentPaintInfo.height > 1) && !mPaintInOneGrid ) { action->setParameter( "%TexNormalSize", "false" ); mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); } else { action->setParameter("%TexNormalSize","true"); } GetSceneManipulator()->setActiveAction(action); buildPreviewBitmap(currentPaintInfo); if ( mEnablePreview->IsChecked() == false ) { // 如果不显示缩略图,就显示默认的黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } } // 如果名字中有.,说明不是文件名,是目录名 else { mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); mRandom->Enable(false); mEnablePreview->Enable(true); // 把整个目录的纹理进行判断,并加入到透明纹理列表 const Fairy::Action* action = OnStartAutoTexAction(itemId, mCurrentFileName); if ( action != 0 ) { // 从该组纹理的实心纹理中随机用一个来做为缩略图 // 读取这张纹理,并缩放到mPreviewImageWidth*mPreviewImageHeight,用于缩略图 // Ogre::String tempTexName = action->getParameter( "%TextureName" ); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str()); // const Fairy::TextureInfo ¤tPaintInfo = currentPaintInfos[0]; // 构建preview image buildPreviewBitmap(currentPaintInfos[0]); } else { mEnablePreview->Enable(false); mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } if ( mEnablePreview->IsChecked() == false ) { // 如果不显示缩略图,就显示默认的黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } } } // 让所有的checkbox回复未选择的状态 mFlipHorizontal->SetValue(false); mFlipVertical->SetValue(false); mRotateRightAngle->SetValue(false); mMirrorDiagonal->SetValue(false); mRandom->SetValue(false); } catch (Ogre::Exception &e) { wxMessageBox( e.getDescription().c_str(), /* _("Texture Wrong")*/wxT("纹理定义出错或找不到纹理图片"), wxOK|wxCENTRE|wxICON_ERROR, this); } }
void ActorSceneCanvas::OnMouseMove(wxMouseEvent& e) { ShowPos(e.GetX(), e.GetY()); if (!GetSceneManipulator()) return; if (m_pCameraManip) { wxASSERT(mDragButton != wxMOUSE_BTN_NONE); m_pCameraManip->onMotion(e.GetX(), e.GetY()); } if (mDragStarted && e.LeftIsDown()) { mDragCurrent =Ogre::Vector2(e.GetX(), e.GetY()) ; mDragDelta = mDragCurrent - mDragOrigin; mDragOrigin = mDragCurrent; if (Fairy::CDataManipulator::GetDataManipulator() && mCanManipulateAxis) { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Fairy::LogicModel* pModel = GetDataManipulator()->m_pObjTemplate; if (pModel) { Ogre::Vector3 objPos = pModel->getPosition(); Ogre::Real distance = oldPos.distance(objPos); Ogre::Real factor = distance*0.1/150.0; Ogre::Vector3 pos=Fairy::CDataManipulator::m_baseNode->getPosition(); Ogre::Vector3 fdeltaxi = Ogre::Vector3::ZERO; Ogre::Quaternion qRot = Fairy::CDataManipulator::m_baseNode->getOrientation(); //david-<< if(mXax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_X); if(mYax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_Y); if(mZax) fdeltaxi = /*qRot**/(mDragDelta.x*0.1*Ogre::Vector3::UNIT_Z); //david->> Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorTrans(fdeltaxi,Ogre::Quaternion::IDENTITY,true); } } } if(mDragRightStarted && e.RightIsDown()) { mDragCurrent =Ogre::Vector2(e.GetX(), e.GetY()) ; mDragDelta = mDragCurrent - mDragOrigin; mDragOrigin = mDragCurrent; // Ogre::Radian x = Ogre::Degree(mDragDelta.val[0]); // Ogre::Radian y = Ogre::Degree(mDragDelta.val[1]); // Fairy::CDataManipulator::m_axex->yaw(y); // Fairy::CDataManipulator::m_axex->pitch(x); if ( Fairy::CDataManipulator::GetDataManipulator() &&(mXax || mYax || mZax) && mCanManipulateAxis) { Ogre::Vector3 fBaseAxis = Ogre::Vector3::ZERO; Ogre::Quaternion fBaseRot = Fairy::CDataManipulator::m_baseNode->getOrientation(); if(mXax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_X; if(mYax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_Y; if(mZax) fBaseAxis =/* fBaseRot**/Ogre::Vector3::UNIT_Z; //david-<< Ogre::Radian angle = Ogre::Degree(mDragDelta.y); //david->> Ogre::Quaternion rot(angle, fBaseAxis); if(mRotFirst) { Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorTrans(Ogre::Vector3::ZERO, rot, false); } else { Fairy::CDataManipulator::GetDataManipulator()->_updateCurLocatorRot(rot); } } } if (GetActiveAction()) { //GetActiveAction()->onMotion(e.GetX(), e.GetY()); if (e.ControlDown()) { GetActiveAction()->setParameter("FUNC_KEY", "CTRL"); } if(e.AltDown()) { GetActiveAction()->setParameter("FUNC_KEY", "ATL"); } if(e.ShiftDown()) { GetActiveAction()->setParameter("FUNC_KEY", "SHIFT"); } } else { //GetSceneManipulator()->getHitIndicator("IntersectPoint")->setHitPoint(e.GetX(), e.GetY()); } // 显示标准模型 //if ( GetSceneManipulator()->getShowStandardModel() ) // GetSceneManipulator()->getHitIndicator("StandardModelIndicator")->setHitPoint(0.5,0.5); //else // GetSceneManipulator()->getHitIndicator("StandardModelIndicator")->hide(); m_CurrentMousePos.x = e.GetX(); m_CurrentMousePos.y = e.GetY(); Ogre::Vector3 position; bool hit = GetSceneManipulator()->getTerrainIntersects(m_CurrentMousePos.x, m_CurrentMousePos.y, position); std::pair<int, int> gridCoord = GetSceneManipulator()->getTerrainData()->getGrid(position.x, position.z); if (hit) { mParentFrame->SetStatusText("World Coordinate : " + Ogre::StringConverter::toString((int)(position.x)) + " " + Ogre::StringConverter::toString((int)(position.y)) + " " + Ogre::StringConverter::toString((int)(position.z)), 0); mParentFrame->SetStatusText("Grid Coordinate : " + Ogre::StringConverter::toString(gridCoord.first) + " " + Ogre::StringConverter::toString(gridCoord.second), 1); } }
void BrushSelector::OnCheck( wxCommandEvent &event ) { if ( event.GetId() == feID_RANDOM ) { // 禁止其他按钮 if ( mRandom->IsChecked() ) { mIsRandomOrientation = true; mFlipHorizontal->Enable(false); mFlipVertical->Enable(false); mRotateRightAngle->Enable(false); mMirrorDiagonal->Enable(false); } else { mIsRandomOrientation = false; mFlipHorizontal->Enable(true); mFlipVertical->Enable(true); mRotateRightAngle->Enable(true); mMirrorDiagonal->Enable(true); } } else { mCurrentOrientationType = 0; // 以下是checkbox状态的判断 if ( mFlipHorizontal->IsChecked() == true ) { mCurrentOrientationType |= 1; } if ( mFlipVertical->IsChecked() == true ) { mCurrentOrientationType |= 2; } if ( mRotateRightAngle->IsChecked() == true ) { mCurrentOrientationType |= 4; } if ( mMirrorDiagonal->IsChecked() == true ) { mCurrentOrientationType |= 8; } } Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction"); assert (action); action->setParameter( "%UseRandomOrientation", mIsRandomOrientation ? "true" : "false" ); action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) ); GetSceneManipulator()->setActiveAction(action); // wxImage tempPreview; if ( mEnablePreview->IsChecked() ) { // 选中按钮时,缩略图也要相应变化 if ( event.GetId() == feID_FLIP_HORIZONTAL ) { mCurrentPreviewImage = mCurrentPreviewImage.Mirror(); mBrushesPreview->SetBitmap(mCurrentPreviewImage); } if ( event.GetId() == feID_FLIP_VERTICAL ) { mCurrentPreviewImage = mCurrentPreviewImage.Mirror(false); mBrushesPreview->SetBitmap(mCurrentPreviewImage); } if ( event.GetId() == feID_ROTATE_RIGHT_ANGLE ) { if ( mRotateRightAngle->IsChecked() == true ) { mCurrentPreviewImage = mCurrentPreviewImage.Rotate90(false); mBrushesPreview->SetBitmap(mCurrentPreviewImage); } else { mCurrentPreviewImage = mCurrentPreviewImage.Rotate90(); mBrushesPreview->SetBitmap(mCurrentPreviewImage); } } } else { // 如果不显示缩略图,就显示默认的黑白图 mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } // 预览图的开关 if ( event.GetId() == feID_ENABLE_PIXMAP_PREVIEW ) { if ( mEnablePreview->IsChecked() ) { // 如果用户打开开关,就用前面OnPixmapListSelected中计算好的预览图来显示 // 这也是为什么前面OnPixmapListSelected中无论这个开关是否打开都要计算预览图的原因 // 不然的话,这里打开开关后显示的是上次计算的预览图,而不是当前所选纹理的预览图 mBrushesPreview->SetBitmap(mCurrentPreviewImage); } else { mBrushesPreview->SetBitmap(mBlackWhitePreviewImage); } } }
void BrushSelector::ShowBrushRightButtonMenu(const wxTreeItemId &itemId) { // 清空全地形平铺的画刷数组 mPixmapArray.clear(); wxMenu menu; // 增加菜单项 menu.Append(feID_PIXMAP_FULLTERRAINPAINT, _T("&Full Terrain Paint")); // 初始时为不可用 menu.Enable(feID_PIXMAP_FULLTERRAINPAINT,false); // 以下是检测该目录下或该文件是否符合要求(不可为tga文件) wxTreeItemId rootId = mBrushesTree->GetRootItem(); if ( itemId == rootId ) return; if (itemId.IsOk()) { // 如果选项的父是root,说明该画刷是放在根目录下的,也有可能是根目录下的子目录 if ( mBrushesTree->GetItemParent(itemId) == rootId ) { mCurrentFileName = mBrushesTree->GetItemText(itemId); } else { // 以下处理不是放在根目录下的画刷 wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId); mCurrentFileName = mBrushesTree->GetItemText(itemId); // 以此取出父目录的目录名,组合成相对路径名,并加上文件名 while ( parentId != rootId ) { wxString parentText = mBrushesTree->GetItemText(parentId); parentText += '/'; mCurrentFileName.Prepend( parentText ); parentId = mBrushesTree->GetItemParent(parentId); } } // 如果名字中有.,说明是文件名,不是目录名 if ( mCurrentFileName.find_first_of('|') != wxString::npos ) { Ogre::String currentFileName(mCurrentFileName.c_str()); size_t pos = currentFileName.find_last_of('/'); // 取出brush名称 Ogre::String brushName = currentFileName.substr(0,pos); Ogre::String textureName = currentFileName.substr(pos+1); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(brushName); const Fairy::TextureInfo ¤tPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName); // 如果该纹理不是透明纹理,可以用于平铺整个地形 if ( !mSceneManipulator->IsTransparentTexture(currentPaintInfo.ownerTextureName) ) { Fairy::PaintPixmap pixmap; mSceneManipulator->setPaintPixmapInfo(pixmap, currentPaintInfo); mPixmapArray.push_back(pixmap); } } // 如果名字中有.,说明不是文件名,是目录名 else { // 获取组的名称 wxString groupName = mBrushesTree->GetItemText(itemId); // 把之前的路径加上去 wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId); wxTreeItemId rootId = mBrushesTree->GetRootItem(); while ( parentId != rootId ) { wxString parentText = mBrushesTree->GetItemText(parentId); parentText += '/'; groupName.Prepend( parentText ); parentId = mBrushesTree->GetItemParent(parentId); } groupName += "/"; // 获取该目录下的第一个节点 wxTreeItemIdValue dummy; wxTreeItemId childId = mBrushesTree->GetFirstChild(itemId,dummy); while ( childId.IsOk() == true ) { // 遍历每个节点,设置纹理名称 wxString texName = mBrushesTree->GetItemText(childId); childId = mBrushesTree->GetNextChild(itemId,dummy); if ( texName.find('|') == wxString::npos ) continue; texName.Prepend(groupName); Ogre::String currentFileName(texName.c_str()); size_t pos = currentFileName.find_last_of('/'); // 取出brush名称 Ogre::String brushName = currentFileName.substr(0,pos); Ogre::String textureName = currentFileName.substr(pos+1); const Fairy::TextureInfos ¤tPaintInfos = GetSceneManipulator()->getTextureInfos(brushName); const Fairy::TextureInfo ¤tPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName); // 如果该纹理不是透明纹理,可以用于平铺整个地形 if ( !mSceneManipulator->IsTransparentTexture(currentPaintInfo.ownerTextureName) ) { Fairy::PaintPixmap pixmap; mSceneManipulator->setPaintPixmapInfo(pixmap, currentPaintInfo); mPixmapArray.push_back(pixmap); } } } if ( mPixmapArray.size() > 0 ) { // 让菜单显示 menu.Enable(feID_PIXMAP_FULLTERRAINPAINT,true); } else menu.Enable(feID_PIXMAP_FULLTERRAINPAINT,false); } // 增加一项,选中后可以让一张纹理总是对应一个格(可能是hack的代码,可能该成配置文件,或可以自定义一张纹理对应多少格) // 增加菜单项 menu.AppendCheckItem(feID_PIXMAP_PAINTINONEGRID, _T("&Paint this texture in one grid")); // 初始时为不可用 // menu.Enable(feID_PIXMAP_PAINTINONEGRID,false); menu.Check(feID_PIXMAP_PAINTINONEGRID,mPaintInOneGrid); PopupMenu(&menu); }
// // 创建建筑物的行走面数据。 // void FairyEditorFrame::CreateBuildingCollisionData() { std::string strTemp; // Ogre::String meshName; // 静态物体对应的mesh模型文件. Ogre::String meshFile; // 静态物体对应的mesh模型文件. Ogre::String meshPath; // 静态物体对应的mesh模型文件. Ogre::Vector3 position; // 静态物体摆放的位置. Ogre::Quaternion rotateQuaternion; // 旋转数据. Ogre::Vector3 scale; // 缩放数据. int iStrLen = 0; // mesh 文件名字的长度 int iPos = 0; // mesh 文件名字中 ‘ / ’的位置. // 清空以前的数据。 m_TriInMapInfoMap.m_triInfoInMap.clear(); // 查找每一个带有行走面数据的物体 const Fairy::Scene::Objects& mObjects = GetSceneManipulator()->getSceneInfo()->getObjects(); for (Fairy::Scene::Objects::const_iterator it = mObjects.begin(); it != mObjects.end(); ++it) { const Fairy::ObjectPtr& object = *it; //if ( ("StaticEntity" != object->getType())&&("Model" != object->getType())) //{ // continue; //}// //if ( (Fairy::StaticEntityObject::msType != object->getType()) // &&(Fairy::ModelObject::msType != object->getType())) // { // continue; // }// if(Fairy::StaticEntityObject::msType != object->getType()) { continue; }// meshName = Fairy::VariantCast<Ogre::String>(object->getProperty("mesh name")); Ogre::StringUtil::splitFilename(meshName, meshFile, meshPath); iPos = meshFile.find_last_of("."); std::string strName; strName.empty(); if(iPos> 0) { strName = meshFile.substr(0, iPos); } else { strName = meshFile; } strName = strName + ".cll"; //FairyEditorFrame::BUILDING_COLLISION_MAP::iterator it1; //FairyEditorFrame::BUILDING_COLLISION_MAP::iterator itEnd1; //itEnd1 = m_buildingCollisionInfoLibMap.end(); //for(it1 = m_buildingCollisionInfoLibMap.begin(); it1 != itEnd1; it1++) //{ // std::string strCllFileName = it1->first; // if(strName == strCllFileName) // { // break; // } //} //if(it1 == itEnd1) //{ // continue; //} ////if(0 == m_buildingCollisionInfoLibMap.count(strName)) ////{ //// continue; ////}// // 得到模型的平移, 旋转和缩放数据。 position = Fairy::VariantCast<Ogre::Vector3>(object->getProperty("position")); rotateQuaternion = Fairy::VariantCast<Ogre::Quaternion>(object->getProperty("orientation")); scale = Fairy::VariantCast<Ogre::Vector3>(object->getProperty("scale")); // 创建变换矩阵。 Ogre::Matrix4 TransformMatrix; BuildTransformMatrix(TransformMatrix, position, rotateQuaternion, scale); // 先把行走面数据注册到地图中去。 RegisterCollisionToMap(strName, TransformMatrix); } }
void BrushSelector::buildPreviewBitmap( const Fairy::TextureInfo texInfo ) { const Ogre::uchar BytePerPixel = 8; // 读取原始image Ogre::Image *oriImage = GetSceneManipulator()->getPreviewImage(texInfo.ownerTextureName); // 源大纹理的大小 size_t oriImageHeight = oriImage->getHeight(); size_t oriImageWidth = oriImage->getWidth(); Ogre::uchar *oriImageData = oriImage->getData(); // 所选纹理的大小 size_t newImageWidth = texInfo.width*TexTileSize; size_t newImageHeight = texInfo.height*TexTileSize; // 分配一个足够大的空间来保存新建的image的数据 size_t newImagegetRowSpan = newImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节) Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[newImageHeight*newImagegetRowSpan]; Ogre::uchar *newImageDataPointer = newImageData; // 得知起始像素点 size_t startPoint = ( oriImageWidth * texInfo.topCorner + texInfo.leftCorner ) * TexTileSize * oriImage->getBPP()/BytePerPixel; Ogre::uchar *oriImagedataPointer = oriImageData + startPoint; // 把所选的纹理的数据提取出来,并创建一个新的image for ( Ogre::uint i=0; i<newImageHeight; ++i ) { memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan); newImageDataPointer += newImagegetRowSpan; oriImagedataPointer += oriImage->getRowSpan(); } Ogre::Image newImage; newImage.loadDynamicImage(newImageData,newImageWidth,newImageHeight,1,oriImage->getFormat(),true); // 如果所选纹理大于64*64,就先resize if ( texInfo.width > 1 || texInfo.height > 1 ) newImage.resize(mPreviewImageWidth, mPreviewImageHeight); // 如果有alpha,要与黑白图进行混合 if ( newImage.getHasAlpha() ) { Ogre::ColourValue col; for ( int i=0; i<mPreviewImageWidth; ++i ) { for ( int j=0; j<mPreviewImageWidth; ++j ) { col = newImage.getColourAt(j,i,0); float alphaValue = col.a; unsigned char r = col.r*255 * alphaValue + mBlackWhitePreviewImage.GetRed(i,j) * ( 1.0f - alphaValue); unsigned char g = col.g*255 * alphaValue + mBlackWhitePreviewImage.GetGreen(i,j) * ( 1.0f - alphaValue); unsigned char b = col.b*255 * alphaValue + mBlackWhitePreviewImage.GetBlue(i,j) * ( 1.0f - alphaValue); // 设置到image中 mCurrentPreviewImage.SetRGB(j,i,r,g,b); } } // 设置到缩略图控件中 mBrushesPreview->SetBitmap(mCurrentPreviewImage); } // 没有alpha,就直接拷贝数据 else { Ogre::ColourValue col; for ( int i=0; i<mPreviewImageWidth; ++i ) { for ( int j=0; j<mPreviewImageWidth; ++j ) { col = newImage.getColourAt(j,i,0); unsigned char r = col.r*255; unsigned char g = col.g*255; unsigned char b = col.b*255; // 设置到image中 mCurrentPreviewImage.SetRGB(j,i,r,g,b); } } mBrushesPreview->SetBitmap(mCurrentPreviewImage); } }
Fairy::Action* ActorSceneCanvas::GetActiveAction(void) const { return GetSceneManipulator()->getActiveAction(); }