Exemple #1
0
    private AasRenderSubmeshData GetSubmeshData(AasRenderData renderData,
                                                int submeshId,
                                                ISubmesh submesh)
    {
        if (renderData.submeshes[submeshId] == null)
        {
            renderData.submeshes[submeshId] = new AasRenderSubmeshData(mDevice);
        }

        var submeshData = renderData.submeshes[submeshId];

        if (!submeshData.created)
        {
            submeshData.posBuffer     = mDevice.CreateVertexBuffer(submesh.Positions, false, "AasSubmeshPositions");
            submeshData.normalsBuffer = mDevice.CreateVertexBuffer <Vector4>(submesh.Normals, false, "AasSubmeshNormals");
            submeshData.uvBuffer      = mDevice.CreateVertexBuffer(submesh.UV, debugName: "AasSubmeshUV");
            submeshData.idxBuffer     = mDevice.CreateIndexBuffer(submesh.Indices);

            var binding = submeshData.binding.Resource;
            binding.AddBuffer <Vector4>(submeshData.posBuffer, 0)
            .AddElement(VertexElementType.Float4, VertexElementSemantic.Position);
            binding.AddBuffer <Vector4>(submeshData.normalsBuffer, 0)
            .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal);
            binding.AddBuffer <Vector2>(submeshData.uvBuffer, 0)
            .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

            submeshData.created = true;
        }
        else
        {
            submeshData.posBuffer.Resource.Update(submesh.Positions);
            submeshData.normalsBuffer.Resource.Update <Vector4>(submesh.Normals);
        }

        return(submeshData);
    }