Changeset 381

Show
Ignore:
Timestamp:
09/15/11 13:49:12 (8 months ago)
Author:
Carsten
Message:

Model Editor:
Added automatic alignment of the ground plane to the bottom of the model, taking the current animation sequence into account.
This makes inspecting a model a lot more convenient. :-)

Location:
cafu/trunk/CaWE/ModelEditor
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp

    r345 r381  
    6363ModelEditor::ModelDocumentT::ModelDocumentT(GameConfigT* GameConfig, const wxString& FileName) 
    6464    : m_Model(LoadModel(FileName)), 
     65      m_SequenceBB(m_Model->GetBB(-1, 0.0f)), 
    6566      m_Submodels(), 
    6667      m_Gui(new cf::GuiSys::GuiImplT("Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
     
    106107    delete m_Gui; 
    107108    delete m_Model; 
     109} 
     110 
     111 
     112void ModelEditor::ModelDocumentT::SetSelection(ModelElementTypeT Type, const ArrayT<unsigned int>& NewSel) 
     113{ 
     114    wxASSERT(Type<4); 
     115    m_Selection[Type]=NewSel; 
     116 
     117    if (Type==ANIM) 
     118    { 
     119        if (m_Selection[ANIM].Size()==0) 
     120        { 
     121            m_SequenceBB=m_Model->GetBB(-1, 0.0f); 
     122        } 
     123        else 
     124        { 
     125            m_SequenceBB=BoundingBox3fT(); 
     126 
     127            for (unsigned long SelNr=0; SelNr<m_Selection[ANIM].Size(); SelNr++) 
     128            { 
     129                const CafuModelT::AnimT& Anim=m_Model->GetAnims()[m_Selection[ANIM][SelNr]]; 
     130 
     131                for (unsigned long FrameNr=0; FrameNr<Anim.Frames.Size(); FrameNr++) 
     132                    m_SequenceBB+=Anim.Frames[FrameNr].BB; 
     133            } 
     134        } 
     135    } 
    108136} 
    109137 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.hpp

    r345 r381  
    2525#include "ObserverPattern.hpp" 
    2626#include "ElementTypes.hpp" 
     27#include "Math3D/BoundingBox.hpp" 
    2728#include "Math3D/Vector3.hpp" 
    2829#include "Templates/Array.hpp" 
     
    102103        const CafuModelT*               GetModel() const           { return m_Model; } 
    103104        const ArrayT<unsigned int>&     GetSelection(ModelElementTypeT Type) const { wxASSERT(Type<4); return m_Selection[Type]; } 
     105        const BoundingBox3fT&           GetSequenceBB() const      { return m_SequenceBB; } 
    104106        const ArrayT<EditorMaterialI*>& GetEditorMaterials() const { return m_EditorMaterials; } 
    105107        const AnimStateT&               GetAnimState() const       { return m_AnimState; } 
     
    112114 
    113115        CafuModelT*      GetModel()      { return m_Model; } 
    114         void             SetSelection(ModelElementTypeT Type, const ArrayT<unsigned int>& NewSel) { wxASSERT(Type<4); m_Selection[Type]=NewSel; } 
     116        void             SetSelection(ModelElementTypeT Type, const ArrayT<unsigned int>& NewSel); 
    115117        AnimStateT&      GetAnimState()  { return m_AnimState; } 
    116118        void             LoadSubmodel(const wxString& FileName); 
     
    134136        CafuModelT*              m_Model;           ///< The model that is being edited. 
    135137        ArrayT<unsigned int>     m_Selection[4];    ///< The selected joints, meshes, animations and GUI fixtures. 
     138        BoundingBox3fT           m_SequenceBB;      ///< The bounding-box encompassing all frames of the currently selected animation sequence(s). 
    136139        ArrayT<EditorMaterialI*> m_EditorMaterials; ///< One editor material for each material in the model (its material manager). 
    137140        AnimStateT               m_AnimState;       ///< The current state of the model animation. 
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.cpp

    r380 r381  
    4747      m_GridSpacing(Options.Grid.InitialSpacing), 
    4848      m_GroundPlane_Show(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/GroundPlane_Show", 1l)!=0), 
     49      m_GroundPlane_PosZ(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/GroundPlane_PosZ", 0.0f)), 
     50      m_GroundPlane_AutoZ(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/GroundPlane_AutoZ", 1l)!=0), 
    4951      m_Model_ShowMesh(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowMesh", 1l)!=0), 
    5052      m_Model_ShowSkeleton(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowSkeleton", 0l)!=0), 
     
    118120    wxPGProperty* GroundPlane=AppendIn(SceneElemsCat, new wxStringProperty("Ground Plane", wxPG_LABEL, "<composed>")); 
    119121    AppendIn(GroundPlane, new wxBoolProperty("Show", wxPG_LABEL, m_GroundPlane_Show)); 
    120     AppendIn(GroundPlane, new wxFloatProperty("Height (z-Pos)", wxPG_LABEL, Ground->GetBB().Max.z)); 
     122    AppendIn(GroundPlane, new wxFloatProperty("Height (z-Pos)", wxPG_LABEL, m_GroundPlane_PosZ)); 
     123    AppendIn(GroundPlane, new wxBoolProperty("Auto Height", wxPG_LABEL, m_GroundPlane_AutoZ)); 
    121124    AppendIn(GroundPlane, new wxStringProperty("Material", wxPG_LABEL, Ground->GetFaces()[0].GetMaterial()->GetName()));   // TODO: MaterialProperty 
    122125 
     
    199202    else if (PropName=="Camera.Advanced.far plane dist")  Camera.FarPlaneDist=PropValueF; 
    200203    else if (PropName=="Ground Plane.Show")               m_GroundPlane_Show=Prop->GetValue().GetBool(); 
    201     else if (PropName=="Ground Plane.Height (z-Pos)") 
    202     { 
    203         Ground->TrafoMove(Vector3fT(0, 0, PropValueF - Ground->GetBB().Max.z)); 
    204     } 
     204    else if (PropName=="Ground Plane.Height (z-Pos)")     m_GroundPlane_PosZ=PropValueF; 
     205    else if (PropName=="Ground Plane.Auto Height")        m_GroundPlane_AutoZ=Prop->GetValue().GetBool(); 
    205206    else if (PropName=="Ground Plane.Material") 
    206207    { 
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.hpp

    r380 r381  
    5454        float                m_GridSpacing; 
    5555        bool                 m_GroundPlane_Show; 
     56        float                m_GroundPlane_PosZ; 
     57        bool                 m_GroundPlane_AutoZ; 
    5658        bool                 m_Model_ShowMesh; 
    5759        bool                 m_Model_ShowSkeleton; 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r380 r381  
    578578    MatSys::Renderer->SetCurrentLightDirMap(NULL);    // The MatSys provides a default for LightDirMaps when NULL is set. 
    579579 
     580    // Update the z-position of the ground plane. 
     581    if (ScenePropGrid->m_GroundPlane_Show) 
     582    { 
     583        MapBrushT*  Ground=m_Parent->GetModelDoc()->GetGround(); 
     584        const float DeltaZ=(ScenePropGrid->m_GroundPlane_AutoZ 
     585            ? m_Parent->GetModelDoc()->GetSequenceBB().Min.z 
     586            : ScenePropGrid->m_GroundPlane_PosZ) - Ground->GetBB().Max.z; 
     587 
     588        if (fabs(DeltaZ) > 0.0001f) 
     589            Ground->TrafoMove(Vector3fT(0, 0, DeltaZ)); 
     590    } 
     591 
    580592    // Render the world axes. They're great for technical and emotional reassurance. 
    581593    if (ScenePropGrid->m_ShowOrigin)