Advertisement
snake5

editor mesh code (wip)

Feb 15th, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. struct EdEntMesh : EDGUILayoutRow
  2. {
  3.     FINLINE void Acquire(){ ++m_refcount; }
  4.     FINLINE void Release(){ --m_refcount; if( m_refcount <= 0 ) delete this; }
  5.     int32_t m_refcount;
  6.    
  7.     EdEntMesh() :
  8.         m_refcount( 0 ),
  9.         m_group( true, "Mesh properties" ),
  10.         m_ctlPos( V3(0), 2, V3(-8192), V3(8192) ),
  11.         m_ctlAngles( V3(0), 2, V3(0), V3(360) ),
  12.         m_ctlScaleUni( 1, 2, 0.01f, 100.0f ),
  13.         m_ctlScaleSep( V3(1), 2, V3(0.01f), V3(100.0f) )
  14.     {
  15.         tyname = "mesh";
  16.        
  17.         m_group.caption = "Mesh properties";
  18.         m_ctlPos.caption = "Position";
  19.         m_ctlAngles.caption = "Rotation";
  20.         m_ctlScaleUni.caption = "Scale (uniform)";
  21.         m_ctlScaleSep.caption = "Scale (separate)";
  22.        
  23.         m_group.Add( &m_ctlPos );
  24.         m_group.Add( &m_ctlAngles );
  25.         m_group.Add( &m_ctlScaleUni );
  26.         m_group.Add( &m_ctlScaleSep );
  27.         Add( &m_group );
  28.     }
  29.    
  30.     const Vec3& Pos() const { return m_ctlPos.m_value; }
  31.     const Vec3& RotAngles() const { return m_ctlAngles.m_value; }
  32.     float ScaleUni() const { return m_ctlScaleUni.m_value; }
  33.     const Vec3& ScaleSep() const { return m_ctlScaleSep.m_value; }
  34.    
  35.     void SetPosition( const Vec3& pos ){ m_ctlPos.SetValue( pos ); }
  36.    
  37.     EdEntMesh& operator = ( const EdEntMesh& o )
  38.     {
  39.         m_ctlPos.SetValue( o.Pos() );
  40.         m_ctlAngles.SetValue( o.RotAngles() );
  41.         m_ctlScaleUni.SetValue( o.ScaleUni() );
  42.         m_ctlScaleSep.SetValue( o.ScaleSep() );
  43.         return *this;
  44.     }
  45.    
  46.     virtual int OnEvent( EDGUIEvent* e )
  47.     {
  48.         switch( e->type )
  49.         {
  50.         case EDGUI_EVENT_PROPEDIT:
  51.             RegenerateMesh();
  52.             break;
  53.         }
  54.         return EDGUILayoutRow::OnEvent( e );
  55.     }
  56.    
  57.     void RegenerateMesh()
  58.     {
  59.         if( !cached_mesh )
  60.             cached_mesh = GR_GetMesh( "meshes/test_table.ssm" );
  61.         if( !cached_meshinst )
  62.         {
  63.             cached_meshinst = g_EdScene->CreateMeshInstance();
  64.             cached_meshinst->mesh = cached_mesh;
  65.             cached_meshinst->textures[ 0 ] = GR_GetTexture( "textures/metal0.png" );
  66.         }
  67.         cached_meshinst->matrix = Mat4::CreateSRT( m_ctlScaleSep.m_value * m_ctlScaleUni.m_value, DEG2RAD( m_ctlAngles.m_value ), m_ctlPos.m_value );
  68.     }
  69.    
  70.     bool RayIntersect( const Vec3& rpos, const Vec3& rdir, float outdst[1] )
  71.     {
  72.         return RaySphereIntersect( rpos, rdir, m_ctlPos.m_value, 1, outdst );
  73.     }
  74.    
  75.     EDGUIGroup m_group;
  76.     EDGUIPropVec3 m_ctlPos;
  77.     EDGUIPropVec3 m_ctlAngles;
  78.     EDGUIPropFloat m_ctlScaleUni;
  79.     EDGUIPropVec3 m_ctlScaleSep;
  80.    
  81.     MeshHandle cached_mesh;
  82.     MeshInstHandle cached_meshinst;
  83. };
  84. typedef Handle< EdEntMesh > EdEntMeshHandle;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement