DAVA::Entity* SceneSelectionSystem::GetSelectableEntity(DAVA::Entity* entity) { DAVA::Entity *selectableEntity = NULL; if(NULL != entity) { // find most top solid entity DAVA::Entity *parent = entity; while(NULL != parent) { if(parent->GetSolid()) { selectableEntity = parent; } parent = parent->GetParent(); } // still not found? if(NULL == selectableEntity) { // let it current entity to be tread as solid selectableEntity = entity; } } return selectableEntity; }
void SceneTree::ShowContextMenu(const QPoint &pos) { QModelIndex index = indexAt(pos); DAVA::Entity *clickedEntity = treeModel->GetEntity(index); if(NULL != clickedEntity) { QMenu contextMenu; contextMenu.addAction(QIcon(":/QtIcons/zoom.png"), "Look at", this, SLOT(LookAtSelection())); contextMenu.addSeparator(); contextMenu.addAction(QIcon(":/QtIcons/remove.png"), "Remove", this, SLOT(RemoveSelection())); contextMenu.addSeparator(); QAction *lockAction = contextMenu.addAction(QIcon(":/QtIcons/lock_add.png"), "Lock", this, SLOT(LockEntities())); QAction *unlockAction = contextMenu.addAction(QIcon(":/QtIcons/lock_delete.png"), "Unlock", this, SLOT(UnlockEntities())); if(clickedEntity->GetLocked()) { lockAction->setDisabled(true); } else { unlockAction->setDisabled(true); } contextMenu.exec(mapToGlobal(pos)); } }
void QtPropertyDataIntrospection::BakeTransform() { QtPropertyDataIntrospection * renderComponentProperty = static_cast<QtPropertyDataIntrospection*>(parent); DAVA::Entity * entity = (static_cast<DAVA::RenderComponent*>(renderComponentProperty->object))->GetEntity(); DAVA::RenderObject * ro = static_cast<DAVA::RenderObject*>(object); ro->BakeTransform(entity->GetLocalTransform()); entity->SetLocalTransform(DAVA::Matrix4::IDENTITY); }
void SceneTree::TreeItemDoubleClicked(const QModelIndex & index) { SceneEditor2* sceneEditor = treeModel->GetScene(); if(NULL != sceneEditor) { DAVA::Entity *entity = treeModel->GetEntity(index); if(NULL != entity) { DAVA::AABBox3 box = sceneEditor->selectionSystem->GetSelectionAABox(entity, entity->GetWorldTransform()); sceneEditor->cameraSystem->LookAt(box); } } }
void SceneTreeDelegate::customDraw(QPainter *painter, QStyleOptionViewItem *option, const QModelIndex &index) const { DAVA::Entity *entity = index.data(SceneTreeItem::TreeItemEntityRole).value<DAVA::Entity*>(); if(NULL != entity && entity->GetLocked()) { QRect owRect = option->rect; owRect.setLeft(owRect.right() - 16); lockedIcon.paint(painter, owRect); option->rect.setRight(owRect.left()); } }
void SaveEntityAsAction::Redo() { if(!sc2Path.IsEmpty() && sc2Path.IsEqualToExtension(".sc2") && NULL != entities && entities->Size() > 0) { DAVA::Scene *scene = new DAVA::Scene(); Vector3 oldZero = entities->GetCommonZeroPos(); for(size_t i = 0; i < entities->Size(); ++i) { DAVA::Entity *entity = entities->GetEntity(i); DAVA::Entity *clone = entity->Clone(); Vector3 offset = clone->GetLocalTransform().GetTranslationVector() - oldZero; Matrix4 newLocalTransform = clone->GetLocalTransform(); newLocalTransform.SetTranslationVector(offset); clone->SetLocalTransform(newLocalTransform); DAVA::KeyedArchive *props = GetCustomPropertiesArchieve(clone); if(props) { props->DeleteKey(ResourceEditor::EDITOR_REFERENCE_TO_OWNER); } scene->AddNode(clone); } scene->Save(sc2Path); scene->Release(); } }
EntityGroupItem SceneSelectionSystem::GetSelectableEntity(DAVA::Entity* entity) { EntityGroupItem ret; DAVA::Entity *solidEntity = entity; if(NULL != entity) { // find real solid entity solidEntity = entity; while(NULL != solidEntity && !solidEntity->GetSolid()) { solidEntity = solidEntity->GetParent(); } // if there is no solid entity, try to find lod parent entity if(NULL == solidEntity) { // find entity that has lod component solidEntity = entity; while(NULL != solidEntity && NULL == solidEntity->GetComponent(DAVA::Component::LOD_COMPONENT)) { solidEntity = solidEntity->GetParent(); } } // still not found? if(NULL == solidEntity) { // let it current entity to be tread as solid solidEntity = entity; } ret.entity = entity; ret.solidEntity = solidEntity; ret.bbox = CalcAABox(solidEntity); } return ret; }
DAVA::AABBox3 SceneSelectionSystem::GetSelectionAABox(DAVA::Entity *entity, const DAVA::Matrix4 &transform) const { DAVA::AABBox3 ret = DAVA::AABBox3(DAVA::Vector3(0, 0, 0), 0); if(NULL != entity) { // we will get selection bbox from collision system DAVA::AABBox3 entityBox = collisionSystem->GetBoundingBox(entity); // add childs boxes into entity box for (DAVA::int32 i = 0; i < entity->GetChildrenCount(); i++) { DAVA::Entity *childEntity = entity->GetChild(i); DAVA::AABBox3 childBox = GetSelectionAABox(childEntity, childEntity->GetLocalTransform()); if(entityBox.IsEmpty()) { entityBox = childBox; } else { if(!childBox.IsEmpty()) { entityBox.AddAABBox(childBox); } } } // we should return box with specified transformation if(!entityBox.IsEmpty()) { entityBox.GetTransformedBox(transform, ret); } } return ret; }
QWidget* ActionItemEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QWidget* editor = NULL; switch(index.column()) { case COLUMN_ACTION_TYPE: { QComboBox* combo = new QComboBox(parent); combo->setFrame(false); for(int i = 1; i < ACTION_NAME_COUNT - 1; ++i) //do not add sound aciton { combo->addItem(ACTION_TYPE_NAME[i]); } editor = combo; break; } case COLUMN_ENTITY_NAME: { DAVA::Entity* parentEntity = targetComponent->GetEntity(); DAVA::Vector<DAVA::Entity*> allChildren; parentEntity->GetChildNodes(allChildren); DAVA::Vector<DAVA::String> childrenNames; childrenNames.push_back(parentEntity->GetName()); for(int i = 0; i < allChildren.size(); ++i) { childrenNames.push_back(allChildren[i]->GetName()); } std::sort(childrenNames.begin(), childrenNames.end()); childrenNames.erase(std::unique(childrenNames.begin(), childrenNames.end()), childrenNames.end()); QComboBox* combo = new QComboBox(parent); combo->setFrame(false); for(int i = 0; i < childrenNames.size(); ++i) { combo->addItem(childrenNames[i].c_str()); } editor = combo; break; } case COLUMN_DELAY: { QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent); spinBox->setMinimum(0.0f); spinBox->setMaximum(3600.f); spinBox->setSingleStep(0.01f); editor = spinBox; break; } case COLUMN_SWITCH_INDEX: { QSpinBox* spinBox = new QSpinBox(parent); spinBox->setMinimum(-1); spinBox->setMaximum(128); spinBox->setSingleStep(1); editor = spinBox; break; } case COLUMN_STOPAFTERNREPEATS_INDEX: { QSpinBox* spinBox = new QSpinBox(parent); spinBox->setMinimum(-1); spinBox->setMaximum(100000); spinBox->setSingleStep(1); editor = spinBox; break; } case COLUMN_STOPWHENEMPTY_INDEX: { QComboBox* combo = new QComboBox(parent); combo->setFrame(false); combo->addItem("Yes"); combo->addItem("No"); editor = combo; break; } } DVASSERT(editor); return editor; }
void ModificationWidget::ApplyScaleValues(ST_Axis axis) { DAVA::float32 scaleValue = 1.0f; switch (axis) { case ST_AXIS_X: scaleValue = xAxisModify->value(); break; case ST_AXIS_Y: scaleValue = yAxisModify->value(); break; case ST_AXIS_Z: scaleValue = zAxisModify->value(); break; default: break; } if(NULL != curScene) { EntityGroup selection = curScene->selectionSystem->GetSelection(); if(selection.Size() > 1) { curScene->BeginBatch("Multiple transform"); } for (size_t i = 0; i < selection.Size(); ++i) { DAVA::Entity *entity = selection.GetEntity(i); DAVA::Matrix4 origMatrix = entity->GetLocalTransform(); DAVA::Vector3 pos, scale, rotate; if(origMatrix.Decomposition(pos, scale, rotate)) { DAVA::Matrix4 newMatrix; DAVA::Matrix4 scaleMatrix; DAVA::Matrix4 transformMatrix; DAVA::Matrix4 moveToZeroPos; DAVA::Matrix4 moveFromZeroPos; moveToZeroPos.CreateTranslation(-origMatrix.GetTranslationVector()); moveFromZeroPos.CreateTranslation(origMatrix.GetTranslationVector()); DAVA::float32 newEntityScale; if(pivotMode == PivotAbsolute) { if(0 != scale.x) { newEntityScale = scaleValue / scale.x; } else { newEntityScale = 0; } } else { newEntityScale = scaleValue; } scaleMatrix.CreateScale(DAVA::Vector3(newEntityScale, newEntityScale, newEntityScale)); newMatrix = origMatrix * moveToZeroPos * scaleMatrix * moveFromZeroPos; newMatrix.SetTranslationVector(origMatrix.GetTranslationVector()); curScene->Exec(new TransformCommand(entity, origMatrix, newMatrix)); } } if(selection.Size() > 1) { curScene->EndBatch(); } } }
void ModificationWidget::ApplyRotateValues(ST_Axis axis) { DAVA::float32 x = DAVA::DegToRad(xAxisModify->value()); DAVA::float32 y = DAVA::DegToRad(yAxisModify->value()); DAVA::float32 z = DAVA::DegToRad(zAxisModify->value()); if(NULL != curScene) { EntityGroup selection = curScene->selectionSystem->GetSelection(); if(selection.Size() > 1) { curScene->BeginBatch("Multiple transform"); } for (size_t i = 0; i < selection.Size(); ++i) { DAVA::Entity *entity = selection.GetEntity(i); DAVA::Matrix4 origMatrix = entity->GetLocalTransform(); DAVA::Vector3 pos, scale, rotate; if(origMatrix.Decomposition(pos, scale, rotate)) { DAVA::Matrix4 newMatrix; DAVA::Matrix4 rotationMatrix; DAVA::Matrix4 transformMatrix; DAVA::Matrix4 moveToZeroPos; DAVA::Matrix4 moveFromZeroPos; moveToZeroPos.CreateTranslation(-origMatrix.GetTranslationVector()); moveFromZeroPos.CreateTranslation(origMatrix.GetTranslationVector()); if(pivotMode == PivotAbsolute) { switch (axis) { case ST_AXIS_X: rotationMatrix.CreateRotation(DAVA::Vector3(1, 0, 0), x - rotate.x); break; case ST_AXIS_Y: rotationMatrix.CreateRotation(DAVA::Vector3(0, 1, 0), y - rotate.y); break; case ST_AXIS_Z: rotationMatrix.CreateRotation(DAVA::Vector3(0, 0, 1), z - rotate.z); break; default: break; } } else { switch (axis) { case ST_AXIS_X: rotationMatrix.CreateRotation(DAVA::Vector3(1, 0, 0), x); break; case ST_AXIS_Y: rotationMatrix.CreateRotation(DAVA::Vector3(0, 1, 0), y); break; case ST_AXIS_Z: rotationMatrix.CreateRotation(DAVA::Vector3(0, 0, 1), z); break; default: break; } } newMatrix = origMatrix * moveToZeroPos * rotationMatrix * moveFromZeroPos; newMatrix.SetTranslationVector(origMatrix.GetTranslationVector()); curScene->Exec(new TransformCommand(entity, origMatrix, newMatrix)); } } if(selection.Size() > 1) { curScene->EndBatch(); } } }
void ModificationWidget::ApplyMoveValues(ST_Axis axis) { DAVA::float32 x = xAxisModify->value(); DAVA::float32 y = yAxisModify->value(); DAVA::float32 z = zAxisModify->value(); if(NULL != curScene) { EntityGroup selection = curScene->selectionSystem->GetSelection(); if(selection.Size() > 1) { curScene->BeginBatch("Multiple transform"); } for (size_t i = 0; i < selection.Size(); ++i) { DAVA::Entity *entity = selection.GetEntity(i); DAVA::Matrix4 origMatrix = entity->GetLocalTransform(); DAVA::Vector3 origPos = origMatrix.GetTranslationVector(); DAVA::Vector3 newPos = origPos; if(pivotMode == PivotAbsolute) { switch (axis) { case ST_AXIS_X: newPos.x = x; break; case ST_AXIS_Y: newPos.y = y; break; case ST_AXIS_Z: newPos.z = z; break; default: break; } } else { switch (axis) { case ST_AXIS_X: newPos.x += x; break; case ST_AXIS_Y: newPos.y += y; break; case ST_AXIS_Z: newPos.z += z; break; default: break; } } DAVA::Matrix4 newMatrix = origMatrix; newMatrix.SetTranslationVector(newPos); curScene->Exec(new TransformCommand(entity, origMatrix, newMatrix)); } if(selection.Size() > 1) { curScene->EndBatch(); } } }
void ModificationWidget::ReloadValues() { if(modifMode == ST_MODIF_SCALE) { xLabel->setText("Scale:"); yLabel->setVisible(false); zLabel->setVisible(false); yAxisModify->setVisible(false); zAxisModify->setVisible(false); } else { xLabel->setText("X:"); yLabel->setVisible(true); zLabel->setVisible(true); yAxisModify->setVisible(true); zAxisModify->setVisible(true); } if(NULL != curScene) { EntityGroup selection = curScene->selectionSystem->GetSelection(); if(selection.Size() > 0 && (modifMode == ST_MODIF_MOVE || modifMode == ST_MODIF_ROTATE || modifMode == ST_MODIF_SCALE)) { xAxisModify->setEnabled(true); yAxisModify->setEnabled(true); zAxisModify->setEnabled(true); xAxisModify->showButtons(true); yAxisModify->showButtons(true); zAxisModify->showButtons(true); if(selection.Size() > 1) { groupMode = true; if(pivotMode == PivotRelative) { xAxisModify->setValue(0); yAxisModify->setValue(0); zAxisModify->setValue(0); } else { xAxisModify->showButtons(false); yAxisModify->showButtons(false); zAxisModify->showButtons(false); xAxisModify->clear(); yAxisModify->clear(); zAxisModify->clear(); } } else { groupMode = false; if(pivotMode == PivotRelative) { xAxisModify->setValue(0); yAxisModify->setValue(0); zAxisModify->setValue(0); } else { DAVA::Entity *singleEntity = selection.GetEntity(0); if(NULL != singleEntity) { DAVA::float32 x = 0; DAVA::float32 y = 0; DAVA::float32 z = 0; DAVA::Matrix4 localMatrix = singleEntity->GetLocalTransform(); switch (modifMode) { case ST_MODIF_MOVE: { DAVA::Vector3 translation = localMatrix.GetTranslationVector(); x = translation.x; y = translation.y; z = translation.z; } break; case ST_MODIF_ROTATE: { DAVA::Vector3 pos, scale, rotate; if(localMatrix.Decomposition(pos, scale, rotate)) { x = DAVA::RadToDeg(rotate.x); y = DAVA::RadToDeg(rotate.y); z = DAVA::RadToDeg(rotate.z); } } break; case ST_MODIF_SCALE: { DAVA::Vector3 pos, scale, rotate; if(localMatrix.Decomposition(pos, scale, rotate)) { x = scale.x; y = scale.y; z = scale.z; } } break; default: break; } xAxisModify->setValue(x); yAxisModify->setValue(y); zAxisModify->setValue(z); } } } } else { xAxisModify->showButtons(true); yAxisModify->showButtons(true); zAxisModify->showButtons(true); xAxisModify->setEnabled(false); yAxisModify->setEnabled(false); zAxisModify->setEnabled(false); xAxisModify->clear(); yAxisModify->clear(); zAxisModify->clear(); } } }