public List <VaoAttribute> LoadGLAttributes()
        {
            var vertexBuffer = ParentModel.Model.VertexBuffers[Shape.VertexBufferIndex];

            List <VaoAttribute> attributes = new List <VaoAttribute>();

            int offset = 0;

            foreach (VertexAttrib att in vertexBuffer.Attributes.Values)
            {
                if (!ElementCountLookup.ContainsKey(att.Name.Remove(2)))
                {
                    continue;
                }

                bool assigned = false;
                int  stride   = 0;

                var assign = Material.Material.ShaderAssign;
                foreach (var matAttribute in assign.AttribAssigns)
                {
                    if (matAttribute.Value == att.Name)
                    {
                        //Get the translated attribute that is passed to the fragment shader
                        //Models can assign the same attribute to multiple uniforms (ie u0 to u1, u2)
                        string translated = matAttribute.Key;

                        VaoAttribute vaoAtt = (VaoAttribute)Activator.CreateInstance(VaoAttributeType);
                        vaoAtt.vertexAttributeName = att.Name;
                        vaoAtt.name         = translated;
                        vaoAtt.ElementCount = ElementCountLookup[att.Name.Remove(2)];
                        vaoAtt.Assigned     = assigned;
                        vaoAtt.Offset       = offset;

                        if (att.Name.Contains("_i"))
                        {
                            vaoAtt.Type = VertexAttribPointerType.Int;
                        }
                        else
                        {
                            vaoAtt.Type = VertexAttribPointerType.Float;
                        }

                        attributes.Add(vaoAtt);

                        if (!assigned)
                        {
                            stride   = vaoAtt.Stride;
                            assigned = true;
                        }
                    }
                }

                offset += stride;
            }
            return(attributes);
        }
Exemple #2
0
        public override void LoadMesh(BfresMeshAsset mesh)
        {
            int offset = mesh.Attributes.Sum(x => x.Stride);

            for (int i = 0; i < 3; i++)
            {
                if (mesh.Attributes.Any(x => x.name == $"inst{i}"))
                {
                    continue;
                }

                VaoAttribute vaoAtt = new VaoAttribute();
                vaoAtt.vertexAttributeName = $"inst{i}";
                vaoAtt.name         = $"inst{i}";
                vaoAtt.ElementCount = 4;
                vaoAtt.Offset       = offset;
                vaoAtt.Type         = VertexAttribPointerType.Float;
                mesh.Attributes.Add(vaoAtt);

                offset += vaoAtt.Stride;
            }

            var tangentAttribute = mesh.Attributes.FirstOrDefault(x => x.name == "_t0");

            if (tangentAttribute != null)
            {
                tangentAttribute.name = "tangent";
            }

            //Tangents need to be assigned manually for some reason.
            if (!mesh.Attributes.Any(x => x.name == "tangent"))
            {
                VaoAttribute vaoAtt = new VaoAttribute();
                vaoAtt.vertexAttributeName = $"_t0";
                vaoAtt.name         = $"tangent";
                vaoAtt.ElementCount = 4;
                vaoAtt.Offset       = offset;
                vaoAtt.Type         = VertexAttribPointerType.Float;
                mesh.Attributes.Add(vaoAtt);

                offset += vaoAtt.Stride;
            }

            mesh.UpdateVertexBuffer();
        }