FBX.Scene.Nodes.Node.PropagateState C# (CSharp) Method

PropagateState() public method

Propagates this node's state to its children (e.g. visibility, Local2World transform, etc.) This should be done only once per frame and is usually automatically taken care of by the renderer
public PropagateState ( ) : bool
return bool
        public virtual bool PropagateState()
        {
            bool	bModified = false;
            if ( m_bStateDirty )
            {
                m_PreviousLocal2World = m_Local2World;	// Current becomes previous...
                m_bDeltaMotionDirty = true;				// Delta values become dirty...

                if ( m_Parent == null )
                {
                    m_bPropagatedVisibility = m_bVisible;						// Use our own visibility
                    m_Local2World = m_Local2Parent;								// Use our own transform
                }
                else
                {
                    m_bPropagatedVisibility = m_Parent.m_bVisible;				// Use parent's visibility
                    m_Local2World = m_Local2Parent * m_Parent.m_Local2World;	// Compose with parent...
                }

                if ( m_bFirstLocal2WorldAssignment )
                    m_PreviousLocal2World = m_Local2World;	// For first assignment, previous & current matrices are the same !

                m_bStateDirty = false;	// We're good !
                m_bFirstLocal2WorldAssignment = false;
                bModified = true;
            }

            // Propagate to children
            foreach ( Node Child in m_Children )
                bModified |= Child.PropagateState();

            // Notify of propagation
            if ( bModified && StatePropagated != null )
                StatePropagated( this, EventArgs.Empty );

            return bModified;
        }

Usage Example

示例#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();
        }