コード例 #1
0
        public override void Draw(GameTime time)
        {
            // Clear all pipelines from previously collected models
            foreach (var pipeline in renderSystem.Pipelines)
            {
                var renderMeshState = pipeline.GetOrCreateModelRendererState();
                renderMeshState.RenderModels.Clear();
            }

            // Collect models for this frame
            foreach (var matchingEntity in enabledEntities)
            {
                // Skip model not enabled
                if (!matchingEntity.Value.ModelComponent.Enabled)
                {
                    continue;
                }

                var modelViewHierarchy = matchingEntity.Value.ModelComponent.ModelViewHierarchy;

                var transformationComponent = matchingEntity.Value.TransformationComponent;

                var links = matchingEntity.Value.Links;

                // Update model view hierarchy node matrices
                modelViewHierarchy.NodeTransformations[0].LocalMatrix = transformationComponent.WorldMatrix;
                modelViewHierarchy.UpdateMatrices();

                if (links != null)
                {
                    // Update links: transfer node/bone transformation to a specific entity transformation
                    // Then update this entity transformation tree
                    // TODO: Ideally, we should order update (matchingEntities?) to avoid updating a ModelViewHierarchy before its transformation is updated.
                    foreach (var link in matchingEntity.Value.Links)
                    {
                        var linkTransformation = link.Entity.Transformation;
                        linkTransformation.LocalMatrix = modelViewHierarchy.NodeTransformations[link.NodeIndex].WorldMatrix;

                        linkTransformationToUpdate.Clear();
                        linkTransformationToUpdate.Add(linkTransformation);
                        TransformationProcessor.UpdateTransformations(linkTransformationToUpdate, false);
                    }
                }

                foreach (var renderModelEntry in matchingEntity.Value.RenderModels)
                {
                    var renderModelState = renderModelEntry.Key;
                    var renderModel      = renderModelEntry.Value;

                    // Add model to rendering
                    renderModelState.RenderModels.Add(renderModel);

                    // Upload matrices to TransformationKeys.World
                    modelViewHierarchy.UpdateToRenderModel(renderModel);

                    // Upload skinning blend matrices
                    MeshSkinningUpdater.Update(modelViewHierarchy, renderModel);
                }
            }
        }
コード例 #2
0
ファイル: FBXTestGame.cs プロジェクト: yongweisun/paradox
        protected override void Update(GameTime time)
        {
            if (mvh != null)
            {
                mvh.UpdateMatrices();
                mvh.UpdateToRenderModel(renderModel);

                MeshSkinningUpdater.Update(mvh, renderModel);
            }

            base.Update(time);
        }