Vec3::List getHelpVectors(const InputState& inputState) const { const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); assert(hit.isMatch()); Model::BrushFace* face = Model::hitToFace(hit); return selectHelpVectors(face, hit.hitPoint()); }
bool SetBrushFaceAttributesTool::performCopy(const InputState& inputState, const bool applyToBrush) { if (!applies(inputState)) return false; MapDocumentSPtr document = lock(m_document); const Model::BrushFaceList& selectedFaces = document->selectedBrushFaces(); if (selectedFaces.size() != 1) return false; const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* source = selectedFaces.front(); Model::BrushFace* targetFace = Model::hitToFace(hit); Model::Brush* targetBrush = targetFace->brush(); const Model::BrushFaceList targetList = applyToBrush ? targetBrush->faces() : Model::BrushFaceList(1, targetFace); const Transaction transaction(document); document->deselectAll(); document->select(targetList); if (copyAttributes(inputState)) document->setFaceAttributes(source->attribs()); else document->setTexture(source->texture()); document->deselectAll(); document->select(source); return true; }
bool CreateBrushTool::handleStartPlaneDrag(InputState& inputState, Planef& plane, Vec3f& initialPoint) { assert(m_brush == NULL); Model::EditStateManager& editStateManager = document().editStateManager(); if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone || editStateManager.selectionMode() != Model::EditStateManager::SMNone) return false; Model::FaceHit* hit = static_cast<Model::FaceHit*>(inputState.pickResult().first(Model::HitType::FaceHit, true, m_filter)); if (hit != NULL) { initialPoint = hit->hitPoint(); } else { Renderer::Camera& camera = view().camera(); initialPoint = camera.defaultPoint(inputState.pickRay().direction); } plane = Planef(Vec3f::PosZ, initialPoint); m_initialPoint = initialPoint; updateBounds(m_initialPoint); Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences(); Renderer::TextureRendererManager& textureRendererManager = document().sharedResources().textureRendererManager(); m_brushFigure = new Renderer::BrushFigure(textureRendererManager); m_brushFigure->setFaceColor(prefs.getColor(Preferences::FaceColor)); m_brushFigure->setEdgeColor(prefs.getColor(Preferences::SelectedEdgeColor)); m_brushFigure->setOccludedEdgeColor(prefs.getColor(Preferences::OccludedSelectedEdgeColor)); m_brushFigure->setEdgeMode(Renderer::BrushFigure::EMRenderOccluded); m_brush = new Model::Brush(document().map().worldBounds(), document().map().forceIntegerFacePoints(), m_bounds, document().mruTexture()); m_brushFigure->setBrush(*m_brush); return true; }
bool ResizeBrushesToolController::doStartMouseDrag(const InputState& inputState) { if (!handleInput(inputState)) return false; const bool split = inputState.modifierKeysDown(ModifierKeys::MKCtrlCmd); if (m_tool->beginResize(inputState.pickResult(), split)) { updateDragFaces(inputState); return true; } return false; }
bool doGetNewClipPointPosition(const InputState& inputState, Vec3& position) const { const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* face = hit.target<Model::BrushFace*>(); const Grid& grid = m_tool->grid(); position = grid.snap(hit.hitPoint(), face->boundary()); return true; }
void UVRotateTool::doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch) { if (!m_helper.valid()) return; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& angleHandleHit = pickResult.query().type(AngleHandleHit).occluded().first(); const bool highlight = angleHandleHit.isMatch() || thisToolDragging(); renderBatch.addOneShot(new Render(m_helper, CenterHandleRadius, RotateHandleRadius, highlight)); }
RestrictedDragPolicy::DragInfo ClipToolController::MoveClipPointPart::doStartDrag(const InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return DragInfo(); Vec3 initialPoint; if (!m_callback->tool()->beginDragPoint(inputState.pickResult(), initialPoint)) return DragInfo(); DragRestricter* restricter = m_callback->createDragRestricter(inputState, initialPoint); DragSnapper* snapper = m_callback->createDragSnapper(inputState); return DragInfo(restricter, snapper, initialPoint); }
void RotateObjectsTool::handleRender(InputState& inputState, Renderer::Vbo& vbo, Renderer::RenderContext& renderContext) { Model::EditStateManager& editStateManager = document().editStateManager(); if (editStateManager.selectedEntities().empty() && editStateManager.selectedBrushes().empty()) return; Model::RotateHandleHit* hit = NULL; if (m_rotateHandle.locked()) hit = m_rotateHandle.lastHit(); else hit = static_cast<Model::RotateHandleHit*>(inputState.pickResult().first(Model::HitType::RotateHandleHit, true, view().filter())); m_rotateHandle.render(hit, vbo, renderContext, m_angle); }
MoveObjectsToolController::MoveInfo MoveObjectsToolController::doStartMove(const InputState& inputState) { if (!inputState.modifierKeysPressed(ModifierKeys::MKNone) && !inputState.modifierKeysPressed(ModifierKeys::MKAlt) && !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd) && !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd | ModifierKeys::MKAlt)) return MoveInfo(); const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Group::GroupHit | Model::Entity::EntityHit | Model::Brush::BrushHit).selected().first(); if (!hit.isMatch()) return MoveInfo(); if (!m_tool->startMove(inputState)) return MoveInfo(); return MoveInfo(hit.hitPoint()); }
bool CameraTool::handleStartDrag(InputState& inputState) { if (inputState.mouseButtons() == MouseButtons::MBRight) { if (inputState.modifierKeys() == ModifierKeys::MKAlt) { Model::Hit* hit = inputState.pickResult().first(Model::HitType::ObjectHit, true, m_filter); if (hit != NULL) m_orbitCenter = hit->hitPoint(); else m_orbitCenter = inputState.camera().defaultPoint(); m_orbit = true; return true; } else if (inputState.modifierKeys() == ModifierKeys::MKNone) { return true; } } else if (inputState.mouseButtons() == MouseButtons::MBMiddle && (inputState.modifierKeys() == ModifierKeys::MKNone || inputState.modifierKeys() == ModifierKeys::MKAlt)) { return true; } return false; }
bool RotateObjectsTool::handleStartDrag(InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return false; Model::EditStateManager& editStateManager = document().editStateManager(); const Model::EntityList& entities = editStateManager.selectedEntities(); const Model::BrushList& brushes = editStateManager.selectedBrushes(); if (entities.empty() && brushes.empty()) return false; Model::RotateHandleHit* hit = static_cast<Model::RotateHandleHit*>(inputState.pickResult().first(Model::HitType::RotateHandleHit, true, view().filter())); if (hit == NULL) return false; Vec3f test = hit->hitPoint() - m_rotateHandle.position(); switch (hit->hitArea()) { case Model::RotateHandleHit::HAXAxis: m_axis = Vec3f::PosX; m_invert = ((test.dot(Vec3f::PosX) > 0.0f) == (test.dot(Vec3f::PosY) > 0.0f)); break; case Model::RotateHandleHit::HAYAxis: m_axis = Vec3f::PosY; m_invert = ((test.dot(Vec3f::PosX) > 0.0f) != (test.dot(Vec3f::PosY) > 0.0f)); break; case Model::RotateHandleHit::HAZAxis: m_axis = Vec3f::PosZ; m_invert = false; break; } m_startX = inputState.x(); m_startY = inputState.y(); m_angle = 0.0f; m_center = m_rotateHandle.position(); m_rotateHandle.lock(); beginCommandGroup(Controller::Command::makeObjectActionName(wxT("Rotate"), entities, brushes)); return true; }
void CreateEntityTool::updateEntityPosition(InputState& inputState) { assert(m_entity != NULL); Utility::Grid& grid = document().grid(); Model::FaceHit* hit = static_cast<Model::FaceHit*>(inputState.pickResult().first(Model::HitType::FaceHit, true, view().filter())); Vec3f delta; if (hit == NULL) { Vec3f newPosition = inputState.camera().defaultPoint(inputState.pickRay().direction); const Vec3f& center = m_entity->bounds().center(); delta = grid.moveDeltaForEntity(center, document().map().worldBounds(), newPosition - center); } else { Model::Face& face = hit->face(); delta = grid.moveDeltaForEntity(face, m_entity->bounds(), document().map().worldBounds(), inputState.pickRay(), hit->hitPoint()); } if (delta.null()) return; m_entity->setProperty(Model::Entity::OriginKey, m_entity->origin() + delta, true); m_entityFigure->invalidate(); }
DragInfo doStartDrag(const InputState& inputState) { if (inputState.modifierKeysDown(ModifierKeys::MKShift)) return DragInfo(); const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return DragInfo(); m_oldPolyhedron = m_tool->polyhedron(); const Model::BrushFace* face = Model::hitToFace(hit); m_plane = face->boundary(); m_initialPoint = hit.hitPoint(); updatePolyhedron(m_initialPoint); SurfaceDragRestricter* restricter = new SurfaceDragRestricter(); restricter->setPickable(true); restricter->setType(Model::Brush::BrushHit); restricter->setOccluded(true); return DragInfo(restricter, new NoDragSnapper(), m_initialPoint); }
bool CreateComplexBrushToolController3D::doMouseDoubleClick(const InputState& inputState) { if (!inputState.mouseButtonsDown(MouseButtons::MBLeft)) return false; if (!inputState.checkModifierKeys(MK_No, MK_No, MK_No)) return false; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Polyhedron3 polyhedron = m_tool->polyhedron(); const Model::BrushFace* face = Model::hitToFace(hit); const Model::BrushFace::VertexList vertices = face->vertices(); Model::BrushFace::VertexList::const_iterator it, end; for (it = vertices.begin(), end = vertices.end(); it != end; ++it) polyhedron.addPoint((*it)->position()); m_tool->update(polyhedron); return true; }
bool CreateComplexBrushToolController3D::doMouseClick(const InputState& inputState) { if (!inputState.mouseButtonsDown(MouseButtons::MBLeft)) return false; if (!inputState.checkModifierKeys(MK_No, MK_No, MK_No)) return false; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; const Grid& grid = m_tool->grid(); const Model::BrushFace* face = Model::hitToFace(hit); const Vec3 snapped = grid.snap(hit.hitPoint(), face->boundary()); Polyhedron3 polyhedron = m_tool->polyhedron(); polyhedron.addPoint(snapped); m_tool->update(polyhedron); return true; }
bool UVRotateTool::doStartMouseDrag(const InputState& inputState) { assert(m_helper.valid()); if (!inputState.modifierKeysPressed(ModifierKeys::MKNone) || !inputState.mouseButtonsPressed(MouseButtons::MBLeft)) return false; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& angleHandleHit = pickResult.query().type(AngleHandleHit).occluded().first(); if (!angleHandleHit.isMatch()) return false; const Model::BrushFace* face = m_helper.face(); const Mat4x4 toFace = face->toTexCoordSystemMatrix(Vec2f::Null, Vec2f::One, true); const Vec2f hitPointInFaceCoords(toFace * angleHandleHit.hitPoint()); m_initalAngle = measureAngle(hitPointInFaceCoords) - face->rotation(); MapDocumentSPtr document = lock(m_document); document->beginTransaction("Rotate Texture"); return true; }
void RotateObjectsTool::handlePick(InputState& inputState) { Model::RotateHandleHit* hit = m_rotateHandle.pick(inputState.pickRay()); if (hit != NULL) inputState.pickResult().add(hit); }
void ClipToolController::doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch) { m_tool->render(renderContext, renderBatch, inputState.pickResult()); ToolControllerGroup::doRender(inputState, renderContext, renderBatch); }
void ResizeBrushesToolController::updateDragFaces(const InputState& inputState) { if (!anyToolDragging(inputState)) m_tool->updateDragFaces(inputState.pickResult()); }
void CreateEntityToolController3D::doUpdateEntityPosition(const InputState& inputState) { m_tool->updateEntityPosition3D(inputState.pickRay(), inputState.pickResult()); }