The texture 2D class wraps a standard Nuaj texture and attaches a unique URL and ID to it so it can be serialized
Exemple #1
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();
        }
Exemple #2
0
        /// <summary>
        /// Creates a new texture for the scene
        /// </summary>
        /// <param name="_URL">The relative texture URL to identify the texture</param>
        /// <param name="_OpacityURL">The optional relative URL to identify the opacity texture</param>
        /// <param name="_bCreateMipMaps">True if the texture should be created using mip-maps</param>
        /// <param name="_TextureProvider">The texture provider capable of creating the actual texture</param>
        /// <returns></returns>
        public Texture2D CreateTexture( string _URL, string _OpacityURL, bool _bCreateMipMaps )
        {
            string	FullURL = _URL + "|" + _OpacityURL;	// The full URL is a concatenation of both URLs
            if ( m_URL2Texture.ContainsKey( FullURL ) )
                return m_URL2Texture[FullURL];	// Already registered...

            Texture2D	Result = new Texture2D( this, m_TextureIDCounter++, _URL, _OpacityURL, _bCreateMipMaps );
            m_Textures.Add( Result );
            m_URL2Texture[FullURL] = Result;
            m_ID2Texture[Result.ID] = Result;

            return Result;
        }
        /// <summary>
        ///  Removes a texture parameter (called by one of our TextureParameter which was assigned a texture)
        /// </summary>
        /// <param name="_Texture"></param>
        protected void RemoveTextureParameter( Texture2D _Texture )
        {
            if ( _Texture == null || !m_TextureParameters.Contains( _Texture ) )
                return;

            m_TextureParameters.Remove( _Texture );
        }
 public override void Load( System.IO.BinaryReader _Reader )
 {
     int	TextureID = _Reader.ReadInt32();
     Value = m_Owner.m_Owner.FindTexture( TextureID );
 }
        /// <summary>
        ///  Adds a texture parameter (called by one of our TextureParameter which was assigned a texture)
        /// </summary>
        /// <param name="_Texture"></param>
        protected void AddTextureParameter( Texture2D _Texture )
        {
            if ( _Texture == null )
                return;

            m_TextureParameters.Add( _Texture );
        }