/// <summary> /// Sets the model that this object was instanced from /// </summary> public ModelInstance( Model source ) { m_Source = source; // Set up the animation layers if ( source.Animations == null ) { return; } m_Layers = new AnimationLayer[ ( int )ModelPart.NumParts ]; for ( int layerIndex = 0; layerIndex < ( int )ModelPart.NumParts; ++layerIndex ) { m_ReferencePoints[ layerIndex ] = new ReferencePoint( ( ModelPart )layerIndex ); ModelMesh partMesh = source.GetPartMesh( ( ModelPart )layerIndex ); if ( partMesh == null ) { continue; } if ( source.Animations != null ) { // TODO: This assigns the entire animation set to each layer, which isn't correct (although it'll work OK) m_Layers[ layerIndex ] = new AnimationLayer( source.Animations, ( ModelPart )layerIndex ); } } }
/// <summary> /// Renders the model with a particular set of animation layers /// </summary> public void Render( IRenderContext context, AnimationLayer[] layers, ModelInstance.ReferencePoint[] refPoints ) { if ( m_RaiseRootMeshToFloor ) { ModelMesh.FrameInfo frame = m_RootMesh.GetAnimationFrame( layers ); Graphics.Renderer.Translate( TransformType.LocalToWorld, 0, -frame.MinBounds.Y, 0 ); } m_RootMesh.Render( context, layers, refPoints ); }
/// <summary> /// Renders this mesh using the given context and animation setup /// </summary> public void Render( IRenderContext context, AnimationLayer[] layers, ModelInstance.ReferencePoint[] refPoints ) { // Determine the current animation frame int currentFrame = DefaultFrame; if ( layers != null ) { currentFrame = ( layers[ ( int )Part ].CurrentAnimationFrame ); } // DrawMeshBounds( layers ); // Assign texture sampler parameters // TODO: This should be part of the render technique ITexture2d lastTexture = null; for ( int surfaceIndex = 0; surfaceIndex < m_Surfaces.Length; ++surfaceIndex ) { Surface curSurface = m_Surfaces[ surfaceIndex ]; if ( curSurface.Texture != lastTexture ) { if ( lastTexture != null ) { Graphics.Renderer.UnbindTexture( lastTexture ); } Graphics.Renderer.BindTexture( curSurface.Texture ); lastTexture = curSurface.Texture; } if ( m_TextureParameter != null ) { m_TextureParameter.Set( curSurface.Texture ); } m_SurfaceRenderer.CurrentSurface = curSurface; m_SurfaceRenderer.CurrentFrame = curSurface.SurfaceFrames[ currentFrame ]; m_Technique.Apply( context, m_SurfaceRenderer ); } if ( lastTexture != null ) { Graphics.Renderer.UnbindTexture( lastTexture ); } foreach ( NestedPart nestedPart in m_NestedParts ) { FrameInfo curFrame = FrameInfoList[ currentFrame ]; Tag transformTag = curFrame.Tags[ nestedPart.m_TransformTagIndex ]; Matrix44 transform = transformTag.Transform; Graphics.Renderer.PushTransform( TransformType.LocalToWorld, transform ); ModelMesh nestedMesh = m_Model.GetPartMesh( nestedPart.m_Part ); if ( nestedMesh != null ) { nestedMesh.Render( context, layers, refPoints ); } ModelInstance.ReferencePoint refPt = refPoints[ ( int )nestedPart.m_Part ]; if ( refPt != null ) { refPt.Render( context ); } Graphics.Renderer.PopTransform( TransformType.LocalToWorld ); } }
/// <summary> /// Gets information about the current animation frame /// </summary> /// <param name="layers">Animation layers</param> /// <returns>Returns frame information for the current animation frame</returns> public FrameInfo GetAnimationFrame( AnimationLayer[] layers ) { int index = ( layers == null ) ? DefaultFrame : layers[ ( int )Part ].CurrentAnimationFrame; return FrameInfoList[ index ]; }
/// <summary> /// Debug routing for drawing the bounds of this mesh /// </summary> /// <param name="layers">Animation layer set</param> public void DrawMeshBounds( AnimationLayer[] layers ) { FrameInfo frame = GetAnimationFrame( layers ); Graphics.Draw.AlignedBox( m_BoundsDraw, frame.MinBounds, frame.MaxBounds ); }
/// <summary> /// Adds an animation layer to the control /// </summary> public void AddLayer( AnimationLayer layer ) { m_Layers.Add( layer ); }