The base scene node class that holds a Local->Parent transform
Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        /// Creates a scene node from a stream
        /// </summary>
        /// <param name="_Owner"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Reader"></param>
        internal Node( Scene _Owner, Node _Parent, System.IO.BinaryReader _Reader )
        {
            m_Owner = _Owner;

            //			m_NodeType = _Reader.ReadInt32();	// Don't read back the node type as it has already been consumed by the parent
            m_ID = _Reader.ReadInt32();
            m_Owner.RegisterNodeID( this );
            m_Name = _Reader.ReadString();

            m_Parent = _Parent;
            if ( _Parent != null )
                m_Parent.AddChild( this );

            // Read the matrix
            m_Local2Parent.m[0,0] = _Reader.ReadSingle();
            m_Local2Parent.m[0,1] = _Reader.ReadSingle();
            m_Local2Parent.m[0,2] = _Reader.ReadSingle();
            m_Local2Parent.m[0,3] = _Reader.ReadSingle();
            m_Local2Parent.m[1,0] = _Reader.ReadSingle();
            m_Local2Parent.m[1,1] = _Reader.ReadSingle();
            m_Local2Parent.m[1,2] = _Reader.ReadSingle();
            m_Local2Parent.m[1,3] = _Reader.ReadSingle();
            m_Local2Parent.m[2,0] = _Reader.ReadSingle();
            m_Local2Parent.m[2,1] = _Reader.ReadSingle();
            m_Local2Parent.m[2,2] = _Reader.ReadSingle();
            m_Local2Parent.m[2,3] = _Reader.ReadSingle();
            m_Local2Parent.m[3,0] = _Reader.ReadSingle();
            m_Local2Parent.m[3,1] = _Reader.ReadSingle();
            m_Local2Parent.m[3,2] = _Reader.ReadSingle();
            m_Local2Parent.m[3,3] = _Reader.ReadSingle();

            // Read specific data
            LoadSpecific( _Reader );

            // Read children
            int	ChildrenCount = _Reader.ReadInt32();
            for ( int ChildIndex=0; ChildIndex < ChildrenCount; ChildIndex++ )
            {
                NODE_TYPE	ChildType = (NODE_TYPE) _Reader.ReadByte();
                switch ( ChildType )
                {
                case NODE_TYPE.NODE:
                    new Node( _Owner, this, _Reader );
                    break;

                case NODE_TYPE.MESH:
                    new Mesh( _Owner, this, _Reader );
                    break;

                case NODE_TYPE.LIGHT:
                    new Light( _Owner, this, _Reader );
                    break;

                case NODE_TYPE.CAMERA:
                    new Camera( _Owner, this, _Reader );
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        protected Matrix4x4 m_PreviousLocal2World = Matrix4x4.Identity; // The object transform matrix from the previous frame

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates a new scene node
        /// </summary>
        /// <param name="_Owner"></param>
        /// <param name="_ID"></param>
        /// <param name="_Name"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Local2Parent"></param>
        internal Node( Scene _Owner, int _ID, string _Name, Node _Parent, Matrix4x4 _Local2Parent )
        {
            m_Owner = _Owner;
            m_ID = _ID;
            m_Name = _Name;
            m_Parent = _Parent;
            m_Local2Parent = _Local2Parent;

            // Append the node to its parent
            if ( _Parent != null )
                _Parent.AddChild( this );
        }
Ejemplo n.º 3
0
 public void AddChild( Node _Child )
 {
     m_Children.Add( _Child );
     m_bStateDirty = true;
 }
Ejemplo n.º 4
0
 public void RemoveChild( Node _Child )
 {
     m_Children.Remove( _Child );
 }
Ejemplo n.º 5
0
        protected Node FindNode( Node _Node, string _Name, bool _bCaseSensitive )
        {
            if ( _bCaseSensitive ? _Node.Name == _Name : _Node.Name.ToLower() == _Name )
                return _Node;	// Found it !

            foreach ( Node Child in _Node.Children )
            {
                Node	Result = FindNode( Child, _Name, _bCaseSensitive );
                if ( Result != null )
                    return Result;
            }

            return null;
        }
Ejemplo n.º 6
0
        protected Node FindNode( Node _Node, int _NodeID )
        {
            if ( _Node.ID == _NodeID )
                return _Node;

            foreach ( Node Child in _Node.Children )
            {
                Node	Result = FindNode( Child, _NodeID );
                if ( Result != null )
                    return Result;
            }

            return null;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Registers the node's ID and associate it to the node so we can find nodes by ID later
 /// </summary>
 /// <param name="_Node"></param>
 internal void RegisterNodeID( Node _Node )
 {
     m_ID2Node[_Node.ID] = _Node;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new camera for the scene
        /// </summary>
        /// <param name="_Name"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Local2Parent"></param>
        /// <returns></returns>
        public Camera CreateCamera( string _Name, Node _Parent, Matrix4x4 _Local2Parent )
        {
            Camera	Result = new Camera( this, m_NodeIDCounter++, _Name, _Parent, _Local2Parent );
            m_ID2Node[Result.ID] = Result;
            m_Cameras.Add( Result );

            return Result;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Custom node finder
        /// </summary>
        /// <param name="_Node"></param>
        /// <param name="_D"></param>
        /// <returns></returns>
        public Node FindNode( Node _Node,  FindNodeDelegate _D )
        {
            if ( _D( _Node ) )
                return _Node;	// Found it !

            foreach ( Node Child in _Node.Children )
            {
                Node	Result = FindNode( Child, _D );
                if ( Result != null )
                    return Result;
            }

            return null;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a scene from a stream
        /// </summary>
        /// <param name="_Reader"></param>
        /// <param name="_TextureProvider"></param>
        /// <returns></returns>
        public void Load( System.IO.BinaryReader _Reader )
        {
            // Read back textures
            ClearTextures();
            int	TexturesCount = _Reader.ReadInt32();
            for ( int TextureIndex=0; TextureIndex < TexturesCount; TextureIndex++ )
            {
                Texture2D	T = new Texture2D( this, _Reader );
                m_Textures.Add( T );
                m_URL2Texture.Add( T.URL, T );
                m_ID2Texture.Add( T.ID, T );
            }
            m_TextureIDCounter = m_Textures.Count;

            // Read back material parameters
            ClearMaterialParameters();
            int	MaterialParametersCount = _Reader.ReadInt32();
            for ( int MaterialParameterIndex=0; MaterialParameterIndex < MaterialParametersCount; MaterialParameterIndex++ )
            {
                MaterialParameters	MP = new MaterialParameters( this, _Reader );
                m_MaterialParameters.Add( MP );
                m_ID2MaterialParameters.Add( MP.ID, MP );
            }
            m_MaterialParametersIDCounter = m_MaterialParameters.Count;

            // Read back the nodes hierarchy
            ClearNodes();
            bool	bHasRoot = _Reader.ReadBoolean();
            if ( !bHasRoot )
                return;

            // Read back root type
            Node.NODE_TYPE	Type = (Node.NODE_TYPE) _Reader.ReadByte();
            switch ( Type )
            {
                case Node.NODE_TYPE.NODE:
                    m_Root = new Node( this, null, _Reader );
                    break;

                case Node.NODE_TYPE.MESH:
                    m_Root = new Mesh( this, null, _Reader );
                    m_Meshes.Add( m_Root as Mesh );
                    break;

                case Node.NODE_TYPE.LIGHT:
                    m_Root = new Light( this, null, _Reader );
                    m_Lights.Add( m_Root as Light );
                    break;

                case Node.NODE_TYPE.CAMERA:
                    m_Root = new Camera( this, null, _Reader );
                    m_Cameras.Add( m_Root as Camera );
                    break;
            }
            m_ID2Node[m_Root.ID] = m_Root;

            // Propagate state once so matrices are up to date
            m_Root.PropagateState();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new node for the scene
        /// </summary>
        /// <param name="_Name"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Local2Parent"></param>
        /// <returns></returns>
        public Node CreateNode( string _Name, Node _Parent, Matrix4x4 _Local2Parent )
        {
            Node	Result = new Node( this, m_NodeIDCounter++, _Name, _Parent, _Local2Parent );
            m_ID2Node[Result.ID] = Result;

            if ( _Parent == null )
            {	// New root ?
                if ( m_Root != null )
                    throw new Exception( "You're providing a root (i.e. no parent node) whereas there is already one ! Did you forget to clear the nodes?" );

                m_Root = Result;	// Got ourselves a new root !
            }

            return Result;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a new mesh for the scene
        /// </summary>
        /// <param name="_Name"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Local2Parent"></param>
        /// <returns></returns>
        public Mesh CreateMesh( string _Name, Node _Parent, Matrix4x4 _Local2Parent )
        {
            Mesh	Result = new Mesh( this, m_NodeIDCounter++, _Name, _Parent, _Local2Parent );
            m_ID2Node[Result.ID] = Result;
            m_Meshes.Add( Result );

            return Result;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new light for the scene
        /// </summary>
        /// <param name="_Name"></param>
        /// <param name="_Parent"></param>
        /// <param name="_Local2Parent"></param>
        /// <returns></returns>
        public Light CreateLight( string _Name, Node _Parent, Matrix4x4 _Local2Parent )
        {
            Light	Result = new Light( this, m_NodeIDCounter++, _Name, _Parent, _Local2Parent );
            m_ID2Node[Result.ID] = Result;
            m_Lights.Add( Result );

            return Result;
        }
Ejemplo n.º 14
0
 internal Mesh( Scene _Owner, int _ID, string _Name, Node _Parent, Matrix4x4 _Local2Parent )
     : base(_Owner, _ID, _Name, _Parent, _Local2Parent)
 {
 }
Ejemplo n.º 15
0
        protected Mesh FindMesh( Node _Node, string _Name, bool _bCaseSensitive )
        {
            if ( _Node is Mesh && (_bCaseSensitive ? _Node.Name == _Name : _Node.Name.ToLower() == _Name) )
                return _Node as Mesh;	// Found it !

            foreach ( Node Child in _Node.Children )
            {
                Mesh	Result = FindMesh( Child, _Name, _bCaseSensitive );
                if ( Result != null )
                    return Result;
            }

            return null;
        }
Ejemplo n.º 16
0
 internal Mesh( Scene _Owner, Node _Parent, System.IO.BinaryReader _Reader )
     : base(_Owner, _Parent, _Reader)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Clear the hierarchy of nodes
 /// </summary>
 public void ClearNodes()
 {
     if ( m_Root != null )
         m_Root.Dispose();
     m_Root = null;
     m_ID2Node.Clear();
     m_Meshes.Clear();
     m_Lights.Clear();
     m_Cameras.Clear();
     m_NodeIDCounter = 0;
 }