示例#1
0
        public void Render(RenderEngineComponent renderEngine, Matrix parentWorld)
        {
            var skeleton = AnimationProvider.Skeleton;

            if (skeleton != null)
            {
                Name = AnimationProvider.Skeleton.SkeletonName;
            }
            else
            {
                Name = "Skeleton ";
            }

            if (IsVisible && skeleton != null /* && _animationProvider.IsActive*/)
            {
                _lineRenderer.Clear();

                for (int i = 0; i < skeleton.BoneCount; i++)
                {
                    var parentIndex = skeleton.GetParentBone(i);
                    if (parentIndex == -1)
                    {
                        var boneMatrix2 = skeleton.GetAnimatedWorldTranform(i);
                        _lineRenderer.AddCube(Matrix.CreateScale(SkeletonScale) * Matrix.CreateScale(0.05f) * boneMatrix2 * parentWorld, NodeColour);
                        continue;
                    }


                    float scale      = SkeletonScale;
                    Color drawColour = NodeColour;
                    if (SelectedBoneIndex.HasValue && SelectedBoneIndex.Value == i)
                    {
                        drawColour = SelectedNodeColour;
                        scale     *= 1.5f;
                    }

                    var boneMatrix       = skeleton.GetAnimatedWorldTranform(i);
                    var parentBoneMatrix = skeleton.GetAnimatedWorldTranform(parentIndex);

                    _lineRenderer.AddCube(Matrix.CreateScale(scale) * Matrix.CreateScale(0.05f) * boneMatrix * parentWorld, drawColour);
                    _lineRenderer.AddLine(Vector3.Transform(boneMatrix.Translation, parentWorld), Vector3.Transform(parentBoneMatrix.Translation, parentWorld));
                }

                renderEngine.AddRenderItem(RenderBuckedId.Line, new LineRenderItem()
                {
                    LineMesh = _lineRenderer, World = Matrix.Identity
                });
            }
        }
        public override void Draw(GameTime gameTime)
        {
            var selectionState = GetState();

            _lineGeometry.Clear();
            if (selectionState is ObjectSelectionState objectSelectionState)
            {
                foreach (var item in objectSelectionState.CurrentSelection())
                {
                    _lineGeometry.AddBoundingBox(item.Geometry.BoundingBox);
                    _renderEngine.AddRenderItem(RenderBuckedId.Selection, new LineRenderItem()
                    {
                        World = item.ModelMatrix, LineMesh = _lineGeometry
                    });
                }
            }

            if (selectionState is FaceSelectionState selectionFaceState && selectionFaceState.RenderObject is Rmv2MeshNode meshNode)
            {
                _renderEngine.AddRenderItem(RenderBuckedId.Selection, new GeoRenderItem()
                {
                    ModelMatrix = meshNode.ModelMatrix, Geometry = meshNode.Geometry, Shader = _selectedFacesEffect, Faces = selectionFaceState.SelectedFaces
                });
                _renderEngine.AddRenderItem(RenderBuckedId.Wireframe, new GeoRenderItem()
                {
                    ModelMatrix = meshNode.ModelMatrix, Geometry = meshNode.Geometry, Shader = _wireframeEffect
                });
            }

            if (selectionState is VertexSelectionState selectionVertexState && selectionVertexState.RenderObject != null)
            {
                var vertexObject = selectionVertexState.RenderObject as Rmv2MeshNode;
                _renderEngine.AddRenderItem(RenderBuckedId.Selection, new VertexRenderItem()
                {
                    Node = vertexObject, World = vertexObject.ModelMatrix, SelectedVertices = selectionVertexState.SelectedVertices, VertexRenderer = VertexRenderer
                });
                _renderEngine.AddRenderItem(RenderBuckedId.Wireframe, new GeoRenderItem()
                {
                    ModelMatrix = vertexObject.ModelMatrix, Geometry = vertexObject.Geometry, Shader = _wireframeEffect
                });
            }

            base.Draw(gameTime);
        }