Ejemplo n.º 1
0
 public override void AddToRenderChain(RenderChain chain)
 {
 }
Ejemplo n.º 2
0
        private MorphableMesh NodeContentsToMorphableMesh(Node node, MorphingInterval interval)
        {
            var savedRenderList = Renderer.CurrentRenderList;

            Widget.RenderTransparentWidgets = true;
            try {
                var renderList = new RenderList();
                Renderer.CurrentRenderList = renderList;
                var  renderChain      = new RenderChain();
                var  mesh             = new MorphableMesh();
                int  vertexCount      = 0;
                int  indexCount       = 0;
                bool isFirstTimeStamp = true;
                foreach (var time in interval.Timestamps)
                {
                    node.AnimationTime = time;
                    node.Update(0);
                    node.RenderChainBuilder?.AddToRenderChain(renderChain);
                    renderChain.RenderAndClear();
                    int vc = 0;
                    int ic = 0;
                    foreach (var batch in renderList.Batches)
                    {
                        vc += batch.LastVertex;
                        ic += batch.LastIndex;
                    }
                    if (isFirstTimeStamp)
                    {
                        vertexCount = vc;
                        indexCount  = ic;
                    }
                    else
                    {
                        if (vc != vertexCount || ic != indexCount)
                        {
                            throw new InvalidOperationException("Inconsistent number of vertices or indices");
                        }
                    }
                    if (isFirstTimeStamp)
                    {
                        mesh.UVBuffer = new VertexBuffer <Vector2> {
                            Data = new Vector2[vertexCount]
                        };
                        mesh.IndexBuffer = new IndexBuffer {
                            Data = new ushort[indexCount]
                        };
                    }
                    var morphTarget = new MorphableMesh.MorphTarget {
                        Timestamp      = time,
                        PosColorBuffer = new VertexBuffer <MorphableMesh.PosColor> {
                            Data = new MorphableMesh.PosColor[vertexCount]
                        }
                    };
                    mesh.MorphTargets.Add(morphTarget);
                    int currentVertex = 0;
                    int currentIndex  = 0;
                    foreach (var batch in renderList.Batches)
                    {
                        CopyPosColorData(batch.VertexBuffer.Data, morphTarget.PosColorBuffer.Data, currentVertex, batch.LastVertex);
                        throw new NotImplementedException();
                        //if (isFirstTimeStamp) {
                        //	var mbatch = new MorphableMesh.RenderBatch {
                        //		Texture = batch.Texture1,
                        //		Blending = batch.Blending,
                        //		Shader = batch.Shader,
                        //		StartIndex = batch.StartIndex + currentIndex,
                        //		IndexCount = batch.LastIndex - batch.StartIndex,
                        //	};
                        //	mesh.Batches.Add(mbatch);
                        //	CopyUV1Data(batch.VertexBuffer.Data, mesh.UVBuffer.Data, currentVertex, batch.LastVertex);
                        //	CopyIndices(batch.IndexBuffer.Data, mesh.IndexBuffer.Data, currentIndex, batch.LastIndex, (ushort)currentVertex);
                        //}
                        currentVertex += batch.LastVertex;
                        currentIndex  += batch.LastIndex;
                    }
                    renderList.Clear();
                    isFirstTimeStamp = false;
                }
                return(mesh);
            } finally {
                Renderer.CurrentRenderList      = savedRenderList;
                Widget.RenderTransparentWidgets = false;
            }
        }
Ejemplo n.º 3
0
        public void Render(Matrix44 lightView, Matrix44 lightViewProjection, WindowRect lightViewport)
        {
            depthmat.ViewProjection = lightViewProjection;
            map.SetAsRenderTarget();

            Renderer.Clear(1.0f, 1.0f, 1.0f, 1.0f);

            var oldViewport      = Renderer.Viewport;
            var oldWorld         = Renderer.World;
            var oldView          = Renderer.View;
            var oldProj          = Renderer.Projection;
            var oldZTestEnabled  = Renderer.ZTestEnabled;
            var oldZWriteEnabled = Renderer.ZWriteEnabled;
            var oldCullMode      = Renderer.CullMode;

            Renderer.Flush();
            Renderer.Viewport     = lightViewport;
            Renderer.ZTestEnabled = true;

            var list  = new List <RenderItem>();
            var chain = new RenderChain();

            foreach (var node in viewport.Nodes)
            {
                node.AddToRenderChain(chain);
            }

            for (var i = 0; i < RenderChain.LayerCount; i++)
            {
                var layer = chain.Layers[i];
                if (layer == null || layer.Count == 0)
                {
                    continue;
                }
                for (var j = 0; j < layer.Count; j++)
                {
                    var node = layer[j].Node.AsNode3D;
                    list.Add(new RenderItem {
                        Node     = node,
                        Distance = lightView.TransformVector(node.GlobalTransform.Translation).Z
                    });
                }

                list.Sort(RenderOrderComparers.FrontToBack);
                for (int j = 0; j < list.Count; ++j)
                {
                    RenderNode(list[j].Node);
                }
            }

            chain.Clear();

            Renderer.World         = oldWorld;
            Renderer.Viewport      = oldViewport;
            Renderer.View          = oldView;
            Renderer.Projection    = oldProj;
            Renderer.ZTestEnabled  = oldZTestEnabled;
            Renderer.ZWriteEnabled = oldZWriteEnabled;
            Renderer.CullMode      = oldCullMode;

            map.RestoreRenderTarget();
        }
Ejemplo n.º 4
0
 private void EnsureRenderChain()
 {
     renderChain = renderChain ?? new RenderChain();
 }