コード例 #1
0
        private void SetupDrawCalls(Mesh mesh, Dictionary <string, string> skinMaterials)
        {
            var vbib           = mesh.VBIB;
            var data           = mesh.GetData();
            var gpuMeshBuffers = guiContext.MeshBufferCache.GetVertexIndexBuffers(vbib);

            //Prepare drawcalls
            var sceneObjects = data.GetArray("m_sceneObjects");

            foreach (var sceneObject in sceneObjects)
            {
                var objectDrawCalls = sceneObject.GetArray("m_drawCalls");

                foreach (var objectDrawCall in objectDrawCalls)
                {
                    var materialName = objectDrawCall.GetProperty <string>("m_material") ?? objectDrawCall.GetProperty <string>("m_pMaterial");

                    if (skinMaterials != null && skinMaterials.ContainsKey(materialName))
                    {
                        materialName = skinMaterials[materialName];
                    }

                    var material  = guiContext.MaterialLoader.GetMaterial(materialName);
                    var isOverlay = material.Material.IntParams.ContainsKey("F_OVERLAY");

                    // Ignore overlays for now
                    if (isOverlay)
                    {
                        continue;
                    }

                    var shaderArguments = new Dictionary <string, bool>();

                    if (Mesh.IsCompressedNormalTangent(objectDrawCall))
                    {
                        shaderArguments.Add("fulltangent", false);
                    }

                    // TODO: Don't pass around so much shit
                    var drawCall = CreateDrawCall(objectDrawCall, vbib, shaderArguments, material);

                    DrawCallsAll.Add(drawCall);
                    if (drawCall.Material.IsBlended)
                    {
                        DrawCallsBlended.Add(drawCall);
                    }
                    else
                    {
                        DrawCallsOpaque.Add(drawCall);
                    }
                }
            }

            //drawCalls = drawCalls.OrderBy(x => x.Material.Parameters.Name).ToList();
        }
コード例 #2
0
        private void SetupDrawCalls(Mesh mesh, Dictionary <string, string> skinMaterials)
        {
            var vbib           = mesh.VBIB;
            var data           = mesh.GetData();
            var gpuMeshBuffers = guiContext.MeshBufferCache.GetVertexIndexBuffers(vbib);

            //Prepare drawcalls
            var sceneObjects = data.GetArray("m_sceneObjects");

            foreach (var sceneObject in sceneObjects)
            {
                var objectDrawCalls = sceneObject.GetArray("m_drawCalls");

                foreach (var objectDrawCall in objectDrawCalls)
                {
                    var materialName = objectDrawCall.GetProperty <string>("m_material");

                    if (skinMaterials != null && skinMaterials.ContainsKey(materialName))
                    {
                        materialName = skinMaterials[materialName];
                    }

                    var material  = guiContext.MaterialLoader.GetMaterial(materialName);
                    var isOverlay = material.Material.IntParams.ContainsKey("F_OVERLAY");

                    // Ignore overlays for now
                    if (isOverlay)
                    {
                        continue;
                    }

                    var shaderArguments = new Dictionary <string, bool>();
                    if (objectDrawCall.ContainsKey("m_bUseCompressedNormalTangent"))
                    {
                        shaderArguments.Add("fulltangent", !objectDrawCall.GetProperty <bool>("m_bUseCompressedNormalTangent"));
                    }

                    if (objectDrawCall.ContainsKey("m_nFlags"))
                    {
                        var flags = objectDrawCall.GetProperty <object>("m_nFlags");

                        switch (flags)
                        {
                        case string flagsString:
                            if (flagsString.Contains("MESH_DRAW_FLAGS_USE_COMPRESSED_NORMAL_TANGENT"))
                            {
                                shaderArguments.Add("fulltangent", false);
                            }

                            break;

                        case long flagsLong:
                            // TODO: enum
                            if ((flagsLong & 2) == 2)
                            {
                                shaderArguments.Add("fulltangent", false);
                            }

                            break;
                        }
                    }

                    // TODO: Don't pass around so much shit
                    var drawCall = CreateDrawCall(objectDrawCall, vbib, gpuMeshBuffers, shaderArguments, material);

                    if (drawCall.Material.IsBlended)
                    {
                        DrawCallsBlended.Add(drawCall);
                    }
                    else
                    {
                        DrawCallsOpaque.Add(drawCall);
                    }
                }
            }

            //drawCalls = drawCalls.OrderBy(x => x.Material.Parameters.Name).ToList();
        }