예제 #1
0
        public override void Render()
        {
            var           parentWidget  = Parent.AsWidget;
            var           animationTime = parentWidget.AnimationTime;
            MorphableMesh mesh          = null;

            while (true)
            {
                mesh = Meshes[currMeshIndex];
                if (animationTime < mesh.LeftBound)
                {
                    if (currMeshIndex == 0)
                    {
                        break;
                    }
                    currMeshIndex--;
                }
                else if (animationTime < mesh.RightBound)
                {
                    break;
                }
                else
                {
                    currMeshIndex++;
                }
            }
            mesh.Render(parentWidget);
        }
예제 #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;
            }
        }