-void Face_getClosest(Face& face, SelectionTest& test, SelectionIntersection& bestIntersection, Face*& closestFace)
-{
- SelectionIntersection intersection;
- face.testSelect(test, intersection);
- if(intersection.valid()
- && SelectionIntersection_closer(intersection, bestIntersection))
- {
- bestIntersection = intersection;
- closestFace = &face;
- }
-}
-
-
-class OccludeSelector : public Selector
-{
- SelectionIntersection& m_bestIntersection;
- bool& m_occluded;
-public:
- OccludeSelector(SelectionIntersection& bestIntersection, bool& occluded) : m_bestIntersection(bestIntersection), m_occluded(occluded)
- {
- m_occluded = false;
- }
- void pushSelectable(Selectable& selectable)
- {
- }
- void popSelectable()
- {
- }
- void addIntersection(const SelectionIntersection& intersection)
- {
- if(SelectionIntersection_closer(intersection, m_bestIntersection))
- {
- m_bestIntersection = intersection;
- m_occluded = true;
- }
- }
-};
-
-class BrushGetClosestFaceVisibleWalker : public scene::Graph::Walker
-{
- SelectionTest& m_test;
- Face*& m_closestFace;
- mutable SelectionIntersection m_bestIntersection;
-public:
- BrushGetClosestFaceVisibleWalker(SelectionTest& test, Face*& closestFace) : m_test(test), m_closestFace(closestFace)
- {
- }
- bool pre(const scene::Path& path, scene::Instance& instance) const
- {
- if(path.top().get().visible())
- {
- BrushInstance* brush = Instance_getBrush(instance);
- if(brush != 0)
- {
- m_test.BeginMesh(brush->localToWorld());
-
- for(Brush::const_iterator i = brush->getBrush().begin(); i != brush->getBrush().end(); ++i)
- {
- Face_getClosest(*(*i), m_test, m_bestIntersection, m_closestFace);
- }
- }
- else
- {
- SelectionTestable* selectionTestable = Instance_getSelectionTestable(instance);
- if(selectionTestable)
- {
- bool occluded;
- OccludeSelector selector(m_bestIntersection, occluded);
- selectionTestable->testSelect(selector, m_test);
- if(occluded)
- {
- m_closestFace = 0;
- }
- }
- }
- }
- return true;
- }
-};
-
-Face* Scene_BrushGetClosestFace(scene::Graph& graph, SelectionTest& test)
-{
- Face* closestFace = 0;
- graph.traverse(BrushGetClosestFaceVisibleWalker(test, closestFace));
- return closestFace;
-}
-
-bool Scene_BrushGetClosestFaceTexture(scene::Graph& graph, SelectionTest& test, CopiedString& shader, TextureProjection& projection, ContentsFlagsValue& flags)
-{
- Face* face = Scene_BrushGetClosestFace(graph, test);
- if(face != 0)
- {
- shader = face->GetShader();
- face->GetTexdef(projection);
- flags = face->getShader().m_flags;
- return true;
- }
- return false;
-}
-
-void Scene_BrushSetClosestFaceTexture(scene::Graph& graph, SelectionTest& test, const char* shader, const TextureProjection& projection, const ContentsFlagsValue& flags)
-{
- Face* face = Scene_BrushGetClosestFace(graph, test);
- if(face != 0)
- {
- face->SetShader(shader);
- face->SetTexdef(projection);
- face->SetFlags(flags);
- }
-}
-
-
-class FaceTexture
-{
-public:
- TextureProjection m_projection;
- ContentsFlagsValue m_flags;
-};
-
-FaceTexture g_faceTextureClipboard;
-
-void FaceTextureClipboard_setDefault()
-{
- g_faceTextureClipboard.m_flags = ContentsFlagsValue(0, 0, 0, false);
- TexDef_Construct_Default(g_faceTextureClipboard.m_projection);
-}
-
-void TextureClipboard_textureSelected(const char* shader)
-{
- FaceTextureClipboard_setDefault();
-}
-
-class TextureBrowser;
-extern TextureBrowser g_TextureBrowser;
-void TextureBrowser_SetSelectedShader(TextureBrowser& textureBrowser, const char* shader);
-const char* TextureBrowser_GetSelectedShader(TextureBrowser& textureBrowser);
-
-void Scene_copyClosestFaceTexture(SelectionTest& test)
-{
- CopiedString shader;
- if(Scene_BrushGetClosestFaceTexture(GlobalSceneGraph(), test, shader, g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags))
- {
- TextureBrowser_SetSelectedShader(g_TextureBrowser, shader.c_str());
- }
-}
-
-void Scene_applyClosestFaceTexture(SelectionTest& test)
-{
- UndoableCommand command("facePaintTexture");
-
- Scene_BrushSetClosestFaceTexture(GlobalSceneGraph(), test, TextureBrowser_GetSelectedShader(g_TextureBrowser), g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags);
-
- SceneChangeNotify();
-}
-
-
-
-void SelectedFaces_copyTexture()
-{
- if(!g_SelectedFaceInstances.empty())
- {
- Face& face = g_SelectedFaceInstances.last().getFace();
- face.GetTexdef(g_faceTextureClipboard.m_projection);
- g_faceTextureClipboard.m_flags = face.getShader().m_flags;
-
- TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader());
- }
-}
-
-void FaceInstance_pasteTexture(FaceInstance& faceInstance)
-{
- faceInstance.getFace().SetTexdef(g_faceTextureClipboard.m_projection);
- faceInstance.getFace().SetShader(TextureBrowser_GetSelectedShader(g_TextureBrowser));
- faceInstance.getFace().SetFlags(g_faceTextureClipboard.m_flags);
- SceneChangeNotify();
-}
-
-bool SelectedFaces_empty()
-{
- return g_SelectedFaceInstances.empty();
-}
-
-void SelectedFaces_pasteTexture()
-{
- UndoableCommand command("facePasteTexture");
- g_SelectedFaceInstances.foreach(FaceInstance_pasteTexture);
-}
void Brush_registerCommands()
{
GlobalCommands_insert("SplitSelected", FreeCaller<SplitSelected>(), Accelerator(GDK_Return, (GdkModifierType)GDK_SHIFT_MASK));
GlobalCommands_insert("FlipClip", FreeCaller<FlipClipper>(), Accelerator(GDK_Return, (GdkModifierType)GDK_CONTROL_MASK));
- GlobalCommands_insert("FaceCopyTexture", FreeCaller<SelectedFaces_copyTexture>());
- GlobalCommands_insert("FacePasteTexture", FreeCaller<SelectedFaces_pasteTexture>());
-
GlobalCommands_insert("MakeDetail", FreeCaller<Select_MakeDetail>(), Accelerator('M', (GdkModifierType)GDK_CONTROL_MASK));
GlobalCommands_insert("MakeStructural", FreeCaller<Select_MakeStructural>(), Accelerator('S', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
}